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