@restatedev/restate-sdk 1.4.0 → 1.5.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 (177) hide show
  1. package/README.md +6 -4
  2. package/dist/cjs/src/common_api.d.ts +5 -5
  3. package/dist/cjs/src/common_api.d.ts.map +1 -1
  4. package/dist/cjs/src/common_api.js +2 -1
  5. package/dist/cjs/src/common_api.js.map +1 -1
  6. package/dist/cjs/src/context.d.ts +68 -10
  7. package/dist/cjs/src/context.d.ts.map +1 -1
  8. package/dist/cjs/src/context.js +21 -9
  9. package/dist/cjs/src/context.js.map +1 -1
  10. package/dist/cjs/src/context_impl.d.ts +28 -58
  11. package/dist/cjs/src/context_impl.d.ts.map +1 -1
  12. package/dist/cjs/src/context_impl.js +200 -428
  13. package/dist/cjs/src/context_impl.js.map +1 -1
  14. package/dist/cjs/src/endpoint/endpoint_builder.d.ts +4 -5
  15. package/dist/cjs/src/endpoint/endpoint_builder.d.ts.map +1 -1
  16. package/dist/cjs/src/endpoint/endpoint_builder.js +21 -16
  17. package/dist/cjs/src/endpoint/endpoint_builder.js.map +1 -1
  18. package/dist/cjs/src/endpoint/fetch_endpoint.d.ts +3 -4
  19. package/dist/cjs/src/endpoint/fetch_endpoint.d.ts.map +1 -1
  20. package/dist/cjs/src/endpoint/fetch_endpoint.js +0 -4
  21. package/dist/cjs/src/endpoint/fetch_endpoint.js.map +1 -1
  22. package/dist/cjs/src/endpoint/handlers/fetch.d.ts.map +1 -1
  23. package/dist/cjs/src/endpoint/handlers/fetch.js +1 -0
  24. package/dist/cjs/src/endpoint/handlers/fetch.js.map +1 -1
  25. package/dist/cjs/src/endpoint/handlers/generic.d.ts +7 -13
  26. package/dist/cjs/src/endpoint/handlers/generic.d.ts.map +1 -1
  27. package/dist/cjs/src/endpoint/handlers/generic.js +117 -58
  28. package/dist/cjs/src/endpoint/handlers/generic.js.map +1 -1
  29. package/dist/cjs/src/endpoint/handlers/lambda.d.ts.map +1 -1
  30. package/dist/cjs/src/endpoint/handlers/lambda.js +15 -3
  31. package/dist/cjs/src/endpoint/handlers/lambda.js.map +1 -1
  32. package/dist/cjs/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.d.ts +62 -79
  33. package/dist/cjs/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.d.ts.map +1 -1
  34. package/dist/cjs/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js +561 -874
  35. package/dist/cjs/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js.map +1 -1
  36. package/dist/cjs/src/endpoint/lambda_endpoint.d.ts +3 -4
  37. package/dist/cjs/src/endpoint/lambda_endpoint.d.ts.map +1 -1
  38. package/dist/cjs/src/endpoint/lambda_endpoint.js +0 -4
  39. package/dist/cjs/src/endpoint/lambda_endpoint.js.map +1 -1
  40. package/dist/cjs/src/endpoint/node_endpoint.d.ts +3 -4
  41. package/dist/cjs/src/endpoint/node_endpoint.d.ts.map +1 -1
  42. package/dist/cjs/src/endpoint/node_endpoint.js +12 -4
  43. package/dist/cjs/src/endpoint/node_endpoint.js.map +1 -1
  44. package/dist/cjs/src/endpoint.d.ts +6 -37
  45. package/dist/cjs/src/endpoint.d.ts.map +1 -1
  46. package/dist/cjs/src/generated/version.d.ts +1 -1
  47. package/dist/cjs/src/generated/version.js +1 -1
  48. package/dist/cjs/src/io.d.ts +25 -0
  49. package/dist/cjs/src/io.d.ts.map +1 -0
  50. package/dist/cjs/src/io.js +78 -0
  51. package/dist/cjs/src/io.js.map +1 -0
  52. package/dist/cjs/src/logging/console_logger_transport.d.ts +5 -0
  53. package/dist/cjs/src/logging/console_logger_transport.d.ts.map +1 -0
  54. package/dist/cjs/src/logging/console_logger_transport.js +98 -0
  55. package/dist/cjs/src/logging/console_logger_transport.js.map +1 -0
  56. package/dist/cjs/src/logging/logger.d.ts +11 -0
  57. package/dist/cjs/src/logging/logger.d.ts.map +1 -0
  58. package/dist/cjs/src/logging/logger.js +61 -0
  59. package/dist/cjs/src/logging/logger.js.map +1 -0
  60. package/dist/cjs/src/logging/logger_transport.d.ts +52 -0
  61. package/dist/cjs/src/logging/logger_transport.d.ts.map +1 -0
  62. package/dist/cjs/src/logging/logger_transport.js +59 -0
  63. package/dist/cjs/src/logging/logger_transport.js.map +1 -0
  64. package/dist/cjs/src/promises.d.ts +110 -0
  65. package/dist/cjs/src/promises.d.ts.map +1 -0
  66. package/dist/cjs/src/promises.js +323 -0
  67. package/dist/cjs/src/promises.js.map +1 -0
  68. package/dist/cjs/src/types/components.d.ts +11 -3
  69. package/dist/cjs/src/types/components.d.ts.map +1 -1
  70. package/dist/cjs/src/types/components.js +36 -3
  71. package/dist/cjs/src/types/components.js.map +1 -1
  72. package/dist/cjs/src/types/discovery.d.ts +4 -0
  73. package/dist/cjs/src/types/discovery.d.ts.map +1 -1
  74. package/dist/cjs/src/types/errors.d.ts +8 -0
  75. package/dist/cjs/src/types/errors.d.ts.map +1 -1
  76. package/dist/cjs/src/types/errors.js +12 -1
  77. package/dist/cjs/src/types/errors.js.map +1 -1
  78. package/dist/cjs/src/types/rpc.d.ts +66 -41
  79. package/dist/cjs/src/types/rpc.d.ts.map +1 -1
  80. package/dist/cjs/src/types/rpc.js +25 -76
  81. package/dist/cjs/src/types/rpc.js.map +1 -1
  82. package/dist/cjs/src/user_agent.d.ts +1 -1
  83. package/dist/cjs/src/utils/buffer.d.ts +1 -0
  84. package/dist/cjs/src/utils/buffer.d.ts.map +1 -1
  85. package/dist/cjs/tsconfig.tsbuildinfo +1 -1
  86. package/dist/esm/src/common_api.d.ts +5 -5
  87. package/dist/esm/src/common_api.d.ts.map +1 -1
  88. package/dist/esm/src/common_api.js +1 -1
  89. package/dist/esm/src/common_api.js.map +1 -1
  90. package/dist/esm/src/context.d.ts +68 -10
  91. package/dist/esm/src/context.d.ts.map +1 -1
  92. package/dist/esm/src/context.js +20 -8
  93. package/dist/esm/src/context.js.map +1 -1
  94. package/dist/esm/src/context_impl.d.ts +28 -58
  95. package/dist/esm/src/context_impl.d.ts.map +1 -1
  96. package/dist/esm/src/context_impl.js +196 -425
  97. package/dist/esm/src/context_impl.js.map +1 -1
  98. package/dist/esm/src/endpoint/endpoint_builder.d.ts +4 -5
  99. package/dist/esm/src/endpoint/endpoint_builder.d.ts.map +1 -1
  100. package/dist/esm/src/endpoint/endpoint_builder.js +21 -16
  101. package/dist/esm/src/endpoint/endpoint_builder.js.map +1 -1
  102. package/dist/esm/src/endpoint/fetch_endpoint.d.ts +3 -4
  103. package/dist/esm/src/endpoint/fetch_endpoint.d.ts.map +1 -1
  104. package/dist/esm/src/endpoint/fetch_endpoint.js +0 -4
  105. package/dist/esm/src/endpoint/fetch_endpoint.js.map +1 -1
  106. package/dist/esm/src/endpoint/handlers/fetch.d.ts.map +1 -1
  107. package/dist/esm/src/endpoint/handlers/fetch.js +1 -0
  108. package/dist/esm/src/endpoint/handlers/fetch.js.map +1 -1
  109. package/dist/esm/src/endpoint/handlers/generic.d.ts +7 -13
  110. package/dist/esm/src/endpoint/handlers/generic.d.ts.map +1 -1
  111. package/dist/esm/src/endpoint/handlers/generic.js +110 -51
  112. package/dist/esm/src/endpoint/handlers/generic.js.map +1 -1
  113. package/dist/esm/src/endpoint/handlers/lambda.d.ts.map +1 -1
  114. package/dist/esm/src/endpoint/handlers/lambda.js +15 -3
  115. package/dist/esm/src/endpoint/handlers/lambda.js.map +1 -1
  116. package/dist/esm/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.d.ts +62 -79
  117. package/dist/esm/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.d.ts.map +1 -1
  118. package/dist/esm/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js +559 -873
  119. package/dist/esm/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js.map +1 -1
  120. package/dist/esm/src/endpoint/lambda_endpoint.d.ts +3 -4
  121. package/dist/esm/src/endpoint/lambda_endpoint.d.ts.map +1 -1
  122. package/dist/esm/src/endpoint/lambda_endpoint.js +0 -4
  123. package/dist/esm/src/endpoint/lambda_endpoint.js.map +1 -1
  124. package/dist/esm/src/endpoint/node_endpoint.d.ts +3 -4
  125. package/dist/esm/src/endpoint/node_endpoint.d.ts.map +1 -1
  126. package/dist/esm/src/endpoint/node_endpoint.js +12 -4
  127. package/dist/esm/src/endpoint/node_endpoint.js.map +1 -1
  128. package/dist/esm/src/endpoint.d.ts +6 -37
  129. package/dist/esm/src/endpoint.d.ts.map +1 -1
  130. package/dist/esm/src/generated/version.d.ts +1 -1
  131. package/dist/esm/src/generated/version.js +1 -1
  132. package/dist/esm/src/io.d.ts +25 -0
  133. package/dist/esm/src/io.d.ts.map +1 -0
  134. package/dist/esm/src/io.js +73 -0
  135. package/dist/esm/src/io.js.map +1 -0
  136. package/dist/esm/src/logging/console_logger_transport.d.ts +5 -0
  137. package/dist/esm/src/logging/console_logger_transport.d.ts.map +1 -0
  138. package/dist/esm/src/{logger.js → logging/console_logger_transport.js} +40 -90
  139. package/dist/esm/src/logging/console_logger_transport.js.map +1 -0
  140. package/dist/esm/src/logging/logger.d.ts +11 -0
  141. package/dist/esm/src/logging/logger.d.ts.map +1 -0
  142. package/dist/esm/src/logging/logger.js +57 -0
  143. package/dist/esm/src/logging/logger.js.map +1 -0
  144. package/dist/esm/src/logging/logger_transport.d.ts +52 -0
  145. package/dist/esm/src/logging/logger_transport.d.ts.map +1 -0
  146. package/dist/esm/src/logging/logger_transport.js +55 -0
  147. package/dist/esm/src/logging/logger_transport.js.map +1 -0
  148. package/dist/esm/src/promises.d.ts +110 -0
  149. package/dist/esm/src/promises.d.ts.map +1 -0
  150. package/dist/esm/src/promises.js +311 -0
  151. package/dist/esm/src/promises.js.map +1 -0
  152. package/dist/esm/src/types/components.d.ts +11 -3
  153. package/dist/esm/src/types/components.d.ts.map +1 -1
  154. package/dist/esm/src/types/components.js +36 -3
  155. package/dist/esm/src/types/components.js.map +1 -1
  156. package/dist/esm/src/types/discovery.d.ts +4 -0
  157. package/dist/esm/src/types/discovery.d.ts.map +1 -1
  158. package/dist/esm/src/types/errors.d.ts +8 -0
  159. package/dist/esm/src/types/errors.d.ts.map +1 -1
  160. package/dist/esm/src/types/errors.js +10 -0
  161. package/dist/esm/src/types/errors.js.map +1 -1
  162. package/dist/esm/src/types/rpc.d.ts +66 -41
  163. package/dist/esm/src/types/rpc.d.ts.map +1 -1
  164. package/dist/esm/src/types/rpc.js +25 -76
  165. package/dist/esm/src/types/rpc.js.map +1 -1
  166. package/dist/esm/src/user_agent.d.ts +1 -1
  167. package/dist/esm/src/utils/buffer.d.ts +1 -0
  168. package/dist/esm/src/utils/buffer.d.ts.map +1 -1
  169. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  170. package/package.json +2 -2
  171. package/dist/cjs/src/logger.d.ts +0 -35
  172. package/dist/cjs/src/logger.d.ts.map +0 -1
  173. package/dist/cjs/src/logger.js +0 -151
  174. package/dist/cjs/src/logger.js.map +0 -1
  175. package/dist/esm/src/logger.d.ts +0 -35
  176. package/dist/esm/src/logger.d.ts.map +0 -1
  177. package/dist/esm/src/logger.js.map +0 -1
