@restatedev/restate-sdk 1.7.2 → 1.8.0

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 (180) hide show
  1. package/README.md +4 -3
  2. package/dist/cjs/src/common_api.d.ts +3 -2
  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 +66 -47
  7. package/dist/cjs/src/context.d.ts.map +1 -1
  8. package/dist/cjs/src/context.js.map +1 -1
  9. package/dist/cjs/src/context_impl.d.ts +3 -1
  10. package/dist/cjs/src/context_impl.d.ts.map +1 -1
  11. package/dist/cjs/src/context_impl.js +12 -2
  12. package/dist/cjs/src/context_impl.js.map +1 -1
  13. package/dist/cjs/src/{types → endpoint}/components.d.ts +3 -2
  14. package/dist/cjs/src/endpoint/components.d.ts.map +1 -0
  15. package/dist/cjs/src/{types → endpoint}/components.js +1 -1
  16. package/dist/cjs/src/endpoint/components.js.map +1 -0
  17. package/dist/cjs/src/endpoint/discovery.d.ts.map +1 -0
  18. package/dist/cjs/src/endpoint/discovery.js.map +1 -0
  19. package/dist/cjs/src/endpoint/endpoint.d.ts +33 -0
  20. package/dist/cjs/src/endpoint/endpoint.d.ts.map +1 -0
  21. package/dist/cjs/src/endpoint/endpoint.js +152 -0
  22. package/dist/cjs/src/endpoint/endpoint.js.map +1 -0
  23. package/dist/cjs/src/endpoint/fetch_endpoint.d.ts +3 -6
  24. package/dist/cjs/src/endpoint/fetch_endpoint.d.ts.map +1 -1
  25. package/dist/cjs/src/endpoint/fetch_endpoint.js +8 -13
  26. package/dist/cjs/src/endpoint/fetch_endpoint.js.map +1 -1
  27. package/dist/cjs/src/endpoint/handlers/generic.d.ts +4 -4
  28. package/dist/cjs/src/endpoint/handlers/generic.d.ts.map +1 -1
  29. package/dist/cjs/src/endpoint/handlers/generic.js +18 -9
  30. package/dist/cjs/src/endpoint/handlers/generic.js.map +1 -1
  31. package/dist/cjs/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.d.ts +16 -0
  32. package/dist/cjs/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.d.ts.map +1 -1
  33. package/dist/cjs/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js +40 -1
  34. package/dist/cjs/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js.map +1 -1
  35. package/dist/cjs/src/endpoint/lambda_endpoint.d.ts +2 -5
  36. package/dist/cjs/src/endpoint/lambda_endpoint.d.ts.map +1 -1
  37. package/dist/cjs/src/endpoint/lambda_endpoint.js +8 -13
  38. package/dist/cjs/src/endpoint/lambda_endpoint.js.map +1 -1
  39. package/dist/cjs/src/endpoint/node_endpoint.d.ts +2 -5
  40. package/dist/cjs/src/endpoint/node_endpoint.d.ts.map +1 -1
  41. package/dist/cjs/src/endpoint/node_endpoint.js +55 -63
  42. package/dist/cjs/src/endpoint/node_endpoint.js.map +1 -1
  43. package/dist/cjs/src/endpoint/types.d.ts +48 -0
  44. package/dist/cjs/src/endpoint/types.d.ts.map +1 -0
  45. package/dist/cjs/src/endpoint/types.js +3 -0
  46. package/dist/cjs/src/endpoint/types.js.map +1 -0
  47. package/dist/cjs/src/endpoint/withOptions.d.ts +4 -0
  48. package/dist/cjs/src/endpoint/withOptions.d.ts.map +1 -0
  49. package/dist/cjs/src/endpoint/withOptions.js +19 -0
  50. package/dist/cjs/src/endpoint/withOptions.js.map +1 -0
  51. package/dist/cjs/src/endpoint.d.ts +23 -22
  52. package/dist/cjs/src/endpoint.d.ts.map +1 -1
  53. package/dist/cjs/src/fetch.d.ts +34 -0
  54. package/dist/cjs/src/fetch.d.ts.map +1 -1
  55. package/dist/cjs/src/fetch.js +26 -0
  56. package/dist/cjs/src/fetch.js.map +1 -1
  57. package/dist/cjs/src/generated/version.d.ts +1 -1
  58. package/dist/cjs/src/generated/version.js +1 -1
  59. package/dist/cjs/src/lambda.d.ts +16 -1
  60. package/dist/cjs/src/lambda.d.ts.map +1 -1
  61. package/dist/cjs/src/lambda.js +19 -1
  62. package/dist/cjs/src/lambda.js.map +1 -1
  63. package/dist/cjs/src/node.d.ts +38 -0
  64. package/dist/cjs/src/node.d.ts.map +1 -0
  65. package/dist/cjs/src/node.js +70 -0
  66. package/dist/cjs/src/node.js.map +1 -0
  67. package/dist/cjs/src/public_api.d.ts +1 -6
  68. package/dist/cjs/src/public_api.d.ts.map +1 -1
  69. package/dist/cjs/src/public_api.js +1 -9
  70. package/dist/cjs/src/public_api.js.map +1 -1
  71. package/dist/cjs/src/types/errors.d.ts +43 -1
  72. package/dist/cjs/src/types/errors.d.ts.map +1 -1
  73. package/dist/cjs/src/types/errors.js +52 -5
  74. package/dist/cjs/src/types/errors.js.map +1 -1
  75. package/dist/cjs/src/types/rpc.d.ts +57 -19
  76. package/dist/cjs/src/types/rpc.d.ts.map +1 -1
  77. package/dist/cjs/src/types/rpc.js +24 -22
  78. package/dist/cjs/src/types/rpc.js.map +1 -1
  79. package/dist/cjs/src/user_agent.d.ts +1 -1
  80. package/dist/cjs/tsconfig.tsbuildinfo +1 -1
  81. package/dist/esm/src/common_api.d.ts +3 -2
  82. package/dist/esm/src/common_api.d.ts.map +1 -1
  83. package/dist/esm/src/common_api.js +1 -1
  84. package/dist/esm/src/common_api.js.map +1 -1
  85. package/dist/esm/src/context.d.ts +66 -47
  86. package/dist/esm/src/context.d.ts.map +1 -1
  87. package/dist/esm/src/context.js.map +1 -1
  88. package/dist/esm/src/context_impl.d.ts +3 -1
  89. package/dist/esm/src/context_impl.d.ts.map +1 -1
  90. package/dist/esm/src/context_impl.js +13 -3
  91. package/dist/esm/src/context_impl.js.map +1 -1
  92. package/dist/esm/src/{types → endpoint}/components.d.ts +3 -2
  93. package/dist/esm/src/endpoint/components.d.ts.map +1 -0
  94. package/dist/esm/src/{types → endpoint}/components.js +1 -1
  95. package/dist/esm/src/endpoint/components.js.map +1 -0
  96. package/dist/esm/src/endpoint/discovery.d.ts.map +1 -0
  97. package/dist/esm/src/endpoint/discovery.js.map +1 -0
  98. package/dist/esm/src/endpoint/endpoint.d.ts +33 -0
  99. package/dist/esm/src/endpoint/endpoint.d.ts.map +1 -0
  100. package/dist/esm/src/endpoint/endpoint.js +148 -0
  101. package/dist/esm/src/endpoint/endpoint.js.map +1 -0
  102. package/dist/esm/src/endpoint/fetch_endpoint.d.ts +3 -6
  103. package/dist/esm/src/endpoint/fetch_endpoint.d.ts.map +1 -1
  104. package/dist/esm/src/endpoint/fetch_endpoint.js +7 -12
  105. package/dist/esm/src/endpoint/fetch_endpoint.js.map +1 -1
  106. package/dist/esm/src/endpoint/handlers/generic.d.ts +4 -4
  107. package/dist/esm/src/endpoint/handlers/generic.d.ts.map +1 -1
  108. package/dist/esm/src/endpoint/handlers/generic.js +19 -10
  109. package/dist/esm/src/endpoint/handlers/generic.js.map +1 -1
  110. package/dist/esm/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.d.ts +16 -0
  111. package/dist/esm/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.d.ts.map +1 -1
  112. package/dist/esm/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js +40 -1
  113. package/dist/esm/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js.map +1 -1
  114. package/dist/esm/src/endpoint/lambda_endpoint.d.ts +2 -5
  115. package/dist/esm/src/endpoint/lambda_endpoint.d.ts.map +1 -1
  116. package/dist/esm/src/endpoint/lambda_endpoint.js +7 -12
  117. package/dist/esm/src/endpoint/lambda_endpoint.js.map +1 -1
  118. package/dist/esm/src/endpoint/node_endpoint.d.ts +2 -5
  119. package/dist/esm/src/endpoint/node_endpoint.d.ts.map +1 -1
  120. package/dist/esm/src/endpoint/node_endpoint.js +54 -62
  121. package/dist/esm/src/endpoint/node_endpoint.js.map +1 -1
  122. package/dist/esm/src/endpoint/types.d.ts +48 -0
  123. package/dist/esm/src/endpoint/types.d.ts.map +1 -0
  124. package/dist/esm/src/endpoint/types.js +2 -0
  125. package/dist/esm/src/endpoint/types.js.map +1 -0
  126. package/dist/esm/src/endpoint/withOptions.d.ts +4 -0
  127. package/dist/esm/src/endpoint/withOptions.d.ts.map +1 -0
  128. package/dist/esm/src/endpoint/withOptions.js +16 -0
  129. package/dist/esm/src/endpoint/withOptions.js.map +1 -0
  130. package/dist/esm/src/endpoint.d.ts +23 -22
  131. package/dist/esm/src/endpoint.d.ts.map +1 -1
  132. package/dist/esm/src/fetch.d.ts +34 -0
  133. package/dist/esm/src/fetch.d.ts.map +1 -1
  134. package/dist/esm/src/fetch.js +25 -0
  135. package/dist/esm/src/fetch.js.map +1 -1
  136. package/dist/esm/src/generated/version.d.ts +1 -1
  137. package/dist/esm/src/generated/version.js +1 -1
  138. package/dist/esm/src/lambda.d.ts +16 -1
  139. package/dist/esm/src/lambda.d.ts.map +1 -1
  140. package/dist/esm/src/lambda.js +18 -1
  141. package/dist/esm/src/lambda.js.map +1 -1
  142. package/dist/esm/src/node.d.ts +38 -0
  143. package/dist/esm/src/node.d.ts.map +1 -0
  144. package/dist/esm/src/node.js +51 -0
  145. package/dist/esm/src/node.js.map +1 -0
  146. package/dist/esm/src/public_api.d.ts +1 -6
  147. package/dist/esm/src/public_api.d.ts.map +1 -1
  148. package/dist/esm/src/public_api.js +1 -8
  149. package/dist/esm/src/public_api.js.map +1 -1
  150. package/dist/esm/src/types/errors.d.ts +43 -1
  151. package/dist/esm/src/types/errors.d.ts.map +1 -1
  152. package/dist/esm/src/types/errors.js +50 -4
  153. package/dist/esm/src/types/errors.js.map +1 -1
  154. package/dist/esm/src/types/rpc.d.ts +57 -19
  155. package/dist/esm/src/types/rpc.d.ts.map +1 -1
  156. package/dist/esm/src/types/rpc.js +25 -23
  157. package/dist/esm/src/types/rpc.js.map +1 -1
  158. package/dist/esm/src/user_agent.d.ts +1 -1
  159. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  160. package/package.json +15 -2
  161. package/dist/cjs/src/endpoint/endpoint_builder.d.ts +0 -26
  162. package/dist/cjs/src/endpoint/endpoint_builder.d.ts.map +0 -1
  163. package/dist/cjs/src/endpoint/endpoint_builder.js +0 -143
  164. package/dist/cjs/src/endpoint/endpoint_builder.js.map +0 -1
  165. package/dist/cjs/src/types/components.d.ts.map +0 -1
  166. package/dist/cjs/src/types/components.js.map +0 -1
  167. package/dist/cjs/src/types/discovery.d.ts.map +0 -1
  168. package/dist/cjs/src/types/discovery.js.map +0 -1
  169. package/dist/esm/src/endpoint/endpoint_builder.d.ts +0 -26
  170. package/dist/esm/src/endpoint/endpoint_builder.d.ts.map +0 -1
  171. package/dist/esm/src/endpoint/endpoint_builder.js +0 -139
  172. package/dist/esm/src/endpoint/endpoint_builder.js.map +0 -1
  173. package/dist/esm/src/types/components.d.ts.map +0 -1
  174. package/dist/esm/src/types/components.js.map +0 -1
  175. package/dist/esm/src/types/discovery.d.ts.map +0 -1
  176. package/dist/esm/src/types/discovery.js.map +0 -1
  177. /package/dist/cjs/src/{types → endpoint}/discovery.d.ts +0 -0
  178. /package/dist/cjs/src/{types → endpoint}/discovery.js +0 -0
  179. /package/dist/esm/src/{types → endpoint}/discovery.d.ts +0 -0
  180. /package/dist/esm/src/{types → endpoint}/discovery.js +0 -0
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withOptions = withOptions;
4
+ function withOptions(endpoint, { identityKeys, defaultServiceOptions, logger, services }) {
5
+ let endpointWithOptions = endpoint;
6
+ if (identityKeys && identityKeys.length > 0) {
7
+ endpointWithOptions = endpointWithOptions.withIdentityV1(...identityKeys);
8
+ }
9
+ if (defaultServiceOptions) {
10
+ endpointWithOptions = endpointWithOptions.defaultServiceOptions(defaultServiceOptions);
11
+ }
12
+ if (logger) {
13
+ endpointWithOptions = endpointWithOptions.setLogger(logger);
14
+ }
15
+ return services.reduce((results, service) => {
16
+ return results.bind(service);
17
+ }, endpointWithOptions);
18
+ }
19
+ //# sourceMappingURL=withOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withOptions.js","sourceRoot":"","sources":["../../../../src/endpoint/withOptions.ts"],"names":[],"mappings":";;AAGA,kCAoBC;AApBD,SAAgB,WAAW,CACzB,QAAW,EACX,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,EAAE,QAAQ,EAAmB;IAE1E,IAAI,mBAAmB,GAAG,QAAQ,CAAC;IACnC,IAAI,YAAY,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5C,mBAAmB,GAAG,mBAAmB,CAAC,cAAc,CAAC,GAAG,YAAY,CAAC,CAAC;IAC5E,CAAC;IACD,IAAI,qBAAqB,EAAE,CAAC;QAC1B,mBAAmB,GAAG,mBAAmB,CAAC,qBAAqB,CAC7D,qBAAqB,CACtB,CAAC;IACJ,CAAC;IACD,IAAI,MAAM,EAAE,CAAC;QACX,mBAAmB,GAAG,mBAAmB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;QAC1C,OAAO,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC,EAAE,mBAAmB,CAAC,CAAC;AAC1B,CAAC"}
@@ -1,6 +1,8 @@
1
1
  import type { Http2ServerRequest, Http2ServerResponse } from "http2";
