wao 0.36.0 → 0.36.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/cjs/hb.js +55 -28
- package/esm/hb.js +25 -14
- package/package.json +1 -1
package/cjs/hb.js
CHANGED
|
@@ -77,8 +77,11 @@ var HB = /*#__PURE__*/function () {
|
|
|
77
77
|
url = _ref2$url === void 0 ? "http://localhost:10001" : _ref2$url,
|
|
78
78
|
_ref2$cu = _ref2.cu,
|
|
79
79
|
cu = _ref2$cu === void 0 ? "http://localhost:6363" : _ref2$cu,
|
|
80
|
-
jwk = _ref2.jwk
|
|
80
|
+
jwk = _ref2.jwk,
|
|
81
|
+
_ref2$format = _ref2.format,
|
|
82
|
+
format = _ref2$format === void 0 ? "httpsig" : _ref2$format;
|
|
81
83
|
_classCallCheck(this, HB);
|
|
84
|
+
this.format = format;
|
|
82
85
|
this.cu = cu;
|
|
83
86
|
this.url = url;
|
|
84
87
|
if (jwk) this._init(jwk);
|
|
@@ -393,20 +396,33 @@ var HB = /*#__PURE__*/function () {
|
|
|
393
396
|
key: "compute",
|
|
394
397
|
value: function () {
|
|
395
398
|
var _compute = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(_ref5) {
|
|
396
|
-
var pid, slot, _ref5$path, path;
|
|
399
|
+
var pid, slot, _ref5$path, path, res;
|
|
397
400
|
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
398
401
|
while (1) switch (_context12.prev = _context12.next) {
|
|
399
402
|
case 0:
|
|
400
403
|
pid = _ref5.pid, slot = _ref5.slot, _ref5$path = _ref5.path, path = _ref5$path === void 0 ? "" : _ref5$path;
|
|
401
404
|
if (path && !/^\//.test(path)) path = "/" + path;
|
|
402
|
-
|
|
405
|
+
if (!(this.format === "ans104")) {
|
|
406
|
+
_context12.next = 9;
|
|
407
|
+
break;
|
|
408
|
+
}
|
|
409
|
+
_context12.next = 5;
|
|
410
|
+
return this.get({
|
|
411
|
+
path: "/".concat(pid, "/compute").concat(path),
|
|
412
|
+
slot: slot
|
|
413
|
+
});
|
|
414
|
+
case 5:
|
|
415
|
+
res = _context12.sent;
|
|
416
|
+
return _context12.abrupt("return", res.out);
|
|
417
|
+
case 9:
|
|
418
|
+
_context12.next = 11;
|
|
403
419
|
return this.getJSON({
|
|
404
420
|
path: "/".concat(pid, "/compute").concat(path),
|
|
405
421
|
slot: slot
|
|
406
422
|
});
|
|
407
|
-
case
|
|
423
|
+
case 11:
|
|
408
424
|
return _context12.abrupt("return", _context12.sent);
|
|
409
|
-
case
|
|
425
|
+
case 12:
|
|
410
426
|
case "end":
|
|
411
427
|
return _context12.stop();
|
|
412
428
|
}
|
|
@@ -476,7 +492,7 @@ var HB = /*#__PURE__*/function () {
|
|
|
476
492
|
data: data,
|
|
477
493
|
pid: this.cache,
|
|
478
494
|
tags: {
|
|
479
|
-
"
|
|
495
|
+
"Content-Type": type
|
|
480
496
|
}
|
|
481
497
|
});
|
|
482
498
|
case 9:
|
|
@@ -584,7 +600,7 @@ var HB = /*#__PURE__*/function () {
|
|
|
584
600
|
case 0:
|
|
585
601
|
_ref7 = _args18.length > 0 && _args18[0] !== undefined ? _args18[0] : {}, pid = _ref7.pid, _ref7$tags = _ref7.tags, tags = _ref7$tags === void 0 ? {} : _ref7$tags, data = _ref7.data;
|
|
586
602
|
_tags = (0, _ramda.mergeLeft)(tags, {
|
|
587
|
-
|
|
603
|
+
Type: "Message",
|
|
588
604
|
target: pid
|
|
589
605
|
});
|
|
590
606
|
if (data) _tags.data = data;
|
|
@@ -670,14 +686,13 @@ var HB = /*#__PURE__*/function () {
|
|
|
670
686
|
signingFormat: "ANS-104"
|
|
671
687
|
}));
|
|
672
688
|
signer = new _sdk.ArweaveSigner(this.jwk);
|
|
673
|
-
console.log(_tags);
|
|
674
689
|
di = (0, _arbundles.createData)(data, signer, {
|
|
675
690
|
tags: _tags
|
|
676
691
|
});
|
|
677
|
-
_context19.next =
|
|
692
|
+
_context19.next = 6;
|
|
678
693
|
return di.sign(signer);
|
|
679
|
-
case
|
|
680
|
-
_context19.next =
|
|
694
|
+
case 6:
|
|
695
|
+
_context19.next = 8;
|
|
681
696
|
return fetch("".concat(this.url).concat(path), {
|
|
682
697
|
method: "POST",
|
|
683
698
|
headers: {
|
|
@@ -686,19 +701,19 @@ var HB = /*#__PURE__*/function () {
|
|
|
686
701
|
},
|
|
687
702
|
body: di.binary
|
|
688
703
|
});
|
|
689
|
-
case
|
|
704
|
+
case 8:
|
|
690
705
|
res = _context19.sent;
|
|
691
706
|
_context19.t0 = _hbsig.structured_to;
|
|
692
707
|
_context19.t1 = _hbsig.httpsig_from;
|
|
693
|
-
_context19.next =
|
|
708
|
+
_context19.next = 13;
|
|
694
709
|
return toMsg(res);
|
|
695
|
-
case
|
|
710
|
+
case 13:
|
|
696
711
|
_context19.t2 = _context19.sent;
|
|
697
712
|
_context19.t3 = (0, _context19.t1)(_context19.t2);
|
|
698
713
|
_headers = (0, _context19.t0)(_context19.t3);
|
|
699
714
|
res.out = _headers;
|
|
700
715
|
return _context19.abrupt("return", res);
|
|
701
|
-
case
|
|
716
|
+
case 18:
|
|
702
717
|
case "end":
|
|
703
718
|
return _context19.stop();
|
|
704
719
|
}
|
|
@@ -734,7 +749,7 @@ var HB = /*#__PURE__*/function () {
|
|
|
734
749
|
break;
|
|
735
750
|
}
|
|
736
751
|
_tags = (0, _ramda.mergeLeft)(tags, {
|
|
737
|
-
|
|
752
|
+
Type: "Message"
|
|
738
753
|
});
|
|
739
754
|
_context20.next = 6;
|
|
740
755
|
return this.post104({
|
|
@@ -748,7 +763,7 @@ var HB = /*#__PURE__*/function () {
|
|
|
748
763
|
break;
|
|
749
764
|
case 9:
|
|
750
765
|
_tags2 = (0, _ramda.mergeLeft)(tags, {
|
|
751
|
-
|
|
766
|
+
Type: "Message",
|
|
752
767
|
target: pid
|
|
753
768
|
});
|
|
754
769
|
if (data) _tags2.data = data;
|
|
@@ -865,19 +880,31 @@ var HB = /*#__PURE__*/function () {
|
|
|
865
880
|
key: "now",
|
|
866
881
|
value: function () {
|
|
867
882
|
var _now = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee23(_ref12) {
|
|
868
|
-
var pid, _ref12$path, path;
|
|
883
|
+
var pid, _ref12$path, path, res;
|
|
869
884
|
return _regeneratorRuntime().wrap(function _callee23$(_context23) {
|
|
870
885
|
while (1) switch (_context23.prev = _context23.next) {
|
|
871
886
|
case 0:
|
|
872
887
|
pid = _ref12.pid, _ref12$path = _ref12.path, path = _ref12$path === void 0 ? "" : _ref12$path;
|
|
873
888
|
if (path && !/^\//.test(path)) path = "/" + path;
|
|
874
|
-
|
|
889
|
+
if (!(this.format === "ans104")) {
|
|
890
|
+
_context23.next = 9;
|
|
891
|
+
break;
|
|
892
|
+
}
|
|
893
|
+
_context23.next = 5;
|
|
894
|
+
return this.get({
|
|
895
|
+
path: "/".concat(pid, "/now").concat(path)
|
|
896
|
+
});
|
|
897
|
+
case 5:
|
|
898
|
+
res = _context23.sent;
|
|
899
|
+
return _context23.abrupt("return", res.out);
|
|
900
|
+
case 9:
|
|
901
|
+
_context23.next = 11;
|
|
875
902
|
return this.getJSON({
|
|
876
903
|
path: "/".concat(pid, "/now").concat(path)
|
|
877
904
|
});
|
|
878
|
-
case
|
|
905
|
+
case 11:
|
|
879
906
|
return _context23.abrupt("return", _context23.sent);
|
|
880
|
-
case
|
|
907
|
+
case 12:
|
|
881
908
|
case "end":
|
|
882
909
|
return _context23.stop();
|
|
883
910
|
}
|
|
@@ -999,10 +1026,10 @@ var HB = /*#__PURE__*/function () {
|
|
|
999
1026
|
tags: (0, _ramda.mergeLeft)(tags, {
|
|
1000
1027
|
"codec-device": "ans104@1.0",
|
|
1001
1028
|
"random-seed": (0, _utils.seed)(16),
|
|
1002
|
-
|
|
1029
|
+
Type: "Process",
|
|
1003
1030
|
"execution-device": "test-device@1.0",
|
|
1004
1031
|
device: "process@1.0",
|
|
1005
|
-
|
|
1032
|
+
Scheduler: this.operator
|
|
1006
1033
|
})
|
|
1007
1034
|
});
|
|
1008
1035
|
case 7:
|
|
@@ -1014,10 +1041,10 @@ var HB = /*#__PURE__*/function () {
|
|
|
1014
1041
|
_context27.next = 13;
|
|
1015
1042
|
return this.commit((0, _ramda.mergeLeft)(tags, {
|
|
1016
1043
|
"random-seed": (0, _utils.seed)(16),
|
|
1017
|
-
|
|
1044
|
+
Type: "Process",
|
|
1018
1045
|
"execution-device": "test-device@1.0",
|
|
1019
1046
|
device: "process@1.0",
|
|
1020
|
-
|
|
1047
|
+
Scheduler: this.operator
|
|
1021
1048
|
}), {
|
|
1022
1049
|
path: false
|
|
1023
1050
|
});
|
|
@@ -1027,7 +1054,7 @@ var HB = /*#__PURE__*/function () {
|
|
|
1027
1054
|
_context27.t3 = {
|
|
1028
1055
|
path: "/~process@1.0/schedule",
|
|
1029
1056
|
body: _context27.t1,
|
|
1030
|
-
|
|
1057
|
+
Scheduler: _context27.t2
|
|
1031
1058
|
};
|
|
1032
1059
|
_context27.next = 18;
|
|
1033
1060
|
return _context27.t0.post.call(_context27.t0, _context27.t3);
|
|
@@ -1160,7 +1187,7 @@ var HB = /*#__PURE__*/function () {
|
|
|
1160
1187
|
path: "/~relay@1.0/call",
|
|
1161
1188
|
method: "GET",
|
|
1162
1189
|
"relay-path": "".concat(this.cu, "/results/").concat(process).concat(params),
|
|
1163
|
-
"
|
|
1190
|
+
"Content-Type": "application/json"
|
|
1164
1191
|
});
|
|
1165
1192
|
case 9:
|
|
1166
1193
|
res = _context30.sent;
|
|
@@ -1204,7 +1231,7 @@ var HB = /*#__PURE__*/function () {
|
|
|
1204
1231
|
path: "/~relay@1.0/call",
|
|
1205
1232
|
method: "POST",
|
|
1206
1233
|
"relay-path": "".concat(this.cu, "/dry-run?process-id=").concat(pid),
|
|
1207
|
-
"
|
|
1234
|
+
"Content-Type": "application/json",
|
|
1208
1235
|
"relay-body": JSON.stringify(json)
|
|
1209
1236
|
});
|
|
1210
1237
|
case 6:
|
package/esm/hb.js
CHANGED
|
@@ -24,7 +24,9 @@ class HB {
|
|
|
24
24
|
url = "http://localhost:10001",
|
|
25
25
|
cu = "http://localhost:6363",
|
|
26
26
|
jwk,
|
|
27
|
+
format = "httpsig",
|
|
27
28
|
} = {}) {
|
|
29
|
+
this.format = format
|
|
28
30
|
this.cu = cu
|
|
29
31
|
this.url = url
|
|
30
32
|
if (jwk) this._init(jwk)
|
|
@@ -104,7 +106,12 @@ class HB {
|
|
|
104
106
|
|
|
105
107
|
async compute({ pid, slot, path = "" }) {
|
|
106
108
|
if (path && !/^\//.test(path)) path = "/" + path
|
|
107
|
-
|
|
109
|
+
if (this.format === "ans104") {
|
|
110
|
+
const res = await this.get({ path: `/${pid}/compute${path}`, slot })
|
|
111
|
+
return res.out
|
|
112
|
+
} else {
|
|
113
|
+
return await this.getJSON({ path: `/${pid}/compute${path}`, slot })
|
|
114
|
+
}
|
|
108
115
|
}
|
|
109
116
|
|
|
110
117
|
async computeLegacy({ pid, slot }) {
|
|
@@ -120,7 +127,7 @@ class HB {
|
|
|
120
127
|
const { slot } = await this.scheduleFlat({
|
|
121
128
|
data,
|
|
122
129
|
pid: this.cache,
|
|
123
|
-
tags: { "
|
|
130
|
+
tags: { "Content-Type": type },
|
|
124
131
|
})
|
|
125
132
|
const msgs = await this.messages({ pid: this.cache, from: slot, limit: 1 })
|
|
126
133
|
return msgs.edges[0].node.message.Id
|
|
@@ -139,7 +146,7 @@ class HB {
|
|
|
139
146
|
}
|
|
140
147
|
|
|
141
148
|
async scheduleFlat({ pid, tags = {}, data } = {}) {
|
|
142
|
-
let _tags = mergeLeft(tags, {
|
|
149
|
+
let _tags = mergeLeft(tags, { Type: "Message", target: pid })
|
|
143
150
|
if (data) _tags.data = data
|
|
144
151
|
let res = await this.post({ path: "/~process@1.0/schedule", body: _tags })
|
|
145
152
|
return { slot: res.out.slot, res, pid }
|
|
@@ -156,7 +163,6 @@ class HB {
|
|
|
156
163
|
async post104({ path = "/~process@1.0/schedule", tags = {}, data = "1984" }) {
|
|
157
164
|
const _tags = buildTags(mergeLeft(tags, { signingFormat: "ANS-104" }))
|
|
158
165
|
const signer = new ArweaveSigner(this.jwk)
|
|
159
|
-
console.log(_tags)
|
|
160
166
|
const di = createData(data, signer, { tags: _tags })
|
|
161
167
|
await di.sign(signer)
|
|
162
168
|
let res = await fetch(`${this.url}${path}`, {
|
|
@@ -175,14 +181,14 @@ class HB {
|
|
|
175
181
|
async schedule({ pid, tags = {}, data } = {}) {
|
|
176
182
|
let res = null
|
|
177
183
|
if (this.format === "ans104") {
|
|
178
|
-
let _tags = mergeLeft(tags, {
|
|
184
|
+
let _tags = mergeLeft(tags, { Type: "Message" })
|
|
179
185
|
res = await this.post104({
|
|
180
186
|
path: `/${pid}/schedule`,
|
|
181
187
|
tags: _tags,
|
|
182
188
|
data: data ?? "1984",
|
|
183
189
|
})
|
|
184
190
|
} else {
|
|
185
|
-
let _tags = mergeLeft(tags, {
|
|
191
|
+
let _tags = mergeLeft(tags, { Type: "Message", target: pid })
|
|
186
192
|
if (data) _tags.data = data
|
|
187
193
|
let body = await this.commit(_tags, { path: false })
|
|
188
194
|
let signed = await this.sign({ path: `/${pid}/schedule`, body })
|
|
@@ -212,7 +218,12 @@ class HB {
|
|
|
212
218
|
|
|
213
219
|
async now({ pid, path = "" }) {
|
|
214
220
|
if (path && !/^\//.test(path)) path = "/" + path
|
|
215
|
-
|
|
221
|
+
if (this.format === "ans104") {
|
|
222
|
+
const res = await this.get({ path: `/${pid}/now${path}` })
|
|
223
|
+
return res.out
|
|
224
|
+
} else {
|
|
225
|
+
return await this.getJSON({ path: `/${pid}/now${path}` })
|
|
226
|
+
}
|
|
216
227
|
}
|
|
217
228
|
|
|
218
229
|
async slot({ pid, path = "" }) {
|
|
@@ -244,10 +255,10 @@ class HB {
|
|
|
244
255
|
tags: mergeLeft(tags, {
|
|
245
256
|
"codec-device": "ans104@1.0",
|
|
246
257
|
"random-seed": seed(16),
|
|
247
|
-
|
|
258
|
+
Type: "Process",
|
|
248
259
|
"execution-device": "test-device@1.0",
|
|
249
260
|
device: "process@1.0",
|
|
250
|
-
|
|
261
|
+
Scheduler: this.operator,
|
|
251
262
|
}),
|
|
252
263
|
})
|
|
253
264
|
} else {
|
|
@@ -256,14 +267,14 @@ class HB {
|
|
|
256
267
|
body: await this.commit(
|
|
257
268
|
mergeLeft(tags, {
|
|
258
269
|
"random-seed": seed(16),
|
|
259
|
-
|
|
270
|
+
Type: "Process",
|
|
260
271
|
"execution-device": "test-device@1.0",
|
|
261
272
|
device: "process@1.0",
|
|
262
|
-
|
|
273
|
+
Scheduler: this.operator,
|
|
263
274
|
}),
|
|
264
275
|
{ path: false }
|
|
265
276
|
),
|
|
266
|
-
|
|
277
|
+
Scheduler: this.operator,
|
|
267
278
|
})
|
|
268
279
|
}
|
|
269
280
|
return { res, pid: res.out.process }
|
|
@@ -304,7 +315,7 @@ class HB {
|
|
|
304
315
|
path: "/~relay@1.0/call",
|
|
305
316
|
method: "GET",
|
|
306
317
|
"relay-path": `${this.cu}/results/${process}${params}`,
|
|
307
|
-
"
|
|
318
|
+
"Content-Type": "application/json",
|
|
308
319
|
})
|
|
309
320
|
return JSON.parse(res.body)
|
|
310
321
|
}
|
|
@@ -317,7 +328,7 @@ class HB {
|
|
|
317
328
|
path: "/~relay@1.0/call",
|
|
318
329
|
method: "POST",
|
|
319
330
|
"relay-path": `${this.cu}/dry-run?process-id=${pid}`,
|
|
320
|
-
"
|
|
331
|
+
"Content-Type": "application/json",
|
|
321
332
|
"relay-body": JSON.stringify(json),
|
|
322
333
|
})
|
|
323
334
|
return JSON.parse(res.body)
|