@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
@@ -1,10 +1,12 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
- import { Rand, RestateGrpcChannel, RestateGrpcContext, RpcContext, RpcGateway, ServiceApi } from "./restate_context";
3
+ /// <reference types="node" />
4
+ import { CombineablePromise, KeyedContext, Rand, RestateGrpcChannel, ServiceApi } from "./context";
4
5
  import { StateMachine } from "./state_machine";
5
6
  import { AsyncLocalStorage } from "async_hooks";
6
7
  import { RetrySettings } from "./utils/public_utils";
7
8
  import { Client, SendClient } from "./types/router";
9
+ import { WrappedPromise } from "./utils/promises";
8
10
  export declare enum CallContexType {
9
11
  None = 0,
10
12
  SideEffect = 1,
@@ -14,56 +16,50 @@ export interface CallContext {
14
16
  type: CallContexType;
15
17
  delay?: number;
16
18
  }
17
- export declare class RestateGrpcContextImpl implements RestateGrpcContext {
19
+ export type InternalCombineablePromise<T> = CombineablePromise<T> & WrappedPromise<T> & {
20
+ journalIndex: number;
21
+ };
22
+ export declare class ContextImpl implements KeyedContext, RestateGrpcChannel {
18
23
  readonly id: Buffer;
19
24
  readonly serviceName: string;
25
+ readonly console: Console;
26
+ readonly keyedContext: boolean;
20
27
  private readonly stateMachine;
21
28
  readonly rand: Rand;
22
29
  static callContext: AsyncLocalStorage<CallContext>;
23
- constructor(id: Buffer, serviceName: string, stateMachine: StateMachine<any, any>, rand?: Rand);
30
+ private executingSideEffect;
31
+ constructor(id: Buffer, serviceName: string, console: Console, keyedContext: boolean, stateMachine: StateMachine<any, any>, rand?: Rand);
24
32
  get<T>(name: string): Promise<T | null>;
33
+ stateKeys(): Promise<Array<string>>;
25
34
  set<T>(name: string, value: T): void;
26
35
  clear(name: string): void;
36
+ clearAll(): void;
27
37
  request(service: string, method: string, data: Uint8Array): Promise<Uint8Array>;
28
38
  private invoke;
29
39
  private invokeOneWay;
30
40
  oneWayCall(call: () => Promise<any>): Promise<void>;
31
41
  delayedCall(call: () => Promise<any>, delayMillis?: number): Promise<void>;
42
+ rpc<M>({ path }: ServiceApi<M>): Client<M>;
43
+ send<M>(options: ServiceApi): SendClient<M>;
44
+ sendDelayed<M>({ path }: ServiceApi, delayMillis: number): SendClient<M>;
45
+ grpcChannel(): RestateGrpcChannel;
32
46
  sideEffect<T>(fn: () => Promise<T>, retryPolicy?: RetrySettings): Promise<T>;
33
- sleep(millis: number): Promise<void>;
47
+ sleep(millis: number): CombineablePromise<void>;
48
+ private sleepInternal;
34
49
  awakeable<T>(): {
35
50
  id: string;
36
- promise: Promise<T>;
51
+ promise: CombineablePromise<T>;
37
52
  };
38
- resolveAwakeable<T>(id: string, payload: T): void;
53
+ resolveAwakeable<T>(id: string, payload?: T): void;
39
54
  rejectAwakeable(id: string, reason: string): void;
40
55
  private completeAwakeable;
56
+ createCombinator<T extends readonly CombineablePromise<unknown>[]>(combinatorConstructor: (promises: PromiseLike<unknown>[]) => Promise<unknown>, promises: T): WrappedPromise<unknown>;
41
57
  private isInSideEffect;
42
58
  private isInOneWayCall;
43
59
  private getOneWayCallDelay;
60
+ private checkNotExecutingSideEffect;
44
61
  private checkState;
45
- rpcGateway(): RpcGateway;
46
- }
47
- export declare class RpcContextImpl implements RpcContext {
48
- private readonly ctx;
49
- readonly id: Buffer;
50
- readonly rand: Rand;
51
- readonly serviceName: string;
52
- constructor(ctx: RestateGrpcContext, id?: Buffer, rand?: Rand, serviceName?: string);
53
- rpc<M>({ path }: ServiceApi): Client<M>;
54
- send<M>(options: ServiceApi): SendClient<M>;
55
- sendDelayed<M>({ path }: ServiceApi, delayMillis: number): SendClient<M>;
56
- get<T>(name: string): Promise<T | null>;
57
- set<T>(name: string, value: T): void;
58
- clear(name: string): void;
59
- sideEffect<T>(fn: () => Promise<T>): Promise<T>;
60
- awakeable<T>(): {
61
- id: string;
62
- promise: Promise<T>;
63
- };
64
- resolveAwakeable<T>(id: string, payload: T): void;
65
- rejectAwakeable(id: string, reason: string): void;
66
- sleep(millis: number): Promise<void>;
67
- grpcChannel(): RestateGrpcChannel;
62
+ private checkStateOperation;
63
+ private markCombineablePromise;
68
64
  }
69
- //# sourceMappingURL=restate_context_impl.d.ts.map
65
+ //# sourceMappingURL=context_impl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context_impl.d.ts","sourceRoot":"","sources":["../src/context_impl.ts"],"names":[],"mappings":";;;AAWA,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,IAAI,EACJ,kBAAkB,EAClB,UAAU,EACX,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AA2B/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAahD,OAA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C,iBAAiB;IAYlB,gBAAgB,CAAC,CAAC,SAAS,SAAS,kBAAkB,CAAC,OAAO,CAAC,EAAE,EACtE,qBAAqB,EAAE,CACrB,QAAQ,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,KAC7B,OAAO,CAAC,OAAO,CAAC,EACrB,QAAQ,EAAE,CAAC,GACV,cAAc,CAAC,OAAO,CAAC;IAyB1B,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,kBAAkB;IAK1B,OAAO,CAAC,2BAA2B;IAUnC,OAAO,CAAC,UAAU;IAwBlB,OAAO,CAAC,mBAAmB;IAS3B,OAAO,CAAC,sBAAsB;CAoC/B"}
@@ -0,0 +1,439 @@
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.ContextImpl = exports.CallContexType = void 0;
14
+ const protocol_1 = require("./generated/proto/protocol");
15
+ const protocol_2 = require("./types/protocol");
16
+ const javascript_1 = require("./generated/proto/javascript");
17
+ const async_hooks_1 = require("async_hooks");
18
+ const errors_1 = require("./types/errors");
19
+ const utils_1 = require("./utils/utils");
20
+ const public_utils_1 = require("./utils/public_utils");
21
+ const dynrpc_1 = require("./generated/proto/dynrpc");
22
+ const assumptions_1 = require("./utils/assumptions");
23
+ const rand_1 = require("./utils/rand");
24
+ const promise_combinator_tracker_1 = require("./promise_combinator_tracker");
25
+ var CallContexType;
26
+ (function (CallContexType) {
27
+ CallContexType[CallContexType["None"] = 0] = "None";
28
+ CallContexType[CallContexType["SideEffect"] = 1] = "SideEffect";
29
+ CallContexType[CallContexType["OneWayCall"] = 2] = "OneWayCall";
30
+ })(CallContexType = exports.CallContexType || (exports.CallContexType = {}));
31
+ class ContextImpl {
32
+ id;
33
+ serviceName;
34
+ console;
35
+ keyedContext;
36
+ stateMachine;
37
+ rand;
38
+ // here, we capture the context information for actions on the Restate context that
39
+ // are executed within other actions, such as
40
+ // ctx.oneWayCall( () => client.foo(bar) );
41
+ // we also use this information to ensure we check that only allowed operations are
42
+ // used. Within side-effects, no operations are allowed on the RestateContext.
43
+ // For example, this is illegal: 'ctx.sideEffect(() => {await ctx.get("my-state")})'
44
+ static callContext = new async_hooks_1.AsyncLocalStorage();
45
+ // This is used to guard users against calling ctx.sideEffect without awaiting it.
46
+ // See https://github.com/restatedev/sdk-typescript/issues/197 for more details.
47
+ executingSideEffect = false;
48
+ constructor(id, serviceName, console, keyedContext,
49
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
+ stateMachine, rand = new rand_1.RandImpl(id)) {
51
+ this.id = id;
52
+ this.serviceName = serviceName;
53
+ this.console = console;
54
+ this.keyedContext = keyedContext;
55
+ this.stateMachine = stateMachine;
56
+ this.rand = rand;
57
+ }
58
+ // DON'T make this function async!!! see sideEffect comment for details.
59
+ get(name) {
60
+ // Check if this is a valid action
61
+ this.checkState("get state");
62
+ this.checkStateOperation("get state");
63
+ // Create the message and let the state machine process it
64
+ const msg = protocol_1.GetStateEntryMessage.create({ key: Buffer.from(name) });
65
+ const completed = this.stateMachine.localStateStore.tryCompleteGet(name, msg);
66
+ const getState = async () => {
67
+ const result = await this.stateMachine.handleUserCodeMessage(protocol_2.GET_STATE_ENTRY_MESSAGE_TYPE, msg, completed);
68
+ // If the GetState message did not have a value or empty,
69
+ // then we went to the runtime to get the value.
70
+ // When we get the response, we set it in the localStateStore,
71
+ // to answer subsequent requests
72
+ if (!completed) {
73
+ this.stateMachine.localStateStore.add(name, result);
74
+ }
75
+ if (!(result instanceof Buffer)) {
76
+ return null;
77
+ }
78
+ return (0, utils_1.jsonDeserialize)(result.toString());
79
+ };
80
+ return getState();
81
+ }
82
+ // DON'T make this function async!!! see sideEffect comment for details.
83
+ stateKeys() {
84
+ // Check if this is a valid action
85
+ this.checkState("state keys");
86
+ // Create the message and let the state machine process it
87
+ const msg = protocol_1.GetStateKeysEntryMessage.create({});
88
+ const completed = this.stateMachine.localStateStore.tryCompletedGetStateKeys(msg);
89
+ const getStateKeys = async () => {
90
+ const result = await this.stateMachine.handleUserCodeMessage(protocol_2.GET_STATE_KEYS_ENTRY_MESSAGE_TYPE, msg, completed);
91
+ return result.keys.map((b) => b.toString());
92
+ };
93
+ return getStateKeys();
94
+ }
95
+ set(name, value) {
96
+ this.checkState("set state");
97
+ this.checkStateOperation("set state");
98
+ const msg = this.stateMachine.localStateStore.set(name, value);
99
+ this.stateMachine.handleUserCodeMessage(protocol_2.SET_STATE_ENTRY_MESSAGE_TYPE, msg);
100
+ }
101
+ clear(name) {
102
+ this.checkState("clear state");
103
+ this.checkStateOperation("clear state");
104
+ const msg = this.stateMachine.localStateStore.clear(name);
105
+ this.stateMachine.handleUserCodeMessage(protocol_2.CLEAR_STATE_ENTRY_MESSAGE_TYPE, msg);
106
+ }
107
+ clearAll() {
108
+ this.checkState("clear all state");
109
+ const msg = this.stateMachine.localStateStore.clearAll();
110
+ this.stateMachine.handleUserCodeMessage(protocol_2.CLEAR_ALL_STATE_ENTRY_MESSAGE_TYPE, msg);
111
+ }
112
+ // --- Calls, background calls, etc
113
+ request(service, method, data) {
114
+ if (this.isInOneWayCall()) {
115
+ return this.invokeOneWay(service, method, data, this.getOneWayCallDelay());
116
+ }
117
+ else {
118
+ return this.invoke(service, method, data);
119
+ }
120
+ }
121
+ // DON'T make this function async!!! see sideEffect comment for details.
122
+ invoke(service, method, data) {
123
+ this.checkState("invoke");
124
+ const msg = protocol_1.InvokeEntryMessage.create({
125
+ serviceName: service,
126
+ methodName: method,
127
+ parameter: Buffer.from(data),
128
+ });
129
+ return this.markCombineablePromise(this.stateMachine
130
+ .handleUserCodeMessage(protocol_2.INVOKE_ENTRY_MESSAGE_TYPE, msg)
131
+ .transform((v) => v));
132
+ }
133
+ async invokeOneWay(service, method, data, delay) {
134
+ const actualDelay = delay || 0;
135
+ const invokeTime = actualDelay > 0 ? Date.now() + actualDelay : undefined;
136
+ const msg = protocol_1.BackgroundInvokeEntryMessage.create({
137
+ serviceName: service,
138
+ methodName: method,
139
+ parameter: Buffer.from(data),
140
+ invokeTime: invokeTime,
141
+ });
142
+ await this.stateMachine.handleUserCodeMessage(protocol_2.BACKGROUND_INVOKE_ENTRY_MESSAGE_TYPE, msg);
143
+ return new Uint8Array();
144
+ }
145
+ // DON'T make this function async!!! see sideEffect comment for details.
146
+ oneWayCall(
147
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
148
+ call) {
149
+ this.checkState("oneWayCall");
150
+ return ContextImpl.callContext.run({ type: CallContexType.OneWayCall }, call);
151
+ }
152
+ // DON'T make this function async!!! see sideEffect comment for details.
153
+ delayedCall(
154
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
155
+ call, delayMillis) {
156
+ this.checkState("delayedCall");
157
+ // Delayed call is a one way call with a delay
158
+ return ContextImpl.callContext.run({ type: CallContexType.OneWayCall, delay: delayMillis }, call);
159
+ }
160
+ rpc({ path }) {
161
+ const clientProxy = new Proxy({}, {
162
+ get: (_target, prop) => {
163
+ const route = prop;
164
+ return async (...args) => {
165
+ const request = (0, assumptions_1.requestFromArgs)(args);
166
+ const requestBytes = dynrpc_1.RpcRequest.encode(request).finish();
167
+ return this.invoke(path, route, requestBytes).transform((responseBytes) => dynrpc_1.RpcResponse.decode(responseBytes).response);
168
+ };
169
+ },
170
+ });
171
+ return clientProxy;
172
+ }
173
+ send(options) {
174
+ return this.sendDelayed(options, 0);
175
+ }
176
+ sendDelayed({ path }, delayMillis) {
177
+ const clientProxy = new Proxy({}, {
178
+ get: (_target, prop) => {
179
+ const route = prop;
180
+ return (...args) => {
181
+ const request = (0, assumptions_1.requestFromArgs)(args);
182
+ const requestBytes = dynrpc_1.RpcRequest.encode(request).finish();
183
+ this.invokeOneWay(path, route, requestBytes, delayMillis);
184
+ };
185
+ },
186
+ });
187
+ return clientProxy;
188
+ }
189
+ // --- Methods exposed by respective interfaces to interact with other APIs
190
+ grpcChannel() {
191
+ return this;
192
+ }
193
+ // DON'T make this function async!!!
194
+ // The reason is that we want the erros thrown by the initial checks to be propagated in the caller context,
195
+ // and not in the promise context. To understand the semantic difference, make this function async and run the
196
+ // UnawaitedSideEffectShouldFailSubsequentContextCall test.
197
+ sideEffect(fn, retryPolicy = public_utils_1.DEFAULT_INFINITE_EXPONENTIAL_BACKOFF) {
198
+ if (this.isInSideEffect()) {
199
+ throw new errors_1.TerminalError("You cannot do sideEffect calls from within a side effect.", { errorCode: errors_1.ErrorCodes.INTERNAL });
200
+ }
201
+ else if (this.isInOneWayCall()) {
202
+ throw new errors_1.TerminalError("Cannot do a side effect from within ctx.oneWayCall(...). " +
203
+ "Context method ctx.oneWayCall() can only be used to invoke other services unidirectionally. " +
204
+ "e.g. ctx.oneWayCall(() => client.greet(my_request))", { errorCode: errors_1.ErrorCodes.INTERNAL });
205
+ }
206
+ this.checkNotExecutingSideEffect();
207
+ this.executingSideEffect = true;
208
+ const executeAndLogSideEffect = async () => {
209
+ // in replay mode, we directly return the value from the log
210
+ if (this.stateMachine.nextEntryWillBeReplayed()) {
211
+ const emptyMsg = javascript_1.SideEffectEntryMessage.create({});
212
+ return this.stateMachine.handleUserCodeMessage(protocol_2.SIDE_EFFECT_ENTRY_MESSAGE_TYPE, emptyMsg);
213
+ }
214
+ let sideEffectResult;
215
+ try {
216
+ sideEffectResult = await ContextImpl.callContext.run({ type: CallContexType.SideEffect }, fn);
217
+ }
218
+ catch (e) {
219
+ // we commit any error from the side effet to thr journal, and re-throw it into
220
+ // the function. that way, any catching by the user and reacting to it will be
221
+ // deterministic on replay
222
+ const error = (0, errors_1.ensureError)(e);
223
+ const failure = (0, errors_1.errorToFailureWithTerminal)(error);
224
+ const sideEffectMsg = javascript_1.SideEffectEntryMessage.create({
225
+ failure: failure,
226
+ });
227
+ // this may throw an error from the SDK/runtime/connection side, in case the
228
+ // failure message cannot be committed to the journal. That error would then
229
+ // be returned from this function (replace the original error)
230
+ // that is acceptable, because in such a situation (failure to append to journal),
231
+ // the state machine closes anyways and no further operations will succeed and the
232
+ // the execution aborts
233
+ await this.stateMachine.handleUserCodeMessage(protocol_2.SIDE_EFFECT_ENTRY_MESSAGE_TYPE, sideEffectMsg, false, undefined, true);
234
+ throw e;
235
+ }
236
+ // we have this code outside the above try/catch block, to ensure that any error arising
237
+ // from here is not incorrectly attributed to the side-effect
238
+ const sideEffectMsg = sideEffectResult !== undefined
239
+ ? javascript_1.SideEffectEntryMessage.create({
240
+ value: Buffer.from((0, utils_1.jsonSerialize)(sideEffectResult)),
241
+ })
242
+ : javascript_1.SideEffectEntryMessage.create();
243
+ // if an error arises from committing the side effect result, then this error will
244
+ // be thrown here (reject the returned promise) and the function will see that error,
245
+ // even if the side-effect function completed correctly
246
+ // that is acceptable, because in such a situation (failure to append to journal),
247
+ // the state machine closes anyways and reports an execution failure, meaning no further
248
+ // operations will succeed and the the execution will be retried.
249
+ // If the side-effect result did in fact not make it to the journal, then the side-effect
250
+ // re-executes, and if it made it to the journal after all (error happend inly during
251
+ // ack-back), then retries will use the journaled result.
252
+ // So all good in any case, due to the beauty of "the runtime log is the ground thruth" approach.
253
+ await this.stateMachine.handleUserCodeMessage(protocol_2.SIDE_EFFECT_ENTRY_MESSAGE_TYPE, sideEffectMsg, false, undefined, true);
254
+ return sideEffectResult;
255
+ };
256
+ const sleep = (millis) => this.sleepInternal(millis);
257
+ return executeWithRetries(this.console, retryPolicy, executeAndLogSideEffect, sleep).finally(() => {
258
+ this.executingSideEffect = false;
259
+ });
260
+ }
261
+ sleep(millis) {
262
+ this.checkState("sleep");
263
+ return this.markCombineablePromise(this.sleepInternal(millis));
264
+ }
265
+ sleepInternal(millis) {
266
+ return this.stateMachine.handleUserCodeMessage(protocol_2.SLEEP_ENTRY_MESSAGE_TYPE, protocol_1.SleepEntryMessage.create({ wakeUpTime: Date.now() + millis }));
267
+ }
268
+ // -- Awakeables
269
+ awakeable() {
270
+ this.checkState("awakeable");
271
+ const msg = protocol_1.AwakeableEntryMessage.create();
272
+ const promise = this.stateMachine
273
+ .handleUserCodeMessage(protocol_2.AWAKEABLE_ENTRY_MESSAGE_TYPE, msg)
274
+ .transform((result) => {
275
+ if (!(result instanceof Buffer)) {
276
+ // This should either be a filled buffer or an empty buffer but never anything else.
277
+ throw errors_1.RetryableError.internal("Awakeable was not resolved with a buffer payload");
278
+ }
279
+ return JSON.parse(result.toString());
280
+ });
281
+ // This needs to be done after handling the message in the state machine
282
+ // otherwise the index is not yet incremented.
283
+ const encodedEntryIndex = Buffer.alloc(4 /* Size of u32 */);
284
+ encodedEntryIndex.writeUInt32BE(this.stateMachine.getUserCodeJournalIndex());
285
+ return {
286
+ id: protocol_2.AWAKEABLE_IDENTIFIER_PREFIX +
287
+ Buffer.concat([this.id, encodedEntryIndex]).toString("base64url"),
288
+ promise: this.markCombineablePromise(promise),
289
+ };
290
+ }
291
+ resolveAwakeable(id, payload) {
292
+ // We coerce undefined to null as null can be stringified by JSON.stringify
293
+ const payloadToWrite = payload === undefined ? null : payload;
294
+ this.checkState("resolveAwakeable");
295
+ this.completeAwakeable(id, {
296
+ value: Buffer.from(JSON.stringify(payloadToWrite)),
297
+ });
298
+ }
299
+ rejectAwakeable(id, reason) {
300
+ this.checkState("rejectAwakeable");
301
+ this.completeAwakeable(id, {
302
+ failure: { code: errors_1.ErrorCodes.UNKNOWN, message: reason },
303
+ });
304
+ }
305
+ completeAwakeable(id, base) {
306
+ base.id = id;
307
+ this.stateMachine.handleUserCodeMessage(protocol_2.COMPLETE_AWAKEABLE_ENTRY_MESSAGE_TYPE, protocol_1.CompleteAwakeableEntryMessage.create(base));
308
+ }
309
+ // Used by static methods of CombineablePromise
310
+ createCombinator(combinatorConstructor, promises) {
311
+ const outPromises = [];
312
+ for (const promise of promises) {
313
+ if (promise.__restate_context !== this) {
314
+ throw errors_1.RetryableError.internal("You're mixing up CombineablePromises from different RestateContext. This is not supported.");
315
+ }
316
+ const index = promise
317
+ .journalIndex;
318
+ outPromises.push({
319
+ id: (0, promise_combinator_tracker_1.newJournalEntryPromiseId)(index),
320
+ promise: promise,
321
+ });
322
+ }
323
+ return this.stateMachine.createCombinator(combinatorConstructor, outPromises);
324
+ }
325
+ // -- Various private methods
326
+ isInSideEffect() {
327
+ const context = ContextImpl.callContext.getStore();
328
+ return context?.type === CallContexType.SideEffect;
329
+ }
330
+ isInOneWayCall() {
331
+ const context = ContextImpl.callContext.getStore();
332
+ return context?.type === CallContexType.OneWayCall;
333
+ }
334
+ getOneWayCallDelay() {
335
+ const context = ContextImpl.callContext.getStore();
336
+ return context?.delay;
337
+ }
338
+ checkNotExecutingSideEffect() {
339
+ if (this.executingSideEffect) {
340
+ throw new errors_1.TerminalError(`Invoked a RestateContext method while a side effect is still executing.
341
+ Make sure you await the ctx.sideEffect call before using any other RestateContext method.`, { errorCode: errors_1.ErrorCodes.INTERNAL });
342
+ }
343
+ }
344
+ checkState(callType) {
345
+ const context = ContextImpl.callContext.getStore();
346
+ if (!context) {
347
+ this.checkNotExecutingSideEffect();
348
+ return;
349
+ }
350
+ if (context.type === CallContexType.SideEffect) {
351
+ throw new errors_1.TerminalError(`You cannot do ${callType} calls from within a side effect.`, { errorCode: errors_1.ErrorCodes.INTERNAL });
352
+ }
353
+ if (context.type === CallContexType.OneWayCall) {
354
+ throw new errors_1.TerminalError(`Cannot do a ${callType} from within ctx.oneWayCall(...).
355
+ Context method oneWayCall() can only be used to invoke other services in the background.
356
+ e.g. ctx.oneWayCall(() => client.greet(my_request))`, { errorCode: errors_1.ErrorCodes.INTERNAL });
357
+ }
358
+ }
359
+ checkStateOperation(callType) {
360
+ if (!this.keyedContext) {
361
+ throw new errors_1.TerminalError(`You can do ${callType} calls only from keyed services/routers.`, { errorCode: errors_1.ErrorCodes.INTERNAL });
362
+ }
363
+ }
364
+ markCombineablePromise(p) {
365
+ const journalIndex = this.stateMachine.getUserCodeJournalIndex();
366
+ const orTimeout = (millis) => {
367
+ const sleepPromise = this.sleepInternal(millis).transform(() => {
368
+ throw new errors_1.TimeoutError();
369
+ });
370
+ const sleepPromiseIndex = this.stateMachine.getUserCodeJournalIndex();
371
+ return this.stateMachine.createCombinator(Promise.race.bind(Promise), [
372
+ {
373
+ id: (0, promise_combinator_tracker_1.newJournalEntryPromiseId)(journalIndex),
374
+ promise: p,
375
+ },
376
+ {
377
+ id: (0, promise_combinator_tracker_1.newJournalEntryPromiseId)(sleepPromiseIndex),
378
+ promise: sleepPromise,
379
+ },
380
+ ]);
381
+ };
382
+ return Object.defineProperties(p, {
383
+ __restate_context: {
384
+ value: this,
385
+ },
386
+ journalIndex: {
387
+ value: journalIndex,
388
+ },
389
+ orTimeout: {
390
+ value: orTimeout.bind(this),
391
+ },
392
+ });
393
+ }
394
+ }
395
+ exports.ContextImpl = ContextImpl;
396
+ async function executeWithRetries(console, retrySettings, executeAndLogSideEffect, sleep) {
397
+ const { initialDelayMs = public_utils_1.DEFAULT_INITIAL_DELAY_MS, maxDelayMs = Number.MAX_SAFE_INTEGER, maxRetries = Number.MAX_SAFE_INTEGER, policy = public_utils_1.EXPONENTIAL_BACKOFF, name = "side-effect", } = retrySettings;
398
+ let currentDelayMs = initialDelayMs;
399
+ let retriesLeft = maxRetries;
400
+ // eslint-disable-next-line no-constant-condition
401
+ while (true) {
402
+ try {
403
+ return await executeAndLogSideEffect();
404
+ }
405
+ catch (e) {
406
+ if (e instanceof errors_1.TerminalError) {
407
+ throw e;
408
+ }
409
+ // journal mismatch errors are special:
410
+ // - they are not terminal errors, because we want to allow pushing new code so
411
+ // that retries succeed later
412
+ // - they are not retried within the service, because they will never succeed within this service,
413
+ // but can only succeed within a new invocation going to service with fixed code
414
+ // we hence break the retries here similar to terminal errors
415
+ if (e instanceof errors_1.RestateError &&
416
+ e.code == errors_1.RestateErrorCodes.JOURNAL_MISMATCH) {
417
+ throw e;
418
+ }
419
+ const error = (0, errors_1.ensureError)(e);
420
+ console.debug("Error while executing side effect '%s': %s - %s", name, error.name, error.message);
421
+ if (error.stack) {
422
+ console.debug(error.stack);
423
+ }
424
+ if (retriesLeft > 0) {
425
+ console.debug("Retrying in %d ms", currentDelayMs);
426
+ }
427
+ else {
428
+ console.debug("No retries left.");
429
+ throw new errors_1.TerminalError(`Retries exhausted for ${name}. Last error: ${error.name}: ${error.message}`, {
430
+ errorCode: errors_1.ErrorCodes.INTERNAL,
431
+ });
432
+ }
433
+ }
434
+ await sleep(currentDelayMs);
435
+ retriesLeft -= 1;
436
+ currentDelayMs = Math.min(policy.computeNextDelay(currentDelayMs), maxDelayMs);
437
+ }
438
+ }
439
+ //# sourceMappingURL=context_impl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context_impl.js","sourceRoot":"","sources":["../src/context_impl.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAUH,yDAUoC;AACpC,+CAa0B;AAC1B,6DAAsE;AACtE,6CAAgD;AAChD,2CASwB;AACxB,yCAA+D;AAE/D,uDAK8B;AAE9B,qDAAmE;AACnE,qDAAsD;AACtD,uCAAwC;AACxC,6EAAwE;AAGxE,IAAY,cAIX;AAJD,WAAY,cAAc;IACxB,mDAAI,CAAA;IACJ,+DAAU,CAAA;IACV,+DAAU,CAAA;AACZ,CAAC,EAJW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAIzB;AAYD,MAAa,WAAW;IAcJ;IACA;IACA;IACA;IAEC;IACD;IAnBlB,mFAAmF;IACnF,6CAA6C;IAC7C,2CAA2C;IAC3C,mFAAmF;IACnF,8EAA8E;IAC9E,oFAAoF;IACpF,MAAM,CAAC,WAAW,GAAG,IAAI,+BAAiB,EAAe,CAAC;IAE1D,kFAAkF;IAClF,gFAAgF;IACxE,mBAAmB,GAAG,KAAK,CAAC;IAEpC,YACkB,EAAU,EACV,WAAmB,EACnB,OAA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AAC,GAAG,CACvB,MAAM,CAAC,gBAAgB,CAAC,cAAc,CAAC,EACvC,UAAU,CACX,CAAC;KACH;AACH,CAAC"}
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { RpcContext } from "../restate_context";
2
+ import { Context } from "../context";
3
3
  import { RemoteContext } from "../generated/proto/services";
4
4
  import { OutgoingHttpHeaders } from "http";
5
5
  export type RestateConnectionOptions = {
@@ -22,6 +22,6 @@ export declare const connection: (address: string, opt?: RestateConnectionOption
22
22
  export declare class RestateConnection {
23
23
  private readonly remote;
24
24
  constructor(remote: RemoteContext);
25
- invoke<I, O>(id: string, input: I, handler: (ctx: RpcContext, input: I) => Promise<O>, opt?: RestateInvocationOptions): Promise<O>;
25
+ invoke<I, O>(id: string, input: I, handler: (ctx: Context, input: I) => Promise<O>, opt?: RestateInvocationOptions): Promise<O>;
26
26
  }
27
27
  //# sourceMappingURL=api.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/embedded/api.ts"],"names":[],"mappings":";AAWA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIhD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,MAAM,CAAC;AAE3C,MAAM,MAAM,wBAAwB,GAAG;IACrC;;OAEG;IACH,OAAO,EAAE,mBAAmB,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,UAAU,YACZ,MAAM,QACT,wBAAwB,KAC7B,iBAC2D,CAAC;AAE/D,qBAAa,iBAAiB;IAChB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,aAAa;IAE3C,MAAM,CAAC,CAAC,EAAE,CAAC,EAChB,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EAClD,GAAG,CAAC,EAAE,wBAAwB,GAC7B,OAAO,CAAC,CAAC,CAAC;CAKd"}
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/embedded/api.ts"],"names":[],"mappings":";AAWA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAIrC,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,MAAM,CAAC;AAE3C,MAAM,MAAM,wBAAwB,GAAG;IACrC;;OAEG;IACH,OAAO,EAAE,mBAAmB,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,UAAU,YACZ,MAAM,QACT,wBAAwB,KAC7B,iBAC2D,CAAC;AAE/D,qBAAa,iBAAiB;IAChB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,aAAa;IAE3C,MAAM,CAAC,CAAC,EAAE,CAAC,EAChB,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EAC/C,GAAG,CAAC,EAAE,wBAAwB,GAC7B,OAAO,CAAC,CAAC,CAAC;CAKd"}
@@ -0,0 +1,35 @@
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.RestateConnection = exports.connection = void 0;
17
+ const invocation_1 = require("./invocation");
18
+ const handler_1 = require("./handler");
19
+ const crypto_1 = __importDefault(require("crypto"));
20
+ const http2_remote_1 = require("./http2_remote");
21
+ const connection = (address, opt) => new RestateConnection((0, http2_remote_1.bufConnectRemoteContext)(address, opt));
22
+ exports.connection = connection;
23
+ class RestateConnection {
24
+ remote;
25
+ constructor(remote) {
26
+ this.remote = remote;
27
+ }
28
+ invoke(id, input, handler, opt) {
29
+ const method = (0, handler_1.wrapHandler)(handler);
30
+ const streamId = crypto_1.default.randomUUID();
31
+ return (0, invocation_1.doInvoke)(this.remote, id, streamId, input, method, opt);
32
+ }
33
+ }
34
+ exports.RestateConnection = RestateConnection;
35
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/embedded/api.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;AAGH,6CAAwC;AACxC,uCAAwC;AACxC,oDAA4B;AAE5B,iDAAyD;AAqBlD,MAAM,UAAU,GAAG,CACxB,OAAe,EACf,GAA8B,EACX,EAAE,CACrB,IAAI,iBAAiB,CAAC,IAAA,sCAAuB,EAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;AAJlD,QAAA,UAAU,cAIwC;AAE/D,MAAa,iBAAiB;IACC;IAA7B,YAA6B,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IAE/C,MAAM,CACX,EAAU,EACV,KAAQ,EACR,OAA+C,EAC/C,GAA8B;QAE9B,MAAM,MAAM,GAAG,IAAA,qBAAW,EAAC,OAAO,CAAC,CAAC;QACpC,MAAM,QAAQ,GAAG,gBAAM,CAAC,UAAU,EAAE,CAAC;QACrC,OAAO,IAAA,qBAAQ,EAAO,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IACvE,CAAC;CACF;AAbD,8CAaC"}
@@ -1,4 +1,4 @@
1
- import { RpcContext } from "../restate_context";
1
+ import { Context } from "../context";
2
2
  import { HostedGrpcServiceMethod } from "../types/grpc";
3
- export declare function wrapHandler<I, O>(handler: (ctx: RpcContext, input: I) => Promise<O>): HostedGrpcServiceMethod<I, O>;
3
+ export declare function wrapHandler<I, O>(handler: (ctx: Context, input: I) => Promise<O>): HostedGrpcServiceMethod<I, O>;
4
4
  //# sourceMappingURL=handler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/embedded/handler.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,UAAU,EAAc,MAAM,oBAAoB,CAAC;AAE5D,OAAO,EAAqB,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAE3E,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAC9B,OAAO,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GACjD,uBAAuB,CAAC,CAAC,EAAE,CAAC,CAAC,CAmB/B"}
1
+ {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/embedded/handler.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,OAAO,EAAc,MAAM,YAAY,CAAC;AACjD,OAAO,EAAqB,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAE3E,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAC9B,OAAO,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAC9C,uBAAuB,CAAC,CAAC,EAAE,CAAC,CAAC,CAmB/B"}