2
2
  import type { VirtualObjectDefinition, ServiceDefinition, WorkflowDefinition } from "@restatedev/restate-sdk-core";
3
3
  import type { LoggerTransport } from "./logging/logger_transport.js";
4
+ import type { ObjectOptions, ServiceOptions, WorkflowOptions } from "./types/rpc.js";
5
+ export type DefaultServiceOptions = ServiceOptions & ObjectOptions & WorkflowOptions;
4
6
  export interface RestateEndpointBase<E> {
5
7
  /**
6
8
  * Binds a new durable service / virtual object / workflow.
@@ -18,34 +20,43 @@ export interface RestateEndpointBase<E> {
18
20
  *
19
21
  */
20
22
  withIdentityV1(...keys: string[]): E;
23
+ /**
24
+ * Set default service options that will be used by all services bind to this endpoint.
25
+ *
26
+ * Options can be overridden on each service/handler.
27
+ *
28
+ * @param options
29
+ */
30
+ defaultServiceOptions(options: DefaultServiceOptions): E;
21
31
  /**
22
32
  * Replace the default console-based {@link LoggerTransport}
23
33
  * @param logger
24
34
  * @example
25
35
  * Using console:
26
36
  * ```ts
27
- * restate.setLogger((meta, message, ...o) => {console.log(`${meta.level}: `, message, ...o)})
28
- * ```
37
+ * restate.setLogger((meta, message, ...o) => {console.log(`${meta.level}: `, message, ...o)})
38
+ * ```
29
39
  * @example
30
40
  * Using winston:
31
41
  * ```ts
32
- * const logger = createLogger({ ... })
33
- * restate.setLogger((meta, message, ...o) => {logger.log(meta.level, {invocationId: meta.context?.invocationId}, [message, ...o].join(' '))})
34
- * ```
42
+ * const logger = createLogger({ ... })
43
+ * restate.setLogger((meta, message, ...o) => {logger.log(meta.level, {invocationId: meta.context?.invocationId}, [message, ...o].join(' '))})
44
+ * ```
35
45
  * @example
36
46
  * Using pino:
37
47
  * ```ts
38
- * const logger = pino()
39
- * restate.setLogger((meta, message, ...o) => {logger[meta.level]({invocationId: meta.context?.invocationId}, [message, ...o].join(' '))})
40
- * ```
48
+ * const logger = pino()
49
+ * restate.setLogger((meta, message, ...o) => {logger[meta.level]({invocationId: meta.context?.invocationId}, [message, ...o].join(' '))})
50
+ * ```
41
51
  */
42
52
  setLogger(logger: LoggerTransport): E;
43
53
  }
