@restatedev/restate-sdk-cloudflare-workers 1.7.3 → 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 (87) hide show
  1. package/dist/esm/src/common_api.d.ts +3 -2
  2. package/dist/esm/src/common_api.d.ts.map +1 -1
  3. package/dist/esm/src/common_api.js +1 -1
  4. package/dist/esm/src/common_api.js.map +1 -1
  5. package/dist/esm/src/context.d.ts +66 -47
  6. package/dist/esm/src/context.d.ts.map +1 -1
  7. package/dist/esm/src/context.js.map +1 -1
  8. package/dist/esm/src/context_impl.d.ts.map +1 -1
  9. package/dist/esm/src/context_impl.js +9 -1
  10. package/dist/esm/src/context_impl.js.map +1 -1
  11. package/dist/esm/src/{types → endpoint}/components.d.ts +2 -2
  12. package/dist/esm/src/endpoint/components.d.ts.map +1 -0
  13. package/dist/esm/src/{types → endpoint}/components.js +1 -1
  14. package/dist/esm/src/endpoint/components.js.map +1 -0
  15. package/dist/esm/src/endpoint/discovery.d.ts.map +1 -0
  16. package/dist/esm/src/endpoint/discovery.js.map +1 -0
  17. package/dist/esm/src/endpoint/endpoint.d.ts +33 -0
  18. package/dist/esm/src/endpoint/endpoint.d.ts.map +1 -0
  19. package/dist/esm/src/endpoint/endpoint.js +148 -0
  20. package/dist/esm/src/endpoint/endpoint.js.map +1 -0
  21. package/dist/esm/src/endpoint/fetch_endpoint.d.ts +3 -6
  22. package/dist/esm/src/endpoint/fetch_endpoint.d.ts.map +1 -1
  23. package/dist/esm/src/endpoint/fetch_endpoint.js +7 -12
  24. package/dist/esm/src/endpoint/fetch_endpoint.js.map +1 -1
  25. package/dist/esm/src/endpoint/handlers/generic.d.ts +4 -4
  26. package/dist/esm/src/endpoint/handlers/generic.d.ts.map +1 -1
  27. package/dist/esm/src/endpoint/handlers/generic.js +13 -4
  28. package/dist/esm/src/endpoint/handlers/generic.js.map +1 -1
  29. package/dist/esm/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.d.ts +2 -0
  30. package/dist/esm/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings_bg.js +31 -0
  31. package/dist/esm/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings_bg.wasm +0 -0
  32. package/dist/esm/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings_bg.wasm.d.ts +2 -0
  33. package/dist/esm/src/endpoint/lambda_endpoint.d.ts +2 -5
  34. package/dist/esm/src/endpoint/lambda_endpoint.d.ts.map +1 -1
  35. package/dist/esm/src/endpoint/lambda_endpoint.js +7 -12
  36. package/dist/esm/src/endpoint/lambda_endpoint.js.map +1 -1
  37. package/dist/esm/src/endpoint/node_endpoint.d.ts +2 -5
  38. package/dist/esm/src/endpoint/node_endpoint.d.ts.map +1 -1
  39. package/dist/esm/src/endpoint/node_endpoint.js +54 -62
  40. package/dist/esm/src/endpoint/node_endpoint.js.map +1 -1
  41. package/dist/esm/src/endpoint/types.d.ts +48 -0
  42. package/dist/esm/src/endpoint/types.d.ts.map +1 -0
  43. package/dist/esm/src/endpoint/types.js +2 -0
  44. package/dist/esm/src/endpoint/types.js.map +1 -0
  45. package/dist/esm/src/endpoint/withOptions.d.ts +4 -0
  46. package/dist/esm/src/endpoint/withOptions.d.ts.map +1 -0
  47. package/dist/esm/src/endpoint/withOptions.js +16 -0
  48. package/dist/esm/src/endpoint/withOptions.js.map +1 -0
  49. package/dist/esm/src/endpoint.d.ts +23 -22
  50. package/dist/esm/src/endpoint.d.ts.map +1 -1
  51. package/dist/esm/src/fetch.d.ts +34 -0
  52. package/dist/esm/src/fetch.d.ts.map +1 -1
  53. package/dist/esm/src/fetch.js +37 -4
  54. package/dist/esm/src/fetch.js.map +1 -1
  55. package/dist/esm/src/generated/version.d.ts +1 -1
  56. package/dist/esm/src/generated/version.js +1 -1
  57. package/dist/esm/src/lambda.d.ts +16 -1
  58. package/dist/esm/src/lambda.d.ts.map +1 -1
  59. package/dist/esm/src/lambda.js +18 -1
  60. package/dist/esm/src/lambda.js.map +1 -1
  61. package/dist/esm/src/node.d.ts +38 -0
  62. package/dist/esm/src/node.d.ts.map +1 -0
  63. package/dist/esm/src/node.js +51 -0
  64. package/dist/esm/src/node.js.map +1 -0
  65. package/dist/esm/src/public_api.d.ts +1 -6
  66. package/dist/esm/src/public_api.d.ts.map +1 -1
  67. package/dist/esm/src/public_api.js +1 -8
  68. package/dist/esm/src/public_api.js.map +1 -1
  69. package/dist/esm/src/types/errors.d.ts +25 -0
  70. package/dist/esm/src/types/errors.d.ts.map +1 -1
  71. package/dist/esm/src/types/errors.js +29 -1
  72. package/dist/esm/src/types/errors.js.map +1 -1
  73. package/dist/esm/src/types/rpc.d.ts +19 -19
  74. package/dist/esm/src/types/rpc.js +19 -19
  75. package/dist/esm/src/user_agent.d.ts +1 -1
  76. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  77. package/package.json +2 -2
  78. package/dist/esm/src/endpoint/endpoint_builder.d.ts +0 -26
  79. package/dist/esm/src/endpoint/endpoint_builder.d.ts.map +0 -1
  80. package/dist/esm/src/endpoint/endpoint_builder.js +0 -139
  81. package/dist/esm/src/endpoint/endpoint_builder.js.map +0 -1
  82. package/dist/esm/src/types/components.d.ts.map +0 -1
  83. package/dist/esm/src/types/components.js.map +0 -1
  84. package/dist/esm/src/types/discovery.d.ts.map +0 -1
  85. package/dist/esm/src/types/discovery.js.map +0 -1
  86. /package/dist/esm/src/{types → endpoint}/discovery.d.ts +0 -0
  87. /package/dist/esm/src/{types → endpoint}/discovery.js +0 -0
