@restatedev/restate-sdk-cloudflare-workers 1.11.1 → 1.12.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 (117) hide show
  1. package/dist/_virtual/rolldown_runtime.cjs +9 -0
  2. package/dist/common_api.cjs +2 -1
  3. package/dist/common_api.d.cts +6 -2
  4. package/dist/common_api.d.cts.map +1 -1
  5. package/dist/common_api.d.ts +6 -2
  6. package/dist/common_api.d.ts.map +1 -1
  7. package/dist/common_api.js +2 -1
  8. package/dist/common_api.js.map +1 -1
  9. package/dist/context.cjs +13 -9
  10. package/dist/context.d.cts +36 -29
  11. package/dist/context.d.cts.map +1 -1
  12. package/dist/context.d.ts +36 -29
  13. package/dist/context.d.ts.map +1 -1
  14. package/dist/context.js +13 -9
  15. package/dist/context.js.map +1 -1
  16. package/dist/context_impl.cjs +150 -91
  17. package/dist/context_impl.d.cts +8 -0
  18. package/dist/context_impl.d.ts +8 -0
  19. package/dist/context_impl.js +151 -93
  20. package/dist/context_impl.js.map +1 -1
  21. package/dist/endpoint/components.cjs +35 -20
  22. package/dist/endpoint/components.d.cts +5 -0
  23. package/dist/endpoint/components.d.ts +5 -0
  24. package/dist/endpoint/components.js +35 -20
  25. package/dist/endpoint/components.js.map +1 -1
  26. package/dist/endpoint/endpoint.cjs +2 -2
  27. package/dist/endpoint/endpoint.d.cts +5 -0
  28. package/dist/endpoint/endpoint.d.ts +5 -0
  29. package/dist/endpoint/endpoint.js +2 -2
  30. package/dist/endpoint/endpoint.js.map +1 -1
  31. package/dist/endpoint/handlers/generic.cjs +115 -39
  32. package/dist/endpoint/handlers/generic.js +115 -39
  33. package/dist/endpoint/handlers/generic.js.map +1 -1
  34. package/dist/endpoint/handlers/types.d.cts +1 -0
  35. package/dist/endpoint/handlers/types.d.ts +1 -0
  36. package/dist/endpoint/handlers/utils.cjs +1 -1
  37. package/dist/endpoint/handlers/utils.js +1 -1
  38. package/dist/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.d.ts +4 -1
  39. package/dist/endpoint/handlers/vm/sdk_shared_core_wasm_bindings_bg.js +48 -2
  40. package/dist/endpoint/handlers/vm/sdk_shared_core_wasm_bindings_bg.wasm +0 -0
  41. package/dist/endpoint/handlers/vm/sdk_shared_core_wasm_bindings_bg.wasm.d.ts +4 -1
  42. package/dist/endpoint/node_endpoint.cjs +28 -12
  43. package/dist/endpoint/node_endpoint.js +27 -11
  44. package/dist/endpoint/node_endpoint.js.map +1 -1
  45. package/dist/endpoint/types.d.cts +1 -1
  46. package/dist/endpoint/types.d.ts +1 -1
  47. package/dist/endpoint.d.cts +87 -5
  48. package/dist/endpoint.d.cts.map +1 -1
  49. package/dist/endpoint.d.ts +87 -5
  50. package/dist/endpoint.d.ts.map +1 -1
  51. package/dist/error_sanitization.cjs +26 -0
  52. package/dist/error_sanitization.js +26 -0
  53. package/dist/error_sanitization.js.map +1 -0
  54. package/dist/fetch.cjs +3 -1
  55. package/dist/fetch.d.cts +5 -3
  56. package/dist/fetch.d.cts.map +1 -1
  57. package/dist/fetch.d.ts +5 -3
  58. package/dist/fetch.d.ts.map +1 -1
  59. package/dist/fetch.js.map +1 -1
  60. package/dist/hooks.d.cts +87 -0
  61. package/dist/hooks.d.cts.map +1 -0
  62. package/dist/hooks.d.ts +87 -0
  63. package/dist/hooks.d.ts.map +1 -0
  64. package/dist/index.cjs +3 -1
  65. package/dist/index.d.cts +6 -4
  66. package/dist/index.d.ts +6 -4
  67. package/dist/index.js +3 -2
  68. package/dist/internal.cjs +3 -1
  69. package/dist/internal.d.cts +186 -2
  70. package/dist/internal.d.cts.map +1 -1
  71. package/dist/internal.d.ts +186 -2
  72. package/dist/internal.d.ts.map +1 -1
  73. package/dist/internal.js +4 -1
  74. package/dist/internal.js.map +1 -1
  75. package/dist/io.d.cts +1 -0
  76. package/dist/io.d.ts +1 -0
  77. package/dist/lambda.cjs +3 -1
  78. package/dist/lambda.d.cts +5 -3
  79. package/dist/lambda.d.cts.map +1 -1
  80. package/dist/lambda.d.ts +5 -3
  81. package/dist/lambda.d.ts.map +1 -1
  82. package/dist/lambda.js +3 -2
  83. package/dist/lambda.js.map +1 -1
  84. package/dist/logging/logger.d.cts +1 -0
  85. package/dist/logging/logger.d.ts +1 -0
  86. package/dist/node.cjs +23 -6
  87. package/dist/node.d.cts +46 -8
  88. package/dist/node.d.cts.map +1 -1
  89. package/dist/node.d.ts +46 -8
  90. package/dist/node.d.ts.map +1 -1
  91. package/dist/node.js +23 -7
  92. package/dist/node.js.map +1 -1
  93. package/dist/package.cjs +1 -1
  94. package/dist/package.js +1 -1
  95. package/dist/package.js.map +1 -1
  96. package/dist/promises.cjs +90 -53
  97. package/dist/promises.d.cts +18 -0
  98. package/dist/promises.d.cts.map +1 -0
  99. package/dist/promises.d.ts +18 -0
  100. package/dist/promises.d.ts.map +1 -0
  101. package/dist/promises.js +85 -48
  102. package/dist/promises.js.map +1 -1
  103. package/dist/types/errors.cjs +13 -0
  104. package/dist/types/errors.d.cts +11 -5
  105. package/dist/types/errors.d.cts.map +1 -1
  106. package/dist/types/errors.d.ts +11 -5
  107. package/dist/types/errors.d.ts.map +1 -1
  108. package/dist/types/errors.js +13 -1
  109. package/dist/types/errors.js.map +1 -1
  110. package/dist/types/rpc.cjs +7 -19
  111. package/dist/types/rpc.d.cts +174 -0
  112. package/dist/types/rpc.d.cts.map +1 -1
  113. package/dist/types/rpc.d.ts +174 -0
  114. package/dist/types/rpc.d.ts.map +1 -1
  115. package/dist/types/rpc.js +7 -19
  116. package/dist/types/rpc.js.map +1 -1
  117. package/package.json +3 -3
@@ -1,7 +1,8 @@
1
1
  import { ObjectOptions, ServiceOptions, WorkflowOptions } from "./types/rpc.cjs";
2
2
  import { LoggerTransport } from "./logging/logger_transport.cjs";
3
3
  import { JournalValueCodec, ServiceDefinition, VirtualObjectDefinition, WorkflowDefinition } from "@restatedev/restate-sdk-core";
4
- import { Http2ServerRequest, Http2ServerResponse } from "http2";
4
+ import { IncomingMessage, ServerResponse } from "node:http";
5
+ import { Http2ServerRequest, Http2ServerResponse } from "node:http2";
5
6
 
6
7
  //#region src/endpoint.d.ts
7
8
  type DefaultServiceOptions = ServiceOptions & ObjectOptions & WorkflowOptions;