44
54
  /**
45
55
  * RestateEndpoint encapsulates all the Restate services served by this endpoint.
46
56
  *
47
- * A RestateEndpoint can either be served either as HTTP2 server, using the methods {@link listen} or {@link http2Handler},
48
- * or as Lambda, using the method {@link lambdaHandler}.
57
+ * A RestateEndpoint can either be served as HTTP2 server, using the methods {@link RestateEndpoint.listen} or {@link RestateEndpoint.http2Handler}.
58
+ *
59
+ * For Lambda, check {@link LambdaEndpoint}
49
60
  *
50
61
  * @example
51
62
  * A typical endpoint served as HTTP server would look like this:
@@ -57,16 +68,6 @@ export interface RestateEndpointBase<E> {
57
68
  * .bind(myService)
58
69
  * .listen(8000);
59
70
  * ```
60
- * @example
61
- * A typical endpoint served as AWS Lambda would look like this:
62
- * ```
63
- * import * as restate from "@restatedev/restate-sdk/lambda";
64
- *
65
- * export const handler = restate
66
- * .endpoint()
67
- * .bind(myService)
68
- * .handler();
69
- * ```
70
71
  */
71
72
  export interface RestateEndpoint extends RestateEndpointBase<RestateEndpoint> {
72
73
  /**
@@ -86,14 +87,14 @@ export interface RestateEndpoint extends RestateEndpointBase<RestateEndpoint> {
86
87
  * httpServer.listen(port);
87
88
  * ```
88
89
  *
89
- * If you need to manually control the server lifecycle, we suggest to manually instantiate the http2 server and use {@link http2Handler}.
90
+ * If you need to manually control the server lifecycle, we suggest to manually instantiate the http2 server and use {@link RestateEndpoint.http2Handler}.
90
91
  *
91
92
  * @param port The port to listen at. May be undefined (see above).
92
93
  * @returns a Promise that resolves with the bound port, or rejects with a failure otherwise.
93
94
  */
94
95
  listen(port?: number): Promise<number>;
95
96
  /**
96
- * Returns an http2 server handler. See {@link listen} for more details.
97
+ * Returns an http2 server handler. See {@link RestateEndpoint.listen} for more details.
97
98
  */
98
99
  http2Handler(): (request: Http2ServerRequest, response: Http2ServerResponse) => void;
99
100
  }
