wao 0.9.2 → 0.10.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/ao.js +31 -32
- package/cjs/aoconnect-base.js +197 -175
- package/cjs/armem-base.js +300 -116
- package/cjs/armem-web.js +11 -1
- package/cjs/armem.js +8 -1
- package/cjs/{ar-base.js → bar.js} +29 -30
- package/cjs/build.js +8 -0
- package/cjs/compress.js +165 -0
- package/cjs/server.js +66 -46
- package/cjs/tar.js +2 -2
- package/cjs/tgql.js +81 -78
- package/cjs/waosm/waosm.js +332 -0
- package/cjs/waosm-node/waosm.js +21 -0
- package/cjs/waosm-node/waosm_bg.js +193 -0
- package/cjs/waosm-node.js +28 -0
- package/cjs/war.js +2 -2
- package/esm/ao.js +7 -7
- package/esm/aoconnect-base.js +25 -24
- package/esm/armem-base.js +91 -11
- package/esm/armem-web.js +2 -1
- package/esm/armem.js +2 -1
- package/esm/{ar-base.js → bar.js} +9 -15
- package/esm/build.js +7 -0
- package/esm/compress.js +113 -0
- package/esm/lfdb.js +1 -3
- package/esm/server.js +5 -5
- package/esm/tar.js +1 -1
- package/esm/tgql.js +2 -2
- package/esm/waosm/README.md +79 -0
- package/esm/waosm/package.json +14 -0
- package/esm/waosm/waosm.d.ts +46 -0
- package/esm/waosm/waosm.js +264 -0
- package/esm/waosm/waosm_bg.wasm +0 -0
- package/esm/waosm/waosm_bg.wasm.d.ts +10 -0
- package/esm/waosm-node/README.md +79 -0
- package/esm/waosm-node/waosm.d.ts +12 -0
- package/esm/waosm-node/waosm.js +4 -0
- package/esm/waosm-node/waosm_bg.js +171 -0
- package/esm/waosm-node/waosm_bg.wasm +0 -0
- package/esm/waosm-node/waosm_bg.wasm.d.ts +10 -0
- package/esm/waosm-node.js +13 -0
- package/esm/war.js +1 -1
- package/package.json +4 -1
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Decompressor = exports.Compressor = void 0;
|
|
7
|
+
exports.__wbg_buffer_609cc3eee51ed158 = __wbg_buffer_609cc3eee51ed158;
|
|
8
|
+
exports.__wbg_length_a446193dc22c12f8 = __wbg_length_a446193dc22c12f8;
|
|
9
|
+
exports.__wbg_newwithbyteoffsetandlength_d97e637ebe145a9a = __wbg_newwithbyteoffsetandlength_d97e637ebe145a9a;
|
|
10
|
+
exports.__wbg_newwithlength_a381634e90c276d4 = __wbg_newwithlength_a381634e90c276d4;
|
|
11
|
+
exports.__wbg_set_65595bdd868b3009 = __wbg_set_65595bdd868b3009;
|
|
12
|
+
exports.__wbg_set_wasm = __wbg_set_wasm;
|
|
13
|
+
exports.__wbindgen_memory = __wbindgen_memory;
|
|
14
|
+
exports.__wbindgen_object_drop_ref = __wbindgen_object_drop_ref;
|
|
15
|
+
exports.__wbindgen_throw = __wbindgen_throw;
|
|
16
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
17
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
18
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
19
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
20
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
21
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
22
|
+
var wasm;
|
|
23
|
+
function __wbg_set_wasm(val) {
|
|
24
|
+
wasm = val;
|
|
25
|
+
}
|
|
26
|
+
var heap = new Array(128).fill(undefined);
|
|
27
|
+
heap.push(undefined, null, true, false);
|
|
28
|
+
function getObject(idx) {
|
|
29
|
+
return heap[idx];
|
|
30
|
+
}
|
|
31
|
+
var heap_next = heap.length;
|
|
32
|
+
function addHeapObject(obj) {
|
|
33
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
34
|
+
var idx = heap_next;
|
|
35
|
+
heap_next = heap[idx];
|
|
36
|
+
heap[idx] = obj;
|
|
37
|
+
return idx;
|
|
38
|
+
}
|
|
39
|
+
function dropObject(idx) {
|
|
40
|
+
if (idx < 132) return;
|
|
41
|
+
heap[idx] = heap_next;
|
|
42
|
+
heap_next = idx;
|
|
43
|
+
}
|
|
44
|
+
function takeObject(idx) {
|
|
45
|
+
var ret = getObject(idx);
|
|
46
|
+
dropObject(idx);
|
|
47
|
+
return ret;
|
|
48
|
+
}
|
|
49
|
+
var lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
|
|
50
|
+
var cachedTextDecoder = new lTextDecoder('utf-8', {
|
|
51
|
+
ignoreBOM: true,
|
|
52
|
+
fatal: true
|
|
53
|
+
});
|
|
54
|
+
cachedTextDecoder.decode();
|
|
55
|
+
var cachedUint8ArrayMemory0 = null;
|
|
56
|
+
function getUint8ArrayMemory0() {
|
|
57
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
58
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
59
|
+
}
|
|
60
|
+
return cachedUint8ArrayMemory0;
|
|
61
|
+
}
|
|
62
|
+
function getStringFromWasm0(ptr, len) {
|
|
63
|
+
ptr = ptr >>> 0;
|
|
64
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
65
|
+
}
|
|
66
|
+
var WASM_VECTOR_LEN = 0;
|
|
67
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
68
|
+
var ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
69
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
70
|
+
WASM_VECTOR_LEN = arg.length;
|
|
71
|
+
return ptr;
|
|
72
|
+
}
|
|
73
|
+
var CompressorFinalization = typeof FinalizationRegistry === 'undefined' ? {
|
|
74
|
+
register: function register() {},
|
|
75
|
+
unregister: function unregister() {}
|
|
76
|
+
} : new FinalizationRegistry(function (ptr) {
|
|
77
|
+
return wasm.__wbg_compressor_free(ptr >>> 0, 1);
|
|
78
|
+
});
|
|
79
|
+
var Compressor = exports.Compressor = /*#__PURE__*/function () {
|
|
80
|
+
function Compressor() {
|
|
81
|
+
_classCallCheck(this, Compressor);
|
|
82
|
+
var ret = wasm.compressor_new();
|
|
83
|
+
this.__wbg_ptr = ret >>> 0;
|
|
84
|
+
CompressorFinalization.register(this, this.__wbg_ptr, this);
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* @param {Uint8Array} data
|
|
89
|
+
* @returns {Uint8Array}
|
|
90
|
+
*/
|
|
91
|
+
return _createClass(Compressor, [{
|
|
92
|
+
key: "__destroy_into_raw",
|
|
93
|
+
value: function __destroy_into_raw() {
|
|
94
|
+
var ptr = this.__wbg_ptr;
|
|
95
|
+
this.__wbg_ptr = 0;
|
|
96
|
+
CompressorFinalization.unregister(this);
|
|
97
|
+
return ptr;
|
|
98
|
+
}
|
|
99
|
+
}, {
|
|
100
|
+
key: "free",
|
|
101
|
+
value: function free() {
|
|
102
|
+
var ptr = this.__destroy_into_raw();
|
|
103
|
+
wasm.__wbg_compressor_free(ptr, 0);
|
|
104
|
+
}
|
|
105
|
+
}, {
|
|
106
|
+
key: "compress",
|
|
107
|
+
value: function compress(data) {
|
|
108
|
+
var ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
109
|
+
var len0 = WASM_VECTOR_LEN;
|
|
110
|
+
var ret = wasm.compressor_compress(this.__wbg_ptr, ptr0, len0);
|
|
111
|
+
return takeObject(ret);
|
|
112
|
+
}
|
|
113
|
+
}]);
|
|
114
|
+
}();
|
|
115
|
+
var DecompressorFinalization = typeof FinalizationRegistry === 'undefined' ? {
|
|
116
|
+
register: function register() {},
|
|
117
|
+
unregister: function unregister() {}
|
|
118
|
+
} : new FinalizationRegistry(function (ptr) {
|
|
119
|
+
return wasm.__wbg_decompressor_free(ptr >>> 0, 1);
|
|
120
|
+
});
|
|
121
|
+
var Decompressor = exports.Decompressor = /*#__PURE__*/function () {
|
|
122
|
+
function Decompressor() {
|
|
123
|
+
_classCallCheck(this, Decompressor);
|
|
124
|
+
var ret = wasm.compressor_new();
|
|
125
|
+
this.__wbg_ptr = ret >>> 0;
|
|
126
|
+
DecompressorFinalization.register(this, this.__wbg_ptr, this);
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* @param {Uint8Array} data
|
|
131
|
+
* @returns {Uint8Array}
|
|
132
|
+
*/
|
|
133
|
+
return _createClass(Decompressor, [{
|
|
134
|
+
key: "__destroy_into_raw",
|
|
135
|
+
value: function __destroy_into_raw() {
|
|
136
|
+
var ptr = this.__wbg_ptr;
|
|
137
|
+
this.__wbg_ptr = 0;
|
|
138
|
+
DecompressorFinalization.unregister(this);
|
|
139
|
+
return ptr;
|
|
140
|
+
}
|
|
141
|
+
}, {
|
|
142
|
+
key: "free",
|
|
143
|
+
value: function free() {
|
|
144
|
+
var ptr = this.__destroy_into_raw();
|
|
145
|
+
wasm.__wbg_decompressor_free(ptr, 0);
|
|
146
|
+
}
|
|
147
|
+
}, {
|
|
148
|
+
key: "decompress",
|
|
149
|
+
value: function decompress(data) {
|
|
150
|
+
var ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
151
|
+
var len0 = WASM_VECTOR_LEN;
|
|
152
|
+
var ret = wasm.decompressor_decompress(this.__wbg_ptr, ptr0, len0);
|
|
153
|
+
return takeObject(ret);
|
|
154
|
+
}
|
|
155
|
+
}]);
|
|
156
|
+
}();
|
|
157
|
+
function __wbg_buffer_609cc3eee51ed158(arg0) {
|
|
158
|
+
var ret = getObject(arg0).buffer;
|
|
159
|
+
return addHeapObject(ret);
|
|
160
|
+
}
|
|
161
|
+
;
|
|
162
|
+
function __wbg_length_a446193dc22c12f8(arg0) {
|
|
163
|
+
var ret = getObject(arg0).length;
|
|
164
|
+
return ret;
|
|
165
|
+
}
|
|
166
|
+
;
|
|
167
|
+
function __wbg_newwithbyteoffsetandlength_d97e637ebe145a9a(arg0, arg1, arg2) {
|
|
168
|
+
var ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);
|
|
169
|
+
return addHeapObject(ret);
|
|
170
|
+
}
|
|
171
|
+
;
|
|
172
|
+
function __wbg_newwithlength_a381634e90c276d4(arg0) {
|
|
173
|
+
var ret = new Uint8Array(arg0 >>> 0);
|
|
174
|
+
return addHeapObject(ret);
|
|
175
|
+
}
|
|
176
|
+
;
|
|
177
|
+
function __wbg_set_65595bdd868b3009(arg0, arg1, arg2) {
|
|
178
|
+
getObject(arg0).set(getObject(arg1), arg2 >>> 0);
|
|
179
|
+
}
|
|
180
|
+
;
|
|
181
|
+
function __wbindgen_memory() {
|
|
182
|
+
var ret = wasm.memory;
|
|
183
|
+
return addHeapObject(ret);
|
|
184
|
+
}
|
|
185
|
+
;
|
|
186
|
+
function __wbindgen_object_drop_ref(arg0) {
|
|
187
|
+
takeObject(arg0);
|
|
188
|
+
}
|
|
189
|
+
;
|
|
190
|
+
function __wbindgen_throw(arg0, arg1) {
|
|
191
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
192
|
+
}
|
|
193
|
+
;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
var _waosm_bg = _interopRequireWildcard(require("./waosm-node/waosm_bg.js"));
|
|
8
|
+
var wasmBindings = _waosm_bg;
|
|
9
|
+
Object.keys(_waosm_bg).forEach(function (key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
if (key in exports && exports[key] === _waosm_bg[key]) return;
|
|
12
|
+
Object.defineProperty(exports, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _waosm_bg[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
var _fs = require("fs");
|
|
20
|
+
var _path = require("path");
|
|
21
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
22
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
23
|
+
var wasm = (0, _fs.readFileSync)((0, _path.resolve)(import.meta.dirname, "./waosm-node/waosm_bg.wasm"));
|
|
24
|
+
var wasmModule = new WebAssembly.Module(wasm);
|
|
25
|
+
var wasmInstance = new WebAssembly.Instance(wasmModule, {
|
|
26
|
+
"./waosm_bg.js": wasmBindings
|
|
27
|
+
});
|
|
28
|
+
(0, _waosm_bg.__wbg_set_wasm)(wasmInstance.exports);
|
package/cjs/war.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports["default"] = void 0;
|
|
8
|
-
var
|
|
8
|
+
var _bar = _interopRequireDefault(require("./bar.js"));
|
|
9
9
|
var _armemWeb = _interopRequireDefault(require("./armem-web.js"));
|
|
10
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
11
11
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
@@ -33,5 +33,5 @@ var AR = /*#__PURE__*/function (_BAR) {
|
|
|
33
33
|
}
|
|
34
34
|
_inherits(AR, _BAR);
|
|
35
35
|
return _createClass(AR);
|
|
36
|
-
}(
|
|
36
|
+
}(_bar["default"]);
|
|
37
37
|
var _default = exports["default"] = AR;
|
package/esm/ao.js
CHANGED
|
@@ -369,7 +369,6 @@ class AO {
|
|
|
369
369
|
data: jsonToStr(data),
|
|
370
370
|
})
|
|
371
371
|
} catch (e) {
|
|
372
|
-
console.log(e)
|
|
373
372
|
err = e
|
|
374
373
|
}
|
|
375
374
|
const p = pid ? this.p(pid) : null
|
|
@@ -405,8 +404,7 @@ class AO {
|
|
|
405
404
|
}
|
|
406
405
|
}
|
|
407
406
|
}
|
|
408
|
-
const checkOut = async (get, _txs, _txmap) => {
|
|
409
|
-
let out = null
|
|
407
|
+
const checkOut = async (get, _txs, _txmap, out) => {
|
|
410
408
|
for (let v of _txs) {
|
|
411
409
|
if (isNil(_txmap[v.id].res)) {
|
|
412
410
|
const res = await this.result({ process: pid, message: v.id })
|
|
@@ -414,8 +412,9 @@ class AO {
|
|
|
414
412
|
}
|
|
415
413
|
if (!isNil(_txmap[v.id].res) && _txmap[v.id].out !== true) {
|
|
416
414
|
_txmap[v.id].out = true
|
|
417
|
-
|
|
418
|
-
|
|
415
|
+
const _out = getTagVal(get, _txmap[v.id].res, v.from)
|
|
416
|
+
out = mergeOut(out, _out, get)
|
|
417
|
+
if (isOutComplete(out, get)) break
|
|
419
418
|
}
|
|
420
419
|
}
|
|
421
420
|
return out
|
|
@@ -455,14 +454,15 @@ class AO {
|
|
|
455
454
|
await wait(1000)
|
|
456
455
|
await getNewTxs(pid, _txs, _txmap)
|
|
457
456
|
} while (Date.now() - start < timeout)
|
|
457
|
+
|
|
458
458
|
if (!checked) {
|
|
459
459
|
err = "something went wrong!"
|
|
460
460
|
} else {
|
|
461
|
-
out = mergeOut(out, await checkOut(get, _txs, _txmap), get)
|
|
461
|
+
out = mergeOut(out, await checkOut(get, _txs, _txmap, out), get)
|
|
462
462
|
if (!isOutComplete(out, get) && !isNil(get)) {
|
|
463
463
|
while (Date.now() - start < timeout) {
|
|
464
464
|
await getNewTxs(pid, _txs, _txmap)
|
|
465
|
-
out = mergeOut(out, await checkOut(get, _txs, _txmap), get)
|
|
465
|
+
out = mergeOut(out, await checkOut(get, _txs, _txmap, out), get)
|
|
466
466
|
if (isOutComplete(out, get)) break
|
|
467
467
|
await wait(1000)
|
|
468
468
|
}
|
package/esm/aoconnect-base.js
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
dirname,
|
|
15
15
|
} from "./utils.js"
|
|
16
16
|
import weavedrive from "./weavedrive.js"
|
|
17
|
-
import { is, clone, fromPairs, map, mergeLeft, isNil } from "ramda"
|
|
17
|
+
import { is, clone, fromPairs, map, mergeLeft, isNil, dissoc, o } from "ramda"
|
|
18
18
|
|
|
19
19
|
export default ({ AR, scheduler, mu, su, cu, acc, AoLoader, ArMem } = {}) => {
|
|
20
20
|
return (mem, { cache, log = false, extensions = {} } = {}) => {
|
|
@@ -70,12 +70,12 @@ export default ({ AR, scheduler, mu, su, cu, acc, AoLoader, ArMem } = {}) => {
|
|
|
70
70
|
return {
|
|
71
71
|
Process: {
|
|
72
72
|
Id: pid,
|
|
73
|
-
Tags: (await mem.
|
|
73
|
+
Tags: (await mem.getTx(pid))?.tags ?? [],
|
|
74
74
|
Owner: owner,
|
|
75
75
|
},
|
|
76
76
|
Module: {
|
|
77
77
|
Id: module,
|
|
78
|
-
Tags: (await mem.
|
|
78
|
+
Tags: (await mem.getTx(module))?.tags ?? [],
|
|
79
79
|
},
|
|
80
80
|
}
|
|
81
81
|
}
|
|
@@ -124,7 +124,7 @@ export default ({ AR, scheduler, mu, su, cu, acc, AoLoader, ArMem } = {}) => {
|
|
|
124
124
|
format,
|
|
125
125
|
WeaveDrive: wdrive,
|
|
126
126
|
spawn: item,
|
|
127
|
-
module: await mem.
|
|
127
|
+
module: await mem.getTx(mod),
|
|
128
128
|
})
|
|
129
129
|
} catch (e) {}
|
|
130
130
|
if (!handle) return null
|
|
@@ -136,7 +136,6 @@ export default ({ AR, scheduler, mu, su, cu, acc, AoLoader, ArMem } = {}) => {
|
|
|
136
136
|
let memory = opt.memory ?? null
|
|
137
137
|
let p = {
|
|
138
138
|
extension: ext,
|
|
139
|
-
item: item?.binary,
|
|
140
139
|
format,
|
|
141
140
|
id: id,
|
|
142
141
|
epochs: [],
|
|
@@ -146,10 +145,8 @@ export default ({ AR, scheduler, mu, su, cu, acc, AoLoader, ArMem } = {}) => {
|
|
|
146
145
|
memory,
|
|
147
146
|
owner,
|
|
148
147
|
height: 0,
|
|
149
|
-
res: { [id]: res },
|
|
148
|
+
//res: { [id]: res },
|
|
150
149
|
results: [id],
|
|
151
|
-
txs: [],
|
|
152
|
-
opt,
|
|
153
150
|
}
|
|
154
151
|
if (memory) {
|
|
155
152
|
// forking...
|
|
@@ -166,11 +163,12 @@ export default ({ AR, scheduler, mu, su, cu, acc, AoLoader, ArMem } = {}) => {
|
|
|
166
163
|
res = await _module.handle(null, msg, _env)
|
|
167
164
|
p.memory = res.Memory
|
|
168
165
|
delete res.Memory
|
|
169
|
-
p.res[id] = res
|
|
166
|
+
//p.res[id] = res
|
|
170
167
|
} else {
|
|
171
168
|
p.height += 1
|
|
172
169
|
}
|
|
173
|
-
|
|
170
|
+
const _msg = { ...o(dissoc("signer"), dissoc("memory"))(opt), res }
|
|
171
|
+
await mem.set(_msg, "msgs", id)
|
|
174
172
|
if (_tags["Cron-Interval"]) {
|
|
175
173
|
let [num, unit] = _tags["Cron-Interval"].split("-")
|
|
176
174
|
let int = 0
|
|
@@ -221,7 +219,7 @@ export default ({ AR, scheduler, mu, su, cu, acc, AoLoader, ArMem } = {}) => {
|
|
|
221
219
|
|
|
222
220
|
const assign = async opt => {
|
|
223
221
|
const p = await mem.get("env", opt.process)
|
|
224
|
-
if (!p) return null
|
|
222
|
+
if (!p || !opt.process) return null
|
|
225
223
|
let _opt = await mem.get("msgs", opt.message)
|
|
226
224
|
let hash = genHashChain(p.hash, opt.message)
|
|
227
225
|
p.hash = hash
|
|
@@ -285,19 +283,19 @@ export default ({ AR, scheduler, mu, su, cu, acc, AoLoader, ArMem } = {}) => {
|
|
|
285
283
|
p.handle = await AoLoader(wasm, {
|
|
286
284
|
format,
|
|
287
285
|
WeaveDrive: wdrive,
|
|
288
|
-
spawn:
|
|
289
|
-
module: await mem.
|
|
286
|
+
spawn: (await mem.getTx(p.id)).item,
|
|
287
|
+
module: await mem.getTx(mod),
|
|
290
288
|
})
|
|
291
289
|
mem.env[opt.process].handle = p.handle
|
|
292
290
|
}
|
|
293
291
|
const res = await p.handle(p.memory, msg, _env)
|
|
294
292
|
p.memory = res.Memory
|
|
295
293
|
delete res.Memory
|
|
296
|
-
p.res[opt.message] = res
|
|
294
|
+
//p.res[opt.message] = res
|
|
297
295
|
p.results.push(opt.message)
|
|
298
|
-
p.txs.unshift({ id, ...opt })
|
|
299
296
|
await mem.set(p, "env", opt.process)
|
|
300
|
-
|
|
297
|
+
const _msg = { ...dissoc("signer", _opt), res }
|
|
298
|
+
await mem.set(_msg, "msgs", opt.message)
|
|
301
299
|
for (const v of res.Messages ?? []) {
|
|
302
300
|
if (await mem.get("env", v.Target)) {
|
|
303
301
|
await message({
|
|
@@ -361,7 +359,7 @@ export default ({ AR, scheduler, mu, su, cu, acc, AoLoader, ArMem } = {}) => {
|
|
|
361
359
|
if (opt.for) {
|
|
362
360
|
opt.tags.push({ name: "Pushed-For", value: opt.for })
|
|
363
361
|
opt.tags.push({ name: "From-Process", value: opt.from })
|
|
364
|
-
const pr = (await mem.
|
|
362
|
+
const pr = (await mem.getTx(opt.from))?.tags ?? []
|
|
365
363
|
const module = tags(pr).Module
|
|
366
364
|
if (module) opt.tags.push({ name: "From-Module", value: module })
|
|
367
365
|
}
|
|
@@ -372,7 +370,8 @@ export default ({ AR, scheduler, mu, su, cu, acc, AoLoader, ArMem } = {}) => {
|
|
|
372
370
|
target: opt.process,
|
|
373
371
|
}))
|
|
374
372
|
}
|
|
375
|
-
|
|
373
|
+
const _msg = dissoc("signer", opt)
|
|
374
|
+
await mem.set(_msg, "msgs", id)
|
|
376
375
|
await assign({
|
|
377
376
|
message_item: item,
|
|
378
377
|
message: id,
|
|
@@ -408,20 +407,22 @@ export default ({ AR, scheduler, mu, su, cu, acc, AoLoader, ArMem } = {}) => {
|
|
|
408
407
|
spawn,
|
|
409
408
|
assign,
|
|
410
409
|
ar,
|
|
411
|
-
result: async opt =>
|
|
412
|
-
(await mem.get("env", opt.process))?.res[opt.message],
|
|
410
|
+
result: async opt => (await mem.get("msgs", opt.message))?.res,
|
|
413
411
|
results: async opt => {
|
|
414
412
|
const p = await mem.get("env", opt.process)
|
|
415
413
|
let results = []
|
|
416
414
|
const limit = opt.limit ?? 25
|
|
417
415
|
if (opt.sort === "DESC") {
|
|
418
416
|
for (let i = p.results.length - 1; 0 < i; i--) {
|
|
419
|
-
results.push({
|
|
417
|
+
results.push({
|
|
418
|
+
cursor: p.results[i],
|
|
419
|
+
node: await this.result(p.results[i]),
|
|
420
|
+
})
|
|
420
421
|
if (results.length >= limit) break
|
|
421
422
|
}
|
|
422
423
|
} else {
|
|
423
424
|
for (let i = 0; i < p.results.length; i++) {
|
|
424
|
-
results.push({ node:
|
|
425
|
+
results.push({ node: await this.result(p.results[i]) })
|
|
425
426
|
if (results.length >= limit) break
|
|
426
427
|
}
|
|
427
428
|
}
|
|
@@ -464,8 +465,8 @@ export default ({ AR, scheduler, mu, su, cu, acc, AoLoader, ArMem } = {}) => {
|
|
|
464
465
|
p.handle = await AoLoader(wasm, {
|
|
465
466
|
format,
|
|
466
467
|
WeaveDrive: wdrive,
|
|
467
|
-
spawn:
|
|
468
|
-
module: await mem.
|
|
468
|
+
spawn: (await mem.getTx(p.id)).item,
|
|
469
|
+
module: await mem.getTx(mod),
|
|
469
470
|
})
|
|
470
471
|
mem.env[opt.process].handle = p.handle
|
|
471
472
|
}
|
package/esm/armem-base.js
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
import _Arweave from "arweave"
|
|
2
2
|
const Arweave = _Arweave.default ?? _Arweave
|
|
3
|
-
|
|
4
|
-
import {
|
|
3
|
+
import { Bundle } from "arbundles"
|
|
4
|
+
import { compress, decompress } from "./compress.js"
|
|
5
|
+
import { last, assoc, is } from "ramda"
|
|
5
6
|
import { buildTags, tags } from "./utils.js"
|
|
7
|
+
import base64url from "base64url"
|
|
6
8
|
|
|
7
9
|
export default class ArMemBase {
|
|
8
|
-
constructor({
|
|
10
|
+
constructor({
|
|
11
|
+
MU_URL,
|
|
12
|
+
CU_URL,
|
|
13
|
+
SU_URL,
|
|
14
|
+
GATEWAY_URL,
|
|
15
|
+
scheduler,
|
|
16
|
+
cache,
|
|
17
|
+
init,
|
|
18
|
+
Compressor,
|
|
19
|
+
Decompressor,
|
|
20
|
+
} = {}) {
|
|
9
21
|
this.__type__ = "mem"
|
|
22
|
+
this._init = init
|
|
23
|
+
this.Compressor = Compressor
|
|
24
|
+
this.Decompressor = Decompressor
|
|
10
25
|
this.isInit = false
|
|
11
26
|
this.keyInit = false
|
|
12
27
|
this.keys = {}
|
|
@@ -16,6 +31,11 @@ export default class ArMemBase {
|
|
|
16
31
|
this.scheduler = scheduler
|
|
17
32
|
this.SU_URL = SU_URL
|
|
18
33
|
}
|
|
34
|
+
async owner(di) {
|
|
35
|
+
return base64url.encode(
|
|
36
|
+
Buffer.from(await crypto.subtle.digest("SHA-256", di.rawOwner)),
|
|
37
|
+
)
|
|
38
|
+
}
|
|
19
39
|
getAnchor() {
|
|
20
40
|
return this.blocks.length === 0
|
|
21
41
|
? "Do_Uc2Sju_ffp6Ev0AnLVdPtot15rvMjP-a9VVaA5fM"
|
|
@@ -34,13 +54,28 @@ export default class ArMemBase {
|
|
|
34
54
|
} else {
|
|
35
55
|
this[key] ??= {}
|
|
36
56
|
this[key][field] = val
|
|
37
|
-
if (this.db)
|
|
57
|
+
if (this.db) {
|
|
58
|
+
if (key === "env") {
|
|
59
|
+
let memory = val.memory
|
|
60
|
+
try {
|
|
61
|
+
memory = Array.from(this.compressor.compress(val.memory))
|
|
62
|
+
} catch (e) {
|
|
63
|
+
memory = compress(val.memory)
|
|
64
|
+
}
|
|
65
|
+
await this.db.put(
|
|
66
|
+
`${key}.${field}`,
|
|
67
|
+
assoc("memory", memory, this[key][field]),
|
|
68
|
+
)
|
|
69
|
+
} else {
|
|
70
|
+
await this.db.put(`${key}.${field}`, this[key][field])
|
|
71
|
+
}
|
|
72
|
+
}
|
|
38
73
|
}
|
|
39
74
|
}
|
|
40
75
|
initSync() {
|
|
76
|
+
this.items = {}
|
|
41
77
|
this.addrmap = {}
|
|
42
78
|
this.txs = {}
|
|
43
|
-
this.jwks = {}
|
|
44
79
|
this.blocks = []
|
|
45
80
|
this.blockmap = {}
|
|
46
81
|
this.env = {}
|
|
@@ -118,11 +153,14 @@ export default class ArMemBase {
|
|
|
118
153
|
async init() {
|
|
119
154
|
if (this.isInit) return
|
|
120
155
|
this.isInit = true
|
|
156
|
+
if (typeof this._init === "function") await this._init()
|
|
157
|
+
this.compressor = new this.Compressor()
|
|
158
|
+
this.decompressor = new this.Decompressor()
|
|
121
159
|
if (this.db) {
|
|
122
160
|
for (const v of ["height", "blocks"]) this[v] = await this.get(v)
|
|
123
161
|
for (const v of [
|
|
162
|
+
"items",
|
|
124
163
|
"txs",
|
|
125
|
-
"jwks",
|
|
126
164
|
"env",
|
|
127
165
|
"modules",
|
|
128
166
|
"wasms",
|
|
@@ -136,7 +174,21 @@ export default class ArMemBase {
|
|
|
136
174
|
for (const v2 of items || []) {
|
|
137
175
|
const key = v2.split(".")[0]
|
|
138
176
|
const field = v2.split(".")[1]
|
|
139
|
-
if (key === v)
|
|
177
|
+
if (key === v) {
|
|
178
|
+
if (key.match(/^env/)) {
|
|
179
|
+
let v3 = await this.db.get(v2)
|
|
180
|
+
if (is(Array, v3.memory)) {
|
|
181
|
+
try {
|
|
182
|
+
v3.memory = this.decompressor.decompress(v3.memory)
|
|
183
|
+
} catch (e) {
|
|
184
|
+
v3.memory = decompress(v3.memory)
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
this[v][field] = v3
|
|
188
|
+
} else {
|
|
189
|
+
this[v][field] = await this.db.get(v2)
|
|
190
|
+
}
|
|
191
|
+
}
|
|
140
192
|
}
|
|
141
193
|
}
|
|
142
194
|
} else {
|
|
@@ -146,6 +198,36 @@ export default class ArMemBase {
|
|
|
146
198
|
}
|
|
147
199
|
}
|
|
148
200
|
}
|
|
201
|
+
async getTx(id) {
|
|
202
|
+
let tx = this.txs[id]
|
|
203
|
+
if (tx.bundle) {
|
|
204
|
+
try {
|
|
205
|
+
let bundle = new Bundle(this.txs[tx.bundle].data)
|
|
206
|
+
for (let di of bundle.items) {
|
|
207
|
+
if (id === di.id) {
|
|
208
|
+
const data = di.data
|
|
209
|
+
const data_size = Buffer.byteLength(di.rawData).toString()
|
|
210
|
+
let data_type = ""
|
|
211
|
+
for (const t of di.tags)
|
|
212
|
+
if (t.name === "Content-Type") data_type = t.value
|
|
213
|
+
const owner = await this.owner(di)
|
|
214
|
+
tx = {
|
|
215
|
+
_data: { size: data_size, type: data_type },
|
|
216
|
+
anchor: di.anchor,
|
|
217
|
+
signature: di.signature,
|
|
218
|
+
recipient: di.target,
|
|
219
|
+
id: await di.id,
|
|
220
|
+
item: di,
|
|
221
|
+
owner,
|
|
222
|
+
tags: di.tags,
|
|
223
|
+
data,
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
} catch (e) {}
|
|
228
|
+
}
|
|
229
|
+
return tx
|
|
230
|
+
}
|
|
149
231
|
async getWasm(module) {
|
|
150
232
|
let mod = module ?? this.modules.aos2_0_1
|
|
151
233
|
if (!mod) throw Error("module not found")
|
|
@@ -157,15 +239,13 @@ export default class ArMemBase {
|
|
|
157
239
|
wasm = await this._getWasm(this.wasms[mod].file)
|
|
158
240
|
format = _wasm.format
|
|
159
241
|
} else {
|
|
160
|
-
const tx = await this.
|
|
242
|
+
const tx = await this.getTx(mod)
|
|
161
243
|
if (tx) {
|
|
162
244
|
wasm = Buffer.from(tx.data, "base64")
|
|
163
245
|
format = tags(tx.tags)["Module-Format"]
|
|
164
246
|
}
|
|
165
247
|
}
|
|
166
|
-
} else
|
|
167
|
-
format = _wasm.format
|
|
168
|
-
}
|
|
248
|
+
} else format = _wasm.format
|
|
169
249
|
format ??= "wasm64-unknown-emscripten-draft_2024_02_15"
|
|
170
250
|
return { format, mod, wasm }
|
|
171
251
|
}
|
package/esm/armem-web.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import wdb from "./lua/weavedb-lite.js"
|
|
2
2
|
import Base from "./armem-base.js"
|
|
3
3
|
import db from "./lfdb.js"
|
|
4
|
+
import init, { Compressor, Decompressor } from "./waosm/waosm.js"
|
|
4
5
|
|
|
5
6
|
export default class ArMem extends Base {
|
|
6
7
|
constructor(args = {}) {
|
|
7
|
-
super(args)
|
|
8
|
+
super({ ...args, init, Compressor, Decompressor })
|
|
8
9
|
this.db = db(this)
|
|
9
10
|
this.initSync()
|
|
10
11
|
}
|
package/esm/armem.js
CHANGED
|
@@ -5,11 +5,12 @@ import { open } from "lmdb"
|
|
|
5
5
|
import { readFileSync } from "fs"
|
|
6
6
|
import { resolve } from "path"
|
|
7
7
|
import Base from "./armem-base.js"
|
|
8
|
+
import { Compressor, Decompressor } from "./waosm-node.js"
|
|
8
9
|
|
|
9
10
|
export default class ArMem extends Base {
|
|
10
11
|
constructor(args = {}) {
|
|
11
12
|
const { cache } = args
|
|
12
|
-
super(args)
|
|
13
|
+
super({ ...args, Compressor, Decompressor })
|
|
13
14
|
if (cache) this.db = open({ path: cache, compression: true })
|
|
14
15
|
this.initSync()
|
|
15
16
|
}
|