@@ -10,20 +10,23 @@
10
10
  * https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
11
11
  */
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.ContextImpl = void 0;
13
+ exports.RunClosuresTracker = exports.ContextImpl = void 0;
14
+ const sdk_shared_core_wasm_bindings_js_1 = require("./endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js");
14
15
  const errors_js_1 = require("./types/errors.js");
15
16
  const rpc_js_1 = require("./types/rpc.js");
16
17
  const restate_sdk_core_1 = require("@restatedev/restate-sdk-core");
17
18
  const rand_js_1 = require("./utils/rand.js");
19
+ const completable_promise_js_1 = require("./utils/completable_promise.js");
20
+ const promises_js_1 = require("./promises.js");
21
+ const io_js_1 = require("./io.js");
18
22
  class ContextImpl {
19
23
  coreVm;
20
24
  input;
21
25
  console;
22
26
  handlerKind;
23
- invocationEndPromise;
24
- inputReader;
25
- outputWriter;
27
+ vmLogger;
26
28
  invocationRequest;
29
+ invocationEndPromise;
27
30
  rand;
28
31
  date = {
29
32
  now: () => {
@@ -33,35 +36,34 @@ class ContextImpl {
33
36
  return this.run(() => new Date().toJSON());
34
37
  },
35
38
  };
36
- currentRead;
37
- constructor(coreVm, input, console, handlerKind, attemptHeaders, extraArgs, invocationEndPromise, inputReader, outputWriter) {
39
+ outputPump;
40
+ runClosuresTracker;
41
+ promisesExecutor;
42
+ constructor(coreVm, input, console, handlerKind, vmLogger, invocationRequest, invocationEndPromise, inputReader, outputWriter) {
38
43
  this.coreVm = coreVm;
39
44
  this.input = input;
40
45
  this.console = console;
41
46
  this.handlerKind = handlerKind;
47
+ this.vmLogger = vmLogger;
48
+ this.invocationRequest = invocationRequest;
42
49
  this.invocationEndPromise = invocationEndPromise;
43
- this.inputReader = inputReader;
44
- this.outputWriter = outputWriter;
45
- this.invocationRequest = {
46
- id: input.invocation_id,
47
- headers: input.headers.reduce((headers, { key, value }) => {
48
- headers.set(key, value);
49
- return headers;
50
- }, new Map()),
51
- attemptHeaders: Object.entries(attemptHeaders).reduce((headers, [key, value]) => {
52
- if (value !== undefined) {
53
- headers.set(key, value instanceof Array ? value[0] : value);
54
- }
55
- return headers;
56
- }, new Map()),
57
- body: input.input,
58
- extraArgs,
59
- };
60
50
  this.rand = new rand_js_1.RandImpl(input.invocation_id, () => {
61
- if (coreVm.is_inside_run()) {
62
- throw new Error("Cannot generate random numbers within a run closure. Use the random object outside the run closure.");
63
- }
51
+ // TODO reimplement this check with async context
52
+ // if (coreVm.is_inside_run()) {
53
+ // throw new Error(
54
+ // "Cannot generate random numbers within a run closure. Use the random object outside the run closure."
55
+ // );
56
+ // }
64
57
  });
58
+ this.outputPump = new io_js_1.OutputPump(coreVm, outputWriter);
59
+ this.runClosuresTracker = new RunClosuresTracker();
60
+ this.promisesExecutor = new promises_js_1.PromisesExecutor(coreVm, new io_js_1.InputPump(coreVm, inputReader, this.handleInvocationEndError.bind(this)), this.outputPump, this.runClosuresTracker, this.handleInvocationEndError.bind(this));
61
+ }
62
+ cancel(invocationId) {
63
+ this.processNonCompletableEntry((vm) => vm.sys_cancel_invocation(invocationId));
64
+ }
65
+ attach(invocationId, serde) {
66
+ return this.processCompletableEntry((vm) => vm.sys_attach_invocation(invocationId), completeUsing(SuccessWithSerde(serde ?? (0, rpc_js_1.defaultSerde)()), Failure));
65
67
  }
66
68
  get key() {
67
69
  switch (this.handlerKind) {
@@ -78,36 +80,10 @@ class ContextImpl {
78
80
  return this.invocationRequest;
79
81
  }
80
82
  get(name, serde) {
81
- return this.processCompletableEntry((vm) => vm.sys_get_state(name), (asyncResultValue) => {
82
- if (asyncResultValue === "Empty") {
83
- // Empty
84
- return null;
85
- }
86
- else if ("Success" in asyncResultValue) {
87
- return (serde ?? (0, rpc_js_1.defaultSerde)()).deserialize(asyncResultValue.Success);
88
- }
89
- else if ("Failure" in asyncResultValue) {
90
- throw new errors_js_1.TerminalError(asyncResultValue.Failure.message, {
91
- errorCode: asyncResultValue.Failure.code,
92
- });
93
- }
94
- throw new Error(`Unexpected variant in async result: ${JSON.stringify(asyncResultValue)}`);
95
- });
83
+ return this.processCompletableEntry((vm) => vm.sys_get_state(name), completeUsing(VoidAsNull, SuccessWithSerde(serde ?? (0, rpc_js_1.defaultSerde)())));
96
84
  }
97
85
  stateKeys() {
98
- return this.processCompletableEntry((vm) => vm.sys_get_state_keys(), (asyncResultValue) => {
99
- if (typeof asyncResultValue === "object" &&
100
- "StateKeys" in asyncResultValue) {
101
- return asyncResultValue.StateKeys;
102
- }
103
- else if (typeof asyncResultValue === "object" &&
104
- "Failure" in asyncResultValue) {
105
- throw new errors_js_1.TerminalError(asyncResultValue.Failure.message, {
106
- errorCode: asyncResultValue.Failure.code,
107
- });
108
- }
109
- throw new Error(`Unexpected variant in async result: ${JSON.stringify(asyncResultValue)}`);
110
- });
86
+ return this.processCompletableEntry((vm) => vm.sys_get_state_keys(), completeUsing(StateKeys));
111
87
  }
112
88
  set(name, value, serde) {
113
89
  this.processNonCompletableEntry((vm) => vm.sys_set_state(name, (serde ?? (0, rpc_js_1.defaultSerde)()).serialize(value)));
@@ -123,33 +99,50 @@ class ContextImpl {
123
99
  genericCall(call) {
124
100
  const requestSerde = call.inputSerde ?? restate_sdk_core_1.serde.binary;
125
101
  const responseSerde = call.outputSerde ?? restate_sdk_core_1.serde.binary;
126
- return this.processCompletableEntry((vm) => {
102
+ try {
103
+ const vm = this.coreVm;
127
104
  const parameter = requestSerde.serialize(call.parameter);
128
- return vm.sys_call(call.service, call.method, parameter, call.key);
129
- }, (asyncResultValue) => {
130
- if (typeof asyncResultValue === "object" &&
131
- "Success" in asyncResultValue) {
132
- return responseSerde.deserialize(asyncResultValue.Success);
133
- }
134
- else if (typeof asyncResultValue === "object" &&
135
- "Failure" in asyncResultValue) {
136
- throw new errors_js_1.TerminalError(asyncResultValue.Failure.message, {
137
- errorCode: asyncResultValue.Failure.code,
138
- });
139
- }
140
- throw new Error(`Unexpected variant in async result: ${JSON.stringify(asyncResultValue)}`);
141
- });
105
+ const call_handles = vm.sys_call(call.service, call.method, parameter, call.key, call.headers
106
+ ? Object.entries(call.headers).map(([key, value]) => new sdk_shared_core_wasm_bindings_js_1.WasmHeader(key, value))
107
+ : [], call.idempotencyKey);
108
+ const invocationIdHandle = call_handles.invocation_id_completion_id;
109
+ const invocationIdPromise = this.createInvocationIdPromise(invocationIdHandle);
110
+ const callHandle = call_handles.call_completion_id;
111
+ return new promises_js_1.RestateInvocationPromise(this, callHandle, completeUsing(SuccessWithSerde(responseSerde), Failure), invocationIdPromise);
112
+ }
113
+ catch (e) {
114
+ this.handleInvocationEndError(e);
115
+ // We return a pending promise to avoid the caller to see the error.
116
+ return new promises_js_1.InvocationPendingPromise(this);
117
+ }
142
118
  }
143
119
  genericSend(send) {
144
- this.processNonCompletableEntry((vm) => {
120
+ try {
121
+ const vm = this.coreVm;
145
122
  const requestSerde = send.inputSerde ?? restate_sdk_core_1.serde.binary;
146
123
  const parameter = requestSerde.serialize(send.parameter);
147
124
  let delay;
148
125
  if (send.delay !== undefined) {
149
126
  delay = BigInt(send.delay);
150
127
  }
151
- vm.sys_send(send.service, send.method, parameter, send.key, delay);
152
- });
128
+ const handles = vm.sys_send(send.service, send.method, parameter, send.key, send.headers
129
+ ? Object.entries(send.headers).map(([key, value]) => new sdk_shared_core_wasm_bindings_js_1.WasmHeader(key, value))
130
+ : [], delay, send.idempotencyKey);
131
+ const handle = handles.invocation_id_completion_id;
132
+ const invocationId = this.createInvocationIdPromise(handle);
133
+ return {
134
+ invocationId,
135
+ };
136
+ }
137
+ catch (e) {
138
+ this.handleInvocationEndError(e);
139
+ return {
140
+ invocationId: (0, promises_js_1.pendingPromise)(),
141
+ };
142
+ }
143
+ }
144
+ createInvocationIdPromise(handle) {
145
+ return new promises_js_1.RestateSinglePromise(this, handle, completeUsing(InvocationIdCompleter));
153
146
  }
154
147
  serviceClient({ name }) {
155
148
  return (0, rpc_js_1.makeRpcCallProxy)((call) => this.genericCall(call), name);
@@ -174,28 +167,20 @@ class ContextImpl {
174
167
  // and not in the promise context. To understand the semantic difference, make this function async and run the
175
168
  // UnawaitedSideEffectShouldFailSubsequentContextCall test.
176
169
  run(nameOrAction, actionSecondParameter, options) {
177
- const { name, action } = unpack(nameOrAction, actionSecondParameter);
170
+ const { name, action } = unpackRunParameters(nameOrAction, actionSecondParameter);
178
171
  const serde = options?.serde ?? (0, rpc_js_1.defaultSerde)();
172
+ // Prepare the handle
173
+ let handle;
179
174
  try {
180
- const runEnterResult = this.coreVm.sys_run_enter(name || "");
181
- // Check if the run was already executed
182
- if (typeof runEnterResult === "object" &&
183
- "ExecutedWithSuccess" in runEnterResult) {
184
- return Promise.resolve(serde.deserialize(runEnterResult.ExecutedWithSuccess));
185
- }
186
- else if (typeof runEnterResult === "object" &&
187
- "ExecutedWithFailure" in runEnterResult) {
188
- return Promise.reject(new errors_js_1.TerminalError(runEnterResult.ExecutedWithFailure.message, {
189
- errorCode: runEnterResult.ExecutedWithFailure.code,
190
- }));
191
- }
175
+ handle = this.coreVm.sys_run(name || "");
192
176
  }
193
177
  catch (e) {
194
178
  this.handleInvocationEndError(e);
195
- return pendingPromise();
179
+ return new promises_js_1.RestatePendingPromise(this);
196
180
  }
197
- // We wrap the rest of the execution in this closure to create a future
181
+ // Now prepare the run task
198
182
  const doRun = async () => {
183
+ // Execute the user code
199
184
  const startTime = Date.now();
200
185
  let res;
201
186
  let err;
@@ -206,28 +191,30 @@ class ContextImpl {
206
191
  err = (0, errors_js_1.ensureError)(e);
207
192
  }
208
193
  const attemptDuration = Date.now() - startTime;
209
- // Record the result/failure, get back the handle for the ack.
210
- let handle;
194
+ // Propose the completion to the VM
211
195
  try {
212
196
  if (err !== undefined) {
213
197
  if (err instanceof errors_js_1.TerminalError) {
214
198
  // Record failure, go ahead
215
- handle = this.coreVm.sys_run_exit_failure({
199
+ this.coreVm.propose_run_completion_failure(handle, {
216
200
  code: err.code,
217
201
  message: err.message,
218
202
  });
219
203
  }
220
204
  else {
205
+ this.vmLogger.warn(`Error when processing ctx.run '${name}'.\n`, err);
221
206
  if (options?.retryIntervalFactor === undefined &&
222
207
  options?.initialRetryIntervalMillis === undefined &&
223
208
  options?.maxRetryAttempts === undefined &&
224
209
  options?.maxRetryDurationMillis === undefined &&
225
210
  options?.maxRetryIntervalMillis === undefined) {
226
- // If no retry option was set, simply throw the error.
227
- // This will lead to the invoker applying its retry, without the SDK overriding it.
228
- throw err;
211
+ // If no retry option was set, simply notify the error.
212
+ this.coreVm.notify_error(err.message, err.stack);
213
+ // From now on, no progress will be made.
214
+ this.invocationEndPromise.resolve();
215
+ return (0, promises_js_1.pendingPromise)();
229
216
  }
230
- handle = this.coreVm.sys_run_exit_failure_transient(err.message, err.cause?.toString(), BigInt(attemptDuration), {
217
+ this.coreVm.propose_run_completion_failure_transient(handle, err.message, err.cause?.toString(), BigInt(attemptDuration), {
231
218
  factor: options?.retryIntervalFactor || 2.0,
232
219
  initial_interval: options?.initialRetryIntervalMillis || 50,
233
220
  max_attempts: options?.maxRetryAttempts,
@@ -237,45 +224,25 @@ class ContextImpl {
237
224
  }
238
225
  }
239
226
  else {
227
+ this.coreVm.propose_run_completion_success(handle,
240
228
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
241
229
  // @ts-expect-error
242
- handle = this.coreVm.sys_run_exit_success(serde.serialize(res));
230
+ serde.serialize(res));
243
231
  }
244
232
  }
245
233
  catch (e) {
246
234
  this.handleInvocationEndError(e);
247
- return pendingPromise();
235
+ return (0, promises_js_1.pendingPromise)();
248
236
  }
249
- // Got the handle, wait for the result now (which we get once we get the ack)
250
- return await this.pollAsyncResult(handle, (asyncResultValue) => {
251
- if (typeof asyncResultValue === "object" &&
252
- "Success" in asyncResultValue) {
253
- return serde.deserialize(asyncResultValue.Success);
254
- }
255
- else if (typeof asyncResultValue === "object" &&
256
- "Failure" in asyncResultValue) {
257
- throw new errors_js_1.TerminalError(asyncResultValue.Failure.message, {
258
- errorCode: asyncResultValue.Failure.code,
259
- });
260
- }
261
- throw new Error(`Unexpected variant in async result: ${JSON.stringify(asyncResultValue)}`);
262
- });
237
+ await this.outputPump.awaitNextProgress();
263
238
  };
264
- return doRun();
239
+ // Register the run to execute
240
+ this.runClosuresTracker.registerRunClosure(handle, doRun);
241
+ // Return the promise
242
+ return new promises_js_1.RestateSinglePromise(this, handle, completeUsing(SuccessWithSerde(serde), Failure));
265
243
  }
266
244
  sleep(millis) {
267
- return this.processCompletableEntry((vm) => vm.sys_sleep(BigInt(millis)), (asyncResultValue) => {
268
- if (asyncResultValue === "Empty") {
269
- // Empty
270
- return undefined;
271
- }
272
- else if ("Failure" in asyncResultValue) {
273
- throw new errors_js_1.TerminalError(asyncResultValue.Failure.message, {
274
- errorCode: asyncResultValue.Failure.code,
275
- });
276
- }
277
- throw new Error(`Unexpected variant in async result: ${JSON.stringify(asyncResultValue)}`);
278
- });
245
+ return this.processCompletableEntry((vm) => vm.sys_sleep(BigInt(millis)), completeUsing(VoidAsUndefined));
279
246
  }
280
247
  // -- Awakeables
281
248
  awakeable(serde) {
@@ -287,30 +254,12 @@ class ContextImpl {
287
254
  this.handleInvocationEndError(e);
288
255
  return {
289
256
  id: "invalid",
290
- promise: new LazyContextPromise(0, this, () => pendingPromise()),
257
+ promise: new promises_js_1.RestatePendingPromise(this),
291
258
  };
292
259
  }
293
260
  return {
294
261
  id: awakeable.id,
295
- promise: new LazyContextPromise(awakeable.handle, this, () => this.pollAsyncResult(awakeable.handle, (asyncResultValue) => {
296
- if (typeof asyncResultValue === "object" &&
297
- "Success" in asyncResultValue) {
298
- if (!serde) {
299
- return (0, rpc_js_1.defaultSerde)().deserialize(asyncResultValue.Success);
300
- }
301
- if (asyncResultValue.Success.length === 0) {
302
- return undefined;
303
- }
304
- return serde.deserialize(asyncResultValue.Success);
305
- }
306
- else if (typeof asyncResultValue === "object" &&
307
- "Failure" in asyncResultValue) {
308
- throw new errors_js_1.TerminalError(asyncResultValue.Failure.message, {
309
- errorCode: asyncResultValue.Failure.code,
310
- });
311
- }
312
- throw new Error(`Unexpected variant in async result: ${JSON.stringify(asyncResultValue)}`);
313
- })),
262
+ promise: new promises_js_1.RestateSinglePromise(this, awakeable.handle, completeUsing(VoidAsUndefined, SuccessWithSerde(serde), Failure)),
314
263
  };
315
264
  }
316
265
  resolveAwakeable(id, payload, serde) {
@@ -342,144 +291,22 @@ class ContextImpl {
342
291
  return new DurablePromiseImpl(this, name, serde);
343
292
  }
344
293
  // Used by static methods of CombineablePromise
345
- static createCombinator(combinatorType, promises) {
294
+ static createCombinator(combinatorConstructor, promises) {
346
295
  // Extract context from first promise
347
- const self = extractContext(promises[0]);
296
+ const self = (0, promises_js_1.extractContext)(promises[0]);
348
297
  if (!self) {
349
298
  throw new Error("Not a combinable promise");
350
299
  }
351
300
  // Collect first the promises downcasted to the internal promise type
352
301
  const castedPromises = [];
353
302
  for (const promise of promises) {
354
- if (extractContext(promise) !== self) {
303
+ if ((0, promises_js_1.extractContext)(promise) !== self) {
355
304
  self.handleInvocationEndError(new Error("You're mixing up CombineablePromises from different RestateContext. This is not supported."));
356
- return pendingPromise();
305
+ return new promises_js_1.RestatePendingPromise(self);
357
306
  }
358
307
  castedPromises.push(promise);
359
308
  }
360
- const handles = new Uint32Array(castedPromises.map((p) => p.asyncResultHandle));
361
- // From now on, lazily executes on await
362
- return new LazyPromise(async () => {
363
- let combinatorResultHandle;
364
- try {
365
- // Take output
366
- const nextOutput1 = self.coreVm.take_output();
367
- if (nextOutput1 instanceof Uint8Array) {
368
- await self.outputWriter.write(nextOutput1);
369
- }
370
- for (;;) {
371
- switch (combinatorType) {
372
- case "All":
373
- combinatorResultHandle =
374
- self.coreVm.sys_try_complete_all_combinator(handles);
375
- break;
376
- case "Any":
377
- combinatorResultHandle =
378
- self.coreVm.sys_try_complete_any_combinator(handles);
379
- break;
380
- case "AllSettled":
381
- combinatorResultHandle =
382
- self.coreVm.sys_try_complete_all_settled_combinator(handles);
383
- break;
384
- case "Race":
385
- case "OrTimeout":
386
- combinatorResultHandle =
387
- self.coreVm.sys_try_complete_race_combinator(handles);
388
- break;
389
- }
390
- // We got a result, we're done in this loop
391
- if (combinatorResultHandle !== undefined) {
392
- break;
393
- }
394
- // No result yet, await the next read
395
- await self.awaitNextRead();
396
- }
397
- // We got a result, we need to take_output to write the combinator entry, then we need to poll the result
398
- const nextOutput = self.coreVm.take_output();
399
- if (nextOutput instanceof Uint8Array) {
400
- await self.outputWriter.write(nextOutput);
401
- }
402
- }
403
- catch (e) {
404
- if (e instanceof errors_js_1.TerminalError) {
405
- // All good, this is a recorded failure
406
- throw e;
407
- }
408
- // Not good, this is a retryable error.
409
- self.handleInvocationEndError(e);
410
- return await pendingPromise();
411
- }
412
- const handlesResult = await self.pollAsyncResult(combinatorResultHandle, (asyncResultValue) => {
413
- if (typeof asyncResultValue === "object" &&
414
- "CombinatorResult" in asyncResultValue) {
415
- return asyncResultValue.CombinatorResult;
416
- }
417
- throw new Error(`Unexpected variant in async result: ${JSON.stringify(asyncResultValue)}`);
418
- });
419
- const promisesMap = new Map(castedPromises.map((p) => [p.asyncResultHandle, p]));
420
- // Now all we need to do is to construct the final output based on the handles,
421
- // this depends on combinators themselves.
422
- switch (combinatorType) {
423
- case "All":
424
- return this.extractAllCombinatorResult(handlesResult, promisesMap);
425
- case "Any":
426
- return this.extractAnyCombinatorResult(handlesResult, promisesMap);
427
- case "AllSettled":
428
- return this.extractAllSettledCombinatorResult(handlesResult, promisesMap);
429
- case "Race":
430
- // Just one promise succeeded
431
- return promisesMap.get(handlesResult[0]);
432
- case "OrTimeout":
433
- // The sleep promise is always the second one in the list.
434
- if (handlesResult[0] === castedPromises[1].asyncResultHandle) {
435
- return Promise.reject(new errors_js_1.TimeoutError());
436
- }
437
- else {
438
- return promisesMap.get(handlesResult[0]);
439
- }
440
- }
441
- });
442
- }
443
- static async extractAllCombinatorResult(handlesResult, promisesMap) {
444
- // The result can either all values, or one error
445
- const resultValues = [];
446
- for (const handle of handlesResult) {
447
- try {
448
- resultValues.push(await promisesMap.get(handle));
449
- }
450
- catch (e) {
451
- return Promise.reject(e);
452
- }
453
- }
454
- return Promise.resolve(resultValues);
455
- }
456
- static async extractAnyCombinatorResult(handlesResult, promisesMap) {
457
- // The result can either be one value, or a list of errors
458
- const resultFailures = [];
459
- for (const handle of handlesResult) {
460
- try {
461
- return Promise.resolve(await promisesMap.get(handle));
462
- }
463
- catch (e) {
464
- resultFailures.push(e);
465
- }
466
- }
467
- // Giving back the cause here is completely fine, because all these errors in Aggregate error are Terminal errors!
468
- return Promise.reject(new errors_js_1.TerminalError("All input promises failed", {
469
- cause: new AggregateError(resultFailures),
470
- }));
471
- }
472
- static async extractAllSettledCombinatorResult(handlesResult, promisesMap) {
473
- const resultValues = [];
474
- for (const handle of handlesResult) {
475
- try {
476
- resultValues.push(await promisesMap.get(handle));
477
- }
478
- catch (e) {
479
- resultValues.push(e);
480
- }
481
- }
482
- return Promise.resolve(resultValues);
309
+ return new promises_js_1.RestateCombinatorPromise(self, combinatorConstructor, castedPromises);
483
310
  }
484
311
  // -- Various private methods
485
312
  processNonCompletableEntry(vmCall) {
@@ -490,81 +317,22 @@ class ContextImpl {
490
317
  this.handleInvocationEndError(e);
491
318
  }
492
319
  }
493
- processCompletableEntry(vmCall, transformer) {
320
+ processCompletableEntry(vmCall, completer) {
494
321
  let handle;
495
322
  try {
496
323
  handle = vmCall(this.coreVm);
497
324
  }
498
325
  catch (e) {
499
326
  this.handleInvocationEndError(e);
500
- return new LazyContextPromise(0, this, () => pendingPromise());
501
- }
502
- return new LazyContextPromise(handle, this, () => this.pollAsyncResult(handle, transformer));
503
- }
504
- async pollAsyncResult(handle, transformer) {
505
- try {
506
- // Take output
507
- const nextOutput = this.coreVm.take_output();
508
- if (nextOutput instanceof Uint8Array) {
509
- await this.outputWriter.write(nextOutput);
510
- }
511
- // Now loop waiting for the async result
512
- let asyncResult = this.coreVm.take_async_result(handle);
513
- while (asyncResult === "NotReady") {
514
- await this.awaitNextRead();
515
- // Using notify_await_point immediately before take_async_result
516
- // makes sure the state machine will try to suspend only now,
517
- // in case there aren't other concurrent tasks trying to poll this async result.
518
- this.coreVm.notify_await_point(handle);
519
- asyncResult = this.coreVm.take_async_result(handle);
520
- }
521
- return transformer(asyncResult);
522
- }
523
- catch (e) {
524
- if (e instanceof errors_js_1.TerminalError) {
525
- // All good, this is a recorded failure
526
- throw e;
527
- }
528
- // Not good, this is a retryable error.
529
- this.handleInvocationEndError(e);
530
- return await pendingPromise();
531
- }
532
- }
533
- // This function triggers a read on the input reader,
534
- // and will notify the caller that a read was executed
535
- // and the result was piped in the state machine.
536
- awaitNextRead() {
537
- if (this.currentRead === undefined) {
538
- // Register a new read
539
- this.currentRead = this.readNext().finally(() => {
540
- this.currentRead = undefined;
541
- });
542
- }
543
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
544
- return new Promise((resolve) => this.currentRead?.finally(resolve));
545
- }
546
- async readNext() {
547
- // Take input, and notify it to the vm
548
- let nextValue;
549
- try {
550
- nextValue = await this.inputReader.read();
551
- }
552
- catch (e) {
553
- this.handleInvocationEndError(e);
554
- return pendingPromise();
555
- }
556
- if (nextValue.value !== undefined) {
557
- this.coreVm.notify_input(nextValue.value);
558
- }
559
- if (nextValue.done) {
560
- this.coreVm.notify_input_closed();
327
+ return new promises_js_1.RestatePendingPromise(this);
561
328
  }
329
+ return new promises_js_1.RestateSinglePromise(this, handle, completer);
562
330
  }
563
331
  handleInvocationEndError(e) {
564
332
  const error = (0, errors_js_1.ensureError)(e);
565
333
  if (!(error instanceof errors_js_1.RestateError) ||
566
334
  error.code !== errors_js_1.SUSPENDED_ERROR_CODE) {
567
- this.console.warn("Function completed with an error.\n", error);
335
+ this.vmLogger.warn("Error when processing a Restate context operation.\n", error);
568
336
  }
569
337
  this.coreVm.notify_error(error.message, error.stack);
570
338
  // From now on, no progress will be made.
@@ -572,7 +340,7 @@ class ContextImpl {
572
340
  }
573
341
  }
574
342
  exports.ContextImpl = ContextImpl;
575
- function unpack(a, b) {
343
+ function unpackRunParameters(a, b) {
576
344
  if (typeof a === "string") {
577
345
  if (typeof b !== "function") {
578
346
  throw new TypeError("");
@@ -587,12 +355,6 @@ function unpack(a, b) {
587
355
  }
588
356
  return { action: a };
589
357
  }
590
- const RESTATE_CTX_SYMBOL = Symbol("restateContext");
591
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
592
- function extractContext(n) {
593
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
594
- return n[RESTATE_CTX_SYMBOL];
595
- }
596
358
  class DurablePromiseImpl {
597
359
  ctx;
598
360
  name;
@@ -613,108 +375,118 @@ class DurablePromiseImpl {
613
375
  }
614
376
  [Symbol.toStringTag] = "DurablePromise";
615
377
  get() {
616
- return this.ctx.processCompletableEntry((vm) => vm.sys_get_promise(this.name), (asyncResultValue) => {
617
- if (typeof asyncResultValue === "object" &&
618
- "Success" in asyncResultValue) {
619
- return this.serde.deserialize(asyncResultValue.Success);
620
- }
621
- else if (typeof asyncResultValue === "object" &&
622
- "Failure" in asyncResultValue) {
623
- throw new errors_js_1.TerminalError(asyncResultValue.Failure.message, {
624
- errorCode: asyncResultValue.Failure.code,
625
- });
626
- }
627
- throw new Error(`Unexpected variant in async result: ${JSON.stringify(asyncResultValue)}`);
628
- });
378
+ return this.ctx.processCompletableEntry((vm) => vm.sys_get_promise(this.name), completeUsing(SuccessWithSerde(this.serde), Failure));
629
379
  }
630
380
  peek() {
631
- return this.ctx.processCompletableEntry((vm) => vm.sys_peek_promise(this.name), (asyncResultValue) => {
632
- if (asyncResultValue === "Empty") {
633
- return undefined;
634
- }
635
- else if (typeof asyncResultValue === "object" &&
636
- "Success" in asyncResultValue) {
637
- return this.serde.deserialize(asyncResultValue.Success);
638
- }
639
- else if (typeof asyncResultValue === "object" &&
640
- "Failure" in asyncResultValue) {
641
- throw new errors_js_1.TerminalError(asyncResultValue.Failure.message, {
642
- errorCode: asyncResultValue.Failure.code,
643
- });
644
- }
645
- throw new Error(`Unexpected variant in async result: ${JSON.stringify(asyncResultValue)}`);
646
- });
381
+ return this.ctx.processCompletableEntry((vm) => vm.sys_peek_promise(this.name), completeUsing(VoidAsUndefined, SuccessWithSerde(this.serde), Failure));
647
382
  }
648
383
  resolve(value) {
649
- return this.ctx.processCompletableEntry((vm) => vm.sys_complete_promise_success(this.name, this.serde.serialize(value)), (asyncResultValue) => {
650
- if (asyncResultValue === "Empty") {
651
- return undefined;
652
- }
653
- else if (typeof asyncResultValue === "object" &&
654
- "Failure" in asyncResultValue) {
655
- throw new errors_js_1.TerminalError(asyncResultValue.Failure.message, {
656
- errorCode: asyncResultValue.Failure.code,
657
- });
658
- }
659
- throw new Error(`Unexpected variant in async result: ${JSON.stringify(asyncResultValue)}`);
660
- });
384
+ return this.ctx.processCompletableEntry((vm) => vm.sys_complete_promise_success(this.name, this.serde.serialize(value)), completeUsing(VoidAsUndefined, Failure));
661
385
  }
662
386
  reject(errorMsg) {
663
387
  return this.ctx.processCompletableEntry((vm) => vm.sys_complete_promise_failure(this.name, {
664
388
  code: errors_js_1.INTERNAL_ERROR_CODE,
665
389
  message: errorMsg,
666
- }), (asyncResultValue) => {
667
- if (asyncResultValue === "Empty") {
668
- return undefined;
669
- }
670
- else if (typeof asyncResultValue === "object" &&
671
- "Failure" in asyncResultValue) {
672
- throw new errors_js_1.TerminalError(asyncResultValue.Failure.message, {
673
- errorCode: asyncResultValue.Failure.code,
674
- });
675
- }
676
- throw new Error(`Unexpected variant in async result: ${JSON.stringify(asyncResultValue)}`);
677
- });
390
+ }), completeUsing(VoidAsUndefined, Failure));
678
391
  }
679
392
  }
680
- class LazyPromise {
681
- executor;
682
- _promise;
683
- constructor(executor) {
684
- this.executor = executor;
685
- }
686
- then(onfulfilled, onrejected) {
687
- this._promise = this._promise || this.executor();
688
- return this._promise.then(onfulfilled, onrejected);
689
- }
690
- catch(onrejected) {
691
- this._promise = this._promise || this.executor();
692
- return this._promise.catch(onrejected);
393
+ /// Tracker of run closures to run
394
+ class RunClosuresTracker {
395
+ currentRunWaitPoint;
396
+ runsToExecute = new Map();
397
+ executeRun(handle) {
398
+ const runClosure = this.runsToExecute.get(handle);
399
+ if (runClosure === undefined) {
400
+ throw new Error(`Handle ${handle} doesn't exist`);
401
+ }
402
+ runClosure()
403
+ .finally(() => {
404
+ this.unblockCurrentRunWaitPoint();
405
+ })
406
+ .catch(() => { });
407
+ }
408
+ registerRunClosure(handle, runClosure) {
409
+ this.runsToExecute.set(handle, runClosure);
410
+ }
411
+ awaitNextCompletedRun() {
412
+ if (this.currentRunWaitPoint === undefined) {
413
+ this.currentRunWaitPoint = new completable_promise_js_1.CompletablePromise();
414
+ }
415
+ return this.currentRunWaitPoint.promise;
693
416
  }
694
- finally(onfinally) {
695
- this._promise = this._promise || this.executor();
696
- return this._promise.finally(onfinally);
417
+ unblockCurrentRunWaitPoint() {
418
+ if (this.currentRunWaitPoint !== undefined) {
419
+ const p = this.currentRunWaitPoint;
420
+ this.currentRunWaitPoint = undefined;
421
+ p.resolve();
422
+ }
697
423
  }
698
- [Symbol.toStringTag] = "LazyPromise";
699
424
  }
700
- class LazyContextPromise extends LazyPromise {
701
- asyncResultHandle;
702
- [RESTATE_CTX_SYMBOL];
703
- constructor(asyncResultHandle, ctx, executor) {
704
- super(executor);
705
- this.asyncResultHandle = asyncResultHandle;
706
- this[RESTATE_CTX_SYMBOL] = ctx;
707
- }
708
- orTimeout(millis) {
709
- return ContextImpl.createCombinator("OrTimeout", [
710
- this,
711
- this[RESTATE_CTX_SYMBOL].sleep(millis),
712
- ]);
713
- }
425
+ exports.RunClosuresTracker = RunClosuresTracker;
426
+ function completeUsing(...completers) {
427
+ return (value, prom) => {
428
+ for (const completer of completers) {
429
+ if (completer(value, prom)) {
430
+ return;
431
+ }
432
+ }
433
+ throw new Error(`Unexpected variant in async result: ${JSON.stringify(value)}`);
434
+ };
714
435
  }
715
- // A promise that is never completed
716
- function pendingPromise() {
717
- // eslint-disable-next-line @typescript-eslint/no-empty-function
718
- return new Promise(() => { });
436
+ const VoidAsNull = (value, prom) => {
437
+ if (value === "Empty") {
438
+ prom.resolve(null);
439
+ return true;
440
+ }
441
+ return false;
442
+ };
443
+ const VoidAsUndefined = (value, prom) => {
444
+ if (value === "Empty") {
445
+ prom.resolve(undefined);
446
+ return true;
447
+ }
448
+ return false;
449
+ };
450
+ function SuccessWithSerde(serde, transform) {
451
+ return (value, prom) => {
452
+ if (typeof value !== "object" || !("Success" in value)) {
453
+ return false;
454
+ }
455
+ let val;
456
+ if (serde) {
457
+ val = serde.deserialize(value.Success);
458
+ }
459
+ else {
460
+ val = (0, rpc_js_1.defaultSerde)().deserialize(value.Success);
461
+ }
462
+ if (transform) {
463
+ val = transform(val);
464
+ }
465
+ prom.resolve(val);
466
+ return true;
467
+ };
719
468
  }
469
+ const Failure = (value, prom) => {
470
+ if (typeof value === "object" && "Failure" in value) {
471
+ prom.reject(new errors_js_1.TerminalError(value.Failure.message, {
472
+ errorCode: value.Failure.code,
473
+ }));
474
+ return true;
475
+ }
476
+ return false;
477
+ };
478
+ const StateKeys = (value, prom) => {
479
+ if (typeof value === "object" && "StateKeys" in value) {
480
+ prom.resolve(value.StateKeys);
481
+ return true;
482
+ }
483
+ return false;
484
+ };
485
+ const InvocationIdCompleter = (value, prom) => {
486
+ if (typeof value === "object" && "InvocationId" in value) {
487
+ prom.resolve(value.InvocationId);
488
+ return true;
489
+ }
490
+ return false;
491
+ };
720
492
  //# sourceMappingURL=context_impl.js.map