mol_crypto_lib 0.1.1288 → 0.1.1290
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 +207 -6
- package/node.d.ts.map +1 -1
- package/node.deps.json +1 -1
- package/node.js +1001 -50
- package/node.js.map +1 -1
- package/node.mjs +1001 -50
- package/node.test.js +1681 -393
- package/node.test.js.map +1 -1
- package/package.json +21 -5
- package/web.deps.json +1 -1
package/node.test.js
CHANGED
@@ -113,7 +113,11 @@ var $node = new Proxy({ require }, {
|
|
113
113
|
try {
|
114
114
|
$$.$mol_exec('.', 'npm', 'install', '--omit=dev', '@types/' + name);
|
115
115
|
}
|
116
|
-
catch {
|
116
|
+
catch (e) {
|
117
|
+
if ($$.$mol_fail_catch(e)) {
|
118
|
+
$$.$mol_fail_log(e);
|
119
|
+
}
|
120
|
+
}
|
117
121
|
break;
|
118
122
|
}
|
119
123
|
else {
|
@@ -124,7 +128,7 @@ var $node = new Proxy({ require }, {
|
|
124
128
|
return target.require(name);
|
125
129
|
}
|
126
130
|
catch (error) {
|
127
|
-
if (error.code === 'ERR_REQUIRE_ESM') {
|
131
|
+
if ($.$mol_fail_catch(error) && error.code === 'ERR_REQUIRE_ESM') {
|
128
132
|
const module = cache.get(name);
|
129
133
|
if (module)
|
130
134
|
return module;
|
@@ -144,6 +148,68 @@ require = (req => Object.assign(function require(name) {
|
|
144
148
|
return $node[name];
|
145
149
|
}, req))(require);
|
146
150
|
|
151
|
+
;
|
152
|
+
"use strict";
|
153
|
+
var $;
|
154
|
+
(function ($) {
|
155
|
+
const named = new WeakSet();
|
156
|
+
function $mol_func_name(func) {
|
157
|
+
let name = func.name;
|
158
|
+
if (name?.length > 1)
|
159
|
+
return name;
|
160
|
+
if (named.has(func))
|
161
|
+
return name;
|
162
|
+
for (let key in this) {
|
163
|
+
try {
|
164
|
+
if (this[key] !== func)
|
165
|
+
continue;
|
166
|
+
name = key;
|
167
|
+
Object.defineProperty(func, 'name', { value: name });
|
168
|
+
break;
|
169
|
+
}
|
170
|
+
catch { }
|
171
|
+
}
|
172
|
+
named.add(func);
|
173
|
+
return name;
|
174
|
+
}
|
175
|
+
$.$mol_func_name = $mol_func_name;
|
176
|
+
function $mol_func_name_from(target, source) {
|
177
|
+
Object.defineProperty(target, 'name', { value: source.name });
|
178
|
+
return target;
|
179
|
+
}
|
180
|
+
$.$mol_func_name_from = $mol_func_name_from;
|
181
|
+
})($ || ($ = {}));
|
182
|
+
|
183
|
+
;
|
184
|
+
"use strict";
|
185
|
+
var $;
|
186
|
+
(function ($) {
|
187
|
+
class $mol_error_mix extends AggregateError {
|
188
|
+
cause;
|
189
|
+
name = $$.$mol_func_name(this.constructor).replace(/^\$/, '') + '_Error';
|
190
|
+
constructor(message, cause = {}, ...errors) {
|
191
|
+
super(errors, message, { cause });
|
192
|
+
this.cause = cause;
|
193
|
+
const stack_get = Object.getOwnPropertyDescriptor(this, 'stack')?.get ?? (() => super.stack);
|
194
|
+
Object.defineProperty(this, 'stack', {
|
195
|
+
get: () => (stack_get.call(this) ?? this.message) + '\n' + [JSON.stringify(this.cause, null, ' ') ?? 'no cause', ...this.errors.map(e => e.stack)].map(e => e.trim()
|
196
|
+
.replace(/at /gm, ' at ')
|
197
|
+
.replace(/^(?! +at )(.*)/gm, ' at | $1 (#)')).join('\n')
|
198
|
+
});
|
199
|
+
}
|
200
|
+
static [Symbol.toPrimitive]() {
|
201
|
+
return this.toString();
|
202
|
+
}
|
203
|
+
static toString() {
|
204
|
+
return $$.$mol_func_name(this);
|
205
|
+
}
|
206
|
+
static make(...params) {
|
207
|
+
return new this(...params);
|
208
|
+
}
|
209
|
+
}
|
210
|
+
$.$mol_error_mix = $mol_error_mix;
|
211
|
+
})($ || ($ = {}));
|
212
|
+
|
147
213
|
;
|
148
214
|
"use strict";
|
149
215
|
var $;
|
@@ -275,38 +341,6 @@ var $;
|
|
275
341
|
;
|
276
342
|
"use strict";
|
277
343
|
|
278
|
-
;
|
279
|
-
"use strict";
|
280
|
-
var $;
|
281
|
-
(function ($) {
|
282
|
-
const named = new WeakSet();
|
283
|
-
function $mol_func_name(func) {
|
284
|
-
let name = func.name;
|
285
|
-
if (name?.length > 1)
|
286
|
-
return name;
|
287
|
-
if (named.has(func))
|
288
|
-
return name;
|
289
|
-
for (let key in this) {
|
290
|
-
try {
|
291
|
-
if (this[key] !== func)
|
292
|
-
continue;
|
293
|
-
name = key;
|
294
|
-
Object.defineProperty(func, 'name', { value: name });
|
295
|
-
break;
|
296
|
-
}
|
297
|
-
catch { }
|
298
|
-
}
|
299
|
-
named.add(func);
|
300
|
-
return name;
|
301
|
-
}
|
302
|
-
$.$mol_func_name = $mol_func_name;
|
303
|
-
function $mol_func_name_from(target, source) {
|
304
|
-
Object.defineProperty(target, 'name', { value: source.name });
|
305
|
-
return target;
|
306
|
-
}
|
307
|
-
$.$mol_func_name_from = $mol_func_name_from;
|
308
|
-
})($ || ($ = {}));
|
309
|
-
|
310
344
|
;
|
311
345
|
"use strict";
|
312
346
|
var $;
|
@@ -866,213 +900,1130 @@ var $;
|
|
866
900
|
"use strict";
|
867
901
|
var $;
|
868
902
|
(function ($) {
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
command: `${app} ${args.join(' ')}`,
|
877
|
-
});
|
878
|
-
var res = $node['child_process'].spawnSync(app, args, {
|
879
|
-
cwd: $node.path.resolve(dir),
|
880
|
-
shell: true,
|
881
|
-
env: this.$mol_env(),
|
882
|
-
});
|
883
|
-
if (res.status || res.error) {
|
884
|
-
return $mol_fail(res.error || new Error(res.stderr.toString(), { cause: res.stdout }));
|
885
|
-
}
|
886
|
-
if (!res.stdout)
|
887
|
-
res.stdout = Buffer.from([]);
|
888
|
-
return res;
|
889
|
-
}
|
890
|
-
$.$mol_exec = $mol_exec;
|
891
|
-
})($ || ($ = {}));
|
892
|
-
|
893
|
-
;
|
894
|
-
"use strict";
|
895
|
-
var $;
|
896
|
-
(function ($) {
|
897
|
-
$.$mol_crypto_native = $node.crypto.webcrypto;
|
898
|
-
})($ || ($ = {}));
|
899
|
-
|
900
|
-
;
|
901
|
-
"use strict";
|
902
|
-
var $;
|
903
|
-
(function ($) {
|
904
|
-
const TextEncoder = globalThis.TextEncoder ?? $node.util.TextEncoder;
|
905
|
-
const encoder = new TextEncoder();
|
906
|
-
function $mol_charset_encode(value) {
|
907
|
-
return encoder.encode(value);
|
908
|
-
}
|
909
|
-
$.$mol_charset_encode = $mol_charset_encode;
|
903
|
+
let $mol_wire_cursor;
|
904
|
+
(function ($mol_wire_cursor) {
|
905
|
+
$mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
|
906
|
+
$mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
|
907
|
+
$mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
|
908
|
+
$mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
|
909
|
+
})($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
|
910
910
|
})($ || ($ = {}));
|
911
911
|
|
912
912
|
;
|
913
913
|
"use strict";
|
914
914
|
var $;
|
915
915
|
(function ($) {
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
static async generate() {
|
929
|
-
return new this(await $mol_crypto_native.subtle.generateKey(algorithm, true, ['encrypt', 'decrypt']));
|
916
|
+
class $mol_wire_pub extends Object {
|
917
|
+
data = [];
|
918
|
+
static get [Symbol.species]() {
|
919
|
+
return Array;
|
920
|
+
}
|
921
|
+
sub_from = 0;
|
922
|
+
get sub_list() {
|
923
|
+
const res = [];
|
924
|
+
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
925
|
+
res.push(this.data[i]);
|
926
|
+
}
|
927
|
+
return res;
|
930
928
|
}
|
931
|
-
|
932
|
-
return
|
929
|
+
get sub_empty() {
|
930
|
+
return this.sub_from === this.data.length;
|
933
931
|
}
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
iterations: 10_000,
|
939
|
-
hash: "SHA-256",
|
940
|
-
}, await $mol_crypto_native.subtle.importKey("raw", $mol_charset_encode(pass), "PBKDF2", false, ["deriveKey"]), algorithm, true, ['encrypt', 'decrypt']));
|
932
|
+
sub_on(sub, pub_pos) {
|
933
|
+
const pos = this.data.length;
|
934
|
+
this.data.push(sub, pub_pos);
|
935
|
+
return pos;
|
941
936
|
}
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
return
|
937
|
+
sub_off(sub_pos) {
|
938
|
+
if (!(sub_pos < this.data.length)) {
|
939
|
+
$mol_fail(new Error(`Wrong pos ${sub_pos}`));
|
940
|
+
}
|
941
|
+
const end = this.data.length - 2;
|
942
|
+
if (sub_pos !== end) {
|
943
|
+
this.peer_move(end, sub_pos);
|
944
|
+
}
|
945
|
+
this.data.pop();
|
946
|
+
this.data.pop();
|
947
|
+
if (this.data.length === this.sub_from)
|
948
|
+
this.reap();
|
949
|
+
}
|
950
|
+
reap() { }
|
951
|
+
promote() {
|
952
|
+
$mol_wire_auto()?.track_next(this);
|
953
|
+
}
|
954
|
+
fresh() { }
|
955
|
+
complete() { }
|
956
|
+
get incompleted() {
|
957
|
+
return false;
|
963
958
|
}
|
964
|
-
|
965
|
-
|
959
|
+
emit(quant = $mol_wire_cursor.stale) {
|
960
|
+
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
961
|
+
;
|
962
|
+
this.data[i].absorb(quant);
|
963
|
+
}
|
966
964
|
}
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
965
|
+
peer_move(from_pos, to_pos) {
|
966
|
+
const peer = this.data[from_pos];
|
967
|
+
const self_pos = this.data[from_pos + 1];
|
968
|
+
this.data[to_pos] = peer;
|
969
|
+
this.data[to_pos + 1] = self_pos;
|
970
|
+
peer.peer_repos(self_pos, to_pos);
|
972
971
|
}
|
973
|
-
|
974
|
-
|
975
|
-
...algorithm,
|
976
|
-
iv: salt,
|
977
|
-
}, this.native, closed));
|
972
|
+
peer_repos(peer_pos, self_pos) {
|
973
|
+
this.data[peer_pos + 1] = self_pos;
|
978
974
|
}
|
979
975
|
}
|
980
|
-
$.$
|
976
|
+
$.$mol_wire_pub = $mol_wire_pub;
|
981
977
|
})($ || ($ = {}));
|
982
978
|
|
983
979
|
;
|
984
980
|
"use strict";
|
985
|
-
var $;
|
986
|
-
(function ($) {
|
987
|
-
})($ || ($ = {}));
|
988
981
|
|
989
982
|
;
|
990
983
|
"use strict";
|
991
984
|
var $;
|
992
985
|
(function ($) {
|
993
|
-
$.$
|
986
|
+
$.$mol_wire_auto_sub = null;
|
987
|
+
function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
|
988
|
+
return $.$mol_wire_auto_sub = next;
|
989
|
+
}
|
990
|
+
$.$mol_wire_auto = $mol_wire_auto;
|
991
|
+
$.$mol_wire_affected = [];
|
994
992
|
})($ || ($ = {}));
|
995
993
|
|
996
994
|
;
|
997
995
|
"use strict";
|
998
996
|
var $;
|
999
997
|
(function ($) {
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
return await this.$mol_crypto_secret_id_get();
|
1004
|
-
const id = await this.$mol_crypto_secret_id_new();
|
1005
|
-
this.$mol_dom_context.localStorage.setItem('$mol_crypto_secret', '');
|
1006
|
-
return id;
|
998
|
+
$['devtoolsFormatters'] ||= [];
|
999
|
+
function $mol_dev_format_register(config) {
|
1000
|
+
$['devtoolsFormatters'].push(config);
|
1007
1001
|
}
|
1008
|
-
$.$
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1002
|
+
$.$mol_dev_format_register = $mol_dev_format_register;
|
1003
|
+
$.$mol_dev_format_head = Symbol('$mol_dev_format_head');
|
1004
|
+
$.$mol_dev_format_body = Symbol('$mol_dev_format_body');
|
1005
|
+
$mol_dev_format_register({
|
1006
|
+
header: (val, config = false) => {
|
1007
|
+
if (config)
|
1008
|
+
return null;
|
1009
|
+
if (!val)
|
1010
|
+
return null;
|
1011
|
+
if ($.$mol_dev_format_head in val) {
|
1012
|
+
try {
|
1013
|
+
return val[$.$mol_dev_format_head]();
|
1014
|
+
}
|
1015
|
+
catch (error) {
|
1016
|
+
return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
|
1017
|
+
}
|
1018
|
+
}
|
1019
|
+
if (typeof val === 'function') {
|
1020
|
+
return $mol_dev_format_native(val);
|
1021
|
+
}
|
1022
|
+
if (Symbol.toStringTag in val) {
|
1023
|
+
return $mol_dev_format_native(val);
|
1024
|
+
}
|
1025
|
+
return null;
|
1026
|
+
},
|
1027
|
+
hasBody: val => val[$.$mol_dev_format_body],
|
1028
|
+
body: val => val[$.$mol_dev_format_body](),
|
1029
|
+
});
|
1030
|
+
function $mol_dev_format_native(obj) {
|
1031
|
+
if (typeof obj === 'undefined')
|
1032
|
+
return $.$mol_dev_format_shade('undefined');
|
1033
|
+
return [
|
1034
|
+
'object',
|
1035
|
+
{
|
1036
|
+
object: obj,
|
1037
|
+
config: true,
|
1025
1038
|
},
|
1026
|
-
|
1027
|
-
return $mol_crypto_secret.from(cred.rawId);
|
1039
|
+
];
|
1028
1040
|
}
|
1029
|
-
$.$
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1041
|
+
$.$mol_dev_format_native = $mol_dev_format_native;
|
1042
|
+
function $mol_dev_format_auto(obj) {
|
1043
|
+
if (obj == null)
|
1044
|
+
return $.$mol_dev_format_shade(String(obj));
|
1045
|
+
return [
|
1046
|
+
'object',
|
1047
|
+
{
|
1048
|
+
object: obj,
|
1049
|
+
config: false,
|
1036
1050
|
},
|
1037
|
-
|
1038
|
-
return $mol_crypto_secret.from(cred.rawId);
|
1051
|
+
];
|
1039
1052
|
}
|
1040
|
-
$.$
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1053
|
+
$.$mol_dev_format_auto = $mol_dev_format_auto;
|
1054
|
+
function $mol_dev_format_element(element, style, ...content) {
|
1055
|
+
const styles = [];
|
1056
|
+
for (let key in style)
|
1057
|
+
styles.push(`${key} : ${style[key]}`);
|
1058
|
+
return [
|
1059
|
+
element,
|
1060
|
+
{
|
1061
|
+
style: styles.join(' ; '),
|
1062
|
+
},
|
1063
|
+
...content,
|
1064
|
+
];
|
1049
1065
|
}
|
1050
|
-
$.$
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
var $;
|
1056
|
-
(function ($) {
|
1057
|
-
function $mol_base64_encode_node(str) {
|
1058
|
-
if (!str)
|
1059
|
-
return '';
|
1060
|
-
if (Buffer.isBuffer(str))
|
1061
|
-
return str.toString('base64');
|
1062
|
-
return Buffer.from(str).toString('base64');
|
1066
|
+
$.$mol_dev_format_element = $mol_dev_format_element;
|
1067
|
+
function $mol_dev_format_span(style, ...content) {
|
1068
|
+
return $mol_dev_format_element('span', {
|
1069
|
+
...style,
|
1070
|
+
}, ...content);
|
1063
1071
|
}
|
1064
|
-
$.$
|
1065
|
-
$.$
|
1072
|
+
$.$mol_dev_format_span = $mol_dev_format_span;
|
1073
|
+
$.$mol_dev_format_div = $mol_dev_format_element.bind(null, 'div');
|
1074
|
+
$.$mol_dev_format_ol = $mol_dev_format_element.bind(null, 'ol');
|
1075
|
+
$.$mol_dev_format_li = $mol_dev_format_element.bind(null, 'li');
|
1076
|
+
$.$mol_dev_format_table = $mol_dev_format_element.bind(null, 'table');
|
1077
|
+
$.$mol_dev_format_tr = $mol_dev_format_element.bind(null, 'tr');
|
1078
|
+
$.$mol_dev_format_td = $mol_dev_format_element.bind(null, 'td');
|
1079
|
+
$.$mol_dev_format_accent = $mol_dev_format_span.bind(null, {
|
1080
|
+
'color': 'magenta',
|
1081
|
+
});
|
1082
|
+
$.$mol_dev_format_strong = $mol_dev_format_span.bind(null, {
|
1083
|
+
'font-weight': 'bold',
|
1084
|
+
});
|
1085
|
+
$.$mol_dev_format_string = $mol_dev_format_span.bind(null, {
|
1086
|
+
'color': 'green',
|
1087
|
+
});
|
1088
|
+
$.$mol_dev_format_shade = $mol_dev_format_span.bind(null, {
|
1089
|
+
'color': 'gray',
|
1090
|
+
});
|
1091
|
+
$.$mol_dev_format_indent = $.$mol_dev_format_div.bind(null, {
|
1092
|
+
'margin-left': '13px'
|
1093
|
+
});
|
1066
1094
|
})($ || ($ = {}));
|
1067
1095
|
|
1068
1096
|
;
|
1069
1097
|
"use strict";
|
1070
1098
|
var $;
|
1071
1099
|
(function ($) {
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1100
|
+
class $mol_wire_pub_sub extends $mol_wire_pub {
|
1101
|
+
pub_from = 0;
|
1102
|
+
cursor = $mol_wire_cursor.stale;
|
1103
|
+
get temp() {
|
1104
|
+
return false;
|
1105
|
+
}
|
1106
|
+
get pub_list() {
|
1107
|
+
const res = [];
|
1108
|
+
const max = this.cursor >= 0 ? this.cursor : this.sub_from;
|
1109
|
+
for (let i = this.pub_from; i < max; i += 2) {
|
1110
|
+
if (this.data[i])
|
1111
|
+
res.push(this.data[i]);
|
1112
|
+
}
|
1113
|
+
return res;
|
1114
|
+
}
|
1115
|
+
track_on() {
|
1116
|
+
this.cursor = this.pub_from;
|
1117
|
+
const sub = $mol_wire_auto();
|
1118
|
+
$mol_wire_auto(this);
|
1119
|
+
return sub;
|
1120
|
+
}
|
1121
|
+
promote() {
|
1122
|
+
if (this.cursor >= this.pub_from) {
|
1123
|
+
$mol_fail(new Error('Circular subscription'));
|
1124
|
+
}
|
1125
|
+
super.promote();
|
1126
|
+
}
|
1127
|
+
track_next(pub) {
|
1128
|
+
if (this.cursor < 0)
|
1129
|
+
$mol_fail(new Error('Promo to non begun sub'));
|
1130
|
+
if (this.cursor < this.sub_from) {
|
1131
|
+
const next = this.data[this.cursor];
|
1132
|
+
if (pub === undefined)
|
1133
|
+
return next ?? null;
|
1134
|
+
if (next === pub) {
|
1135
|
+
this.cursor += 2;
|
1136
|
+
return next;
|
1137
|
+
}
|
1138
|
+
if (next) {
|
1139
|
+
if (this.sub_from < this.data.length) {
|
1140
|
+
this.peer_move(this.sub_from, this.data.length);
|
1141
|
+
}
|
1142
|
+
this.peer_move(this.cursor, this.sub_from);
|
1143
|
+
this.sub_from += 2;
|
1144
|
+
}
|
1145
|
+
}
|
1146
|
+
else {
|
1147
|
+
if (pub === undefined)
|
1148
|
+
return null;
|
1149
|
+
if (this.sub_from < this.data.length) {
|
1150
|
+
this.peer_move(this.sub_from, this.data.length);
|
1151
|
+
}
|
1152
|
+
this.sub_from += 2;
|
1153
|
+
}
|
1154
|
+
this.data[this.cursor] = pub;
|
1155
|
+
this.data[this.cursor + 1] = pub.sub_on(this, this.cursor);
|
1156
|
+
this.cursor += 2;
|
1157
|
+
return pub;
|
1158
|
+
}
|
1159
|
+
track_off(sub) {
|
1160
|
+
$mol_wire_auto(sub);
|
1161
|
+
if (this.cursor < 0) {
|
1162
|
+
$mol_fail(new Error('End of non begun sub'));
|
1163
|
+
}
|
1164
|
+
for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
|
1165
|
+
const pub = this.data[cursor];
|
1166
|
+
pub.fresh();
|
1167
|
+
}
|
1168
|
+
this.cursor = $mol_wire_cursor.fresh;
|
1169
|
+
}
|
1170
|
+
pub_off(sub_pos) {
|
1171
|
+
this.data[sub_pos] = undefined;
|
1172
|
+
this.data[sub_pos + 1] = undefined;
|
1173
|
+
}
|
1174
|
+
destructor() {
|
1175
|
+
for (let cursor = this.data.length - 2; cursor >= this.sub_from; cursor -= 2) {
|
1176
|
+
const sub = this.data[cursor];
|
1177
|
+
const pos = this.data[cursor + 1];
|
1178
|
+
sub.pub_off(pos);
|
1179
|
+
this.data.pop();
|
1180
|
+
this.data.pop();
|
1181
|
+
}
|
1182
|
+
this.cursor = this.pub_from;
|
1183
|
+
this.track_cut();
|
1184
|
+
this.cursor = $mol_wire_cursor.final;
|
1185
|
+
}
|
1186
|
+
track_cut() {
|
1187
|
+
if (this.cursor < this.pub_from) {
|
1188
|
+
$mol_fail(new Error('Cut of non begun sub'));
|
1189
|
+
}
|
1190
|
+
let tail = 0;
|
1191
|
+
for (let cursor = this.cursor; cursor < this.sub_from; cursor += 2) {
|
1192
|
+
const pub = this.data[cursor];
|
1193
|
+
pub?.sub_off(this.data[cursor + 1]);
|
1194
|
+
if (this.sub_from < this.data.length) {
|
1195
|
+
this.peer_move(this.data.length - 2, cursor);
|
1196
|
+
this.data.pop();
|
1197
|
+
this.data.pop();
|
1198
|
+
}
|
1199
|
+
else {
|
1200
|
+
++tail;
|
1201
|
+
}
|
1202
|
+
}
|
1203
|
+
for (; tail; --tail) {
|
1204
|
+
this.data.pop();
|
1205
|
+
this.data.pop();
|
1206
|
+
}
|
1207
|
+
this.sub_from = this.cursor;
|
1208
|
+
}
|
1209
|
+
complete() { }
|
1210
|
+
complete_pubs() {
|
1211
|
+
const limit = this.cursor < 0 ? this.sub_from : this.cursor;
|
1212
|
+
for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
|
1213
|
+
const pub = this.data[cursor];
|
1214
|
+
if (pub?.incompleted)
|
1215
|
+
return;
|
1216
|
+
}
|
1217
|
+
for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
|
1218
|
+
const pub = this.data[cursor];
|
1219
|
+
pub?.complete();
|
1220
|
+
}
|
1221
|
+
}
|
1222
|
+
absorb(quant = $mol_wire_cursor.stale) {
|
1223
|
+
if (this.cursor === $mol_wire_cursor.final)
|
1224
|
+
return;
|
1225
|
+
if (this.cursor >= quant)
|
1226
|
+
return;
|
1227
|
+
this.cursor = quant;
|
1228
|
+
this.emit($mol_wire_cursor.doubt);
|
1229
|
+
}
|
1230
|
+
[$mol_dev_format_head]() {
|
1231
|
+
return $mol_dev_format_native(this);
|
1232
|
+
}
|
1233
|
+
get pub_empty() {
|
1234
|
+
return this.sub_from === this.pub_from;
|
1235
|
+
}
|
1236
|
+
}
|
1237
|
+
$.$mol_wire_pub_sub = $mol_wire_pub_sub;
|
1238
|
+
})($ || ($ = {}));
|
1239
|
+
|
1240
|
+
;
|
1241
|
+
"use strict";
|
1242
|
+
var $;
|
1243
|
+
(function ($) {
|
1244
|
+
class $mol_after_tick extends $mol_object2 {
|
1245
|
+
task;
|
1246
|
+
static promise = null;
|
1247
|
+
cancelled = false;
|
1248
|
+
constructor(task) {
|
1249
|
+
super();
|
1250
|
+
this.task = task;
|
1251
|
+
if (!$mol_after_tick.promise)
|
1252
|
+
$mol_after_tick.promise = Promise.resolve().then(() => {
|
1253
|
+
$mol_after_tick.promise = null;
|
1254
|
+
});
|
1255
|
+
$mol_after_tick.promise.then(() => {
|
1256
|
+
if (this.cancelled)
|
1257
|
+
return;
|
1258
|
+
task();
|
1259
|
+
});
|
1260
|
+
}
|
1261
|
+
destructor() {
|
1262
|
+
this.cancelled = true;
|
1263
|
+
}
|
1264
|
+
}
|
1265
|
+
$.$mol_after_tick = $mol_after_tick;
|
1266
|
+
})($ || ($ = {}));
|
1267
|
+
|
1268
|
+
;
|
1269
|
+
"use strict";
|
1270
|
+
var $;
|
1271
|
+
(function ($) {
|
1272
|
+
const handled = new WeakSet();
|
1273
|
+
class $mol_wire_fiber extends $mol_wire_pub_sub {
|
1274
|
+
task;
|
1275
|
+
host;
|
1276
|
+
static warm = true;
|
1277
|
+
static planning = new Set();
|
1278
|
+
static reaping = new Set();
|
1279
|
+
static plan_task = null;
|
1280
|
+
static plan() {
|
1281
|
+
if (this.plan_task)
|
1282
|
+
return;
|
1283
|
+
this.plan_task = new $mol_after_tick(() => {
|
1284
|
+
try {
|
1285
|
+
this.sync();
|
1286
|
+
}
|
1287
|
+
finally {
|
1288
|
+
$mol_wire_fiber.plan_task = null;
|
1289
|
+
}
|
1290
|
+
});
|
1291
|
+
}
|
1292
|
+
static sync() {
|
1293
|
+
while (this.planning.size) {
|
1294
|
+
for (const fiber of this.planning) {
|
1295
|
+
this.planning.delete(fiber);
|
1296
|
+
if (fiber.cursor >= 0)
|
1297
|
+
continue;
|
1298
|
+
if (fiber.cursor === $mol_wire_cursor.final)
|
1299
|
+
continue;
|
1300
|
+
fiber.fresh();
|
1301
|
+
}
|
1302
|
+
}
|
1303
|
+
while (this.reaping.size) {
|
1304
|
+
const fibers = this.reaping;
|
1305
|
+
this.reaping = new Set;
|
1306
|
+
for (const fiber of fibers) {
|
1307
|
+
if (!fiber.sub_empty)
|
1308
|
+
continue;
|
1309
|
+
fiber.destructor();
|
1310
|
+
}
|
1311
|
+
}
|
1312
|
+
}
|
1313
|
+
[Symbol.toStringTag];
|
1314
|
+
cache = undefined;
|
1315
|
+
get args() {
|
1316
|
+
return this.data.slice(0, this.pub_from);
|
1317
|
+
}
|
1318
|
+
result() {
|
1319
|
+
if ($mol_promise_like(this.cache))
|
1320
|
+
return;
|
1321
|
+
if (this.cache instanceof Error)
|
1322
|
+
return;
|
1323
|
+
return this.cache;
|
1324
|
+
}
|
1325
|
+
get incompleted() {
|
1326
|
+
return $mol_promise_like(this.cache);
|
1327
|
+
}
|
1328
|
+
field() {
|
1329
|
+
return this.task.name + '<>';
|
1330
|
+
}
|
1331
|
+
constructor(id, task, host, args) {
|
1332
|
+
super();
|
1333
|
+
this.task = task;
|
1334
|
+
this.host = host;
|
1335
|
+
if (args)
|
1336
|
+
this.data.push(...args);
|
1337
|
+
this.pub_from = this.sub_from = args?.length ?? 0;
|
1338
|
+
this[Symbol.toStringTag] = id;
|
1339
|
+
}
|
1340
|
+
plan() {
|
1341
|
+
$mol_wire_fiber.planning.add(this);
|
1342
|
+
$mol_wire_fiber.plan();
|
1343
|
+
return this;
|
1344
|
+
}
|
1345
|
+
reap() {
|
1346
|
+
$mol_wire_fiber.reaping.add(this);
|
1347
|
+
$mol_wire_fiber.plan();
|
1348
|
+
}
|
1349
|
+
toString() {
|
1350
|
+
return this[Symbol.toStringTag];
|
1351
|
+
}
|
1352
|
+
toJSON() {
|
1353
|
+
return this[Symbol.toStringTag];
|
1354
|
+
}
|
1355
|
+
[$mol_dev_format_head]() {
|
1356
|
+
const cursor = {
|
1357
|
+
[$mol_wire_cursor.stale]: '🔴',
|
1358
|
+
[$mol_wire_cursor.doubt]: '🟡',
|
1359
|
+
[$mol_wire_cursor.fresh]: '🟢',
|
1360
|
+
[$mol_wire_cursor.final]: '🔵',
|
1361
|
+
}[this.cursor] ?? this.cursor.toString();
|
1362
|
+
return $mol_dev_format_div({}, $mol_owning_check(this, this.cache)
|
1363
|
+
? $mol_dev_format_auto({
|
1364
|
+
[$mol_dev_format_head]: () => $mol_dev_format_shade(cursor),
|
1365
|
+
[$mol_dev_format_body]: () => $mol_dev_format_native(this),
|
1366
|
+
})
|
1367
|
+
: $mol_dev_format_shade($mol_dev_format_native(this), cursor), $mol_dev_format_auto(this.cache));
|
1368
|
+
}
|
1369
|
+
get $() {
|
1370
|
+
return (this.host ?? this.task)['$'];
|
1371
|
+
}
|
1372
|
+
emit(quant = $mol_wire_cursor.stale) {
|
1373
|
+
if (this.sub_empty)
|
1374
|
+
this.plan();
|
1375
|
+
else
|
1376
|
+
super.emit(quant);
|
1377
|
+
}
|
1378
|
+
fresh() {
|
1379
|
+
if (this.cursor === $mol_wire_cursor.fresh)
|
1380
|
+
return;
|
1381
|
+
if (this.cursor === $mol_wire_cursor.final)
|
1382
|
+
return;
|
1383
|
+
check: if (this.cursor === $mol_wire_cursor.doubt) {
|
1384
|
+
for (let i = this.pub_from; i < this.sub_from; i += 2) {
|
1385
|
+
;
|
1386
|
+
this.data[i]?.fresh();
|
1387
|
+
if (this.cursor !== $mol_wire_cursor.doubt)
|
1388
|
+
break check;
|
1389
|
+
}
|
1390
|
+
this.cursor = $mol_wire_cursor.fresh;
|
1391
|
+
return;
|
1392
|
+
}
|
1393
|
+
const bu = this.track_on();
|
1394
|
+
let result;
|
1395
|
+
try {
|
1396
|
+
switch (this.pub_from) {
|
1397
|
+
case 0:
|
1398
|
+
result = this.task.call(this.host);
|
1399
|
+
break;
|
1400
|
+
case 1:
|
1401
|
+
result = this.task.call(this.host, this.data[0]);
|
1402
|
+
break;
|
1403
|
+
default:
|
1404
|
+
result = this.task.call(this.host, ...this.args);
|
1405
|
+
break;
|
1406
|
+
}
|
1407
|
+
if ($mol_promise_like(result) && !handled.has(result)) {
|
1408
|
+
const put = (res) => {
|
1409
|
+
if (this.cache === result)
|
1410
|
+
this.put(res);
|
1411
|
+
return res;
|
1412
|
+
};
|
1413
|
+
result = result.then(put, put);
|
1414
|
+
}
|
1415
|
+
}
|
1416
|
+
catch (error) {
|
1417
|
+
if (error instanceof Error || $mol_promise_like(error)) {
|
1418
|
+
result = error;
|
1419
|
+
}
|
1420
|
+
else {
|
1421
|
+
result = new Error(String(error), { cause: error });
|
1422
|
+
}
|
1423
|
+
if ($mol_promise_like(result) && !handled.has(result)) {
|
1424
|
+
result = result.finally(() => {
|
1425
|
+
if (this.cache === result)
|
1426
|
+
this.absorb();
|
1427
|
+
});
|
1428
|
+
}
|
1429
|
+
}
|
1430
|
+
if ($mol_promise_like(result) && !handled.has(result)) {
|
1431
|
+
result = Object.assign(result, {
|
1432
|
+
destructor: result['destructor'] ?? (() => { })
|
1433
|
+
});
|
1434
|
+
handled.add(result);
|
1435
|
+
const error = new Error(`Promise in ${this}`);
|
1436
|
+
Object.defineProperty(result, 'stack', { get: () => error.stack });
|
1437
|
+
}
|
1438
|
+
if (!$mol_promise_like(result)) {
|
1439
|
+
this.track_cut();
|
1440
|
+
}
|
1441
|
+
this.track_off(bu);
|
1442
|
+
this.put(result);
|
1443
|
+
return this;
|
1444
|
+
}
|
1445
|
+
refresh() {
|
1446
|
+
this.cursor = $mol_wire_cursor.stale;
|
1447
|
+
this.fresh();
|
1448
|
+
}
|
1449
|
+
sync() {
|
1450
|
+
if (!$mol_wire_fiber.warm) {
|
1451
|
+
return this.result();
|
1452
|
+
}
|
1453
|
+
this.promote();
|
1454
|
+
this.fresh();
|
1455
|
+
if (this.cache instanceof Error) {
|
1456
|
+
return $mol_fail_hidden(this.cache);
|
1457
|
+
}
|
1458
|
+
if ($mol_promise_like(this.cache)) {
|
1459
|
+
return $mol_fail_hidden(this.cache);
|
1460
|
+
}
|
1461
|
+
return this.cache;
|
1462
|
+
}
|
1463
|
+
async async() {
|
1464
|
+
while (true) {
|
1465
|
+
this.fresh();
|
1466
|
+
if (this.cache instanceof Error) {
|
1467
|
+
$mol_fail_hidden(this.cache);
|
1468
|
+
}
|
1469
|
+
if (!$mol_promise_like(this.cache))
|
1470
|
+
return this.cache;
|
1471
|
+
await Promise.race([this.cache, this.step()]);
|
1472
|
+
if (!$mol_promise_like(this.cache))
|
1473
|
+
return this.cache;
|
1474
|
+
if (this.cursor === $mol_wire_cursor.final) {
|
1475
|
+
await new Promise(() => { });
|
1476
|
+
}
|
1477
|
+
}
|
1478
|
+
}
|
1479
|
+
step() {
|
1480
|
+
return new Promise(done => {
|
1481
|
+
const sub = new $mol_wire_pub_sub;
|
1482
|
+
const prev = sub.track_on();
|
1483
|
+
sub.track_next(this);
|
1484
|
+
sub.track_off(prev);
|
1485
|
+
sub.absorb = () => {
|
1486
|
+
done(null);
|
1487
|
+
setTimeout(() => sub.destructor());
|
1488
|
+
};
|
1489
|
+
});
|
1490
|
+
}
|
1491
|
+
}
|
1492
|
+
$.$mol_wire_fiber = $mol_wire_fiber;
|
1493
|
+
})($ || ($ = {}));
|
1494
|
+
|
1495
|
+
;
|
1496
|
+
"use strict";
|
1497
|
+
var $;
|
1498
|
+
(function ($) {
|
1499
|
+
$.$mol_compare_deep_cache = new WeakMap();
|
1500
|
+
function $mol_compare_deep(left, right) {
|
1501
|
+
if (Object.is(left, right))
|
1502
|
+
return true;
|
1503
|
+
if (left === null)
|
1504
|
+
return false;
|
1505
|
+
if (right === null)
|
1506
|
+
return false;
|
1507
|
+
if (typeof left !== 'object')
|
1508
|
+
return false;
|
1509
|
+
if (typeof right !== 'object')
|
1510
|
+
return false;
|
1511
|
+
const left_proto = Reflect.getPrototypeOf(left);
|
1512
|
+
const right_proto = Reflect.getPrototypeOf(right);
|
1513
|
+
if (left_proto !== right_proto)
|
1514
|
+
return false;
|
1515
|
+
if (left instanceof Boolean)
|
1516
|
+
return Object.is(left.valueOf(), right['valueOf']());
|
1517
|
+
if (left instanceof Number)
|
1518
|
+
return Object.is(left.valueOf(), right['valueOf']());
|
1519
|
+
if (left instanceof String)
|
1520
|
+
return Object.is(left.valueOf(), right['valueOf']());
|
1521
|
+
if (left instanceof Date)
|
1522
|
+
return Object.is(left.valueOf(), right['valueOf']());
|
1523
|
+
if (left instanceof RegExp)
|
1524
|
+
return left.source === right.source && left.flags === right.flags;
|
1525
|
+
if (left instanceof Error)
|
1526
|
+
return left.message === right.message && left.stack === right.stack;
|
1527
|
+
let left_cache = $.$mol_compare_deep_cache.get(left);
|
1528
|
+
if (left_cache) {
|
1529
|
+
const right_cache = left_cache.get(right);
|
1530
|
+
if (typeof right_cache === 'boolean')
|
1531
|
+
return right_cache;
|
1532
|
+
}
|
1533
|
+
else {
|
1534
|
+
left_cache = new WeakMap();
|
1535
|
+
$.$mol_compare_deep_cache.set(left, left_cache);
|
1536
|
+
}
|
1537
|
+
left_cache.set(right, true);
|
1538
|
+
let result;
|
1539
|
+
try {
|
1540
|
+
if (!left_proto)
|
1541
|
+
result = compare_pojo(left, right);
|
1542
|
+
else if (!Reflect.getPrototypeOf(left_proto))
|
1543
|
+
result = compare_pojo(left, right);
|
1544
|
+
else if (Symbol.toPrimitive in left)
|
1545
|
+
result = compare_primitive(left, right);
|
1546
|
+
else if (Array.isArray(left))
|
1547
|
+
result = compare_array(left, right);
|
1548
|
+
else if (left instanceof Set)
|
1549
|
+
result = compare_set(left, right);
|
1550
|
+
else if (left instanceof Map)
|
1551
|
+
result = compare_map(left, right);
|
1552
|
+
else if (ArrayBuffer.isView(left))
|
1553
|
+
result = compare_buffer(left, right);
|
1554
|
+
else if (Symbol.iterator in left)
|
1555
|
+
result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
|
1556
|
+
else
|
1557
|
+
result = false;
|
1558
|
+
}
|
1559
|
+
finally {
|
1560
|
+
left_cache.set(right, result);
|
1561
|
+
}
|
1562
|
+
return result;
|
1563
|
+
}
|
1564
|
+
$.$mol_compare_deep = $mol_compare_deep;
|
1565
|
+
function compare_array(left, right) {
|
1566
|
+
const len = left.length;
|
1567
|
+
if (len !== right.length)
|
1568
|
+
return false;
|
1569
|
+
for (let i = 0; i < len; ++i) {
|
1570
|
+
if (!$mol_compare_deep(left[i], right[i]))
|
1571
|
+
return false;
|
1572
|
+
}
|
1573
|
+
return true;
|
1574
|
+
}
|
1575
|
+
function compare_buffer(left, right) {
|
1576
|
+
const len = left.byteLength;
|
1577
|
+
if (len !== right.byteLength)
|
1578
|
+
return false;
|
1579
|
+
if (left instanceof DataView)
|
1580
|
+
return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, left.byteOffset, left.byteLength));
|
1581
|
+
for (let i = 0; i < len; ++i) {
|
1582
|
+
if (left[i] !== right[i])
|
1583
|
+
return false;
|
1584
|
+
}
|
1585
|
+
return true;
|
1586
|
+
}
|
1587
|
+
function compare_iterator(left, right) {
|
1588
|
+
while (true) {
|
1589
|
+
const left_next = left.next();
|
1590
|
+
const right_next = right.next();
|
1591
|
+
if (left_next.done !== right_next.done)
|
1592
|
+
return false;
|
1593
|
+
if (left_next.done)
|
1594
|
+
break;
|
1595
|
+
if (!$mol_compare_deep(left_next.value, right_next.value))
|
1596
|
+
return false;
|
1597
|
+
}
|
1598
|
+
return true;
|
1599
|
+
}
|
1600
|
+
function compare_set(left, right) {
|
1601
|
+
if (left.size !== right.size)
|
1602
|
+
return false;
|
1603
|
+
return compare_iterator(left.values(), right.values());
|
1604
|
+
}
|
1605
|
+
function compare_map(left, right) {
|
1606
|
+
if (left.size !== right.size)
|
1607
|
+
return false;
|
1608
|
+
return compare_iterator(left.keys(), right.keys())
|
1609
|
+
&& compare_iterator(left.values(), right.values());
|
1610
|
+
}
|
1611
|
+
function compare_pojo(left, right) {
|
1612
|
+
const left_keys = Object.getOwnPropertyNames(left);
|
1613
|
+
const right_keys = Object.getOwnPropertyNames(right);
|
1614
|
+
if (!compare_array(left_keys, right_keys))
|
1615
|
+
return false;
|
1616
|
+
for (let key of left_keys) {
|
1617
|
+
if (!$mol_compare_deep(left[key], right[key]))
|
1618
|
+
return false;
|
1619
|
+
}
|
1620
|
+
const left_syms = Object.getOwnPropertySymbols(left);
|
1621
|
+
const right_syms = Object.getOwnPropertySymbols(right);
|
1622
|
+
if (!compare_array(left_syms, right_syms))
|
1623
|
+
return false;
|
1624
|
+
for (let key of left_syms) {
|
1625
|
+
if (!$mol_compare_deep(left[key], right[key]))
|
1626
|
+
return false;
|
1627
|
+
}
|
1628
|
+
return true;
|
1629
|
+
}
|
1630
|
+
function compare_primitive(left, right) {
|
1631
|
+
return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
|
1632
|
+
}
|
1633
|
+
})($ || ($ = {}));
|
1634
|
+
|
1635
|
+
;
|
1636
|
+
"use strict";
|
1637
|
+
var $;
|
1638
|
+
(function ($) {
|
1639
|
+
class $mol_wire_task extends $mol_wire_fiber {
|
1640
|
+
static getter(task) {
|
1641
|
+
return function $mol_wire_task_get(host, args) {
|
1642
|
+
const sub = $mol_wire_auto();
|
1643
|
+
const existen = sub?.track_next();
|
1644
|
+
reuse: if (existen) {
|
1645
|
+
if (!existen.temp)
|
1646
|
+
break reuse;
|
1647
|
+
if (existen.host !== host)
|
1648
|
+
break reuse;
|
1649
|
+
if (existen.task !== task)
|
1650
|
+
break reuse;
|
1651
|
+
if (!$mol_compare_deep(existen.args, args))
|
1652
|
+
break reuse;
|
1653
|
+
return existen;
|
1654
|
+
}
|
1655
|
+
const key = (host?.[Symbol.toStringTag] ?? host) + ('.' + task.name + '<#>');
|
1656
|
+
const next = new $mol_wire_task(key, task, host, args);
|
1657
|
+
if (existen?.temp) {
|
1658
|
+
$$.$mol_log3_warn({
|
1659
|
+
place: '$mol_wire_task',
|
1660
|
+
message: `Non idempotency`,
|
1661
|
+
existen,
|
1662
|
+
next,
|
1663
|
+
hint: 'Ignore it',
|
1664
|
+
});
|
1665
|
+
}
|
1666
|
+
return next;
|
1667
|
+
};
|
1668
|
+
}
|
1669
|
+
get temp() {
|
1670
|
+
return true;
|
1671
|
+
}
|
1672
|
+
complete() {
|
1673
|
+
if ($mol_promise_like(this.cache))
|
1674
|
+
return;
|
1675
|
+
this.destructor();
|
1676
|
+
}
|
1677
|
+
put(next) {
|
1678
|
+
const prev = this.cache;
|
1679
|
+
this.cache = next;
|
1680
|
+
if ($mol_promise_like(next)) {
|
1681
|
+
this.cursor = $mol_wire_cursor.fresh;
|
1682
|
+
if (next !== prev)
|
1683
|
+
this.emit();
|
1684
|
+
return next;
|
1685
|
+
}
|
1686
|
+
this.cursor = $mol_wire_cursor.final;
|
1687
|
+
if (this.sub_empty)
|
1688
|
+
this.destructor();
|
1689
|
+
else if (next !== prev)
|
1690
|
+
this.emit();
|
1691
|
+
return next;
|
1692
|
+
}
|
1693
|
+
}
|
1694
|
+
$.$mol_wire_task = $mol_wire_task;
|
1695
|
+
})($ || ($ = {}));
|
1696
|
+
|
1697
|
+
;
|
1698
|
+
"use strict";
|
1699
|
+
var $;
|
1700
|
+
(function ($) {
|
1701
|
+
const factories = new WeakMap();
|
1702
|
+
function factory(val) {
|
1703
|
+
let make = factories.get(val);
|
1704
|
+
if (make)
|
1705
|
+
return make;
|
1706
|
+
make = $mol_func_name_from((...args) => new val(...args), val);
|
1707
|
+
factories.set(val, make);
|
1708
|
+
return make;
|
1709
|
+
}
|
1710
|
+
function $mol_wire_sync(obj) {
|
1711
|
+
return new Proxy(obj, {
|
1712
|
+
get(obj, field) {
|
1713
|
+
let val = obj[field];
|
1714
|
+
if (typeof val !== 'function')
|
1715
|
+
return val;
|
1716
|
+
const temp = $mol_wire_task.getter(val);
|
1717
|
+
return function $mol_wire_sync(...args) {
|
1718
|
+
const fiber = temp(obj, args);
|
1719
|
+
return fiber.sync();
|
1720
|
+
};
|
1721
|
+
},
|
1722
|
+
construct(obj, args) {
|
1723
|
+
const temp = $mol_wire_task.getter(factory(obj));
|
1724
|
+
return temp(obj, args).sync();
|
1725
|
+
},
|
1726
|
+
apply(obj, self, args) {
|
1727
|
+
const temp = $mol_wire_task.getter(obj);
|
1728
|
+
return temp(self, args).sync();
|
1729
|
+
},
|
1730
|
+
});
|
1731
|
+
}
|
1732
|
+
$.$mol_wire_sync = $mol_wire_sync;
|
1733
|
+
})($ || ($ = {}));
|
1734
|
+
|
1735
|
+
;
|
1736
|
+
"use strict";
|
1737
|
+
var $;
|
1738
|
+
(function ($) {
|
1739
|
+
class $mol_run_error extends $mol_error_mix {
|
1740
|
+
}
|
1741
|
+
$.$mol_run_error = $mol_run_error;
|
1742
|
+
const child_process = $node['child_process'];
|
1743
|
+
$.$mol_run_spawn = child_process.spawn.bind(child_process);
|
1744
|
+
$.$mol_run_spawn_sync = child_process.spawnSync.bind(child_process);
|
1745
|
+
function $mol_run_async({ dir, timeout, command, env }) {
|
1746
|
+
const args_raw = typeof command === 'string' ? command.split(' ') : command;
|
1747
|
+
const [app, ...args] = args_raw;
|
1748
|
+
if (!env?.MOL_RUN_ASYNC) {
|
1749
|
+
this.$mol_log3_come({
|
1750
|
+
place: '$mol_run_sync',
|
1751
|
+
message: 'Run',
|
1752
|
+
command: args_raw.join(' '),
|
1753
|
+
dir: $node.path.relative('', dir),
|
1754
|
+
});
|
1755
|
+
return this.$mol_run_spawn_sync(app, args, { shell: true, cwd: dir, env });
|
1756
|
+
}
|
1757
|
+
const sub = this.$mol_run_spawn(app, args, {
|
1758
|
+
shell: true,
|
1759
|
+
cwd: dir,
|
1760
|
+
env
|
1761
|
+
});
|
1762
|
+
this.$mol_log3_come({
|
1763
|
+
place: '$mol_run_async',
|
1764
|
+
pid: sub.pid,
|
1765
|
+
message: 'Run',
|
1766
|
+
command: args_raw.join(' '),
|
1767
|
+
dir: $node.path.relative('', dir),
|
1768
|
+
});
|
1769
|
+
let killed = false;
|
1770
|
+
let timer;
|
1771
|
+
const std_data = [];
|
1772
|
+
const error_data = [];
|
1773
|
+
const add = (std_chunk, error_chunk) => {
|
1774
|
+
if (std_chunk)
|
1775
|
+
std_data.push(std_chunk);
|
1776
|
+
if (error_chunk)
|
1777
|
+
error_data.push(error_chunk);
|
1778
|
+
if (!timeout)
|
1779
|
+
return;
|
1780
|
+
clearTimeout(timer);
|
1781
|
+
timer = setTimeout(() => {
|
1782
|
+
const signal = killed ? 'SIGKILL' : 'SIGTERM';
|
1783
|
+
killed = true;
|
1784
|
+
add();
|
1785
|
+
sub.kill(signal);
|
1786
|
+
}, timeout);
|
1787
|
+
};
|
1788
|
+
add();
|
1789
|
+
sub.stdout?.on('data', data => add(data));
|
1790
|
+
sub.stderr?.on('data', data => add(undefined, data));
|
1791
|
+
const promise = new Promise((done, fail) => {
|
1792
|
+
const close = (error, status = null, signal = null) => {
|
1793
|
+
if (!timer && timeout)
|
1794
|
+
return;
|
1795
|
+
clearTimeout(timer);
|
1796
|
+
timer = undefined;
|
1797
|
+
const res = {
|
1798
|
+
pid: sub.pid,
|
1799
|
+
status,
|
1800
|
+
signal,
|
1801
|
+
get stdout() { return Buffer.concat(std_data); },
|
1802
|
+
get stderr() { return Buffer.concat(error_data); }
|
1803
|
+
};
|
1804
|
+
this.$mol_log3_done({
|
1805
|
+
place: '$mol_run_async',
|
1806
|
+
pid: sub.pid,
|
1807
|
+
message: 'Run',
|
1808
|
+
status,
|
1809
|
+
command: args_raw.join(' '),
|
1810
|
+
dir: $node.path.relative('', dir),
|
1811
|
+
});
|
1812
|
+
if (error || status || killed)
|
1813
|
+
return fail(new $mol_run_error((res.stderr.toString() || res.stdout.toString() || 'Run error') + (killed ? ', timeout' : ''), { signal, timeout: killed }, ...error ? [error] : []));
|
1814
|
+
done(res);
|
1815
|
+
};
|
1816
|
+
sub.on('disconnect', () => close(new Error('Disconnected')));
|
1817
|
+
sub.on('error', err => close(err));
|
1818
|
+
sub.on('exit', (status, signal) => close(null, status, signal));
|
1819
|
+
});
|
1820
|
+
return Object.assign(promise, { destructor: () => {
|
1821
|
+
clearTimeout(timer);
|
1822
|
+
sub.kill('SIGKILL');
|
1823
|
+
} });
|
1824
|
+
}
|
1825
|
+
$.$mol_run_async = $mol_run_async;
|
1826
|
+
function $mol_run(options) {
|
1827
|
+
if (!options.env)
|
1828
|
+
options = { ...options, env: this.$mol_env() };
|
1829
|
+
return $mol_wire_sync(this).$mol_run_async(options);
|
1830
|
+
}
|
1831
|
+
$.$mol_run = $mol_run;
|
1832
|
+
})($ || ($ = {}));
|
1833
|
+
|
1834
|
+
;
|
1835
|
+
"use strict";
|
1836
|
+
var $;
|
1837
|
+
(function ($) {
|
1838
|
+
function $mol_exec(dir, command, ...args) {
|
1839
|
+
return this.$mol_run({ command: [command, ...args], dir });
|
1840
|
+
}
|
1841
|
+
$.$mol_exec = $mol_exec;
|
1842
|
+
})($ || ($ = {}));
|
1843
|
+
|
1844
|
+
;
|
1845
|
+
"use strict";
|
1846
|
+
var $;
|
1847
|
+
(function ($) {
|
1848
|
+
$.$mol_crypto_native = $node.crypto.webcrypto;
|
1849
|
+
})($ || ($ = {}));
|
1850
|
+
|
1851
|
+
;
|
1852
|
+
"use strict";
|
1853
|
+
var $;
|
1854
|
+
(function ($) {
|
1855
|
+
const TextEncoder = globalThis.TextEncoder ?? $node.util.TextEncoder;
|
1856
|
+
const encoder = new TextEncoder();
|
1857
|
+
function $mol_charset_encode(value) {
|
1858
|
+
return encoder.encode(value);
|
1859
|
+
}
|
1860
|
+
$.$mol_charset_encode = $mol_charset_encode;
|
1861
|
+
})($ || ($ = {}));
|
1862
|
+
|
1863
|
+
;
|
1864
|
+
"use strict";
|
1865
|
+
var $;
|
1866
|
+
(function ($) {
|
1867
|
+
const algorithm = {
|
1868
|
+
name: 'AES-CBC',
|
1869
|
+
length: 128,
|
1870
|
+
tagLength: 32,
|
1871
|
+
};
|
1872
|
+
class $mol_crypto_secret extends Object {
|
1873
|
+
native;
|
1874
|
+
static size = 16;
|
1875
|
+
constructor(native) {
|
1876
|
+
super();
|
1877
|
+
this.native = native;
|
1878
|
+
}
|
1879
|
+
static async generate() {
|
1880
|
+
return new this(await $mol_crypto_native.subtle.generateKey(algorithm, true, ['encrypt', 'decrypt']));
|
1881
|
+
}
|
1882
|
+
static async from(serial) {
|
1883
|
+
return new this(await $mol_crypto_native.subtle.importKey('raw', serial, algorithm, true, ['encrypt', 'decrypt']));
|
1884
|
+
}
|
1885
|
+
static async pass(pass, salt) {
|
1886
|
+
return new this(await $mol_crypto_native.subtle.deriveKey({
|
1887
|
+
name: "PBKDF2",
|
1888
|
+
salt,
|
1889
|
+
iterations: 10_000,
|
1890
|
+
hash: "SHA-256",
|
1891
|
+
}, await $mol_crypto_native.subtle.importKey("raw", $mol_charset_encode(pass), "PBKDF2", false, ["deriveKey"]), algorithm, true, ['encrypt', 'decrypt']));
|
1892
|
+
}
|
1893
|
+
static async derive(private_serial, public_serial) {
|
1894
|
+
const ecdh = { name: "ECDH", namedCurve: "P-256" };
|
1895
|
+
const jwk = { crv: 'P-256', ext: true, kty: 'EC' };
|
1896
|
+
const private_key = await $mol_crypto_native.subtle.importKey('jwk', {
|
1897
|
+
...jwk,
|
1898
|
+
key_ops: ['deriveKey'],
|
1899
|
+
x: private_serial.slice(0, 43),
|
1900
|
+
y: private_serial.slice(43, 86),
|
1901
|
+
d: private_serial.slice(86, 129),
|
1902
|
+
}, ecdh, true, ['deriveKey']);
|
1903
|
+
const public_key = await $mol_crypto_native.subtle.importKey('jwk', {
|
1904
|
+
...jwk,
|
1905
|
+
key_ops: [],
|
1906
|
+
x: public_serial.slice(0, 43),
|
1907
|
+
y: public_serial.slice(43, 86),
|
1908
|
+
}, ecdh, true, []);
|
1909
|
+
const secret = await $mol_crypto_native.subtle.deriveKey({
|
1910
|
+
name: "ECDH",
|
1911
|
+
public: public_key,
|
1912
|
+
}, private_key, algorithm, true, ["encrypt", "decrypt"]);
|
1913
|
+
return new this(secret);
|
1914
|
+
}
|
1915
|
+
async serial() {
|
1916
|
+
return new Uint8Array(await $mol_crypto_native.subtle.exportKey('raw', this.native));
|
1917
|
+
}
|
1918
|
+
async encrypt(open, salt) {
|
1919
|
+
return new Uint8Array(await $mol_crypto_native.subtle.encrypt({
|
1920
|
+
...algorithm,
|
1921
|
+
iv: salt,
|
1922
|
+
}, this.native, open));
|
1923
|
+
}
|
1924
|
+
async decrypt(closed, salt) {
|
1925
|
+
return new Uint8Array(await $mol_crypto_native.subtle.decrypt({
|
1926
|
+
...algorithm,
|
1927
|
+
iv: salt,
|
1928
|
+
}, this.native, closed));
|
1929
|
+
}
|
1930
|
+
}
|
1931
|
+
$.$mol_crypto_secret = $mol_crypto_secret;
|
1932
|
+
})($ || ($ = {}));
|
1933
|
+
|
1934
|
+
;
|
1935
|
+
"use strict";
|
1936
|
+
var $;
|
1937
|
+
(function ($) {
|
1938
|
+
})($ || ($ = {}));
|
1939
|
+
|
1940
|
+
;
|
1941
|
+
"use strict";
|
1942
|
+
var $;
|
1943
|
+
(function ($) {
|
1944
|
+
$.$mol_dom_context = new $node.jsdom.JSDOM('', { url: 'https://localhost/' }).window;
|
1945
|
+
})($ || ($ = {}));
|
1946
|
+
|
1947
|
+
;
|
1948
|
+
"use strict";
|
1949
|
+
var $;
|
1950
|
+
(function ($) {
|
1951
|
+
async function $mol_crypto_secret_id() {
|
1952
|
+
const signed = this.$mol_dom_context.localStorage.getItem('$mol_crypto_secret');
|
1953
|
+
if (signed === '')
|
1954
|
+
return await this.$mol_crypto_secret_id_get();
|
1955
|
+
const id = await this.$mol_crypto_secret_id_new();
|
1956
|
+
this.$mol_dom_context.localStorage.setItem('$mol_crypto_secret', '');
|
1957
|
+
return id;
|
1958
|
+
}
|
1959
|
+
$.$mol_crypto_secret_id = $mol_crypto_secret_id;
|
1960
|
+
async function $mol_crypto_secret_id_new() {
|
1961
|
+
const cred = await this.$mol_dom_context.navigator.credentials.create({
|
1962
|
+
publicKey: {
|
1963
|
+
rp: {
|
1964
|
+
name: "$mol_crypto_id",
|
1965
|
+
},
|
1966
|
+
user: {
|
1967
|
+
id: new Uint8Array([0]),
|
1968
|
+
name: "",
|
1969
|
+
displayName: ""
|
1970
|
+
},
|
1971
|
+
pubKeyCredParams: [
|
1972
|
+
{ type: "public-key", alg: -7 },
|
1973
|
+
{ type: "public-key", alg: -257 },
|
1974
|
+
],
|
1975
|
+
challenge: new Uint8Array().buffer,
|
1976
|
+
},
|
1977
|
+
});
|
1978
|
+
return $mol_crypto_secret.from(cred.rawId);
|
1979
|
+
}
|
1980
|
+
$.$mol_crypto_secret_id_new = $mol_crypto_secret_id_new;
|
1981
|
+
async function $mol_crypto_secret_id_get() {
|
1982
|
+
const cred = await this.$mol_dom_context.navigator.credentials.get({
|
1983
|
+
mediation: 'silent',
|
1984
|
+
publicKey: {
|
1985
|
+
userVerification: 'discouraged',
|
1986
|
+
challenge: new Uint8Array().buffer,
|
1987
|
+
},
|
1988
|
+
});
|
1989
|
+
return $mol_crypto_secret.from(cred.rawId);
|
1990
|
+
}
|
1991
|
+
$.$mol_crypto_secret_id_get = $mol_crypto_secret_id_get;
|
1992
|
+
})($ || ($ = {}));
|
1993
|
+
|
1994
|
+
;
|
1995
|
+
"use strict";
|
1996
|
+
var $;
|
1997
|
+
(function ($) {
|
1998
|
+
function $mol_base64_encode(src) {
|
1999
|
+
throw new Error('Not implemented');
|
2000
|
+
}
|
2001
|
+
$.$mol_base64_encode = $mol_base64_encode;
|
2002
|
+
})($ || ($ = {}));
|
2003
|
+
|
2004
|
+
;
|
2005
|
+
"use strict";
|
2006
|
+
var $;
|
2007
|
+
(function ($) {
|
2008
|
+
function $mol_base64_encode_node(str) {
|
2009
|
+
if (!str)
|
2010
|
+
return '';
|
2011
|
+
if (Buffer.isBuffer(str))
|
2012
|
+
return str.toString('base64');
|
2013
|
+
return Buffer.from(str).toString('base64');
|
2014
|
+
}
|
2015
|
+
$.$mol_base64_encode_node = $mol_base64_encode_node;
|
2016
|
+
$.$mol_base64_encode = $mol_base64_encode_node;
|
2017
|
+
})($ || ($ = {}));
|
2018
|
+
|
2019
|
+
;
|
2020
|
+
"use strict";
|
2021
|
+
var $;
|
2022
|
+
(function ($) {
|
2023
|
+
function $mol_base64_decode(base64) {
|
2024
|
+
throw new Error('Not implemented');
|
2025
|
+
}
|
2026
|
+
$.$mol_base64_decode = $mol_base64_decode;
|
1076
2027
|
})($ || ($ = {}));
|
1077
2028
|
|
1078
2029
|
;
|
@@ -1596,38 +2547,6 @@ var $;
|
|
1596
2547
|
$mol_test_mocks.push($ => $.$mol_fail_log = () => false);
|
1597
2548
|
})($ || ($ = {}));
|
1598
2549
|
|
1599
|
-
;
|
1600
|
-
"use strict";
|
1601
|
-
var $;
|
1602
|
-
(function ($_1) {
|
1603
|
-
$mol_test_mocks.push($ => {
|
1604
|
-
$.$mol_log3_come = () => { };
|
1605
|
-
$.$mol_log3_done = () => { };
|
1606
|
-
$.$mol_log3_fail = () => { };
|
1607
|
-
$.$mol_log3_warn = () => { };
|
1608
|
-
$.$mol_log3_rise = () => { };
|
1609
|
-
$.$mol_log3_area = () => () => { };
|
1610
|
-
});
|
1611
|
-
})($ || ($ = {}));
|
1612
|
-
|
1613
|
-
;
|
1614
|
-
"use strict";
|
1615
|
-
|
1616
|
-
;
|
1617
|
-
"use strict";
|
1618
|
-
|
1619
|
-
;
|
1620
|
-
"use strict";
|
1621
|
-
|
1622
|
-
;
|
1623
|
-
"use strict";
|
1624
|
-
|
1625
|
-
;
|
1626
|
-
"use strict";
|
1627
|
-
|
1628
|
-
;
|
1629
|
-
"use strict";
|
1630
|
-
|
1631
2550
|
;
|
1632
2551
|
"use strict";
|
1633
2552
|
var $;
|
@@ -1689,6 +2608,15 @@ var $;
|
|
1689
2608
|
;
|
1690
2609
|
"use strict";
|
1691
2610
|
|
2611
|
+
;
|
2612
|
+
"use strict";
|
2613
|
+
|
2614
|
+
;
|
2615
|
+
"use strict";
|
2616
|
+
|
2617
|
+
;
|
2618
|
+
"use strict";
|
2619
|
+
|
1692
2620
|
;
|
1693
2621
|
"use strict";
|
1694
2622
|
var $;
|
@@ -2182,162 +3110,22 @@ var $;
|
|
2182
3110
|
$mol_assert_equal(calls, 0);
|
2183
3111
|
$mol_assert_equal(list[0], 12);
|
2184
3112
|
$mol_assert_equal(list[3], 15);
|
2185
|
-
$mol_assert_equal(list[4], undefined);
|
2186
|
-
$mol_assert_equal(calls, 2);
|
2187
|
-
},
|
2188
|
-
'prevent modification'() {
|
2189
|
-
const list = $mol_range2(i => i, () => 5);
|
2190
|
-
$mol_assert_fail(() => list.push(4), TypeError);
|
2191
|
-
$mol_assert_fail(() => list.pop(), TypeError);
|
2192
|
-
$mol_assert_fail(() => list.unshift(4), TypeError);
|
2193
|
-
$mol_assert_fail(() => list.shift(), TypeError);
|
2194
|
-
$mol_assert_fail(() => list.splice(1, 2), TypeError);
|
2195
|
-
$mol_assert_fail(() => list[1] = 2, TypeError);
|
2196
|
-
$mol_assert_fail(() => list.reverse(), TypeError);
|
2197
|
-
$mol_assert_fail(() => list.sort(), TypeError);
|
2198
|
-
$mol_assert_equal(list.toString(), '0,1,2,3,4');
|
2199
|
-
}
|
2200
|
-
});
|
2201
|
-
})($ || ($ = {}));
|
2202
|
-
|
2203
|
-
;
|
2204
|
-
"use strict";
|
2205
|
-
var $;
|
2206
|
-
(function ($) {
|
2207
|
-
$.$mol_compare_deep_cache = new WeakMap();
|
2208
|
-
function $mol_compare_deep(left, right) {
|
2209
|
-
if (Object.is(left, right))
|
2210
|
-
return true;
|
2211
|
-
if (left === null)
|
2212
|
-
return false;
|
2213
|
-
if (right === null)
|
2214
|
-
return false;
|
2215
|
-
if (typeof left !== 'object')
|
2216
|
-
return false;
|
2217
|
-
if (typeof right !== 'object')
|
2218
|
-
return false;
|
2219
|
-
const left_proto = Reflect.getPrototypeOf(left);
|
2220
|
-
const right_proto = Reflect.getPrototypeOf(right);
|
2221
|
-
if (left_proto !== right_proto)
|
2222
|
-
return false;
|
2223
|
-
if (left instanceof Boolean)
|
2224
|
-
return Object.is(left.valueOf(), right['valueOf']());
|
2225
|
-
if (left instanceof Number)
|
2226
|
-
return Object.is(left.valueOf(), right['valueOf']());
|
2227
|
-
if (left instanceof String)
|
2228
|
-
return Object.is(left.valueOf(), right['valueOf']());
|
2229
|
-
if (left instanceof Date)
|
2230
|
-
return Object.is(left.valueOf(), right['valueOf']());
|
2231
|
-
if (left instanceof RegExp)
|
2232
|
-
return left.source === right.source && left.flags === right.flags;
|
2233
|
-
if (left instanceof Error)
|
2234
|
-
return left.message === right.message && left.stack === right.stack;
|
2235
|
-
let left_cache = $.$mol_compare_deep_cache.get(left);
|
2236
|
-
if (left_cache) {
|
2237
|
-
const right_cache = left_cache.get(right);
|
2238
|
-
if (typeof right_cache === 'boolean')
|
2239
|
-
return right_cache;
|
2240
|
-
}
|
2241
|
-
else {
|
2242
|
-
left_cache = new WeakMap();
|
2243
|
-
$.$mol_compare_deep_cache.set(left, left_cache);
|
2244
|
-
}
|
2245
|
-
left_cache.set(right, true);
|
2246
|
-
let result;
|
2247
|
-
try {
|
2248
|
-
if (!left_proto)
|
2249
|
-
result = compare_pojo(left, right);
|
2250
|
-
else if (!Reflect.getPrototypeOf(left_proto))
|
2251
|
-
result = compare_pojo(left, right);
|
2252
|
-
else if (Symbol.toPrimitive in left)
|
2253
|
-
result = compare_primitive(left, right);
|
2254
|
-
else if (Array.isArray(left))
|
2255
|
-
result = compare_array(left, right);
|
2256
|
-
else if (left instanceof Set)
|
2257
|
-
result = compare_set(left, right);
|
2258
|
-
else if (left instanceof Map)
|
2259
|
-
result = compare_map(left, right);
|
2260
|
-
else if (ArrayBuffer.isView(left))
|
2261
|
-
result = compare_buffer(left, right);
|
2262
|
-
else if (Symbol.iterator in left)
|
2263
|
-
result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
|
2264
|
-
else
|
2265
|
-
result = false;
|
2266
|
-
}
|
2267
|
-
finally {
|
2268
|
-
left_cache.set(right, result);
|
2269
|
-
}
|
2270
|
-
return result;
|
2271
|
-
}
|
2272
|
-
$.$mol_compare_deep = $mol_compare_deep;
|
2273
|
-
function compare_array(left, right) {
|
2274
|
-
const len = left.length;
|
2275
|
-
if (len !== right.length)
|
2276
|
-
return false;
|
2277
|
-
for (let i = 0; i < len; ++i) {
|
2278
|
-
if (!$mol_compare_deep(left[i], right[i]))
|
2279
|
-
return false;
|
2280
|
-
}
|
2281
|
-
return true;
|
2282
|
-
}
|
2283
|
-
function compare_buffer(left, right) {
|
2284
|
-
const len = left.byteLength;
|
2285
|
-
if (len !== right.byteLength)
|
2286
|
-
return false;
|
2287
|
-
if (left instanceof DataView)
|
2288
|
-
return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, left.byteOffset, left.byteLength));
|
2289
|
-
for (let i = 0; i < len; ++i) {
|
2290
|
-
if (left[i] !== right[i])
|
2291
|
-
return false;
|
2292
|
-
}
|
2293
|
-
return true;
|
2294
|
-
}
|
2295
|
-
function compare_iterator(left, right) {
|
2296
|
-
while (true) {
|
2297
|
-
const left_next = left.next();
|
2298
|
-
const right_next = right.next();
|
2299
|
-
if (left_next.done !== right_next.done)
|
2300
|
-
return false;
|
2301
|
-
if (left_next.done)
|
2302
|
-
break;
|
2303
|
-
if (!$mol_compare_deep(left_next.value, right_next.value))
|
2304
|
-
return false;
|
2305
|
-
}
|
2306
|
-
return true;
|
2307
|
-
}
|
2308
|
-
function compare_set(left, right) {
|
2309
|
-
if (left.size !== right.size)
|
2310
|
-
return false;
|
2311
|
-
return compare_iterator(left.values(), right.values());
|
2312
|
-
}
|
2313
|
-
function compare_map(left, right) {
|
2314
|
-
if (left.size !== right.size)
|
2315
|
-
return false;
|
2316
|
-
return compare_iterator(left.keys(), right.keys())
|
2317
|
-
&& compare_iterator(left.values(), right.values());
|
2318
|
-
}
|
2319
|
-
function compare_pojo(left, right) {
|
2320
|
-
const left_keys = Object.getOwnPropertyNames(left);
|
2321
|
-
const right_keys = Object.getOwnPropertyNames(right);
|
2322
|
-
if (!compare_array(left_keys, right_keys))
|
2323
|
-
return false;
|
2324
|
-
for (let key of left_keys) {
|
2325
|
-
if (!$mol_compare_deep(left[key], right[key]))
|
2326
|
-
return false;
|
2327
|
-
}
|
2328
|
-
const left_syms = Object.getOwnPropertySymbols(left);
|
2329
|
-
const right_syms = Object.getOwnPropertySymbols(right);
|
2330
|
-
if (!compare_array(left_syms, right_syms))
|
2331
|
-
return false;
|
2332
|
-
for (let key of left_syms) {
|
2333
|
-
if (!$mol_compare_deep(left[key], right[key]))
|
2334
|
-
return false;
|
3113
|
+
$mol_assert_equal(list[4], undefined);
|
3114
|
+
$mol_assert_equal(calls, 2);
|
3115
|
+
},
|
3116
|
+
'prevent modification'() {
|
3117
|
+
const list = $mol_range2(i => i, () => 5);
|
3118
|
+
$mol_assert_fail(() => list.push(4), TypeError);
|
3119
|
+
$mol_assert_fail(() => list.pop(), TypeError);
|
3120
|
+
$mol_assert_fail(() => list.unshift(4), TypeError);
|
3121
|
+
$mol_assert_fail(() => list.shift(), TypeError);
|
3122
|
+
$mol_assert_fail(() => list.splice(1, 2), TypeError);
|
3123
|
+
$mol_assert_fail(() => list[1] = 2, TypeError);
|
3124
|
+
$mol_assert_fail(() => list.reverse(), TypeError);
|
3125
|
+
$mol_assert_fail(() => list.sort(), TypeError);
|
3126
|
+
$mol_assert_equal(list.toString(), '0,1,2,3,4');
|
2335
3127
|
}
|
2336
|
-
|
2337
|
-
}
|
2338
|
-
function compare_primitive(left, right) {
|
2339
|
-
return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
|
2340
|
-
}
|
3128
|
+
});
|
2341
3129
|
})($ || ($ = {}));
|
2342
3130
|
|
2343
3131
|
;
|
@@ -2595,16 +3383,25 @@ var $;
|
|
2595
3383
|
"use strict";
|
2596
3384
|
var $;
|
2597
3385
|
(function ($_1) {
|
2598
|
-
$
|
2599
|
-
|
2600
|
-
|
2601
|
-
|
2602
|
-
|
2603
|
-
|
2604
|
-
}
|
3386
|
+
$mol_test_mocks.push($ => {
|
3387
|
+
$.$mol_log3_come = () => { };
|
3388
|
+
$.$mol_log3_done = () => { };
|
3389
|
+
$.$mol_log3_fail = () => { };
|
3390
|
+
$.$mol_log3_warn = () => { };
|
3391
|
+
$.$mol_log3_rise = () => { };
|
3392
|
+
$.$mol_log3_area = () => () => { };
|
2605
3393
|
});
|
2606
3394
|
})($ || ($ = {}));
|
2607
3395
|
|
3396
|
+
;
|
3397
|
+
"use strict";
|
3398
|
+
|
3399
|
+
;
|
3400
|
+
"use strict";
|
3401
|
+
|
3402
|
+
;
|
3403
|
+
"use strict";
|
3404
|
+
|
2608
3405
|
;
|
2609
3406
|
"use strict";
|
2610
3407
|
var $;
|
@@ -2849,6 +3646,497 @@ var $;
|
|
2849
3646
|
});
|
2850
3647
|
})($ || ($ = {}));
|
2851
3648
|
|
3649
|
+
;
|
3650
|
+
"use strict";
|
3651
|
+
var $;
|
3652
|
+
(function ($_1) {
|
3653
|
+
$mol_test({
|
3654
|
+
'FQN of anon function'($) {
|
3655
|
+
const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
|
3656
|
+
$mol_assert_equal($$.$mol_func_name_test.name, '');
|
3657
|
+
$mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
|
3658
|
+
$mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
|
3659
|
+
},
|
3660
|
+
});
|
3661
|
+
})($ || ($ = {}));
|
3662
|
+
|
3663
|
+
;
|
3664
|
+
"use strict";
|
3665
|
+
var $;
|
3666
|
+
(function ($) {
|
3667
|
+
$mol_test({
|
3668
|
+
'auto name'() {
|
3669
|
+
class Invalid extends $mol_error_mix {
|
3670
|
+
}
|
3671
|
+
const mix = new Invalid('foo');
|
3672
|
+
$mol_assert_equal(mix.name, 'Invalid_Error');
|
3673
|
+
},
|
3674
|
+
'simpe mix'() {
|
3675
|
+
const mix = new $mol_error_mix('foo', {}, new Error('bar'), new Error('lol'));
|
3676
|
+
$mol_assert_equal(mix.message, 'foo');
|
3677
|
+
$mol_assert_equal(mix.errors.map(e => e.message), ['bar', 'lol']);
|
3678
|
+
},
|
3679
|
+
'provide additional info'() {
|
3680
|
+
class Invalid extends $mol_error_mix {
|
3681
|
+
}
|
3682
|
+
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' }));
|
3683
|
+
const hints = [];
|
3684
|
+
if (mix instanceof $mol_error_mix) {
|
3685
|
+
for (const er of mix.errors) {
|
3686
|
+
if (er instanceof Invalid) {
|
3687
|
+
hints.push(er.cause?.hint ?? '');
|
3688
|
+
}
|
3689
|
+
}
|
3690
|
+
}
|
3691
|
+
$mol_assert_equal(hints, ['> 8 letters', 'need capital letter']);
|
3692
|
+
},
|
3693
|
+
});
|
3694
|
+
})($ || ($ = {}));
|
3695
|
+
|
3696
|
+
;
|
3697
|
+
"use strict";
|
3698
|
+
var $;
|
3699
|
+
(function ($_1) {
|
3700
|
+
$mol_test({
|
3701
|
+
'Collect deps'() {
|
3702
|
+
const pub1 = new $mol_wire_pub;
|
3703
|
+
const pub2 = new $mol_wire_pub;
|
3704
|
+
const sub = new $mol_wire_pub_sub;
|
3705
|
+
const bu1 = sub.track_on();
|
3706
|
+
try {
|
3707
|
+
pub1.promote();
|
3708
|
+
pub2.promote();
|
3709
|
+
pub2.promote();
|
3710
|
+
}
|
3711
|
+
finally {
|
3712
|
+
sub.track_cut();
|
3713
|
+
sub.track_off(bu1);
|
3714
|
+
}
|
3715
|
+
pub1.emit();
|
3716
|
+
pub2.emit();
|
3717
|
+
$mol_assert_like(sub.pub_list, [pub1, pub2, pub2]);
|
3718
|
+
const bu2 = sub.track_on();
|
3719
|
+
try {
|
3720
|
+
pub1.promote();
|
3721
|
+
pub1.promote();
|
3722
|
+
pub2.promote();
|
3723
|
+
}
|
3724
|
+
finally {
|
3725
|
+
sub.track_cut();
|
3726
|
+
sub.track_off(bu2);
|
3727
|
+
}
|
3728
|
+
pub1.emit();
|
3729
|
+
pub2.emit();
|
3730
|
+
$mol_assert_like(sub.pub_list, [pub1, pub1, pub2]);
|
3731
|
+
},
|
3732
|
+
'cyclic detection'($) {
|
3733
|
+
const sub1 = new $mol_wire_pub_sub;
|
3734
|
+
const sub2 = new $mol_wire_pub_sub;
|
3735
|
+
const bu1 = sub1.track_on();
|
3736
|
+
try {
|
3737
|
+
const bu2 = sub2.track_on();
|
3738
|
+
try {
|
3739
|
+
$mol_assert_fail(() => sub1.promote(), 'Circular subscription');
|
3740
|
+
}
|
3741
|
+
finally {
|
3742
|
+
sub2.track_cut();
|
3743
|
+
sub2.track_off(bu2);
|
3744
|
+
}
|
3745
|
+
}
|
3746
|
+
finally {
|
3747
|
+
sub1.track_cut();
|
3748
|
+
sub1.track_off(bu1);
|
3749
|
+
}
|
3750
|
+
},
|
3751
|
+
});
|
3752
|
+
})($ || ($ = {}));
|
3753
|
+
|
3754
|
+
;
|
3755
|
+
"use strict";
|
3756
|
+
var $;
|
3757
|
+
(function ($) {
|
3758
|
+
$.$mol_after_mock_queue = [];
|
3759
|
+
function $mol_after_mock_warp() {
|
3760
|
+
const queue = $.$mol_after_mock_queue.splice(0);
|
3761
|
+
for (const task of queue)
|
3762
|
+
task();
|
3763
|
+
}
|
3764
|
+
$.$mol_after_mock_warp = $mol_after_mock_warp;
|
3765
|
+
class $mol_after_mock_commmon extends $mol_object2 {
|
3766
|
+
task;
|
3767
|
+
promise = Promise.resolve();
|
3768
|
+
cancelled = false;
|
3769
|
+
id;
|
3770
|
+
constructor(task) {
|
3771
|
+
super();
|
3772
|
+
this.task = task;
|
3773
|
+
$.$mol_after_mock_queue.push(task);
|
3774
|
+
}
|
3775
|
+
destructor() {
|
3776
|
+
const index = $.$mol_after_mock_queue.indexOf(this.task);
|
3777
|
+
if (index >= 0)
|
3778
|
+
$.$mol_after_mock_queue.splice(index, 1);
|
3779
|
+
}
|
3780
|
+
}
|
3781
|
+
$.$mol_after_mock_commmon = $mol_after_mock_commmon;
|
3782
|
+
class $mol_after_mock_timeout extends $mol_after_mock_commmon {
|
3783
|
+
delay;
|
3784
|
+
constructor(delay, task) {
|
3785
|
+
super(task);
|
3786
|
+
this.delay = delay;
|
3787
|
+
}
|
3788
|
+
}
|
3789
|
+
$.$mol_after_mock_timeout = $mol_after_mock_timeout;
|
3790
|
+
})($ || ($ = {}));
|
3791
|
+
|
3792
|
+
;
|
3793
|
+
"use strict";
|
3794
|
+
var $;
|
3795
|
+
(function ($_1) {
|
3796
|
+
$mol_test_mocks.push($ => {
|
3797
|
+
$.$mol_after_tick = $mol_after_mock_commmon;
|
3798
|
+
});
|
3799
|
+
})($ || ($ = {}));
|
3800
|
+
|
3801
|
+
;
|
3802
|
+
"use strict";
|
3803
|
+
var $;
|
3804
|
+
(function ($) {
|
3805
|
+
$mol_test({
|
3806
|
+
'Sync execution'() {
|
3807
|
+
class Sync extends $mol_object2 {
|
3808
|
+
static calc(a, b) {
|
3809
|
+
return a + b;
|
3810
|
+
}
|
3811
|
+
}
|
3812
|
+
__decorate([
|
3813
|
+
$mol_wire_method
|
3814
|
+
], Sync, "calc", null);
|
3815
|
+
$mol_assert_equal(Sync.calc(1, 2), 3);
|
3816
|
+
},
|
3817
|
+
async 'async <=> sync'() {
|
3818
|
+
class SyncAsync extends $mol_object2 {
|
3819
|
+
static async val(a) {
|
3820
|
+
return a;
|
3821
|
+
}
|
3822
|
+
static sum(a, b) {
|
3823
|
+
const syn = $mol_wire_sync(this);
|
3824
|
+
return syn.val(a) + syn.val(b);
|
3825
|
+
}
|
3826
|
+
static async calc(a, b) {
|
3827
|
+
return 5 + await $mol_wire_async(this).sum(a, b);
|
3828
|
+
}
|
3829
|
+
}
|
3830
|
+
$mol_assert_equal(await SyncAsync.calc(1, 2), 8);
|
3831
|
+
},
|
3832
|
+
async 'Idempotence control'() {
|
3833
|
+
class Idempotence extends $mol_object2 {
|
3834
|
+
static logs_idemp = 0;
|
3835
|
+
static logs_unidemp = 0;
|
3836
|
+
static log_idemp() {
|
3837
|
+
this.logs_idemp += 1;
|
3838
|
+
}
|
3839
|
+
static log_unidemp() {
|
3840
|
+
this.logs_unidemp += 1;
|
3841
|
+
}
|
3842
|
+
static async val(a) {
|
3843
|
+
return a;
|
3844
|
+
}
|
3845
|
+
static sum(a, b) {
|
3846
|
+
this.log_idemp();
|
3847
|
+
this.log_unidemp();
|
3848
|
+
const syn = $mol_wire_sync(this);
|
3849
|
+
return syn.val(a) + syn.val(b);
|
3850
|
+
}
|
3851
|
+
static async calc(a, b) {
|
3852
|
+
return 5 + await $mol_wire_async(this).sum(a, b);
|
3853
|
+
}
|
3854
|
+
}
|
3855
|
+
__decorate([
|
3856
|
+
$mol_wire_method
|
3857
|
+
], Idempotence, "log_idemp", null);
|
3858
|
+
$mol_assert_equal(await Idempotence.calc(1, 2), 8);
|
3859
|
+
$mol_assert_equal(Idempotence.logs_idemp, 1);
|
3860
|
+
$mol_assert_equal(Idempotence.logs_unidemp, 3);
|
3861
|
+
},
|
3862
|
+
async 'Error handling'() {
|
3863
|
+
class Handle extends $mol_object2 {
|
3864
|
+
static async sum(a, b) {
|
3865
|
+
$mol_fail(new Error('test error ' + (a + b)));
|
3866
|
+
}
|
3867
|
+
static check() {
|
3868
|
+
try {
|
3869
|
+
return $mol_wire_sync(Handle).sum(1, 2);
|
3870
|
+
}
|
3871
|
+
catch (error) {
|
3872
|
+
if ($mol_promise_like(error))
|
3873
|
+
$mol_fail_hidden(error);
|
3874
|
+
$mol_assert_equal(error.message, 'test error 3');
|
3875
|
+
}
|
3876
|
+
}
|
3877
|
+
}
|
3878
|
+
await $mol_wire_async(Handle).check();
|
3879
|
+
},
|
3880
|
+
});
|
3881
|
+
})($ || ($ = {}));
|
3882
|
+
|
3883
|
+
;
|
3884
|
+
"use strict";
|
3885
|
+
var $;
|
3886
|
+
(function ($) {
|
3887
|
+
function $mol_wire_async(obj) {
|
3888
|
+
let fiber;
|
3889
|
+
const temp = $mol_wire_task.getter(obj);
|
3890
|
+
return new Proxy(obj, {
|
3891
|
+
get(obj, field) {
|
3892
|
+
const val = obj[field];
|
3893
|
+
if (typeof val !== 'function')
|
3894
|
+
return val;
|
3895
|
+
let fiber;
|
3896
|
+
const temp = $mol_wire_task.getter(val);
|
3897
|
+
return function $mol_wire_async(...args) {
|
3898
|
+
fiber?.destructor();
|
3899
|
+
fiber = temp(obj, args);
|
3900
|
+
return fiber.async();
|
3901
|
+
};
|
3902
|
+
},
|
3903
|
+
apply(obj, self, args) {
|
3904
|
+
fiber?.destructor();
|
3905
|
+
fiber = temp(self, args);
|
3906
|
+
return fiber.async();
|
3907
|
+
},
|
3908
|
+
});
|
3909
|
+
}
|
3910
|
+
$.$mol_wire_async = $mol_wire_async;
|
3911
|
+
})($ || ($ = {}));
|
3912
|
+
|
3913
|
+
;
|
3914
|
+
"use strict";
|
3915
|
+
var $;
|
3916
|
+
(function ($_1) {
|
3917
|
+
$mol_test({
|
3918
|
+
'test types'($) {
|
3919
|
+
class A {
|
3920
|
+
static a() {
|
3921
|
+
return '';
|
3922
|
+
}
|
3923
|
+
static b() {
|
3924
|
+
return $mol_wire_async(this).a();
|
3925
|
+
}
|
3926
|
+
}
|
3927
|
+
},
|
3928
|
+
async 'Latest method calls wins'($) {
|
3929
|
+
class NameLogger extends $mol_object2 {
|
3930
|
+
static $ = $;
|
3931
|
+
static first = [];
|
3932
|
+
static last = [];
|
3933
|
+
static send(next) {
|
3934
|
+
$mol_wire_sync(this.first).push(next);
|
3935
|
+
this.$.$mol_wait_timeout(0);
|
3936
|
+
this.last.push(next);
|
3937
|
+
}
|
3938
|
+
}
|
3939
|
+
const name = $mol_wire_async(NameLogger).send;
|
3940
|
+
name('john');
|
3941
|
+
const promise = name('jin');
|
3942
|
+
$.$mol_after_mock_warp();
|
3943
|
+
await promise;
|
3944
|
+
$mol_assert_like(NameLogger.first, ['john', 'jin']);
|
3945
|
+
$mol_assert_like(NameLogger.last, ['jin']);
|
3946
|
+
},
|
3947
|
+
async 'Latest function calls wins'($) {
|
3948
|
+
const first = [];
|
3949
|
+
const last = [];
|
3950
|
+
function send_name(next) {
|
3951
|
+
$mol_wire_sync(first).push(next);
|
3952
|
+
$.$mol_wait_timeout(0);
|
3953
|
+
last.push(next);
|
3954
|
+
}
|
3955
|
+
const name = $mol_wire_async(send_name);
|
3956
|
+
name('john');
|
3957
|
+
const promise = name('jin');
|
3958
|
+
$.$mol_after_mock_warp();
|
3959
|
+
await promise;
|
3960
|
+
$mol_assert_like(first, ['john', 'jin']);
|
3961
|
+
$mol_assert_like(last, ['jin']);
|
3962
|
+
},
|
3963
|
+
});
|
3964
|
+
})($ || ($ = {}));
|
3965
|
+
|
3966
|
+
;
|
3967
|
+
"use strict";
|
3968
|
+
var $;
|
3969
|
+
(function ($) {
|
3970
|
+
function $mol_wire_method(host, field, descr) {
|
3971
|
+
if (!descr)
|
3972
|
+
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
3973
|
+
const orig = descr?.value ?? host[field];
|
3974
|
+
const sup = Reflect.getPrototypeOf(host);
|
3975
|
+
if (typeof sup[field] === 'function') {
|
3976
|
+
Object.defineProperty(orig, 'name', { value: sup[field].name });
|
3977
|
+
}
|
3978
|
+
const temp = $mol_wire_task.getter(orig);
|
3979
|
+
const value = function (...args) {
|
3980
|
+
const fiber = temp(this ?? null, args);
|
3981
|
+
return fiber.sync();
|
3982
|
+
};
|
3983
|
+
Object.defineProperty(value, 'name', { value: orig.name + ' ' });
|
3984
|
+
Object.assign(value, { orig });
|
3985
|
+
const descr2 = { ...descr, value };
|
3986
|
+
Reflect.defineProperty(host, field, descr2);
|
3987
|
+
return descr2;
|
3988
|
+
}
|
3989
|
+
$.$mol_wire_method = $mol_wire_method;
|
3990
|
+
})($ || ($ = {}));
|
3991
|
+
|
3992
|
+
;
|
3993
|
+
"use strict";
|
3994
|
+
var $;
|
3995
|
+
(function ($_1) {
|
3996
|
+
$mol_test({
|
3997
|
+
'test types'($) {
|
3998
|
+
class A {
|
3999
|
+
static a() {
|
4000
|
+
return Promise.resolve('');
|
4001
|
+
}
|
4002
|
+
static b() {
|
4003
|
+
return $mol_wire_sync(this).a();
|
4004
|
+
}
|
4005
|
+
}
|
4006
|
+
},
|
4007
|
+
async 'test method from host'($) {
|
4008
|
+
let count = 0;
|
4009
|
+
class A {
|
4010
|
+
static a() {
|
4011
|
+
return $mol_wire_sync(this).b();
|
4012
|
+
}
|
4013
|
+
static b() { return Promise.resolve(++count); }
|
4014
|
+
}
|
4015
|
+
$mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
|
4016
|
+
},
|
4017
|
+
async 'test function'($) {
|
4018
|
+
let count = 0;
|
4019
|
+
class A {
|
4020
|
+
static a() {
|
4021
|
+
return $mol_wire_sync(this.b)();
|
4022
|
+
}
|
4023
|
+
static b() { return Promise.resolve(++count); }
|
4024
|
+
}
|
4025
|
+
$mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
|
4026
|
+
},
|
4027
|
+
async 'test construct itself'($) {
|
4028
|
+
class A {
|
4029
|
+
static instances = [];
|
4030
|
+
static a() {
|
4031
|
+
const a = new ($mol_wire_sync(A))();
|
4032
|
+
this.instances.push(a);
|
4033
|
+
$mol_wire_sync(this).b();
|
4034
|
+
}
|
4035
|
+
static b() { return Promise.resolve(); }
|
4036
|
+
}
|
4037
|
+
await $mol_wire_async(A).a();
|
4038
|
+
$mol_assert_equal(A.instances.length, 2);
|
4039
|
+
$mol_assert_equal(A.instances[0] instanceof A);
|
4040
|
+
$mol_assert_equal(A.instances[0], A.instances[1]);
|
4041
|
+
}
|
4042
|
+
});
|
4043
|
+
})($ || ($ = {}));
|
4044
|
+
|
4045
|
+
;
|
4046
|
+
"use strict";
|
4047
|
+
var $;
|
4048
|
+
(function ($) {
|
4049
|
+
function $mol_promise() {
|
4050
|
+
let done;
|
4051
|
+
let fail;
|
4052
|
+
const promise = new Promise((d, f) => {
|
4053
|
+
done = d;
|
4054
|
+
fail = f;
|
4055
|
+
});
|
4056
|
+
return Object.assign(promise, {
|
4057
|
+
done,
|
4058
|
+
fail,
|
4059
|
+
});
|
4060
|
+
}
|
4061
|
+
$.$mol_promise = $mol_promise;
|
4062
|
+
})($ || ($ = {}));
|
4063
|
+
|
4064
|
+
;
|
4065
|
+
"use strict";
|
4066
|
+
var $;
|
4067
|
+
(function ($) {
|
4068
|
+
class $mol_after_timeout extends $mol_object2 {
|
4069
|
+
delay;
|
4070
|
+
task;
|
4071
|
+
id;
|
4072
|
+
constructor(delay, task) {
|
4073
|
+
super();
|
4074
|
+
this.delay = delay;
|
4075
|
+
this.task = task;
|
4076
|
+
this.id = setTimeout(task, delay);
|
4077
|
+
}
|
4078
|
+
destructor() {
|
4079
|
+
clearTimeout(this.id);
|
4080
|
+
}
|
4081
|
+
}
|
4082
|
+
$.$mol_after_timeout = $mol_after_timeout;
|
4083
|
+
})($ || ($ = {}));
|
4084
|
+
|
4085
|
+
;
|
4086
|
+
"use strict";
|
4087
|
+
var $;
|
4088
|
+
(function ($_1) {
|
4089
|
+
$mol_test_mocks.push($ => {
|
4090
|
+
$.$mol_after_timeout = $mol_after_mock_timeout;
|
4091
|
+
});
|
4092
|
+
})($ || ($ = {}));
|
4093
|
+
|
4094
|
+
;
|
4095
|
+
"use strict";
|
4096
|
+
var $;
|
4097
|
+
(function ($) {
|
4098
|
+
function $mol_wait_timeout_async(timeout) {
|
4099
|
+
const promise = $mol_promise();
|
4100
|
+
const task = new this.$mol_after_timeout(timeout, () => promise.done());
|
4101
|
+
return Object.assign(promise, {
|
4102
|
+
destructor: () => task.destructor()
|
4103
|
+
});
|
4104
|
+
}
|
4105
|
+
$.$mol_wait_timeout_async = $mol_wait_timeout_async;
|
4106
|
+
function $mol_wait_timeout(timeout) {
|
4107
|
+
return this.$mol_wire_sync(this).$mol_wait_timeout_async(timeout);
|
4108
|
+
}
|
4109
|
+
$.$mol_wait_timeout = $mol_wait_timeout;
|
4110
|
+
})($ || ($ = {}));
|
4111
|
+
|
4112
|
+
;
|
4113
|
+
"use strict";
|
4114
|
+
var $;
|
4115
|
+
(function ($_1) {
|
4116
|
+
$mol_test({
|
4117
|
+
async 'exec timeout auto kill child process'($) {
|
4118
|
+
let close_mock = () => { };
|
4119
|
+
const context_mock = $.$mol_ambient({
|
4120
|
+
$mol_run_spawn: () => ({
|
4121
|
+
on(name, cb) {
|
4122
|
+
if (name === 'exit')
|
4123
|
+
close_mock = cb;
|
4124
|
+
},
|
4125
|
+
kill() { close_mock(); }
|
4126
|
+
})
|
4127
|
+
});
|
4128
|
+
let message = '';
|
4129
|
+
try {
|
4130
|
+
const res = await $mol_wire_async(context_mock).$mol_run({ command: 'sleep 10', dir: '.', timeout: 10, env: { 'MOL_RUN_ASYNC': '1' } });
|
4131
|
+
}
|
4132
|
+
catch (e) {
|
4133
|
+
message = e.message;
|
4134
|
+
}
|
4135
|
+
$mol_assert_equal(message, 'Run error, timeout');
|
4136
|
+
}
|
4137
|
+
});
|
4138
|
+
})($ || ($ = {}));
|
4139
|
+
|
2852
4140
|
;
|
2853
4141
|
"use strict";
|
2854
4142
|
var $;
|