appmesh 3.1.6 → 3.1.7
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/README.md +27 -23
- package/dist/appmesh.esm.js +1 -1
- package/package.json +2 -2
- package/src/appmesh.js +77 -71
- package/src/appmesh_tcp.js +306 -210
- package/src/worker.js +34 -44
package/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# App Mesh JavaScript SDK
|
|
2
2
|
|
|
3
|
+
> **Naming**: public methods use camelCase (`listApps`, `runAppSync`). The
|
|
4
|
+
> deprecated snake_case aliases (`list_apps`, ...) were removed in 3.1.7 —
|
|
5
|
+
> migrate callers to the camelCase names.
|
|
6
|
+
|
|
3
7
|
## Client SDK
|
|
4
8
|
|
|
5
9
|
### Build
|
|
@@ -22,7 +26,7 @@ npm i appmesh
|
|
|
22
26
|
import { AppMeshClient } from "appmesh";
|
|
23
27
|
|
|
24
28
|
const client = new AppMeshClient();
|
|
25
|
-
client.
|
|
29
|
+
client.setBearerToken(process.env.APPMESH_BEARER_TOKEN);
|
|
26
30
|
```
|
|
27
31
|
|
|
28
32
|
#### Browser (VUE Example)
|
|
@@ -98,14 +102,14 @@ const server = new AppMeshWorker();
|
|
|
98
102
|
|
|
99
103
|
try {
|
|
100
104
|
// Fetch task from client
|
|
101
|
-
const payload = await server.
|
|
105
|
+
const payload = await server.fetchTask();
|
|
102
106
|
console.log("Received:", payload);
|
|
103
107
|
|
|
104
108
|
// Process the task
|
|
105
109
|
const result = processData(payload);
|
|
106
110
|
|
|
107
111
|
// Return result to client
|
|
108
|
-
await server.
|
|
112
|
+
await server.sendTaskResult(result);
|
|
109
113
|
} catch (error) {
|
|
110
114
|
if (error instanceof ProcessSupersededError || error instanceof WorkerRejectedError) {
|
|
111
115
|
// This process was replaced (412), or its request is permanently invalid (400).
|
|
@@ -151,9 +155,9 @@ const sslConfig = {
|
|
|
151
155
|
await withServer(
|
|
152
156
|
() => new AppMeshWorkerTCP(sslConfig, ["127.0.0.1", 6059]),
|
|
153
157
|
async (server) => {
|
|
154
|
-
const payload = await server.
|
|
158
|
+
const payload = await server.fetchTask();
|
|
155
159
|
const result = processPayload(payload);
|
|
156
|
-
await server.
|
|
160
|
+
await server.sendTaskResult(result);
|
|
157
161
|
}
|
|
158
162
|
);
|
|
159
163
|
// Connection automatically closed
|
|
@@ -192,7 +196,7 @@ new AppMeshWorker(baseURL, sslConfig, options);
|
|
|
192
196
|
|
|
193
197
|
##### Methods
|
|
194
198
|
|
|
195
|
-
###### `
|
|
199
|
+
###### `fetchTask()`
|
|
196
200
|
|
|
197
201
|
Fetch task payload from the App Mesh service. Automatically retries transient failures.
|
|
198
202
|
|
|
@@ -203,11 +207,11 @@ Fetch task payload from the App Mesh service. Automatically retries transient fa
|
|
|
203
207
|
**Example:**
|
|
204
208
|
|
|
205
209
|
```javascript
|
|
206
|
-
const payload = await server.
|
|
210
|
+
const payload = await server.fetchTask();
|
|
207
211
|
const data = JSON.parse(payload);
|
|
208
212
|
```
|
|
209
213
|
|
|
210
|
-
###### `
|
|
214
|
+
###### `sendTaskResult(result)`
|
|
211
215
|
|
|
212
216
|
Return processed result back to the client.
|
|
213
217
|
|
|
@@ -223,12 +227,12 @@ Return processed result back to the client.
|
|
|
223
227
|
|
|
224
228
|
```javascript
|
|
225
229
|
const result = { status: "success", data: processedData };
|
|
226
|
-
await server.
|
|
230
|
+
await server.sendTaskResult(JSON.stringify(result));
|
|
227
231
|
```
|
|
228
232
|
|
|
229
233
|
###### `stop()`
|
|
230
234
|
|
|
231
|
-
Cancel the fetch loop. A running `
|
|
235
|
+
Cancel the fetch loop. A running `fetchTask()` call resolves `null`.
|
|
232
236
|
|
|
233
237
|
```javascript
|
|
234
238
|
server.stop();
|
|
@@ -288,8 +292,8 @@ Context manager for automatic resource cleanup.
|
|
|
288
292
|
await withServer(
|
|
289
293
|
() => new AppMeshWorkerTCP(),
|
|
290
294
|
async (server) => {
|
|
291
|
-
const payload = await server.
|
|
292
|
-
await server.
|
|
295
|
+
const payload = await server.fetchTask();
|
|
296
|
+
await server.sendTaskResult(processData(payload));
|
|
293
297
|
}
|
|
294
298
|
);
|
|
295
299
|
```
|
|
@@ -304,7 +308,7 @@ import { AppMeshWorker } from "appmesh/worker";
|
|
|
304
308
|
const server = new AppMeshWorker();
|
|
305
309
|
|
|
306
310
|
try {
|
|
307
|
-
const payload = await server.
|
|
311
|
+
const payload = await server.fetchTask();
|
|
308
312
|
const data = JSON.parse(payload);
|
|
309
313
|
|
|
310
314
|
// Process JSON data
|
|
@@ -314,9 +318,9 @@ try {
|
|
|
314
318
|
timestamp: new Date().toISOString(),
|
|
315
319
|
};
|
|
316
320
|
|
|
317
|
-
await server.
|
|
321
|
+
await server.sendTaskResult(JSON.stringify(result));
|
|
318
322
|
} catch (error) {
|
|
319
|
-
await server.
|
|
323
|
+
await server.sendTaskResult(
|
|
320
324
|
JSON.stringify({
|
|
321
325
|
status: "error",
|
|
322
326
|
message: error.message,
|
|
@@ -333,7 +337,7 @@ import crypto from "crypto";
|
|
|
333
337
|
|
|
334
338
|
const server = new AppMeshWorker();
|
|
335
339
|
|
|
336
|
-
const binaryPayload = await server.
|
|
340
|
+
const binaryPayload = await server.fetchTask();
|
|
337
341
|
const hash = crypto.createHash("sha256");
|
|
338
342
|
hash.update(binaryPayload);
|
|
339
343
|
|
|
@@ -342,7 +346,7 @@ const result = {
|
|
|
342
346
|
checksum: hash.digest("hex"),
|
|
343
347
|
};
|
|
344
348
|
|
|
345
|
-
await server.
|
|
349
|
+
await server.sendTaskResult(JSON.stringify(result));
|
|
346
350
|
```
|
|
347
351
|
|
|
348
352
|
#### Long-Running Task
|
|
@@ -352,7 +356,7 @@ import { AppMeshWorker } from "appmesh/worker";
|
|
|
352
356
|
|
|
353
357
|
const server = new AppMeshWorker();
|
|
354
358
|
|
|
355
|
-
const config = JSON.parse(await server.
|
|
359
|
+
const config = JSON.parse(await server.fetchTask());
|
|
356
360
|
const results = [];
|
|
357
361
|
|
|
358
362
|
for (let i = 0; i < config.steps; i++) {
|
|
@@ -362,7 +366,7 @@ for (let i = 0; i < config.steps; i++) {
|
|
|
362
366
|
console.log(`Step ${i + 1}/${config.steps} completed`);
|
|
363
367
|
}
|
|
364
368
|
|
|
365
|
-
await server.
|
|
369
|
+
await server.sendTaskResult(
|
|
366
370
|
JSON.stringify({
|
|
367
371
|
status: "success",
|
|
368
372
|
results: results,
|
|
@@ -379,9 +383,9 @@ await server.send_task_result(
|
|
|
379
383
|
import { AppMeshClient } from "appmesh";
|
|
380
384
|
|
|
381
385
|
const client = new AppMeshClient();
|
|
382
|
-
client.
|
|
386
|
+
client.setBearerToken(process.env.APPMESH_BEARER_TOKEN);
|
|
383
387
|
|
|
384
|
-
const result = await client.
|
|
388
|
+
const result = await client.runTask(
|
|
385
389
|
"my-app",
|
|
386
390
|
JSON.stringify({
|
|
387
391
|
action: "process",
|
|
@@ -400,7 +404,7 @@ import { AppMeshWorker } from "appmesh/worker";
|
|
|
400
404
|
|
|
401
405
|
const server = new AppMeshWorker();
|
|
402
406
|
|
|
403
|
-
const payload = await server.
|
|
407
|
+
const payload = await server.fetchTask();
|
|
404
408
|
const request = JSON.parse(payload);
|
|
405
409
|
|
|
406
410
|
const result = {
|
|
@@ -408,7 +412,7 @@ const result = {
|
|
|
408
412
|
sum: request.data.reduce((a, b) => a + b, 0),
|
|
409
413
|
};
|
|
410
414
|
|
|
411
|
-
await server.
|
|
415
|
+
await server.sendTaskResult(JSON.stringify(result));
|
|
412
416
|
```
|
|
413
417
|
|
|
414
418
|
## Behavioral contract
|