mol_crypto_lib 0.1.1288 → 0.1.1289

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.js CHANGED
@@ -153,6 +153,68 @@ require = (req => Object.assign(function require(name) {
153
153
  return $node[name];
154
154
  }, req))(require);
155
155
 
156
+ ;
157
+ "use strict";
158
+ var $;
159
+ (function ($) {
160
+ const named = new WeakSet();
161
+ function $mol_func_name(func) {
162
+ let name = func.name;
163
+ if (name?.length > 1)
164
+ return name;
165
+ if (named.has(func))
166
+ return name;
167
+ for (let key in this) {
168
+ try {
169
+ if (this[key] !== func)
170
+ continue;
171
+ name = key;
172
+ Object.defineProperty(func, 'name', { value: name });
173
+ break;
174
+ }
175
+ catch { }
176
+ }
177
+ named.add(func);
178
+ return name;
179
+ }
180
+ $.$mol_func_name = $mol_func_name;
181
+ function $mol_func_name_from(target, source) {
182
+ Object.defineProperty(target, 'name', { value: source.name });
183
+ return target;
184
+ }
185
+ $.$mol_func_name_from = $mol_func_name_from;
186
+ })($ || ($ = {}));
187
+
188
+ ;
189
+ "use strict";
190
+ var $;
191
+ (function ($) {
192
+ class $mol_error_mix extends AggregateError {
193
+ cause;
194
+ name = $$.$mol_func_name(this.constructor).replace(/^\$/, '') + '_Error';
195
+ constructor(message, cause = {}, ...errors) {
196
+ super(errors, message, { cause });
197
+ this.cause = cause;
198
+ const stack_get = Object.getOwnPropertyDescriptor(this, 'stack')?.get ?? (() => super.stack);
199
+ Object.defineProperty(this, 'stack', {
200
+ 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()
201
+ .replace(/at /gm, ' at ')
202
+ .replace(/^(?! +at )(.*)/gm, ' at | $1 (#)')).join('\n')
203
+ });
204
+ }
205
+ static [Symbol.toPrimitive]() {
206
+ return this.toString();
207
+ }
208
+ static toString() {
209
+ return $$.$mol_func_name(this);
210
+ }
211
+ static make(...params) {
212
+ return new this(...params);
213
+ }
214
+ }
215
+ $.$mol_error_mix = $mol_error_mix;
216
+ })($ || ($ = {}));
217
+
156
218
  ;
157
219
  "use strict";
158
220
  var $;
@@ -284,38 +346,6 @@ var $;
284
346
  ;
285
347
  "use strict";
286
348
 
287
- ;
288
- "use strict";
289
- var $;
290
- (function ($) {
291
- const named = new WeakSet();
292
- function $mol_func_name(func) {
293
- let name = func.name;
294
- if (name?.length > 1)
295
- return name;
296
- if (named.has(func))
297
- return name;
298
- for (let key in this) {
299
- try {
300
- if (this[key] !== func)
301
- continue;
302
- name = key;
303
- Object.defineProperty(func, 'name', { value: name });
304
- break;
305
- }
306
- catch { }
307
- }
308
- named.add(func);
309
- return name;
310
- }
311
- $.$mol_func_name = $mol_func_name;
312
- function $mol_func_name_from(target, source) {
313
- Object.defineProperty(target, 'name', { value: source.name });
314
- return target;
315
- }
316
- $.$mol_func_name_from = $mol_func_name_from;
317
- })($ || ($ = {}));
318
-
319
349
  ;
320
350
  "use strict";
321
351
  var $;
@@ -875,26 +905,921 @@ var $;
875
905
  "use strict";
876
906
  var $;
