soroban-events 2.0.0 → 2.0.2
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/package.json +1 -1
- package/src/cli-command.js +56 -12
- package/src/cli.js +44 -14
- package/src/engine.js +4 -4
package/package.json
CHANGED
package/src/cli-command.js
CHANGED
|
@@ -85,8 +85,12 @@ export class Command {
|
|
|
85
85
|
const args =
|
|
86
86
|
argv.slice(2);
|
|
87
87
|
|
|
88
|
+
if (args.length === 0) {
|
|
89
|
+
this.printHelp();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
88
93
|
if (
|
|
89
|
-
args.length === 0 ||
|
|
90
94
|
args[0] === '--help' ||
|
|
91
95
|
args[0] === '-h'
|
|
92
96
|
) {
|
|
@@ -121,6 +125,24 @@ export class Command {
|
|
|
121
125
|
}
|
|
122
126
|
|
|
123
127
|
async #run(args) {
|
|
128
|
+
if (
|
|
129
|
+
args[0] === '--help' ||
|
|
130
|
+
args[0] === '-h'
|
|
131
|
+
) {
|
|
132
|
+
this.printHelp();
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (
|
|
137
|
+
args[0] === '--version' ||
|
|
138
|
+
args[0] === '-v'
|
|
139
|
+
) {
|
|
140
|
+
process.stdout.write(
|
|
141
|
+
`${this.#version}\n`
|
|
142
|
+
);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
124
146
|
const values = {};
|
|
125
147
|
|
|
126
148
|
for (const option of this.#options) {
|
|
@@ -178,24 +200,46 @@ export class Command {
|
|
|
178
200
|
}
|
|
179
201
|
|
|
180
202
|
printHelp() {
|
|
181
|
-
const
|
|
182
|
-
this
|
|
203
|
+
const command =
|
|
204
|
+
this;
|
|
183
205
|
|
|
184
|
-
const
|
|
185
|
-
|
|
206
|
+
const lines = [
|
|
207
|
+
command.#name,
|
|
208
|
+
command.#description,
|
|
209
|
+
''
|
|
210
|
+
];
|
|
186
211
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
root.#name,
|
|
190
|
-
root.#description,
|
|
191
|
-
'',
|
|
212
|
+
if (command.#commands.size > 0) {
|
|
213
|
+
lines.push(
|
|
192
214
|
'Commands:',
|
|
193
|
-
...commands.map(
|
|
215
|
+
...[...command.#commands.keys()].map(
|
|
194
216
|
name =>
|
|
195
217
|
` ${name}`
|
|
196
218
|
),
|
|
197
219
|
''
|
|
198
|
-
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (command.#options.length > 0) {
|
|
224
|
+
lines.push(
|
|
225
|
+
'Options:',
|
|
226
|
+
...command.#options.map(
|
|
227
|
+
option =>
|
|
228
|
+
` ${option.flag} ${option.description}`
|
|
229
|
+
),
|
|
230
|
+
''
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (command.#version) {
|
|
235
|
+
lines.push(
|
|
236
|
+
' -v, --version Show version',
|
|
237
|
+
''
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
process.stdout.write(
|
|
242
|
+
lines.join('\n')
|
|
199
243
|
);
|
|
200
244
|
}
|
|
201
245
|
}
|
package/src/cli.js
CHANGED
|
@@ -56,7 +56,17 @@ program
|
|
|
56
56
|
await fetch(
|
|
57
57
|
rpc,
|
|
58
58
|
{
|
|
59
|
-
method: '
|
|
59
|
+
method: 'POST',
|
|
60
|
+
headers: {
|
|
61
|
+
'content-type':
|
|
62
|
+
'application/json'
|
|
63
|
+
},
|
|
64
|
+
body: JSON.stringify({
|
|
65
|
+
jsonrpc: '2.0',
|
|
66
|
+
id: 1,
|
|
67
|
+
method: 'getHealth',
|
|
68
|
+
params: {}
|
|
69
|
+
})
|
|
60
70
|
}
|
|
61
71
|
);
|
|
62
72
|
|
|
@@ -131,23 +141,43 @@ program
|
|
|
131
141
|
);
|
|
132
142
|
}
|
|
133
143
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
null,
|
|
138
|
-
2
|
|
139
|
-
) + '\n'
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
if (!response.ok) {
|
|
143
|
-
process.exitCode = 1;
|
|
144
|
-
}
|
|
144
|
+
const rpcError =
|
|
145
|
+
parsed &&
|
|
146
|
+
parsed.error;
|
|
145
147
|
|
|
146
148
|
if (
|
|
147
|
-
|
|
148
|
-
|
|
149
|
+
response.ok === false ||
|
|
150
|
+
rpcError
|
|
149
151
|
) {
|
|
152
|
+
process.stdout.write(
|
|
153
|
+
JSON.stringify(
|
|
154
|
+
rpcError ?? {
|
|
155
|
+
status: response.status,
|
|
156
|
+
statusText: response.statusText
|
|
157
|
+
},
|
|
158
|
+
null,
|
|
159
|
+
2
|
|
160
|
+
) + '\n'
|
|
161
|
+
);
|
|
162
|
+
|
|
150
163
|
process.exitCode = 1;
|
|
164
|
+
} else {
|
|
165
|
+
const sequence =
|
|
166
|
+
parsed &&
|
|
167
|
+
parsed.result &&
|
|
168
|
+
parsed.result.sequence;
|
|
169
|
+
|
|
170
|
+
if (
|
|
171
|
+
sequence === undefined
|
|
172
|
+
) {
|
|
173
|
+
throw new Error(
|
|
174
|
+
'RPC response did not contain result.sequence'
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
process.stdout.write(
|
|
179
|
+
`${sequence}\n`
|
|
180
|
+
);
|
|
151
181
|
}
|
|
152
182
|
}
|
|
153
183
|
);
|
package/src/engine.js
CHANGED
|
@@ -370,7 +370,7 @@ export class EventEngine {
|
|
|
370
370
|
checkpoint,
|
|
371
371
|
checkpointKey,
|
|
372
372
|
signal,
|
|
373
|
-
|
|
373
|
+
onEvent: async (
|
|
374
374
|
event,
|
|
375
375
|
context
|
|
376
376
|
) => {
|
|
@@ -384,10 +384,10 @@ export class EventEngine {
|
|
|
384
384
|
}
|
|
385
385
|
|
|
386
386
|
if (
|
|
387
|
-
typeof options.
|
|
387
|
+
typeof options.onEvent ===
|
|
388
388
|
'function'
|
|
389
389
|
) {
|
|
390
|
-
await options.
|
|
390
|
+
await options.onEvent(
|
|
391
391
|
event,
|
|
392
392
|
context
|
|
393
393
|
);
|
|
@@ -506,7 +506,7 @@ export class EventEngine {
|
|
|
506
506
|
await this.consume({
|
|
507
507
|
filters,
|
|
508
508
|
signal: effectiveSignal,
|
|
509
|
-
|
|
509
|
+
onEvent
|
|
510
510
|
});
|
|
511
511
|
|
|
512
512
|
return {
|