@restatedev/restate-sdk 0.7.2-worker → 0.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/LICENSE +1 -1
- package/README.md +29 -51
- package/dist/clients/workflow_client.d.ts +77 -0
- package/dist/clients/workflow_client.d.ts.map +1 -0
- package/dist/clients/workflow_client.js +172 -0
- package/dist/clients/workflow_client.js.map +1 -0
- package/dist/connection/buffered_connection.js +44 -0
- package/dist/connection/buffered_connection.js.map +1 -0
- package/dist/connection/connection.js +13 -0
- package/dist/connection/connection.js.map +1 -0
- package/dist/connection/embedded_connection.js +59 -0
- package/dist/connection/embedded_connection.js.map +1 -0
- package/dist/connection/http_connection.js +203 -0
- package/dist/connection/http_connection.js.map +1 -0
- package/dist/connection/lambda_connection.js +58 -0
- package/dist/connection/lambda_connection.js.map +1 -0
- package/dist/{restate_context.d.ts → context.d.ts} +239 -170
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +113 -0
- package/dist/context.js.map +1 -0
- package/dist/{restate_context_impl.d.ts → context_impl.d.ts} +26 -30
- package/dist/context_impl.d.ts.map +1 -0
- package/dist/context_impl.js +439 -0
- package/dist/context_impl.js.map +1 -0
- package/dist/embedded/api.d.ts +2 -2
- package/dist/embedded/api.d.ts.map +1 -1
- package/dist/embedded/api.js +35 -0
- package/dist/embedded/api.js.map +1 -0
- package/dist/embedded/handler.d.ts +2 -2
- package/dist/embedded/handler.d.ts.map +1 -1
- package/dist/embedded/handler.js +26 -0
- package/dist/embedded/handler.js.map +1 -0
- package/dist/embedded/http2_remote.js +91 -0
- package/dist/embedded/http2_remote.js.map +1 -0
- package/dist/embedded/invocation.d.ts.map +1 -1
- package/dist/embedded/invocation.js +94 -0
- package/dist/embedded/invocation.js.map +1 -0
- package/dist/endpoint/endpoint_impl.d.ts +35 -0
- package/dist/endpoint/endpoint_impl.d.ts.map +1 -0
- package/dist/endpoint/endpoint_impl.js +405 -0
- package/dist/endpoint/endpoint_impl.js.map +1 -0
- package/dist/endpoint/http2_handler.d.ts +11 -0
- package/dist/endpoint/http2_handler.d.ts.map +1 -0
- package/dist/endpoint/http2_handler.js +119 -0
- package/dist/endpoint/http2_handler.js.map +1 -0
- package/dist/endpoint/lambda_handler.d.ts +15 -0
- package/dist/endpoint/lambda_handler.d.ts.map +1 -0
- package/dist/endpoint/lambda_handler.js +144 -0
- package/dist/endpoint/lambda_handler.js.map +1 -0
- package/dist/endpoint.d.ts +161 -0
- package/dist/endpoint.d.ts.map +1 -0
- package/dist/endpoint.js +22 -0
- package/dist/endpoint.js.map +1 -0
- package/dist/generated/dev/restate/events.js +371 -0
- package/dist/generated/dev/restate/events.js.map +1 -0
- package/dist/generated/dev/restate/ext.js +215 -0
- package/dist/generated/dev/restate/ext.js.map +1 -0
- package/dist/generated/google/protobuf/descriptor.js +6676 -0
- package/dist/generated/google/protobuf/descriptor.js.map +1 -0
- package/dist/generated/google/protobuf/empty.js +107 -0
- package/dist/generated/google/protobuf/empty.js.map +1 -0
- package/dist/generated/google/protobuf/struct.js +754 -0
- package/dist/generated/google/protobuf/struct.js.map +1 -0
- package/dist/generated/proto/discovery.js +364 -0
- package/dist/generated/proto/discovery.js.map +1 -0
- package/dist/generated/proto/dynrpc.js +668 -0
- package/dist/generated/proto/dynrpc.js.map +1 -0
- package/dist/generated/proto/javascript.d.ts +13 -0
- package/dist/generated/proto/javascript.d.ts.map +1 -1
- package/dist/generated/proto/javascript.js +416 -0
- package/dist/generated/proto/javascript.js.map +1 -0
- package/dist/generated/proto/protocol.d.ts +43 -0
- package/dist/generated/proto/protocol.d.ts.map +1 -1
- package/dist/generated/proto/protocol.js +2641 -0
- package/dist/generated/proto/protocol.js.map +1 -0
- package/dist/generated/proto/services.js +1535 -0
- package/dist/generated/proto/services.js.map +1 -0
- package/dist/generated/proto/test.js +321 -0
- package/dist/generated/proto/test.js.map +1 -0
- package/dist/invocation.d.ts +4 -1
- package/dist/invocation.d.ts.map +1 -1
- package/dist/invocation.js +157 -0
- package/dist/invocation.js.map +1 -0
- package/dist/io/decoder.d.ts +1 -0
- package/dist/io/decoder.d.ts.map +1 -1
- package/dist/io/decoder.js +140 -0
- package/dist/io/decoder.js.map +1 -0
- package/dist/io/encoder.d.ts +1 -2
- package/dist/io/encoder.d.ts.map +1 -1
- package/dist/io/encoder.js +68 -0
- package/dist/io/encoder.js.map +1 -0
- package/dist/journal.d.ts +13 -4
- package/dist/journal.d.ts.map +1 -1
- package/dist/journal.js +405 -0
- package/dist/journal.js.map +1 -0
- package/dist/local_state_store.d.ts +5 -3
- package/dist/local_state_store.d.ts.map +1 -1
- package/dist/local_state_store.js +82 -0
- package/dist/local_state_store.js.map +1 -0
- package/dist/logger.d.ts +19 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +90 -0
- package/dist/logger.js.map +1 -0
- package/dist/promise_combinator_tracker.d.ts +29 -0
- package/dist/promise_combinator_tracker.d.ts.map +1 -0
- package/dist/promise_combinator_tracker.js +128 -0
- package/dist/promise_combinator_tracker.js.map +1 -0
- package/dist/public_api.d.ts +5 -5
- package/dist/public_api.d.ts.map +1 -1
- package/dist/public_api.js +60 -0
- package/dist/public_api.js.map +1 -0
- package/dist/state_machine.d.ts +19 -12
- package/dist/state_machine.d.ts.map +1 -1
- package/dist/state_machine.js +437 -0
- package/dist/state_machine.js.map +1 -0
- package/dist/types/errors.d.ts +12 -3
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +273 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/grpc.d.ts +6 -4
- package/dist/types/grpc.d.ts.map +1 -1
- package/dist/types/grpc.js +81 -0
- package/dist/types/grpc.js.map +1 -0
- package/dist/types/protocol.d.ts +9 -5
- package/dist/types/protocol.d.ts.map +1 -1
- package/dist/types/protocol.js +147 -0
- package/dist/types/protocol.js.map +1 -0
- package/dist/types/router.d.ts +8 -8
- package/dist/types/router.d.ts.map +1 -1
- package/dist/types/router.js +36 -0
- package/dist/types/router.js.map +1 -0
- package/dist/types/types.d.ts +1 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/types.js +138 -0
- package/dist/types/types.js.map +1 -0
- package/dist/utils/{assumpsions.d.ts → assumptions.d.ts} +1 -1
- package/dist/utils/{assumpsions.d.ts.map → assumptions.d.ts.map} +1 -1
- package/dist/utils/assumptions.js +101 -0
- package/dist/utils/assumptions.js.map +1 -0
- package/dist/utils/message_logger.d.ts +28 -0
- package/dist/utils/message_logger.d.ts.map +1 -0
- package/dist/utils/message_logger.js +88 -0
- package/dist/utils/message_logger.js.map +1 -0
- package/dist/utils/promises.d.ts +15 -0
- package/dist/utils/promises.d.ts.map +1 -0
- package/dist/utils/promises.js +67 -0
- package/dist/utils/promises.js.map +1 -0
- package/dist/utils/public_utils.js +49 -0
- package/dist/utils/public_utils.js.map +1 -0
- package/dist/utils/rand.d.ts +1 -1
- package/dist/utils/rand.d.ts.map +1 -1
- package/dist/utils/rand.js +114 -0
- package/dist/utils/rand.js.map +1 -0
- package/dist/utils/utils.d.ts +1 -10
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +122 -0
- package/dist/utils/utils.js.map +1 -0
- package/dist/workflows/workflow.d.ts +101 -0
- package/dist/workflows/workflow.d.ts.map +1 -0
- package/dist/workflows/workflow.js +80 -0
- package/dist/workflows/workflow.js.map +1 -0
- package/dist/workflows/workflow_state_service.d.ts +35 -0
- package/dist/workflows/workflow_state_service.d.ts.map +1 -0
- package/dist/workflows/workflow_state_service.js +201 -0
- package/dist/workflows/workflow_state_service.js.map +1 -0
- package/dist/workflows/workflow_wrapper_service.d.ts +10 -0
- package/dist/workflows/workflow_wrapper_service.d.ts.map +1 -0
- package/dist/workflows/workflow_wrapper_service.js +264 -0
- package/dist/workflows/workflow_wrapper_service.js.map +1 -0
- package/package.json +38 -38
- package/src/clients/workflow_client.ts +290 -0
- package/src/connection/buffered_connection.ts +47 -0
- package/src/connection/connection.ts +34 -0
- package/src/connection/embedded_connection.ts +62 -0
- package/src/connection/http_connection.ts +228 -0
- package/src/connection/lambda_connection.ts +69 -0
- package/src/context.ts +633 -0
- package/src/context_impl.ts +721 -0
- package/src/embedded/api.ts +57 -0
- package/src/embedded/handler.ts +36 -0
- package/src/embedded/http2_remote.ts +103 -0
- package/src/embedded/invocation.ts +126 -0
- package/src/endpoint/endpoint_impl.ts +623 -0
- package/src/endpoint/http2_handler.ts +151 -0
- package/src/endpoint/lambda_handler.ts +178 -0
- package/src/endpoint.ts +187 -0
- package/src/generated/dev/restate/events.ts +430 -0
- package/src/generated/dev/restate/ext.ts +238 -0
- package/src/generated/google/protobuf/descriptor.ts +7889 -0
- package/src/generated/google/protobuf/empty.ts +150 -0
- package/src/generated/google/protobuf/struct.ts +878 -0
- package/src/generated/proto/discovery.ts +423 -0
- package/src/generated/proto/dynrpc.ts +768 -0
- package/src/generated/proto/javascript.ts +488 -0
- package/src/generated/proto/protocol.ts +3091 -0
- package/src/generated/proto/services.ts +1834 -0
- package/src/generated/proto/test.ts +387 -0
- package/src/invocation.ts +212 -0
- package/src/io/decoder.ts +171 -0
- package/src/io/encoder.ts +72 -0
- package/src/journal.ts +537 -0
- package/src/local_state_store.ts +94 -0
- package/src/logger.ts +121 -0
- package/src/promise_combinator_tracker.ts +191 -0
- package/src/public_api.ts +53 -0
- package/src/state_machine.ts +635 -0
- package/src/types/errors.ts +297 -0
- package/src/types/grpc.ts +97 -0
- package/src/types/protocol.ts +201 -0
- package/src/types/router.ts +118 -0
- package/src/types/types.ts +160 -0
- package/src/utils/assumptions.ts +131 -0
- package/src/utils/message_logger.ts +112 -0
- package/src/utils/promises.ts +118 -0
- package/src/utils/public_utils.ts +91 -0
- package/src/utils/rand.ts +142 -0
- package/src/utils/utils.ts +178 -0
- package/src/workflows/workflow.ts +178 -0
- package/src/workflows/workflow_state_service.ts +299 -0
- package/src/workflows/workflow_wrapper_service.ts +314 -0
- package/dist/cloudflare_bundle.js +0 -26133
- package/dist/restate_context.d.ts.map +0 -1
- package/dist/restate_context_impl.d.ts.map +0 -1
- package/dist/server/base_restate_server.d.ts +0 -32
- package/dist/server/base_restate_server.d.ts.map +0 -1
- package/dist/server/restate_lambda_handler.d.ts +0 -104
- package/dist/server/restate_lambda_handler.d.ts.map +0 -1
- package/dist/server/restate_server.d.ts +0 -97
- package/dist/server/restate_server.d.ts.map +0 -1
- package/dist/utils/logger.d.ts +0 -60
- package/dist/utils/logger.d.ts.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2023 - Restate Software, Inc., Restate GmbH
|
|
3
|
+
Copyright (c) 2023-2024 - Restate Software, Inc., Restate GmbH
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -37,35 +37,17 @@ restate
|
|
|
37
37
|
.listen(9080);
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
semantics.
|
|
52
|
-
- **state:** keyed handlers can attach key/value state, which is eagerly pushed into handlers during
|
|
53
|
-
invocation, and written back upon completion. This is particularly efficient for FaaS deployments
|
|
54
|
-
(stateful serverless, yay!).
|
|
55
|
-
- **observability & introspection:** Restate automatically generates Open Telemetry traces for the
|
|
56
|
-
interactions between handlers and gives you a SQL shell to query the distributed state of the application.
|
|
57
|
-
- **gRPC support:** Handlers may optionally be defined as gRPC services, and Restate will act as the transport
|
|
58
|
-
layer for the services/clients in that case.
|
|
59
|
-
|
|
60
|
-
📖 Check out our [docs](https://docs.restate.dev) to get quickly started!
|
|
61
|
-
|
|
62
|
-
🗣️ Join our [discord channel](https://discord.gg/skW3AZ6uGd) to talk to the community.
|
|
63
|
-
|
|
64
|
-
🏠 Visit our [GitHub org](https://github.com/restatedev) for more details.
|
|
65
|
-
|
|
66
|
-
# Using the SDK
|
|
67
|
-
|
|
68
|
-
To use this SDK, simply add the dependency to your project:
|
|
40
|
+
## Community
|
|
41
|
+
|
|
42
|
+
* 🤗️ [Join our online community](https://discord.gg/skW3AZ6uGd) for help, sharing feedback and talking to the community.
|
|
43
|
+
* 📖 [Check out our documentation](https://docs.restate.dev) to get quickly started!
|
|
44
|
+
* 📣 [Follow us on Twitter](https://twitter.com/restatedev) for staying up to date.
|
|
45
|
+
* 🙋 [Create a GitHub issue](https://github.com/restatedev/sdk-typescript/issues) for requesting a new feature or reporting a problem.
|
|
46
|
+
* 🏠 [Visit our GitHub org](https://github.com/restatedev) for exploring other repositories.
|
|
47
|
+
|
|
48
|
+
## Using the SDK
|
|
49
|
+
|
|
50
|
+
To use this SDK, add the dependency to your project:
|
|
69
51
|
```shell
|
|
70
52
|
npm install @restatedev/restate-sdk
|
|
71
53
|
```
|
|
@@ -75,13 +57,17 @@ For brand-new projects, we recommend using the [Restate Node Template](https://g
|
|
|
75
57
|
npx -y @restatedev/create-app@latest
|
|
76
58
|
```
|
|
77
59
|
|
|
78
|
-
|
|
60
|
+
## Contributing
|
|
79
61
|
|
|
80
|
-
|
|
81
|
-
|
|
62
|
+
We’re excited if you join the Restate community and start contributing!
|
|
63
|
+
Whether it is feature requests, bug reports, ideas & feedback or PRs, we appreciate any and all contributions.
|
|
64
|
+
We know that your time is precious and, therefore, deeply value any effort to contribute!
|
|
82
65
|
|
|
83
66
|
### Building the SDK
|
|
84
67
|
|
|
68
|
+
#### Prerequisites
|
|
69
|
+
- [NodeJS (and npm)](https://nodejs.org) installed
|
|
70
|
+
|
|
85
71
|
Install the dependencies, build the Restate protocol types (from ProtoBuf), and transpile the TypeScript code:
|
|
86
72
|
```shell
|
|
87
73
|
npm install
|
|
@@ -115,37 +101,29 @@ npm run example
|
|
|
115
101
|
npm run proto
|
|
116
102
|
```
|
|
117
103
|
|
|
118
|
-
### Testing end-to-end with Restate
|
|
119
|
-
|
|
120
|
-
This requires the [Docker Engine](https://docs.docker.com/engine/install/) to launch the Restate runtime for testing.
|
|
121
|
-
|
|
122
|
-
Start the runtime in a Docker container and tell Restate about the example service. This requires the example to be running, to make the discovery succeed!
|
|
123
|
-
- On Linux:
|
|
124
|
-
```shell
|
|
125
|
-
docker run --name restate_dev --rm --network=host docker.io/restatedev/restate:latest
|
|
104
|
+
### Testing end-to-end with Restate Server
|
|
126
105
|
|
|
127
|
-
|
|
128
|
-
```
|
|
129
|
-
- On macOS:
|
|
130
|
-
```shell
|
|
131
|
-
docker run --name restate_dev --rm -p 9070:9070 -p 8080:8080 docker.io/restatedev/restate:latest
|
|
106
|
+
[Launch the Restate Server](https://github.com/restatedev/restate?tab=readme-ov-file#install-the-server) for testing your SDK changes.
|
|
132
107
|
|
|
133
|
-
|
|
134
|
-
|
|
108
|
+
Register a service with the server via the Restate CLI.
|
|
109
|
+
This requires that the service is running to make the discovery succeed!
|
|
135
110
|
|
|
111
|
+
```shell
|
|
112
|
+
npx @restatedev/restate deployment register http://localhost:9080
|
|
113
|
+
```
|
|
136
114
|
|
|
137
115
|
Invoke the example service from the command line:
|
|
138
116
|
```shell
|
|
139
117
|
curl -X POST http://localhost:8080/greeter/greet -H 'content-type: application/json' -d '{"name": "Pete"}'
|
|
140
118
|
```
|
|
141
119
|
|
|
142
|
-
|
|
120
|
+
## Releasing the package
|
|
143
121
|
|
|
144
|
-
|
|
122
|
+
### Pre-release
|
|
145
123
|
|
|
146
124
|
Before release, make sure the `buf.lock` of the proto descriptors is updated. See [Update the proto descriptors](#update-the-proto-descriptors).
|
|
147
125
|
|
|
148
|
-
|
|
126
|
+
### Releasing via release-it
|
|
149
127
|
|
|
150
128
|
Releasing a new npm package from this repo requires:
|
|
151
129
|
|
|
@@ -160,7 +138,7 @@ npm run release
|
|
|
160
138
|
|
|
161
139
|
The actual `npm publish` is run by GitHub actions once a GitHub release is created.
|
|
162
140
|
|
|
163
|
-
|
|
141
|
+
### Releasing manually
|
|
164
142
|
|
|
165
143
|
1. Bump the version field in package.json to `X.Y.Z`
|
|
166
144
|
2. Create and push a tag of the form `vX.Y.Z` to the upstream repository
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import * as restate from "../public_api";
|
|
2
|
+
/**
|
|
3
|
+
* A client to interact with running workflows.
|
|
4
|
+
*/
|
|
5
|
+
export interface WorkflowClient<R, U> {
|
|
6
|
+
/**
|
|
7
|
+
* Gets the ID of the workflow that this client talks to.
|
|
8
|
+
*/
|
|
9
|
+
workflowId(): string;
|
|
10
|
+
/**
|
|
11
|
+
* Gets the status of the workflow, as a {@link restate.workflow.LifecycleStatus}.
|
|
12
|
+
* This will take on the values "NOT_STARTED", "RUNNING", "FINISHED", "FAILED".
|
|
13
|
+
*/
|
|
14
|
+
status(): Promise<restate.workflow.LifecycleStatus>;
|
|
15
|
+
/**
|
|
16
|
+
* Returns a promise completed with the result. This will resolve successfully on successful
|
|
17
|
+
* termination of the workflow, and will be rejected if the workflow throws an Error.
|
|
18
|
+
*/
|
|
19
|
+
result(): Promise<R>;
|
|
20
|
+
/**
|
|
21
|
+
* Gets the interface to the workflow through which all the workflow's additional methods
|
|
22
|
+
* can be called.
|
|
23
|
+
*
|
|
24
|
+
* To get the proper typed client, use the {@link WorkflowConnection.submitWorkflow} or
|
|
25
|
+
* {@link WorkflowConnection.connectToWorkflow} functions that accpet a typed ServiceApi
|
|
26
|
+
* object, as in the example below.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* In the workflow definition:
|
|
30
|
+
* ```
|
|
31
|
+
* const myWorkflow = restate.workflow.workflow("acme.myworkflow", { ... });
|
|
32
|
+
* export const myWorkflowApi = myworkflow.api;
|
|
33
|
+
* ```
|
|
34
|
+
* In the client code:
|
|
35
|
+
* ```
|
|
36
|
+
* import { myWorkflowApi } from "../server/myWorkflow"
|
|
37
|
+
* ...
|
|
38
|
+
* const restate = connectWorkflows("https://restatehost:8080");
|
|
39
|
+
* restate.submitWorkflow(myWorkflowApi, workflowId, args);
|
|
40
|
+
* restate.connectToWorkflow(myWorkflowApi, workflowId);
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
workflowInterface(): restate.Client<restate.workflow.WorkflowClientApi<U>>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A connection to Restate that let's you submit workflows or connect to workflows.
|
|
47
|
+
* This is a typed client that internally makes HTTP calls to Restate to launch trigger
|
|
48
|
+
* an execution of a workflow service, or to connect to an existing execution.
|
|
49
|
+
*/
|
|
50
|
+
export interface RestateClient {
|
|
51
|
+
submitWorkflow<R, T>(path: string, workflowId: string, params: T): Promise<{
|
|
52
|
+
status: restate.workflow.WorkflowStartResult;
|
|
53
|
+
client: WorkflowClient<R, unknown>;
|
|
54
|
+
}>;
|
|
55
|
+
submitWorkflow<R, T, U>(workflowApi: restate.ServiceApi<restate.workflow.WorkflowRestateRpcApi<R, T, U>>, workflowId: string, params: T): Promise<{
|
|
56
|
+
status: restate.workflow.WorkflowStartResult;
|
|
57
|
+
client: WorkflowClient<R, U>;
|
|
58
|
+
}>;
|
|
59
|
+
connectToWorkflow<R = unknown>(path: string, workflowId: string): Promise<{
|
|
60
|
+
status: restate.workflow.LifecycleStatus;
|
|
61
|
+
client: WorkflowClient<R, unknown>;
|
|
62
|
+
}>;
|
|
63
|
+
connectToWorkflow<R, T, U>(workflowApi: restate.ServiceApi<restate.workflow.WorkflowRestateRpcApi<R, T, U>>, workflowId: string): Promise<{
|
|
64
|
+
status: restate.workflow.LifecycleStatus;
|
|
65
|
+
client: WorkflowClient<R, U>;
|
|
66
|
+
}>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Creates a typed client to start and interact with workflow executions.
|
|
70
|
+
* The specifiec URI must point to the Restate request endpoint (ingress).
|
|
71
|
+
*
|
|
72
|
+
* This function doesn't immediately verify the connection, it will not fail
|
|
73
|
+
* if Restate is unreachable. Connection failures will only manifest when
|
|
74
|
+
* attempting to submit or connect a specific workflow.
|
|
75
|
+
*/
|
|
76
|
+
export declare function connect(restateUri: string): RestateClient;
|
|
77
|
+
//# sourceMappingURL=workflow_client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow_client.d.ts","sourceRoot":"","sources":["../../src/clients/workflow_client.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,OAAO,MAAM,eAAe,CAAC;AAGzC;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,EAAE,CAAC;IAClC;;OAEG;IACH,UAAU,IAAI,MAAM,CAAC;IAErB;;;OAGG;IACH,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;IAEpD;;;OAGG;IACH,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;IAErB;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;CAC5E;AAED;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,cAAc,CAAC,CAAC,EAAE,CAAC,EACjB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,CAAC,GACR,OAAO,CAAC;QACT,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAC;QAC7C,MAAM,EAAE,cAAc,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;KACpC,CAAC,CAAC;IAEH,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EACpB,WAAW,EAAE,OAAO,CAAC,UAAU,CAC7B,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAChD,EACD,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,CAAC,GACR,OAAO,CAAC;QACT,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAC;QAC7C,MAAM,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;KAC9B,CAAC,CAAC;IAEH,iBAAiB,CAAC,CAAC,GAAG,OAAO,EAC3B,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC;QACT,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC;QACzC,MAAM,EAAE,cAAc,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;KACpC,CAAC,CAAC;IAEH,iBAAiB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EACvB,WAAW,EAAE,OAAO,CAAC,UAAU,CAC7B,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAChD,EACD,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC;QACT,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC;QACzC,MAAM,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;KAC9B,CAAC,CAAC;CACJ;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,aAAa,CAyDzD"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2023-2024 - Restate Software, Inc., Restate GmbH
|
|
4
|
+
*
|
|
5
|
+
* This file is part of the Restate SDK for Node.js/TypeScript,
|
|
6
|
+
* which is released under the MIT license.
|
|
7
|
+
*
|
|
8
|
+
* You can find a copy of the license in file LICENSE in the root
|
|
9
|
+
* directory of this repository or package, or at
|
|
10
|
+
* https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
|
|
11
|
+
*/
|
|
12
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
15
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
16
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
17
|
+
}
|
|
18
|
+
Object.defineProperty(o, k2, desc);
|
|
19
|
+
}) : (function(o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k;
|
|
21
|
+
o[k2] = m[k];
|
|
22
|
+
}));
|
|
23
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
24
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
25
|
+
}) : function(o, v) {
|
|
26
|
+
o["default"] = v;
|
|
27
|
+
});
|
|
28
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.connect = void 0;
|
|
37
|
+
const restate = __importStar(require("../public_api"));
|
|
38
|
+
const errors_1 = require("../types/errors");
|
|
39
|
+
/**
|
|
40
|
+
* Creates a typed client to start and interact with workflow executions.
|
|
41
|
+
* The specifiec URI must point to the Restate request endpoint (ingress).
|
|
42
|
+
*
|
|
43
|
+
* This function doesn't immediately verify the connection, it will not fail
|
|
44
|
+
* if Restate is unreachable. Connection failures will only manifest when
|
|
45
|
+
* attempting to submit or connect a specific workflow.
|
|
46
|
+
*/
|
|
47
|
+
function connect(restateUri) {
|
|
48
|
+
return {
|
|
49
|
+
submitWorkflow: async (pathOrApi, workflowId, params) => {
|
|
50
|
+
const path = typeof pathOrApi === "string" ? pathOrApi : pathOrApi.path;
|
|
51
|
+
let result;
|
|
52
|
+
try {
|
|
53
|
+
result = await makeCall(restateUri, path, "submit", workflowId, params);
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
const error = (0, errors_1.ensureError)(err);
|
|
57
|
+
throw new Error("Cannot start workflow: " + error.message, {
|
|
58
|
+
cause: error,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
status: result,
|
|
63
|
+
client: new WorkflowClientImpl(restateUri, path, workflowId),
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
async connectToWorkflow(pathOrApi, workflowId) {
|
|
67
|
+
const path = typeof pathOrApi === "string" ? pathOrApi : pathOrApi.path;
|
|
68
|
+
const client = new WorkflowClientImpl(restateUri, path, workflowId);
|
|
69
|
+
const status = await client.status();
|
|
70
|
+
if (status === restate.workflow.LifecycleStatus.NOT_STARTED) {
|
|
71
|
+
throw new Error("No workflow running/finished/failed with ID " + workflowId);
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
status,
|
|
75
|
+
client: new WorkflowClientImpl(restateUri, path, workflowId),
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
exports.connect = connect;
|
|
81
|
+
class WorkflowClientImpl {
|
|
82
|
+
restateUri;
|
|
83
|
+
serviceName;
|
|
84
|
+
wfId;
|
|
85
|
+
constructor(restateUri, serviceName, wfId) {
|
|
86
|
+
this.restateUri = restateUri;
|
|
87
|
+
this.serviceName = serviceName;
|
|
88
|
+
this.wfId = wfId;
|
|
89
|
+
}
|
|
90
|
+
workflowId() {
|
|
91
|
+
return this.wfId;
|
|
92
|
+
}
|
|
93
|
+
status() {
|
|
94
|
+
return this.makeCall("status", {});
|
|
95
|
+
}
|
|
96
|
+
result() {
|
|
97
|
+
return this.makeCall("waitForResult", {});
|
|
98
|
+
}
|
|
99
|
+
workflowInterface() {
|
|
100
|
+
const clientProxy = new Proxy({}, {
|
|
101
|
+
get: (_target, prop) => {
|
|
102
|
+
const method = prop;
|
|
103
|
+
return async (args) => {
|
|
104
|
+
return this.makeCall(method, args);
|
|
105
|
+
};
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
return clientProxy;
|
|
109
|
+
}
|
|
110
|
+
async makeCall(method, args) {
|
|
111
|
+
return await makeCall(this.restateUri, this.serviceName, method, this.wfId, args);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// ----------------------------------------------------------------------------
|
|
115
|
+
// Utils
|
|
116
|
+
// ----------------------------------------------------------------------------
|
|
117
|
+
async function makeCall(restateUri, serviceName, method, workflowId, params) {
|
|
118
|
+
if (!workflowId || typeof workflowId !== "string") {
|
|
119
|
+
throw new Error("missing workflowId");
|
|
120
|
+
}
|
|
121
|
+
if (params === undefined) {
|
|
122
|
+
params = {};
|
|
123
|
+
}
|
|
124
|
+
if (typeof params !== "object") {
|
|
125
|
+
throw new Error("invalid parameters: must be an object");
|
|
126
|
+
}
|
|
127
|
+
const url = `${restateUri}/${serviceName}/${method}`;
|
|
128
|
+
const data = {
|
|
129
|
+
request: {
|
|
130
|
+
workflowId,
|
|
131
|
+
...params,
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
let body;
|
|
135
|
+
try {
|
|
136
|
+
body = JSON.stringify(data);
|
|
137
|
+
}
|
|
138
|
+
catch (err) {
|
|
139
|
+
throw new Error("Cannot encode request: " + err, { cause: err });
|
|
140
|
+
}
|
|
141
|
+
// eslint-disable-next-line no-console
|
|
142
|
+
console.debug(`Making call to Restate at ${url}`);
|
|
143
|
+
const httpResponse = await fetch(url, {
|
|
144
|
+
method: "POST",
|
|
145
|
+
headers: {
|
|
146
|
+
"Content-Type": "application/json",
|
|
147
|
+
},
|
|
148
|
+
body,
|
|
149
|
+
});
|
|
150
|
+
const responseText = await httpResponse.text();
|
|
151
|
+
if (!httpResponse.ok) {
|
|
152
|
+
throw new Error(`Request failed: ${httpResponse.status}\n${responseText}`);
|
|
153
|
+
}
|
|
154
|
+
let response;
|
|
155
|
+
try {
|
|
156
|
+
response = JSON.parse(responseText);
|
|
157
|
+
}
|
|
158
|
+
catch (err) {
|
|
159
|
+
throw new Error("Cannot parse response JSON: " + err, { cause: err });
|
|
160
|
+
}
|
|
161
|
+
if (response.error) {
|
|
162
|
+
throw new Error(response.error);
|
|
163
|
+
}
|
|
164
|
+
if (response.response) {
|
|
165
|
+
return response.response;
|
|
166
|
+
}
|
|
167
|
+
if (Object.keys(response).length === 0) {
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
throw new Error("Unrecognized response object: " + responseText);
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=workflow_client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow_client.js","sourceRoot":"","sources":["../../src/clients/workflow_client.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,uDAAyC;AACzC,4CAA8C;AA8F9C;;;;;;;GAOG;AACH,SAAgB,OAAO,CAAC,UAAkB;IACxC,OAAO;QACL,cAAc,EAAE,KAAK,EACnB,SAEuE,EACvE,UAAkB,EAClB,MAAS,EAIR,EAAE;YACH,MAAM,IAAI,GAAG,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC;YAExE,IAAI,MAA4C,CAAC;YACjD,IAAI;gBACF,MAAM,GAAG,MAAM,QAAQ,CAAC,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;aACzE;YAAC,OAAO,GAAG,EAAE;gBACZ,MAAM,KAAK,GAAG,IAAA,oBAAW,EAAC,GAAG,CAAC,CAAC;gBAC/B,MAAM,IAAI,KAAK,CAAC,yBAAyB,GAAG,KAAK,CAAC,OAAO,EAAE;oBACzD,KAAK,EAAE,KAAK;iBACb,CA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ufferedConnection = void 0;
|
|
4
|
+
const encoder_1 = require("../io/encoder");
|
|
5
|
+
class BufferedConnection {
|
|
6
|
+
flushFn;
|
|
7
|
+
queue = [];
|
|
8
|
+
flushing = Promise.resolve();
|
|
9
|
+
constructor(flushFn) {
|
|
10
|
+
this.flushFn = flushFn;
|
|
11
|
+
}
|
|
12
|
+
send(msg) {
|
|
13
|
+
const len = this.queue.push(msg);
|
|
14
|
+
if (len === 1) {
|
|
15
|
+
// we are the first in line, therefore we schedule a flush,
|
|
16
|
+
// BUT we must wait for the previous flush to end.
|
|
17
|
+
this.flushing = this.flushing.then(() => this.scheduleFlush());
|
|
18
|
+
}
|
|
19
|
+
// we don't need to reschedule the `flush` here,
|
|
20
|
+
// because the flush happens anyway at the end of the current event loop iteration.
|
|
21
|
+
// tag along to the previously scheduled flush.
|
|
22
|
+
return this.flushing;
|
|
23
|
+
}
|
|
24
|
+
end() {
|
|
25
|
+
this.flushing = this.flushing.then(() => this.flush());
|
|
26
|
+
return this.flushing;
|
|
27
|
+
}
|
|
28
|
+
scheduleFlush() {
|
|
29
|
+
// schedule a flush at the end of the current event loop iteration.
|
|
30
|
+
return new Promise((resolve, reject) => setImmediate(() => {
|
|
31
|
+
this.flush().then(resolve).catch(reject);
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
async flush() {
|
|
35
|
+
if (this.queue.length === 0) {
|
|
36
|
+
return Promise.resolve();
|
|
37
|
+
}
|
|
38
|
+
const buffer = (0, encoder_1.encodeMessages)(this.queue);
|
|
39
|
+
this.queue = [];
|
|
40
|
+
return this.flushFn(buffer);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.BufferedConnection = BufferedConnection;
|
|
44
|
+
//# sourceMappingURL=buffered_connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffered_connection.js","sourceRoot":"","sources":["../../src/connection/buffered_connection.ts"],"names":[],"mappings":";;;AAAA,2CAA+C;AAI/C,MAAa,k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AE,CAAC;QAEhB,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;CACF;AA1CD,gDA0CC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2023-2024 - Restate Software, Inc., Restate GmbH
|
|
4
|
+
*
|
|
5
|
+
* This file is part of the Restate SDK for Node.js/TypeScript,
|
|
6
|
+
* which is released under the MIT license.
|
|
7
|
+
*
|
|
8
|
+
* You can find a copy of the license in file LICENSE in the root
|
|
9
|
+
* directory of this repository or package, or at
|
|
10
|
+
* https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
//# sourceMappingURL=connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/connection/connection.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2023-2024 - Restate Software, Inc., Restate GmbH
|
|
4
|
+
*
|
|
5
|
+
* This file is part of the Restate SDK for Node.js/TypeScript,
|
|
6
|
+
* which is released under the MIT license.
|
|
7
|
+
*
|
|
8
|
+
* You can find a copy of the license in file LICENSE in the root
|
|
9
|
+
* directory of this repository or package, or at
|
|
10
|
+
* https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.EmbeddedConnection = exports.InvocationAlreadyCompletedError = exports.FencedOffError = void 0;
|
|
14
|
+
const buffered_connection_1 = require("./buffered_connection");
|
|
15
|
+
class FencedOffError extends Error {
|
|
16
|
+
constructor() {
|
|
17
|
+
super("FencedOff");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.FencedOffError = FencedOffError;
|
|
21
|
+
class InvocationAlreadyCompletedError extends Error {
|
|
22
|
+
constructor() {
|
|
23
|
+
super("Completed");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.InvocationAlreadyCompletedError = InvocationAlreadyCompletedError;
|
|
27
|
+
class EmbeddedConnection {
|
|
28
|
+
operationId;
|
|
29
|
+
streamId;
|
|
30
|
+
remote;
|
|
31
|
+
buffered;
|
|
32
|
+
constructor(operationId, streamId, remote) {
|
|
33
|
+
this.operationId = operationId;
|
|
34
|
+
this.streamId = streamId;
|
|
35
|
+
this.remote = remote;
|
|
36
|
+
this.buffered = new buffered_connection_1.BufferedConnection((buffer) => this.sendBuffer(buffer));
|
|
37
|
+
}
|
|
38
|
+
send(msg) {
|
|
39
|
+
return this.buffered.send(msg);
|
|
40
|
+
}
|
|
41
|
+
end() {
|
|
42
|
+
return this.buffered.end();
|
|
43
|
+
}
|
|
44
|
+
async sendBuffer(buffer) {
|
|
45
|
+
const res = await this.remote.send({
|
|
46
|
+
operationId: this.operationId,
|
|
47
|
+
streamId: this.streamId,
|
|
48
|
+
messages: buffer,
|
|
49
|
+
});
|
|
50
|
+
if (res.invalidStream !== undefined) {
|
|
51
|
+
throw new FencedOffError();
|
|
52
|
+
}
|
|
53
|
+
if (res.invocationCompleted !== undefined) {
|
|
54
|
+
throw new InvocationAlreadyCompletedError();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.EmbeddedConnection = EmbeddedConnection;
|
|
59
|
+
//# sourceMappingURL=embedded_connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embedded_connection.js","sourceRoot":"","sources":["../../src/connection/embedded_connection.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAIH,+DAA2D;AAG3D,MAAa,cAAe,SAAQ,KAAK;IACvC;QACE,KAAK,CAAC,WAAW,CAAC,CAAC;IACrB,CAAC;CACF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