@@ -1 +1 @@
1
- {"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../../../src/endpoint.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC;AACrE,OAAO,KAAK,EACV,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAErE,MAAM,WAAW,mBAAmB,CAAC,CAAC;IACpC;;;;QAII;IACJ,IAAI,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EACtB,OAAO,EACH,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,GACvB,uBAAuB,CAAC,CAAC,EAAE,CAAC,CAAC,GAC7B,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,GAC3B,CAAC,CAAC;IAEL;;;;;;;;OAQG;IACH,cAAc,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IAErC;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,CAAC,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,WAAW,eAAgB,SAAQ,mBAAmB,CAAC,eAAe,CAAC;IAC3E;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEvC;;OAEG;IACH,YAAY,IAAI,CACd,OAAO,EAAE,kBAAkB,EAC3B,QAAQ,EAAE,mBAAmB,KAC1B,IAAI,CAAC;CACX"}
1
+ {"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../../../src/endpoint.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC;AACrE,OAAO,KAAK,EACV,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,eAAe,EAChB,MAAM,gBAAgB,CAAC;AAExB,MAAM,MAAM,qBAAqB,GAAG,cAAc,GAChD,aAAa,GACb,eAAe,CAAC;AAElB,MAAM,WAAW,mBAAmB,CAAC,CAAC;IACpC;;;;QAII;IACJ,IAAI,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EACtB,OAAO,EACH,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,GACvB,uBAAuB,CAAC,CAAC,EAAE,CAAC,CAAC,GAC7B,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,GAC3B,CAAC,CAAC;IAEL;;;;;;;;OAQG;IACH,cAAc,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IAErC;;;;;;OAMG;IACH,qBAAqB,CAAC,OAAO,EAAE,qBAAqB,GAAG,CAAC,CAAC;IAEzD;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,CAAC,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,eAAgB,SAAQ,mBAAmB,CAAC,eAAe,CAAC;IAC3E;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEvC;;OAEG;IACH,YAAY,IAAI,CACd,OAAO,EAAE,kBAAkB,EAC3B,QAAQ,EAAE,mBAAmB,KAC1B,IAAI,CAAC;CACX"}
@@ -1,8 +1,42 @@
1
1
  export * from "./common_api.js";
2
2
  import { type FetchEndpoint } from "./endpoint/fetch_endpoint.js";
3
+ import type { EndpointOptions } from "./endpoint/types.js";
3
4
  /**
4
5
  * Create a new {@link RestateEndpoint} in request response protocol mode.
5
6
  * Bidirectional mode (must be served over http2) can be enabled with .enableHttp2()
6
7
  */
7
8
  export declare function endpoint(): FetchEndpoint;
9
+ interface FetchEndpointOptions extends EndpointOptions {
10
+ /**
11
+ * Enables bidirectional communication for the handler.
12
+ *
13
+ * When set to `true`, the handler supports bidirectional streaming (e.g., via HTTP/2 or compatible HTTP/1.1 servers).
14
+ * When `false`, the handler operates in request-response mode only.
15
+ *
16
+ * @default false
17
+ */
18
+ bidirectional?: boolean;
19
+ }
20
+ /**
21
+ * Creates a Fetch handler that encapsulates all the Restate services served by this endpoint.
22
+ *
23
+ * @param {FetchEndpointOptions} options - Configuration options for the endpoint handler.
24
+ * @returns A fetch handler function.
25
+ *
26
+ * @example
27
+ * A typical request-response handler would look like this:
28
+ * ```
29
+ * import { createEndpointHandler } from "@restatedev/restate-sdk/fetch";
30
+ *
31
+ * export const handler = createEndpointHandler({ services: [myService] })
32
+ *
33
+ * @example
34
+ * A typical bidirectional handler (works with http2 and some http1.1 servers) would look like this:
35
+ * ```
36
+ * import { createEndpointHandler } from "@restatedev/restate-sdk/fetch";
37
+ *
38
+ * export const handler = createEndpointHandler({ services: [myService], bidirectional: true })
39
+ *
40
+ */
41
+ export declare function createEndpointHandler(options: FetchEndpointOptions): (request: Request, ...extraArgs: unknown[]) => Promise<Response>;
8
42
  //# sourceMappingURL=fetch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../src/fetch.ts"],"names":[],"mappings":"AAWA,cAAc,iBAAiB,CAAC;AAEhC,OAAO,EACL,KAAK,aAAa,EAEnB,MAAM,8BAA8B,CAAC;AAEtC;;;GAGG;AACH,wBAAgB,QAAQ,IAAI,aAAa,CAExC"}
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../src/fetch.ts"],"names":[],"mappings":"AAWA,cAAc,iBAAiB,CAAC;AAEhC,OAAO,EACL,KAAK,aAAa,EAEnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG3D;;;GAGG;AACH,wBAAgB,QAAQ,IAAI,aAAa,CAExC;AAED,UAAU,oBAAqB,SAAQ,eAAe;IACpD;;;;;;;OAOG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,oBAAoB,oEAOlE"}
@@ -25,8 +25,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
25
25
  };
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
27
  exports.endpoint = endpoint;
28
+ exports.createEndpointHandler = createEndpointHandler;
28
29
  __exportStar(require("./common_api.js"), exports);
29
30
  const fetch_endpoint_js_1 = require("./endpoint/fetch_endpoint.js");
