@resonatehq/dev 0.1.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 +201 -0
- package/README.md +251 -0
- package/dist/api.d.ts +163 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +2 -0
- package/dist/api.js.map +1 -0
- package/dist/entities.d.ts +74 -0
- package/dist/entities.d.ts.map +1 -0
- package/dist/entities.js +2 -0
- package/dist/entities.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/server.d.ts +107 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +878 -0
- package/dist/server.js.map +1 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +13 -0
- package/dist/utils.js.map +1 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
# @resonatehq/dev
|
|
2
|
+
|
|
3
|
+
A TypeScript development server implementation for the Resonate distributed async/await framework. This package provides an in-memory server for local development and testing of durable execution patterns.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
`@resonatehq/dev` is a lightweight, in-memory implementation of the Resonate server that enables developers to build and test distributed applications locally without requiring external infrastructure. It implements the core Resonate protocol for managing promises, tasks, and schedules in a distributed system.
|
|
8
|
+
|
|
9
|
+
## What is Resonate?
|
|
10
|
+
|
|
11
|
+
Resonate is a distributed async/await framework that provides durable execution guarantees. It extends the familiar promise-based programming model to work reliably across distributed systems, network failures, and process restarts.
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
### Core Capabilities
|
|
16
|
+
|
|
17
|
+
- **Promise Management**: Create, settle, register, and subscribe to distributed promises with various states (pending, resolved, rejected, canceled, timedout)
|
|
18
|
+
- **Task Orchestration**: Acquire, suspend, fulfill, release, and manage distributed tasks with versioning and heartbeat support
|
|
19
|
+
- **Schedule Management**: Create and manage cron-based schedules for recurring promise execution
|
|
20
|
+
- **State Inspection**: Access complete system state including promises, tasks, schedules, and statistics
|
|
21
|
+
- **Message Routing**: Built-in router for distributing invoke, resume, and notify messages
|
|
22
|
+
|
|
23
|
+
### Key Features
|
|
24
|
+
|
|
25
|
+
- **In-Memory Storage**: Fast, ephemeral storage for development and testing
|
|
26
|
+
- **Time-based Simulation**: Control time flow for testing timeouts and schedules
|
|
27
|
+
- **Version Control**: Built-in versioning for optimistic concurrency control
|
|
28
|
+
- **Task Leasing**: TTL-based task claiming with heartbeat support
|
|
29
|
+
- **Callback Registration**: Subscribe to promise state changes
|
|
30
|
+
- **Statistics**: Real-time metrics on promise and task states
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install @resonatehq/dev
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Or with Bun:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
bun add @resonatehq/dev
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
### Basic Server Setup
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { Server } from "@resonatehq/dev";
|
|
50
|
+
|
|
51
|
+
// Create a new server instance
|
|
52
|
+
const server = new Server();
|
|
53
|
+
|
|
54
|
+
// Process a request
|
|
55
|
+
const response = server.process({
|
|
56
|
+
at: Date.now(),
|
|
57
|
+
req: {
|
|
58
|
+
kind: "promise.create",
|
|
59
|
+
head: {
|
|
60
|
+
corrId: "correlation-id-1",
|
|
61
|
+
version: server.version
|
|
62
|
+
},
|
|
63
|
+
data: {
|
|
64
|
+
id: "my-promise",
|
|
65
|
+
param: { headers: {}, data: JSON.stringify({ foo: "bar" }) },
|
|
66
|
+
tags: { env: "dev" },
|
|
67
|
+
timeoutAt: Date.now() + 60000, // 1 minute timeout
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
console.log(response);
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Working with Promises
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
// Create a promise
|
|
79
|
+
const createRes = server.process({
|
|
80
|
+
at: Date.now(),
|
|
81
|
+
req: {
|
|
82
|
+
kind: "promise.create",
|
|
83
|
+
head: { corrId: "1", version: server.version },
|
|
84
|
+
data: {
|
|
85
|
+
id: "promise-1",
|
|
86
|
+
param: { headers: {}, data: "" },
|
|
87
|
+
tags: {},
|
|
88
|
+
timeoutAt: Date.now() + 60000,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Get promise status
|
|
94
|
+
const getRes = server.process({
|
|
95
|
+
at: Date.now(),
|
|
96
|
+
req: {
|
|
97
|
+
kind: "promise.get",
|
|
98
|
+
head: { corrId: "2", version: server.version },
|
|
99
|
+
data: { id: "promise-1" },
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Settle a promise
|
|
104
|
+
const settleRes = server.process({
|
|
105
|
+
at: Date.now(),
|
|
106
|
+
req: {
|
|
107
|
+
kind: "promise.settle",
|
|
108
|
+
head: { corrId: "3", version: server.version },
|
|
109
|
+
data: {
|
|
110
|
+
id: "promise-1",
|
|
111
|
+
state: "resolved",
|
|
112
|
+
value: { headers: {}, data: JSON.stringify({ result: "success" }) },
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Working with Tasks
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
// Create a task
|
|
122
|
+
const taskRes = server.process({
|
|
123
|
+
at: Date.now(),
|
|
124
|
+
req: {
|
|
125
|
+
kind: "task.create",
|
|
126
|
+
head: { corrId: "4", version: server.version },
|
|
127
|
+
data: {
|
|
128
|
+
pid: "process-1",
|
|
129
|
+
ttl: 30000, // 30 seconds
|
|
130
|
+
action: {
|
|
131
|
+
kind: "promise.create",
|
|
132
|
+
head: { corrId: "5", version: server.version },
|
|
133
|
+
data: {
|
|
134
|
+
id: "task-promise",
|
|
135
|
+
param: { headers: {}, data: "" },
|
|
136
|
+
tags: {},
|
|
137
|
+
timeoutAt: Date.now() + 60000,
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// Acquire a task
|
|
145
|
+
const acquireRes = server.process({
|
|
146
|
+
at: Date.now(),
|
|
147
|
+
req: {
|
|
148
|
+
kind: "task.acquire",
|
|
149
|
+
head: { corrId: "6", version: server.version },
|
|
150
|
+
data: {
|
|
151
|
+
id: "task-id",
|
|
152
|
+
version: 1,
|
|
153
|
+
pid: "process-1",
|
|
154
|
+
ttl: 30000,
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Working with Schedules
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
// Create a schedule
|
|
164
|
+
const scheduleRes = server.process({
|
|
165
|
+
at: Date.now(),
|
|
166
|
+
req: {
|
|
167
|
+
kind: "schedule.create",
|
|
168
|
+
head: { corrId: "7", version: server.version },
|
|
169
|
+
data: {
|
|
170
|
+
id: "daily-job",
|
|
171
|
+
cron: "0 0 * * *", // Daily at midnight
|
|
172
|
+
promiseId: "scheduled-promise",
|
|
173
|
+
promiseTimeout: 3600000, // 1 hour
|
|
174
|
+
promiseParam: { headers: {}, data: "" },
|
|
175
|
+
promiseTags: { type: "scheduled" },
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Time-based Operations
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
// Get next timeout
|
|
185
|
+
const timeout = server.next({ at: Date.now() });
|
|
186
|
+
console.log(`Next event in ${timeout}ms`);
|
|
187
|
+
|
|
188
|
+
// Step forward in time and get messages
|
|
189
|
+
const messages = server.step({ at: Date.now() + timeout });
|
|
190
|
+
for (const { mesg, recv } of messages) {
|
|
191
|
+
console.log(`Message to ${recv}:`, mesg);
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Inspecting State
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
const state = server.getState();
|
|
199
|
+
|
|
200
|
+
console.log(`Promises: ${state.stats.promiseCount}`);
|
|
201
|
+
console.log(`Tasks: ${state.stats.taskCount}`);
|
|
202
|
+
console.log(`Schedules: ${state.stats.scheduleCount}`);
|
|
203
|
+
console.log(`Pending promises: ${state.stats.pendingPromises}`);
|
|
204
|
+
console.log(`Claimed tasks: ${state.stats.claimedTasks}`);
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## API Types
|
|
208
|
+
|
|
209
|
+
The package exports comprehensive TypeScript types for all requests and responses:
|
|
210
|
+
|
|
211
|
+
- **Promise Operations**: `PromiseCreateReq`, `PromiseGetReq`, `PromiseSettleReq`, `PromiseRegisterReq`, `PromiseSubscribeReq`
|
|
212
|
+
- **Task Operations**: `TaskCreateReq`, `TaskAcquireReq`, `TaskSuspendReq`, `TaskFulfillReq`, `TaskReleaseReq`, `TaskHeartbeatReq`
|
|
213
|
+
- **Schedule Operations**: `ScheduleCreateReq`, `ScheduleGetReq`, `ScheduleDeleteReq`
|
|
214
|
+
- **Entities**: `Promise`, `Task`, `Schedule`, `Message`
|
|
215
|
+
- **Utilities**: `assert`, `assertDefined`
|
|
216
|
+
|
|
217
|
+
## Development
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
# Install dependencies
|
|
221
|
+
bun install
|
|
222
|
+
|
|
223
|
+
# Build
|
|
224
|
+
bun run build
|
|
225
|
+
|
|
226
|
+
# Run tests
|
|
227
|
+
bun test
|
|
228
|
+
|
|
229
|
+
# Format code
|
|
230
|
+
bun run format
|
|
231
|
+
|
|
232
|
+
# Type check
|
|
233
|
+
bun run type-check
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## Use Cases
|
|
237
|
+
|
|
238
|
+
- **Local Development**: Test distributed applications without external dependencies
|
|
239
|
+
- **Integration Testing**: Simulate distributed promise execution in tests
|
|
240
|
+
- **Time Travel Testing**: Control time flow to test timeouts and schedules
|
|
241
|
+
- **Protocol Validation**: Verify correct implementation of the Resonate protocol
|
|
242
|
+
- **Learning**: Understand distributed async/await patterns
|
|
243
|
+
|
|
244
|
+
## License
|
|
245
|
+
|
|
246
|
+
See [LICENSE](LICENSE) file for details.
|
|
247
|
+
|
|
248
|
+
## Related Projects
|
|
249
|
+
|
|
250
|
+
- [Resonate](https://github.com/resonatehq/resonate) - The main Resonate project
|
|
251
|
+
- [Resonate SDK](https://github.com/resonatehq/resonate-sdk-ts) - TypeScript SDK for building Resonate applications
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import type { Promise, Schedule, Task } from "./entities";
|
|
2
|
+
type ReqResKind = "promise.get" | "promise.create" | "promise.settle" | "promise.register" | "promise.subscribe" | "task.get" | "task.create" | "task.acquire" | "task.suspend" | "task.fulfill" | "task.release" | "task.fence" | "task.heartbeat" | "schedule.get" | "schedule.create" | "schedule.delete" | "error";
|
|
3
|
+
type ReqSchema<K extends ReqResKind, T> = {
|
|
4
|
+
kind: K;
|
|
5
|
+
head: {
|
|
6
|
+
auth?: string;
|
|
7
|
+
corrId: string;
|
|
8
|
+
version: string;
|
|
9
|
+
};
|
|
10
|
+
data: T;
|
|
11
|
+
};
|
|
12
|
+
type ResSchema<K extends ReqResKind, S extends number, T> = {
|
|
13
|
+
kind: K;
|
|
14
|
+
head: {
|
|
15
|
+
corrId: string;
|
|
16
|
+
status: S;
|
|
17
|
+
version: string;
|
|
18
|
+
};
|
|
19
|
+
data: T;
|
|
20
|
+
};
|
|
21
|
+
export type ErrorCode = 400 | 404 | 409 | 429 | 500;
|
|
22
|
+
export type ErrorRes = ResSchema<"error", ErrorCode, string>;
|
|
23
|
+
export type PromiseGetReq = ReqSchema<"promise.get", {
|
|
24
|
+
id: string;
|
|
25
|
+
}>;
|
|
26
|
+
export type PromiseGetRes = ResSchema<"promise.get", 200, {
|
|
27
|
+
promise: Promise;
|
|
28
|
+
}>;
|
|
29
|
+
export type PromiseCreateReq = ReqSchema<"promise.create", {
|
|
30
|
+
id: string;
|
|
31
|
+
param: {
|
|
32
|
+
headers: {
|
|
33
|
+
[key: string]: string;
|
|
34
|
+
};
|
|
35
|
+
data: string;
|
|
36
|
+
};
|
|
37
|
+
tags: {
|
|
38
|
+
[key: string]: string;
|
|
39
|
+
};
|
|
40
|
+
timeoutAt: number;
|
|
41
|
+
}>;
|
|
42
|
+
export type PromiseCreateRes = ResSchema<"promise.create", 200, {
|
|
43
|
+
promise: Promise;
|
|
44
|
+
}>;
|
|
45
|
+
export type PromiseSettleReq = ReqSchema<"promise.settle", {
|
|
46
|
+
id: string;
|
|
47
|
+
state: "resolved" | "rejected" | "rejected_canceled";
|
|
48
|
+
value: {
|
|
49
|
+
headers: {
|
|
50
|
+
[key: string]: string;
|
|
51
|
+
};
|
|
52
|
+
data: string;
|
|
53
|
+
};
|
|
54
|
+
}>;
|
|
55
|
+
export type PromiseSettleRes = ResSchema<"promise.settle", 200, {
|
|
56
|
+
promise: Promise;
|
|
57
|
+
}>;
|
|
58
|
+
export type PromiseRegisterReq = ReqSchema<"promise.register", {
|
|
59
|
+
awaiter: string;
|
|
60
|
+
awaited: string;
|
|
61
|
+
}>;
|
|
62
|
+
export type PromiseRegisterRes = ResSchema<"promise.register", 200, {
|
|
63
|
+
promise: Promise;
|
|
64
|
+
}>;
|
|
65
|
+
export type PromiseSubscribeReq = ReqSchema<"promise.subscribe", {
|
|
66
|
+
awaited: string;
|
|
67
|
+
address: string;
|
|
68
|
+
}>;
|
|
69
|
+
export type PromiseSubscribeRes = ResSchema<"promise.subscribe", 200, {
|
|
70
|
+
promise: Promise;
|
|
71
|
+
}>;
|
|
72
|
+
export type TaskGetReq = ReqSchema<"task.get", {
|
|
73
|
+
id: string;
|
|
74
|
+
}>;
|
|
75
|
+
export type TaskGetRes = ResSchema<"task.get", 200, {
|
|
76
|
+
task: Task;
|
|
77
|
+
}>;
|
|
78
|
+
export type TaskCreateReq = ReqSchema<"task.create", {
|
|
79
|
+
pid: string;
|
|
80
|
+
ttl: number;
|
|
81
|
+
action: PromiseCreateReq;
|
|
82
|
+
}>;
|
|
83
|
+
export type TaskCreateRes = ResSchema<"task.create", 200, {
|
|
84
|
+
task?: Task;
|
|
85
|
+
promise: Promise;
|
|
86
|
+
}>;
|
|
87
|
+
export type TaskAcquireReq = ReqSchema<"task.acquire", {
|
|
88
|
+
id: string;
|
|
89
|
+
version: number;
|
|
90
|
+
pid: string;
|
|
91
|
+
ttl: number;
|
|
92
|
+
}>;
|
|
93
|
+
export type TaskAcquireRes = ResSchema<"task.acquire", 200, {
|
|
94
|
+
kind: "invoke" | "resume";
|
|
95
|
+
data: {
|
|
96
|
+
promise: Promise;
|
|
97
|
+
preload: Promise[];
|
|
98
|
+
};
|
|
99
|
+
}>;
|
|
100
|
+
export type TaskSuspendReq = ReqSchema<"task.suspend", {
|
|
101
|
+
id: string;
|
|
102
|
+
version: number;
|
|
103
|
+
actions: PromiseRegisterReq[];
|
|
104
|
+
}>;
|
|
105
|
+
export type TaskSuspendRes = ResSchema<"task.suspend", 200 | 300, undefined>;
|
|
106
|
+
export type TaskFulfillReq = ReqSchema<"task.fulfill", {
|
|
107
|
+
id: string;
|
|
108
|
+
version: number;
|
|
109
|
+
action: PromiseSettleReq;
|
|
110
|
+
}>;
|
|
111
|
+
export type TaskFulfillRes = ResSchema<"task.fulfill", 200, {
|
|
112
|
+
promise: Promise;
|
|
113
|
+
}>;
|
|
114
|
+
export type TaskReleaseReq = ReqSchema<"task.release", {
|
|
115
|
+
id: string;
|
|
116
|
+
version: number;
|
|
117
|
+
}>;
|
|
118
|
+
export type TaskReleaseRes = ResSchema<"task.release", 200, undefined>;
|
|
119
|
+
export type TaskFenceReq = ReqSchema<"task.fence", {
|
|
120
|
+
id: string;
|
|
121
|
+
version: number;
|
|
122
|
+
action: PromiseCreateReq | PromiseSettleReq;
|
|
123
|
+
}>;
|
|
124
|
+
export type TaskFenceRes = ResSchema<"task.fence", 200, {
|
|
125
|
+
action: PromiseCreateRes | PromiseSettleRes;
|
|
126
|
+
}>;
|
|
127
|
+
export type TaskHeartbeatReq = ReqSchema<"task.heartbeat", {
|
|
128
|
+
pid: string;
|
|
129
|
+
tasks: Task[];
|
|
130
|
+
}>;
|
|
131
|
+
export type TaskHeartbeatRes = ResSchema<"task.heartbeat", 200, undefined>;
|
|
132
|
+
export type ScheduleGetReq = ReqSchema<"schedule.get", {
|
|
133
|
+
id: string;
|
|
134
|
+
}>;
|
|
135
|
+
export type ScheduleGetRes = ResSchema<"schedule.get", 200, {
|
|
136
|
+
schedule: Schedule;
|
|
137
|
+
}>;
|
|
138
|
+
export type ScheduleCreateReq = ReqSchema<"schedule.create", {
|
|
139
|
+
id: string;
|
|
140
|
+
cron: string;
|
|
141
|
+
promiseId: string;
|
|
142
|
+
promiseTimeout: number;
|
|
143
|
+
promiseParam: {
|
|
144
|
+
headers: {
|
|
145
|
+
[key: string]: string;
|
|
146
|
+
};
|
|
147
|
+
data: string;
|
|
148
|
+
};
|
|
149
|
+
promiseTags: {
|
|
150
|
+
[key: string]: string;
|
|
151
|
+
};
|
|
152
|
+
}>;
|
|
153
|
+
export type ScheduleCreateRes = ResSchema<"schedule.create", 200, {
|
|
154
|
+
schedule: Schedule;
|
|
155
|
+
}>;
|
|
156
|
+
export type ScheduleDeleteReq = ReqSchema<"schedule.delete", {
|
|
157
|
+
id: string;
|
|
158
|
+
}>;
|
|
159
|
+
export type ScheduleDeleteRes = ResSchema<"schedule.delete", 200, undefined>;
|
|
160
|
+
export type Req = PromiseGetReq | PromiseCreateReq | PromiseSettleReq | PromiseRegisterReq | PromiseSubscribeReq | TaskGetReq | TaskCreateReq | TaskAcquireReq | TaskSuspendReq | TaskFulfillReq | TaskReleaseReq | TaskFenceReq | TaskHeartbeatReq | ScheduleGetReq | ScheduleCreateReq | ScheduleDeleteReq;
|
|
161
|
+
export type Res = PromiseGetRes | PromiseCreateRes | PromiseSettleRes | PromiseRegisterRes | PromiseSubscribeRes | TaskGetRes | TaskCreateRes | TaskAcquireRes | TaskSuspendRes | TaskFulfillRes | TaskReleaseRes | TaskFenceRes | TaskHeartbeatRes | ScheduleGetRes | ScheduleCreateRes | ScheduleDeleteRes | ErrorRes;
|
|
162
|
+
export {};
|
|
163
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAE1D,KAAK,UAAU,GACX,aAAa,GACb,gBAAgB,GAChB,gBAAgB,GAChB,kBAAkB,GAClB,mBAAmB,GACnB,UAAU,GACV,aAAa,GACb,cAAc,GACd,cAAc,GACd,cAAc,GACd,cAAc,GACd,YAAY,GACZ,gBAAgB,GAChB,cAAc,GACd,iBAAiB,GACjB,iBAAiB,GACjB,OAAO,CAAC;AAEZ,KAAK,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,IAAI;IACxC,IAAI,EAAE,CAAC,CAAC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AAA;SAAE,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACnE,WAAW,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CACxC,CACF,CAAC;AACF,MAAM,MAAM,iBAAiB,GAAG,SAAS,CACvC,iBAAiB,EACjB,GAAG,EACH;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CACvB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,SAAS,CAAC,iBAAiB,EAAE;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAC7E,MAAM,MAAM,iBAAiB,GAAG,SAAS,CAAC,iBAAiB,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;AAE7E,MAAM,MAAM,GAAG,GACX,aAAa,GACb,gBAAgB,GAChB,gBAAgB,GAChB,kBAAkB,GAClB,mBAAmB,GACnB,UAAU,GACV,aAAa,GACb,cAAc,GACd,cAAc,GACd,cAAc,GACd,cAAc,GACd,YAAY,GACZ,gBAAgB,GAChB,cAAc,GACd,iBAAiB,GACjB,iBAAiB,CAAC;AAEtB,MAAM,MAAM,GAAG,GACX,aAAa,GACb,gBAAgB,GAChB,gBAAgB,GAChB,kBAAkB,GAClB,mBAAmB,GACnB,UAAU,GACV,aAAa,GACb,cAAc,GACd,cAAc,GACd,cAAc,GACd,cAAc,GACd,YAAY,GACZ,gBAAgB,GAChB,cAAc,GACd,iBAAiB,GACjB,iBAAiB,GACjB,QAAQ,CAAC"}
|
package/dist/api.js
ADDED
package/dist/api.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":""}
|