@@ -63,12 +64,15 @@ interface RestateEndpointBase<E> {
63
64
  /**
64
65
  * RestateEndpoint encapsulates all the Restate services served by this endpoint.
65
66
  *
66
- * A RestateEndpoint can either be served as HTTP2 server, using the methods {@link RestateEndpoint.listen} or {@link RestateEndpoint.http2Handler}.
67
+ * A RestateEndpoint can be served as:
68
+ * - An HTTP/2 server using {@link RestateEndpoint.listen}, {@link RestateEndpoint.http2Handler}
69
+ * - An HTTP/1.1 server using {@link RestateEndpoint.http1Handler}
70
+ * - A combined HTTP/1.1 + HTTP/2 server using {@link RestateEndpoint.handler}
67
71
  *
68
72
  * For Lambda, check {@link LambdaEndpoint}
69
73
  *
70
74
  * @example
71
- * A typical endpoint served as HTTP server would look like this:
75
+ * A typical endpoint served as HTTP/2 server:
72
76
  * ```
73
77
  * import * as restate from "@restatedev/restate-sdk";
74
78
  *
@@ -77,6 +81,28 @@ interface RestateEndpointBase<E> {
77
81
  * .bind(myService)
78
82
  * .listen(8000);
79
83
  * ```
84
+ *
85
+ * @example
86
+ * Using the HTTP/1.1 handler with your own server:
87
+ * ```
88
+ * import * as http from "node:http";
89
+ * import * as restate from "@restatedev/restate-sdk";
90
+ *
91
+ * const endpoint = restate.endpoint().bind(myService);
92
+ * const server = http.createServer(endpoint.http1Handler());
93
+ * server.listen(8000);
94
+ * ```
95
+ *
96
+ * @example
97
+ * Using the combined handler with an HTTP/2 server that also accepts HTTP/1.1:
98
+ * ```
99
+ * import * as http2 from "node:http2";
100
+ * import * as restate from "@restatedev/restate-sdk";
101
+ *
102
+ * const endpoint = restate.endpoint().bind(myService);
103
+ * const server = http2.createSecureServer({ key, cert, allowHTTP1: true }, endpoint.handler());
104
+ * server.listen(8000);
105
+ * ```
80
106
  */
81
107
  interface RestateEndpoint extends RestateEndpointBase<RestateEndpoint> {
82
108
  /**
@@ -103,9 +129,65 @@ interface RestateEndpoint extends RestateEndpointBase<RestateEndpoint> {
103
129
  */
104
130
  listen(port?: number): Promise<number>;
105
131
  /**
106
- * Returns an http2 server handler. See {@link RestateEndpoint.listen} for more details.
132
+ * Returns an http2 server handler.
133
+ *
134
+ * By default, this handler uses bidirectional streaming (`BIDI_STREAM`).
135
+ * Set `bidirectional: false` to use request-response mode (`REQUEST_RESPONSE`).
136
+ *
137
+ * See {@link RestateEndpoint.listen} for more details.
138
+ */
139
+ http2Handler(options?: {
140
+ bidirectional?: boolean;
141
+ }): (request: Http2ServerRequest, response: Http2ServerResponse) => void;
142
+ /**
143
+ * Returns an http1 server handler.
144
+ *
145
+ * By default, this handler operates in request-response protocol mode (`REQUEST_RESPONSE`),
146
+ * which buffers the full request before sending the response. This is the safest mode
147
+ * for HTTP/1.1 and works across all environments and proxies.
148
+ *
149
+ * Set `bidirectional: true` to enable bidirectional streaming (`BIDI_STREAM`) for
150
+ * HTTP/1.1 servers that support it. Note that some proxies and clients may not
151
+ * handle HTTP/1.1 bidirectional streaming correctly.
152
+ *
153
+ * @example
154
+ * ```
155
+ * const httpServer = http.createServer(endpoint.http1Handler());
156
+ * httpServer.listen(port);
157
+ * ```
158
+ */
159
+ http1Handler(options?: {
160
+ bidirectional?: boolean;
161
+ }): (request: IncomingMessage, response: ServerResponse) => void;
162
+ /**
163
+ * Returns a combined request handler that auto-detects HTTP/1 vs HTTP/2
164
+ * requests and dispatches to the appropriate internal handler.
165
+ *
166
+ * By default (when `bidirectional` is omitted), HTTP/2+ requests use
167
+ * bidirectional streaming (`BIDI_STREAM`) and HTTP/1 requests use
168
+ * request-response mode (`REQUEST_RESPONSE`).
169
+ *
170
+ * Set `bidirectional: true` to force `BIDI_STREAM` for all requests,
171
+ * or `bidirectional: false` to force `REQUEST_RESPONSE` for all requests.
172
+ *
173
+ * This is useful with `http2.createSecureServer({ allowHTTP1: true })`, where
174
+ * the same server handles both HTTP/1.1 and HTTP/2 connections.
175
+ *
176
+ * @example
177
+ * ```
178
+ * const server = http2.createSecureServer(
179
+ * { key, cert, allowHTTP1: true },
180
+ * endpoint.handler()
181
+ * );
182
+ * server.listen(port);
183
+ * ```
107
184
  */
108
- http2Handler(): (request: Http2ServerRequest, response: Http2ServerResponse) => void;
185
+ handler(options?: {
186
+ bidirectional?: boolean;
187
+ }): {
188
+ (request: IncomingMessage, response: ServerResponse): void;
189
+ (request: Http2ServerRequest, response: Http2ServerResponse): void;
190
+ };
109
191
  }
110
192
  //#endregion
111
193
  export { DefaultServiceOptions, RestateEndpoint, RestateEndpointBase };
@@ -1 +1 @@
1
- {"version":3,"file":"endpoint.d.cts","names":[],"sources":["../src/endpoint.ts"],"sourcesContent":[],"mappings":";;;;;;KAyBY,qBAAA,GAAwB,iBAClC,gBACA;UAEe;EAJL;;;;;EAIK,IAAA,CAAA,UAAA,MAAA,EAAmB,CAAA,CAAA,CAAA,OAAA,EAQ5B,iBAR4B,CAQV,CARU,EAQP,CARO,CAAA,GAS5B,uBAT4B,CASJ,CATI,EASD,CATC,CAAA,GAU5B,kBAV4B,CAUT,CAVS,EAUN,CAVM,CAAA,CAAA,EAW/B,CAX+B;EAQV;;;;;;;;;EAGrB,cAAA,CAAA,GAAA,IAAA,EAAA,MAAA,EAAA,CAAA,EAWgC,CAXhC;EAWgC;;;;;;;EAwCyC,qBAAA,CAAA,OAAA,EA/B7C,qBA+B6C,CAAA,EA/BrB,CA+BqB;EAAC;AAqB/E;;;;;;;;;;;;;;;;;;;;oBA7BoB,kBAAkB;;;;;;;iDAQW,QAAQ,qBAAqB;;;;;;;;;;;;;;;;;;;;UAqB7D,eAAA,SAAwB,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;yBAuBpC;;;;4BAMZ,8BACC"}
1
+ {"version":3,"file":"endpoint.d.cts","names":[],"sources":["../src/endpoint.ts"],"sourcesContent":[],"mappings":";;;;;;;KA0BY,qBAAA,GAAwB,iBAClC,gBACA;UAEe;EAJL;;;;;EAIK,IAAA,CAAA,UAAA,MAAA,EAAmB,CAAA,CAAA,CAAA,OAAA,EAQ5B,iBAR4B,CAQV,CARU,EAQP,CARO,CAAA,GAS5B,uBAT4B,CASJ,CATI,EASD,CATC,CAAA,GAU5B,kBAV4B,CAUT,CAVS,EAUN,CAVM,CAAA,CAAA,EAW/B,CAX+B;EAQV;;;;;;;;;EAGrB,cAAA,CAAA,GAAA,IAAA,EAAA,MAAA,EAAA,CAAA,EAWgC,CAXhC;EAWgC;;;;;;;EAwCyC,qBAAA,CAAA,OAAA,EA/B7C,qBA+B6C,CAAA,EA/BrB,CA+BqB;EAAC;AA8C/E;;;;;;;;;;;;;;;;;;;;oBAtDoB,kBAAkB;;;;;;;iDAQW,QAAQ,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UA8C7D,eAAA,SAAwB,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;yBAuBpC;;;;;;;;;;;gBAYT,8BAA8B;;;;;;;;;;;;;;;;;;;;gBAqB9B,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;cA0B7B,2BAA2B;cAC3B,8BAA8B"}
@@ -1,7 +1,8 @@
1
1
  import { ObjectOptions, ServiceOptions, WorkflowOptions } from "./types/rpc.js";
2
2
  import { LoggerTransport } from "./logging/logger_transport.js";
3
3
  import { JournalValueCodec, ServiceDefinition, VirtualObjectDefinition, WorkflowDefinition } from "@restatedev/restate-sdk-core";
4
- import { Http2ServerRequest, Http2ServerResponse } from "http2";
4
+ import { Http2ServerRequest, Http2ServerResponse } from "node:http2";
5
+ import { IncomingMessage, ServerResponse } from "node:http";
5
6
 
6
7
  //#region src/endpoint.d.ts
7
8
  type DefaultServiceOptions = ServiceOptions & ObjectOptions & WorkflowOptions;
@@ -63,12 +64,15 @@ interface RestateEndpointBase<E> {
63
64
  /**
64
65
  * RestateEndpoint encapsulates all the Restate services served by this endpoint.
65
66
  *
66
- * A RestateEndpoint can either be served as HTTP2 server, using the methods {@link RestateEndpoint.listen} or {@link RestateEndpoint.http2Handler}.
67
+ * A RestateEndpoint can be served as:
68
+ * - An HTTP/2 server using {@link RestateEndpoint.listen}, {@link RestateEndpoint.http2Handler}
69
+ * - An HTTP/1.1 server using {@link RestateEndpoint.http1Handler}
70
+ * - A combined HTTP/1.1 + HTTP/2 server using {@link RestateEndpoint.handler}
67
71
  *
68
72
  * For Lambda, check {@link LambdaEndpoint}
69
73
  *
70
74
  * @example
71
- * A typical endpoint served as HTTP server would look like this:
75
+ * A typical endpoint served as HTTP/2 server:
72
76
  * ```
73
77
  * import * as restate from "@restatedev/restate-sdk";
74
78
  *
@@ -77,6 +81,28 @@ interface RestateEndpointBase<E> {
77
81
  * .bind(myService)
78
82
  * .listen(8000);
79
83
  * ```
84
+ *
85
+ * @example
86
+ * Using the HTTP/1.1 handler with your own server:
87
+ * ```
88
+ * import * as http from "node:http";
89
+ * import * as restate from "@restatedev/restate-sdk";
90
+ *
91
+ * const endpoint = restate.endpoint().bind(myService);
92
+ * const server = http.createServer(endpoint.http1Handler());
93
+ * server.listen(8000);
94
+ * ```
95
+ *
96
+ * @example
97
+ * Using the combined handler with an HTTP/2 server that also accepts HTTP/1.1:
98
+ * ```
99
+ * import * as http2 from "node:http2";
100
+ * import * as restate from "@restatedev/restate-sdk";
101
+ *
102
+ * const endpoint = restate.endpoint().bind(myService);
103
+ * const server = http2.createSecureServer({ key, cert, allowHTTP1: true }, endpoint.handler());
104
+ * server.listen(8000);
105
+ * ```
80
106
  */
81
107
  interface RestateEndpoint extends RestateEndpointBase<RestateEndpoint> {
82
108
  /**
@@ -103,9 +129,65 @@ interface RestateEndpoint extends RestateEndpointBase<RestateEndpoint> {
103
129
  */
104
130
  listen(port?: number): Promise<number>;
105
131
  /**
106
- * Returns an http2 server handler. See {@link RestateEndpoint.listen} for more details.
132
+ * Returns an http2 server handler.
133
+ *
134
+ * By default, this handler uses bidirectional streaming (`BIDI_STREAM`).
135
+ * Set `bidirectional: false` to use request-response mode (`REQUEST_RESPONSE`).
136
+ *
137
+ * See {@link RestateEndpoint.listen} for more details.
138
+ */
139
+ http2Handler(options?: {
140
+ bidirectional?: boolean;
141
+ }): (request: Http2ServerRequest, response: Http2ServerResponse) => void;
142
+ /**
143
+ * Returns an http1 server handler.
144
+ *
145
+ * By default, this handler operates in request-response protocol mode (`REQUEST_RESPONSE`),
146
+ * which buffers the full request before sending the response. This is the safest mode
147
+ * for HTTP/1.1 and works across all environments and proxies.
148
+ *
149
+ * Set `bidirectional: true` to enable bidirectional streaming (`BIDI_STREAM`) for
150
+ * HTTP/1.1 servers that support it. Note that some proxies and clients may not
151
+ * handle HTTP/1.1 bidirectional streaming correctly.
152
+ *
153
+ * @example
154
+ * ```
155
+ * const httpServer = http.createServer(endpoint.http1Handler());
156
+ * httpServer.listen(port);
157
+ * ```
158
+ */
159
+ http1Handler(options?: {
160
+ bidirectional?: boolean;
161
+ }): (request: IncomingMessage, response: ServerResponse) => void;
162
+ /**
163
+ * Returns a combined request handler that auto-detects HTTP/1 vs HTTP/2
164
+ * requests and dispatches to the appropriate internal handler.
165
+ *
166
+ * By default (when `bidirectional` is omitted), HTTP/2+ requests use
167
+ * bidirectional streaming (`BIDI_STREAM`) and HTTP/1 requests use
168
+ * request-response mode (`REQUEST_RESPONSE`).
169
+ *
170
+ * Set `bidirectional: true` to force `BIDI_STREAM` for all requests,
171
+ * or `bidirectional: false` to force `REQUEST_RESPONSE` for all requests.
172
+ *
173
+ * This is useful with `http2.createSecureServer({ allowHTTP1: true })`, where
174
+ * the same server handles both HTTP/1.1 and HTTP/2 connections.
175
+ *
176
+ * @example
177
+ * ```
178
+ * const server = http2.createSecureServer(
179
+ * { key, cert, allowHTTP1: true },
180
+ * endpoint.handler()
181
+ * );
182
+ * server.listen(port);
183
+ * ```
107
184
  */
108
- http2Handler(): (request: Http2ServerRequest, response: Http2ServerResponse) => void;
185
+ handler(options?: {
186
+ bidirectional?: boolean;
187
+ }): {
188
+ (request: IncomingMessage, response: ServerResponse): void;
189
+ (request: Http2ServerRequest, response: Http2ServerResponse): void;
190
+ };
109
191
  }
110
192
  //#endregion
111
193
  export { DefaultServiceOptions, RestateEndpoint, RestateEndpointBase };
@@ -1 +1 @@
1
- {"version":3,"file":"endpoint.d.ts","names":[],"sources":["../src/endpoint.ts"],"sourcesContent":[],"mappings":";;;;;;KAyBY,qBAAA,GAAwB,iBAClC,gBACA;UAEe;EAJL;;;;;EAIK,IAAA,CAAA,UAAA,MAAA,EAAmB,CAAA,CAAA,CAAA,OAAA,EAQ5B,iBAR4B,CAQV,CARU,EAQP,CARO,CAAA,GAS5B,uBAT4B,CASJ,CATI,EASD,CATC,CAAA,GAU5B,kBAV4B,CAUT,CAVS,EAUN,CAVM,CAAA,CAAA,EAW/B,CAX+B;EAQV;;;;;;;;;EAGrB,cAAA,CAAA,GAAA,IAAA,EAAA,MAAA,EAAA,CAAA,EAWgC,CAXhC;EAWgC;;;;;;;EAwCyC,qBAAA,CAAA,OAAA,EA/B7C,qBA+B6C,CAAA,EA/BrB,CA+BqB;EAAC;AAqB/E;;;;;;;;;;;;;;;;;;;;oBA7BoB,kBAAkB;;;;;;;iDAQW,QAAQ,qBAAqB;;;;;;;;;;;;;;;;;;;;UAqB7D,eAAA,SAAwB,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;yBAuBpC;;;;4BAMZ,8BACC"}
1
+ {"version":3,"file":"endpoint.d.ts","names":[],"sources":["../src/endpoint.ts"],"sourcesContent":[],"mappings":";;;;;;;KA0BY,qBAAA,GAAwB,iBAClC,gBACA;UAEe;EAJL;;;;;EAIK,IAAA,CAAA,UAAA,MAAA,EAAmB,CAAA,CAAA,CAAA,OAAA,EAQ5B,iBAR4B,CAQV,CARU,EAQP,CARO,CAAA,GAS5B,uBAT4B,CASJ,CATI,EASD,CATC,CAAA,GAU5B,kBAV4B,CAUT,CAVS,EAUN,CAVM,CAAA,CAAA,EAW/B,CAX+B;EAQV;;;;;;;;;EAGrB,cAAA,CAAA,GAAA,IAAA,EAAA,MAAA,EAAA,CAAA,EAWgC,CAXhC;EAWgC;;;;;;;EAwCyC,qBAAA,CAAA,OAAA,EA/B7C,qBA+B6C,CAAA,EA/BrB,CA+BqB;EAAC;AA8C/E;;;;;;;;;;;;;;;;;;;;oBAtDoB,kBAAkB;;;;;;;iDAQW,QAAQ,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UA8C7D,eAAA,SAAwB,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;yBAuBpC;;;;;;;;;;;gBAYT,8BAA8B;;;;;;;;;;;;;;;;;;;;gBAqB9B,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;cA0B7B,2BAA2B;cAC3B,8BAA8B"}
@@ -0,0 +1,26 @@
1
+ const require_errors = require('./types/errors.cjs');
2
+ const require_context_impl = require('./context_impl.cjs');
3
+
4
+ //#region src/error_sanitization.ts
5
+ /**
6
+ * Strips SDK-internal metadata from an error before it enters the interceptor
7
+ * chain. Interceptors see a plain Error — no CommandError.
8
+ */
9
+ function sanitizeError(e) {
10
+ if (e instanceof require_context_impl.CommandError) return require_errors.ensureError(e.cause);
11
+ return require_errors.ensureError(e);
12
+ }
13
+ /**
14
+ * Restores SDK-internal metadata after the interceptor chain exits, using the
15
+ * original error's metadata and the interceptor's error as the new cause.
16
+ * If the original had no SDK metadata, the interceptor's error passes through
17
+ * unchanged.
18
+ */
19
+ function restoreError(interceptorError, original) {
20
+ if (original instanceof require_context_impl.CommandError) return original.commandIndex !== void 0 ? new require_context_impl.CommandError(interceptorError, original.commandType, original.commandIndex) : new require_context_impl.CommandError(interceptorError, original.commandType);
21
+ return interceptorError;
22
+ }
23
+
24
+ //#endregion
25
+ exports.restoreError = restoreError;
26
+ exports.sanitizeError = sanitizeError;
@@ -0,0 +1,26 @@
1
+ import { ensureError } from "./types/errors.js";
2
+ import { CommandError } from "./context_impl.js";
3
+
4
+ //#region src/error_sanitization.ts
5
+ /**
6
+ * Strips SDK-internal metadata from an error before it enters the interceptor
7
+ * chain. Interceptors see a plain Error — no CommandError.
8
+ */
9
+ function sanitizeError(e) {
10
+ if (e instanceof CommandError) return ensureError(e.cause);
11
+ return ensureError(e);
12
+ }
13
+ /**
14
+ * Restores SDK-internal metadata after the interceptor chain exits, using the
15
+ * original error's metadata and the interceptor's error as the new cause.
16
+ * If the original had no SDK metadata, the interceptor's error passes through
17
+ * unchanged.
18
+ */
19
+ function restoreError(interceptorError, original) {
20
+ if (original instanceof CommandError) return original.commandIndex !== void 0 ? new CommandError(interceptorError, original.commandType, original.commandIndex) : new CommandError(interceptorError, original.commandType);
21
+ return interceptorError;
22
+ }
23
+
24
+ //#endregion
25
+ export { restoreError, sanitizeError };
26
+ //# sourceMappingURL=error_sanitization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error_sanitization.js","names":[],"sources":["../src/error_sanitization.ts"],"sourcesContent":["/*\n * Copyright (c) 2023-2024 - Restate Software, Inc., Restate GmbH\n *\n * This file is part of the Restate SDK for Node.js/TypeScript,\n * which is released under the MIT license.\n *\n * You can find a copy of the license in file LICENSE in the root\n * directory of this repository or package, or at\n * https://github.com/restatedev/sdk-typescript/blob/main/LICENSE\n */\n\nimport { CommandError } from \"./context_impl.js\";\nimport { ensureError } from \"./types/errors.js\";\n\n/**\n * Strips SDK-internal metadata from an error before it enters the interceptor\n * chain. Interceptors see a plain Error — no CommandError.\n */\nexport function sanitizeError(e: unknown): Error {\n if (e instanceof CommandError) return ensureError(e.cause);\n return ensureError(e);\n}\n\n/**\n * Restores SDK-internal metadata after the interceptor chain exits, using the\n * original error's metadata and the interceptor's error as the new cause.\n * If the original had no SDK metadata, the interceptor's error passes through\n * unchanged.\n */\nexport function restoreError(\n interceptorError: unknown,\n original: unknown\n): unknown {\n if (original instanceof CommandError) {\n return original.commandIndex !== undefined\n ? new CommandError(\n interceptorError,\n original.commandType,\n original.commandIndex\n )\n : new CommandError(interceptorError, original.commandType);\n }\n return interceptorError;\n}\n"],"mappings":";;;;;;;;AAkBA,SAAgB,cAAc,GAAmB;AAC/C,KAAI,aAAa,aAAc,QAAO,YAAY,EAAE,MAAM;AAC1D,QAAO,YAAY,EAAE;;;;;;;;AASvB,SAAgB,aACd,kBACA,UACS;AACT,KAAI,oBAAoB,aACtB,QAAO,SAAS,iBAAiB,SAC7B,IAAI,aACF,kBACA,SAAS,aACT,SAAS,aACV,GACD,IAAI,aAAa,kBAAkB,SAAS,YAAY;AAE9D,QAAO"}
package/dist/fetch.cjs CHANGED
@@ -1,7 +1,8 @@
1
1
  const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
2
  const require_errors = require('./types/errors.cjs');
3
- const require_rpc = require('./types/rpc.cjs');
3
+ const require_promises = require('./promises.cjs');
4
4
  const require_context = require('./context.cjs');
5
+ const require_rpc = require('./types/rpc.cjs');
5
6
  const require_internal = require('./internal.cjs');
6
7
  const require_common_api = require('./common_api.cjs');
7
8
  const require_fetch_endpoint = require('./endpoint/fetch_endpoint.cjs');
@@ -73,6 +74,7 @@ Object.defineProperty(exports, 'internal', {
73
74
  return require_internal.internal_exports;
74
75
  }
75
76
  });
77
+ exports.isRestatePromise = require_promises.isRestatePromise;
76
78
  exports.object = require_rpc.object;
77
79
  Object.defineProperty(exports, 'rpc', {
78
80
  enumerable: true,
package/dist/fetch.d.cts CHANGED
@@ -1,10 +1,12 @@
1
1
  import { CancelledError, RestateError, RetryableError, RetryableErrorOptions, TerminalError, TimeoutError } from "./types/errors.cjs";
2
+ import { Hooks, HooksProvider, Interceptor } from "./hooks.cjs";
2
3
  import { Client, ClientCallOptions, ClientSendOptions, InferArg, ObjectHandlerOpts, ObjectOptions, ObjectOpts, Opts, RemoveVoidArgument, RetryPolicy, SendClient, SendOpts, ServiceHandlerOpts, ServiceOptions, ServiceOpts, WorkflowHandlerOpts, WorkflowOptions, WorkflowOpts, handlers, object, rpc, service, workflow } from "./types/rpc.cjs";
3
- import { Context, ContextDate, DurablePromise, GenericCall, GenericSend, InvocationHandle, InvocationId, InvocationIdParser, InvocationPromise, KeyValueStore, ObjectContext, ObjectSharedContext, Rand, Request as Request$1, RestatePromise, RunAction, RunOptions, SendOptions, TypedState, UntypedState, WorkflowContext, WorkflowSharedContext } from "./context.cjs";
4
+ import { Context, ContextDate, DurablePromise, GenericCall, GenericSend, InvocationHandle, InvocationId, InvocationIdParser, InvocationPromise, KeyValueStore, ObjectContext, ObjectSharedContext, Rand, Request as Request$1, RestatePromise, RunAction, RunOptions, Target, TypedState, UntypedState, WorkflowContext, WorkflowSharedContext } from "./context.cjs";
5
+ import { internal_d_exports } from "./internal.cjs";
4
6
  import { LogMetadata, LogSource, LoggerContext, LoggerTransport, RestateLogLevel } from "./logging/logger_transport.cjs";
5
7
  import { DefaultServiceOptions, RestateEndpoint, RestateEndpointBase } from "./endpoint.cjs";
8
+ import { isRestatePromise } from "./promises.cjs";
6
9
  import { EndpointOptions } from "./endpoint/types.cjs";
7
- import { internal_d_exports } from "./internal.cjs";
8
10
  import { CombineablePromise, Duration, JournalValueCodec, ObjectHandler, RestateContext, RestateObjectContext, RestateObjectSharedContext, RestateWorkflowContext, RestateWorkflowSharedContext, Serde, Service, ServiceDefinition, ServiceDefinitionFrom, ServiceHandler, VirtualObject, VirtualObjectDefinition, VirtualObjectDefinitionFrom, Workflow, WorkflowDefinition, WorkflowDefinitionFrom, WorkflowHandler, WorkflowSharedHandler, createObjectHandler, createObjectSharedHandler, createServiceHandler, createWorkflowHandler, createWorkflowSharedHandler, serde } from "./common_api.cjs";
9
11
  import { FetchEndpoint } from "./endpoint/fetch_endpoint.cjs";
10
12
 
@@ -49,5 +51,5 @@ interface FetchEndpointOptions extends EndpointOptions {
49
51
  */
50
52
  declare function createEndpointHandler(options: FetchEndpointOptions): (request: Request, ...extraArgs: unknown[]) => Promise<Response>;
51
53
  //#endregion
52
- export { CancelledError, Client, ClientCallOptions, ClientSendOptions, CombineablePromise, Context, ContextDate, DefaultServiceOptions, DurablePromise, Duration, EndpointOptions, type FetchEndpoint, FetchEndpointOptions, GenericCall, GenericSend, InferArg, InvocationHandle, InvocationId, InvocationIdParser, InvocationPromise, JournalValueCodec, KeyValueStore, LogMetadata, LogSource, LoggerContext, LoggerTransport, ObjectContext, ObjectHandler, ObjectHandlerOpts, ObjectOptions, ObjectOpts, ObjectSharedContext, Opts, Rand, RemoveVoidArgument, Request$1 as Request, RestateContext, RestateEndpoint, RestateEndpointBase, RestateError, RestateLogLevel, RestateObjectContext, RestateObjectSharedContext, RestatePromise, RestateWorkflowContext, RestateWorkflowSharedContext, RetryPolicy, RetryableError, RetryableErrorOptions, RunAction, RunOptions, SendClient, SendOptions, SendOpts, Serde, Service, ServiceDefinition, ServiceDefinitionFrom, ServiceHandler, ServiceHandlerOpts, ServiceOptions, ServiceOpts, TerminalError, TimeoutError, TypedState, UntypedState, VirtualObject, VirtualObjectDefinition, VirtualObjectDefinitionFrom, Workflow, WorkflowContext, WorkflowDefinition, WorkflowDefinitionFrom, WorkflowHandler, WorkflowHandlerOpts, WorkflowOptions, WorkflowOpts, WorkflowSharedContext, WorkflowSharedHandler, createEndpointHandler, createObjectHandler, createObjectSharedHandler, createServiceHandler, createWorkflowHandler, createWorkflowSharedHandler, endpoint, handlers, internal_d_exports as internal, object, rpc, serde, service, workflow };
54
+ export { CancelledError, Client, ClientCallOptions, ClientSendOptions, CombineablePromise, Context, ContextDate, DefaultServiceOptions, DurablePromise, Duration, EndpointOptions, type FetchEndpoint, FetchEndpointOptions, GenericCall, GenericSend, Hooks, HooksProvider, InferArg, Interceptor, InvocationHandle, InvocationId, InvocationIdParser, InvocationPromise, JournalValueCodec, KeyValueStore, LogMetadata, LogSource, LoggerContext, LoggerTransport, ObjectContext, ObjectHandler, ObjectHandlerOpts, ObjectOptions, ObjectOpts, ObjectSharedContext, Opts, Rand, RemoveVoidArgument, Request$1 as Request, RestateContext, RestateEndpoint, RestateEndpointBase, RestateError, RestateLogLevel, RestateObjectContext, RestateObjectSharedContext, RestatePromise, RestateWorkflowContext, RestateWorkflowSharedContext, RetryPolicy, RetryableError, RetryableErrorOptions, RunAction, RunOptions, SendClient, SendOpts, Serde, Service, ServiceDefinition, ServiceDefinitionFrom, ServiceHandler, ServiceHandlerOpts, ServiceOptions, ServiceOpts, Target, TerminalError, TimeoutError, TypedState, UntypedState, VirtualObject, VirtualObjectDefinition, VirtualObjectDefinitionFrom, Workflow, WorkflowContext, WorkflowDefinition, WorkflowDefinitionFrom, WorkflowHandler, WorkflowHandlerOpts, WorkflowOptions, WorkflowOpts, WorkflowSharedContext, WorkflowSharedHandler, createEndpointHandler, createObjectHandler, createObjectSharedHandler, createServiceHandler, createWorkflowHandler, createWorkflowSharedHandler, endpoint, handlers, internal_d_exports as internal, isRestatePromise, object, rpc, serde, service, workflow };
53
55
  //# sourceMappingURL=fetch.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.d.cts","names":[],"sources":["../src/fetch.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;iBAyBgB,QAAA,CAAA,GAAY;UAIX,oBAAA,SAA6B;;AAJ9C;AAIA;AAiCA;;;;;EAAmE,aAAA,CAAA,EAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;iBAAnD,qBAAA,UAA+B,iCAAoB,qCAAA,QAAA"}
1
+ {"version":3,"file":"fetch.d.cts","names":[],"sources":["../src/fetch.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;iBAyBgB,QAAA,CAAA,GAAY;UAIX,oBAAA,SAA6B;;;;AAJ9C;AAIA;AAiCA;;;EAAmE,aAAA,CAAA,EAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;iBAAnD,qBAAA,UAA+B,iCAAoB,qCAAA,QAAA"}
package/dist/fetch.d.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  import { CancelledError, RestateError, RetryableError, RetryableErrorOptions, TerminalError, TimeoutError } from "./types/errors.js";
2
+ import { Hooks, HooksProvider, Interceptor } from "./hooks.js";
2
3
  import { Client, ClientCallOptions, ClientSendOptions, InferArg, ObjectHandlerOpts, ObjectOptions, ObjectOpts, Opts, RemoveVoidArgument, RetryPolicy, SendClient, SendOpts, ServiceHandlerOpts, ServiceOptions, ServiceOpts, WorkflowHandlerOpts, WorkflowOptions, WorkflowOpts, handlers, object, rpc, service, workflow } from "./types/rpc.js";
3
- import { Context, ContextDate, DurablePromise, GenericCall, GenericSend, InvocationHandle, InvocationId, InvocationIdParser, InvocationPromise, KeyValueStore, ObjectContext, ObjectSharedContext, Rand, Request as Request$1, RestatePromise, RunAction, RunOptions, SendOptions, TypedState, UntypedState, WorkflowContext, WorkflowSharedContext } from "./context.js";
4
+ import { Context, ContextDate, DurablePromise, GenericCall, GenericSend, InvocationHandle, InvocationId, InvocationIdParser, InvocationPromise, KeyValueStore, ObjectContext, ObjectSharedContext, Rand, Request as Request$1, RestatePromise, RunAction, RunOptions, Target, TypedState, UntypedState, WorkflowContext, WorkflowSharedContext } from "./context.js";
5
+ import { internal_d_exports } from "./internal.js";
4
6
  import { LogMetadata, LogSource, LoggerContext, LoggerTransport, RestateLogLevel } from "./logging/logger_transport.js";
5
7
  import { DefaultServiceOptions, RestateEndpoint, RestateEndpointBase } from "./endpoint.js";
8
+ import { isRestatePromise } from "./promises.js";
6
9
  import { EndpointOptions } from "./endpoint/types.js";
7
- import { internal_d_exports } from "./internal.js";
8
10
  import { CombineablePromise, Duration, JournalValueCodec, ObjectHandler, RestateContext, RestateObjectContext, RestateObjectSharedContext, RestateWorkflowContext, RestateWorkflowSharedContext, Serde, Service, ServiceDefinition, ServiceDefinitionFrom, ServiceHandler, VirtualObject, VirtualObjectDefinition, VirtualObjectDefinitionFrom, Workflow, WorkflowDefinition, WorkflowDefinitionFrom, WorkflowHandler, WorkflowSharedHandler, createObjectHandler, createObjectSharedHandler, createServiceHandler, createWorkflowHandler, createWorkflowSharedHandler, serde } from "./common_api.js";
9
11
  import { FetchEndpoint } from "./endpoint/fetch_endpoint.js";
10
12
 
@@ -49,5 +51,5 @@ interface FetchEndpointOptions extends EndpointOptions {
49
51
  */
50
52
  declare function createEndpointHandler(options: FetchEndpointOptions): (request: Request, ...extraArgs: unknown[]) => Promise<Response>;
51
53
  //#endregion
52
- export { CancelledError, Client, ClientCallOptions, ClientSendOptions, CombineablePromise, Context, ContextDate, DefaultServiceOptions, DurablePromise, Duration, EndpointOptions, type FetchEndpoint, FetchEndpointOptions, GenericCall, GenericSend, InferArg, InvocationHandle, InvocationId, InvocationIdParser, InvocationPromise, JournalValueCodec, KeyValueStore, LogMetadata, LogSource, LoggerContext, LoggerTransport, ObjectContext, ObjectHandler, ObjectHandlerOpts, ObjectOptions, ObjectOpts, ObjectSharedContext, Opts, Rand, RemoveVoidArgument, Request$1 as Request, RestateContext, RestateEndpoint, RestateEndpointBase, RestateError, RestateLogLevel, RestateObjectContext, RestateObjectSharedContext, RestatePromise, RestateWorkflowContext, RestateWorkflowSharedContext, RetryPolicy, RetryableError, RetryableErrorOptions, RunAction, RunOptions, SendClient, SendOptions, SendOpts, Serde, Service, ServiceDefinition, ServiceDefinitionFrom, ServiceHandler, ServiceHandlerOpts, ServiceOptions, ServiceOpts, TerminalError, TimeoutError, TypedState, UntypedState, VirtualObject, VirtualObjectDefinition, VirtualObjectDefinitionFrom, Workflow, WorkflowContext, WorkflowDefinition, WorkflowDefinitionFrom, WorkflowHandler, WorkflowHandlerOpts, WorkflowOptions, WorkflowOpts, WorkflowSharedContext, WorkflowSharedHandler, createEndpointHandler, createObjectHandler, createObjectSharedHandler, createServiceHandler, createWorkflowHandler, createWorkflowSharedHandler, endpoint, handlers, internal_d_exports as internal, object, rpc, serde, service, workflow };
54
+ export { CancelledError, Client, ClientCallOptions, ClientSendOptions, CombineablePromise, Context, ContextDate, DefaultServiceOptions, DurablePromise, Duration, EndpointOptions, type FetchEndpoint, FetchEndpointOptions, GenericCall, GenericSend, Hooks, HooksProvider, InferArg, Interceptor, InvocationHandle, InvocationId, InvocationIdParser, InvocationPromise, JournalValueCodec, KeyValueStore, LogMetadata, LogSource, LoggerContext, LoggerTransport, ObjectContext, ObjectHandler, ObjectHandlerOpts, ObjectOptions, ObjectOpts, ObjectSharedContext, Opts, Rand, RemoveVoidArgument, Request$1 as Request, RestateContext, RestateEndpoint, RestateEndpointBase, RestateError, RestateLogLevel, RestateObjectContext, RestateObjectSharedContext, RestatePromise, RestateWorkflowContext, RestateWorkflowSharedContext, RetryPolicy, RetryableError, RetryableErrorOptions, RunAction, RunOptions, SendClient, SendOpts, Serde, Service, ServiceDefinition, ServiceDefinitionFrom, ServiceHandler, ServiceHandlerOpts, ServiceOptions, ServiceOpts, Target, TerminalError, TimeoutError, TypedState, UntypedState, VirtualObject, VirtualObjectDefinition, VirtualObjectDefinitionFrom, Workflow, WorkflowContext, WorkflowDefinition, WorkflowDefinitionFrom, WorkflowHandler, WorkflowHandlerOpts, WorkflowOptions, WorkflowOpts, WorkflowSharedContext, WorkflowSharedHandler, createEndpointHandler, createObjectHandler, createObjectSharedHandler, createServiceHandler, createWorkflowHandler, createWorkflowSharedHandler, endpoint, handlers, internal_d_exports as internal, isRestatePromise, object, rpc, serde, service, workflow };
53
55
  //# sourceMappingURL=fetch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.d.ts","names":[],"sources":["../src/fetch.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;iBAyBgB,QAAA,CAAA,GAAY;UAIX,oBAAA,SAA6B;;AAJ9C;AAIA;AAiCA;;;;;EAAmE,aAAA,CAAA,EAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;iBAAnD,qBAAA,UAA+B,iCAAoB,qCAAA,QAAA"}
1
+ {"version":3,"file":"fetch.d.ts","names":[],"sources":["../src/fetch.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;iBAyBgB,QAAA,CAAA,GAAY;UAIX,oBAAA,SAA6B;;;;AAJ9C;AAIA;AAiCA;;;EAAmE,aAAA,CAAA,EAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;iBAAnD,qBAAA,UAA+B,iCAAoB,qCAAA,QAAA"}
package/dist/fetch.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.js","names":[],"sources":["../src/fetch.ts"],"sourcesContent":["/*\n * Copyright (c) 2023-2024 - Restate Software, Inc., Restate GmbH\n *\n * This file is part of the Restate SDK for Node.js/TypeScript,\n * which is released under the MIT license.\n *\n * You can find a copy of the license in file LICENSE in the root\n * directory of this repository or package, or at\n * https://github.com/restatedev/sdk-typescript/blob/main/LICENSE\n */\n\nexport * from \"./common_api.js\";\n\nimport {\n type FetchEndpoint,\n FetchEndpointImpl,\n} from \"./endpoint/fetch_endpoint.js\";\nimport type { EndpointOptions } from \"./endpoint/types.js\";\nimport { withOptions } from \"./endpoint/withOptions.js\";\n\n/**\n * Create a new {@link RestateEndpoint} in request response protocol mode.\n * Bidirectional mode (must be served over http2) can be enabled with .enableHttp2()\n * @deprecated Please use {@link createEndpointHandler}\n */\nexport function endpoint(): FetchEndpoint {\n return new FetchEndpointImpl(\"REQUEST_RESPONSE\");\n}\n\nexport interface FetchEndpointOptions extends EndpointOptions {\n /**\n * Enables bidirectional communication for the handler.\n *\n * When set to `true`, the handler supports bidirectional streaming (e.g., via HTTP/2 or compatible HTTP/1.1 servers).\n * When `false`, the handler operates in request-response mode only.\n *\n * @default false\n */\n bidirectional?: boolean;\n}\n\n/**\n * Creates a Fetch handler that encapsulates all the Restate services served by this endpoint.\n *\n * @param {FetchEndpointOptions} options - Configuration options for the endpoint handler.\n * @returns A fetch handler function.\n *\n * @example\n * A typical request-response handler would look like this:\n * ```\n * import { createEndpointHandler } from \"@restatedev/restate-sdk/fetch\";\n *\n * export const handler = createEndpointHandler({ services: [myService] })\n *\n * @example\n * A typical bidirectional handler (works with http2 and some http1.1 servers) would look like this:\n * ```\n * import { createEndpointHandler } from \"@restatedev/restate-sdk/fetch\";\n *\n * export const handler = createEndpointHandler({ services: [myService], bidirectional: true })\n *\n */\nexport function createEndpointHandler(options: FetchEndpointOptions) {\n return withOptions<FetchEndpoint>(\n new FetchEndpointImpl(\n options.bidirectional ? \"BIDI_STREAM\" : \"REQUEST_RESPONSE\"\n ),\n options\n ).handler().fetch;\n}\nexport { type FetchEndpoint } from \"./endpoint/fetch_endpoint.js\";\n"],"mappings":";;;;;;;;;;;;;;AAyBA,SAAgB,WAA0B;AACxC,QAAO,IAAI,kBAAkB,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;AAoClD,SAAgB,sBAAsB,SAA+B;AACnE,QAAO,YACL,IAAI,kBACF,QAAQ,gBAAgB,gBAAgB,mBACzC,EACD,QACD,CAAC,SAAS,CAAC"}
1
+ {"version":3,"file":"fetch.js","names":[],"sources":["../src/fetch.ts"],"sourcesContent":["/*\n * Copyright (c) 2023-2024 - Restate Software, Inc., Restate GmbH\n *\n * This file is part of the Restate SDK for Node.js/TypeScript,\n * which is released under the MIT license.\n *\n * You can find a copy of the license in file LICENSE in the root\n * directory of this repository or package, or at\n * https://github.com/restatedev/sdk-typescript/blob/main/LICENSE\n */\n\nexport * from \"./common_api.js\";\n\nimport {\n type FetchEndpoint,\n FetchEndpointImpl,\n} from \"./endpoint/fetch_endpoint.js\";\nimport type { EndpointOptions } from \"./endpoint/types.js\";\nimport { withOptions } from \"./endpoint/withOptions.js\";\n\n/**\n * Create a new {@link RestateEndpoint} in request response protocol mode.\n * Bidirectional mode (must be served over http2) can be enabled with .enableHttp2()\n * @deprecated Please use {@link createEndpointHandler}\n */\nexport function endpoint(): FetchEndpoint {\n return new FetchEndpointImpl(\"REQUEST_RESPONSE\");\n}\n\nexport interface FetchEndpointOptions extends EndpointOptions {\n /**\n * Enables bidirectional communication for the handler.\n *\n * When set to `true`, the handler supports bidirectional streaming (e.g., via HTTP/2 or compatible HTTP/1.1 servers).\n * When `false`, the handler operates in request-response mode only.\n *\n * @default false\n */\n bidirectional?: boolean;\n}\n\n/**\n * Creates a Fetch handler that encapsulates all the Restate services served by this endpoint.\n *\n * @param {FetchEndpointOptions} options - Configuration options for the endpoint handler.\n * @returns A fetch handler function.\n *\n * @example\n * A typical request-response handler would look like this:\n * ```\n * import { createEndpointHandler } from \"@restatedev/restate-sdk/fetch\";\n *\n * export const handler = createEndpointHandler({ services: [myService] })\n *\n * @example\n * A typical bidirectional handler (works with http2 and some http1.1 servers) would look like this:\n * ```\n * import { createEndpointHandler } from \"@restatedev/restate-sdk/fetch\";\n *\n * export const handler = createEndpointHandler({ services: [myService], bidirectional: true })\n *\n */\nexport function createEndpointHandler(options: FetchEndpointOptions) {\n return withOptions<FetchEndpoint>(\n new FetchEndpointImpl(\n options.bidirectional ? \"BIDI_STREAM\" : \"REQUEST_RESPONSE\"\n ),\n options\n ).handler().fetch;\n}\nexport { type FetchEndpoint } from \"./endpoint/fetch_endpoint.js\";\n"],"mappings":";;;;;;;;;;;;;;;AAyBA,SAAgB,WAA0B;AACxC,QAAO,IAAI,kBAAkB,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;AAoClD,SAAgB,sBAAsB,SAA+B;AACnE,QAAO,YACL,IAAI,kBACF,QAAQ,gBAAgB,gBAAgB,mBACzC,EACD,QACD,CAAC,SAAS,CAAC"}
@@ -0,0 +1,87 @@
1
+ import { Request } from "./context.cjs";
2
+
3
+ //#region src/hooks.d.ts
4
+
5
+ /**
6
+ * Interceptors wrap handler and ctx.run() execution. They are part of the
7
+ * invocation — anything that happens inside them (including after `next()`)
8
+ * affects the invocation outcome.
9
+ *
10
+ * ## Error behavior
11
+ *
12
+ * Errors thrown at any point (before or after `next()`) affect the invocation:
13
+ *
14
+ * - **{@link TerminalError}** — the invocation **fails immediately**, no retry.
15
+ * - **Any other error** — Restate **retries** the invocation.
16
+ * - On suspension or pause, `next()` also rejects with an error. This does not
17
+ * mean the invocation failed — the attempt is simply ending. Do any cleanup
18
+ * you need and rethrow.
19
+ *
20
+ * ## Output
21
+ *
22
+ * Interceptors **cannot alter the handler's success return value** (the `void`
23
+ * signature means there is no way to replace it), but they **can transform
24
+ * errors** by catching and rethrowing a different error.
25
+ *
26
+ * ## Rules
27
+ *
28
+ * - `next()` must be called exactly once.
29
+ *
30
+ * ## When interceptors fire
31
+ *
32
+ * - `handler` fires on every attempt.
33
+ * - `run` fires when the `ctx.run()` closure executes. If the result is
34
+ * already in the journal, the closure is skipped and so is the interceptor.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * interceptor: {
39
+ * handler: async (next) => {
40
+ * console.log(`before ${ctx.request.target}`);
41
+ * try {
42
+ * await next();
43
+ * console.log(`after ${ctx.request.target}`);
44
+ * } catch (e) {
45
+ * console.log(`error ${ctx.request.target}: ${e}`);
46
+ * // Always rethrow — swallowing the error changes the
47
+ * // invocation outcome. You can also throw a different
48
+ * // error (e.g. TerminalError to fail immediately).
49
+ * throw e;
50
+ * }
51
+ * },
52
+ * run: async (name, next) => {
53
+ * console.log(` before run "${name}"`);
54
+ * try {
55
+ * await next();
56
+ * console.log(` after run "${name}"`);
57
+ * } catch (e) {
58
+ * console.log(` error run "${name}": ${e}`);
59
+ * throw e;
60
+ * }
61
+ * },
62
+ * }
63
+ * ```
64
+ */
65
+ interface Interceptor {
66
+ /** Wraps the entire handler invocation. Fires on every attempt. */
67
+ handler?: (next: () => Promise<void>) => Promise<void>;
68
+ /**
69
+ * Wraps each `ctx.run()` call. Only fires for runs that actually execute —
70
+ * replayed runs (already in the journal) are skipped.
71
+ * `name` is the run's label.
72
+ */
73
+ run?: (name: string, next: () => Promise<void>) => Promise<void>;
74
+ }
75
+ interface Hooks {
76
+ interceptor?: Interceptor;
77
+ }
78
+ /**
79
+ * Factory called on every attempt. Receives the invocation request,
80
+ * returns hooks for that attempt's lifetime. Each attempt gets a fresh call.
81
+ */
82
+ type HooksProvider = (ctx: {
83
+ request: Request;
84
+ }) => Hooks;
85
+ //#endregion
86
+ export { Hooks, HooksProvider, Interceptor };
87
+ //# sourceMappingURL=hooks.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.d.cts","names":[],"sources":["../src/hooks.ts"],"sourcesContent":[],"mappings":";;;;;;AAgEA;;;;;;AAaA;AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAvBiB,WAAA;;yBAEQ,kBAAkB;;;;;;mCAMR,kBAAkB;;UAKpC,KAAA;gBACD;;;;;;KASJ,aAAA;WAAiC;MAAc"}
@@ -0,0 +1,87 @@
1
+ import { Request } from "./context.js";
2
+
3
+ //#region src/hooks.d.ts
4
+
5
+ /**
6
+ * Interceptors wrap handler and ctx.run() execution. They are part of the
7
+ * invocation — anything that happens inside them (including after `next()`)
8
+ * affects the invocation outcome.
9
+ *
10
+ * ## Error behavior
11
+ *
12
+ * Errors thrown at any point (before or after `next()`) affect the invocation:
13
+ *
14
+ * - **{@link TerminalError}** — the invocation **fails immediately**, no retry.
15
+ * - **Any other error** — Restate **retries** the invocation.
16
+ * - On suspension or pause, `next()` also rejects with an error. This does not
17
+ * mean the invocation failed — the attempt is simply ending. Do any cleanup
18
+ * you need and rethrow.
19
+ *
20
+ * ## Output
21
+ *
22
+ * Interceptors **cannot alter the handler's success return value** (the `void`
23
+ * signature means there is no way to replace it), but they **can transform
24
+ * errors** by catching and rethrowing a different error.
25
+ *
26
+ * ## Rules
27
+ *
28
+ * - `next()` must be called exactly once.
29
+ *
30
+ * ## When interceptors fire
31
+ *
32
+ * - `handler` fires on every attempt.
33
+ * - `run` fires when the `ctx.run()` closure executes. If the result is
34
+ * already in the journal, the closure is skipped and so is the interceptor.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * interceptor: {
39
+ * handler: async (next) => {
40
+ * console.log(`before ${ctx.request.target}`);
41
+ * try {
42
+ * await next();
43
+ * console.log(`after ${ctx.request.target}`);
44
+ * } catch (e) {
45
+ * console.log(`error ${ctx.request.target}: ${e}`);
46
+ * // Always rethrow — swallowing the error changes the
47
+ * // invocation outcome. You can also throw a different
48
+ * // error (e.g. TerminalError to fail immediately).
49
+ * throw e;
50
+ * }
51
+ * },
52
+ * run: async (name, next) => {
53
+ * console.log(` before run "${name}"`);
54
+ * try {
55
+ * await next();
56
+ * console.log(` after run "${name}"`);
57
+ * } catch (e) {
58
+ * console.log(` error run "${name}": ${e}`);
59
+ * throw e;
60
+ * }
61
+ * },
62
+ * }
63
+ * ```
64
+ */
65
+ interface Interceptor {
66
+ /** Wraps the entire handler invocation. Fires on every attempt. */
67
+ handler?: (next: () => Promise<void>) => Promise<void>;
68
+ /**
69
+ * Wraps each `ctx.run()` call. Only fires for runs that actually execute —
70
+ * replayed runs (already in the journal) are skipped.
71
+ * `name` is the run's label.
72
+ */
73
+ run?: (name: string, next: () => Promise<void>) => Promise<void>;
74
+ }
75
+ interface Hooks {
76
+ interceptor?: Interceptor;
77
+ }
78
+ /**
79
+ * Factory called on every attempt. Receives the invocation request,
80
+ * returns hooks for that attempt's lifetime. Each attempt gets a fresh call.
81
+ */
82
+ type HooksProvider = (ctx: {
83
+ request: Request;
84
+ }) => Hooks;
85
+ //#endregion
86
+ export { Hooks, HooksProvider, Interceptor };
87
+ //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.d.ts","names":[],"sources":["../src/hooks.ts"],"sourcesContent":[],"mappings":";;;;;;AAgEA;;;;;;AAaA;AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAvBiB,WAAA;;yBAEQ,kBAAkB;;;;;;mCAMR,kBAAkB;;UAKpC,KAAA;gBACD;;;;;;KASJ,aAAA;WAAiC;MAAc"}
package/dist/index.cjs CHANGED
@@ -1,7 +1,8 @@
1
1
  const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
2
  const require_errors = require('./types/errors.cjs');
3
- const require_rpc = require('./types/rpc.cjs');
3
+ const require_promises = require('./promises.cjs');
4
4
  const require_context = require('./context.cjs');
5
+ const require_rpc = require('./types/rpc.cjs');
5
6
  const require_internal = require('./internal.cjs');
6
7
  const require_common_api = require('./common_api.cjs');
7
8
  const require_node = require('./node.cjs');
@@ -37,6 +38,7 @@ Object.defineProperty(exports, 'internal', {
37
38
  return require_internal.internal_exports;
38
39
  }
39
40
  });
41
+ exports.isRestatePromise = require_promises.isRestatePromise;
40
42
  exports.object = require_rpc.object;
41
43
  Object.defineProperty(exports, 'rpc', {
42
44
  enumerable: true,