mol_crypto_lib 0.1.1385 → 0.1.1386
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/node.d.ts +91 -81
- package/node.d.ts.map +1 -1
- package/node.deps.json +1 -1
- package/node.js +431 -369
- package/node.js.map +1 -1
- package/node.meta.tree +4 -1
- package/node.mjs +431 -369
- package/node.test.js +1383 -1302
- package/node.test.js.map +1 -1
- package/package.json +20 -18
- package/web.d.ts +50 -40
- package/web.d.ts.map +1 -1
- package/web.deps.json +1 -1
- package/web.js +229 -167
- package/web.js.map +1 -1
- package/web.meta.tree +4 -1
- package/web.mjs +229 -167
- package/web.test.js +71 -52
- package/web.test.js.map +1 -1
package/node.test.js
CHANGED
@@ -21,6 +21,97 @@ $.$$ = $
|
|
21
21
|
|
22
22
|
;
|
23
23
|
"use strict";
|
24
|
+
var $;
|
25
|
+
(function ($) {
|
26
|
+
function $mol_base64_encode(src) {
|
27
|
+
throw new Error('Not implemented');
|
28
|
+
}
|
29
|
+
$.$mol_base64_encode = $mol_base64_encode;
|
30
|
+
})($ || ($ = {}));
|
31
|
+
|
32
|
+
;
|
33
|
+
"use strict";
|
34
|
+
var $;
|
35
|
+
(function ($) {
|
36
|
+
function $mol_base64_encode_node(str) {
|
37
|
+
if (!str)
|
38
|
+
return '';
|
39
|
+
if (Buffer.isBuffer(str))
|
40
|
+
return str.toString('base64');
|
41
|
+
return Buffer.from(str).toString('base64');
|
42
|
+
}
|
43
|
+
$.$mol_base64_encode_node = $mol_base64_encode_node;
|
44
|
+
$.$mol_base64_encode = $mol_base64_encode_node;
|
45
|
+
})($ || ($ = {}));
|
46
|
+
|
47
|
+
;
|
48
|
+
"use strict";
|
49
|
+
var $;
|
50
|
+
(function ($) {
|
51
|
+
function $mol_base64_decode(base64) {
|
52
|
+
throw new Error('Not implemented');
|
53
|
+
}
|
54
|
+
$.$mol_base64_decode = $mol_base64_decode;
|
55
|
+
})($ || ($ = {}));
|
56
|
+
|
57
|
+
;
|
58
|
+
"use strict";
|
59
|
+
var $;
|
60
|
+
(function ($) {
|
61
|
+
function $mol_base64_decode_node(base64Str) {
|
62
|
+
base64Str = base64Str.replace(/-/g, '+').replace(/_/g, '/');
|
63
|
+
const buffer = Buffer.from(base64Str, 'base64');
|
64
|
+
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
65
|
+
}
|
66
|
+
$.$mol_base64_decode_node = $mol_base64_decode_node;
|
67
|
+
$.$mol_base64_decode = $mol_base64_decode_node;
|
68
|
+
})($ || ($ = {}));
|
69
|
+
|
70
|
+
;
|
71
|
+
"use strict";
|
72
|
+
var $;
|
73
|
+
(function ($) {
|
74
|
+
function $mol_base64_ae_encode(buffer) {
|
75
|
+
return $mol_base64_encode(buffer).replace(/\+/g, 'æ').replace(/\//g, 'Æ').replace(/=/g, '');
|
76
|
+
}
|
77
|
+
$.$mol_base64_ae_encode = $mol_base64_ae_encode;
|
78
|
+
function $mol_base64_ae_decode(str) {
|
79
|
+
return $mol_base64_decode(str.replace(/æ/g, '+').replace(/Æ/g, '/'));
|
80
|
+
}
|
81
|
+
$.$mol_base64_ae_decode = $mol_base64_ae_decode;
|
82
|
+
})($ || ($ = {}));
|
83
|
+
|
84
|
+
;
|
85
|
+
"use strict";
|
86
|
+
var $;
|
87
|
+
(function ($) {
|
88
|
+
const named = new WeakSet();
|
89
|
+
function $mol_func_name(func) {
|
90
|
+
let name = func.name;
|
91
|
+
if (name?.length > 1)
|
92
|
+
return name;
|
93
|
+
if (named.has(func))
|
94
|
+
return name;
|
95
|
+
for (let key in this) {
|
96
|
+
try {
|
97
|
+
if (this[key] !== func)
|
98
|
+
continue;
|
99
|
+
name = key;
|
100
|
+
Object.defineProperty(func, 'name', { value: name });
|
101
|
+
break;
|
102
|
+
}
|
103
|
+
catch { }
|
104
|
+
}
|
105
|
+
named.add(func);
|
106
|
+
return name;
|
107
|
+
}
|
108
|
+
$.$mol_func_name = $mol_func_name;
|
109
|
+
function $mol_func_name_from(target, source) {
|
110
|
+
Object.defineProperty(target, 'name', { value: source.name });
|
111
|
+
return target;
|
112
|
+
}
|
113
|
+
$.$mol_func_name_from = $mol_func_name_from;
|
114
|
+
})($ || ($ = {}));
|
24
115
|
|
25
116
|
;
|
26
117
|
"use strict";
|
@@ -32,6 +123,125 @@ var $;
|
|
32
123
|
$.$mol_fail = $mol_fail;
|
33
124
|
})($ || ($ = {}));
|
34
125
|
|
126
|
+
;
|
127
|
+
"use strict";
|
128
|
+
var $;
|
129
|
+
(function ($) {
|
130
|
+
class $mol_buffer extends DataView {
|
131
|
+
static from(array) {
|
132
|
+
if (typeof array === 'number')
|
133
|
+
array = new Uint8Array(array);
|
134
|
+
if (typeof array === 'string')
|
135
|
+
array = $mol_base64_ae_decode(array);
|
136
|
+
return new this(array.buffer, array.byteOffset, array.byteLength);
|
137
|
+
}
|
138
|
+
static toString() {
|
139
|
+
return $$.$mol_func_name(this);
|
140
|
+
}
|
141
|
+
getUint48(offset, LE = false) {
|
142
|
+
if (offset % 4) {
|
143
|
+
return this.getUint16(offset, LE) + this.getUint32(offset + 2, LE) * 2 ** 16;
|
144
|
+
}
|
145
|
+
else {
|
146
|
+
return this.getUint32(offset, LE) + this.getUint16(offset + 4, LE) * 2 ** 32;
|
147
|
+
}
|
148
|
+
}
|
149
|
+
setUint48(offset, value, LE = false) {
|
150
|
+
if (offset % 4) {
|
151
|
+
this.setUint16(offset, value & ((1 << 16) - 1), LE);
|
152
|
+
this.setUint32(offset + 2, (value / 2 ** 16) | 0, LE);
|
153
|
+
}
|
154
|
+
else {
|
155
|
+
this.setUint32(offset, value | 0, LE);
|
156
|
+
this.setUint16(offset + 4, (value / 2 ** 32) | 0, LE);
|
157
|
+
}
|
158
|
+
}
|
159
|
+
int8(offset, next) {
|
160
|
+
if (next === undefined)
|
161
|
+
return this.getInt8(offset);
|
162
|
+
if (next >= -(2 ** 7) && next < 2 ** 7)
|
163
|
+
return this.setInt8(offset, next), next;
|
164
|
+
$mol_fail(new Error(`Wrong int8 value ${next}`));
|
165
|
+
}
|
166
|
+
uint8(offset, next) {
|
167
|
+
if (next === undefined)
|
168
|
+
return this.getUint8(offset);
|
169
|
+
if (next >= 0 && next < 2 ** 8)
|
170
|
+
return this.setUint8(offset, next), next;
|
171
|
+
$mol_fail(new Error(`Wrong uint8 value ${next}`));
|
172
|
+
}
|
173
|
+
int16(offset, next) {
|
174
|
+
if (next === undefined)
|
175
|
+
return this.getInt16(offset, true);
|
176
|
+
if (next >= -(2 ** 15) && next < 2 ** 15)
|
177
|
+
return this.setInt16(offset, next, true), next;
|
178
|
+
$mol_fail(new Error(`Wrong int16 value ${next}`));
|
179
|
+
}
|
180
|
+
uint16(offset, next) {
|
181
|
+
if (next === undefined)
|
182
|
+
return this.getUint16(offset, true);
|
183
|
+
if (next >= 0 && next < 2 ** 16)
|
184
|
+
return this.setUint16(offset, next, true), next;
|
185
|
+
$mol_fail(new Error(`Wrong uint16 value ${next}`));
|
186
|
+
}
|
187
|
+
int32(offset, next) {
|
188
|
+
if (next === undefined)
|
189
|
+
return this.getInt32(offset, true);
|
190
|
+
if (next >= -(2 ** 31) && next < 2 ** 31)
|
191
|
+
return this.setInt32(offset, next, true), next;
|
192
|
+
$mol_fail(new Error(`Wrong int32 value ${next}`));
|
193
|
+
}
|
194
|
+
uint32(offset, next) {
|
195
|
+
if (next === undefined)
|
196
|
+
return this.getUint32(offset, true);
|
197
|
+
if (next >= 0 && next < 2 ** 32)
|
198
|
+
return this.setUint32(offset, next, true), next;
|
199
|
+
$mol_fail(new Error(`Wrong uint32 value ${next}`));
|
200
|
+
}
|
201
|
+
uint48(offset, next) {
|
202
|
+
if (next === undefined)
|
203
|
+
return this.getUint48(offset, true);
|
204
|
+
if (next >= 0 && next < 2 ** 48)
|
205
|
+
return this.setUint48(offset, next, true), next;
|
206
|
+
$mol_fail(new Error(`Wrong uint48 value ${next}`));
|
207
|
+
}
|
208
|
+
int64(offset, next) {
|
209
|
+
if (next === undefined)
|
210
|
+
return this.getBigInt64(offset, true);
|
211
|
+
if (next >= -(2 ** 63) && next < 2 ** 63)
|
212
|
+
return this.setBigInt64(offset, next, true), next;
|
213
|
+
$mol_fail(new Error(`Wrong int64 value ${next}`));
|
214
|
+
}
|
215
|
+
uint64(offset, next) {
|
216
|
+
if (next === undefined)
|
217
|
+
return this.getBigUint64(offset, true);
|
218
|
+
if (next >= 0 && next < 2 ** 64)
|
219
|
+
return this.setBigUint64(offset, next, true), next;
|
220
|
+
$mol_fail(new Error(`Wrong uint64 value ${next}`));
|
221
|
+
}
|
222
|
+
float32(offset, next) {
|
223
|
+
if (next !== undefined)
|
224
|
+
this.setFloat32(offset, next, true);
|
225
|
+
return this.getFloat32(offset, true);
|
226
|
+
}
|
227
|
+
float64(offset, next) {
|
228
|
+
if (next !== undefined)
|
229
|
+
this.setFloat64(offset, next, true);
|
230
|
+
return this.getFloat64(offset, true);
|
231
|
+
}
|
232
|
+
asArray() {
|
233
|
+
return new Uint8Array(this.buffer, this.byteOffset, this.byteLength);
|
234
|
+
}
|
235
|
+
toString() {
|
236
|
+
return $mol_base64_ae_encode(this.asArray());
|
237
|
+
}
|
238
|
+
}
|
239
|
+
$.$mol_buffer = $mol_buffer;
|
240
|
+
})($ || ($ = {}));
|
241
|
+
|
242
|
+
;
|
243
|
+
"use strict";
|
244
|
+
|
35
245
|
;
|
36
246
|
"use strict";
|
37
247
|
var $;
|
@@ -142,38 +352,6 @@ require = (req => Object.assign(function require(name) {
|
|
142
352
|
return $node[name];
|
143
353
|
}, req))(require);
|
144
354
|
|
145
|
-
;
|
146
|
-
"use strict";
|
147
|
-
var $;
|
148
|
-
(function ($) {
|
149
|
-
const named = new WeakSet();
|
150
|
-
function $mol_func_name(func) {
|
151
|
-
let name = func.name;
|
152
|
-
if (name?.length > 1)
|
153
|
-
return name;
|
154
|
-
if (named.has(func))
|
155
|
-
return name;
|
156
|
-
for (let key in this) {
|
157
|
-
try {
|
158
|
-
if (this[key] !== func)
|
159
|
-
continue;
|
160
|
-
name = key;
|
161
|
-
Object.defineProperty(func, 'name', { value: name });
|
162
|
-
break;
|
163
|
-
}
|
164
|
-
catch { }
|
165
|
-
}
|
166
|
-
named.add(func);
|
167
|
-
return name;
|
168
|
-
}
|
169
|
-
$.$mol_func_name = $mol_func_name;
|
170
|
-
function $mol_func_name_from(target, source) {
|
171
|
-
Object.defineProperty(target, 'name', { value: source.name });
|
172
|
-
return target;
|
173
|
-
}
|
174
|
-
$.$mol_func_name_from = $mol_func_name_from;
|
175
|
-
})($ || ($ = {}));
|
176
|
-
|
177
355
|
;
|
178
356
|
"use strict";
|
179
357
|
var $;
|
@@ -1905,83 +2083,155 @@ var $;
|
|
1905
2083
|
"use strict";
|
1906
2084
|
var $;
|
1907
2085
|
(function ($) {
|
1908
|
-
|
1909
|
-
|
1910
|
-
function $mol_charset_encode(value) {
|
1911
|
-
return encoder.encode(value);
|
2086
|
+
function $mol_crypto_salt() {
|
2087
|
+
return $mol_crypto_native.getRandomValues(new Uint8Array(16));
|
1912
2088
|
}
|
1913
|
-
$.$
|
2089
|
+
$.$mol_crypto_salt = $mol_crypto_salt;
|
2090
|
+
$.$mol_crypto_salt_once = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6]);
|
1914
2091
|
})($ || ($ = {}));
|
1915
2092
|
|
1916
2093
|
;
|
1917
2094
|
"use strict";
|
1918
2095
|
var $;
|
1919
2096
|
(function ($) {
|
1920
|
-
|
1921
|
-
|
1922
|
-
|
1923
|
-
|
1924
|
-
|
1925
|
-
|
1926
|
-
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
1934
|
-
|
1935
|
-
static
|
1936
|
-
|
1937
|
-
|
1938
|
-
|
1939
|
-
|
1940
|
-
|
1941
|
-
|
1942
|
-
|
1943
|
-
|
1944
|
-
|
1945
|
-
|
1946
|
-
|
1947
|
-
|
1948
|
-
|
1949
|
-
|
1950
|
-
|
1951
|
-
|
1952
|
-
|
1953
|
-
|
1954
|
-
|
1955
|
-
|
1956
|
-
|
1957
|
-
|
1958
|
-
|
1959
|
-
|
1960
|
-
|
1961
|
-
|
1962
|
-
|
1963
|
-
|
1964
|
-
|
1965
|
-
|
1966
|
-
|
2097
|
+
function $mol_base64_url_encode(buffer) {
|
2098
|
+
return $mol_base64_encode(buffer).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
2099
|
+
}
|
2100
|
+
$.$mol_base64_url_encode = $mol_base64_url_encode;
|
2101
|
+
function $mol_base64_url_decode(str) {
|
2102
|
+
return $mol_base64_decode(str.replace(/-/g, '+').replace(/_/g, '/'));
|
2103
|
+
}
|
2104
|
+
$.$mol_base64_url_decode = $mol_base64_url_decode;
|
2105
|
+
})($ || ($ = {}));
|
2106
|
+
|
2107
|
+
;
|
2108
|
+
"use strict";
|
2109
|
+
var $;
|
2110
|
+
(function ($) {
|
2111
|
+
class $mol_wrapper extends $mol_object2 {
|
2112
|
+
static wrap;
|
2113
|
+
static run(task) {
|
2114
|
+
return this.func(task)();
|
2115
|
+
}
|
2116
|
+
static func(func) {
|
2117
|
+
return this.wrap(func);
|
2118
|
+
}
|
2119
|
+
static get class() {
|
2120
|
+
return (Class) => {
|
2121
|
+
const construct = (target, args) => new Class(...args);
|
2122
|
+
const handler = {
|
2123
|
+
construct: this.func(construct)
|
2124
|
+
};
|
2125
|
+
handler[Symbol.toStringTag] = Class.name + '#';
|
2126
|
+
return new Proxy(Class, handler);
|
2127
|
+
};
|
2128
|
+
}
|
2129
|
+
static get method() {
|
2130
|
+
return (obj, name, descr) => {
|
2131
|
+
descr.value = this.func(descr.value);
|
2132
|
+
return descr;
|
2133
|
+
};
|
2134
|
+
}
|
2135
|
+
static get field() {
|
2136
|
+
return (obj, name, descr) => {
|
2137
|
+
descr.get = descr.set = this.func(descr.get);
|
2138
|
+
return descr;
|
2139
|
+
};
|
2140
|
+
}
|
2141
|
+
}
|
2142
|
+
$.$mol_wrapper = $mol_wrapper;
|
2143
|
+
})($ || ($ = {}));
|
2144
|
+
|
2145
|
+
;
|
2146
|
+
"use strict";
|
2147
|
+
var $;
|
2148
|
+
(function ($) {
|
2149
|
+
class $mol_memo extends $mol_wrapper {
|
2150
|
+
static wrap(task) {
|
2151
|
+
const store = new WeakMap();
|
2152
|
+
const fun = function (next) {
|
2153
|
+
if (next === undefined && store.has(this))
|
2154
|
+
return store.get(this);
|
2155
|
+
const val = task.call(this, next) ?? next;
|
2156
|
+
store.set(this, val);
|
2157
|
+
return val;
|
2158
|
+
};
|
2159
|
+
Reflect.defineProperty(fun, 'name', { value: task.name + ' ' });
|
2160
|
+
return fun;
|
2161
|
+
}
|
2162
|
+
}
|
2163
|
+
$.$mol_memo = $mol_memo;
|
2164
|
+
})($ || ($ = {}));
|
2165
|
+
|
2166
|
+
;
|
2167
|
+
"use strict";
|
2168
|
+
var $;
|
2169
|
+
(function ($) {
|
2170
|
+
class $mol_crypto_sacred extends $mol_buffer {
|
2171
|
+
static size = 16;
|
2172
|
+
static make() {
|
2173
|
+
return this.from($mol_crypto_salt());
|
2174
|
+
}
|
2175
|
+
static from(serial) {
|
2176
|
+
if (typeof serial === 'string') {
|
2177
|
+
serial = new Uint8Array([
|
2178
|
+
...$mol_base64_url_decode(serial),
|
2179
|
+
]);
|
2180
|
+
}
|
2181
|
+
if (!(serial instanceof Uint8Array)) {
|
2182
|
+
serial = new Uint8Array(serial.buffer, serial.byteOffset, serial.byteLength);
|
2183
|
+
}
|
2184
|
+
;
|
2185
|
+
serial[0] = 0;
|
2186
|
+
const sacred = super.from(serial);
|
2187
|
+
return sacred;
|
2188
|
+
}
|
2189
|
+
static async from_native(native) {
|
2190
|
+
const buf = await $mol_crypto_native.subtle.exportKey('raw', native);
|
2191
|
+
const sacred = this.from(new Uint8Array(buf));
|
2192
|
+
sacred._native = native;
|
2193
|
+
return sacred;
|
2194
|
+
}
|
2195
|
+
constructor(buffer, byteOffset, byteLength) {
|
2196
|
+
super(buffer, byteOffset, byteLength);
|
2197
|
+
if (this.getUint8(0) !== 0)
|
2198
|
+
$mol_fail(new Error('Buffer should starts with 0 byte'));
|
2199
|
+
}
|
2200
|
+
toString() {
|
2201
|
+
return $mol_base64_url_encode(this.asArray());
|
1967
2202
|
}
|
1968
|
-
|
1969
|
-
|
2203
|
+
_native;
|
2204
|
+
async native() {
|
2205
|
+
return this._native ?? (this._native = await $mol_crypto_native.subtle.importKey('raw', this, {
|
2206
|
+
name: 'AES-CBC',
|
2207
|
+
length: 128,
|
2208
|
+
}, true, ['encrypt', 'decrypt']));
|
1970
2209
|
}
|
1971
2210
|
async encrypt(open, salt) {
|
1972
2211
|
return new Uint8Array(await $mol_crypto_native.subtle.encrypt({
|
1973
|
-
|
2212
|
+
name: 'AES-CBC',
|
2213
|
+
length: 128,
|
2214
|
+
tagLength: 32,
|
1974
2215
|
iv: salt,
|
1975
|
-
}, this.native, open));
|
2216
|
+
}, await this.native(), open));
|
1976
2217
|
}
|
1977
2218
|
async decrypt(closed, salt) {
|
1978
2219
|
return new Uint8Array(await $mol_crypto_native.subtle.decrypt({
|
1979
|
-
|
2220
|
+
name: 'AES-CBC',
|
2221
|
+
length: 128,
|
2222
|
+
tagLength: 32,
|
1980
2223
|
iv: salt,
|
1981
|
-
}, this.native, closed));
|
2224
|
+
}, await this.native(), closed));
|
2225
|
+
}
|
2226
|
+
async close(sacred, salt) {
|
2227
|
+
const buf = new Uint8Array(this.buffer, this.byteOffset + 1, this.byteLength - 1);
|
2228
|
+
return sacred.encrypt(buf, salt);
|
1982
2229
|
}
|
1983
2230
|
}
|
1984
|
-
|
2231
|
+
__decorate([
|
2232
|
+
$mol_memo.method
|
2233
|
+
], $mol_crypto_sacred.prototype, "toString", null);
|
2234
|
+
$.$mol_crypto_sacred = $mol_crypto_sacred;
|
1985
2235
|
})($ || ($ = {}));
|
1986
2236
|
|
1987
2237
|
;
|
@@ -2008,411 +2258,234 @@ var $;
|
|
2008
2258
|
"use strict";
|
2009
2259
|
var $;
|
2010
2260
|
(function ($) {
|
2011
|
-
async function $
|
2012
|
-
const
|
2013
|
-
if (
|
2014
|
-
return await this.$
|
2015
|
-
const id = await this.$
|
2016
|
-
this.$
|
2261
|
+
async function $mol_crypto_sacred_id() {
|
2262
|
+
const inited = this.$mol_dom.localStorage.getItem('$mol_crypto_sacred_id');
|
2263
|
+
if (inited === 'true')
|
2264
|
+
return await this.$mol_crypto_sacred_id_get();
|
2265
|
+
const id = await this.$mol_crypto_sacred_id_new();
|
2266
|
+
this.$mol_dom.localStorage.setItem('$mol_crypto_sacred_id', 'true');
|
2017
2267
|
return id;
|
2018
2268
|
}
|
2019
|
-
$.$
|
2020
|
-
async function $
|
2021
|
-
const cred = await this.$
|
2269
|
+
$.$mol_crypto_sacred_id = $mol_crypto_sacred_id;
|
2270
|
+
async function $mol_crypto_sacred_id_new() {
|
2271
|
+
const cred = await this.$mol_dom.navigator.credentials.create({
|
2022
2272
|
publicKey: {
|
2023
2273
|
rp: {
|
2024
|
-
name: "$
|
2274
|
+
name: "$mol_crypto_sacred_id",
|
2275
|
+
},
|
2276
|
+
authenticatorSelection: {
|
2277
|
+
userVerification: 'discouraged',
|
2278
|
+
residentKey: 'discouraged',
|
2025
2279
|
},
|
2026
2280
|
user: {
|
2027
2281
|
id: new Uint8Array([0]),
|
2028
2282
|
name: "",
|
2029
2283
|
displayName: ""
|
2030
2284
|
},
|
2031
|
-
pubKeyCredParams: [
|
2032
|
-
{ type: "public-key", alg: -7 },
|
2033
|
-
{ type: "public-key", alg: -257 },
|
2034
|
-
],
|
2285
|
+
pubKeyCredParams: [],
|
2035
2286
|
challenge: new Uint8Array().buffer,
|
2036
2287
|
},
|
2037
2288
|
});
|
2038
|
-
|
2289
|
+
console.log(cred);
|
2290
|
+
const key = new Uint8Array(cred.rawId, 0, 16);
|
2291
|
+
return $mol_crypto_sacred.from(key);
|
2039
2292
|
}
|
2040
|
-
$.$
|
2041
|
-
async function $
|
2042
|
-
const cred = await this.$
|
2293
|
+
$.$mol_crypto_sacred_id_new = $mol_crypto_sacred_id_new;
|
2294
|
+
async function $mol_crypto_sacred_id_get() {
|
2295
|
+
const cred = await this.$mol_dom.navigator.credentials.get({
|
2043
2296
|
mediation: 'silent',
|
2044
2297
|
publicKey: {
|
2045
2298
|
userVerification: 'discouraged',
|
2046
2299
|
challenge: new Uint8Array().buffer,
|
2047
2300
|
},
|
2048
2301
|
});
|
2049
|
-
|
2302
|
+
const key = new Uint8Array(cred.rawId, 0, 16);
|
2303
|
+
console.log(key);
|
2304
|
+
return $mol_crypto_sacred.from(key);
|
2050
2305
|
}
|
2051
|
-
$.$
|
2306
|
+
$.$mol_crypto_sacred_id_get = $mol_crypto_sacred_id_get;
|
2052
2307
|
})($ || ($ = {}));
|
2053
2308
|
|
2054
2309
|
;
|
2055
2310
|
"use strict";
|
2056
2311
|
var $;
|
2057
2312
|
(function ($) {
|
2058
|
-
|
2059
|
-
|
2313
|
+
const TextEncoder = globalThis.TextEncoder ?? $node.util.TextEncoder;
|
2314
|
+
const encoder = new TextEncoder();
|
2315
|
+
function $mol_charset_encode(value) {
|
2316
|
+
return encoder.encode(value);
|
2060
2317
|
}
|
2061
|
-
$.$
|
2318
|
+
$.$mol_charset_encode = $mol_charset_encode;
|
2062
2319
|
})($ || ($ = {}));
|
2063
2320
|
|
2064
2321
|
;
|
2065
2322
|
"use strict";
|
2066
2323
|
var $;
|
2067
2324
|
(function ($) {
|
2068
|
-
function $
|
2069
|
-
|
2070
|
-
|
2071
|
-
|
2072
|
-
|
2073
|
-
|
2325
|
+
async function $mol_crypto_sacred_pass(pass, salt) {
|
2326
|
+
const raw = await $mol_crypto_native.subtle.importKey("raw", $mol_charset_encode(pass), "PBKDF2", false, ["deriveKey"]);
|
2327
|
+
const hard = await $mol_crypto_native.subtle.deriveKey({
|
2328
|
+
name: "PBKDF2",
|
2329
|
+
salt,
|
2330
|
+
iterations: 10_000,
|
2331
|
+
hash: "SHA-256",
|
2332
|
+
}, raw, {
|
2333
|
+
name: 'AES-CBC',
|
2334
|
+
length: 128,
|
2335
|
+
}, Boolean('extractable'), ['encrypt', 'decrypt']);
|
2336
|
+
return $mol_crypto_sacred.from_native(hard);
|
2074
2337
|
}
|
2075
|
-
$.$
|
2076
|
-
$.$mol_base64_encode = $mol_base64_encode_node;
|
2338
|
+
$.$mol_crypto_sacred_pass = $mol_crypto_sacred_pass;
|
2077
2339
|
})($ || ($ = {}));
|
2078
2340
|
|
2079
2341
|
;
|
2080
2342
|
"use strict";
|
2081
2343
|
var $;
|
2082
2344
|
(function ($) {
|
2083
|
-
|
2084
|
-
|
2345
|
+
const ecdsa = {
|
2346
|
+
name: 'ECDSA',
|
2347
|
+
hash: 'SHA-1',
|
2348
|
+
namedCurve: "P-256",
|
2349
|
+
};
|
2350
|
+
const ecdh = { name: "ECDH", namedCurve: "P-256" };
|
2351
|
+
const jwk = { crv: 'P-256', ext: true, kty: 'EC' };
|
2352
|
+
class $mol_crypto_key extends $mol_buffer {
|
2353
|
+
static from(serial) {
|
2354
|
+
if (typeof serial === 'string') {
|
2355
|
+
serial = new Uint8Array([
|
2356
|
+
...$mol_base64_url_decode(serial.slice(0, 43)),
|
2357
|
+
...$mol_base64_url_decode(serial.slice(43, 86)),
|
2358
|
+
...$mol_base64_url_decode(serial.slice(86, 129)),
|
2359
|
+
]);
|
2360
|
+
}
|
2361
|
+
return super.from(serial);
|
2362
|
+
}
|
2363
|
+
toString() {
|
2364
|
+
const arr = this.asArray();
|
2365
|
+
return $mol_base64_url_encode(arr.subarray(0, 32))
|
2366
|
+
+ $mol_base64_url_encode(arr.subarray(32, 64))
|
2367
|
+
+ $mol_base64_url_encode(arr.subarray(64));
|
2368
|
+
}
|
2085
2369
|
}
|
2086
|
-
|
2087
|
-
|
2088
|
-
|
2089
|
-
;
|
2090
|
-
|
2091
|
-
|
2092
|
-
|
2093
|
-
|
2094
|
-
|
2095
|
-
|
2096
|
-
|
2370
|
+
__decorate([
|
2371
|
+
$mol_memo.method
|
2372
|
+
], $mol_crypto_key.prototype, "toString", null);
|
2373
|
+
$.$mol_crypto_key = $mol_crypto_key;
|
2374
|
+
class $mol_crypto_key_public extends $mol_crypto_key {
|
2375
|
+
static size_str = 86;
|
2376
|
+
static size_bin = 64;
|
2377
|
+
async native() {
|
2378
|
+
const str = this.toString();
|
2379
|
+
return $mol_crypto_native.subtle.importKey('jwk', {
|
2380
|
+
crv: "P-256",
|
2381
|
+
ext: true,
|
2382
|
+
key_ops: ['verify'],
|
2383
|
+
kty: "EC",
|
2384
|
+
x: str.slice(0, 43),
|
2385
|
+
y: str.slice(43, 86),
|
2386
|
+
}, ecdsa, Boolean('extractable'), ['verify']);
|
2387
|
+
}
|
2388
|
+
async native_derive() {
|
2389
|
+
const serial = this.toString();
|
2390
|
+
return await $mol_crypto_native.subtle.importKey('jwk', {
|
2391
|
+
...jwk,
|
2392
|
+
key_ops: [],
|
2393
|
+
x: serial.slice(0, 43),
|
2394
|
+
y: serial.slice(43, 86),
|
2395
|
+
}, ecdh, true, []);
|
2396
|
+
}
|
2397
|
+
async verify(data, sign) {
|
2398
|
+
return await $mol_crypto_native.subtle.verify(ecdsa, await this.native(), sign, data);
|
2399
|
+
}
|
2097
2400
|
}
|
2098
|
-
|
2099
|
-
|
2401
|
+
__decorate([
|
2402
|
+
$mol_memo.method
|
2403
|
+
], $mol_crypto_key_public.prototype, "native", null);
|
2404
|
+
__decorate([
|
2405
|
+
$mol_memo.method
|
2406
|
+
], $mol_crypto_key_public.prototype, "native_derive", null);
|
2407
|
+
$.$mol_crypto_key_public = $mol_crypto_key_public;
|
2408
|
+
class $mol_crypto_key_private extends $mol_crypto_key {
|
2409
|
+
static size_str = 129;
|
2410
|
+
static size_bin = 96;
|
2411
|
+
static size_sign = 64;
|
2412
|
+
static async generate() {
|
2413
|
+
const pair = await $mol_crypto_native.subtle.generateKey(ecdsa, Boolean('extractable'), ['sign', 'verify']);
|
2414
|
+
const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', pair.privateKey);
|
2415
|
+
return this.from(x + y + d);
|
2416
|
+
}
|
2417
|
+
async native() {
|
2418
|
+
const str = this.toString();
|
2419
|
+
return await $mol_crypto_native.subtle.importKey('jwk', {
|
2420
|
+
crv: "P-256",
|
2421
|
+
ext: true,
|
2422
|
+
key_ops: ['sign'],
|
2423
|
+
kty: "EC",
|
2424
|
+
x: str.slice(0, 43),
|
2425
|
+
y: str.slice(43, 86),
|
2426
|
+
d: str.slice(86, 129),
|
2427
|
+
}, ecdsa, Boolean('extractable'), ['sign']);
|
2428
|
+
}
|
2429
|
+
async native_derive() {
|
2430
|
+
const serial = this.toString();
|
2431
|
+
return $mol_crypto_native.subtle.importKey('jwk', {
|
2432
|
+
...jwk,
|
2433
|
+
key_ops: ['deriveKey', 'deriveBits'],
|
2434
|
+
x: serial.slice(0, 43),
|
2435
|
+
y: serial.slice(43, 86),
|
2436
|
+
d: serial.slice(86, 129),
|
2437
|
+
}, ecdh, Boolean('extractable'), ['deriveKey', 'deriveBits']);
|
2438
|
+
}
|
2439
|
+
public() {
|
2440
|
+
return new $mol_crypto_key_public(this.buffer, this.byteOffset, this.byteOffset + 64);
|
2441
|
+
}
|
2442
|
+
async sign(data) {
|
2443
|
+
return new Uint8Array(await $mol_crypto_native.subtle.sign(ecdsa, await this.native(), data));
|
2444
|
+
}
|
2445
|
+
}
|
2446
|
+
__decorate([
|
2447
|
+
$mol_memo.method
|
2448
|
+
], $mol_crypto_key_private.prototype, "native", null);
|
2449
|
+
__decorate([
|
2450
|
+
$mol_memo.method
|
2451
|
+
], $mol_crypto_key_private.prototype, "native_derive", null);
|
2452
|
+
__decorate([
|
2453
|
+
$mol_memo.method
|
2454
|
+
], $mol_crypto_key_private.prototype, "public", null);
|
2455
|
+
$.$mol_crypto_key_private = $mol_crypto_key_private;
|
2100
2456
|
})($ || ($ = {}));
|
2101
2457
|
|
2102
2458
|
;
|
2103
2459
|
"use strict";
|
2104
2460
|
var $;
|
2105
2461
|
(function ($) {
|
2106
|
-
function $
|
2107
|
-
return $
|
2108
|
-
|
2109
|
-
|
2110
|
-
|
2111
|
-
return $mol_base64_decode(str.replace(/æ/g, '+').replace(/Æ/g, '/'));
|
2462
|
+
async function $mol_crypto_sacred_shared(priv, pub) {
|
2463
|
+
return $mol_crypto_sacred.from(new Uint8Array(await $mol_crypto_native.subtle.deriveBits({
|
2464
|
+
name: "ECDH",
|
2465
|
+
public: await pub.native_derive(),
|
2466
|
+
}, await priv.native_derive(), $mol_crypto_sacred.size)));
|
2112
2467
|
}
|
2113
|
-
$.$
|
2468
|
+
$.$mol_crypto_sacred_shared = $mol_crypto_sacred_shared;
|
2114
2469
|
})($ || ($ = {}));
|
2115
2470
|
|
2116
2471
|
;
|
2117
2472
|
"use strict";
|
2118
2473
|
var $;
|
2119
2474
|
(function ($) {
|
2120
|
-
|
2121
|
-
|
2122
|
-
|
2123
|
-
|
2124
|
-
|
2125
|
-
|
2126
|
-
|
2127
|
-
|
2128
|
-
|
2129
|
-
|
2130
|
-
|
2131
|
-
|
2132
|
-
|
2133
|
-
|
2134
|
-
}
|
2135
|
-
else {
|
2136
|
-
return this.getUint32(offset, LE) + this.getUint16(offset + 4, LE) * 2 ** 32;
|
2137
|
-
}
|
2138
|
-
}
|
2139
|
-
setUint48(offset, value, LE = false) {
|
2140
|
-
if (offset % 4) {
|
2141
|
-
this.setUint16(offset, value & ((1 << 16) - 1), LE);
|
2142
|
-
this.setUint32(offset + 2, (value / 2 ** 16) | 0, LE);
|
2143
|
-
}
|
2144
|
-
else {
|
2145
|
-
this.setUint32(offset, value | 0, LE);
|
2146
|
-
this.setUint16(offset + 4, (value / 2 ** 32) | 0, LE);
|
2147
|
-
}
|
2148
|
-
}
|
2149
|
-
int8(offset, next) {
|
2150
|
-
if (next === undefined)
|
2151
|
-
return this.getInt8(offset);
|
2152
|
-
if (next >= -(2 ** 7) && next < 2 ** 7)
|
2153
|
-
return this.setInt8(offset, next), next;
|
2154
|
-
$mol_fail(new Error(`Wrong int8 value ${next}`));
|
2155
|
-
}
|
2156
|
-
uint8(offset, next) {
|
2157
|
-
if (next === undefined)
|
2158
|
-
return this.getUint8(offset);
|
2159
|
-
if (next >= 0 && next < 2 ** 8)
|
2160
|
-
return this.setUint8(offset, next), next;
|
2161
|
-
$mol_fail(new Error(`Wrong uint8 value ${next}`));
|
2162
|
-
}
|
2163
|
-
int16(offset, next) {
|
2164
|
-
if (next === undefined)
|
2165
|
-
return this.getInt16(offset, true);
|
2166
|
-
if (next >= -(2 ** 15) && next < 2 ** 15)
|
2167
|
-
return this.setInt16(offset, next, true), next;
|
2168
|
-
$mol_fail(new Error(`Wrong int16 value ${next}`));
|
2169
|
-
}
|
2170
|
-
uint16(offset, next) {
|
2171
|
-
if (next === undefined)
|
2172
|
-
return this.getUint16(offset, true);
|
2173
|
-
if (next >= 0 && next < 2 ** 16)
|
2174
|
-
return this.setUint16(offset, next, true), next;
|
2175
|
-
$mol_fail(new Error(`Wrong uint16 value ${next}`));
|
2176
|
-
}
|
2177
|
-
int32(offset, next) {
|
2178
|
-
if (next === undefined)
|
2179
|
-
return this.getInt32(offset, true);
|
2180
|
-
if (next >= -(2 ** 31) && next < 2 ** 31)
|
2181
|
-
return this.setInt32(offset, next, true), next;
|
2182
|
-
$mol_fail(new Error(`Wrong int32 value ${next}`));
|
2183
|
-
}
|
2184
|
-
uint32(offset, next) {
|
2185
|
-
if (next === undefined)
|
2186
|
-
return this.getUint32(offset, true);
|
2187
|
-
if (next >= 0 && next < 2 ** 32)
|
2188
|
-
return this.setUint32(offset, next, true), next;
|
2189
|
-
$mol_fail(new Error(`Wrong uint32 value ${next}`));
|
2190
|
-
}
|
2191
|
-
uint48(offset, next) {
|
2192
|
-
if (next === undefined)
|
2193
|
-
return this.getUint48(offset, true);
|
2194
|
-
if (next >= 0 && next < 2 ** 48)
|
2195
|
-
return this.setUint48(offset, next, true), next;
|
2196
|
-
$mol_fail(new Error(`Wrong uint48 value ${next}`));
|
2197
|
-
}
|
2198
|
-
int64(offset, next) {
|
2199
|
-
if (next === undefined)
|
2200
|
-
return this.getBigInt64(offset, true);
|
2201
|
-
if (next >= -(2 ** 63) && next < 2 ** 63)
|
2202
|
-
return this.setBigInt64(offset, next, true), next;
|
2203
|
-
$mol_fail(new Error(`Wrong int64 value ${next}`));
|
2204
|
-
}
|
2205
|
-
uint64(offset, next) {
|
2206
|
-
if (next === undefined)
|
2207
|
-
return this.getBigUint64(offset, true);
|
2208
|
-
if (next >= 0 && next < 2 ** 64)
|
2209
|
-
return this.setBigUint64(offset, next, true), next;
|
2210
|
-
$mol_fail(new Error(`Wrong uint64 value ${next}`));
|
2211
|
-
}
|
2212
|
-
float32(offset, next) {
|
2213
|
-
if (next !== undefined)
|
2214
|
-
this.setFloat32(offset, next, true);
|
2215
|
-
return this.getFloat32(offset, true);
|
2216
|
-
}
|
2217
|
-
float64(offset, next) {
|
2218
|
-
if (next !== undefined)
|
2219
|
-
this.setFloat64(offset, next, true);
|
2220
|
-
return this.getFloat64(offset, true);
|
2221
|
-
}
|
2222
|
-
asArray() {
|
2223
|
-
return new Uint8Array(this.buffer, this.byteOffset, this.byteLength);
|
2224
|
-
}
|
2225
|
-
toString() {
|
2226
|
-
return $mol_base64_ae_encode(this.asArray());
|
2227
|
-
}
|
2228
|
-
}
|
2229
|
-
$.$mol_buffer = $mol_buffer;
|
2230
|
-
})($ || ($ = {}));
|
2231
|
-
|
2232
|
-
;
|
2233
|
-
"use strict";
|
2234
|
-
var $;
|
2235
|
-
(function ($) {
|
2236
|
-
function $mol_base64_url_encode(buffer) {
|
2237
|
-
return $mol_base64_encode(buffer).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
2238
|
-
}
|
2239
|
-
$.$mol_base64_url_encode = $mol_base64_url_encode;
|
2240
|
-
function $mol_base64_url_decode(str) {
|
2241
|
-
return $mol_base64_decode(str.replace(/-/g, '+').replace(/_/g, '/'));
|
2242
|
-
}
|
2243
|
-
$.$mol_base64_url_decode = $mol_base64_url_decode;
|
2244
|
-
})($ || ($ = {}));
|
2245
|
-
|
2246
|
-
;
|
2247
|
-
"use strict";
|
2248
|
-
var $;
|
2249
|
-
(function ($) {
|
2250
|
-
class $mol_wrapper extends $mol_object2 {
|
2251
|
-
static wrap;
|
2252
|
-
static run(task) {
|
2253
|
-
return this.func(task)();
|
2254
|
-
}
|
2255
|
-
static func(func) {
|
2256
|
-
return this.wrap(func);
|
2257
|
-
}
|
2258
|
-
static get class() {
|
2259
|
-
return (Class) => {
|
2260
|
-
const construct = (target, args) => new Class(...args);
|
2261
|
-
const handler = {
|
2262
|
-
construct: this.func(construct)
|
2263
|
-
};
|
2264
|
-
handler[Symbol.toStringTag] = Class.name + '#';
|
2265
|
-
return new Proxy(Class, handler);
|
2266
|
-
};
|
2267
|
-
}
|
2268
|
-
static get method() {
|
2269
|
-
return (obj, name, descr) => {
|
2270
|
-
descr.value = this.func(descr.value);
|
2271
|
-
return descr;
|
2272
|
-
};
|
2273
|
-
}
|
2274
|
-
static get field() {
|
2275
|
-
return (obj, name, descr) => {
|
2276
|
-
descr.get = descr.set = this.func(descr.get);
|
2277
|
-
return descr;
|
2278
|
-
};
|
2279
|
-
}
|
2280
|
-
}
|
2281
|
-
$.$mol_wrapper = $mol_wrapper;
|
2282
|
-
})($ || ($ = {}));
|
2283
|
-
|
2284
|
-
;
|
2285
|
-
"use strict";
|
2286
|
-
var $;
|
2287
|
-
(function ($) {
|
2288
|
-
class $mol_memo extends $mol_wrapper {
|
2289
|
-
static wrap(task) {
|
2290
|
-
const store = new WeakMap();
|
2291
|
-
const fun = function (next) {
|
2292
|
-
if (next === undefined && store.has(this))
|
2293
|
-
return store.get(this);
|
2294
|
-
const val = task.call(this, next) ?? next;
|
2295
|
-
store.set(this, val);
|
2296
|
-
return val;
|
2297
|
-
};
|
2298
|
-
Reflect.defineProperty(fun, 'name', { value: task.name + ' ' });
|
2299
|
-
return fun;
|
2300
|
-
}
|
2301
|
-
}
|
2302
|
-
$.$mol_memo = $mol_memo;
|
2303
|
-
})($ || ($ = {}));
|
2304
|
-
|
2305
|
-
;
|
2306
|
-
"use strict";
|
2307
|
-
var $;
|
2308
|
-
(function ($) {
|
2309
|
-
const algorithm = {
|
2310
|
-
name: 'ECDSA',
|
2311
|
-
hash: 'SHA-1',
|
2312
|
-
namedCurve: "P-256",
|
2313
|
-
};
|
2314
|
-
class $mol_crypto_key extends $mol_buffer {
|
2315
|
-
static from(serial) {
|
2316
|
-
if (typeof serial === 'string') {
|
2317
|
-
serial = new Uint8Array([
|
2318
|
-
...$mol_base64_url_decode(serial.slice(0, 43)),
|
2319
|
-
...$mol_base64_url_decode(serial.slice(43, 86)),
|
2320
|
-
...$mol_base64_url_decode(serial.slice(86, 129)),
|
2321
|
-
]);
|
2322
|
-
}
|
2323
|
-
return super.from(serial);
|
2324
|
-
}
|
2325
|
-
asArray() {
|
2326
|
-
return new Uint8Array(this.buffer, this.byteOffset, this.byteLength);
|
2327
|
-
}
|
2328
|
-
toString() {
|
2329
|
-
const arr = this.asArray();
|
2330
|
-
return $mol_base64_url_encode(arr.subarray(0, 32))
|
2331
|
-
+ $mol_base64_url_encode(arr.subarray(32, 64))
|
2332
|
-
+ $mol_base64_url_encode(arr.subarray(64));
|
2333
|
-
}
|
2334
|
-
}
|
2335
|
-
__decorate([
|
2336
|
-
$mol_memo.method
|
2337
|
-
], $mol_crypto_key.prototype, "toString", null);
|
2338
|
-
$.$mol_crypto_key = $mol_crypto_key;
|
2339
|
-
class $mol_crypto_key_public extends $mol_crypto_key {
|
2340
|
-
static size_str = 86;
|
2341
|
-
static size_bin = 64;
|
2342
|
-
async native() {
|
2343
|
-
const str = this.toString();
|
2344
|
-
return $mol_crypto_native.subtle.importKey('jwk', {
|
2345
|
-
crv: "P-256",
|
2346
|
-
ext: true,
|
2347
|
-
key_ops: ['verify'],
|
2348
|
-
kty: "EC",
|
2349
|
-
x: str.slice(0, 43),
|
2350
|
-
y: str.slice(43, 86),
|
2351
|
-
}, algorithm, true, ['verify']);
|
2352
|
-
}
|
2353
|
-
async verify(data, sign) {
|
2354
|
-
return await $mol_crypto_native.subtle.verify(algorithm, await this.native(), sign, data);
|
2355
|
-
}
|
2356
|
-
}
|
2357
|
-
__decorate([
|
2358
|
-
$mol_memo.method
|
2359
|
-
], $mol_crypto_key_public.prototype, "native", null);
|
2360
|
-
$.$mol_crypto_key_public = $mol_crypto_key_public;
|
2361
|
-
class $mol_crypto_key_private extends $mol_crypto_key {
|
2362
|
-
static size_str = 129;
|
2363
|
-
static size_bin = 96;
|
2364
|
-
static size_sign = 64;
|
2365
|
-
static async generate() {
|
2366
|
-
const pair = await $mol_crypto_native.subtle.generateKey(algorithm, true, ['sign', 'verify']);
|
2367
|
-
const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', pair.privateKey);
|
2368
|
-
return this.from(x + y + d);
|
2369
|
-
}
|
2370
|
-
async native() {
|
2371
|
-
const str = this.toString();
|
2372
|
-
return await $mol_crypto_native.subtle.importKey('jwk', {
|
2373
|
-
crv: "P-256",
|
2374
|
-
ext: true,
|
2375
|
-
key_ops: ['sign'],
|
2376
|
-
kty: "EC",
|
2377
|
-
x: str.slice(0, 43),
|
2378
|
-
y: str.slice(43, 86),
|
2379
|
-
d: str.slice(86, 129),
|
2380
|
-
}, algorithm, true, ['sign']);
|
2381
|
-
}
|
2382
|
-
public() {
|
2383
|
-
return new $mol_crypto_key_public(this.buffer, this.byteOffset, this.byteOffset + 64);
|
2384
|
-
}
|
2385
|
-
async sign(data) {
|
2386
|
-
return new Uint8Array(await $mol_crypto_native.subtle.sign(algorithm, await this.native(), data));
|
2387
|
-
}
|
2388
|
-
}
|
2389
|
-
__decorate([
|
2390
|
-
$mol_memo.method
|
2391
|
-
], $mol_crypto_key_private.prototype, "native", null);
|
2392
|
-
__decorate([
|
2393
|
-
$mol_memo.method
|
2394
|
-
], $mol_crypto_key_private.prototype, "public", null);
|
2395
|
-
$.$mol_crypto_key_private = $mol_crypto_key_private;
|
2396
|
-
})($ || ($ = {}));
|
2397
|
-
|
2398
|
-
;
|
2399
|
-
"use strict";
|
2400
|
-
var $;
|
2401
|
-
(function ($) {
|
2402
|
-
let sponge = new Uint32Array(80);
|
2403
|
-
function $mol_crypto_hash(input) {
|
2404
|
-
const data = input instanceof Uint8Array
|
2405
|
-
? input
|
2406
|
-
: new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
|
2407
|
-
const bits = data.byteLength << 3;
|
2408
|
-
const kbits = bits >> 5;
|
2409
|
-
const kword = 0x80 << (24 - bits & 0b11111);
|
2410
|
-
const bytes = 16 + (bits + 64 >>> 9 << 4);
|
2411
|
-
const klens = bytes - 1;
|
2412
|
-
const words = new Int32Array(data.buffer, data.byteOffset, data.byteLength >> 2);
|
2413
|
-
let tail = 0;
|
2414
|
-
for (let i = words.length * 4; i < data.length; ++i) {
|
2415
|
-
tail |= data[i] << (i << 3 & 0b11000);
|
2475
|
+
let sponge = new Uint32Array(80);
|
2476
|
+
function $mol_crypto_hash(input) {
|
2477
|
+
const data = input instanceof Uint8Array
|
2478
|
+
? input
|
2479
|
+
: new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
|
2480
|
+
const bits = data.byteLength << 3;
|
2481
|
+
const kbits = bits >> 5;
|
2482
|
+
const kword = 0x80 << (24 - bits & 0b11111);
|
2483
|
+
const bytes = 16 + (bits + 64 >>> 9 << 4);
|
2484
|
+
const klens = bytes - 1;
|
2485
|
+
const words = new Int32Array(data.buffer, data.byteOffset, data.byteLength >> 2);
|
2486
|
+
let tail = 0;
|
2487
|
+
for (let i = words.length * 4; i < data.length; ++i) {
|
2488
|
+
tail |= data[i] << (i << 3 & 0b11000);
|
2416
2489
|
}
|
2417
2490
|
const hash = new Int32Array([1732584193, -271733879, -1732584194, 271733878, -1009589776]);
|
2418
2491
|
for (let i = 0; i < bytes; i += 16) {
|
@@ -2497,17 +2570,6 @@ var $;
|
|
2497
2570
|
$.$mol_crypto_hash = $mol_crypto_hash;
|
2498
2571
|
})($ || ($ = {}));
|
2499
2572
|
|
2500
|
-
;
|
2501
|
-
"use strict";
|
2502
|
-
var $;
|
2503
|
-
(function ($) {
|
2504
|
-
function $mol_crypto_salt() {
|
2505
|
-
return $mol_crypto_native.getRandomValues(new Uint8Array(16));
|
2506
|
-
}
|
2507
|
-
$.$mol_crypto_salt = $mol_crypto_salt;
|
2508
|
-
$.$mol_crypto_salt_once = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6]);
|
2509
|
-
})($ || ($ = {}));
|
2510
|
-
|
2511
2573
|
;
|
2512
2574
|
"use strict";
|
2513
2575
|
var $;
|
@@ -2615,86 +2677,15 @@ var $;
|
|
2615
2677
|
;
|
2616
2678
|
"use strict";
|
2617
2679
|
var $;
|
2618
|
-
(function ($) {
|
2619
|
-
|
2620
|
-
|
2621
|
-
|
2622
|
-
|
2623
|
-
|
2624
|
-
|
2625
|
-
|
2626
|
-
|
2627
|
-
return;
|
2628
|
-
$mol_fail(new Error(`${value} ≠ false`));
|
2629
|
-
}
|
2630
|
-
$.$mol_assert_not = $mol_assert_not;
|
2631
|
-
function $mol_assert_fail(handler, ErrorRight) {
|
2632
|
-
const fail = $.$mol_fail;
|
2633
|
-
try {
|
2634
|
-
$.$mol_fail = $.$mol_fail_hidden;
|
2635
|
-
handler();
|
2636
|
-
}
|
2637
|
-
catch (error) {
|
2638
|
-
$.$mol_fail = fail;
|
2639
|
-
if (typeof ErrorRight === 'string') {
|
2640
|
-
$mol_assert_equal(error.message, ErrorRight);
|
2641
|
-
}
|
2642
|
-
else {
|
2643
|
-
$mol_assert_equal(error instanceof ErrorRight, true);
|
2644
|
-
}
|
2645
|
-
return error;
|
2646
|
-
}
|
2647
|
-
finally {
|
2648
|
-
$.$mol_fail = fail;
|
2649
|
-
}
|
2650
|
-
$mol_fail(new Error('Not failed'));
|
2651
|
-
}
|
2652
|
-
$.$mol_assert_fail = $mol_assert_fail;
|
2653
|
-
function $mol_assert_like(...args) {
|
2654
|
-
$mol_assert_equal(...args);
|
2655
|
-
}
|
2656
|
-
$.$mol_assert_like = $mol_assert_like;
|
2657
|
-
function $mol_assert_unique(...args) {
|
2658
|
-
for (let i = 0; i < args.length; ++i) {
|
2659
|
-
for (let j = 0; j < args.length; ++j) {
|
2660
|
-
if (i === j)
|
2661
|
-
continue;
|
2662
|
-
if (!$mol_compare_deep(args[i], args[j]))
|
2663
|
-
continue;
|
2664
|
-
$mol_fail(new Error(`args[${i}] = args[${j}] = ${print(args[i])}`));
|
2665
|
-
}
|
2666
|
-
}
|
2667
|
-
}
|
2668
|
-
$.$mol_assert_unique = $mol_assert_unique;
|
2669
|
-
function $mol_assert_equal(...args) {
|
2670
|
-
for (let i = 1; i < args.length; ++i) {
|
2671
|
-
if ($mol_compare_deep(args[0], args[i]))
|
2672
|
-
continue;
|
2673
|
-
if (args[0] instanceof $mol_dom_context.Element && args[i] instanceof $mol_dom_context.Element && args[0].outerHTML === args[i].outerHTML)
|
2674
|
-
continue;
|
2675
|
-
return $mol_fail(new Error(`args[0] ≠ args[${i}]\n${print(args[0])}\n---\n${print(args[i])}`));
|
2676
|
-
}
|
2677
|
-
}
|
2678
|
-
$.$mol_assert_equal = $mol_assert_equal;
|
2679
|
-
const print = (val) => {
|
2680
|
-
if (!val)
|
2681
|
-
return val;
|
2682
|
-
if (typeof val === 'bigint')
|
2683
|
-
return String(val) + 'n';
|
2684
|
-
if (typeof val === 'symbol')
|
2685
|
-
return `Symbol(${val.description})`;
|
2686
|
-
if (typeof val !== 'object')
|
2687
|
-
return val;
|
2688
|
-
if ('outerHTML' in val)
|
2689
|
-
return val.outerHTML;
|
2690
|
-
try {
|
2691
|
-
return JSON.stringify(val, (k, v) => typeof v === 'bigint' ? String(v) : v, '\t');
|
2692
|
-
}
|
2693
|
-
catch (error) {
|
2694
|
-
console.error(error);
|
2695
|
-
return val;
|
2696
|
-
}
|
2697
|
-
};
|
2680
|
+
(function ($_1) {
|
2681
|
+
$mol_test({
|
2682
|
+
'FQN of anon function'($) {
|
2683
|
+
const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
|
2684
|
+
$mol_assert_equal($$.$mol_func_name_test.name, '');
|
2685
|
+
$mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
|
2686
|
+
$mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
|
2687
|
+
},
|
2688
|
+
});
|
2698
2689
|
})($ || ($ = {}));
|
2699
2690
|
|
2700
2691
|
;
|
@@ -2702,50 +2693,31 @@ var $;
|
|
2702
2693
|
var $;
|
2703
2694
|
(function ($) {
|
2704
2695
|
$mol_test({
|
2705
|
-
'
|
2706
|
-
$
|
2707
|
-
|
2708
|
-
|
2709
|
-
$
|
2710
|
-
},
|
2711
|
-
'two must be equal'() {
|
2712
|
-
$mol_assert_equal(2, 2);
|
2713
|
-
},
|
2714
|
-
'three must be equal'() {
|
2715
|
-
$mol_assert_equal(2, 2, 2);
|
2716
|
-
},
|
2717
|
-
'two must be unique'() {
|
2718
|
-
$mol_assert_unique([2], [3]);
|
2719
|
-
},
|
2720
|
-
'three must be unique'() {
|
2721
|
-
$mol_assert_unique([1], [2], [3]);
|
2722
|
-
},
|
2723
|
-
'two must be alike'() {
|
2724
|
-
$mol_assert_like([3], [3]);
|
2725
|
-
},
|
2726
|
-
'three must be alike'() {
|
2727
|
-
$mol_assert_like([3], [3], [3]);
|
2728
|
-
},
|
2729
|
-
'two object must be alike'() {
|
2730
|
-
$mol_assert_like({ a: 1 }, { a: 1 });
|
2696
|
+
'auto name'() {
|
2697
|
+
class Invalid extends $mol_error_mix {
|
2698
|
+
}
|
2699
|
+
const mix = new Invalid('foo');
|
2700
|
+
$mol_assert_equal(mix.name, 'Invalid_Error');
|
2731
2701
|
},
|
2732
|
-
'
|
2733
|
-
|
2702
|
+
'simpe mix'() {
|
2703
|
+
const mix = new $mol_error_mix('foo', {}, new Error('bar'), new Error('lol'));
|
2704
|
+
$mol_assert_equal(mix.message, 'foo');
|
2705
|
+
$mol_assert_equal(mix.errors.map(e => e.message), ['bar', 'lol']);
|
2706
|
+
},
|
2707
|
+
'provide additional info'() {
|
2708
|
+
class Invalid extends $mol_error_mix {
|
2709
|
+
}
|
2710
|
+
const mix = new $mol_error_mix('Wrong password', {}, new Invalid('Too short', { value: 'p@ssw0rd', hint: '> 8 letters' }), new Invalid('Too simple', { value: 'p@ssw0rd', hint: 'need capital letter' }));
|
2711
|
+
const hints = [];
|
2712
|
+
if (mix instanceof $mol_error_mix) {
|
2713
|
+
for (const er of mix.errors) {
|
2714
|
+
if (er instanceof Invalid) {
|
2715
|
+
hints.push(er.cause?.hint ?? '');
|
2716
|
+
}
|
2717
|
+
}
|
2718
|
+
}
|
2719
|
+
$mol_assert_equal(hints, ['> 8 letters', 'need capital letter']);
|
2734
2720
|
},
|
2735
|
-
});
|
2736
|
-
})($ || ($ = {}));
|
2737
|
-
|
2738
|
-
;
|
2739
|
-
"use strict";
|
2740
|
-
var $;
|
2741
|
-
(function ($_1) {
|
2742
|
-
$mol_test_mocks.push($ => {
|
2743
|
-
$.$mol_log3_come = () => { };
|
2744
|
-
$.$mol_log3_done = () => { };
|
2745
|
-
$.$mol_log3_fail = () => { };
|
2746
|
-
$.$mol_log3_warn = () => { };
|
2747
|
-
$.$mol_log3_rise = () => { };
|
2748
|
-
$.$mol_log3_area = () => () => { };
|
2749
2721
|
});
|
2750
2722
|
})($ || ($ = {}));
|
2751
2723
|
|
@@ -2772,155 +2744,16 @@ var $;
|
|
2772
2744
|
var $;
|
2773
2745
|
(function ($) {
|
2774
2746
|
$mol_test({
|
2775
|
-
'
|
2776
|
-
|
2777
|
-
|
2778
|
-
|
2779
|
-
|
2780
|
-
const proxy = $mol_delegate({}, () => ({ foo: 777 }));
|
2781
|
-
$mol_assert_equal('foo' in proxy, true);
|
2782
|
-
},
|
2783
|
-
'set'() {
|
2784
|
-
const target = { foo: 777 };
|
2785
|
-
const proxy = $mol_delegate({}, () => target);
|
2786
|
-
proxy.foo = 123;
|
2787
|
-
$mol_assert_equal(target.foo, 123);
|
2788
|
-
},
|
2789
|
-
'getOwnPropertyDescriptor'() {
|
2790
|
-
const proxy = $mol_delegate({}, () => ({ foo: 777 }));
|
2791
|
-
$mol_assert_like(Object.getOwnPropertyDescriptor(proxy, 'foo'), {
|
2792
|
-
value: 777,
|
2793
|
-
writable: true,
|
2794
|
-
enumerable: true,
|
2795
|
-
configurable: true,
|
2796
|
-
});
|
2797
|
-
},
|
2798
|
-
'ownKeys'() {
|
2799
|
-
const proxy = $mol_delegate({}, () => ({ foo: 777, [Symbol.toStringTag]: 'bar' }));
|
2800
|
-
$mol_assert_like(Reflect.ownKeys(proxy), ['foo', Symbol.toStringTag]);
|
2801
|
-
},
|
2802
|
-
'getPrototypeOf'() {
|
2803
|
-
class Foo {
|
2804
|
-
}
|
2805
|
-
const proxy = $mol_delegate({}, () => new Foo);
|
2806
|
-
$mol_assert_equal(Object.getPrototypeOf(proxy), Foo.prototype);
|
2807
|
-
},
|
2808
|
-
'setPrototypeOf'() {
|
2809
|
-
class Foo {
|
2810
|
-
}
|
2811
|
-
const target = {};
|
2812
|
-
const proxy = $mol_delegate({}, () => target);
|
2813
|
-
Object.setPrototypeOf(proxy, Foo.prototype);
|
2814
|
-
$mol_assert_equal(Object.getPrototypeOf(target), Foo.prototype);
|
2815
|
-
},
|
2816
|
-
'instanceof'() {
|
2817
|
-
class Foo {
|
2818
|
-
}
|
2819
|
-
const proxy = $mol_delegate({}, () => new Foo);
|
2820
|
-
$mol_assert_ok(proxy instanceof Foo);
|
2821
|
-
$mol_assert_ok(proxy instanceof $mol_delegate);
|
2822
|
-
},
|
2823
|
-
'autobind'() {
|
2824
|
-
class Foo {
|
2747
|
+
'init with overload'() {
|
2748
|
+
class X extends $mol_object {
|
2749
|
+
foo() {
|
2750
|
+
return 1;
|
2751
|
+
}
|
2825
2752
|
}
|
2826
|
-
|
2827
|
-
|
2828
|
-
$mol_assert_ok(proxy instanceof $mol_delegate);
|
2829
|
-
},
|
2830
|
-
});
|
2831
|
-
})($ || ($ = {}));
|
2832
|
-
|
2833
|
-
;
|
2834
|
-
"use strict";
|
2835
|
-
var $;
|
2836
|
-
(function ($_1) {
|
2837
|
-
$mol_test({
|
2838
|
-
'span for same uri'($) {
|
2839
|
-
const span = new $mol_span('test.ts', '', 1, 3, 4);
|
2840
|
-
const child = span.span(4, 5, 8);
|
2841
|
-
$mol_assert_equal(child.uri, 'test.ts');
|
2842
|
-
$mol_assert_equal(child.row, 4);
|
2843
|
-
$mol_assert_equal(child.col, 5);
|
2844
|
-
$mol_assert_equal(child.length, 8);
|
2845
|
-
},
|
2846
|
-
'span after of given position'($) {
|
2847
|
-
const span = new $mol_span('test.ts', '', 1, 3, 4);
|
2848
|
-
const child = span.after(11);
|
2849
|
-
$mol_assert_equal(child.uri, 'test.ts');
|
2850
|
-
$mol_assert_equal(child.row, 1);
|
2851
|
-
$mol_assert_equal(child.col, 7);
|
2852
|
-
$mol_assert_equal(child.length, 11);
|
2853
|
-
},
|
2854
|
-
'slice span - regular'($) {
|
2855
|
-
const span = new $mol_span('test.ts', '', 1, 3, 5);
|
2856
|
-
const child = span.slice(1, 4);
|
2857
|
-
$mol_assert_equal(child.row, 1);
|
2858
|
-
$mol_assert_equal(child.col, 4);
|
2859
|
-
$mol_assert_equal(child.length, 3);
|
2860
|
-
const child2 = span.slice(2, 2);
|
2861
|
-
$mol_assert_equal(child2.col, 5);
|
2862
|
-
$mol_assert_equal(child2.length, 0);
|
2863
|
-
},
|
2864
|
-
'slice span - negative'($) {
|
2865
|
-
const span = new $mol_span('test.ts', '', 1, 3, 5);
|
2866
|
-
const child = span.slice(-3, -1);
|
2867
|
-
$mol_assert_equal(child.row, 1);
|
2868
|
-
$mol_assert_equal(child.col, 5);
|
2869
|
-
$mol_assert_equal(child.length, 2);
|
2870
|
-
},
|
2871
|
-
'slice span - out of range'($) {
|
2872
|
-
const span = new $mol_span('test.ts', '', 1, 3, 5);
|
2873
|
-
$mol_assert_fail(() => span.slice(-1, 3), `End value '3' can't be less than begin value (test.ts#1:3/5)`);
|
2874
|
-
$mol_assert_fail(() => span.slice(1, 6), `End value '6' out of range (test.ts#1:3/5)`);
|
2875
|
-
$mol_assert_fail(() => span.slice(1, 10), `End value '10' out of range (test.ts#1:3/5)`);
|
2876
|
-
},
|
2877
|
-
'error handling'($) {
|
2878
|
-
const span = new $mol_span('test.ts', '', 1, 3, 4);
|
2879
|
-
const error = span.error('Some error');
|
2880
|
-
$mol_assert_equal(error.message, 'Some error (test.ts#1:3/4)');
|
2881
|
-
}
|
2882
|
-
});
|
2883
|
-
})($ || ($ = {}));
|
2884
|
-
|
2885
|
-
;
|
2886
|
-
"use strict";
|
2887
|
-
var $;
|
2888
|
-
(function ($_1) {
|
2889
|
-
$mol_test({
|
2890
|
-
'inserting'($) {
|
2891
|
-
$mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
|
2892
|
-
.insert($mol_tree2.struct('x'), 'a', 'b', 'c')
|
2893
|
-
.toString(), 'a b x\n');
|
2894
|
-
$mol_assert_equal($.$mol_tree2_from_string('a b\n')
|
2895
|
-
.insert($mol_tree2.struct('x'), 'a', 'b', 'c', 'd')
|
2896
|
-
.toString(), 'a b c x\n');
|
2897
|
-
$mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
|
2898
|
-
.insert($mol_tree2.struct('x'), 0, 0, 0)
|
2899
|
-
.toString(), 'a b x\n');
|
2900
|
-
$mol_assert_equal($.$mol_tree2_from_string('a b\n')
|
2901
|
-
.insert($mol_tree2.struct('x'), 0, 0, 0, 0)
|
2902
|
-
.toString(), 'a b \\\n\tx\n');
|
2903
|
-
$mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
|
2904
|
-
.insert($mol_tree2.struct('x'), null, null, null)
|
2905
|
-
.toString(), 'a b x\n');
|
2906
|
-
$mol_assert_equal($.$mol_tree2_from_string('a b\n')
|
2907
|
-
.insert($mol_tree2.struct('x'), null, null, null, null)
|
2908
|
-
.toString(), 'a b \\\n\tx\n');
|
2909
|
-
},
|
2910
|
-
'deleting'($) {
|
2911
|
-
$mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
|
2912
|
-
.insert(null, 'a', 'b', 'c')
|
2913
|
-
.toString(), 'a b\n');
|
2914
|
-
$mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
|
2915
|
-
.insert(null, 0, 0, 0)
|
2916
|
-
.toString(), 'a b\n');
|
2917
|
-
},
|
2918
|
-
'hack'($) {
|
2919
|
-
const res = $.$mol_tree2_from_string(`foo bar xxx\n`)
|
2920
|
-
.hack({
|
2921
|
-
'bar': (input, belt) => [input.struct('777', input.hack(belt))],
|
2753
|
+
var x = X.make({
|
2754
|
+
foo: () => 2,
|
2922
2755
|
});
|
2923
|
-
$mol_assert_equal(
|
2756
|
+
$mol_assert_equal(x.foo(), 2);
|
2924
2757
|
},
|
2925
2758
|
});
|
2926
2759
|
})($ || ($ = {}));
|
@@ -2930,67 +2763,55 @@ var $;
|
|
2930
2763
|
var $;
|
2931
2764
|
(function ($_1) {
|
2932
2765
|
$mol_test({
|
2933
|
-
'
|
2934
|
-
$
|
2935
|
-
$
|
2936
|
-
$
|
2937
|
-
|
2938
|
-
|
2939
|
-
|
2940
|
-
|
2941
|
-
|
2942
|
-
|
2943
|
-
|
2944
|
-
|
2945
|
-
|
2946
|
-
|
2947
|
-
|
2948
|
-
|
2949
|
-
|
2950
|
-
|
2951
|
-
|
2952
|
-
|
2953
|
-
|
2954
|
-
|
2955
|
-
|
2956
|
-
|
2957
|
-
|
2958
|
-
|
2959
|
-
}
|
2960
|
-
|
2961
|
-
|
2962
|
-
|
2963
|
-
$mol_assert_fail(() => {
|
2964
|
-
$.$mol_tree2_from_string(tree, 'test');
|
2965
|
-
}, 'Wrong nodes separator\ntest#2:1/2\n!!\n \tbar');
|
2966
|
-
},
|
2967
|
-
'Wrong nodes separator in the middle'($) {
|
2968
|
-
const tree = `foo bar\n`;
|
2969
|
-
$mol_assert_fail(() => {
|
2970
|
-
$.$mol_tree2_from_string(tree, 'test');
|
2971
|
-
}, 'Wrong nodes separator\ntest#1:5/1\n !\nfoo bar');
|
2972
|
-
},
|
2973
|
-
'Unexpected EOF, LF required'($) {
|
2974
|
-
const tree = ` foo`;
|
2975
|
-
$mol_assert_fail(() => {
|
2976
|
-
$.$mol_tree2_from_string(tree, 'test');
|
2977
|
-
}, 'Unexpected EOF, LF required\ntest#1:5/1\n !\n foo');
|
2766
|
+
'Collect deps'() {
|
2767
|
+
const pub1 = new $mol_wire_pub;
|
2768
|
+
const pub2 = new $mol_wire_pub;
|
2769
|
+
const sub = new $mol_wire_pub_sub;
|
2770
|
+
const bu1 = sub.track_on();
|
2771
|
+
try {
|
2772
|
+
pub1.promote();
|
2773
|
+
pub2.promote();
|
2774
|
+
pub2.promote();
|
2775
|
+
}
|
2776
|
+
finally {
|
2777
|
+
sub.track_cut();
|
2778
|
+
sub.track_off(bu1);
|
2779
|
+
}
|
2780
|
+
pub1.emit();
|
2781
|
+
pub2.emit();
|
2782
|
+
$mol_assert_like(sub.pub_list, [pub1, pub2, pub2]);
|
2783
|
+
const bu2 = sub.track_on();
|
2784
|
+
try {
|
2785
|
+
pub1.promote();
|
2786
|
+
pub1.promote();
|
2787
|
+
pub2.promote();
|
2788
|
+
}
|
2789
|
+
finally {
|
2790
|
+
sub.track_cut();
|
2791
|
+
sub.track_off(bu2);
|
2792
|
+
}
|
2793
|
+
pub1.emit();
|
2794
|
+
pub2.emit();
|
2795
|
+
$mol_assert_like(sub.pub_list, [pub1, pub1, pub2]);
|
2978
2796
|
},
|
2979
|
-
'
|
2980
|
-
const
|
2981
|
-
const
|
2982
|
-
const
|
2983
|
-
|
2984
|
-
|
2985
|
-
|
2797
|
+
'cyclic detection'($) {
|
2798
|
+
const sub1 = new $mol_wire_pub_sub;
|
2799
|
+
const sub2 = new $mol_wire_pub_sub;
|
2800
|
+
const bu1 = sub1.track_on();
|
2801
|
+
try {
|
2802
|
+
const bu2 = sub2.track_on();
|
2803
|
+
try {
|
2804
|
+
$mol_assert_fail(() => sub1.promote(), 'Circular subscription');
|
2805
|
+
}
|
2806
|
+
finally {
|
2807
|
+
sub2.track_cut();
|
2808
|
+
sub2.track_off(bu2);
|
2986
2809
|
}
|
2987
|
-
}
|
2988
|
-
|
2989
|
-
|
2990
|
-
|
2991
|
-
|
2992
|
-
]);
|
2993
|
-
$mol_assert_equal(res.toString(), 'foo bar\n');
|
2810
|
+
}
|
2811
|
+
finally {
|
2812
|
+
sub1.track_cut();
|
2813
|
+
sub1.track_off(bu1);
|
2814
|
+
}
|
2994
2815
|
},
|
2995
2816
|
});
|
2996
2817
|
})($ || ($ = {}));
|
@@ -2999,29 +2820,46 @@ var $;
|
|
2999
2820
|
"use strict";
|
3000
2821
|
var $;
|
3001
2822
|
(function ($) {
|
3002
|
-
|
3003
|
-
|
3004
|
-
|
3005
|
-
|
3006
|
-
|
3007
|
-
|
3008
|
-
|
3009
|
-
|
3010
|
-
|
3011
|
-
|
2823
|
+
$.$mol_after_mock_queue = [];
|
2824
|
+
function $mol_after_mock_warp() {
|
2825
|
+
const queue = $.$mol_after_mock_queue.splice(0);
|
2826
|
+
for (const task of queue)
|
2827
|
+
task();
|
2828
|
+
}
|
2829
|
+
$.$mol_after_mock_warp = $mol_after_mock_warp;
|
2830
|
+
class $mol_after_mock_commmon extends $mol_object2 {
|
2831
|
+
task;
|
2832
|
+
promise = Promise.resolve();
|
2833
|
+
cancelled = false;
|
2834
|
+
id;
|
2835
|
+
constructor(task) {
|
2836
|
+
super();
|
2837
|
+
this.task = task;
|
2838
|
+
$.$mol_after_mock_queue.push(task);
|
2839
|
+
}
|
2840
|
+
destructor() {
|
2841
|
+
const index = $.$mol_after_mock_queue.indexOf(this.task);
|
2842
|
+
if (index >= 0)
|
2843
|
+
$.$mol_after_mock_queue.splice(index, 1);
|
2844
|
+
}
|
2845
|
+
}
|
2846
|
+
$.$mol_after_mock_commmon = $mol_after_mock_commmon;
|
2847
|
+
class $mol_after_mock_timeout extends $mol_after_mock_commmon {
|
2848
|
+
delay;
|
2849
|
+
constructor(delay, task) {
|
2850
|
+
super(task);
|
2851
|
+
this.delay = delay;
|
2852
|
+
}
|
2853
|
+
}
|
2854
|
+
$.$mol_after_mock_timeout = $mol_after_mock_timeout;
|
3012
2855
|
})($ || ($ = {}));
|
3013
2856
|
|
3014
2857
|
;
|
3015
2858
|
"use strict";
|
3016
2859
|
var $;
|
3017
2860
|
(function ($_1) {
|
3018
|
-
$
|
3019
|
-
|
3020
|
-
const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
|
3021
|
-
$mol_assert_equal($$.$mol_func_name_test.name, '');
|
3022
|
-
$mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
|
3023
|
-
$mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
|
3024
|
-
},
|
2861
|
+
$mol_test_mocks.push($ => {
|
2862
|
+
$.$mol_after_tick = $mol_after_mock_commmon;
|
3025
2863
|
});
|
3026
2864
|
})($ || ($ = {}));
|
3027
2865
|
|
@@ -3030,49 +2868,202 @@ var $;
|
|
3030
2868
|
var $;
|
3031
2869
|
(function ($) {
|
3032
2870
|
$mol_test({
|
3033
|
-
'
|
3034
|
-
class
|
2871
|
+
'Sync execution'() {
|
2872
|
+
class Sync extends $mol_object2 {
|
2873
|
+
static calc(a, b) {
|
2874
|
+
return a + b;
|
2875
|
+
}
|
3035
2876
|
}
|
3036
|
-
|
3037
|
-
|
2877
|
+
__decorate([
|
2878
|
+
$mol_wire_method
|
2879
|
+
], Sync, "calc", null);
|
2880
|
+
$mol_assert_equal(Sync.calc(1, 2), 3);
|
3038
2881
|
},
|
3039
|
-
'
|
3040
|
-
|
3041
|
-
|
3042
|
-
|
2882
|
+
async 'async <=> sync'() {
|
2883
|
+
class SyncAsync extends $mol_object2 {
|
2884
|
+
static async val(a) {
|
2885
|
+
return a;
|
2886
|
+
}
|
2887
|
+
static sum(a, b) {
|
2888
|
+
const syn = $mol_wire_sync(this);
|
2889
|
+
return syn.val(a) + syn.val(b);
|
2890
|
+
}
|
2891
|
+
static async calc(a, b) {
|
2892
|
+
return 5 + await $mol_wire_async(this).sum(a, b);
|
2893
|
+
}
|
2894
|
+
}
|
2895
|
+
$mol_assert_equal(await SyncAsync.calc(1, 2), 8);
|
3043
2896
|
},
|
3044
|
-
'
|
3045
|
-
class
|
2897
|
+
async 'Idempotence control'() {
|
2898
|
+
class Idempotence extends $mol_object2 {
|
2899
|
+
static logs_idemp = 0;
|
2900
|
+
static logs_unidemp = 0;
|
2901
|
+
static log_idemp() {
|
2902
|
+
this.logs_idemp += 1;
|
2903
|
+
}
|
2904
|
+
static log_unidemp() {
|
2905
|
+
this.logs_unidemp += 1;
|
2906
|
+
}
|
2907
|
+
static async val(a) {
|
2908
|
+
return a;
|
2909
|
+
}
|
2910
|
+
static sum(a, b) {
|
2911
|
+
this.log_idemp();
|
2912
|
+
this.log_unidemp();
|
2913
|
+
const syn = $mol_wire_sync(this);
|
2914
|
+
return syn.val(a) + syn.val(b);
|
2915
|
+
}
|
2916
|
+
static async calc(a, b) {
|
2917
|
+
return 5 + await $mol_wire_async(this).sum(a, b);
|
2918
|
+
}
|
3046
2919
|
}
|
3047
|
-
|
3048
|
-
|
3049
|
-
|
3050
|
-
|
3051
|
-
|
3052
|
-
|
2920
|
+
__decorate([
|
2921
|
+
$mol_wire_method
|
2922
|
+
], Idempotence, "log_idemp", null);
|
2923
|
+
$mol_assert_equal(await Idempotence.calc(1, 2), 8);
|
2924
|
+
$mol_assert_equal(Idempotence.logs_idemp, 1);
|
2925
|
+
$mol_assert_equal(Idempotence.logs_unidemp, 3);
|
2926
|
+
},
|
2927
|
+
async 'Error handling'() {
|
2928
|
+
class Handle extends $mol_object2 {
|
2929
|
+
static async sum(a, b) {
|
2930
|
+
$mol_fail(new Error('test error ' + (a + b)));
|
2931
|
+
}
|
2932
|
+
static check() {
|
2933
|
+
try {
|
2934
|
+
return $mol_wire_sync(Handle).sum(1, 2);
|
2935
|
+
}
|
2936
|
+
catch (error) {
|
2937
|
+
if ($mol_promise_like(error))
|
2938
|
+
$mol_fail_hidden(error);
|
2939
|
+
$mol_assert_equal(error.message, 'test error 3');
|
3053
2940
|
}
|
3054
2941
|
}
|
3055
2942
|
}
|
3056
|
-
$
|
2943
|
+
await $mol_wire_async(Handle).check();
|
3057
2944
|
},
|
3058
2945
|
});
|
3059
2946
|
})($ || ($ = {}));
|
3060
2947
|
|
2948
|
+
;
|
2949
|
+
"use strict";
|
2950
|
+
var $;
|
2951
|
+
(function ($_1) {
|
2952
|
+
$mol_test_mocks.push($ => {
|
2953
|
+
$.$mol_log3_come = () => { };
|
2954
|
+
$.$mol_log3_done = () => { };
|
2955
|
+
$.$mol_log3_fail = () => { };
|
2956
|
+
$.$mol_log3_warn = () => { };
|
2957
|
+
$.$mol_log3_rise = () => { };
|
2958
|
+
$.$mol_log3_area = () => () => { };
|
2959
|
+
});
|
2960
|
+
})($ || ($ = {}));
|
2961
|
+
|
2962
|
+
;
|
2963
|
+
"use strict";
|
2964
|
+
var $;
|
2965
|
+
(function ($) {
|
2966
|
+
function $mol_wire_method(host, field, descr) {
|
2967
|
+
if (!descr)
|
2968
|
+
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
2969
|
+
const orig = descr?.value ?? host[field];
|
2970
|
+
const sup = Reflect.getPrototypeOf(host);
|
2971
|
+
if (typeof sup[field] === 'function') {
|
2972
|
+
Object.defineProperty(orig, 'name', { value: sup[field].name });
|
2973
|
+
}
|
2974
|
+
const temp = $mol_wire_task.getter(orig);
|
2975
|
+
const value = function (...args) {
|
2976
|
+
const fiber = temp(this ?? null, args);
|
2977
|
+
return fiber.sync();
|
2978
|
+
};
|
2979
|
+
Object.defineProperty(value, 'name', { value: orig.name + ' ' });
|
2980
|
+
Object.assign(value, { orig });
|
2981
|
+
const descr2 = { ...descr, value };
|
2982
|
+
Reflect.defineProperty(host, field, descr2);
|
2983
|
+
return descr2;
|
2984
|
+
}
|
2985
|
+
$.$mol_wire_method = $mol_wire_method;
|
2986
|
+
})($ || ($ = {}));
|
2987
|
+
|
3061
2988
|
;
|
3062
2989
|
"use strict";
|
3063
2990
|
var $;
|
3064
2991
|
(function ($) {
|
2992
|
+
function $mol_wire_async(obj) {
|
2993
|
+
let fiber;
|
2994
|
+
const temp = $mol_wire_task.getter(obj);
|
2995
|
+
return new Proxy(obj, {
|
2996
|
+
get(obj, field) {
|
2997
|
+
const val = obj[field];
|
2998
|
+
if (typeof val !== 'function')
|
2999
|
+
return val;
|
3000
|
+
let fiber;
|
3001
|
+
const temp = $mol_wire_task.getter(val);
|
3002
|
+
return function $mol_wire_async(...args) {
|
3003
|
+
fiber?.destructor();
|
3004
|
+
fiber = temp(obj, args);
|
3005
|
+
return fiber.async();
|
3006
|
+
};
|
3007
|
+
},
|
3008
|
+
apply(obj, self, args) {
|
3009
|
+
fiber?.destructor();
|
3010
|
+
fiber = temp(self, args);
|
3011
|
+
return fiber.async();
|
3012
|
+
},
|
3013
|
+
});
|
3014
|
+
}
|
3015
|
+
$.$mol_wire_async = $mol_wire_async;
|
3016
|
+
})($ || ($ = {}));
|
3017
|
+
|
3018
|
+
;
|
3019
|
+
"use strict";
|
3020
|
+
var $;
|
3021
|
+
(function ($_1) {
|
3065
3022
|
$mol_test({
|
3066
|
-
'
|
3067
|
-
class
|
3068
|
-
|
3069
|
-
return
|
3023
|
+
'test types'($) {
|
3024
|
+
class A {
|
3025
|
+
static a() {
|
3026
|
+
return '';
|
3027
|
+
}
|
3028
|
+
static b() {
|
3029
|
+
return $mol_wire_async(this).a();
|
3030
|
+
}
|
3031
|
+
}
|
3032
|
+
},
|
3033
|
+
async 'Latest method calls wins'($) {
|
3034
|
+
class NameLogger extends $mol_object2 {
|
3035
|
+
static $ = $;
|
3036
|
+
static first = [];
|
3037
|
+
static last = [];
|
3038
|
+
static send(next) {
|
3039
|
+
$mol_wire_sync(this.first).push(next);
|
3040
|
+
$$.$mol_wait_timeout(0);
|
3041
|
+
this.last.push(next);
|
3070
3042
|
}
|
3071
3043
|
}
|
3072
|
-
|
3073
|
-
|
3074
|
-
|
3075
|
-
|
3044
|
+
const name = $mol_wire_async(NameLogger).send;
|
3045
|
+
name('john');
|
3046
|
+
const promise = name('jin');
|
3047
|
+
$.$mol_after_mock_warp();
|
3048
|
+
await promise;
|
3049
|
+
$mol_assert_equal(NameLogger.first, ['john', 'jin']);
|
3050
|
+
$mol_assert_equal(NameLogger.last, ['jin']);
|
3051
|
+
},
|
3052
|
+
async 'Latest function calls wins'($) {
|
3053
|
+
const first = [];
|
3054
|
+
const last = [];
|
3055
|
+
function send_name(next) {
|
3056
|
+
$mol_wire_sync(first).push(next);
|
3057
|
+
$$.$mol_wait_timeout(0);
|
3058
|
+
last.push(next);
|
3059
|
+
}
|
3060
|
+
const name = $mol_wire_async(send_name);
|
3061
|
+
name('john');
|
3062
|
+
const promise = name('jin');
|
3063
|
+
$.$mol_after_mock_warp();
|
3064
|
+
await promise;
|
3065
|
+
$mol_assert_equal(first, ['john', 'jin']);
|
3066
|
+
$mol_assert_equal(last, ['jin']);
|
3076
3067
|
},
|
3077
3068
|
});
|
3078
3069
|
})($ || ($ = {}));
|
@@ -3082,56 +3073,51 @@ var $;
|
|
3082
3073
|
var $;
|
3083
3074
|
(function ($_1) {
|
3084
3075
|
$mol_test({
|
3085
|
-
'
|
3086
|
-
|
3087
|
-
|
3088
|
-
|
3089
|
-
|
3090
|
-
|
3091
|
-
|
3092
|
-
|
3093
|
-
pub2.promote();
|
3094
|
-
}
|
3095
|
-
finally {
|
3096
|
-
sub.track_cut();
|
3097
|
-
sub.track_off(bu1);
|
3098
|
-
}
|
3099
|
-
pub1.emit();
|
3100
|
-
pub2.emit();
|
3101
|
-
$mol_assert_like(sub.pub_list, [pub1, pub2, pub2]);
|
3102
|
-
const bu2 = sub.track_on();
|
3103
|
-
try {
|
3104
|
-
pub1.promote();
|
3105
|
-
pub1.promote();
|
3106
|
-
pub2.promote();
|
3107
|
-
}
|
3108
|
-
finally {
|
3109
|
-
sub.track_cut();
|
3110
|
-
sub.track_off(bu2);
|
3076
|
+
'test types'($) {
|
3077
|
+
class A {
|
3078
|
+
static a() {
|
3079
|
+
return Promise.resolve('');
|
3080
|
+
}
|
3081
|
+
static b() {
|
3082
|
+
return $mol_wire_sync(this).a();
|
3083
|
+
}
|
3111
3084
|
}
|
3112
|
-
pub1.emit();
|
3113
|
-
pub2.emit();
|
3114
|
-
$mol_assert_like(sub.pub_list, [pub1, pub1, pub2]);
|
3115
3085
|
},
|
3116
|
-
'
|
3117
|
-
|
3118
|
-
|
3119
|
-
|
3120
|
-
|
3121
|
-
const bu2 = sub2.track_on();
|
3122
|
-
try {
|
3123
|
-
$mol_assert_fail(() => sub1.promote(), 'Circular subscription');
|
3124
|
-
}
|
3125
|
-
finally {
|
3126
|
-
sub2.track_cut();
|
3127
|
-
sub2.track_off(bu2);
|
3086
|
+
async 'test method from host'($) {
|
3087
|
+
let count = 0;
|
3088
|
+
class A {
|
3089
|
+
static a() {
|
3090
|
+
return $mol_wire_sync(this).b();
|
3128
3091
|
}
|
3092
|
+
static b() { return Promise.resolve(++count); }
|
3129
3093
|
}
|
3130
|
-
|
3131
|
-
|
3132
|
-
|
3094
|
+
$mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
|
3095
|
+
},
|
3096
|
+
async 'test function'($) {
|
3097
|
+
let count = 0;
|
3098
|
+
class A {
|
3099
|
+
static a() {
|
3100
|
+
return $mol_wire_sync(this.b)();
|
3101
|
+
}
|
3102
|
+
static b() { return Promise.resolve(++count); }
|
3133
3103
|
}
|
3104
|
+
$mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
|
3134
3105
|
},
|
3106
|
+
async 'test construct itself'($) {
|
3107
|
+
class A {
|
3108
|
+
static instances = [];
|
3109
|
+
static a() {
|
3110
|
+
const a = new ($mol_wire_sync(A))();
|
3111
|
+
this.instances.push(a);
|
3112
|
+
$mol_wire_sync(this).b();
|
3113
|
+
}
|
3114
|
+
static b() { return Promise.resolve(); }
|
3115
|
+
}
|
3116
|
+
await $mol_wire_async(A).a();
|
3117
|
+
$mol_assert_equal(A.instances.length, 2);
|
3118
|
+
$mol_assert_equal(A.instances[0] instanceof A);
|
3119
|
+
$mol_assert_equal(A.instances[0], A.instances[1]);
|
3120
|
+
}
|
3135
3121
|
});
|
3136
3122
|
})($ || ($ = {}));
|
3137
3123
|
|
@@ -3139,38 +3125,73 @@ var $;
|
|
3139
3125
|
"use strict";
|
3140
3126
|
var $;
|
3141
3127
|
(function ($) {
|
3142
|
-
|
3143
|
-
|
3144
|
-
|
3145
|
-
|
3146
|
-
|
3128
|
+
function $mol_promise() {
|
3129
|
+
let done;
|
3130
|
+
let fail;
|
3131
|
+
const promise = new Promise((d, f) => {
|
3132
|
+
done = d;
|
3133
|
+
fail = f;
|
3134
|
+
});
|
3135
|
+
return Object.assign(promise, {
|
3136
|
+
done,
|
3137
|
+
fail,
|
3138
|
+
});
|
3147
3139
|
}
|
3148
|
-
$.$
|
3149
|
-
|
3140
|
+
$.$mol_promise = $mol_promise;
|
3141
|
+
})($ || ($ = {}));
|
3142
|
+
|
3143
|
+
;
|
3144
|
+
"use strict";
|
3145
|
+
var $;
|
3146
|
+
(function ($) {
|
3147
|
+
class $mol_after_timeout extends $mol_object2 {
|
3148
|
+
delay;
|
3150
3149
|
task;
|
3151
|
-
promise = Promise.resolve();
|
3152
|
-
cancelled = false;
|
3153
3150
|
id;
|
3154
|
-
constructor(task) {
|
3151
|
+
constructor(delay, task) {
|
3155
3152
|
super();
|
3153
|
+
this.delay = delay;
|
3156
3154
|
this.task = task;
|
3157
|
-
|
3155
|
+
this.id = setTimeout(task, delay);
|
3158
3156
|
}
|
3159
3157
|
destructor() {
|
3160
|
-
|
3161
|
-
if (index >= 0)
|
3162
|
-
$.$mol_after_mock_queue.splice(index, 1);
|
3158
|
+
clearTimeout(this.id);
|
3163
3159
|
}
|
3164
3160
|
}
|
3165
|
-
$.$
|
3166
|
-
|
3161
|
+
$.$mol_after_timeout = $mol_after_timeout;
|
3162
|
+
})($ || ($ = {}));
|
3163
|
+
|
3164
|
+
;
|
3165
|
+
"use strict";
|
3166
|
+
var $;
|
3167
|
+
(function ($_1) {
|
3168
|
+
$mol_test_mocks.push($ => {
|
3169
|
+
$.$mol_after_timeout = $mol_after_mock_timeout;
|
3170
|
+
});
|
3171
|
+
})($ || ($ = {}));
|
3172
|
+
|
3173
|
+
;
|
3174
|
+
"use strict";
|
3175
|
+
var $;
|
3176
|
+
(function ($) {
|
3177
|
+
class $mol_after_work extends $mol_object2 {
|
3167
3178
|
delay;
|
3179
|
+
task;
|
3180
|
+
id;
|
3168
3181
|
constructor(delay, task) {
|
3169
|
-
super(
|
3182
|
+
super();
|
3170
3183
|
this.delay = delay;
|
3184
|
+
this.task = task;
|
3185
|
+
this.id = requestIdleCallback(task, { timeout: delay });
|
3186
|
+
}
|
3187
|
+
destructor() {
|
3188
|
+
cancelIdleCallback(this.id);
|
3171
3189
|
}
|
3172
3190
|
}
|
3173
|
-
$.$
|
3191
|
+
$.$mol_after_work = $mol_after_work;
|
3192
|
+
if (typeof requestIdleCallback !== 'function') {
|
3193
|
+
$.$mol_after_work = $mol_after_timeout;
|
3194
|
+
}
|
3174
3195
|
})($ || ($ = {}));
|
3175
3196
|
|
3176
3197
|
;
|
@@ -3178,7 +3199,7 @@ var $;
|
|
3178
3199
|
var $;
|
3179
3200
|
(function ($_1) {
|
3180
3201
|
$mol_test_mocks.push($ => {
|
3181
|
-
$.$
|
3202
|
+
$.$mol_after_work = $mol_after_mock_timeout;
|
3182
3203
|
});
|
3183
3204
|
})($ || ($ = {}));
|
3184
3205
|
|
@@ -3186,81 +3207,113 @@ var $;
|
|
3186
3207
|
"use strict";
|
3187
3208
|
var $;
|
3188
3209
|
(function ($) {
|
3210
|
+
function $mol_wait_rest_async() {
|
3211
|
+
return new Promise(done => {
|
3212
|
+
new this.$mol_after_work(16, () => done(null));
|
3213
|
+
});
|
3214
|
+
}
|
3215
|
+
$.$mol_wait_rest_async = $mol_wait_rest_async;
|
3216
|
+
function $mol_wait_rest() {
|
3217
|
+
return this.$mol_wire_sync(this).$mol_wait_rest_async();
|
3218
|
+
}
|
3219
|
+
$.$mol_wait_rest = $mol_wait_rest;
|
3220
|
+
})($ || ($ = {}));
|
3221
|
+
|
3222
|
+
;
|
3223
|
+
"use strict";
|
3224
|
+
var $;
|
3225
|
+
(function ($_1) {
|
3226
|
+
var $$;
|
3227
|
+
(function ($$) {
|
3228
|
+
$mol_test_mocks.push($ => {
|
3229
|
+
$.$mol_wait_timeout = function $mol_wait_timeout_mock(timeout) { };
|
3230
|
+
$.$mol_wait_timeout_async = async function $mol_wait_timeout_async_mock(timeout) { };
|
3231
|
+
});
|
3232
|
+
})($$ = $_1.$$ || ($_1.$$ = {}));
|
3233
|
+
})($ || ($ = {}));
|
3234
|
+
|
3235
|
+
;
|
3236
|
+
"use strict";
|
3237
|
+
var $;
|
3238
|
+
(function ($) {
|
3239
|
+
function $mol_wait_timeout_async(timeout) {
|
3240
|
+
const promise = $mol_promise();
|
3241
|
+
const task = new this.$mol_after_timeout(timeout, () => promise.done());
|
3242
|
+
return Object.assign(promise, {
|
3243
|
+
destructor: () => task.destructor()
|
3244
|
+
});
|
3245
|
+
}
|
3246
|
+
$.$mol_wait_timeout_async = $mol_wait_timeout_async;
|
3247
|
+
function $mol_wait_timeout(timeout) {
|
3248
|
+
return this.$mol_wire_sync(this).$mol_wait_timeout_async(timeout);
|
3249
|
+
}
|
3250
|
+
$.$mol_wait_timeout = $mol_wait_timeout;
|
3251
|
+
})($ || ($ = {}));
|
3252
|
+
|
3253
|
+
;
|
3254
|
+
"use strict";
|
3255
|
+
var $;
|
3256
|
+
(function ($_1) {
|
3257
|
+
var $$;
|
3258
|
+
(function ($$) {
|
3259
|
+
$mol_test_mocks.push($ => {
|
3260
|
+
$.$mol_wait_rest = function $mol_wait_rest_mock() { };
|
3261
|
+
$.$mol_wait_rest_async = async function $mol_wait_rest_async_mock() { };
|
3262
|
+
});
|
3263
|
+
})($$ = $_1.$$ || ($_1.$$ = {}));
|
3264
|
+
})($ || ($ = {}));
|
3265
|
+
|
3266
|
+
;
|
3267
|
+
"use strict";
|
3268
|
+
var $;
|
3269
|
+
(function ($_1) {
|
3189
3270
|
$mol_test({
|
3190
|
-
'
|
3191
|
-
|
3192
|
-
|
3193
|
-
|
3194
|
-
|
3195
|
-
|
3196
|
-
|
3197
|
-
|
3198
|
-
|
3199
|
-
|
3200
|
-
|
3201
|
-
|
3202
|
-
class SyncAsync extends $mol_object2 {
|
3203
|
-
static async val(a) {
|
3204
|
-
return a;
|
3205
|
-
}
|
3206
|
-
static sum(a, b) {
|
3207
|
-
const syn = $mol_wire_sync(this);
|
3208
|
-
return syn.val(a) + syn.val(b);
|
3209
|
-
}
|
3210
|
-
static async calc(a, b) {
|
3211
|
-
return 5 + await $mol_wire_async(this).sum(a, b);
|
3212
|
-
}
|
3271
|
+
async 'exec timeout auto kill child process'($) {
|
3272
|
+
let close_mock = () => { };
|
3273
|
+
const error_message = 'Run error, timeout';
|
3274
|
+
function mol_run_spawn_sync_mock() {
|
3275
|
+
return {
|
3276
|
+
output: [],
|
3277
|
+
stdout: error_message,
|
3278
|
+
stderr: '',
|
3279
|
+
status: 0,
|
3280
|
+
signal: null,
|
3281
|
+
pid: 123,
|
3282
|
+
};
|
3213
3283
|
}
|
3214
|
-
|
3215
|
-
|
3216
|
-
|
3217
|
-
|
3218
|
-
|
3219
|
-
|
3220
|
-
|
3221
|
-
|
3222
|
-
}
|
3223
|
-
static log_unidemp() {
|
3224
|
-
this.logs_unidemp += 1;
|
3225
|
-
}
|
3226
|
-
static async val(a) {
|
3227
|
-
return a;
|
3228
|
-
}
|
3229
|
-
static sum(a, b) {
|
3230
|
-
this.log_idemp();
|
3231
|
-
this.log_unidemp();
|
3232
|
-
const syn = $mol_wire_sync(this);
|
3233
|
-
return syn.val(a) + syn.val(b);
|
3234
|
-
}
|
3235
|
-
static async calc(a, b) {
|
3236
|
-
return 5 + await $mol_wire_async(this).sum(a, b);
|
3237
|
-
}
|
3284
|
+
function mol_run_spawn_mock() {
|
3285
|
+
return {
|
3286
|
+
on(name, cb) {
|
3287
|
+
if (name === 'exit')
|
3288
|
+
close_mock = cb;
|
3289
|
+
},
|
3290
|
+
kill() { close_mock(); }
|
3291
|
+
};
|
3238
3292
|
}
|
3239
|
-
|
3240
|
-
$
|
3241
|
-
|
3242
|
-
|
3243
|
-
$
|
3244
|
-
|
3245
|
-
|
3246
|
-
|
3247
|
-
class Handle extends $mol_object2 {
|
3248
|
-
static async sum(a, b) {
|
3249
|
-
$mol_fail(new Error('test error ' + (a + b)));
|
3250
|
-
}
|
3251
|
-
static check() {
|
3252
|
-
try {
|
3253
|
-
return $mol_wire_sync(Handle).sum(1, 2);
|
3254
|
-
}
|
3255
|
-
catch (error) {
|
3256
|
-
if ($mol_promise_like(error))
|
3257
|
-
$mol_fail_hidden(error);
|
3258
|
-
$mol_assert_equal(error.message, 'test error 3');
|
3259
|
-
}
|
3293
|
+
const context_mock = $.$mol_ambient({
|
3294
|
+
$mol_run_spawn_sync: mol_run_spawn_sync_mock,
|
3295
|
+
$mol_run_spawn: mol_run_spawn_mock
|
3296
|
+
});
|
3297
|
+
class $mol_run_mock extends $mol_run {
|
3298
|
+
static get $() { return context_mock; }
|
3299
|
+
static async_enabled() {
|
3300
|
+
return true;
|
3260
3301
|
}
|
3261
3302
|
}
|
3262
|
-
|
3263
|
-
|
3303
|
+
let message = '';
|
3304
|
+
try {
|
3305
|
+
const res = await $mol_wire_async($mol_run_mock).spawn({
|
3306
|
+
command: 'sleep 10',
|
3307
|
+
dir: '.',
|
3308
|
+
timeout: 10,
|
3309
|
+
env: { 'MOL_RUN_ASYNC': '1' }
|
3310
|
+
});
|
3311
|
+
}
|
3312
|
+
catch (e) {
|
3313
|
+
message = e.message;
|
3314
|
+
}
|
3315
|
+
$mol_assert_equal(message, error_message);
|
3316
|
+
}
|
3264
3317
|
});
|
3265
3318
|
})($ || ($ = {}));
|
3266
3319
|
|
@@ -3974,179 +4027,17 @@ var $;
|
|
3974
4027
|
this.rand = rand;
|
3975
4028
|
}
|
3976
4029
|
[Symbol.toPrimitive](mode) {
|
3977
|
-
return this.name;
|
3978
|
-
}
|
3979
|
-
}
|
3980
|
-
$mol_assert_ok($mol_compare_deep(new User('Jin'), new User('Jin')));
|
3981
|
-
$mol_assert_not($mol_compare_deep(new User('Jin'), new User('John')));
|
3982
|
-
},
|
3983
|
-
'Iterable'() {
|
3984
|
-
$mol_assert_ok($mol_compare_deep(new URLSearchParams({ foo: 'bar' }), new URLSearchParams({ foo: 'bar' })));
|
3985
|
-
$mol_assert_not($mol_compare_deep(new URLSearchParams({ foo: 'xxx' }), new URLSearchParams({ foo: 'yyy' })));
|
3986
|
-
$mol_assert_not($mol_compare_deep(new URLSearchParams({ foo: 'xxx', bar: 'yyy' }), new URLSearchParams({ bar: 'yyy', foo: 'xxx' })));
|
3987
|
-
},
|
3988
|
-
});
|
3989
|
-
})($ || ($ = {}));
|
3990
|
-
|
3991
|
-
;
|
3992
|
-
"use strict";
|
3993
|
-
var $;
|
3994
|
-
(function ($) {
|
3995
|
-
function $mol_wire_async(obj) {
|
3996
|
-
let fiber;
|
3997
|
-
const temp = $mol_wire_task.getter(obj);
|
3998
|
-
return new Proxy(obj, {
|
3999
|
-
get(obj, field) {
|
4000
|
-
const val = obj[field];
|
4001
|
-
if (typeof val !== 'function')
|
4002
|
-
return val;
|
4003
|
-
let fiber;
|
4004
|
-
const temp = $mol_wire_task.getter(val);
|
4005
|
-
return function $mol_wire_async(...args) {
|
4006
|
-
fiber?.destructor();
|
4007
|
-
fiber = temp(obj, args);
|
4008
|
-
return fiber.async();
|
4009
|
-
};
|
4010
|
-
},
|
4011
|
-
apply(obj, self, args) {
|
4012
|
-
fiber?.destructor();
|
4013
|
-
fiber = temp(self, args);
|
4014
|
-
return fiber.async();
|
4015
|
-
},
|
4016
|
-
});
|
4017
|
-
}
|
4018
|
-
$.$mol_wire_async = $mol_wire_async;
|
4019
|
-
})($ || ($ = {}));
|
4020
|
-
|
4021
|
-
;
|
4022
|
-
"use strict";
|
4023
|
-
var $;
|
4024
|
-
(function ($_1) {
|
4025
|
-
$mol_test({
|
4026
|
-
'test types'($) {
|
4027
|
-
class A {
|
4028
|
-
static a() {
|
4029
|
-
return '';
|
4030
|
-
}
|
4031
|
-
static b() {
|
4032
|
-
return $mol_wire_async(this).a();
|
4033
|
-
}
|
4034
|
-
}
|
4035
|
-
},
|
4036
|
-
async 'Latest method calls wins'($) {
|
4037
|
-
class NameLogger extends $mol_object2 {
|
4038
|
-
static $ = $;
|
4039
|
-
static first = [];
|
4040
|
-
static last = [];
|
4041
|
-
static send(next) {
|
4042
|
-
$mol_wire_sync(this.first).push(next);
|
4043
|
-
$$.$mol_wait_timeout(0);
|
4044
|
-
this.last.push(next);
|
4045
|
-
}
|
4046
|
-
}
|
4047
|
-
const name = $mol_wire_async(NameLogger).send;
|
4048
|
-
name('john');
|
4049
|
-
const promise = name('jin');
|
4050
|
-
$.$mol_after_mock_warp();
|
4051
|
-
await promise;
|
4052
|
-
$mol_assert_equal(NameLogger.first, ['john', 'jin']);
|
4053
|
-
$mol_assert_equal(NameLogger.last, ['jin']);
|
4054
|
-
},
|
4055
|
-
async 'Latest function calls wins'($) {
|
4056
|
-
const first = [];
|
4057
|
-
const last = [];
|
4058
|
-
function send_name(next) {
|
4059
|
-
$mol_wire_sync(first).push(next);
|
4060
|
-
$$.$mol_wait_timeout(0);
|
4061
|
-
last.push(next);
|
4062
|
-
}
|
4063
|
-
const name = $mol_wire_async(send_name);
|
4064
|
-
name('john');
|
4065
|
-
const promise = name('jin');
|
4066
|
-
$.$mol_after_mock_warp();
|
4067
|
-
await promise;
|
4068
|
-
$mol_assert_equal(first, ['john', 'jin']);
|
4069
|
-
$mol_assert_equal(last, ['jin']);
|
4070
|
-
},
|
4071
|
-
});
|
4072
|
-
})($ || ($ = {}));
|
4073
|
-
|
4074
|
-
;
|
4075
|
-
"use strict";
|
4076
|
-
var $;
|
4077
|
-
(function ($) {
|
4078
|
-
function $mol_wire_method(host, field, descr) {
|
4079
|
-
if (!descr)
|
4080
|
-
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
4081
|
-
const orig = descr?.value ?? host[field];
|
4082
|
-
const sup = Reflect.getPrototypeOf(host);
|
4083
|
-
if (typeof sup[field] === 'function') {
|
4084
|
-
Object.defineProperty(orig, 'name', { value: sup[field].name });
|
4085
|
-
}
|
4086
|
-
const temp = $mol_wire_task.getter(orig);
|
4087
|
-
const value = function (...args) {
|
4088
|
-
const fiber = temp(this ?? null, args);
|
4089
|
-
return fiber.sync();
|
4090
|
-
};
|
4091
|
-
Object.defineProperty(value, 'name', { value: orig.name + ' ' });
|
4092
|
-
Object.assign(value, { orig });
|
4093
|
-
const descr2 = { ...descr, value };
|
4094
|
-
Reflect.defineProperty(host, field, descr2);
|
4095
|
-
return descr2;
|
4096
|
-
}
|
4097
|
-
$.$mol_wire_method = $mol_wire_method;
|
4098
|
-
})($ || ($ = {}));
|
4099
|
-
|
4100
|
-
;
|
4101
|
-
"use strict";
|
4102
|
-
var $;
|
4103
|
-
(function ($_1) {
|
4104
|
-
$mol_test({
|
4105
|
-
'test types'($) {
|
4106
|
-
class A {
|
4107
|
-
static a() {
|
4108
|
-
return Promise.resolve('');
|
4109
|
-
}
|
4110
|
-
static b() {
|
4111
|
-
return $mol_wire_sync(this).a();
|
4112
|
-
}
|
4113
|
-
}
|
4114
|
-
},
|
4115
|
-
async 'test method from host'($) {
|
4116
|
-
let count = 0;
|
4117
|
-
class A {
|
4118
|
-
static a() {
|
4119
|
-
return $mol_wire_sync(this).b();
|
4120
|
-
}
|
4121
|
-
static b() { return Promise.resolve(++count); }
|
4122
|
-
}
|
4123
|
-
$mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
|
4124
|
-
},
|
4125
|
-
async 'test function'($) {
|
4126
|
-
let count = 0;
|
4127
|
-
class A {
|
4128
|
-
static a() {
|
4129
|
-
return $mol_wire_sync(this.b)();
|
4130
|
-
}
|
4131
|
-
static b() { return Promise.resolve(++count); }
|
4132
|
-
}
|
4133
|
-
$mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
|
4134
|
-
},
|
4135
|
-
async 'test construct itself'($) {
|
4136
|
-
class A {
|
4137
|
-
static instances = [];
|
4138
|
-
static a() {
|
4139
|
-
const a = new ($mol_wire_sync(A))();
|
4140
|
-
this.instances.push(a);
|
4141
|
-
$mol_wire_sync(this).b();
|
4142
|
-
}
|
4143
|
-
static b() { return Promise.resolve(); }
|
4144
|
-
}
|
4145
|
-
await $mol_wire_async(A).a();
|
4146
|
-
$mol_assert_equal(A.instances.length, 2);
|
4147
|
-
$mol_assert_equal(A.instances[0] instanceof A);
|
4148
|
-
$mol_assert_equal(A.instances[0], A.instances[1]);
|
4149
|
-
}
|
4030
|
+
return this.name;
|
4031
|
+
}
|
4032
|
+
}
|
4033
|
+
$mol_assert_ok($mol_compare_deep(new User('Jin'), new User('Jin')));
|
4034
|
+
$mol_assert_not($mol_compare_deep(new User('Jin'), new User('John')));
|
4035
|
+
},
|
4036
|
+
'Iterable'() {
|
4037
|
+
$mol_assert_ok($mol_compare_deep(new URLSearchParams({ foo: 'bar' }), new URLSearchParams({ foo: 'bar' })));
|
4038
|
+
$mol_assert_not($mol_compare_deep(new URLSearchParams({ foo: 'xxx' }), new URLSearchParams({ foo: 'yyy' })));
|
4039
|
+
$mol_assert_not($mol_compare_deep(new URLSearchParams({ foo: 'xxx', bar: 'yyy' }), new URLSearchParams({ bar: 'yyy', foo: 'xxx' })));
|
4040
|
+
},
|
4150
4041
|
});
|
4151
4042
|
})($ || ($ = {}));
|
4152
4043
|
|
@@ -4154,81 +4045,122 @@ var $;
|
|
4154
4045
|
"use strict";
|
4155
4046
|
var $;
|
4156
4047
|
(function ($) {
|
4157
|
-
function $
|
4158
|
-
|
4159
|
-
|
4160
|
-
|
4161
|
-
done = d;
|
4162
|
-
fail = f;
|
4163
|
-
});
|
4164
|
-
return Object.assign(promise, {
|
4165
|
-
done,
|
4166
|
-
fail,
|
4167
|
-
});
|
4048
|
+
function $mol_assert_ok(value) {
|
4049
|
+
if (value)
|
4050
|
+
return;
|
4051
|
+
$mol_fail(new Error(`${value} ≠ true`));
|
4168
4052
|
}
|
4169
|
-
$.$
|
4170
|
-
|
4171
|
-
|
4172
|
-
;
|
4173
|
-
|
4174
|
-
|
4175
|
-
|
4176
|
-
|
4177
|
-
|
4178
|
-
|
4179
|
-
|
4180
|
-
|
4181
|
-
super();
|
4182
|
-
this.delay = delay;
|
4183
|
-
this.task = task;
|
4184
|
-
this.id = setTimeout(task, delay);
|
4053
|
+
$.$mol_assert_ok = $mol_assert_ok;
|
4054
|
+
function $mol_assert_not(value) {
|
4055
|
+
if (!value)
|
4056
|
+
return;
|
4057
|
+
$mol_fail(new Error(`${value} ≠ false`));
|
4058
|
+
}
|
4059
|
+
$.$mol_assert_not = $mol_assert_not;
|
4060
|
+
function $mol_assert_fail(handler, ErrorRight) {
|
4061
|
+
const fail = $.$mol_fail;
|
4062
|
+
try {
|
4063
|
+
$.$mol_fail = $.$mol_fail_hidden;
|
4064
|
+
handler();
|
4185
4065
|
}
|
4186
|
-
|
4187
|
-
|
4066
|
+
catch (error) {
|
4067
|
+
$.$mol_fail = fail;
|
4068
|
+
if (typeof ErrorRight === 'string') {
|
4069
|
+
$mol_assert_equal(error.message, ErrorRight);
|
4070
|
+
}
|
4071
|
+
else {
|
4072
|
+
$mol_assert_equal(error instanceof ErrorRight, true);
|
4073
|
+
}
|
4074
|
+
return error;
|
4188
4075
|
}
|
4189
|
-
|
4190
|
-
|
4191
|
-
})($ || ($ = {}));
|
4192
|
-
|
4193
|
-
;
|
4194
|
-
"use strict";
|
4195
|
-
var $;
|
4196
|
-
(function ($_1) {
|
4197
|
-
$mol_test_mocks.push($ => {
|
4198
|
-
$.$mol_after_timeout = $mol_after_mock_timeout;
|
4199
|
-
});
|
4200
|
-
})($ || ($ = {}));
|
4201
|
-
|
4202
|
-
;
|
4203
|
-
"use strict";
|
4204
|
-
var $;
|
4205
|
-
(function ($) {
|
4206
|
-
class $mol_after_work extends $mol_object2 {
|
4207
|
-
delay;
|
4208
|
-
task;
|
4209
|
-
id;
|
4210
|
-
constructor(delay, task) {
|
4211
|
-
super();
|
4212
|
-
this.delay = delay;
|
4213
|
-
this.task = task;
|
4214
|
-
this.id = requestIdleCallback(task, { timeout: delay });
|
4076
|
+
finally {
|
4077
|
+
$.$mol_fail = fail;
|
4215
4078
|
}
|
4216
|
-
|
4217
|
-
|
4079
|
+
$mol_fail(new Error('Not failed'));
|
4080
|
+
}
|
4081
|
+
$.$mol_assert_fail = $mol_assert_fail;
|
4082
|
+
function $mol_assert_like(...args) {
|
4083
|
+
$mol_assert_equal(...args);
|
4084
|
+
}
|
4085
|
+
$.$mol_assert_like = $mol_assert_like;
|
4086
|
+
function $mol_assert_unique(...args) {
|
4087
|
+
for (let i = 0; i < args.length; ++i) {
|
4088
|
+
for (let j = 0; j < args.length; ++j) {
|
4089
|
+
if (i === j)
|
4090
|
+
continue;
|
4091
|
+
if (!$mol_compare_deep(args[i], args[j]))
|
4092
|
+
continue;
|
4093
|
+
$mol_fail(new Error(`args[${i}] = args[${j}] = ${print(args[i])}`));
|
4094
|
+
}
|
4218
4095
|
}
|
4219
4096
|
}
|
4220
|
-
$.$
|
4221
|
-
|
4222
|
-
|
4097
|
+
$.$mol_assert_unique = $mol_assert_unique;
|
4098
|
+
function $mol_assert_equal(...args) {
|
4099
|
+
for (let i = 1; i < args.length; ++i) {
|
4100
|
+
if ($mol_compare_deep(args[0], args[i]))
|
4101
|
+
continue;
|
4102
|
+
if (args[0] instanceof $mol_dom_context.Element && args[i] instanceof $mol_dom_context.Element && args[0].outerHTML === args[i].outerHTML)
|
4103
|
+
continue;
|
4104
|
+
return $mol_fail(new Error(`args[0] ≠ args[${i}]\n${print(args[0])}\n---\n${print(args[i])}`));
|
4105
|
+
}
|
4223
4106
|
}
|
4107
|
+
$.$mol_assert_equal = $mol_assert_equal;
|
4108
|
+
const print = (val) => {
|
4109
|
+
if (!val)
|
4110
|
+
return val;
|
4111
|
+
if (typeof val === 'bigint')
|
4112
|
+
return String(val) + 'n';
|
4113
|
+
if (typeof val === 'symbol')
|
4114
|
+
return `Symbol(${val.description})`;
|
4115
|
+
if (typeof val !== 'object')
|
4116
|
+
return val;
|
4117
|
+
if ('outerHTML' in val)
|
4118
|
+
return val.outerHTML;
|
4119
|
+
try {
|
4120
|
+
return JSON.stringify(val, (k, v) => typeof v === 'bigint' ? String(v) : v, '\t');
|
4121
|
+
}
|
4122
|
+
catch (error) {
|
4123
|
+
console.error(error);
|
4124
|
+
return val;
|
4125
|
+
}
|
4126
|
+
};
|
4224
4127
|
})($ || ($ = {}));
|
4225
4128
|
|
4226
4129
|
;
|
4227
4130
|
"use strict";
|
4228
4131
|
var $;
|
4229
|
-
(function ($
|
4230
|
-
$
|
4231
|
-
|
4132
|
+
(function ($) {
|
4133
|
+
$mol_test({
|
4134
|
+
'must be false'() {
|
4135
|
+
$mol_assert_not(0);
|
4136
|
+
},
|
4137
|
+
'must be true'() {
|
4138
|
+
$mol_assert_ok(1);
|
4139
|
+
},
|
4140
|
+
'two must be equal'() {
|
4141
|
+
$mol_assert_equal(2, 2);
|
4142
|
+
},
|
4143
|
+
'three must be equal'() {
|
4144
|
+
$mol_assert_equal(2, 2, 2);
|
4145
|
+
},
|
4146
|
+
'two must be unique'() {
|
4147
|
+
$mol_assert_unique([2], [3]);
|
4148
|
+
},
|
4149
|
+
'three must be unique'() {
|
4150
|
+
$mol_assert_unique([1], [2], [3]);
|
4151
|
+
},
|
4152
|
+
'two must be alike'() {
|
4153
|
+
$mol_assert_like([3], [3]);
|
4154
|
+
},
|
4155
|
+
'three must be alike'() {
|
4156
|
+
$mol_assert_like([3], [3], [3]);
|
4157
|
+
},
|
4158
|
+
'two object must be alike'() {
|
4159
|
+
$mol_assert_like({ a: 1 }, { a: 1 });
|
4160
|
+
},
|
4161
|
+
'three object must be alike'() {
|
4162
|
+
$mol_assert_like({ a: 1 }, { a: 1 }, { a: 1 });
|
4163
|
+
},
|
4232
4164
|
});
|
4233
4165
|
})($ || ($ = {}));
|
4234
4166
|
|
@@ -4236,60 +4168,158 @@ var $;
|
|
4236
4168
|
"use strict";
|
4237
4169
|
var $;
|
4238
4170
|
(function ($) {
|
4239
|
-
|
4240
|
-
|
4241
|
-
|
4242
|
-
|
4243
|
-
|
4244
|
-
|
4245
|
-
|
4246
|
-
|
4247
|
-
|
4248
|
-
|
4249
|
-
|
4250
|
-
|
4251
|
-
;
|
4252
|
-
|
4253
|
-
|
4254
|
-
(
|
4255
|
-
|
4256
|
-
|
4257
|
-
|
4258
|
-
|
4259
|
-
|
4260
|
-
|
4261
|
-
|
4171
|
+
$mol_test({
|
4172
|
+
'get'() {
|
4173
|
+
const proxy = $mol_delegate({}, () => ({ foo: 777 }));
|
4174
|
+
$mol_assert_equal(proxy.foo, 777);
|
4175
|
+
},
|
4176
|
+
'has'() {
|
4177
|
+
const proxy = $mol_delegate({}, () => ({ foo: 777 }));
|
4178
|
+
$mol_assert_equal('foo' in proxy, true);
|
4179
|
+
},
|
4180
|
+
'set'() {
|
4181
|
+
const target = { foo: 777 };
|
4182
|
+
const proxy = $mol_delegate({}, () => target);
|
4183
|
+
proxy.foo = 123;
|
4184
|
+
$mol_assert_equal(target.foo, 123);
|
4185
|
+
},
|
4186
|
+
'getOwnPropertyDescriptor'() {
|
4187
|
+
const proxy = $mol_delegate({}, () => ({ foo: 777 }));
|
4188
|
+
$mol_assert_like(Object.getOwnPropertyDescriptor(proxy, 'foo'), {
|
4189
|
+
value: 777,
|
4190
|
+
writable: true,
|
4191
|
+
enumerable: true,
|
4192
|
+
configurable: true,
|
4193
|
+
});
|
4194
|
+
},
|
4195
|
+
'ownKeys'() {
|
4196
|
+
const proxy = $mol_delegate({}, () => ({ foo: 777, [Symbol.toStringTag]: 'bar' }));
|
4197
|
+
$mol_assert_like(Reflect.ownKeys(proxy), ['foo', Symbol.toStringTag]);
|
4198
|
+
},
|
4199
|
+
'getPrototypeOf'() {
|
4200
|
+
class Foo {
|
4201
|
+
}
|
4202
|
+
const proxy = $mol_delegate({}, () => new Foo);
|
4203
|
+
$mol_assert_equal(Object.getPrototypeOf(proxy), Foo.prototype);
|
4204
|
+
},
|
4205
|
+
'setPrototypeOf'() {
|
4206
|
+
class Foo {
|
4207
|
+
}
|
4208
|
+
const target = {};
|
4209
|
+
const proxy = $mol_delegate({}, () => target);
|
4210
|
+
Object.setPrototypeOf(proxy, Foo.prototype);
|
4211
|
+
$mol_assert_equal(Object.getPrototypeOf(target), Foo.prototype);
|
4212
|
+
},
|
4213
|
+
'instanceof'() {
|
4214
|
+
class Foo {
|
4215
|
+
}
|
4216
|
+
const proxy = $mol_delegate({}, () => new Foo);
|
4217
|
+
$mol_assert_ok(proxy instanceof Foo);
|
4218
|
+
$mol_assert_ok(proxy instanceof $mol_delegate);
|
4219
|
+
},
|
4220
|
+
'autobind'() {
|
4221
|
+
class Foo {
|
4222
|
+
}
|
4223
|
+
const proxy = $mol_delegate({}, () => new Foo);
|
4224
|
+
$mol_assert_ok(proxy instanceof Foo);
|
4225
|
+
$mol_assert_ok(proxy instanceof $mol_delegate);
|
4226
|
+
},
|
4227
|
+
});
|
4262
4228
|
})($ || ($ = {}));
|
4263
4229
|
|
4264
4230
|
;
|
4265
4231
|
"use strict";
|
4266
4232
|
var $;
|
4267
|
-
(function ($) {
|
4268
|
-
|
4269
|
-
|
4270
|
-
|
4271
|
-
|
4272
|
-
|
4273
|
-
|
4274
|
-
|
4275
|
-
|
4276
|
-
|
4277
|
-
|
4278
|
-
|
4279
|
-
|
4233
|
+
(function ($_1) {
|
4234
|
+
$mol_test({
|
4235
|
+
'span for same uri'($) {
|
4236
|
+
const span = new $mol_span('test.ts', '', 1, 3, 4);
|
4237
|
+
const child = span.span(4, 5, 8);
|
4238
|
+
$mol_assert_equal(child.uri, 'test.ts');
|
4239
|
+
$mol_assert_equal(child.row, 4);
|
4240
|
+
$mol_assert_equal(child.col, 5);
|
4241
|
+
$mol_assert_equal(child.length, 8);
|
4242
|
+
},
|
4243
|
+
'span after of given position'($) {
|
4244
|
+
const span = new $mol_span('test.ts', '', 1, 3, 4);
|
4245
|
+
const child = span.after(11);
|
4246
|
+
$mol_assert_equal(child.uri, 'test.ts');
|
4247
|
+
$mol_assert_equal(child.row, 1);
|
4248
|
+
$mol_assert_equal(child.col, 7);
|
4249
|
+
$mol_assert_equal(child.length, 11);
|
4250
|
+
},
|
4251
|
+
'slice span - regular'($) {
|
4252
|
+
const span = new $mol_span('test.ts', '', 1, 3, 5);
|
4253
|
+
const child = span.slice(1, 4);
|
4254
|
+
$mol_assert_equal(child.row, 1);
|
4255
|
+
$mol_assert_equal(child.col, 4);
|
4256
|
+
$mol_assert_equal(child.length, 3);
|
4257
|
+
const child2 = span.slice(2, 2);
|
4258
|
+
$mol_assert_equal(child2.col, 5);
|
4259
|
+
$mol_assert_equal(child2.length, 0);
|
4260
|
+
},
|
4261
|
+
'slice span - negative'($) {
|
4262
|
+
const span = new $mol_span('test.ts', '', 1, 3, 5);
|
4263
|
+
const child = span.slice(-3, -1);
|
4264
|
+
$mol_assert_equal(child.row, 1);
|
4265
|
+
$mol_assert_equal(child.col, 5);
|
4266
|
+
$mol_assert_equal(child.length, 2);
|
4267
|
+
},
|
4268
|
+
'slice span - out of range'($) {
|
4269
|
+
const span = new $mol_span('test.ts', '', 1, 3, 5);
|
4270
|
+
$mol_assert_fail(() => span.slice(-1, 3), `End value '3' can't be less than begin value (test.ts#1:3/5)`);
|
4271
|
+
$mol_assert_fail(() => span.slice(1, 6), `End value '6' out of range (test.ts#1:3/5)`);
|
4272
|
+
$mol_assert_fail(() => span.slice(1, 10), `End value '10' out of range (test.ts#1:3/5)`);
|
4273
|
+
},
|
4274
|
+
'error handling'($) {
|
4275
|
+
const span = new $mol_span('test.ts', '', 1, 3, 4);
|
4276
|
+
const error = span.error('Some error');
|
4277
|
+
$mol_assert_equal(error.message, 'Some error (test.ts#1:3/4)');
|
4278
|
+
}
|
4279
|
+
});
|
4280
4280
|
})($ || ($ = {}));
|
4281
4281
|
|
4282
4282
|
;
|
4283
4283
|
"use strict";
|
4284
4284
|
var $;
|
4285
4285
|
(function ($_1) {
|
4286
|
-
|
4287
|
-
|
4288
|
-
|
4289
|
-
|
4290
|
-
|
4291
|
-
|
4292
|
-
|
4286
|
+
$mol_test({
|
4287
|
+
'inserting'($) {
|
4288
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
|
4289
|
+
.insert($mol_tree2.struct('x'), 'a', 'b', 'c')
|
4290
|
+
.toString(), 'a b x\n');
|
4291
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b\n')
|
4292
|
+
.insert($mol_tree2.struct('x'), 'a', 'b', 'c', 'd')
|
4293
|
+
.toString(), 'a b c x\n');
|
4294
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
|
4295
|
+
.insert($mol_tree2.struct('x'), 0, 0, 0)
|
4296
|
+
.toString(), 'a b x\n');
|
4297
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b\n')
|
4298
|
+
.insert($mol_tree2.struct('x'), 0, 0, 0, 0)
|
4299
|
+
.toString(), 'a b \\\n\tx\n');
|
4300
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
|
4301
|
+
.insert($mol_tree2.struct('x'), null, null, null)
|
4302
|
+
.toString(), 'a b x\n');
|
4303
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b\n')
|
4304
|
+
.insert($mol_tree2.struct('x'), null, null, null, null)
|
4305
|
+
.toString(), 'a b \\\n\tx\n');
|
4306
|
+
},
|
4307
|
+
'deleting'($) {
|
4308
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
|
4309
|
+
.insert(null, 'a', 'b', 'c')
|
4310
|
+
.toString(), 'a b\n');
|
4311
|
+
$mol_assert_equal($.$mol_tree2_from_string('a b c d\n')
|
4312
|
+
.insert(null, 0, 0, 0)
|
4313
|
+
.toString(), 'a b\n');
|
4314
|
+
},
|
4315
|
+
'hack'($) {
|
4316
|
+
const res = $.$mol_tree2_from_string(`foo bar xxx\n`)
|
4317
|
+
.hack({
|
4318
|
+
'bar': (input, belt) => [input.struct('777', input.hack(belt))],
|
4319
|
+
});
|
4320
|
+
$mol_assert_equal(res.map(String), ['foo 777 xxx\n']);
|
4321
|
+
},
|
4322
|
+
});
|
4293
4323
|
})($ || ($ = {}));
|
4294
4324
|
|
4295
4325
|
;
|
@@ -4297,52 +4327,68 @@ var $;
|
|
4297
4327
|
var $;
|
4298
4328
|
(function ($_1) {
|
4299
4329
|
$mol_test({
|
4300
|
-
|
4301
|
-
|
4302
|
-
|
4303
|
-
|
4304
|
-
|
4305
|
-
|
4306
|
-
|
4307
|
-
|
4308
|
-
|
4309
|
-
|
4310
|
-
|
4311
|
-
|
4312
|
-
|
4313
|
-
|
4314
|
-
|
4315
|
-
|
4316
|
-
|
4317
|
-
|
4318
|
-
|
4319
|
-
|
4320
|
-
|
4321
|
-
|
4322
|
-
|
4323
|
-
|
4324
|
-
|
4325
|
-
|
4326
|
-
|
4327
|
-
|
4328
|
-
|
4329
|
-
|
4330
|
+
'tree parsing'($) {
|
4331
|
+
$mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids.length, 2);
|
4332
|
+
$mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids[1].type, "bar");
|
4333
|
+
$mol_assert_equal($.$mol_tree2_from_string("foo\n\n\n").kids.length, 1);
|
4334
|
+
$mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids.length, 2);
|
4335
|
+
$mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids[1].value, "bar");
|
4336
|
+
$mol_assert_equal($.$mol_tree2_from_string("foo bar \\pol\n").kids[0].kids[0].kids[0].value, "pol");
|
4337
|
+
$mol_assert_equal($.$mol_tree2_from_string("foo bar\n\t\\pol\n\t\\men\n").kids[0].kids[0].kids[1].value, "men");
|
4338
|
+
$mol_assert_equal($.$mol_tree2_from_string('foo bar \\text\n').toString(), 'foo bar \\text\n');
|
4339
|
+
},
|
4340
|
+
'Too many tabs'($) {
|
4341
|
+
const tree = `
|
4342
|
+
foo
|
4343
|
+
bar
|
4344
|
+
`;
|
4345
|
+
$mol_assert_fail(() => {
|
4346
|
+
$.$mol_tree2_from_string(tree, 'test');
|
4347
|
+
}, 'Too many tabs\ntest#3:1/6\n!!!!!!\n\t\t\t\t\t\tbar');
|
4348
|
+
},
|
4349
|
+
'Too few tabs'($) {
|
4350
|
+
const tree = `
|
4351
|
+
foo
|
4352
|
+
bar
|
4353
|
+
`;
|
4354
|
+
$mol_assert_fail(() => {
|
4355
|
+
$.$mol_tree2_from_string(tree, 'test');
|
4356
|
+
}, 'Too few tabs\ntest#3:1/4\n!!!!\n\t\t\t\tbar');
|
4357
|
+
},
|
4358
|
+
'Wrong nodes separator at start'($) {
|
4359
|
+
const tree = `foo\n \tbar\n`;
|
4360
|
+
$mol_assert_fail(() => {
|
4361
|
+
$.$mol_tree2_from_string(tree, 'test');
|
4362
|
+
}, 'Wrong nodes separator\ntest#2:1/2\n!!\n \tbar');
|
4363
|
+
},
|
4364
|
+
'Wrong nodes separator in the middle'($) {
|
4365
|
+
const tree = `foo bar\n`;
|
4366
|
+
$mol_assert_fail(() => {
|
4367
|
+
$.$mol_tree2_from_string(tree, 'test');
|
4368
|
+
}, 'Wrong nodes separator\ntest#1:5/1\n !\nfoo bar');
|
4369
|
+
},
|
4370
|
+
'Unexpected EOF, LF required'($) {
|
4371
|
+
const tree = ` foo`;
|
4372
|
+
$mol_assert_fail(() => {
|
4373
|
+
$.$mol_tree2_from_string(tree, 'test');
|
4374
|
+
}, 'Unexpected EOF, LF required\ntest#1:5/1\n !\n foo');
|
4375
|
+
},
|
4376
|
+
'Errors skip and collect'($) {
|
4377
|
+
const tree = `foo bar`;
|
4378
|
+
const errors = [];
|
4379
|
+
const $$ = $.$mol_ambient({
|
4380
|
+
$mol_fail: (error) => {
|
4381
|
+
errors.push(error.message);
|
4382
|
+
return null;
|
4330
4383
|
}
|
4331
|
-
}
|
4332
|
-
|
4333
|
-
|
4334
|
-
|
4335
|
-
|
4336
|
-
|
4337
|
-
|
4338
|
-
|
4339
|
-
});
|
4340
|
-
}
|
4341
|
-
catch (e) {
|
4342
|
-
message = e.message;
|
4343
|
-
}
|
4344
|
-
$mol_assert_equal(message, error_message);
|
4345
|
-
}
|
4384
|
+
});
|
4385
|
+
const res = $$.$mol_tree2_from_string(tree, 'test');
|
4386
|
+
$mol_assert_like(errors, [
|
4387
|
+
'Wrong nodes separator\ntest#1:5/1\n !\nfoo bar',
|
4388
|
+
'Unexpected EOF, LF required\ntest#1:9/1\n !\nfoo bar',
|
4389
|
+
]);
|
4390
|
+
$mol_assert_equal(res.toString(), 'foo bar\n');
|
4391
|
+
},
|
4346
4392
|
});
|
4347
4393
|
})($ || ($ = {}));
|
4348
4394
|
|
@@ -4351,10 +4397,13 @@ var $;
|
|
4351
4397
|
var $;
|
4352
4398
|
(function ($) {
|
4353
4399
|
$mol_test({
|
4354
|
-
'
|
4355
|
-
|
4356
|
-
|
4357
|
-
$
|
4400
|
+
'fromJSON'() {
|
4401
|
+
$mol_assert_equal($mol_tree2_from_json([]).toString(), '/\n');
|
4402
|
+
$mol_assert_equal($mol_tree2_from_json([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
|
4403
|
+
$mol_assert_equal($mol_tree2_from_json([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
|
4404
|
+
$mol_assert_equal($mol_tree2_from_json(new Uint16Array([1, 10, 256])).toString(), '\\\x01\x00\n\\\x00\x00\x01\n');
|
4405
|
+
$mol_assert_equal($mol_tree2_from_json(['', 'foo', 'bar\nbaz']).toString(), '/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n');
|
4406
|
+
$mol_assert_equal($mol_tree2_from_json({ 'foo': false, 'bar\nbaz': 'lol' }).toString(), '*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n');
|
4358
4407
|
},
|
4359
4408
|
});
|
4360
4409
|
})($ || ($ = {}));
|
@@ -4537,51 +4586,83 @@ var $;
|
|
4537
4586
|
var $;
|
4538
4587
|
(function ($) {
|
4539
4588
|
$mol_test({
|
4540
|
-
async '
|
4541
|
-
const secret =
|
4542
|
-
const key =
|
4543
|
-
$mol_assert_equal(key.byteLength, $
|
4589
|
+
async 'Sizes'() {
|
4590
|
+
const secret = $mol_crypto_sacred.make();
|
4591
|
+
const key = secret.asArray();
|
4592
|
+
$mol_assert_equal(key.byteLength, $mol_crypto_sacred.size);
|
4544
4593
|
const data = new Uint8Array([1, 2, 3]);
|
4545
4594
|
const salt = $mol_crypto_salt();
|
4546
4595
|
const closed = await secret.encrypt(data, salt);
|
4547
|
-
$mol_assert_equal(closed.byteLength,
|
4596
|
+
$mol_assert_equal(closed.byteLength, $mol_crypto_sacred.size);
|
4597
|
+
const self_closed = await secret.close(secret, salt);
|
4598
|
+
$mol_assert_equal(self_closed.byteLength, $mol_crypto_sacred.size);
|
4548
4599
|
},
|
4549
|
-
async '
|
4550
|
-
const secret =
|
4600
|
+
async 'Decrypt self encrypted'() {
|
4601
|
+
const secret = $mol_crypto_sacred.make();
|
4551
4602
|
const data = new Uint8Array([1, 2, 3]);
|
4552
4603
|
const salt = $mol_crypto_salt();
|
4553
4604
|
const closed = await secret.encrypt(data, salt);
|
4554
4605
|
const opened = await secret.decrypt(closed, salt);
|
4555
4606
|
$mol_assert_equal(data, opened);
|
4556
4607
|
},
|
4557
|
-
async '
|
4608
|
+
async 'Decrypt encrypted with exported key'() {
|
4558
4609
|
const data = new Uint8Array([1, 2, 3]);
|
4559
4610
|
const salt = $mol_crypto_salt();
|
4560
|
-
const Alice =
|
4611
|
+
const Alice = $mol_crypto_sacred.make();
|
4561
4612
|
const closed = await Alice.encrypt(data, salt);
|
4562
|
-
const Bob =
|
4613
|
+
const Bob = $mol_crypto_sacred.from(Alice.asArray());
|
4563
4614
|
const opened = await Bob.decrypt(closed, salt);
|
4564
4615
|
$mol_assert_equal(data, opened);
|
4565
4616
|
},
|
4566
|
-
|
4567
|
-
|
4568
|
-
|
4569
|
-
|
4570
|
-
|
4571
|
-
|
4617
|
+
});
|
4618
|
+
})($ || ($ = {}));
|
4619
|
+
|
4620
|
+
;
|
4621
|
+
"use strict";
|
4622
|
+
var $;
|
4623
|
+
(function ($) {
|
4624
|
+
$mol_test({
|
4625
|
+
'encode utf8 string'() {
|
4626
|
+
const str = 'Hello, ΧΨΩЫ';
|
4627
|
+
const encoded = new Uint8Array([72, 101, 108, 108, 111, 44, 32, 206, 167, 206, 168, 206, 169, 208, 171]);
|
4628
|
+
$mol_assert_like($mol_charset_encode(str), encoded);
|
4572
4629
|
},
|
4573
|
-
|
4630
|
+
});
|
4631
|
+
})($ || ($ = {}));
|
4632
|
+
|
4633
|
+
;
|
4634
|
+
"use strict";
|
4635
|
+
var $;
|
4636
|
+
(function ($) {
|
4637
|
+
$mol_test({
|
4638
|
+
async 'Derivation from password'() {
|
4574
4639
|
const data = new Uint8Array([1, 2, 3]);
|
4575
4640
|
const salt1 = $mol_crypto_salt();
|
4576
|
-
const
|
4641
|
+
const secret1 = await $mol_crypto_sacred_pass('hello', salt1);
|
4642
|
+
const secret2 = await $mol_crypto_sacred_pass('hello', salt1);
|
4577
4643
|
const salt2 = $mol_crypto_salt();
|
4578
|
-
const closed = await
|
4579
|
-
const opened = await
|
4644
|
+
const closed = await secret1.encrypt(data, salt2);
|
4645
|
+
const opened = await secret2.decrypt(closed, salt2);
|
4580
4646
|
$mol_assert_equal(data, opened);
|
4581
4647
|
},
|
4582
4648
|
});
|
4583
4649
|
})($ || ($ = {}));
|
4584
4650
|
|
4651
|
+
;
|
4652
|
+
"use strict";
|
4653
|
+
var $;
|
4654
|
+
(function ($) {
|
4655
|
+
$mol_test({
|
4656
|
+
async 'Shared secret from public & private keys'() {
|
4657
|
+
const A = await $mol_crypto_key_private.generate();
|
4658
|
+
const B = await $mol_crypto_key_private.generate();
|
4659
|
+
const SA = await $mol_crypto_sacred_shared(A, B.public());
|
4660
|
+
const SB = await $mol_crypto_sacred_shared(B, A.public());
|
4661
|
+
$mol_assert_equal(SA.asArray(), SB.asArray());
|
4662
|
+
},
|
4663
|
+
});
|
4664
|
+
})($ || ($ = {}));
|
4665
|
+
|
4585
4666
|
;
|
4586
4667
|
"use strict";
|
4587
4668
|
var $;
|