31
+ const withOptions_js_1 = require("./endpoint/withOptions.js");
30
32
  /**
31
33
  * Create a new {@link RestateEndpoint} in request response protocol mode.
32
34
  * Bidirectional mode (must be served over http2) can be enabled with .enableHttp2()
@@ -34,4 +36,28 @@ const fetch_endpoint_js_1 = require("./endpoint/fetch_endpoint.js");
34
36
  function endpoint() {
35
37
  return new fetch_endpoint_js_1.FetchEndpointImpl("REQUEST_RESPONSE");
36
38
  }
39
+ /**
40
+ * Creates a Fetch handler that encapsulates all the Restate services served by this endpoint.
41
+ *
42
+ * @param {FetchEndpointOptions} options - Configuration options for the endpoint handler.
43
+ * @returns A fetch handler function.
44
+ *
45
+ * @example
46
+ * A typical request-response handler would look like this:
47
+ * ```
48
+ * import { createEndpointHandler } from "@restatedev/restate-sdk/fetch";
49
+ *
50
+ * export const handler = createEndpointHandler({ services: [myService] })
51
+ *
52
+ * @example
53
+ * A typical bidirectional handler (works with http2 and some http1.1 servers) would look like this:
54
+ * ```
55
+ * import { createEndpointHandler } from "@restatedev/restate-sdk/fetch";
56
+ *
57
+ * export const handler = createEndpointHandler({ services: [myService], bidirectional: true })
58
+ *
59
+ */
60
+ function createEndpointHandler(options) {
61
+ return (0, withOptions_js_1.withOptions)(new fetch_endpoint_js_1.FetchEndpointImpl(options.bidirectional ? "BIDI_STREAM" : "REQUEST_RESPONSE"), options).handler().fetch;
62
+ }
37
63
  //# sourceMappingURL=fetch.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../../src/fetch.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;;;;;;;;;;;AAaH,4BAEC;AAbD,kDAAgC;AAEhC,oEAGsC;AAEtC;;;GAGG;AACH,SAAgB,QAAQ;IACtB,OAAO,IAAI,qCAAiB,CAAC,kBAAkB,CAAC,CAAC;AACnD,CAAC"}
1
+ {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../../src/fetch.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;;;;;;;;;;;AAeH,4BAEC;AAmCD,sDAOC;AAzDD,kDAAgC;AAEhC,oEAGsC;AAEtC,8DAAwD;AAExD;;;GAGG;AACH,SAAgB,QAAQ;IACtB,OAAO,IAAI,qCAAiB,CAAC,kBAAkB,CAAC,CAAC;AACnD,CAAC;AAcD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,qBAAqB,CAAC,OAA6B;IACjE,OAAO,IAAA,4BAAW,EAChB,IAAI,qCAAiB,CACnB,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,kBAAkB,CAC3D,EACD,OAAO,CACR,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC;AACpB,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare const SDK_VERSION = "1.7.2";
1
+ export declare const SDK_VERSION = "1.8.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = '1.7.2';
4
+ exports.SDK_VERSION = '1.8.0';
5
5
  //# sourceMappingURL=version.js.map
@@ -1,7 +1,22 @@
1
1
  export * from "./common_api.js";
2
2
  import { type LambdaEndpoint } from "./endpoint/lambda_endpoint.js";
3
+ import type { EndpointOptions } from "./endpoint/types.js";
3
4
  /**
4
- * Create a new {@link RestateEndpoint}.
5
+ * Create a new {@link LambdaEndpoint}.
5
6
  */
6
7
  export declare function endpoint(): LambdaEndpoint;
8
+ /**
9
+ * Creates a Lambda handler that encapsulates all the Restate services served by this endpoint.
10
+ *
11
+ * @param {EndpointOptions} options - Configuration options for the endpoint handler.
12
+ * @returns A Lambda handler function.
13
+ *
14
+ * @example
15
+ * A typical endpoint served as Lambda would look like this:
16
+ * ```
17
+ * import { createEndpointHandler } from "@restatedev/restate-sdk/lambda";
18
+ *
19
+ * export const handler = createEndpointHandler({ services: [myService] })
20
+ */
21
+ export declare function createEndpointHandler(options: EndpointOptions): (event: any, ctx: any) => Promise<any>;
7
22
  //# sourceMappingURL=lambda.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lambda.d.ts","sourceRoot":"","sources":["../../../src/lambda.ts"],"names":[],"mappings":"AAWA,cAAc,iBAAiB,CAAC;AAEhC,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,+BAA+B,CAAC;AAEvC;;GAEG;AACH,wBAAgB,QAAQ,IAAI,cAAc,CAEzC"}
1
+ {"version":3,"file":"lambda.d.ts","sourceRoot":"","sources":["../../../src/lambda.ts"],"names":[],"mappings":"AAWA,cAAc,iBAAiB,CAAC;AAEhC,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG3D;;GAEG;AACH,wBAAgB,QAAQ,IAAI,cAAc,CAEzC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,eAAe,0CAK7D"}
@@ -25,12 +25,30 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
25
25
  };
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
27
  exports.endpoint = endpoint;
28
+ exports.createEndpointHandler = createEndpointHandler;
28
29
  __exportStar(require("./common_api.js"), exports);
29
30
  const lambda_endpoint_js_1 = require("./endpoint/lambda_endpoint.js");
31
+ const withOptions_js_1 = require("./endpoint/withOptions.js");
30
32
  /**
31
- * Create a new {@link RestateEndpoint}.
33
+ * Create a new {@link LambdaEndpoint}.
32
34
  */
33
35
  function endpoint() {
34
36
  return new lambda_endpoint_js_1.LambdaEndpointImpl();
35
37
  }
38
+ /**
39
+ * Creates a Lambda handler that encapsulates all the Restate services served by this endpoint.
40
+ *
41
+ * @param {EndpointOptions} options - Configuration options for the endpoint handler.
42
+ * @returns A Lambda handler function.
43
+ *
44
+ * @example
45
+ * A typical endpoint served as Lambda would look like this:
46
+ * ```
47
+ * import { createEndpointHandler } from "@restatedev/restate-sdk/lambda";
48
+ *
49
+ * export const handler = createEndpointHandler({ services: [myService] })
50
+ */
51
+ function createEndpointHandler(options) {
52
+ return (0, withOptions_js_1.withOptions)(new lambda_endpoint_js_1.LambdaEndpointImpl(), options).handler();
53
+ }
36
54
  //# sourceMappingURL=lambda.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"lambda.js","sourceRoot":"","sources":["../../../src/lambda.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;;;;;;;;;;;AAYH,4BAEC;AAZD,kDAAgC;AAEhC,sEAGuC;AAEvC;;GAEG;AACH,SAAgB,QAAQ;IACtB,OAAO,IAAI,uCAAkB,EAAE,CAAC;AAClC,CAAC"}
