@restatedev/restate-sdk 0.7.3-worker → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +29 -51
  3. package/dist/clients/workflow_client.d.ts +77 -0
  4. package/dist/clients/workflow_client.d.ts.map +1 -0
  5. package/dist/clients/workflow_client.js +172 -0
  6. package/dist/clients/workflow_client.js.map +1 -0
  7. package/dist/connection/buffered_connection.js +44 -0
  8. package/dist/connection/buffered_connection.js.map +1 -0
  9. package/dist/connection/connection.js +13 -0
  10. package/dist/connection/connection.js.map +1 -0
  11. package/dist/connection/embedded_connection.js +59 -0
  12. package/dist/connection/embedded_connection.js.map +1 -0
  13. package/dist/connection/http_connection.js +203 -0
  14. package/dist/connection/http_connection.js.map +1 -0
  15. package/dist/connection/lambda_connection.js +58 -0
  16. package/dist/connection/lambda_connection.js.map +1 -0
  17. package/dist/{restate_context.d.ts → context.d.ts} +239 -170
  18. package/dist/context.d.ts.map +1 -0
  19. package/dist/context.js +113 -0
  20. package/dist/context.js.map +1 -0
  21. package/dist/{restate_context_impl.d.ts → context_impl.d.ts} +26 -30
  22. package/dist/context_impl.d.ts.map +1 -0
  23. package/dist/context_impl.js +439 -0
  24. package/dist/context_impl.js.map +1 -0
  25. package/dist/embedded/api.d.ts +2 -2
  26. package/dist/embedded/api.d.ts.map +1 -1
  27. package/dist/embedded/api.js +35 -0
  28. package/dist/embedded/api.js.map +1 -0
  29. package/dist/embedded/handler.d.ts +2 -2
  30. package/dist/embedded/handler.d.ts.map +1 -1
  31. package/dist/embedded/handler.js +26 -0
  32. package/dist/embedded/handler.js.map +1 -0
  33. package/dist/embedded/http2_remote.js +91 -0
  34. package/dist/embedded/http2_remote.js.map +1 -0
  35. package/dist/embedded/invocation.d.ts.map +1 -1
  36. package/dist/embedded/invocation.js +94 -0
  37. package/dist/embedded/invocation.js.map +1 -0
  38. package/dist/endpoint/endpoint_impl.d.ts +35 -0
  39. package/dist/endpoint/endpoint_impl.d.ts.map +1 -0
  40. package/dist/endpoint/endpoint_impl.js +405 -0
  41. package/dist/endpoint/endpoint_impl.js.map +1 -0
  42. package/dist/endpoint/http2_handler.d.ts +11 -0
  43. package/dist/endpoint/http2_handler.d.ts.map +1 -0
  44. package/dist/endpoint/http2_handler.js +119 -0
  45. package/dist/endpoint/http2_handler.js.map +1 -0
  46. package/dist/endpoint/lambda_handler.d.ts +15 -0
  47. package/dist/endpoint/lambda_handler.d.ts.map +1 -0
  48. package/dist/endpoint/lambda_handler.js +144 -0
  49. package/dist/endpoint/lambda_handler.js.map +1 -0
  50. package/dist/endpoint.d.ts +161 -0
  51. package/dist/endpoint.d.ts.map +1 -0
  52. package/dist/endpoint.js +22 -0
  53. package/dist/endpoint.js.map +1 -0
  54. package/dist/generated/dev/restate/events.js +371 -0
  55. package/dist/generated/dev/restate/events.js.map +1 -0
  56. package/dist/generated/dev/restate/ext.js +215 -0
  57. package/dist/generated/dev/restate/ext.js.map +1 -0
  58. package/dist/generated/google/protobuf/descriptor.js +6676 -0
  59. package/dist/generated/google/protobuf/descriptor.js.map +1 -0
  60. package/dist/generated/google/protobuf/empty.js +107 -0
  61. package/dist/generated/google/protobuf/empty.js.map +1 -0
  62. package/dist/generated/google/protobuf/struct.js +754 -0
  63. package/dist/generated/google/protobuf/struct.js.map +1 -0
  64. package/dist/generated/proto/discovery.js +364 -0
  65. package/dist/generated/proto/discovery.js.map +1 -0
  66. package/dist/generated/proto/dynrpc.js +668 -0
  67. package/dist/generated/proto/dynrpc.js.map +1 -0
  68. package/dist/generated/proto/javascript.d.ts +13 -0
  69. package/dist/generated/proto/javascript.d.ts.map +1 -1
  70. package/dist/generated/proto/javascript.js +416 -0
  71. package/dist/generated/proto/javascript.js.map +1 -0
  72. package/dist/generated/proto/protocol.d.ts +43 -0
  73. package/dist/generated/proto/protocol.d.ts.map +1 -1
  74. package/dist/generated/proto/protocol.js +2641 -0
  75. package/dist/generated/proto/protocol.js.map +1 -0
  76. package/dist/generated/proto/services.js +1535 -0
  77. package/dist/generated/proto/services.js.map +1 -0
  78. package/dist/generated/proto/test.js +321 -0
  79. package/dist/generated/proto/test.js.map +1 -0
  80. package/dist/invocation.d.ts +4 -1
  81. package/dist/invocation.d.ts.map +1 -1
  82. package/dist/invocation.js +157 -0
  83. package/dist/invocation.js.map +1 -0
  84. package/dist/io/decoder.d.ts +1 -0
  85. package/dist/io/decoder.d.ts.map +1 -1
  86. package/dist/io/decoder.js +140 -0
  87. package/dist/io/decoder.js.map +1 -0
  88. package/dist/io/encoder.d.ts +1 -2
  89. package/dist/io/encoder.d.ts.map +1 -1
  90. package/dist/io/encoder.js +68 -0
  91. package/dist/io/encoder.js.map +1 -0
  92. package/dist/journal.d.ts +13 -4
  93. package/dist/journal.d.ts.map +1 -1
  94. package/dist/journal.js +405 -0
  95. package/dist/journal.js.map +1 -0
  96. package/dist/local_state_store.d.ts +5 -3
  97. package/dist/local_state_store.d.ts.map +1 -1
  98. package/dist/local_state_store.js +82 -0
  99. package/dist/local_state_store.js.map +1 -0
  100. package/dist/logger.d.ts +19 -0
  101. package/dist/logger.d.ts.map +1 -0
  102. package/dist/logger.js +90 -0
  103. package/dist/logger.js.map +1 -0
  104. package/dist/promise_combinator_tracker.d.ts +29 -0
  105. package/dist/promise_combinator_tracker.d.ts.map +1 -0
  106. package/dist/promise_combinator_tracker.js +128 -0
  107. package/dist/promise_combinator_tracker.js.map +1 -0
  108. package/dist/public_api.d.ts +5 -5
  109. package/dist/public_api.d.ts.map +1 -1
  110. package/dist/public_api.js +60 -0
  111. package/dist/public_api.js.map +1 -0
  112. package/dist/state_machine.d.ts +19 -12
  113. package/dist/state_machine.d.ts.map +1 -1
  114. package/dist/state_machine.js +437 -0
  115. package/dist/state_machine.js.map +1 -0
  116. package/dist/types/errors.d.ts +12 -3
  117. package/dist/types/errors.d.ts.map +1 -1
  118. package/dist/types/errors.js +273 -0
  119. package/dist/types/errors.js.map +1 -0
  120. package/dist/types/grpc.d.ts +6 -4
  121. package/dist/types/grpc.d.ts.map +1 -1
  122. package/dist/types/grpc.js +81 -0
  123. package/dist/types/grpc.js.map +1 -0
  124. package/dist/types/protocol.d.ts +9 -5
  125. package/dist/types/protocol.d.ts.map +1 -1
  126. package/dist/types/protocol.js +147 -0
  127. package/dist/types/protocol.js.map +1 -0
  128. package/dist/types/router.d.ts +8 -8
  129. package/dist/types/router.d.ts.map +1 -1
  130. package/dist/types/router.js +36 -0
  131. package/dist/types/router.js.map +1 -0
  132. package/dist/types/types.d.ts +1 -0
  133. package/dist/types/types.d.ts.map +1 -1
  134. package/dist/types/types.js +138 -0
  135. package/dist/types/types.js.map +1 -0
  136. package/dist/utils/{assumpsions.d.ts → assumptions.d.ts} +1 -1
  137. package/dist/utils/{assumpsions.d.ts.map → assumptions.d.ts.map} +1 -1
  138. package/dist/utils/assumptions.js +101 -0
  139. package/dist/utils/assumptions.js.map +1 -0
  140. package/dist/utils/message_logger.d.ts +28 -0
  141. package/dist/utils/message_logger.d.ts.map +1 -0
  142. package/dist/utils/message_logger.js +88 -0
  143. package/dist/utils/message_logger.js.map +1 -0
  144. package/dist/utils/promises.d.ts +15 -0
  145. package/dist/utils/promises.d.ts.map +1 -0
  146. package/dist/utils/promises.js +67 -0
  147. package/dist/utils/promises.js.map +1 -0
  148. package/dist/utils/public_utils.js +49 -0
  149. package/dist/utils/public_utils.js.map +1 -0
  150. package/dist/utils/rand.d.ts +1 -1
  151. package/dist/utils/rand.d.ts.map +1 -1
  152. package/dist/utils/rand.js +114 -0
  153. package/dist/utils/rand.js.map +1 -0
  154. package/dist/utils/utils.d.ts +1 -10
  155. package/dist/utils/utils.d.ts.map +1 -1
  156. package/dist/utils/utils.js +122 -0
  157. package/dist/utils/utils.js.map +1 -0
  158. package/dist/workflows/workflow.d.ts +101 -0
  159. package/dist/workflows/workflow.d.ts.map +1 -0
  160. package/dist/workflows/workflow.js +80 -0
  161. package/dist/workflows/workflow.js.map +1 -0
  162. package/dist/workflows/workflow_state_service.d.ts +35 -0
  163. package/dist/workflows/workflow_state_service.d.ts.map +1 -0
  164. package/dist/workflows/workflow_state_service.js +201 -0
  165. package/dist/workflows/workflow_state_service.js.map +1 -0
  166. package/dist/workflows/workflow_wrapper_service.d.ts +10 -0
  167. package/dist/workflows/workflow_wrapper_service.d.ts.map +1 -0
  168. package/dist/workflows/workflow_wrapper_service.js +264 -0
  169. package/dist/workflows/workflow_wrapper_service.js.map +1 -0
  170. package/package.json +38 -39
  171. package/src/clients/workflow_client.ts +290 -0
  172. package/src/connection/buffered_connection.ts +47 -0
  173. package/src/connection/connection.ts +34 -0
  174. package/src/connection/embedded_connection.ts +62 -0
  175. package/src/connection/http_connection.ts +228 -0
  176. package/src/connection/lambda_connection.ts +69 -0
  177. package/src/context.ts +633 -0
  178. package/src/context_impl.ts +721 -0
  179. package/src/embedded/api.ts +57 -0
  180. package/src/embedded/handler.ts +36 -0
  181. package/src/embedded/http2_remote.ts +103 -0
  182. package/src/embedded/invocation.ts +126 -0
  183. package/src/endpoint/endpoint_impl.ts +623 -0
  184. package/src/endpoint/http2_handler.ts +151 -0
  185. package/src/endpoint/lambda_handler.ts +181 -0
  186. package/src/endpoint.ts +187 -0
  187. package/src/generated/dev/restate/events.ts +430 -0
  188. package/src/generated/dev/restate/ext.ts +238 -0
  189. package/src/generated/google/protobuf/descriptor.ts +7889 -0
  190. package/src/generated/google/protobuf/empty.ts +150 -0
  191. package/src/generated/google/protobuf/struct.ts +878 -0
  192. package/src/generated/proto/discovery.ts +423 -0
  193. package/src/generated/proto/dynrpc.ts +768 -0
  194. package/src/generated/proto/javascript.ts +488 -0
  195. package/src/generated/proto/protocol.ts +3091 -0
  196. package/src/generated/proto/services.ts +1834 -0
  197. package/src/generated/proto/test.ts +387 -0
  198. package/src/invocation.ts +212 -0
  199. package/src/io/decoder.ts +171 -0
  200. package/src/io/encoder.ts +72 -0
  201. package/src/journal.ts +537 -0
  202. package/src/local_state_store.ts +94 -0
  203. package/src/logger.ts +121 -0
  204. package/src/promise_combinator_tracker.ts +191 -0
  205. package/src/public_api.ts +53 -0
  206. package/src/state_machine.ts +635 -0
  207. package/src/types/errors.ts +297 -0
  208. package/src/types/grpc.ts +97 -0
  209. package/src/types/protocol.ts +201 -0
  210. package/src/types/router.ts +118 -0
  211. package/src/types/types.ts +160 -0
  212. package/src/utils/assumptions.ts +131 -0
  213. package/src/utils/message_logger.ts +112 -0
  214. package/src/utils/promises.ts +118 -0
  215. package/src/utils/public_utils.ts +91 -0
  216. package/src/utils/rand.ts +142 -0
  217. package/src/utils/utils.ts +178 -0
  218. package/src/workflows/workflow.ts +178 -0
  219. package/src/workflows/workflow_state_service.ts +299 -0
  220. package/src/workflows/workflow_wrapper_service.ts +314 -0
  221. package/dist/cloudflare_bundle.js +0 -27387
  222. package/dist/restate_context.d.ts.map +0 -1
  223. package/dist/restate_context_impl.d.ts.map +0 -1
  224. package/dist/server/base_restate_server.d.ts +0 -32
  225. package/dist/server/base_restate_server.d.ts.map +0 -1
  226. package/dist/server/restate_lambda_handler.d.ts +0 -104
  227. package/dist/server/restate_lambda_handler.d.ts.map +0 -1
  228. package/dist/server/restate_server.d.ts +0 -97
  229. package/dist/server/restate_server.d.ts.map +0 -1
  230. package/dist/utils/logger.d.ts +0 -60
  231. package/dist/utils/logger.d.ts.map +0 -1
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2023-2024 - Restate Software, Inc., Restate GmbH
4
+ *
5
+ * This file is part of the Restate SDK for Node.js/TypeScript,
6
+ * which is released under the MIT license.
7
+ *
8
+ * You can find a copy of the license in file LICENSE in the root
9
+ * directory of this repository or package, or at
10
+ * https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.wrapHandler = void 0;
14
+ const context_1 = require("../context");
15
+ const grpc_1 = require("../types/grpc");
16
+ function wrapHandler(handler) {
17
+ const localMethod = (instance, input) => {
18
+ return handler((0, context_1.useContext)(instance), input);
19
+ };
20
+ const encoder = (output) => Buffer.from(JSON.stringify(output));
21
+ const decoder = (buf) => JSON.parse(buf.toString());
22
+ const method = new grpc_1.GrpcServiceMethod("", "", false, localMethod, decoder, encoder);
23
+ return new grpc_1.HostedGrpcServiceMethod({}, "", "", method);
24
+ }
25
+ exports.wrapHandler = wrapHandler;
26
+ //# sourceMappingURL=handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.js","sourceRoot":"","sources":["../../src/embedded/handler.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH,wCAAiD;AACjD,wCAA2E;AAE3E,SAAgB,WAAW,CACzB,OAA+C;IAE/C,MAAM,WAAW,GAAG,CAAC,QAAiB,EAAE,KAAQ,EAAc,EAAE;QAC9D,OAAO,OAAO,CAAC,IAAA,oBAAU,EAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,CAAC;IAC9C,CAAC,CAAC;IAEF,MAAM,OAAO,GAAG,CAAC,MAAS,EAAc,EAAE,CACxC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IACtC,MAAM,OAAO,GAAG,CAAC,GAAe,EAAK,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;IAEnE,MAAM,MAAM,GAAG,IAAI,wBAAiB,CAClC,EAAE,EACF,EAAE,EACF,KAAK,EACL,WAAW,EACX,OAAO,EACP,OAAO,CACR,CAAC;IAEF,OAAO,IAAI,8BAAuB,CAAO,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;AAC/D,CAAC;AArBD,kCAqBC"}
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2023-2024 - Restate Software, Inc., Restate GmbH
4
+ *
5
+ * This file is part of the Restate SDK for Node.js/TypeScript,
6
+ * which is released under the MIT license.
7
+ *
8
+ * You can find a copy of the license in file LICENSE in the root
9
+ * directory of this repository or package, or at
10
+ * https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
11
+ */
12
+ 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.bufConnectRemoteContext = exports.RequestError = void 0;
17
+ const node_http2_1 = __importDefault(require("node:http2"));
18
+ const events_1 = require("events");
19
+ const services_1 = require("../generated/proto/services");
20
+ class RequestError extends Error {
21
+ url;
22
+ status;
23
+ statusText;
24
+ constructor(url, status, statusText) {
25
+ super(`${status} ${statusText ?? ""}`);
26
+ this.url = url;
27
+ this.status = status;
28
+ this.statusText = statusText;
29
+ }
30
+ precondtionFailed() {
31
+ return this.status === node_http2_1.default.constants.HTTP_STATUS_PRECONDITION_FAILED;
32
+ }
33
+ }
34
+ exports.RequestError = RequestError;
35
+ const bufConnectRemoteContext = (url, opt) => {
36
+ const httpClient = new ProtobufHttp2Client(url, opt);
37
+ return new services_1.RemoteContextClientImpl({
38
+ request: (service, method, data) => httpClient.post(`/${service}/${method}`, data),
39
+ });
40
+ };
41
+ exports.bufConnectRemoteContext = bufConnectRemoteContext;
42
+ class ProtobufHttp2Client {
43
+ ingress;
44
+ session;
45
+ additionalHeaders;
46
+ constructor(ingress, opt) {
47
+ this.ingress = ingress;
48
+ this.additionalHeaders = opt?.headers == undefined ? {} : opt?.headers;
49
+ }
50
+ async client() {
51
+ if (this.session !== undefined) {
52
+ return this.session;
53
+ }
54
+ const client = node_http2_1.default.connect(this.ingress);
55
+ client.unref();
56
+ client.once("goaway", () => {
57
+ this.session = undefined;
58
+ });
59
+ client.once("close", () => {
60
+ this.session = undefined;
61
+ });
62
+ this.session = client;
63
+ return client;
64
+ }
65
+ async post(path, body) {
66
+ const client = await this.client();
67
+ const req = client.request({
68
+ ...{
69
+ [node_http2_1.default.constants.HTTP2_HEADER_SCHEME]: "http",
70
+ [node_http2_1.default.constants.HTTP2_HEADER_METHOD]: node_http2_1.default.constants.HTTP2_METHOD_POST,
71
+ [node_http2_1.default.constants.HTTP2_HEADER_PATH]: path,
72
+ [node_http2_1.default.constants.HTTP2_HEADER_CONTENT_TYPE]: "application/proto",
73
+ [node_http2_1.default.constants.HTTP2_HEADER_ACCEPT]: "application/proto",
74
+ [node_http2_1.default.constants.HTTP2_HEADER_CONTENT_LENGTH]: body.length,
75
+ },
76
+ ...this.additionalHeaders,
77
+ });
78
+ req.end(body);
79
+ const [headers] = await (0, events_1.once)(req, "response");
80
+ const status = headers[node_http2_1.default.constants.HTTP2_HEADER_STATUS] ?? 0;
81
+ if (status !== 200) {
82
+ throw new RequestError(path, status);
83
+ }
84
+ const chunks = [];
85
+ for await (const chunk of req) {
86
+ chunks.push(chunk);
87
+ }
88
+ return Buffer.concat(chunks);
89
+ }
90
+ }
91
+ //# sourceMappingURL=http2_remote.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http2_remote.js","sourceRoot":"","sources":["../../src/embedded/http2_remote.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;AAEH,4DAA+B;AAC/B,mCAA8B;AAC9B,0DAGqC;AAIrC,MAAa,YAAa,SAAQ,KAAK;IAEnB;IACA;IACA;IAHlB,YACkB,GAAW,EACX,MAAc,EACd,UAAmB;QAEnC,KAAK,CAAC,GAAG,MAAM,IAAI,UAAU,IAAI,EAAE,EAAE,CAAC,CAAC;QAJvB,QAAG,GAAH,GAAG,CAAQ;QACX,WAAM,GAAN,MAAM,CAAQ;QACd,eAAU,GAAV,UAAU,CAAS;IAGrC,CAAC;IAED,iBAAiB;QACf,OAAO,IAAI,CAAC,MAAM,KAAK,oBAAK,CAAC,SAAS,CAAC,+BAA+B,CAAC;IACzE,CAAC;CACF;AAZD,oCAYC;AAEM,MAAM,uBAAuB,GAAG,CACrC,GAAW,EACX,GAA8B,EACf,EAAE;IACjB,MAAM,UAAU,GAAG,I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6B,CAAC;AAErC,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAOxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,OAAO,CAAC;AAEjD,eAAO,MAAM,QAAQ,iBACX,aAAa,eACR,MAAM,YACT,MAAM,yDAGV,wBAAwB,eAkF/B,CAAC"}
1
+ {"version":3,"file":"invocation.d.ts","sourceRoot":"","sources":["../../src/embedded/invocation.ts"],"names":[],"mappings":"AAaA,OAAO,EAEL,aAAa,EAEd,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAOxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,OAAO,CAAC;AAEjD,eAAO,MAAM,QAAQ,iBACX,aAAa,eACR,MAAM,YACT,MAAM,yDAGV,wBAAwB,eAoF/B,CAAC"}
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2023-2024 - Restate Software, Inc., Restate GmbH
4
+ *
5
+ * This file is part of the Restate SDK for Node.js/TypeScript,
6
+ * which is released under the MIT license.
7
+ *
8
+ * You can find a copy of the license in file LICENSE in the root
9
+ * directory of this repository or package, or at
10
+ * https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.doInvoke = void 0;
14
+ const decoder_1 = require("../io/decoder");
15
+ const services_1 = require("../generated/proto/services");
16
+ const invocation_1 = require("../invocation");
17
+ const state_machine_1 = require("../state_machine");
18
+ const discovery_1 = require("../generated/proto/discovery");
19
+ const embedded_connection_1 = require("../connection/embedded_connection");
20
+ const doInvoke = async (remote, operationId, streamId, input, method, opt) => {
21
+ //
22
+ // 1. ask to Start this execution.
23
+ //
24
+ const startRequest = services_1.StartRequest.fromPartial({
25
+ operationId,
26
+ streamId,
27
+ argument: Buffer.from(JSON.stringify(input)),
28
+ });
29
+ if (opt != undefined && opt.retain != undefined) {
30
+ startRequest.retentionPeriodSec = opt.retain;
31
+ }
32
+ const res = await remote.start(startRequest);
33
+ if (res.completed !== undefined) {
34
+ return unwrap(res.completed);
35
+ }
36
+ //
37
+ // 2. rebuild the previous execution state
38
+ //
39
+ const messages = (0, decoder_1.decodeMessagesBuffer)(res.executing ?? Buffer.alloc(0));
40
+ const journalBuilder = new invocation_1.InvocationBuilder(method);
41
+ messages.forEach((e) => journalBuilder.handleMessage(e));
42
+ const journal = journalBuilder.build();
43
+ //
44
+ // 3. resume the execution state machine
45
+ //
46
+ const connection = new embedded_connection_1.EmbeddedConnection(operationId, streamId, remote);
47
+ const stateMachine = new state_machine_1.StateMachine(connection, journal, discovery_1.ProtocolMode.BIDI_STREAM, false, journal.inferLoggerContext(), -1);
48
+ //
49
+ // 4. track the state machine execution result
50
+ //
51
+ let done = false;
52
+ const invocation = stateMachine.invoke().finally(() => (done = true));
53
+ //
54
+ // 5. keep pulling for input and feeding this to the fsm.
55
+ //
56
+ try {
57
+ while (!done) {
58
+ const recv = await remote.recv({
59
+ operationId,
60
+ streamId,
61
+ });
62
+ if (recv.invalidStream !== undefined) {
63
+ throw new embedded_connection_1.FencedOffError();
64
+ }
65
+ if (recv.invocationCompleted !== undefined) {
66
+ break;
67
+ }
68
+ const buffer = recv.messages ?? Buffer.alloc(0);
69
+ const messages = (0, decoder_1.decodeMessagesBuffer)(buffer);
70
+ messages.forEach((m) => stateMachine.handleMessage(m));
71
+ }
72
+ }
73
+ catch (e) {
74
+ stateMachine.handleStreamError(e);
75
+ throw e;
76
+ }
77
+ //
78
+ // 6. wait for the state machine to complete the invocation
79
+ //
80
+ const maybeResult = await invocation;
81
+ if (maybeResult instanceof Buffer) {
82
+ return JSON.parse(maybeResult.toString());
83
+ }
84
+ // TODO: no sure what to do here. The state machine has decided to be suspended?
85
+ throw new Error("suspended");
86
+ };
87
+ exports.doInvoke = doInvoke;
88
+ const unwrap = (response) => {
89
+ if (response.success === undefined) {
90
+ throw new Error(response.failure?.message ?? "");
91
+ }
92
+ return JSON.parse(response.success.toString());
93
+ };
94
+ //# sourceMappingURL=invocation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invocation.js","sourceRoot":"","sources":["../../src/embedded/invocation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH,2CAAqD;AAErD,0DAIqC;AACrC,8CAAkD;AAElD,oDAAgD;AAChD,4DAA4D;AAC5D,2EAG2C;AAGpC,MAAM,QAAQ,GAAG,KAAK,EAC3B,MAAqB,EACrB,WAAmB,EACnB,QAAgB,EAChB,KAAQ,EACR,MAAqC,EACrC,GAA8B,EAClB,EAAE;IACd,EAAE;IACF,kCAAkC;IAClC,EAAE;IAEF,MAAM,YAAY,GAAG,uBAAY,CAAC,WAAW,CAAC;QAC5C,WAAW;QACX,QAAQ;QACR,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;KAC7C,CAAC,CAAC;IACH,IAAI,GAAG,IAAI,SAAS,IAAI,GAAG,CAAC,MAAM,IAAI,SAAS,EAAE;QAC/C,YAAY,CAAC,kBAAkB,GAAG,GAAG,CAAC,MAAM,CAAC;KAC9C;IACD,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAE7C,IAAI,GAAG,CAAC,SAAS,KAAK,SAAS,EAAE;QAC/B,OAAO,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;KAC9B;IAED,EAAE;IACF,0CAA0C;IAC1C,EAAE;IAEF,MAAM,QAAQ,GAAG,IAAA,8BAAoB,EAAC,GAAG,CAAC,SAAS,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACxE,MAAM,cAAc,GAAG,IAAI,8BAAiB,CAAC,MAAM,CAAC,CAAC;IACrD,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAU,EAAE,EAAE,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IACl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AM,CAAC,CAAC;KACT;IAED,EAAE;IACF,2DAA2D;IAC3D,EAAE;IACF,MAAM,WAAW,GAAG,MAAM,UAAU,CAAC;IACrC,IAAI,WAAW,YAAY,MAAM,EAAE;QACjC,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,CAAC;KAC3C;IAED,gFAAgF;IAChF,MAAM,IAAI,KAAK,CAAC,WAAW,CAAC,CAAC;AAC/B,CAAC,CAAC;AA1FW,QAAA,QAAQ,YA0FnB;AAEF,MAAM,MAAM,GAAG,CAAI,QAA2B,EAAK,EAAE;IACnD,IAAI,QAAQ,CAAC,OAAO,KAAK,SAAS,EAAE;QAClC,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC;KAClD;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAM,CAAC;AACtD,CAAC,CAAC"}
@@ -0,0 +1,35 @@
1
+ /// <reference types="node" />
2
+ import { GrpcService, GrpcServiceMethod, HostedGrpcServiceMethod, ProtoMetadata } from "../types/grpc";
3
+ import { DeepPartial, ServiceDiscoveryResponse } from "../generated/proto/discovery";
4
+ import { MethodDescriptorProto as MethodDescriptorProto1 } from "ts-proto-descriptors";
5
+ import { ProtoMetadata as RpcServiceProtoMetadata } from "../generated/proto/dynrpc";
6
+ import { RestateEndpoint, ServiceBundle } from "../public_api";
7
+ import { KeyedRouter, UnKeyedRouter } from "../types/router";
8
+ import { ServiceOpts } from "../endpoint";
9
+ import { Http2ServerRequest, Http2ServerResponse } from "http2";
10
+ export declare class EndpointImpl implements RestateEndpoint {
11
+ protected readonly methods: Record<string, HostedGrpcServiceMethod<unknown, unknown>>;
12
+ readonly discovery: DeepPartial<ServiceDiscoveryResponse>;
13
+ protected readonly dynrpcDescriptor: RpcServiceProtoMetadata;
14
+ constructor();
15
+ bindService({ descriptor, service, instance }: ServiceOpts): RestateEndpoint;
16
+ bindRouter<M>(path: string, router: UnKeyedRouter<M>): RestateEndpoint;
17
+ bindKeyedRouter<M>(path: string, router: KeyedRouter<M>): RestateEndpoint;
18
+ bind(services: ServiceBundle): RestateEndpoint;
19
+ http2Handler(): (request: Http2ServerRequest, response: Http2ServerResponse) => void;
20
+ lambdaHandler(): (event: any, ctx: any) => Promise<any>;
21
+ listen(port?: number): Promise<void>;
22
+ private addDescriptor;
23
+ private rpcHandler;
24
+ stringKeyedEventHandler(keyed: boolean, route: string, handler: Function): {
25
+ descriptor: MethodDescriptorProto1;
26
+ method: GrpcServiceMethod<unknown, unknown>;
27
+ };
28
+ private bindRpcService;
29
+ methodByUrl<I, O>(url: string | undefined | null): HostedGrpcServiceMethod<I, O> | undefined;
30
+ }
31
+ export declare function parseService(meta: ProtoMetadata, serviceName: string, instance: any): GrpcService;
32
+ export type RpcRouter = {
33
+ [key: string]: Function;
34
+ };
35
+ //# sourceMappingURL=endpoint_impl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoint_impl.d.ts","sourceRoot":"","sources":["../../src/endpoint/endpoint_impl.ts"],"names":[],"mappings":";AAaA,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,uBAAuB,EACvB,aAAa,EACd,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,WAAW,EACX,wBAAwB,EACzB,MAAM,8BAA8B,CAAC;AAOtC,OAAO,EAGL,qBAAqB,IAAI,sBAAsB,EAChD,MAAM,sBAAsB,CAAC;AAM9B,OAAO,EAGL,aAAa,IAAI,uBAAuB,EAGzC,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,eAAe,EAAE,aAAa,EAAiB,MAAM,eAAe,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,aAAa,EAAkB,MAAM,iBAAiB,CAAC;AAG7E,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAc,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAA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