@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.
- package/dist/esm/src/common_api.d.ts +3 -2
- package/dist/esm/src/common_api.d.ts.map +1 -1
- package/dist/esm/src/common_api.js +1 -1
- package/dist/esm/src/common_api.js.map +1 -1
- package/dist/esm/src/context.d.ts +66 -47
- package/dist/esm/src/context.d.ts.map +1 -1
- package/dist/esm/src/context.js.map +1 -1
- package/dist/esm/src/context_impl.d.ts.map +1 -1
- package/dist/esm/src/context_impl.js +9 -1
- package/dist/esm/src/context_impl.js.map +1 -1
- package/dist/esm/src/{types → endpoint}/components.d.ts +2 -2
- package/dist/esm/src/endpoint/components.d.ts.map +1 -0
- package/dist/esm/src/{types → endpoint}/components.js +1 -1
- package/dist/esm/src/endpoint/components.js.map +1 -0
- package/dist/esm/src/endpoint/discovery.d.ts.map +1 -0
- package/dist/esm/src/endpoint/discovery.js.map +1 -0
- package/dist/esm/src/endpoint/endpoint.d.ts +33 -0
- package/dist/esm/src/endpoint/endpoint.d.ts.map +1 -0
- package/dist/esm/src/endpoint/endpoint.js +148 -0
- package/dist/esm/src/endpoint/endpoint.js.map +1 -0
- package/dist/esm/src/endpoint/fetch_endpoint.d.ts +3 -6
- package/dist/esm/src/endpoint/fetch_endpoint.d.ts.map +1 -1
- package/dist/esm/src/endpoint/fetch_endpoint.js +7 -12
- package/dist/esm/src/endpoint/fetch_endpoint.js.map +1 -1
- package/dist/esm/src/endpoint/handlers/generic.d.ts +4 -4
- package/dist/esm/src/endpoint/handlers/generic.d.ts.map +1 -1
- package/dist/esm/src/endpoint/handlers/generic.js +13 -4
- package/dist/esm/src/endpoint/handlers/generic.js.map +1 -1
- package/dist/esm/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.d.ts +2 -0
- package/dist/esm/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings_bg.js +31 -0
- package/dist/esm/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings_bg.wasm +0 -0
- package/dist/esm/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings_bg.wasm.d.ts +2 -0
- package/dist/esm/src/endpoint/lambda_endpoint.d.ts +2 -5
- package/dist/esm/src/endpoint/lambda_endpoint.d.ts.map +1 -1
- package/dist/esm/src/endpoint/lambda_endpoint.js +7 -12
- package/dist/esm/src/endpoint/lambda_endpoint.js.map +1 -1
- package/dist/esm/src/endpoint/node_endpoint.d.ts +2 -5
- package/dist/esm/src/endpoint/node_endpoint.d.ts.map +1 -1
- package/dist/esm/src/endpoint/node_endpoint.js +54 -62
- package/dist/esm/src/endpoint/node_endpoint.js.map +1 -1
- package/dist/esm/src/endpoint/types.d.ts +48 -0
- package/dist/esm/src/endpoint/types.d.ts.map +1 -0
- package/dist/esm/src/endpoint/types.js +2 -0
- package/dist/esm/src/endpoint/types.js.map +1 -0
- package/dist/esm/src/endpoint/withOptions.d.ts +4 -0
- package/dist/esm/src/endpoint/withOptions.d.ts.map +1 -0
- package/dist/esm/src/endpoint/withOptions.js +16 -0
- package/dist/esm/src/endpoint/withOptions.js.map +1 -0
- package/dist/esm/src/endpoint.d.ts +23 -22
- package/dist/esm/src/endpoint.d.ts.map +1 -1
- package/dist/esm/src/fetch.d.ts +34 -0
- package/dist/esm/src/fetch.d.ts.map +1 -1
- package/dist/esm/src/fetch.js +37 -4
- package/dist/esm/src/fetch.js.map +1 -1
- package/dist/esm/src/generated/version.d.ts +1 -1
- package/dist/esm/src/generated/version.js +1 -1
- package/dist/esm/src/lambda.d.ts +16 -1
- package/dist/esm/src/lambda.d.ts.map +1 -1
- package/dist/esm/src/lambda.js +18 -1
- package/dist/esm/src/lambda.js.map +1 -1
- package/dist/esm/src/node.d.ts +38 -0
- package/dist/esm/src/node.d.ts.map +1 -0
- package/dist/esm/src/node.js +51 -0
- package/dist/esm/src/node.js.map +1 -0
- package/dist/esm/src/public_api.d.ts +1 -6
- package/dist/esm/src/public_api.d.ts.map +1 -1
- package/dist/esm/src/public_api.js +1 -8
- package/dist/esm/src/public_api.js.map +1 -1
- package/dist/esm/src/types/errors.d.ts +25 -0
- package/dist/esm/src/types/errors.d.ts.map +1 -1
- package/dist/esm/src/types/errors.js +29 -1
- package/dist/esm/src/types/errors.js.map +1 -1
- package/dist/esm/src/types/rpc.d.ts +19 -19
- package/dist/esm/src/types/rpc.js +19 -19
- package/dist/esm/src/user_agent.d.ts +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/dist/esm/src/endpoint/endpoint_builder.d.ts +0 -26
- package/dist/esm/src/endpoint/endpoint_builder.d.ts.map +0 -1
- package/dist/esm/src/endpoint/endpoint_builder.js +0 -139
- package/dist/esm/src/endpoint/endpoint_builder.js.map +0 -1
- package/dist/esm/src/types/components.d.ts.map +0 -1
- package/dist/esm/src/types/components.js.map +0 -1
- package/dist/esm/src/types/discovery.d.ts.map +0 -1
- package/dist/esm/src/types/discovery.js.map +0 -1
- /package/dist/esm/src/{types → endpoint}/discovery.d.ts +0 -0
- /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 {
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
93
|
-
const server = http2.createServer(
|
|
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":"","sources":["../../../../src/endpoint/node_endpoint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAaH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"node_endpoint.js","sourceRoot":"","sources":["../../../../src/endpoint/node_endpoint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAaH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,EAAE,WAAW,EAAE,MA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"../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 @@
|
|
|
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
|
-
*
|
|
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
|
-
*
|
|
33
|
-
*
|
|
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
|
-
*
|
|
39
|
-
*
|
|
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
|
|
48
|
-
*
|
|
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;
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QAAQ,EAAE,mBAAmB,KAC1B,IAAI,CAAC;CACX"}
|
package/dist/esm/src/fetch.d.ts
CHANGED
|
@@ -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;
|
|
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"}
|
package/dist/esm/src/fetch.js
CHANGED
|
@@ -10,13 +10,46 @@
|
|
|
10
10
|
*/
|
|
11
11
|
export * from "./common_api.js";
|
|
12
12
|
import { FetchEndpointImpl } from "./endpoint/fetch_endpoint.js";
|
|
13
|
-
import {
|
|
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
|
-
|
|
20
|
-
|
|
20
|
+
cloudflareWorkersBundlerPatch();
|
|
21
|
+
return new FetchEndpointImpl("REQUEST_RESPONSE");
|
|
21
22
|
}
|
|
22
|
-
|
|
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.
|
|
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.
|
|
1
|
+
export const SDK_VERSION = '1.8.0';
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
package/dist/esm/src/lambda.d.ts
CHANGED
|
@@ -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
|
|
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;
|
|
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"}
|
package/dist/esm/src/lambda.js
CHANGED
|
@@ -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
|
|
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"}
|