877
907
  (function ($) {
878
- function $mol_exec(dir, command, ...args) {
879
- let [app, ...args0] = command.split(' ');
880
- args = [...args0, ...args];
908
+ let $mol_wire_cursor;
909
+ (function ($mol_wire_cursor) {
910
+ $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
911
+ $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
912
+ $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
913
+ $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
914
+ })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
915
+ })($ || ($ = {}));
916
+
917
+ ;
918
+ "use strict";
919
+ var $;
920
+ (function ($) {
921
+ class $mol_wire_pub extends Object {
922
+ data = [];
923
+ static get [Symbol.species]() {
924
+ return Array;
925
+ }
926
+ sub_from = 0;
927
+ get sub_list() {
928
+ const res = [];
929
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
930
+ res.push(this.data[i]);
931
+ }
932
+ return res;
933
+ }
934
+ get sub_empty() {
935
+ return this.sub_from === this.data.length;
936
+ }
937
+ sub_on(sub, pub_pos) {
938
+ const pos = this.data.length;
939
+ this.data.push(sub, pub_pos);
940
+ return pos;
941
+ }
942
+ sub_off(sub_pos) {
943
+ if (!(sub_pos < this.data.length)) {
944
+ $mol_fail(new Error(`Wrong pos ${sub_pos}`));
945
+ }
946
+ const end = this.data.length - 2;
947
+ if (sub_pos !== end) {
948
+ this.peer_move(end, sub_pos);
949
+ }
950
+ this.data.pop();
951
+ this.data.pop();
952
+ if (this.data.length === this.sub_from)
953
+ this.reap();
954
+ }
955
+ reap() { }
956
+ promote() {
957
+ $mol_wire_auto()?.track_next(this);
958
+ }
959
+ fresh() { }
960
+ complete() { }
961
+ get incompleted() {
962
+ return false;
963
+ }
964
+ emit(quant = $mol_wire_cursor.stale) {
965
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
966
+ ;
967
+ this.data[i].absorb(quant);
968
+ }
969
+ }
970
+ peer_move(from_pos, to_pos) {
971
+ const peer = this.data[from_pos];
972
+ const self_pos = this.data[from_pos + 1];
973
+ this.data[to_pos] = peer;
974
+ this.data[to_pos + 1] = self_pos;
975
+ peer.peer_repos(self_pos, to_pos);
976
+ }
977
+ peer_repos(peer_pos, self_pos) {
978
+ this.data[peer_pos + 1] = self_pos;
979
+ }
980
+ }
981
+ $.$mol_wire_pub = $mol_wire_pub;
982
+ })($ || ($ = {}));
983
+
984
+ ;
985
+ "use strict";
986
+
987
+ ;
988
+ "use strict";
989
+ var $;
990
+ (function ($) {
991
+ $.$mol_wire_auto_sub = null;
992
+ function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
993
+ return $.$mol_wire_auto_sub = next;
994
+ }
995
+ $.$mol_wire_auto = $mol_wire_auto;
996
+ $.$mol_wire_affected = [];
997
+ })($ || ($ = {}));
998
+
999
+ ;
1000
+ "use strict";
1001
+ var $;
1002
+ (function ($) {
1003
+ $['devtoolsFormatters'] ||= [];
1004
+ function $mol_dev_format_register(config) {
1005
+ $['devtoolsFormatters'].push(config);
1006
+ }
1007
+ $.$mol_dev_format_register = $mol_dev_format_register;
1008
+ $.$mol_dev_format_head = Symbol('$mol_dev_format_head');
1009
+ $.$mol_dev_format_body = Symbol('$mol_dev_format_body');
1010
+ $mol_dev_format_register({
1011
+ header: (val, config = false) => {
1012
+ if (config)
1013
+ return null;
1014
+ if (!val)
1015
+ return null;
1016
+ if ($.$mol_dev_format_head in val) {
1017
+ try {
1018
+ return val[$.$mol_dev_format_head]();
1019
+ }
1020
+ catch (error) {
1021
+ return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
1022
+ }
1023
+ }
1024
+ if (typeof val === 'function') {
1025
+ return $mol_dev_format_native(val);
1026
+ }
1027
+ if (Symbol.toStringTag in val) {
1028
+ return $mol_dev_format_native(val);
1029
+ }
1030
+ return null;
1031
+ },
1032
+ hasBody: val => val[$.$mol_dev_format_body],
1033
+ body: val => val[$.$mol_dev_format_body](),
1034
+ });
1035
+ function $mol_dev_format_native(obj) {
1036
+ if (typeof obj === 'undefined')
1037
+ return $.$mol_dev_format_shade('undefined');
1038
+ return [
1039
+ 'object',
1040
+ {
1041
+ object: obj,
1042
+ config: true,
1043
+ },
1044
+ ];
1045
+ }
1046
+ $.$mol_dev_format_native = $mol_dev_format_native;
1047
+ function $mol_dev_format_auto(obj) {
1048
+ if (obj == null)
1049
+ return $.$mol_dev_format_shade(String(obj));
1050
+ return [
1051
+ 'object',
1052
+ {
1053
+ object: obj,
1054
+ config: false,
1055
+ },
1056
+ ];
1057
+ }
1058
+ $.$mol_dev_format_auto = $mol_dev_format_auto;
1059
+ function $mol_dev_format_element(element, style, ...content) {
1060
+ const styles = [];
1061
+ for (let key in style)
1062
+ styles.push(`${key} : ${style[key]}`);
1063
+ return [
1064
+ element,
1065
+ {
1066
+ style: styles.join(' ; '),
1067
+ },
1068
+ ...content,
1069
+ ];
1070
+ }
1071
+ $.$mol_dev_format_element = $mol_dev_format_element;
1072
+ function $mol_dev_format_span(style, ...content) {
1073
+ return $mol_dev_format_element('span', {
1074
+ ...style,
1075
+ }, ...content);
1076
+ }
1077
+ $.$mol_dev_format_span = $mol_dev_format_span;
1078
+ $.$mol_dev_format_div = $mol_dev_format_element.bind(null, 'div');
1079
+ $.$mol_dev_format_ol = $mol_dev_format_element.bind(null, 'ol');
1080
+ $.$mol_dev_format_li = $mol_dev_format_element.bind(null, 'li');
1081
+ $.$mol_dev_format_table = $mol_dev_format_element.bind(null, 'table');
1082
+ $.$mol_dev_format_tr = $mol_dev_format_element.bind(null, 'tr');
1083
+ $.$mol_dev_format_td = $mol_dev_format_element.bind(null, 'td');
1084
+ $.$mol_dev_format_accent = $mol_dev_format_span.bind(null, {
1085
+ 'color': 'magenta',
1086
+ });
1087
+ $.$mol_dev_format_strong = $mol_dev_format_span.bind(null, {
1088
+ 'font-weight': 'bold',
1089
+ });
1090
+ $.$mol_dev_format_string = $mol_dev_format_span.bind(null, {
1091
+ 'color': 'green',
1092
+ });
1093
+ $.$mol_dev_format_shade = $mol_dev_format_span.bind(null, {
1094
+ 'color': 'gray',
1095
+ });
1096
+ $.$mol_dev_format_indent = $.$mol_dev_format_div.bind(null, {
1097
+ 'margin-left': '13px'
1098
+ });
1099
+ })($ || ($ = {}));
1100
+
1101
+ ;
1102
+ "use strict";
1103
+ var $;
1104
+ (function ($) {
1105
+ class $mol_wire_pub_sub extends $mol_wire_pub {
1106
+ pub_from = 0;
1107
+ cursor = $mol_wire_cursor.stale;
1108
+ get temp() {
1109
+ return false;
1110
+ }
1111
+ get pub_list() {
1112
+ const res = [];
1113
+ const max = this.cursor >= 0 ? this.cursor : this.sub_from;
1114
+ for (let i = this.pub_from; i < max; i += 2) {
1115
+ if (this.data[i])
1116
+ res.push(this.data[i]);
1117
+ }
1118
+ return res;
1119
+ }
1120
+ track_on() {
1121
+ this.cursor = this.pub_from;
1122
+ const sub = $mol_wire_auto();
1123
+ $mol_wire_auto(this);
1124
+ return sub;
1125
+ }
1126
+ promote() {
1127
+ if (this.cursor >= this.pub_from) {
1128
+ $mol_fail(new Error('Circular subscription'));
1129
+ }
1130
+ super.promote();
1131
+ }
1132
+ track_next(pub) {
1133
+ if (this.cursor < 0)
1134
+ $mol_fail(new Error('Promo to non begun sub'));
1135
+ if (this.cursor < this.sub_from) {
1136
+ const next = this.data[this.cursor];
1137
+ if (pub === undefined)
1138
+ return next ?? null;
1139
+ if (next === pub) {
1140
+ this.cursor += 2;
1141
+ return next;
1142
+ }
1143
+ if (next) {
1144
+ if (this.sub_from < this.data.length) {
1145
+ this.peer_move(this.sub_from, this.data.length);
1146
+ }
1147
+ this.peer_move(this.cursor, this.sub_from);
1148
+ this.sub_from += 2;
1149
+ }
1150
+ }
1151
+ else {
1152
+ if (pub === undefined)
1153
+ return null;
1154
+ if (this.sub_from < this.data.length) {
1155
+ this.peer_move(this.sub_from, this.data.length);
1156
+ }
1157
+ this.sub_from += 2;
1158
+ }
1159
+ this.data[this.cursor] = pub;
1160
+ this.data[this.cursor + 1] = pub.sub_on(this, this.cursor);
1161
+ this.cursor += 2;
1162
+ return pub;
1163
+ }
1164
+ track_off(sub) {
1165
+ $mol_wire_auto(sub);
1166
+ if (this.cursor < 0) {
1167
+ $mol_fail(new Error('End of non begun sub'));
1168
+ }
1169
+ for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
1170
+ const pub = this.data[cursor];
1171
+ pub.fresh();
1172
+ }
1173
+ this.cursor = $mol_wire_cursor.fresh;
1174
+ }
1175
+ pub_off(sub_pos) {
1176
+ this.data[sub_pos] = undefined;
1177
+ this.data[sub_pos + 1] = undefined;
1178
+ }
1179
+ destructor() {
1180
+ for (let cursor = this.data.length - 2; cursor >= this.sub_from; cursor -= 2) {
1181
+ const sub = this.data[cursor];
1182
+ const pos = this.data[cursor + 1];
1183
+ sub.pub_off(pos);
1184
+ this.data.pop();
1185
+ this.data.pop();
1186
+ }
1187
+ this.cursor = this.pub_from;
1188
+ this.track_cut();
1189
+ this.cursor = $mol_wire_cursor.final;
1190
+ }
1191
+ track_cut() {
1192
+ if (this.cursor < this.pub_from) {
1193
+ $mol_fail(new Error('Cut of non begun sub'));
1194
+ }
1195
+ let tail = 0;
1196
+ for (let cursor = this.cursor; cursor < this.sub_from; cursor += 2) {
1197
+ const pub = this.data[cursor];
1198
+ pub?.sub_off(this.data[cursor + 1]);
1199
+ if (this.sub_from < this.data.length) {
1200
+ this.peer_move(this.data.length - 2, cursor);
1201
+ this.data.pop();
1202
+ this.data.pop();
1203
+ }
1204
+ else {
1205
+ ++tail;
1206
+ }
1207
+ }
1208
+ for (; tail; --tail) {
1209
+ this.data.pop();
1210
+ this.data.pop();
1211
+ }
1212
+ this.sub_from = this.cursor;
1213
+ }
1214
+ complete() { }
1215
+ complete_pubs() {
1216
+ const limit = this.cursor < 0 ? this.sub_from : this.cursor;
1217
+ for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
1218
+ const pub = this.data[cursor];
1219
+ if (pub?.incompleted)
1220
+ return;
1221
+ }
1222
+ for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
1223
+ const pub = this.data[cursor];
1224
+ pub?.complete();
1225
+ }
1226
+ }
1227
+ absorb(quant = $mol_wire_cursor.stale) {
1228
+ if (this.cursor === $mol_wire_cursor.final)
1229
+ return;
1230
+ if (this.cursor >= quant)
1231
+ return;
1232
+ this.cursor = quant;
1233
+ this.emit($mol_wire_cursor.doubt);
1234
+ }
1235
+ [$mol_dev_format_head]() {
1236
+ return $mol_dev_format_native(this);
1237
+ }
1238
+ get pub_empty() {
1239
+ return this.sub_from === this.pub_from;
1240
+ }
1241
+ }
1242
+ $.$mol_wire_pub_sub = $mol_wire_pub_sub;
1243
+ })($ || ($ = {}));
1244
+
1245
+ ;
1246
+ "use strict";
1247
+ var $;
1248
+ (function ($) {
1249
+ class $mol_after_tick extends $mol_object2 {
1250
+ task;
1251
+ static promise = null;
1252
+ cancelled = false;
1253
+ constructor(task) {
1254
+ super();
1255
+ this.task = task;
1256
+ if (!$mol_after_tick.promise)
1257
+ $mol_after_tick.promise = Promise.resolve().then(() => {
1258
+ $mol_after_tick.promise = null;
1259
+ });
1260
+ $mol_after_tick.promise.then(() => {
1261
+ if (this.cancelled)
1262
+ return;
1263
+ task();
1264
+ });
1265
+ }
1266
+ destructor() {
1267
+ this.cancelled = true;
1268
+ }
1269
+ }
1270
+ $.$mol_after_tick = $mol_after_tick;
1271
+ })($ || ($ = {}));
1272
+
1273
+ ;
1274
+ "use strict";
1275
+ var $;
1276
+ (function ($) {
1277
+ const handled = new WeakSet();
1278
+ class $mol_wire_fiber extends $mol_wire_pub_sub {
1279
+ task;
1280
+ host;
1281
+ static warm = true;
1282
+ static planning = new Set();
1283
+ static reaping = new Set();
1284
+ static plan_task = null;
1285
+ static plan() {
1286
+ if (this.plan_task)
1287
+ return;
1288
+ this.plan_task = new $mol_after_tick(() => {
1289
+ try {
1290
+ this.sync();
1291
+ }
1292
+ finally {
1293
+ $mol_wire_fiber.plan_task = null;
1294
+ }
1295
+ });
1296
+ }
1297
+ static sync() {
1298
+ while (this.planning.size) {
1299
+ for (const fiber of this.planning) {
1300
+ this.planning.delete(fiber);
1301
+ if (fiber.cursor >= 0)
1302
+ continue;
1303
+ if (fiber.cursor === $mol_wire_cursor.final)
1304
+ continue;
1305
+ fiber.fresh();
1306
+ }
1307
+ }
1308
+ while (this.reaping.size) {
1309
+ const fibers = this.reaping;
1310
+ this.reaping = new Set;
1311
+ for (const fiber of fibers) {
1312
+ if (!fiber.sub_empty)
1313
+ continue;
1314
+ fiber.destructor();
1315
+ }
1316
+ }
1317
+ }
1318
+ [Symbol.toStringTag];
1319
+ cache = undefined;
1320
+ get args() {
1321
+ return this.data.slice(0, this.pub_from);
1322
+ }
1323
+ result() {
1324
+ if ($mol_promise_like(this.cache))
1325
+ return;
1326
+ if (this.cache instanceof Error)
1327
+ return;
1328
+ return this.cache;
1329
+ }
1330
+ get incompleted() {
1331
+ return $mol_promise_like(this.cache);
1332
+ }
1333
+ field() {
1334
+ return this.task.name + '<>';
1335
+ }
1336
+ constructor(id, task, host, args) {
1337
+ super();
1338
+ this.task = task;
1339
+ this.host = host;
1340
+ if (args)
1341
+ this.data.push(...args);
1342
+ this.pub_from = this.sub_from = args?.length ?? 0;
1343
+ this[Symbol.toStringTag] = id;
1344
+ }
1345
+ plan() {
1346
+ $mol_wire_fiber.planning.add(this);
1347
+ $mol_wire_fiber.plan();
1348
+ return this;
1349
+ }
1350
+ reap() {
1351
+ $mol_wire_fiber.reaping.add(this);
1352
+ $mol_wire_fiber.plan();
1353
+ }
1354
+ toString() {
1355
+ return this[Symbol.toStringTag];
1356
+ }
1357
+ toJSON() {
1358
+ return this[Symbol.toStringTag];
1359
+ }
1360
+ [$mol_dev_format_head]() {
1361
+ const cursor = {
1362
+ [$mol_wire_cursor.stale]: '🔴',
1363
+ [$mol_wire_cursor.doubt]: '🟡',
1364
+ [$mol_wire_cursor.fresh]: '🟢',
1365
+ [$mol_wire_cursor.final]: '🔵',
1366
+ }[this.cursor] ?? this.cursor.toString();
1367
+ return $mol_dev_format_div({}, $mol_owning_check(this, this.cache)
1368
+ ? $mol_dev_format_auto({
1369
+ [$mol_dev_format_head]: () => $mol_dev_format_shade(cursor),
1370
+ [$mol_dev_format_body]: () => $mol_dev_format_native(this),
1371
+ })
1372
+ : $mol_dev_format_shade($mol_dev_format_native(this), cursor), $mol_dev_format_auto(this.cache));
1373
+ }
1374
+ get $() {
1375
+ return (this.host ?? this.task)['$'];
1376
+ }
1377
+ emit(quant = $mol_wire_cursor.stale) {
1378
+ if (this.sub_empty)
1379
+ this.plan();
1380
+ else
1381
+ super.emit(quant);
1382
+ }
1383
+ fresh() {
1384
+ if (this.cursor === $mol_wire_cursor.fresh)
1385
+ return;
1386
+ if (this.cursor === $mol_wire_cursor.final)
1387
+ return;
1388
+ check: if (this.cursor === $mol_wire_cursor.doubt) {
1389
+ for (let i = this.pub_from; i < this.sub_from; i += 2) {
1390
+ ;
1391
+ this.data[i]?.fresh();
1392
+ if (this.cursor !== $mol_wire_cursor.doubt)
1393
+ break check;
1394
+ }
1395
+ this.cursor = $mol_wire_cursor.fresh;
1396
+ return;
1397
+ }
1398
+ const bu = this.track_on();
1399
+ let result;
1400
+ try {
1401
+ switch (this.pub_from) {
1402
+ case 0:
1403
+ result = this.task.call(this.host);
1404
+ break;
1405
+ case 1:
1406
+ result = this.task.call(this.host, this.data[0]);
1407
+ break;
1408
+ default:
1409
+ result = this.task.call(this.host, ...this.args);
1410
+ break;
1411
+ }
1412
+ if ($mol_promise_like(result) && !handled.has(result)) {
1413
+ const put = (res) => {
1414
+ if (this.cache === result)
1415
+ this.put(res);
1416
+ return res;
1417
+ };
1418
+ result = result.then(put, put);
1419
+ }
1420
+ }
1421
+ catch (error) {
1422
+ if (error instanceof Error || $mol_promise_like(error)) {
1423
+ result = error;
1424
+ }
1425
+ else {
1426
+ result = new Error(String(error), { cause: error });
1427
+ }
1428
+ if ($mol_promise_like(result) && !handled.has(result)) {
1429
+ result = result.finally(() => {
1430
+ if (this.cache === result)
1431
+ this.absorb();
1432
+ });
1433
+ }
1434
+ }
1435
+ if ($mol_promise_like(result) && !handled.has(result)) {
1436
+ result = Object.assign(result, {
1437
+ destructor: result['destructor'] ?? (() => { })
1438
+ });
1439
+ handled.add(result);
1440
+ const error = new Error(`Promise in ${this}`);
1441
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
1442
+ }
1443
+ if (!$mol_promise_like(result)) {
1444
+ this.track_cut();
1445
+ }
1446
+ this.track_off(bu);
1447
+ this.put(result);
1448
+ return this;
1449
+ }
1450
+ refresh() {
1451
+ this.cursor = $mol_wire_cursor.stale;
1452
+ this.fresh();
1453
+ }
1454
+ sync() {
1455
+ if (!$mol_wire_fiber.warm) {
1456
+ return this.result();
1457
+ }
1458
+ this.promote();
1459
+ this.fresh();
1460
+ if (this.cache instanceof Error) {
1461
+ return $mol_fail_hidden(this.cache);
1462
+ }
1463
+ if ($mol_promise_like(this.cache)) {
1464
+ return $mol_fail_hidden(this.cache);
1465
+ }
1466
+ return this.cache;
1467
+ }
1468
+ async async() {
1469
+ while (true) {
1470
+ this.fresh();
1471
+ if (this.cache instanceof Error) {
1472
+ $mol_fail_hidden(this.cache);
1473
+ }
1474
+ if (!$mol_promise_like(this.cache))
1475
+ return this.cache;
1476
+ await Promise.race([this.cache, this.step()]);
1477
+ if (!$mol_promise_like(this.cache))
1478
+ return this.cache;
1479
+ if (this.cursor === $mol_wire_cursor.final) {
1480
+ await new Promise(() => { });
1481
+ }
1482
+ }
1483
+ }
1484
+ step() {
1485
+ return new Promise(done => {
1486
+ const sub = new $mol_wire_pub_sub;
1487
+ const prev = sub.track_on();
1488
+ sub.track_next(this);
1489
+ sub.track_off(prev);
1490
+ sub.absorb = () => {
1491
+ done(null);
1492
+ setTimeout(() => sub.destructor());
1493
+ };
1494
+ });
1495
+ }
1496
+ }
1497
+ $.$mol_wire_fiber = $mol_wire_fiber;
1498
+ })($ || ($ = {}));
1499
+
1500
+ ;
1501
+ "use strict";
1502
+ var $;
1503
+ (function ($) {
1504
+ $.$mol_compare_deep_cache = new WeakMap();
1505
+ function $mol_compare_deep(left, right) {
1506
+ if (Object.is(left, right))
1507
+ return true;
1508
+ if (left === null)
1509
+ return false;
1510
+ if (right === null)
1511
+ return false;
1512
+ if (typeof left !== 'object')
1513
+ return false;
1514
+ if (typeof right !== 'object')
1515
+ return false;
1516
+ const left_proto = Reflect.getPrototypeOf(left);
1517
+ const right_proto = Reflect.getPrototypeOf(right);
1518
+ if (left_proto !== right_proto)
1519
+ return false;
1520
+ if (left instanceof Boolean)
1521
+ return Object.is(left.valueOf(), right['valueOf']());
1522
+ if (left instanceof Number)
1523
+ return Object.is(left.valueOf(), right['valueOf']());
1524
+ if (left instanceof String)
1525
+ return Object.is(left.valueOf(), right['valueOf']());
1526
+ if (left instanceof Date)
1527
+ return Object.is(left.valueOf(), right['valueOf']());
1528
+ if (left instanceof RegExp)
1529
+ return left.source === right.source && left.flags === right.flags;
1530
+ if (left instanceof Error)
1531
+ return left.message === right.message && left.stack === right.stack;
1532
+ let left_cache = $.$mol_compare_deep_cache.get(left);
1533
+ if (left_cache) {
1534
+ const right_cache = left_cache.get(right);
1535
+ if (typeof right_cache === 'boolean')
1536
+ return right_cache;
1537
+ }
1538
+ else {
1539
+ left_cache = new WeakMap();
1540
+ $.$mol_compare_deep_cache.set(left, left_cache);
1541
+ }
1542
+ left_cache.set(right, true);
1543
+ let result;
1544
+ try {
1545
+ if (!left_proto)
1546
+ result = compare_pojo(left, right);
1547
+ else if (!Reflect.getPrototypeOf(left_proto))
1548
+ result = compare_pojo(left, right);
1549
+ else if (Symbol.toPrimitive in left)
1550
+ result = compare_primitive(left, right);
1551
+ else if (Array.isArray(left))
1552
+ result = compare_array(left, right);
1553
+ else if (left instanceof Set)
1554
+ result = compare_set(left, right);
1555
+ else if (left instanceof Map)
1556
+ result = compare_map(left, right);
1557
+ else if (ArrayBuffer.isView(left))
1558
+ result = compare_buffer(left, right);
1559
+ else if (Symbol.iterator in left)
1560
+ result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
1561
+ else
1562
+ result = false;
1563
+ }
1564
+ finally {
1565
+ left_cache.set(right, result);
1566
+ }
1567
+ return result;
1568
+ }
1569
+ $.$mol_compare_deep = $mol_compare_deep;
1570
+ function compare_array(left, right) {
1571
+ const len = left.length;
1572
+ if (len !== right.length)
1573
+ return false;
1574
+ for (let i = 0; i < len; ++i) {
1575
+ if (!$mol_compare_deep(left[i], right[i]))
1576
+ return false;
1577
+ }
1578
+ return true;
1579
+ }
1580
+ function compare_buffer(left, right) {
1581
+ const len = left.byteLength;
1582
+ if (len !== right.byteLength)
1583
+ return false;
1584
+ if (left instanceof DataView)
1585
+ return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, left.byteOffset, left.byteLength));
1586
+ for (let i = 0; i < len; ++i) {
1587
+ if (left[i] !== right[i])
1588
+ return false;
1589
+ }
1590
+ return true;
1591
+ }
1592
+ function compare_iterator(left, right) {
1593
+ while (true) {
1594
+ const left_next = left.next();
1595
+ const right_next = right.next();
1596
+ if (left_next.done !== right_next.done)
1597
+ return false;
1598
+ if (left_next.done)
1599
+ break;
1600
+ if (!$mol_compare_deep(left_next.value, right_next.value))
1601
+ return false;
1602
+ }
1603
+ return true;
1604
+ }
1605
+ function compare_set(left, right) {
1606
+ if (left.size !== right.size)
1607
+ return false;
1608
+ return compare_iterator(left.values(), right.values());
1609
+ }
1610
+ function compare_map(left, right) {
1611
+ if (left.size !== right.size)
1612
+ return false;
1613
+ return compare_iterator(left.keys(), right.keys())
1614
+ && compare_iterator(left.values(), right.values());
1615
+ }
1616
+ function compare_pojo(left, right) {
1617
+ const left_keys = Object.getOwnPropertyNames(left);
1618
+ const right_keys = Object.getOwnPropertyNames(right);
1619
+ if (!compare_array(left_keys, right_keys))
1620
+ return false;
1621
+ for (let key of left_keys) {
1622
+ if (!$mol_compare_deep(left[key], right[key]))
1623
+ return false;
1624
+ }
1625
+ const left_syms = Object.getOwnPropertySymbols(left);
1626
+ const right_syms = Object.getOwnPropertySymbols(right);
1627
+ if (!compare_array(left_syms, right_syms))
1628
+ return false;
1629
+ for (let key of left_syms) {
1630
+ if (!$mol_compare_deep(left[key], right[key]))
1631
+ return false;
1632
+ }
1633
+ return true;
1634
+ }
1635
+ function compare_primitive(left, right) {
1636
+ return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
1637
+ }
1638
+ })($ || ($ = {}));
1639
+
1640
+ ;
1641
+ "use strict";
1642
+ var $;
1643
+ (function ($) {
1644
+ class $mol_wire_task extends $mol_wire_fiber {
1645
+ static getter(task) {
1646
+ return function $mol_wire_task_get(host, args) {
1647
+ const sub = $mol_wire_auto();
1648
+ const existen = sub?.track_next();
1649
+ reuse: if (existen) {
1650
+ if (!existen.temp)
1651
+ break reuse;
1652
+ if (existen.host !== host)
1653
+ break reuse;
1654
+ if (existen.task !== task)
1655
+ break reuse;
1656
+ if (!$mol_compare_deep(existen.args, args))
1657
+ break reuse;
1658
+ return existen;
1659
+ }
1660
+ const key = (host?.[Symbol.toStringTag] ?? host) + ('.' + task.name + '<#>');
1661
+ const next = new $mol_wire_task(key, task, host, args);
1662
+ if (existen?.temp) {
1663
+ $$.$mol_log3_warn({
1664
+ place: '$mol_wire_task',
1665
+ message: `Non idempotency`,
1666
+ existen,
1667
+ next,
1668
+ hint: 'Ignore it',
1669
+ });
1670
+ }
1671
+ return next;
1672
+ };
1673
+ }
1674
+ get temp() {
1675
+ return true;
1676
+ }
1677
+ complete() {
1678
+ if ($mol_promise_like(this.cache))
1679
+ return;
1680
+ this.destructor();
1681
+ }
1682
+ put(next) {
1683
+ const prev = this.cache;
1684
+ this.cache = next;
1685
+ if ($mol_promise_like(next)) {
1686
+ this.cursor = $mol_wire_cursor.fresh;
1687
+ if (next !== prev)
1688
+ this.emit();
1689
+ return next;
1690
+ }
1691
+ this.cursor = $mol_wire_cursor.final;
1692
+ if (this.sub_empty)
1693
+ this.destructor();
1694
+ else if (next !== prev)
1695
+ this.emit();
1696
+ return next;
1697
+ }
1698
+ }
1699
+ $.$mol_wire_task = $mol_wire_task;
1700
+ })($ || ($ = {}));
1701
+
1702
+ ;
1703
+ "use strict";
1704
+ var $;
1705
+ (function ($) {
1706
+ function $mol_wire_sync(obj) {
1707
+ return new Proxy(obj, {
1708
+ get(obj, field) {
1709
+ const val = obj[field];
1710
+ if (typeof val !== 'function')
1711
+ return val;
1712
+ const temp = $mol_wire_task.getter(val);
1713
+ return function $mol_wire_sync(...args) {
1714
+ const fiber = temp(obj, args);
1715
+ return fiber.sync();
1716
+ };
1717
+ },
1718
+ apply(obj, self, args) {
1719
+ const temp = $mol_wire_task.getter(obj);
1720
+ const fiber = temp(self, args);
1721
+ return fiber.sync();
1722
+ },
1723
+ });
1724
+ }
1725
+ $.$mol_wire_sync = $mol_wire_sync;
1726
+ })($ || ($ = {}));
1727
+
1728
+ ;
1729
+ "use strict";
1730
+ var $;
1731
+ (function ($) {
1732
+ class $mol_run_error extends $mol_error_mix {
1733
+ }
1734
+ $.$mol_run_error = $mol_run_error;
1735
+ const child_process = $node['child_process'];
1736
+ $.$mol_run_spawn = child_process.spawn.bind(child_process);
1737
+ function $mol_run_async({ dir, timeout, command, env }) {
1738
+ const args_raw = typeof command === 'string' ? command.split(' ') : command;
1739
+ const [app, ...args] = args_raw;
1740
+ const sub = this.$mol_run_spawn(app, args, {
1741
+ shell: true,
1742
+ cwd: dir,
1743
+ env
1744
+ });
881
1745
  this.$mol_log3_come({
882
- place: '$mol_exec',
883
- dir: $node.path.relative('', dir),
1746
+ place: '$mol_run_async',
1747
+ pid: sub.pid,
884
1748
  message: 'Run',
885
- command: `${app} ${args.join(' ')}`,
1749
+ command: args_raw.join(' '),
1750
+ dir: $node.path.relative('', dir),
886
1751
  });
887
- var res = $node['child_process'].spawnSync(app, args, {
888
- cwd: $node.path.resolve(dir),
889
- shell: true,
890
- env: this.$mol_env(),
1752
+ let killed = false;
1753
+ let timer;
1754
+ const std_data = [];
1755
+ const error_data = [];
1756
+ const add = (std_chunk, error_chunk) => {
1757
+ if (std_chunk)
1758
+ std_data.push(std_chunk);
1759
+ if (error_chunk)
1760
+ error_data.push(error_chunk);
1761
+ if (!timeout)
1762
+ return;
1763
+ clearTimeout(timer);
1764
+ timer = setTimeout(() => {
1765
+ const signal = killed ? 'SIGKILL' : 'SIGTERM';
1766
+ killed = true;
1767
+ add();
1768
+ sub.kill(signal);
1769
+ }, timeout);
1770
+ };
1771
+ add();
1772
+ sub.stdout?.on('data', data => add(data));
1773
+ sub.stderr?.on('data', data => add(undefined, data));
1774
+ const promise = new Promise((done, fail) => {
1775
+ const close = (error, status = null, signal = null) => {
1776
+ if (!timer && timeout)
1777
+ return;
1778
+ clearTimeout(timer);
1779
+ timer = undefined;
1780
+ const res = {
1781
+ pid: sub.pid,
1782
+ status,
1783
+ signal,
1784
+ get stdout() { return Buffer.concat(std_data); },
1785
+ get stderr() { return Buffer.concat(error_data); }
1786
+ };
1787
+ this.$mol_log3_done({
1788
+ place: '$mol_run_async',
1789
+ pid: sub.pid,
1790
+ message: 'Run',
1791
+ status,
1792
+ command: args_raw.join(' '),
1793
+ dir: $node.path.relative('', dir),
1794
+ });
1795
+ if (error || status || killed)
1796
+ return fail(new $mol_run_error((res.stderr.toString() || res.stdout.toString() || 'Run error') + (killed ? ', timeout' : ''), { signal, timeout: killed }, ...error ? [error] : []));
1797
+ done(res);
1798
+ };
1799
+ sub.on('disconnect', () => close(new Error('Disconnected')));
1800
+ sub.on('error', err => close(err));
1801
+ sub.on('exit', (status, signal) => close(null, status, signal));
891
1802
  });
892
- if (res.status || res.error) {
893
- return $mol_fail(res.error || new Error(res.stderr.toString(), { cause: res.stdout }));
894
- }
895
- if (!res.stdout)
896
- res.stdout = Buffer.from([]);
897
- return res;
1803
+ return Object.assign(promise, { destructor: () => {
1804
+ clearTimeout(timer);
1805
+ sub.kill('SIGKILL');
1806
+ } });
1807
+ }
1808
+ $.$mol_run_async = $mol_run_async;
1809
+ function $mol_run(options) {
1810
+ if (!options.env)
1811
+ options = { ...options, env: this.$mol_env() };
1812
+ return $mol_wire_sync(this).$mol_run_async(options);
1813
+ }
1814
+ $.$mol_run = $mol_run;
1815
+ })($ || ($ = {}));
1816
+
1817
+ ;
1818
+ "use strict";
1819
+ var $;
1820
+ (function ($) {
1821
+ function $mol_exec(dir, command, ...args) {
1822
+ return this.$mol_run({ command: [command, ...args], dir });
898
1823
  }
899
1824
  $.$mol_exec = $mol_exec;
900
1825
  })($ || ($ = {}));