1
+ {"version":3,"file":"lambda.js","sourceRoot":"","sources":["../../../src/lambda.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;;;;;;;;;;;AAcH,4BAEC;AAeD,sDAKC;AAlCD,kDAAgC;AAEhC,sEAGuC;AAEvC,8DAAwD;AAExD;;GAEG;AACH,SAAgB,QAAQ;IACtB,OAAO,IAAI,uCAAkB,EAAE,CAAC;AAClC,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,qBAAqB,CAAC,OAAwB;IAC5D,OAAO,IAAA,4BAAW,EAChB,IAAI,uCAAkB,EAAE,EACxB,OAAO,CACR,CAAC,OAAO,EAAE,CAAC;AACd,CAAC"}
@@ -0,0 +1,38 @@
1
+ export * from "./common_api.js";
2
+ import type { RestateEndpoint } from "./endpoint.js";
3
+ import type { EndpointOptions } from "./endpoint/types.js";
4
+ /**
5
+ * Create a new {@link RestateEndpoint}.
6
+ */
7
+ export declare function endpoint(): RestateEndpoint;
8
+ /**
9
+ * Creates an HTTP/2 request handler for the provided services.
10
+ *
11
+ * @example
12
+ * ```
13
+ * const httpServer = http2.createServer(createEndpointHandler({ services: [myService] }));
14
+ * httpServer.listen(port);
15
+ * ```
16
+ * @param {EndpointOptions} options - Configuration options for the endpoint handler.
17
+ * @returns An HTTP/2 request handler function.
18
+ */
19
+ export declare function createEndpointHandler(options: EndpointOptions): (request: import("http2").Http2ServerRequest, response: import("http2").Http2ServerResponse) => void;
20
+ export interface ServeOptions extends EndpointOptions {
21
+ port?: number;
22
+ }
23
+ /**
24
+ * Serves this Restate services as HTTP2 server, listening to the given port.
25
+ *
26
+ * If the port is undefined, this method will use the port set in the `PORT`
27
+ * environment variable. If that variable is undefined as well, the method will
28
+ * default to port 9080.
29
+ *
30
+ * The returned promise resolves with the bound port when the server starts listening, or rejects with a failure otherwise.
31
+ *
32
+ * If you need to manually control the server lifecycle, we suggest to manually instantiate the http2 server and use {@link createEndpointHandler}.
33
+ *
34
+ * @param {ServeOptions} options - Configuration options for the endpoint handler.
35
+ * @returns a Promise that resolves with the bound port, or rejects with a failure otherwise.
36
+ */
37
+ export declare function serve({ port, ...options }: ServeOptions): Promise<number>;
38
+ //# sourceMappingURL=node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../src/node.ts"],"names":[],"mappings":"AAWA,cAAc,iBAAiB,CAAC;AAChC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG3D;;GAEG;AACH,wBAAgB,QAAQ,IAAI,eAAe,CAE1C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,eAAe,wGAK7D;AAED,MAAM,WAAW,YAAa,SAAQ,eAAe;IACnD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,KAAK,CAAC,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,EAAE,YAAY,mBAEvD"}
@@ -0,0 +1,70 @@
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ var desc = Object.getOwnPropertyDescriptor(m, k);
15
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
16
+ desc = { enumerable: true, get: function() { return m[k]; } };
17
+ }
18
+ Object.defineProperty(o, k2, desc);
19
+ }) : (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k;
21
+ o[k2] = m[k];
22
+ }));
23
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
24
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.endpoint = endpoint;
28
+ exports.createEndpointHandler = createEndpointHandler;
29
+ exports.serve = serve;
30
+ __exportStar(require("./common_api.js"), exports);
31
+ const node_endpoint_js_1 = require("./endpoint/node_endpoint.js");
32
+ const withOptions_js_1 = require("./endpoint/withOptions.js");
33
+ /**
34
+ * Create a new {@link RestateEndpoint}.
35
+ */
36
+ function endpoint() {
37
+ return new node_endpoint_js_1.NodeEndpoint();
38
+ }
39
+ /**
40
+ * Creates an HTTP/2 request handler for the provided services.
41
+ *
42
+ * @example
43
+ * ```
44
+ * const httpServer = http2.createServer(createEndpointHandler({ services: [myService] }));
45
+ * httpServer.listen(port);
46
+ * ```
47
+ * @param {EndpointOptions} options - Configuration options for the endpoint handler.
48
+ * @returns An HTTP/2 request handler function.
49
+ */
50
+ function createEndpointHandler(options) {
51
+ return (0, withOptions_js_1.withOptions)(new node_endpoint_js_1.NodeEndpoint(), options).http2Handler();
52
+ }
53
+ /**
54
+ * Serves this Restate services as HTTP2 server, listening to the given port.
55
+ *
56
+ * If the port is undefined, this method will use the port set in the `PORT`
57
+ * environment variable. If that variable is undefined as well, the method will
58
+ * default to port 9080.
59
+ *
60
+ * The returned promise resolves with the bound port when the server starts listening, or rejects with a failure otherwise.
61
+ *
62
+ * If you need to manually control the server lifecycle, we suggest to manually instantiate the http2 server and use {@link createEndpointHandler}.
63
+ *
64
+ * @param {ServeOptions} options - Configuration options for the endpoint handler.
65
+ * @returns a Promise that resolves with the bound port, or rejects with a failure otherwise.
66
+ */
67
+ function serve({ port, ...options }) {
68
+ return (0, withOptions_js_1.withOptions)(new node_endpoint_js_1.NodeEndpoint(), options).listen(port);
69
+ }
70
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../../../src/node.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;;;;;;;;;;;AAWH,4BAEC;AAaD,sDAKC;AAoBD,sBAEC;AAnDD,kDAAgC;AAEhC,kEAA2D;AAE3D,8DAAwD;AAExD;;GAEG;AACH,SAAgB,QAAQ;IACtB,OAAO,IAAI,+BAAY,EAAE,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,qBAAqB,CAAC,OAAwB;IAC5D,OAAO,IAAA,4BAAW,EAChB,IAAI,+BAAY,EAAE,EAClB,OAAO,CACR,CAAC,YAAY,EAAE,CAAC;AACnB,CAAC;AAMD;;;;;;;;;;;;;GAaG;AACH,SAAgB,KAAK,CAAC,EAAE,IAAI,EAAE,GAAG,OAAO,EAAgB;IACtD,OAAO,IAAA,4BAAW,EAAkB,IAAI,+BAAY,EAAE,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAChF,CAAC"}
@@ -1,7 +1,2 @@
1
- export * from "./common_api.js";
2
- import type { RestateEndpoint } from "./endpoint.js";
3
- /**
4
- * Create a new {@link RestateEndpoint}.
5
- */
6
- export declare function endpoint(): RestateEndpoint;
1
+ export * from "./node.js";
7
2
  //# sourceMappingURL=public_api.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"public_api.d.ts","sourceRoot":"","sources":["../../../src/public_api.ts"],"names":[],"mappings":"AAWA,cAAc,iBAAiB,CAAC;AAEhC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGrD;;GAEG;AACH,wBAAgB,QAAQ,IAAI,eAAe,CAE1C"}