@@ -9,28 +9,22 @@
9
9
  * https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
10
10
  */
11
11
  import * as http2 from "http2";
12
- import { LambdaHandler } from "./handlers/lambda.js";
13
- import { EndpointBuilder } from "./endpoint_builder.js";
12
+ import { EndpointBuilder } from "./endpoint.js";
14
13
  import { GenericHandler } from "./handlers/generic.js";
15
14
  import { Readable, Writable } from "node:stream";
16
15
  import { ensureError } from "../types/errors.js";
17
16
  export class NodeEndpoint {
18
17
  builder = new EndpointBuilder();
19
- get keySet() {
20
- return this.builder.keySet;
21
- }
22
- componentByName(componentName) {
23
- return this.builder.componentByName(componentName);
24
- }
25
- addComponent(component) {
26
- this.builder.addComponent(component);
27
- }
28
18
  bind(definition) {
29
19
  this.builder.bind(definition);
30
20
  return this;
31
21
  }
32
22
  withIdentityV1(...keys) {
33
- this.builder.withIdentityV1(...keys);
23
+ this.builder.addIdentityKeys(...keys);
24
+ return this;
25
+ }
26
+ defaultServiceOptions(options) {
27
+ this.builder.setDefaultServiceOptions(options);
34
28
  return this;
35
29
  }
36
30
  setLogger(logger) {
@@ -38,59 +32,13 @@ export class NodeEndpoint {
38
32
  return this;
39
33
  }
40
34
  http2Handler() {
41
- const handler = new GenericHandler(this.builder, "BIDI_STREAM");
42
- return (request, response) => {
43
- (async () => {
44
- const abortController = new AbortController();
45
- request.once("aborted", () => {
46
- abortController.abort();
47
- });
48
- request.once("close", () => {
49
- abortController.abort();
50
- });
51
- request.once("error", () => {
52
- abortController.abort();
53
- });
54
- if (request.destroyed || request.aborted) {
55
- this.builder.rlog.error("Client disconnected");
56
- abortController.abort();
57
- }
58
- try {
59
- const url = request.url;
60
- const webRequestBody = Readable.toWeb(request);
61
- const resp = await handler.handle({
62
- url,
63
- headers: request.headers,
64
- body: webRequestBody,
65
- extraArgs: [],
66
- abortSignal: abortController.signal,
67
- });
68
- if (response.destroyed) {
69
- return;
70
- }
71
- response.writeHead(resp.statusCode, resp.headers);
72
- const responseWeb = Writable.toWeb(response);
73
- await resp.body.pipeTo(responseWeb);
74
- }
75
- catch (e) {
76
- const error = ensureError(e);
77
- this.builder.rlog.error("Error while handling connection: " + (error.stack ?? error.message));
78
- response.destroy(error);
79
- abortController.abort();
80
- }
81
- })().catch(() => { });
82
- };
83
- }
84
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
85
- lambdaHandler() {
86
- const genericHandler = new GenericHandler(this.builder, "REQUEST_RESPONSE");
87
- const handler = new LambdaHandler(genericHandler);
88
- return handler.handleRequest.bind(handler);
35
+ return nodeHttp2Handler(this.builder.build());
89
36
  }
90
37
  listen(port) {
38
+ const endpoint = this.builder.build();
91
39
  const actualPort = port ?? parseInt(process.env.PORT ?? "9080");
92
- this.builder.rlog.info(`Restate SDK started listening on ${actualPort}...`);
93
- const server = http2.createServer(this.http2Handler());
40
+ endpoint.rlog.info(`Restate SDK started listening on ${actualPort}...`);
41
+ const server = http2.createServer(nodeHttp2Handler(endpoint));
94
42
  return new Promise((resolve, reject) => {
95
43
  let failed = false;
96
44
  server.once("error", (e) => {
@@ -112,4 +60,48 @@ export class NodeEndpoint {
112
60
  });
113
61
  }
114
62
  }
63
+ function nodeHttp2Handler(endpoint) {
64
+ const handler = new GenericHandler(endpoint, "BIDI_STREAM");
65
+ return (request, response) => {
66
+ (async () => {
67
+ const abortController = new AbortController();
68
+ request.once("aborted", () => {
69
+ abortController.abort();
70
+ });
71
+ request.once("close", () => {
72
+ abortController.abort();
73
+ });
74
+ request.once("error", () => {
75
+ abortController.abort();
76
+ });
77
+ if (request.destroyed || request.aborted) {
78
+ endpoint.rlog.error("Client disconnected");
79
+ abortController.abort();
80
+ }
81
+ try {
82
+ const url = request.url;
83
+ const webRequestBody = Readable.toWeb(request);
84
+ const resp = await handler.handle({
85
+ url,
86
+ headers: request.headers,
87
+ body: webRequestBody,
88
+ extraArgs: [],
89
+ abortSignal: abortController.signal,
90
+ });
91
+ if (response.destroyed) {
92
+ return;
93
+ }
94
+ response.writeHead(resp.statusCode, resp.headers);
95
+ const responseWeb = Writable.toWeb(response);
96
+ await resp.body.pipeTo(responseWeb);
97
+ }
98
+ catch (e) {
99
+ const error = ensureError(e);
100
+ endpoint.rlog.error("Error while handling connection: " + (error.stack ?? error.message));
101
+ response.destroy(error);
102
+ abortController.abort();
103
+ }
104
+ })().catch(() => { });
105
+ };
106
+ }
115
107
  //# sourceMappingURL=node_endpoint.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"node_endpoint.js","sourceRoot":"","s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E,eAAe,CAAC,MAAM;iBACpC,CAAC,CAAC;gBAEH,IAAI,QAAQ,CAAC,SAAS,EAAE,CAAC;oBACvB,OAAO;gBACT,CAAC;gBAED,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;gBAClD,MAAM,WAAW,GAAG,QAAQ,CAAC,KAAK,CAChC,QAAQ,CACqB,CAAC;gBAChC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YACtC,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,MAAM,KAAK,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;gBAC7B,QAAQ,CAAC,IAAI,CAAC,KAAK,CACjB,mCAAmC,GAAG,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,CACrE,CAAC;gBACF,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;gBACxB,eAAe,CAAC,KAAK,EAAE,CAAC;YAC1B,CAAC;QACH,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IACvB,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,48 @@
1
+ import type { DefaultServiceOptions, LoggerTransport, ServiceDefinition, VirtualObjectDefinition, WorkflowDefinition } from "../common_api.js";
2
+ /**
3
+ * Options for creating an endpoint handler for Node.js HTTP/2 servers.
4
+ */
5
+ export interface EndpointOptions {
6
+ /**
7
+ * A list of Restate services, virtual objects, or workflows that will be exposed via the endpoint.
8
+ */
9
+ services: Array<ServiceDefinition<string, unknown> | VirtualObjectDefinition<string, unknown> | WorkflowDefinition<string, unknown>>;
10
+ /**
11
+ * Provide a list of v1 request identity public keys eg `publickeyv1_2G8dCQhArfvGpzPw5Vx2ALciR4xCLHfS5YaT93XjNxX9` to validate
12
+ * incoming requests against, limiting requests to Restate clusters with the corresponding private keys. This public key format is
13
+ * logged by the Restate process at startup if a request identity private key is provided.
14
+ *
15
+ * If this function is called, all incoming requests irrelevant of endpoint type will be expected to have
16
+ * `x-restate-signature-scheme: v1` and `x-restate-jwt-v1: <valid jwt signed with one of these keys>`. If not called,
17
+ *
18
+ */
19
+ identityKeys?: string[];
20
+ /**
21
+ * Default service options that will be used by all services bind to this endpoint.
22
+ *
23
+ * Options can be overridden on each service/handler.
24
+ */
25
+ defaultServiceOptions?: DefaultServiceOptions;
26
+ /**
27
+ * Replace the default console-based {@link LoggerTransport}
28
+ * @example
29
+ * Using console:
30
+ * ```ts
31
+ * createEndpointHandler({ logger: (meta, message, ...o) => {console.log(`${meta.level}: `, message, ...o)}})
32
+ * ```
33
+ * @example
34
+ * Using winston:
35
+ * ```ts
36
+ * const logger = createLogger({ ... })
37
+ * createEndpointHandler({ logger: (meta, message, ...o) => {logger.log(meta.level, {invocationId: meta.context?.invocationId}, [message, ...o].join(' '))} })
38
+ * ```
39
+ * @example
40
+ * Using pino:
41
+ * ```ts
42
+ * const logger = pino()
43
+ * createEndpointHandler({ logger: (meta, message, ...o) => {logger[meta.level]({invocationId: meta.context?.invocationId}, [message, ...o].join(' '))}} )
44
+ * ```
45
+ */
46
+ logger?: LoggerTransport;
47
+ }
48
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/endpoint/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,eAAe,EACf,iBAAiB,EACjB,uBAAuB,EACvB,kBAAkB,EACnB,MAAM,kBAAkB,CAAC;AAE1B;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,QAAQ,EAAE,KAAK,CACX,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,GAClC,uBAAuB,CAAC,MAAM,EAAE,OAAO,CAAC,GACxC,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CACtC,CAAC;IACF;;;;;;;;OAQG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;IAC9C;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM,CAAC,EAAE,eAAe,CAAC;CAC1B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/endpoint/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import type { RestateEndpointBase } from "../endpoint.js";
2
+ import type { EndpointOptions } from "./types.js";
3
+ export declare function withOptions<E extends RestateEndpointBase<E>>(endpoint: E, { identityKeys, defaultServiceOptions, logger, services }: EndpointOptions): E;
4
+ //# sourceMappingURL=withOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withOptions.d.ts","sourceRoot":"","sources":["../../../../src/endpoint/withOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,wBAAgB,WAAW,CAAC,CAAC,SAAS,mBAAmB,CAAC,CAAC,CAAC,EAC1D,QAAQ,EAAE,CAAC,EACX,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,eAAe,GACzE,CAAC,CAiBH"}
@@ -0,0 +1,16 @@
1
+ export function withOptions(endpoint, { identityKeys, defaultServiceOptions, logger, services }) {
2
+ let endpointWithOptions = endpoint;
3
+ if (identityKeys && identityKeys.length > 0) {
4
+ endpointWithOptions = endpointWithOptions.withIdentityV1(...identityKeys);
5
+ }
6
+ if (defaultServiceOptions) {
7
+ endpointWithOptions = endpointWithOptions.defaultServiceOptions(defaultServiceOptions);
8
+ }
9
+ if (logger) {
10
+ endpointWithOptions = endpointWithOptions.setLogger(logger);
11
+ }
12
+ return services.reduce((results, service) => {
13
+ return results.bind(service);
14
+ }, endpointWithOptions);
15
+ }
16
+ //# sourceMappingURL=withOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withOptions.js","sourceRoot":"","sources":["../../../../src/endpoint/withOptions.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,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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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"}
@@ -10,13 +10,46 @@
10
10
  */
11
11
  export * from "./common_api.js";
12
12
  import { FetchEndpointImpl } from "./endpoint/fetch_endpoint.js";
13
- import { cloudflareWorkersBundlerPatch } from "./endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js"
13
+ import { withOptions } from "./endpoint/withOptions.js";
14
+ import { cloudflareWorkersBundlerPatch } from "./endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js";
14
15
  /**
15
16
  * Create a new {@link RestateEndpoint} in request response protocol mode.
16
17
  * Bidirectional mode (must be served over http2) can be enabled with .enableHttp2()
17
18
  */
18
19
  export function endpoint() {
19
- cloudflareWorkersBundlerPatch()
20
- return new FetchEndpointImpl("REQUEST_RESPONSE");
20
+ cloudflareWorkersBundlerPatch();
21
+ return new FetchEndpointImpl("REQUEST_RESPONSE");
21
22
  }
22
- //# sourceMappingURL=fetch.js.map
23
+
24
+ /**
25
+ * Creates a Cloudflare worker handler that encapsulates all the Restate services served by this endpoint.
26
+ *
27
+ * @param options - Configuration options for the endpoint handler.
28
+ * @returns A worker handler.
29
+ *
30
+ * @example
31
+ * A typical request-response handler would look like this:
32
+ * ```
33
+ * import { createEndpointHandler } from "@restatedev/restate-sdk/restate-sdk-cloudflare-workers";
34
+ *
35
+ * export const handler = createEndpointHandler({ services: [myService] })
36
+ *
37
+ * @example
38
+ * A typical bidirectional handler (works with http2 and some http1.1 servers) would look like this:
39
+ * ```
40
+ * import { createEndpointHandler } from "@restatedev/restate-sdk/restate-sdk-cloudflare-workers";
41
+ *
42
+ * export const handler = createEndpointHandler({ services: [myService], bidirectional: true })
43
+ *
44
+ */
45
+ export function createEndpointHandler(options) {
46
+ cloudflareWorkersBundlerPatch();
47
+ return withOptions(
48
+ new FetchEndpointImpl(
49
+ options.bidirectional ? "BIDI_STREAM" : "REQUEST_RESPONSE"
50
+ ),
51
+ options
52
+ ).handler().fetch;
53
+ }
54
+
55
+ //# sourceMappingURL=fetch.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../../src/fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,cAAc,iBAAiB,CAAC;AAEhC,OAAO,EAEL,iBAAiB,GAClB,MAAM,8BAA8B,CAAC;AAEtC;;;GAGG;AACH,MAAM,UAAU,QAAQ;IACtB,OAAO,IAAI,iBAAiB,CAAC,kBAAkB,CAAC,CAAC;AACnD,CAAC"}
1
+ {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../../src/fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,cAAc,iBAAiB,CAAC;AAEhC,OAAO,EAEL,iBAAiB,GAClB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD;;;GAGG;AACH,MAAM,UAAU,QAAQ;IACtB,OAAO,IAAI,iBAAiB,CAAC,kBAAkB,CAAC,CAAC;AACnD,CAAC;AAcD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAA6B;IACjE,OAAO,WAAW,CAChB,IAAI,iBAAiB,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.3";
1
+ export declare const SDK_VERSION = "1.8.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -1,2 +1,2 @@
1
- export const SDK_VERSION = '1.7.3';
1
+ export const SDK_VERSION = '1.8.0';
2
2
  //# 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"}
@@ -10,10 +10,27 @@
10
10
  */
11
11
  export * from "./common_api.js";
12
12
  import { LambdaEndpointImpl, } from "./endpoint/lambda_endpoint.js";
13
+ import { withOptions } from "./endpoint/withOptions.js";
13
14
  /**
14
- * Create a new {@link RestateEndpoint}.
15
+ * Create a new {@link LambdaEndpoint}.
15
16
  */
16
17
  export function endpoint() {
17
18
  return new LambdaEndpointImpl();
18
19
  }
20
+ /**
21
+ * Creates a Lambda handler that encapsulates all the Restate services served by this endpoint.
22
+ *
23
+ * @param {EndpointOptions} options - Configuration options for the endpoint handler.
24
+ * @returns A Lambda handler function.
25
+ *
26
+ * @example
27
+ * A typical endpoint served as Lambda would look like this:
28
+ * ```
29
+ * import { createEndpointHandler } from "@restatedev/restate-sdk/lambda";
30
+ *
31
+ * export const handler = createEndpointHandler({ services: [myService] })
32
+ */
33
+ export function createEndpointHandler(options) {
34
+ return withOptions(new LambdaEndpointImpl(), options).handler();
35
+ }
19
36
  //# sourceMappingURL=lambda.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"lambda.js","sourceRoot":"","sources":["../../../src/lambda.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,cAAc,iBAAiB,CAAC;AAEhC,OAAO,EACL,kBAAkB,GAEnB,MAAM,+BAA+B,CAAC;AAEvC;;GAEG;AACH,MAAM,UAAU,QAAQ;IACtB,OAAO,IAAI,kBAAkB,EAAE,CAAC;AAClC,CAAC"}
1
+ {"version":3,"file":"lambda.js","sourceRoot":"","sources":["../../../src/lambda.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,cAAc,iBAAiB,CAAC;AAEhC,OAAO,EACL,kBAAkB,GAEnB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD;;GAEG;AACH,MAAM,UAAU,QAAQ;IACtB,OAAO,IAAI,kBAAkB,EAAE,CAAC;AAClC,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAwB;IAC5D,OAAO,WAAW,CAChB,IAAI,kBAAkB,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"}