1
+ {"version":3,"file":"public_api.d.ts","sourceRoot":"","sources":["../../../src/public_api.ts"],"names":[],"mappings":"AAWA,cAAc,WAAW,CAAC"}
@@ -24,13 +24,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
24
24
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
25
25
  };
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.endpoint = endpoint;
28
- __exportStar(require("./common_api.js"), exports);
29
- const node_endpoint_js_1 = require("./endpoint/node_endpoint.js");
30
- /**
31
- * Create a new {@link RestateEndpoint}.
32
- */
33
- function endpoint() {
34
- return new node_endpoint_js_1.NodeEndpoint();
35
- }
27
+ __exportStar(require("./node.js"), exports);
36
28
  //# sourceMappingURL=public_api.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"public_api.js","sourceRoot":"","sources":["../../../src/public_api.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;;;;;;;;;;;AAUH,4BAEC;AAVD,kDAAgC;AAGhC,kEAA2D;AAE3D;;GAEG;AACH,SAAgB,QAAQ;IACtB,OAAO,IAAI,+BAAY,EAAE,CAAC;AAC5B,CAAC"}
1
+ {"version":3,"file":"public_api.js","sourceRoot":"","sources":["../../../src/public_api.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;;;;;;;;;;;AAEH,4CAA0B"}
@@ -1,10 +1,11 @@
1
+ import type { Duration } from "@restatedev/restate-sdk-core";
1
2
  export declare const INTERNAL_ERROR_CODE = 500;
2
3
  export declare const TIMEOUT_ERROR_CODE = 408;
3
4
  export declare const CANCEL_ERROR_CODE = 409;
4
5
  export declare const UNKNOWN_ERROR_CODE = 500;
5
6
  export declare const CLOSED_ERROR_CODE = 598;
6
7
  export declare const SUSPENDED_ERROR_CODE = 599;
7
- export declare function ensureError(e: unknown): Error;
8
+ export declare function ensureError(e: unknown, asTerminalError?: (error: any) => TerminalError | undefined): Error;
8
9
  export declare function logError(log: Console, e: unknown): void;
9
10
  export declare class RestateError extends Error {
10
11
  readonly code: number;
@@ -14,19 +15,60 @@ export declare class RestateError extends Error {
14
15
  cause?: any;
15
16
  });
16
17
  }
18
+ /**
19
+ * Does not lead to Restate retries.
20
+ *
21
+ * Leads to an output message with a failure defined.
22
+ */
17
23
  export declare class TerminalError extends RestateError {
18
24
  name: string;
19
25
  constructor(message: string, options?: {
26
+ /**
27
+ * Error code. This should be an HTTP status code, and in case the service was invoked from the ingress, this will be propagated back to the caller.
28
+ */
20
29
  errorCode?: number;
30
+ /**
31
+ * @deprecated YOU MUST NOT USE THIS FIELD, AS IT WON'T BE RECORDED AND CAN LEAD TO NON-DETERMINISM! From the next SDK version, the constructor won't accept this field anymore.
32
+ */
21
33
  cause?: any;
22
34
  });
23
35
  }
36
+ /**
37
+ * Returned by `RestatePromise.withTimeout` when the timeout is reached.
38
+ */
24
39
  export declare class TimeoutError extends TerminalError {
25
40
  name: string;
26
41
  constructor();
27
42
  }
43
+ /**
44
+ * Returned when the invocation was cancelled.
45
+ */
28
46
  export declare class CancelledError extends TerminalError {
29
47
  name: string;
30
48
  constructor();
31
49
  }
50
+ export interface RetryableErrorOptions {
51
+ /**
52
+ * In how long it should retry.
53
+ */
54
+ retryAfter?: Duration | number;
55
+ }
56
+ /**
57
+ * Error that Restate will retry. By using this error type within a `ctx.run` closure,
58
+ * you can dynamically provide the retry delay specified in {@link RetryableErrorOptions}.
59
+ *
60
+ * You can wrap another error using {@link from}.
61
+ */
62
+ export declare class RetryableError extends RestateError {
63
+ name: string;
64
+ readonly retryAfter?: Duration | number;
65
+ constructor(message: string, options?: RetryableErrorOptions & {
66
+ errorCode?: number;
67
+ cause?: any;
68
+ });
69
+ /**
70
+ * Create a `RetryableError` from the given cause.
71
+ */
72
+ static from(cause: any, options?: RetryableErrorOptions): RetryableError;
73
+ }
32
74
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../src/types/errors.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,mBAAmB,MAAM,CAAC;AACvC,eAAO,MAAM,kBAAkB,MAAM,CAAC;AACtC,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAGtC,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,KAAK,CAmB7C;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,QAiBhD;AAED,qBAAa,YAAa,SAAQ,KAAK;IACrC,SAAgB,IAAI,EAAE,MAAM,CAAC;IACtB,IAAI,SAAkB;gBAEjB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,GAAG,CAAA;KAAE;CAI3E;AAID,qBAAa,aAAc,SAAQ,YAAY;IACtC,IAAI,SAAmB;gBAElB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,GAAG,CAAA;KAAE;CAG3E;AAED,qBAAa,YAAa,SAAQ,aAAa;IACtC,IAAI,SAAkB;;CAK9B;AAED,qBAAa,cAAe,SAAQ,aAAa;IACxC,IAAI,SAAoB;;CAKhC"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../src/types/errors.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAE7D,eAAO,MAAM,mBAAmB,MAAM,CAAC;AACvC,eAAO,MAAM,kBAAkB,MAAM,CAAC;AACtC,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAGtC,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC,wBAAgB,WAAW,CACzB,CAAC,EAAE,OAAO,EACV,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,aAAa,GAAG,SAAS,GAC1D,KAAK,CA6BP;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,QAiBhD;AAED,qBAAa,YAAa,SAAQ,KAAK;IACrC,SAAgB,IAAI,EAAE,MAAM,CAAC;IACtB,IAAI,SAAkB;gBAEjB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,GAAG,CAAA;KAAE;CAI3E;AAED;;;;GAIG;AACH,qBAAa,aAAc,SAAQ,YAAY;IACtC,IAAI,SAAmB;gBAG5B,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QACR;;WAEG;QACH,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB;;WAEG;QACH,KAAK,CAAC,EAAE,GAAG,CAAC;KACb;CAIJ;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,aAAa;IACtC,IAAI,SAAkB;;CAK9B;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,aAAa;IACxC,IAAI,SAAoB;;CAKhC;AAED,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,UAAU,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;CAChC;AAED;;;;;GAKG;AACH,qBAAa,cAAe,SAAQ,YAAY;IACvC,IAAI,SAAoB;IAE/B,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;gBAGtC,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,qBAAqB,GAAG;QAChC,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,KAAK,CAAC,EAAE,GAAG,CAAC;KACb;IAUH;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,cAAc;CAQzE"}
@@ -10,10 +10,9 @@
10
10
  * https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
11
11
  */
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.CancelledError = exports.TimeoutError = exports.TerminalError = exports.RestateError = exports.SUSPENDED_ERROR_CODE = exports.CLOSED_ERROR_CODE = exports.UNKNOWN_ERROR_CODE = exports.CANCEL_ERROR_CODE = exports.TIMEOUT_ERROR_CODE = exports.INTERNAL_ERROR_CODE = void 0;
13
+ exports.RetryableError = exports.CancelledError = exports.TimeoutError = exports.TerminalError = exports.RestateError = exports.SUSPENDED_ERROR_CODE = exports.CLOSED_ERROR_CODE = exports.UNKNOWN_ERROR_CODE = exports.CANCEL_ERROR_CODE = exports.TIMEOUT_ERROR_CODE = exports.INTERNAL_ERROR_CODE = void 0;
14
14
  exports.ensureError = ensureError;
15
15
  exports.logError = logError;
16
- /* eslint-disable @typescript-eslint/no-explicit-any */
17
16
  exports.INTERNAL_ERROR_CODE = 500;
18
17
  exports.TIMEOUT_ERROR_CODE = 408;
19
18
  exports.CANCEL_ERROR_CODE = 409;
@@ -21,7 +20,15 @@ exports.UNKNOWN_ERROR_CODE = 500;
21
20
  // From shared core!
22
21
  exports.CLOSED_ERROR_CODE = 598;
23
22
  exports.SUSPENDED_ERROR_CODE = 599;
24
- function ensureError(e) {
23
+ function ensureError(e, asTerminalError) {
24
+ if (e instanceof TerminalError) {
25
+ return e;
26
+ }
27
+ // Try convert to terminal error
28
+ const maybeTerminalError = asTerminalError ? asTerminalError(e) : undefined;
29
+ if (maybeTerminalError) {
30
+ return maybeTerminalError;
31
+ }
25
32
  if (e instanceof Error) {
26
33
  return e;
27
34
  }
@@ -31,6 +38,7 @@ function ensureError(e) {
31
38
  errorCode: e.code,
32
39
  });
33
40
  }
41
+ // None of the types we know
34
42
  let msg;
35
43
  try {
36
44
  msg = JSON.stringify(e);
@@ -65,8 +73,11 @@ class RestateError extends Error {
65
73
  }
66
74
  }
67
75
  exports.RestateError = RestateError;
68
- // Does not lead to Restate retries
69
- // Leads to an output message with a failure defined
76
+ /**
77
+ * Does not lead to Restate retries.
78
+ *
79
+ * Leads to an output message with a failure defined.
80
+ */
70
81
  class TerminalError extends RestateError {
71
82
  name = "TerminalError";
72
83
  constructor(message, options) {
@@ -74,6 +85,9 @@ class TerminalError extends RestateError {
74
85
  }
75
86
  }
76
87
  exports.TerminalError = TerminalError;
88
+ /**
89
+ * Returned by `RestatePromise.withTimeout` when the timeout is reached.
90
+ */
77
91
  class TimeoutError extends TerminalError {
78
92
  name = "TimeoutError";
79
93
  constructor() {
@@ -81,6 +95,9 @@ class TimeoutError extends TerminalError {
81
95
  }
82
96
  }
83
97
  exports.TimeoutError = TimeoutError;
98
+ /**
99
+ * Returned when the invocation was cancelled.
100
+ */
84
101
  class CancelledError extends TerminalError {
85
102
  name = "CancelledError";
86
103
  constructor() {
@@ -88,4 +105,34 @@ class CancelledError extends TerminalError {
88
105
  }
89
106
  }
90
107
  exports.CancelledError = CancelledError;
108
+ /**
109
+ * Error that Restate will retry. By using this error type within a `ctx.run` closure,
110
+ * you can dynamically provide the retry delay specified in {@link RetryableErrorOptions}.
111
+ *
112
+ * You can wrap another error using {@link from}.
113
+ */
114
+ class RetryableError extends RestateError {
115
+ name = "RetryableError";
116
+ retryAfter;
117
+ constructor(message, options) {
118
+ super(message, {
119
+ errorCode: options?.errorCode,
120
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
121
+ cause: options?.cause,
122
+ });
123
+ this.retryAfter = options?.retryAfter;
124
+ }
125
+ /**
126
+ * Create a `RetryableError` from the given cause.
127
+ */
128
+ static from(cause, options) {
129
+ const error = ensureError(cause);
130
+ return new RetryableError(error.message, {
131
+ errorCode: error["errorCode"],
132
+ cause: cause,
133
+ ...options,
134
+ });
135
+ }
136
+ }
137
+ exports.RetryableError = RetryableError;
91
138
  //# sourceMappingURL=errors.js.map