mol_text_distance 0.0.953 → 0.0.955
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.deps.json +1 -1
- package/node.test.js +1383 -156
- package/node.test.js.map +1 -1
- package/package.json +1 -1
- package/web.deps.json +1 -1
package/node.test.js
CHANGED
|
@@ -305,162 +305,6 @@ require = (req => Object.assign(function require(name) {
|
|
|
305
305
|
return $node[name];
|
|
306
306
|
}, req))(require);
|
|
307
307
|
|
|
308
|
-
;
|
|
309
|
-
"use strict";
|
|
310
|
-
var $;
|
|
311
|
-
(function ($) {
|
|
312
|
-
function $mol_log3_area_lazy(event) {
|
|
313
|
-
const self = this;
|
|
314
|
-
const stack = self.$mol_log3_stack;
|
|
315
|
-
const deep = stack.length;
|
|
316
|
-
let logged = false;
|
|
317
|
-
stack.push(() => {
|
|
318
|
-
logged = true;
|
|
319
|
-
self.$mol_log3_area.call(self, event);
|
|
320
|
-
});
|
|
321
|
-
return () => {
|
|
322
|
-
if (logged)
|
|
323
|
-
self.console.groupEnd();
|
|
324
|
-
if (stack.length > deep)
|
|
325
|
-
stack.length = deep;
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
$.$mol_log3_area_lazy = $mol_log3_area_lazy;
|
|
329
|
-
$.$mol_log3_stack = [];
|
|
330
|
-
})($ || ($ = {}));
|
|
331
|
-
|
|
332
|
-
;
|
|
333
|
-
"use strict";
|
|
334
|
-
var $;
|
|
335
|
-
(function ($) {
|
|
336
|
-
class $mol_term_color {
|
|
337
|
-
static reset = this.ansi(0, 0);
|
|
338
|
-
static bold = this.ansi(1, 22);
|
|
339
|
-
static italic = this.ansi(3, 23);
|
|
340
|
-
static underline = this.ansi(4, 24);
|
|
341
|
-
static inverse = this.ansi(7, 27);
|
|
342
|
-
static hidden = this.ansi(8, 28);
|
|
343
|
-
static strike = this.ansi(9, 29);
|
|
344
|
-
static gray = this.ansi(90, 39);
|
|
345
|
-
static red = this.ansi(91, 39);
|
|
346
|
-
static green = this.ansi(92, 39);
|
|
347
|
-
static yellow = this.ansi(93, 39);
|
|
348
|
-
static blue = this.ansi(94, 39);
|
|
349
|
-
static magenta = this.ansi(95, 39);
|
|
350
|
-
static cyan = this.ansi(96, 39);
|
|
351
|
-
static Gray = (str) => this.inverse(this.gray(str));
|
|
352
|
-
static Red = (str) => this.inverse(this.red(str));
|
|
353
|
-
static Green = (str) => this.inverse(this.green(str));
|
|
354
|
-
static Yellow = (str) => this.inverse(this.yellow(str));
|
|
355
|
-
static Blue = (str) => this.inverse(this.blue(str));
|
|
356
|
-
static Magenta = (str) => this.inverse(this.magenta(str));
|
|
357
|
-
static Cyan = (str) => this.inverse(this.cyan(str));
|
|
358
|
-
static ansi(open, close) {
|
|
359
|
-
if (typeof process === 'undefined')
|
|
360
|
-
return String;
|
|
361
|
-
if (!process.stdout.isTTY)
|
|
362
|
-
return String;
|
|
363
|
-
const prefix = `\x1b[${open}m`;
|
|
364
|
-
const postfix = `\x1b[${close}m`;
|
|
365
|
-
const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
|
|
366
|
-
return function colorer(str) {
|
|
367
|
-
str = String(str);
|
|
368
|
-
if (str === '')
|
|
369
|
-
return str;
|
|
370
|
-
const suffix = str.replace(suffix_regexp, prefix);
|
|
371
|
-
return prefix + suffix + postfix;
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
$.$mol_term_color = $mol_term_color;
|
|
376
|
-
})($ || ($ = {}));
|
|
377
|
-
|
|
378
|
-
;
|
|
379
|
-
"use strict";
|
|
380
|
-
var $;
|
|
381
|
-
(function ($) {
|
|
382
|
-
function $mol_log3_node_make(level, output, type, color) {
|
|
383
|
-
return function $mol_log3_logger(event) {
|
|
384
|
-
if (!event.time)
|
|
385
|
-
event = { time: new Date().toISOString(), ...event };
|
|
386
|
-
let tree = this.$mol_tree2_from_json(event);
|
|
387
|
-
tree = tree.struct(type, tree.kids);
|
|
388
|
-
let str = color(tree.toString());
|
|
389
|
-
this.console[level](str);
|
|
390
|
-
const self = this;
|
|
391
|
-
return () => self.console.groupEnd();
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
|
-
$.$mol_log3_node_make = $mol_log3_node_make;
|
|
395
|
-
$.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
|
|
396
|
-
$.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
|
|
397
|
-
$.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
|
|
398
|
-
$.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
|
|
399
|
-
$.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
|
|
400
|
-
$.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
|
|
401
|
-
})($ || ($ = {}));
|
|
402
|
-
|
|
403
|
-
;
|
|
404
|
-
"use strict";
|
|
405
|
-
var $;
|
|
406
|
-
(function ($_1) {
|
|
407
|
-
$mol_test_mocks.push($ => {
|
|
408
|
-
$.$mol_log3_come = () => { };
|
|
409
|
-
$.$mol_log3_done = () => { };
|
|
410
|
-
$.$mol_log3_fail = () => { };
|
|
411
|
-
$.$mol_log3_warn = () => { };
|
|
412
|
-
$.$mol_log3_rise = () => { };
|
|
413
|
-
$.$mol_log3_area = () => () => { };
|
|
414
|
-
});
|
|
415
|
-
})($ || ($ = {}));
|
|
416
|
-
|
|
417
|
-
;
|
|
418
|
-
"use strict";
|
|
419
|
-
var $;
|
|
420
|
-
(function ($) {
|
|
421
|
-
function $mol_env() {
|
|
422
|
-
return {};
|
|
423
|
-
}
|
|
424
|
-
$.$mol_env = $mol_env;
|
|
425
|
-
})($ || ($ = {}));
|
|
426
|
-
|
|
427
|
-
;
|
|
428
|
-
"use strict";
|
|
429
|
-
var $;
|
|
430
|
-
(function ($) {
|
|
431
|
-
$.$mol_env = function $mol_env() {
|
|
432
|
-
return this.process.env;
|
|
433
|
-
};
|
|
434
|
-
})($ || ($ = {}));
|
|
435
|
-
|
|
436
|
-
;
|
|
437
|
-
"use strict";
|
|
438
|
-
var $;
|
|
439
|
-
(function ($) {
|
|
440
|
-
function $mol_exec(dir, command, ...args) {
|
|
441
|
-
let [app, ...args0] = command.split(' ');
|
|
442
|
-
args = [...args0, ...args];
|
|
443
|
-
this.$mol_log3_come({
|
|
444
|
-
place: '$mol_exec',
|
|
445
|
-
dir: $node.path.relative('', dir),
|
|
446
|
-
message: 'Run',
|
|
447
|
-
command: `${app} ${args.join(' ')}`,
|
|
448
|
-
});
|
|
449
|
-
var res = $node['child_process'].spawnSync(app, args, {
|
|
450
|
-
cwd: $node.path.resolve(dir),
|
|
451
|
-
shell: true,
|
|
452
|
-
env: this.$mol_env(),
|
|
453
|
-
});
|
|
454
|
-
if (res.status || res.error) {
|
|
455
|
-
return $mol_fail(res.error || new Error(res.stderr.toString(), { cause: res.stdout }));
|
|
456
|
-
}
|
|
457
|
-
if (!res.stdout)
|
|
458
|
-
res.stdout = Buffer.from([]);
|
|
459
|
-
return res;
|
|
460
|
-
}
|
|
461
|
-
$.$mol_exec = $mol_exec;
|
|
462
|
-
})($ || ($ = {}));
|
|
463
|
-
|
|
464
308
|
;
|
|
465
309
|
"use strict";
|
|
466
310
|
var $;
|
|
@@ -1440,6 +1284,115 @@ var $;
|
|
|
1440
1284
|
});
|
|
1441
1285
|
})($ || ($ = {}));
|
|
1442
1286
|
|
|
1287
|
+
;
|
|
1288
|
+
"use strict";
|
|
1289
|
+
var $;
|
|
1290
|
+
(function ($) {
|
|
1291
|
+
function $mol_log3_area_lazy(event) {
|
|
1292
|
+
const self = this;
|
|
1293
|
+
const stack = self.$mol_log3_stack;
|
|
1294
|
+
const deep = stack.length;
|
|
1295
|
+
let logged = false;
|
|
1296
|
+
stack.push(() => {
|
|
1297
|
+
logged = true;
|
|
1298
|
+
self.$mol_log3_area.call(self, event);
|
|
1299
|
+
});
|
|
1300
|
+
return () => {
|
|
1301
|
+
if (logged)
|
|
1302
|
+
self.console.groupEnd();
|
|
1303
|
+
if (stack.length > deep)
|
|
1304
|
+
stack.length = deep;
|
|
1305
|
+
};
|
|
1306
|
+
}
|
|
1307
|
+
$.$mol_log3_area_lazy = $mol_log3_area_lazy;
|
|
1308
|
+
$.$mol_log3_stack = [];
|
|
1309
|
+
})($ || ($ = {}));
|
|
1310
|
+
|
|
1311
|
+
;
|
|
1312
|
+
"use strict";
|
|
1313
|
+
var $;
|
|
1314
|
+
(function ($) {
|
|
1315
|
+
class $mol_term_color {
|
|
1316
|
+
static reset = this.ansi(0, 0);
|
|
1317
|
+
static bold = this.ansi(1, 22);
|
|
1318
|
+
static italic = this.ansi(3, 23);
|
|
1319
|
+
static underline = this.ansi(4, 24);
|
|
1320
|
+
static inverse = this.ansi(7, 27);
|
|
1321
|
+
static hidden = this.ansi(8, 28);
|
|
1322
|
+
static strike = this.ansi(9, 29);
|
|
1323
|
+
static gray = this.ansi(90, 39);
|
|
1324
|
+
static red = this.ansi(91, 39);
|
|
1325
|
+
static green = this.ansi(92, 39);
|
|
1326
|
+
static yellow = this.ansi(93, 39);
|
|
1327
|
+
static blue = this.ansi(94, 39);
|
|
1328
|
+
static magenta = this.ansi(95, 39);
|
|
1329
|
+
static cyan = this.ansi(96, 39);
|
|
1330
|
+
static Gray = (str) => this.inverse(this.gray(str));
|
|
1331
|
+
static Red = (str) => this.inverse(this.red(str));
|
|
1332
|
+
static Green = (str) => this.inverse(this.green(str));
|
|
1333
|
+
static Yellow = (str) => this.inverse(this.yellow(str));
|
|
1334
|
+
static Blue = (str) => this.inverse(this.blue(str));
|
|
1335
|
+
static Magenta = (str) => this.inverse(this.magenta(str));
|
|
1336
|
+
static Cyan = (str) => this.inverse(this.cyan(str));
|
|
1337
|
+
static ansi(open, close) {
|
|
1338
|
+
if (typeof process === 'undefined')
|
|
1339
|
+
return String;
|
|
1340
|
+
if (!process.stdout.isTTY)
|
|
1341
|
+
return String;
|
|
1342
|
+
const prefix = `\x1b[${open}m`;
|
|
1343
|
+
const postfix = `\x1b[${close}m`;
|
|
1344
|
+
const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
|
|
1345
|
+
return function colorer(str) {
|
|
1346
|
+
str = String(str);
|
|
1347
|
+
if (str === '')
|
|
1348
|
+
return str;
|
|
1349
|
+
const suffix = str.replace(suffix_regexp, prefix);
|
|
1350
|
+
return prefix + suffix + postfix;
|
|
1351
|
+
};
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
$.$mol_term_color = $mol_term_color;
|
|
1355
|
+
})($ || ($ = {}));
|
|
1356
|
+
|
|
1357
|
+
;
|
|
1358
|
+
"use strict";
|
|
1359
|
+
var $;
|
|
1360
|
+
(function ($) {
|
|
1361
|
+
function $mol_log3_node_make(level, output, type, color) {
|
|
1362
|
+
return function $mol_log3_logger(event) {
|
|
1363
|
+
if (!event.time)
|
|
1364
|
+
event = { time: new Date().toISOString(), ...event };
|
|
1365
|
+
let tree = this.$mol_tree2_from_json(event);
|
|
1366
|
+
tree = tree.struct(type, tree.kids);
|
|
1367
|
+
let str = color(tree.toString());
|
|
1368
|
+
this.console[level](str);
|
|
1369
|
+
const self = this;
|
|
1370
|
+
return () => self.console.groupEnd();
|
|
1371
|
+
};
|
|
1372
|
+
}
|
|
1373
|
+
$.$mol_log3_node_make = $mol_log3_node_make;
|
|
1374
|
+
$.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
|
|
1375
|
+
$.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
|
|
1376
|
+
$.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
|
|
1377
|
+
$.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
|
|
1378
|
+
$.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
|
|
1379
|
+
$.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
|
|
1380
|
+
})($ || ($ = {}));
|
|
1381
|
+
|
|
1382
|
+
;
|
|
1383
|
+
"use strict";
|
|
1384
|
+
var $;
|
|
1385
|
+
(function ($_1) {
|
|
1386
|
+
$mol_test_mocks.push($ => {
|
|
1387
|
+
$.$mol_log3_come = () => { };
|
|
1388
|
+
$.$mol_log3_done = () => { };
|
|
1389
|
+
$.$mol_log3_fail = () => { };
|
|
1390
|
+
$.$mol_log3_warn = () => { };
|
|
1391
|
+
$.$mol_log3_rise = () => { };
|
|
1392
|
+
$.$mol_log3_area = () => () => { };
|
|
1393
|
+
});
|
|
1394
|
+
})($ || ($ = {}));
|
|
1395
|
+
|
|
1443
1396
|
;
|
|
1444
1397
|
"use strict";
|
|
1445
1398
|
var $;
|
|
@@ -2311,6 +2264,1280 @@ var $;
|
|
|
2311
2264
|
});
|
|
2312
2265
|
})($ || ($ = {}));
|
|
2313
2266
|
|
|
2267
|
+
;
|
|
2268
|
+
"use strict";
|
|
2269
|
+
var $;
|
|
2270
|
+
(function ($) {
|
|
2271
|
+
class $mol_error_mix extends AggregateError {
|
|
2272
|
+
cause;
|
|
2273
|
+
name = $$.$mol_func_name(this.constructor).replace(/^\$/, '') + '_Error';
|
|
2274
|
+
constructor(message, cause = {}, ...errors) {
|
|
2275
|
+
super(errors, message, { cause });
|
|
2276
|
+
this.cause = cause;
|
|
2277
|
+
const stack_get = Object.getOwnPropertyDescriptor(this, 'stack')?.get ?? (() => super.stack);
|
|
2278
|
+
Object.defineProperty(this, 'stack', {
|
|
2279
|
+
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()
|
|
2280
|
+
.replace(/at /gm, ' at ')
|
|
2281
|
+
.replace(/^(?! +at )(.*)/gm, ' at | $1 (#)')).join('\n')
|
|
2282
|
+
});
|
|
2283
|
+
}
|
|
2284
|
+
static [Symbol.toPrimitive]() {
|
|
2285
|
+
return this.toString();
|
|
2286
|
+
}
|
|
2287
|
+
static toString() {
|
|
2288
|
+
return $$.$mol_func_name(this);
|
|
2289
|
+
}
|
|
2290
|
+
static make(...params) {
|
|
2291
|
+
return new this(...params);
|
|
2292
|
+
}
|
|
2293
|
+
}
|
|
2294
|
+
$.$mol_error_mix = $mol_error_mix;
|
|
2295
|
+
})($ || ($ = {}));
|
|
2296
|
+
|
|
2297
|
+
;
|
|
2298
|
+
"use strict";
|
|
2299
|
+
var $;
|
|
2300
|
+
(function ($) {
|
|
2301
|
+
$mol_test({
|
|
2302
|
+
'auto name'() {
|
|
2303
|
+
class Invalid extends $mol_error_mix {
|
|
2304
|
+
}
|
|
2305
|
+
const mix = new Invalid('foo');
|
|
2306
|
+
$mol_assert_equal(mix.name, 'Invalid_Error');
|
|
2307
|
+
},
|
|
2308
|
+
'simpe mix'() {
|
|
2309
|
+
const mix = new $mol_error_mix('foo', {}, new Error('bar'), new Error('lol'));
|
|
2310
|
+
$mol_assert_equal(mix.message, 'foo');
|
|
2311
|
+
$mol_assert_equal(mix.errors.map(e => e.message), ['bar', 'lol']);
|
|
2312
|
+
},
|
|
2313
|
+
'provide additional info'() {
|
|
2314
|
+
class Invalid extends $mol_error_mix {
|
|
2315
|
+
}
|
|
2316
|
+
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' }));
|
|
2317
|
+
const hints = [];
|
|
2318
|
+
if (mix instanceof $mol_error_mix) {
|
|
2319
|
+
for (const er of mix.errors) {
|
|
2320
|
+
if (er instanceof Invalid) {
|
|
2321
|
+
hints.push(er.cause?.hint ?? '');
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
$mol_assert_equal(hints, ['> 8 letters', 'need capital letter']);
|
|
2326
|
+
},
|
|
2327
|
+
});
|
|
2328
|
+
})($ || ($ = {}));
|
|
2329
|
+
|
|
2330
|
+
;
|
|
2331
|
+
"use strict";
|
|
2332
|
+
var $;
|
|
2333
|
+
(function ($) {
|
|
2334
|
+
function $mol_env() {
|
|
2335
|
+
return {};
|
|
2336
|
+
}
|
|
2337
|
+
$.$mol_env = $mol_env;
|
|
2338
|
+
})($ || ($ = {}));
|
|
2339
|
+
|
|
2340
|
+
;
|
|
2341
|
+
"use strict";
|
|
2342
|
+
var $;
|
|
2343
|
+
(function ($) {
|
|
2344
|
+
$.$mol_env = function $mol_env() {
|
|
2345
|
+
return this.process.env;
|
|
2346
|
+
};
|
|
2347
|
+
})($ || ($ = {}));
|
|
2348
|
+
|
|
2349
|
+
;
|
|
2350
|
+
"use strict";
|
|
2351
|
+
var $;
|
|
2352
|
+
(function ($) {
|
|
2353
|
+
let $mol_wire_cursor;
|
|
2354
|
+
(function ($mol_wire_cursor) {
|
|
2355
|
+
$mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
|
|
2356
|
+
$mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
|
|
2357
|
+
$mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
|
|
2358
|
+
$mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
|
|
2359
|
+
})($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
|
|
2360
|
+
})($ || ($ = {}));
|
|
2361
|
+
|
|
2362
|
+
;
|
|
2363
|
+
"use strict";
|
|
2364
|
+
var $;
|
|
2365
|
+
(function ($) {
|
|
2366
|
+
class $mol_wire_pub extends Object {
|
|
2367
|
+
data = [];
|
|
2368
|
+
static get [Symbol.species]() {
|
|
2369
|
+
return Array;
|
|
2370
|
+
}
|
|
2371
|
+
sub_from = 0;
|
|
2372
|
+
get sub_list() {
|
|
2373
|
+
const res = [];
|
|
2374
|
+
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
2375
|
+
res.push(this.data[i]);
|
|
2376
|
+
}
|
|
2377
|
+
return res;
|
|
2378
|
+
}
|
|
2379
|
+
get sub_empty() {
|
|
2380
|
+
return this.sub_from === this.data.length;
|
|
2381
|
+
}
|
|
2382
|
+
sub_on(sub, pub_pos) {
|
|
2383
|
+
const pos = this.data.length;
|
|
2384
|
+
this.data.push(sub, pub_pos);
|
|
2385
|
+
return pos;
|
|
2386
|
+
}
|
|
2387
|
+
sub_off(sub_pos) {
|
|
2388
|
+
if (!(sub_pos < this.data.length)) {
|
|
2389
|
+
$mol_fail(new Error(`Wrong pos ${sub_pos}`));
|
|
2390
|
+
}
|
|
2391
|
+
const end = this.data.length - 2;
|
|
2392
|
+
if (sub_pos !== end) {
|
|
2393
|
+
this.peer_move(end, sub_pos);
|
|
2394
|
+
}
|
|
2395
|
+
this.data.pop();
|
|
2396
|
+
this.data.pop();
|
|
2397
|
+
if (this.data.length === this.sub_from)
|
|
2398
|
+
this.reap();
|
|
2399
|
+
}
|
|
2400
|
+
reap() { }
|
|
2401
|
+
promote() {
|
|
2402
|
+
$mol_wire_auto()?.track_next(this);
|
|
2403
|
+
}
|
|
2404
|
+
fresh() { }
|
|
2405
|
+
complete() { }
|
|
2406
|
+
get incompleted() {
|
|
2407
|
+
return false;
|
|
2408
|
+
}
|
|
2409
|
+
emit(quant = $mol_wire_cursor.stale) {
|
|
2410
|
+
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
2411
|
+
;
|
|
2412
|
+
this.data[i].absorb(quant);
|
|
2413
|
+
}
|
|
2414
|
+
}
|
|
2415
|
+
peer_move(from_pos, to_pos) {
|
|
2416
|
+
const peer = this.data[from_pos];
|
|
2417
|
+
const self_pos = this.data[from_pos + 1];
|
|
2418
|
+
this.data[to_pos] = peer;
|
|
2419
|
+
this.data[to_pos + 1] = self_pos;
|
|
2420
|
+
peer.peer_repos(self_pos, to_pos);
|
|
2421
|
+
}
|
|
2422
|
+
peer_repos(peer_pos, self_pos) {
|
|
2423
|
+
this.data[peer_pos + 1] = self_pos;
|
|
2424
|
+
}
|
|
2425
|
+
}
|
|
2426
|
+
$.$mol_wire_pub = $mol_wire_pub;
|
|
2427
|
+
})($ || ($ = {}));
|
|
2428
|
+
|
|
2429
|
+
;
|
|
2430
|
+
"use strict";
|
|
2431
|
+
|
|
2432
|
+
;
|
|
2433
|
+
"use strict";
|
|
2434
|
+
var $;
|
|
2435
|
+
(function ($) {
|
|
2436
|
+
$.$mol_wire_auto_sub = null;
|
|
2437
|
+
function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
|
|
2438
|
+
return $.$mol_wire_auto_sub = next;
|
|
2439
|
+
}
|
|
2440
|
+
$.$mol_wire_auto = $mol_wire_auto;
|
|
2441
|
+
$.$mol_wire_affected = [];
|
|
2442
|
+
})($ || ($ = {}));
|
|
2443
|
+
|
|
2444
|
+
;
|
|
2445
|
+
"use strict";
|
|
2446
|
+
var $;
|
|
2447
|
+
(function ($) {
|
|
2448
|
+
$['devtoolsFormatters'] ||= [];
|
|
2449
|
+
function $mol_dev_format_register(config) {
|
|
2450
|
+
$['devtoolsFormatters'].push(config);
|
|
2451
|
+
}
|
|
2452
|
+
$.$mol_dev_format_register = $mol_dev_format_register;
|
|
2453
|
+
$.$mol_dev_format_head = Symbol('$mol_dev_format_head');
|
|
2454
|
+
$.$mol_dev_format_body = Symbol('$mol_dev_format_body');
|
|
2455
|
+
$mol_dev_format_register({
|
|
2456
|
+
header: (val, config = false) => {
|
|
2457
|
+
if (config)
|
|
2458
|
+
return null;
|
|
2459
|
+
if (!val)
|
|
2460
|
+
return null;
|
|
2461
|
+
if ($.$mol_dev_format_head in val) {
|
|
2462
|
+
try {
|
|
2463
|
+
return val[$.$mol_dev_format_head]();
|
|
2464
|
+
}
|
|
2465
|
+
catch (error) {
|
|
2466
|
+
return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
if (typeof val === 'function') {
|
|
2470
|
+
return $mol_dev_format_native(val);
|
|
2471
|
+
}
|
|
2472
|
+
if (Symbol.toStringTag in val) {
|
|
2473
|
+
return $mol_dev_format_native(val);
|
|
2474
|
+
}
|
|
2475
|
+
return null;
|
|
2476
|
+
},
|
|
2477
|
+
hasBody: val => val[$.$mol_dev_format_body],
|
|
2478
|
+
body: val => val[$.$mol_dev_format_body](),
|
|
2479
|
+
});
|
|
2480
|
+
function $mol_dev_format_native(obj) {
|
|
2481
|
+
if (typeof obj === 'undefined')
|
|
2482
|
+
return $.$mol_dev_format_shade('undefined');
|
|
2483
|
+
return [
|
|
2484
|
+
'object',
|
|
2485
|
+
{
|
|
2486
|
+
object: obj,
|
|
2487
|
+
config: true,
|
|
2488
|
+
},
|
|
2489
|
+
];
|
|
2490
|
+
}
|
|
2491
|
+
$.$mol_dev_format_native = $mol_dev_format_native;
|
|
2492
|
+
function $mol_dev_format_auto(obj) {
|
|
2493
|
+
if (obj == null)
|
|
2494
|
+
return $.$mol_dev_format_shade(String(obj));
|
|
2495
|
+
return [
|
|
2496
|
+
'object',
|
|
2497
|
+
{
|
|
2498
|
+
object: obj,
|
|
2499
|
+
config: false,
|
|
2500
|
+
},
|
|
2501
|
+
];
|
|
2502
|
+
}
|
|
2503
|
+
$.$mol_dev_format_auto = $mol_dev_format_auto;
|
|
2504
|
+
function $mol_dev_format_element(element, style, ...content) {
|
|
2505
|
+
const styles = [];
|
|
2506
|
+
for (let key in style)
|
|
2507
|
+
styles.push(`${key} : ${style[key]}`);
|
|
2508
|
+
return [
|
|
2509
|
+
element,
|
|
2510
|
+
{
|
|
2511
|
+
style: styles.join(' ; '),
|
|
2512
|
+
},
|
|
2513
|
+
...content,
|
|
2514
|
+
];
|
|
2515
|
+
}
|
|
2516
|
+
$.$mol_dev_format_element = $mol_dev_format_element;
|
|
2517
|
+
function $mol_dev_format_span(style, ...content) {
|
|
2518
|
+
return $mol_dev_format_element('span', {
|
|
2519
|
+
...style,
|
|
2520
|
+
}, ...content);
|
|
2521
|
+
}
|
|
2522
|
+
$.$mol_dev_format_span = $mol_dev_format_span;
|
|
2523
|
+
$.$mol_dev_format_div = $mol_dev_format_element.bind(null, 'div');
|
|
2524
|
+
$.$mol_dev_format_ol = $mol_dev_format_element.bind(null, 'ol');
|
|
2525
|
+
$.$mol_dev_format_li = $mol_dev_format_element.bind(null, 'li');
|
|
2526
|
+
$.$mol_dev_format_table = $mol_dev_format_element.bind(null, 'table');
|
|
2527
|
+
$.$mol_dev_format_tr = $mol_dev_format_element.bind(null, 'tr');
|
|
2528
|
+
$.$mol_dev_format_td = $mol_dev_format_element.bind(null, 'td');
|
|
2529
|
+
$.$mol_dev_format_accent = $mol_dev_format_span.bind(null, {
|
|
2530
|
+
'color': 'magenta',
|
|
2531
|
+
});
|
|
2532
|
+
$.$mol_dev_format_strong = $mol_dev_format_span.bind(null, {
|
|
2533
|
+
'font-weight': 'bold',
|
|
2534
|
+
});
|
|
2535
|
+
$.$mol_dev_format_string = $mol_dev_format_span.bind(null, {
|
|
2536
|
+
'color': 'green',
|
|
2537
|
+
});
|
|
2538
|
+
$.$mol_dev_format_shade = $mol_dev_format_span.bind(null, {
|
|
2539
|
+
'color': 'gray',
|
|
2540
|
+
});
|
|
2541
|
+
$.$mol_dev_format_indent = $.$mol_dev_format_div.bind(null, {
|
|
2542
|
+
'margin-left': '13px'
|
|
2543
|
+
});
|
|
2544
|
+
})($ || ($ = {}));
|
|
2545
|
+
|
|
2546
|
+
;
|
|
2547
|
+
"use strict";
|
|
2548
|
+
var $;
|
|
2549
|
+
(function ($) {
|
|
2550
|
+
class $mol_wire_pub_sub extends $mol_wire_pub {
|
|
2551
|
+
pub_from = 0;
|
|
2552
|
+
cursor = $mol_wire_cursor.stale;
|
|
2553
|
+
get temp() {
|
|
2554
|
+
return false;
|
|
2555
|
+
}
|
|
2556
|
+
get pub_list() {
|
|
2557
|
+
const res = [];
|
|
2558
|
+
const max = this.cursor >= 0 ? this.cursor : this.sub_from;
|
|
2559
|
+
for (let i = this.pub_from; i < max; i += 2) {
|
|
2560
|
+
if (this.data[i])
|
|
2561
|
+
res.push(this.data[i]);
|
|
2562
|
+
}
|
|
2563
|
+
return res;
|
|
2564
|
+
}
|
|
2565
|
+
track_on() {
|
|
2566
|
+
this.cursor = this.pub_from;
|
|
2567
|
+
const sub = $mol_wire_auto();
|
|
2568
|
+
$mol_wire_auto(this);
|
|
2569
|
+
return sub;
|
|
2570
|
+
}
|
|
2571
|
+
promote() {
|
|
2572
|
+
if (this.cursor >= this.pub_from) {
|
|
2573
|
+
$mol_fail(new Error('Circular subscription'));
|
|
2574
|
+
}
|
|
2575
|
+
super.promote();
|
|
2576
|
+
}
|
|
2577
|
+
track_next(pub) {
|
|
2578
|
+
if (this.cursor < 0)
|
|
2579
|
+
$mol_fail(new Error('Promo to non begun sub'));
|
|
2580
|
+
if (this.cursor < this.sub_from) {
|
|
2581
|
+
const next = this.data[this.cursor];
|
|
2582
|
+
if (pub === undefined)
|
|
2583
|
+
return next ?? null;
|
|
2584
|
+
if (next === pub) {
|
|
2585
|
+
this.cursor += 2;
|
|
2586
|
+
return next;
|
|
2587
|
+
}
|
|
2588
|
+
if (next) {
|
|
2589
|
+
if (this.sub_from < this.data.length) {
|
|
2590
|
+
this.peer_move(this.sub_from, this.data.length);
|
|
2591
|
+
}
|
|
2592
|
+
this.peer_move(this.cursor, this.sub_from);
|
|
2593
|
+
this.sub_from += 2;
|
|
2594
|
+
}
|
|
2595
|
+
}
|
|
2596
|
+
else {
|
|
2597
|
+
if (pub === undefined)
|
|
2598
|
+
return null;
|
|
2599
|
+
if (this.sub_from < this.data.length) {
|
|
2600
|
+
this.peer_move(this.sub_from, this.data.length);
|
|
2601
|
+
}
|
|
2602
|
+
this.sub_from += 2;
|
|
2603
|
+
}
|
|
2604
|
+
this.data[this.cursor] = pub;
|
|
2605
|
+
this.data[this.cursor + 1] = pub.sub_on(this, this.cursor);
|
|
2606
|
+
this.cursor += 2;
|
|
2607
|
+
return pub;
|
|
2608
|
+
}
|
|
2609
|
+
track_off(sub) {
|
|
2610
|
+
$mol_wire_auto(sub);
|
|
2611
|
+
if (this.cursor < 0) {
|
|
2612
|
+
$mol_fail(new Error('End of non begun sub'));
|
|
2613
|
+
}
|
|
2614
|
+
for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
|
|
2615
|
+
const pub = this.data[cursor];
|
|
2616
|
+
pub.fresh();
|
|
2617
|
+
}
|
|
2618
|
+
this.cursor = $mol_wire_cursor.fresh;
|
|
2619
|
+
}
|
|
2620
|
+
pub_off(sub_pos) {
|
|
2621
|
+
this.data[sub_pos] = undefined;
|
|
2622
|
+
this.data[sub_pos + 1] = undefined;
|
|
2623
|
+
}
|
|
2624
|
+
destructor() {
|
|
2625
|
+
for (let cursor = this.data.length - 2; cursor >= this.sub_from; cursor -= 2) {
|
|
2626
|
+
const sub = this.data[cursor];
|
|
2627
|
+
const pos = this.data[cursor + 1];
|
|
2628
|
+
sub.pub_off(pos);
|
|
2629
|
+
this.data.pop();
|
|
2630
|
+
this.data.pop();
|
|
2631
|
+
}
|
|
2632
|
+
this.cursor = this.pub_from;
|
|
2633
|
+
this.track_cut();
|
|
2634
|
+
this.cursor = $mol_wire_cursor.final;
|
|
2635
|
+
}
|
|
2636
|
+
track_cut() {
|
|
2637
|
+
if (this.cursor < this.pub_from) {
|
|
2638
|
+
$mol_fail(new Error('Cut of non begun sub'));
|
|
2639
|
+
}
|
|
2640
|
+
let tail = 0;
|
|
2641
|
+
for (let cursor = this.cursor; cursor < this.sub_from; cursor += 2) {
|
|
2642
|
+
const pub = this.data[cursor];
|
|
2643
|
+
pub?.sub_off(this.data[cursor + 1]);
|
|
2644
|
+
if (this.sub_from < this.data.length) {
|
|
2645
|
+
this.peer_move(this.data.length - 2, cursor);
|
|
2646
|
+
this.data.pop();
|
|
2647
|
+
this.data.pop();
|
|
2648
|
+
}
|
|
2649
|
+
else {
|
|
2650
|
+
++tail;
|
|
2651
|
+
}
|
|
2652
|
+
}
|
|
2653
|
+
for (; tail; --tail) {
|
|
2654
|
+
this.data.pop();
|
|
2655
|
+
this.data.pop();
|
|
2656
|
+
}
|
|
2657
|
+
this.sub_from = this.cursor;
|
|
2658
|
+
}
|
|
2659
|
+
complete() { }
|
|
2660
|
+
complete_pubs() {
|
|
2661
|
+
const limit = this.cursor < 0 ? this.sub_from : this.cursor;
|
|
2662
|
+
for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
|
|
2663
|
+
const pub = this.data[cursor];
|
|
2664
|
+
if (pub?.incompleted)
|
|
2665
|
+
return;
|
|
2666
|
+
}
|
|
2667
|
+
for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
|
|
2668
|
+
const pub = this.data[cursor];
|
|
2669
|
+
pub?.complete();
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2672
|
+
absorb(quant = $mol_wire_cursor.stale) {
|
|
2673
|
+
if (this.cursor === $mol_wire_cursor.final)
|
|
2674
|
+
return;
|
|
2675
|
+
if (this.cursor >= quant)
|
|
2676
|
+
return;
|
|
2677
|
+
this.cursor = quant;
|
|
2678
|
+
this.emit($mol_wire_cursor.doubt);
|
|
2679
|
+
}
|
|
2680
|
+
[$mol_dev_format_head]() {
|
|
2681
|
+
return $mol_dev_format_native(this);
|
|
2682
|
+
}
|
|
2683
|
+
get pub_empty() {
|
|
2684
|
+
return this.sub_from === this.pub_from;
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2687
|
+
$.$mol_wire_pub_sub = $mol_wire_pub_sub;
|
|
2688
|
+
})($ || ($ = {}));
|
|
2689
|
+
|
|
2690
|
+
;
|
|
2691
|
+
"use strict";
|
|
2692
|
+
var $;
|
|
2693
|
+
(function ($_1) {
|
|
2694
|
+
$mol_test({
|
|
2695
|
+
'Collect deps'() {
|
|
2696
|
+
const pub1 = new $mol_wire_pub;
|
|
2697
|
+
const pub2 = new $mol_wire_pub;
|
|
2698
|
+
const sub = new $mol_wire_pub_sub;
|
|
2699
|
+
const bu1 = sub.track_on();
|
|
2700
|
+
try {
|
|
2701
|
+
pub1.promote();
|
|
2702
|
+
pub2.promote();
|
|
2703
|
+
pub2.promote();
|
|
2704
|
+
}
|
|
2705
|
+
finally {
|
|
2706
|
+
sub.track_cut();
|
|
2707
|
+
sub.track_off(bu1);
|
|
2708
|
+
}
|
|
2709
|
+
pub1.emit();
|
|
2710
|
+
pub2.emit();
|
|
2711
|
+
$mol_assert_like(sub.pub_list, [pub1, pub2, pub2]);
|
|
2712
|
+
const bu2 = sub.track_on();
|
|
2713
|
+
try {
|
|
2714
|
+
pub1.promote();
|
|
2715
|
+
pub1.promote();
|
|
2716
|
+
pub2.promote();
|
|
2717
|
+
}
|
|
2718
|
+
finally {
|
|
2719
|
+
sub.track_cut();
|
|
2720
|
+
sub.track_off(bu2);
|
|
2721
|
+
}
|
|
2722
|
+
pub1.emit();
|
|
2723
|
+
pub2.emit();
|
|
2724
|
+
$mol_assert_like(sub.pub_list, [pub1, pub1, pub2]);
|
|
2725
|
+
},
|
|
2726
|
+
'cyclic detection'($) {
|
|
2727
|
+
const sub1 = new $mol_wire_pub_sub;
|
|
2728
|
+
const sub2 = new $mol_wire_pub_sub;
|
|
2729
|
+
const bu1 = sub1.track_on();
|
|
2730
|
+
try {
|
|
2731
|
+
const bu2 = sub2.track_on();
|
|
2732
|
+
try {
|
|
2733
|
+
$mol_assert_fail(() => sub1.promote(), 'Circular subscription');
|
|
2734
|
+
}
|
|
2735
|
+
finally {
|
|
2736
|
+
sub2.track_cut();
|
|
2737
|
+
sub2.track_off(bu2);
|
|
2738
|
+
}
|
|
2739
|
+
}
|
|
2740
|
+
finally {
|
|
2741
|
+
sub1.track_cut();
|
|
2742
|
+
sub1.track_off(bu1);
|
|
2743
|
+
}
|
|
2744
|
+
},
|
|
2745
|
+
});
|
|
2746
|
+
})($ || ($ = {}));
|
|
2747
|
+
|
|
2748
|
+
;
|
|
2749
|
+
"use strict";
|
|
2750
|
+
var $;
|
|
2751
|
+
(function ($) {
|
|
2752
|
+
$.$mol_after_mock_queue = [];
|
|
2753
|
+
function $mol_after_mock_warp() {
|
|
2754
|
+
const queue = $.$mol_after_mock_queue.splice(0);
|
|
2755
|
+
for (const task of queue)
|
|
2756
|
+
task();
|
|
2757
|
+
}
|
|
2758
|
+
$.$mol_after_mock_warp = $mol_after_mock_warp;
|
|
2759
|
+
class $mol_after_mock_commmon extends $mol_object2 {
|
|
2760
|
+
task;
|
|
2761
|
+
promise = Promise.resolve();
|
|
2762
|
+
cancelled = false;
|
|
2763
|
+
id;
|
|
2764
|
+
constructor(task) {
|
|
2765
|
+
super();
|
|
2766
|
+
this.task = task;
|
|
2767
|
+
$.$mol_after_mock_queue.push(task);
|
|
2768
|
+
}
|
|
2769
|
+
destructor() {
|
|
2770
|
+
const index = $.$mol_after_mock_queue.indexOf(this.task);
|
|
2771
|
+
if (index >= 0)
|
|
2772
|
+
$.$mol_after_mock_queue.splice(index, 1);
|
|
2773
|
+
}
|
|
2774
|
+
}
|
|
2775
|
+
$.$mol_after_mock_commmon = $mol_after_mock_commmon;
|
|
2776
|
+
class $mol_after_mock_timeout extends $mol_after_mock_commmon {
|
|
2777
|
+
delay;
|
|
2778
|
+
constructor(delay, task) {
|
|
2779
|
+
super(task);
|
|
2780
|
+
this.delay = delay;
|
|
2781
|
+
}
|
|
2782
|
+
}
|
|
2783
|
+
$.$mol_after_mock_timeout = $mol_after_mock_timeout;
|
|
2784
|
+
})($ || ($ = {}));
|
|
2785
|
+
|
|
2786
|
+
;
|
|
2787
|
+
"use strict";
|
|
2788
|
+
var $;
|
|
2789
|
+
(function ($) {
|
|
2790
|
+
class $mol_after_tick extends $mol_object2 {
|
|
2791
|
+
task;
|
|
2792
|
+
static promise = null;
|
|
2793
|
+
cancelled = false;
|
|
2794
|
+
constructor(task) {
|
|
2795
|
+
super();
|
|
2796
|
+
this.task = task;
|
|
2797
|
+
if (!$mol_after_tick.promise)
|
|
2798
|
+
$mol_after_tick.promise = Promise.resolve().then(() => {
|
|
2799
|
+
$mol_after_tick.promise = null;
|
|
2800
|
+
});
|
|
2801
|
+
$mol_after_tick.promise.then(() => {
|
|
2802
|
+
if (this.cancelled)
|
|
2803
|
+
return;
|
|
2804
|
+
task();
|
|
2805
|
+
});
|
|
2806
|
+
}
|
|
2807
|
+
destructor() {
|
|
2808
|
+
this.cancelled = true;
|
|
2809
|
+
}
|
|
2810
|
+
}
|
|
2811
|
+
$.$mol_after_tick = $mol_after_tick;
|
|
2812
|
+
})($ || ($ = {}));
|
|
2813
|
+
|
|
2814
|
+
;
|
|
2815
|
+
"use strict";
|
|
2816
|
+
var $;
|
|
2817
|
+
(function ($_1) {
|
|
2818
|
+
$mol_test_mocks.push($ => {
|
|
2819
|
+
$.$mol_after_tick = $mol_after_mock_commmon;
|
|
2820
|
+
});
|
|
2821
|
+
})($ || ($ = {}));
|
|
2822
|
+
|
|
2823
|
+
;
|
|
2824
|
+
"use strict";
|
|
2825
|
+
var $;
|
|
2826
|
+
(function ($) {
|
|
2827
|
+
const handled = new WeakSet();
|
|
2828
|
+
class $mol_wire_fiber extends $mol_wire_pub_sub {
|
|
2829
|
+
task;
|
|
2830
|
+
host;
|
|
2831
|
+
static warm = true;
|
|
2832
|
+
static planning = new Set();
|
|
2833
|
+
static reaping = new Set();
|
|
2834
|
+
static plan_task = null;
|
|
2835
|
+
static plan() {
|
|
2836
|
+
if (this.plan_task)
|
|
2837
|
+
return;
|
|
2838
|
+
this.plan_task = new $mol_after_tick(() => {
|
|
2839
|
+
try {
|
|
2840
|
+
this.sync();
|
|
2841
|
+
}
|
|
2842
|
+
finally {
|
|
2843
|
+
$mol_wire_fiber.plan_task = null;
|
|
2844
|
+
}
|
|
2845
|
+
});
|
|
2846
|
+
}
|
|
2847
|
+
static sync() {
|
|
2848
|
+
while (this.planning.size) {
|
|
2849
|
+
for (const fiber of this.planning) {
|
|
2850
|
+
this.planning.delete(fiber);
|
|
2851
|
+
if (fiber.cursor >= 0)
|
|
2852
|
+
continue;
|
|
2853
|
+
if (fiber.cursor === $mol_wire_cursor.final)
|
|
2854
|
+
continue;
|
|
2855
|
+
fiber.fresh();
|
|
2856
|
+
}
|
|
2857
|
+
}
|
|
2858
|
+
while (this.reaping.size) {
|
|
2859
|
+
const fibers = this.reaping;
|
|
2860
|
+
this.reaping = new Set;
|
|
2861
|
+
for (const fiber of fibers) {
|
|
2862
|
+
if (!fiber.sub_empty)
|
|
2863
|
+
continue;
|
|
2864
|
+
fiber.destructor();
|
|
2865
|
+
}
|
|
2866
|
+
}
|
|
2867
|
+
}
|
|
2868
|
+
[Symbol.toStringTag];
|
|
2869
|
+
cache = undefined;
|
|
2870
|
+
get args() {
|
|
2871
|
+
return this.data.slice(0, this.pub_from);
|
|
2872
|
+
}
|
|
2873
|
+
result() {
|
|
2874
|
+
if ($mol_promise_like(this.cache))
|
|
2875
|
+
return;
|
|
2876
|
+
if (this.cache instanceof Error)
|
|
2877
|
+
return;
|
|
2878
|
+
return this.cache;
|
|
2879
|
+
}
|
|
2880
|
+
get incompleted() {
|
|
2881
|
+
return $mol_promise_like(this.cache);
|
|
2882
|
+
}
|
|
2883
|
+
field() {
|
|
2884
|
+
return this.task.name + '<>';
|
|
2885
|
+
}
|
|
2886
|
+
constructor(id, task, host, args) {
|
|
2887
|
+
super();
|
|
2888
|
+
this.task = task;
|
|
2889
|
+
this.host = host;
|
|
2890
|
+
if (args)
|
|
2891
|
+
this.data.push(...args);
|
|
2892
|
+
this.pub_from = this.sub_from = args?.length ?? 0;
|
|
2893
|
+
this[Symbol.toStringTag] = id;
|
|
2894
|
+
}
|
|
2895
|
+
plan() {
|
|
2896
|
+
$mol_wire_fiber.planning.add(this);
|
|
2897
|
+
$mol_wire_fiber.plan();
|
|
2898
|
+
return this;
|
|
2899
|
+
}
|
|
2900
|
+
reap() {
|
|
2901
|
+
$mol_wire_fiber.reaping.add(this);
|
|
2902
|
+
$mol_wire_fiber.plan();
|
|
2903
|
+
}
|
|
2904
|
+
toString() {
|
|
2905
|
+
return this[Symbol.toStringTag];
|
|
2906
|
+
}
|
|
2907
|
+
toJSON() {
|
|
2908
|
+
return this[Symbol.toStringTag];
|
|
2909
|
+
}
|
|
2910
|
+
[$mol_dev_format_head]() {
|
|
2911
|
+
const cursor = {
|
|
2912
|
+
[$mol_wire_cursor.stale]: '🔴',
|
|
2913
|
+
[$mol_wire_cursor.doubt]: '🟡',
|
|
2914
|
+
[$mol_wire_cursor.fresh]: '🟢',
|
|
2915
|
+
[$mol_wire_cursor.final]: '🔵',
|
|
2916
|
+
}[this.cursor] ?? this.cursor.toString();
|
|
2917
|
+
return $mol_dev_format_div({}, $mol_owning_check(this, this.cache)
|
|
2918
|
+
? $mol_dev_format_auto({
|
|
2919
|
+
[$mol_dev_format_head]: () => $mol_dev_format_shade(cursor),
|
|
2920
|
+
[$mol_dev_format_body]: () => $mol_dev_format_native(this),
|
|
2921
|
+
})
|
|
2922
|
+
: $mol_dev_format_shade($mol_dev_format_native(this), cursor), $mol_dev_format_auto(this.cache));
|
|
2923
|
+
}
|
|
2924
|
+
get $() {
|
|
2925
|
+
return (this.host ?? this.task)['$'];
|
|
2926
|
+
}
|
|
2927
|
+
emit(quant = $mol_wire_cursor.stale) {
|
|
2928
|
+
if (this.sub_empty)
|
|
2929
|
+
this.plan();
|
|
2930
|
+
else
|
|
2931
|
+
super.emit(quant);
|
|
2932
|
+
}
|
|
2933
|
+
fresh() {
|
|
2934
|
+
if (this.cursor === $mol_wire_cursor.fresh)
|
|
2935
|
+
return;
|
|
2936
|
+
if (this.cursor === $mol_wire_cursor.final)
|
|
2937
|
+
return;
|
|
2938
|
+
check: if (this.cursor === $mol_wire_cursor.doubt) {
|
|
2939
|
+
for (let i = this.pub_from; i < this.sub_from; i += 2) {
|
|
2940
|
+
;
|
|
2941
|
+
this.data[i]?.fresh();
|
|
2942
|
+
if (this.cursor !== $mol_wire_cursor.doubt)
|
|
2943
|
+
break check;
|
|
2944
|
+
}
|
|
2945
|
+
this.cursor = $mol_wire_cursor.fresh;
|
|
2946
|
+
return;
|
|
2947
|
+
}
|
|
2948
|
+
const bu = this.track_on();
|
|
2949
|
+
let result;
|
|
2950
|
+
try {
|
|
2951
|
+
switch (this.pub_from) {
|
|
2952
|
+
case 0:
|
|
2953
|
+
result = this.task.call(this.host);
|
|
2954
|
+
break;
|
|
2955
|
+
case 1:
|
|
2956
|
+
result = this.task.call(this.host, this.data[0]);
|
|
2957
|
+
break;
|
|
2958
|
+
default:
|
|
2959
|
+
result = this.task.call(this.host, ...this.args);
|
|
2960
|
+
break;
|
|
2961
|
+
}
|
|
2962
|
+
if ($mol_promise_like(result) && !handled.has(result)) {
|
|
2963
|
+
const put = (res) => {
|
|
2964
|
+
if (this.cache === result)
|
|
2965
|
+
this.put(res);
|
|
2966
|
+
return res;
|
|
2967
|
+
};
|
|
2968
|
+
result = result.then(put, put);
|
|
2969
|
+
}
|
|
2970
|
+
}
|
|
2971
|
+
catch (error) {
|
|
2972
|
+
if (error instanceof Error || $mol_promise_like(error)) {
|
|
2973
|
+
result = error;
|
|
2974
|
+
}
|
|
2975
|
+
else {
|
|
2976
|
+
result = new Error(String(error), { cause: error });
|
|
2977
|
+
}
|
|
2978
|
+
if ($mol_promise_like(result) && !handled.has(result)) {
|
|
2979
|
+
result = result.finally(() => {
|
|
2980
|
+
if (this.cache === result)
|
|
2981
|
+
this.absorb();
|
|
2982
|
+
});
|
|
2983
|
+
}
|
|
2984
|
+
}
|
|
2985
|
+
if ($mol_promise_like(result) && !handled.has(result)) {
|
|
2986
|
+
result = Object.assign(result, {
|
|
2987
|
+
destructor: result['destructor'] ?? (() => { })
|
|
2988
|
+
});
|
|
2989
|
+
handled.add(result);
|
|
2990
|
+
const error = new Error(`Promise in ${this}`);
|
|
2991
|
+
Object.defineProperty(result, 'stack', { get: () => error.stack });
|
|
2992
|
+
}
|
|
2993
|
+
if (!$mol_promise_like(result)) {
|
|
2994
|
+
this.track_cut();
|
|
2995
|
+
}
|
|
2996
|
+
this.track_off(bu);
|
|
2997
|
+
this.put(result);
|
|
2998
|
+
return this;
|
|
2999
|
+
}
|
|
3000
|
+
refresh() {
|
|
3001
|
+
this.cursor = $mol_wire_cursor.stale;
|
|
3002
|
+
this.fresh();
|
|
3003
|
+
}
|
|
3004
|
+
sync() {
|
|
3005
|
+
if (!$mol_wire_fiber.warm) {
|
|
3006
|
+
return this.result();
|
|
3007
|
+
}
|
|
3008
|
+
this.promote();
|
|
3009
|
+
this.fresh();
|
|
3010
|
+
if (this.cache instanceof Error) {
|
|
3011
|
+
return $mol_fail_hidden(this.cache);
|
|
3012
|
+
}
|
|
3013
|
+
if ($mol_promise_like(this.cache)) {
|
|
3014
|
+
return $mol_fail_hidden(this.cache);
|
|
3015
|
+
}
|
|
3016
|
+
return this.cache;
|
|
3017
|
+
}
|
|
3018
|
+
async async() {
|
|
3019
|
+
while (true) {
|
|
3020
|
+
this.fresh();
|
|
3021
|
+
if (this.cache instanceof Error) {
|
|
3022
|
+
$mol_fail_hidden(this.cache);
|
|
3023
|
+
}
|
|
3024
|
+
if (!$mol_promise_like(this.cache))
|
|
3025
|
+
return this.cache;
|
|
3026
|
+
await Promise.race([this.cache, this.step()]);
|
|
3027
|
+
if (!$mol_promise_like(this.cache))
|
|
3028
|
+
return this.cache;
|
|
3029
|
+
if (this.cursor === $mol_wire_cursor.final) {
|
|
3030
|
+
await new Promise(() => { });
|
|
3031
|
+
}
|
|
3032
|
+
}
|
|
3033
|
+
}
|
|
3034
|
+
step() {
|
|
3035
|
+
return new Promise(done => {
|
|
3036
|
+
const sub = new $mol_wire_pub_sub;
|
|
3037
|
+
const prev = sub.track_on();
|
|
3038
|
+
sub.track_next(this);
|
|
3039
|
+
sub.track_off(prev);
|
|
3040
|
+
sub.absorb = () => {
|
|
3041
|
+
done(null);
|
|
3042
|
+
setTimeout(() => sub.destructor());
|
|
3043
|
+
};
|
|
3044
|
+
});
|
|
3045
|
+
}
|
|
3046
|
+
}
|
|
3047
|
+
$.$mol_wire_fiber = $mol_wire_fiber;
|
|
3048
|
+
})($ || ($ = {}));
|
|
3049
|
+
|
|
3050
|
+
;
|
|
3051
|
+
"use strict";
|
|
3052
|
+
var $;
|
|
3053
|
+
(function ($) {
|
|
3054
|
+
$mol_test({
|
|
3055
|
+
'Sync execution'() {
|
|
3056
|
+
class Sync extends $mol_object2 {
|
|
3057
|
+
static calc(a, b) {
|
|
3058
|
+
return a + b;
|
|
3059
|
+
}
|
|
3060
|
+
}
|
|
3061
|
+
__decorate([
|
|
3062
|
+
$mol_wire_method
|
|
3063
|
+
], Sync, "calc", null);
|
|
3064
|
+
$mol_assert_equal(Sync.calc(1, 2), 3);
|
|
3065
|
+
},
|
|
3066
|
+
async 'async <=> sync'() {
|
|
3067
|
+
class SyncAsync extends $mol_object2 {
|
|
3068
|
+
static async val(a) {
|
|
3069
|
+
return a;
|
|
3070
|
+
}
|
|
3071
|
+
static sum(a, b) {
|
|
3072
|
+
const syn = $mol_wire_sync(this);
|
|
3073
|
+
return syn.val(a) + syn.val(b);
|
|
3074
|
+
}
|
|
3075
|
+
static async calc(a, b) {
|
|
3076
|
+
return 5 + await $mol_wire_async(this).sum(a, b);
|
|
3077
|
+
}
|
|
3078
|
+
}
|
|
3079
|
+
$mol_assert_equal(await SyncAsync.calc(1, 2), 8);
|
|
3080
|
+
},
|
|
3081
|
+
async 'Idempotence control'() {
|
|
3082
|
+
class Idempotence extends $mol_object2 {
|
|
3083
|
+
static logs_idemp = 0;
|
|
3084
|
+
static logs_unidemp = 0;
|
|
3085
|
+
static log_idemp() {
|
|
3086
|
+
this.logs_idemp += 1;
|
|
3087
|
+
}
|
|
3088
|
+
static log_unidemp() {
|
|
3089
|
+
this.logs_unidemp += 1;
|
|
3090
|
+
}
|
|
3091
|
+
static async val(a) {
|
|
3092
|
+
return a;
|
|
3093
|
+
}
|
|
3094
|
+
static sum(a, b) {
|
|
3095
|
+
this.log_idemp();
|
|
3096
|
+
this.log_unidemp();
|
|
3097
|
+
const syn = $mol_wire_sync(this);
|
|
3098
|
+
return syn.val(a) + syn.val(b);
|
|
3099
|
+
}
|
|
3100
|
+
static async calc(a, b) {
|
|
3101
|
+
return 5 + await $mol_wire_async(this).sum(a, b);
|
|
3102
|
+
}
|
|
3103
|
+
}
|
|
3104
|
+
__decorate([
|
|
3105
|
+
$mol_wire_method
|
|
3106
|
+
], Idempotence, "log_idemp", null);
|
|
3107
|
+
$mol_assert_equal(await Idempotence.calc(1, 2), 8);
|
|
3108
|
+
$mol_assert_equal(Idempotence.logs_idemp, 1);
|
|
3109
|
+
$mol_assert_equal(Idempotence.logs_unidemp, 3);
|
|
3110
|
+
},
|
|
3111
|
+
async 'Error handling'() {
|
|
3112
|
+
class Handle extends $mol_object2 {
|
|
3113
|
+
static async sum(a, b) {
|
|
3114
|
+
$mol_fail(new Error('test error ' + (a + b)));
|
|
3115
|
+
}
|
|
3116
|
+
static check() {
|
|
3117
|
+
try {
|
|
3118
|
+
return $mol_wire_sync(Handle).sum(1, 2);
|
|
3119
|
+
}
|
|
3120
|
+
catch (error) {
|
|
3121
|
+
if ($mol_promise_like(error))
|
|
3122
|
+
$mol_fail_hidden(error);
|
|
3123
|
+
$mol_assert_equal(error.message, 'test error 3');
|
|
3124
|
+
}
|
|
3125
|
+
}
|
|
3126
|
+
}
|
|
3127
|
+
await $mol_wire_async(Handle).check();
|
|
3128
|
+
},
|
|
3129
|
+
});
|
|
3130
|
+
})($ || ($ = {}));
|
|
3131
|
+
|
|
3132
|
+
;
|
|
3133
|
+
"use strict";
|
|
3134
|
+
var $;
|
|
3135
|
+
(function ($) {
|
|
3136
|
+
class $mol_wire_task extends $mol_wire_fiber {
|
|
3137
|
+
static getter(task) {
|
|
3138
|
+
return function $mol_wire_task_get(host, args) {
|
|
3139
|
+
const sub = $mol_wire_auto();
|
|
3140
|
+
const existen = sub?.track_next();
|
|
3141
|
+
reuse: if (existen) {
|
|
3142
|
+
if (!existen.temp)
|
|
3143
|
+
break reuse;
|
|
3144
|
+
if (existen.host !== host)
|
|
3145
|
+
break reuse;
|
|
3146
|
+
if (existen.task !== task)
|
|
3147
|
+
break reuse;
|
|
3148
|
+
if (!$mol_compare_deep(existen.args, args))
|
|
3149
|
+
break reuse;
|
|
3150
|
+
return existen;
|
|
3151
|
+
}
|
|
3152
|
+
const key = (host?.[Symbol.toStringTag] ?? host) + ('.' + task.name + '<#>');
|
|
3153
|
+
const next = new $mol_wire_task(key, task, host, args);
|
|
3154
|
+
if (existen?.temp) {
|
|
3155
|
+
$$.$mol_log3_warn({
|
|
3156
|
+
place: '$mol_wire_task',
|
|
3157
|
+
message: `Non idempotency`,
|
|
3158
|
+
existen,
|
|
3159
|
+
next,
|
|
3160
|
+
hint: 'Ignore it',
|
|
3161
|
+
});
|
|
3162
|
+
}
|
|
3163
|
+
return next;
|
|
3164
|
+
};
|
|
3165
|
+
}
|
|
3166
|
+
get temp() {
|
|
3167
|
+
return true;
|
|
3168
|
+
}
|
|
3169
|
+
complete() {
|
|
3170
|
+
if ($mol_promise_like(this.cache))
|
|
3171
|
+
return;
|
|
3172
|
+
this.destructor();
|
|
3173
|
+
}
|
|
3174
|
+
put(next) {
|
|
3175
|
+
const prev = this.cache;
|
|
3176
|
+
this.cache = next;
|
|
3177
|
+
if ($mol_promise_like(next)) {
|
|
3178
|
+
this.cursor = $mol_wire_cursor.fresh;
|
|
3179
|
+
if (next !== prev)
|
|
3180
|
+
this.emit();
|
|
3181
|
+
return next;
|
|
3182
|
+
}
|
|
3183
|
+
this.cursor = $mol_wire_cursor.final;
|
|
3184
|
+
if (this.sub_empty)
|
|
3185
|
+
this.destructor();
|
|
3186
|
+
else if (next !== prev)
|
|
3187
|
+
this.emit();
|
|
3188
|
+
return next;
|
|
3189
|
+
}
|
|
3190
|
+
}
|
|
3191
|
+
$.$mol_wire_task = $mol_wire_task;
|
|
3192
|
+
})($ || ($ = {}));
|
|
3193
|
+
|
|
3194
|
+
;
|
|
3195
|
+
"use strict";
|
|
3196
|
+
var $;
|
|
3197
|
+
(function ($) {
|
|
3198
|
+
function $mol_wire_method(host, field, descr) {
|
|
3199
|
+
if (!descr)
|
|
3200
|
+
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
|
3201
|
+
const orig = descr?.value ?? host[field];
|
|
3202
|
+
const sup = Reflect.getPrototypeOf(host);
|
|
3203
|
+
if (typeof sup[field] === 'function') {
|
|
3204
|
+
Object.defineProperty(orig, 'name', { value: sup[field].name });
|
|
3205
|
+
}
|
|
3206
|
+
const temp = $mol_wire_task.getter(orig);
|
|
3207
|
+
const value = function (...args) {
|
|
3208
|
+
const fiber = temp(this ?? null, args);
|
|
3209
|
+
return fiber.sync();
|
|
3210
|
+
};
|
|
3211
|
+
Object.defineProperty(value, 'name', { value: orig.name + ' ' });
|
|
3212
|
+
Object.assign(value, { orig });
|
|
3213
|
+
const descr2 = { ...descr, value };
|
|
3214
|
+
Reflect.defineProperty(host, field, descr2);
|
|
3215
|
+
return descr2;
|
|
3216
|
+
}
|
|
3217
|
+
$.$mol_wire_method = $mol_wire_method;
|
|
3218
|
+
})($ || ($ = {}));
|
|
3219
|
+
|
|
3220
|
+
;
|
|
3221
|
+
"use strict";
|
|
3222
|
+
var $;
|
|
3223
|
+
(function ($) {
|
|
3224
|
+
function $mol_wire_async(obj) {
|
|
3225
|
+
let fiber;
|
|
3226
|
+
const temp = $mol_wire_task.getter(obj);
|
|
3227
|
+
return new Proxy(obj, {
|
|
3228
|
+
get(obj, field) {
|
|
3229
|
+
const val = obj[field];
|
|
3230
|
+
if (typeof val !== 'function')
|
|
3231
|
+
return val;
|
|
3232
|
+
let fiber;
|
|
3233
|
+
const temp = $mol_wire_task.getter(val);
|
|
3234
|
+
return function $mol_wire_async(...args) {
|
|
3235
|
+
fiber?.destructor();
|
|
3236
|
+
fiber = temp(obj, args);
|
|
3237
|
+
return fiber.async();
|
|
3238
|
+
};
|
|
3239
|
+
},
|
|
3240
|
+
apply(obj, self, args) {
|
|
3241
|
+
fiber?.destructor();
|
|
3242
|
+
fiber = temp(self, args);
|
|
3243
|
+
return fiber.async();
|
|
3244
|
+
},
|
|
3245
|
+
});
|
|
3246
|
+
}
|
|
3247
|
+
$.$mol_wire_async = $mol_wire_async;
|
|
3248
|
+
})($ || ($ = {}));
|
|
3249
|
+
|
|
3250
|
+
;
|
|
3251
|
+
"use strict";
|
|
3252
|
+
var $;
|
|
3253
|
+
(function ($_1) {
|
|
3254
|
+
$mol_test({
|
|
3255
|
+
'test types'($) {
|
|
3256
|
+
class A {
|
|
3257
|
+
static a() {
|
|
3258
|
+
return '';
|
|
3259
|
+
}
|
|
3260
|
+
static b() {
|
|
3261
|
+
return $mol_wire_async(this).a();
|
|
3262
|
+
}
|
|
3263
|
+
}
|
|
3264
|
+
},
|
|
3265
|
+
async 'Latest method calls wins'($) {
|
|
3266
|
+
class NameLogger extends $mol_object2 {
|
|
3267
|
+
static $ = $;
|
|
3268
|
+
static first = [];
|
|
3269
|
+
static last = [];
|
|
3270
|
+
static send(next) {
|
|
3271
|
+
$mol_wire_sync(this.first).push(next);
|
|
3272
|
+
this.$.$mol_wait_timeout(0);
|
|
3273
|
+
this.last.push(next);
|
|
3274
|
+
}
|
|
3275
|
+
}
|
|
3276
|
+
const name = $mol_wire_async(NameLogger).send;
|
|
3277
|
+
name('john');
|
|
3278
|
+
const promise = name('jin');
|
|
3279
|
+
$.$mol_after_mock_warp();
|
|
3280
|
+
await promise;
|
|
3281
|
+
$mol_assert_like(NameLogger.first, ['john', 'jin']);
|
|
3282
|
+
$mol_assert_like(NameLogger.last, ['jin']);
|
|
3283
|
+
},
|
|
3284
|
+
async 'Latest function calls wins'($) {
|
|
3285
|
+
const first = [];
|
|
3286
|
+
const last = [];
|
|
3287
|
+
function send_name(next) {
|
|
3288
|
+
$mol_wire_sync(first).push(next);
|
|
3289
|
+
$.$mol_wait_timeout(0);
|
|
3290
|
+
last.push(next);
|
|
3291
|
+
}
|
|
3292
|
+
const name = $mol_wire_async(send_name);
|
|
3293
|
+
name('john');
|
|
3294
|
+
const promise = name('jin');
|
|
3295
|
+
$.$mol_after_mock_warp();
|
|
3296
|
+
await promise;
|
|
3297
|
+
$mol_assert_like(first, ['john', 'jin']);
|
|
3298
|
+
$mol_assert_like(last, ['jin']);
|
|
3299
|
+
},
|
|
3300
|
+
});
|
|
3301
|
+
})($ || ($ = {}));
|
|
3302
|
+
|
|
3303
|
+
;
|
|
3304
|
+
"use strict";
|
|
3305
|
+
var $;
|
|
3306
|
+
(function ($) {
|
|
3307
|
+
function $mol_wire_sync(obj) {
|
|
3308
|
+
return new Proxy(obj, {
|
|
3309
|
+
get(obj, field) {
|
|
3310
|
+
const val = obj[field];
|
|
3311
|
+
if (typeof val !== 'function')
|
|
3312
|
+
return val;
|
|
3313
|
+
const temp = $mol_wire_task.getter(val);
|
|
3314
|
+
return function $mol_wire_sync(...args) {
|
|
3315
|
+
const fiber = temp(obj, args);
|
|
3316
|
+
return fiber.sync();
|
|
3317
|
+
};
|
|
3318
|
+
},
|
|
3319
|
+
apply(obj, self, args) {
|
|
3320
|
+
const temp = $mol_wire_task.getter(obj);
|
|
3321
|
+
const fiber = temp(self, args);
|
|
3322
|
+
return fiber.sync();
|
|
3323
|
+
},
|
|
3324
|
+
});
|
|
3325
|
+
}
|
|
3326
|
+
$.$mol_wire_sync = $mol_wire_sync;
|
|
3327
|
+
})($ || ($ = {}));
|
|
3328
|
+
|
|
3329
|
+
;
|
|
3330
|
+
"use strict";
|
|
3331
|
+
var $;
|
|
3332
|
+
(function ($_1) {
|
|
3333
|
+
$mol_test({
|
|
3334
|
+
'test types'($) {
|
|
3335
|
+
class A {
|
|
3336
|
+
static a() {
|
|
3337
|
+
return Promise.resolve('');
|
|
3338
|
+
}
|
|
3339
|
+
static b() {
|
|
3340
|
+
return $mol_wire_sync(this).a();
|
|
3341
|
+
}
|
|
3342
|
+
}
|
|
3343
|
+
},
|
|
3344
|
+
});
|
|
3345
|
+
})($ || ($ = {}));
|
|
3346
|
+
|
|
3347
|
+
;
|
|
3348
|
+
"use strict";
|
|
3349
|
+
var $;
|
|
3350
|
+
(function ($) {
|
|
3351
|
+
function $mol_promise() {
|
|
3352
|
+
let done;
|
|
3353
|
+
let fail;
|
|
3354
|
+
const promise = new Promise((d, f) => {
|
|
3355
|
+
done = d;
|
|
3356
|
+
fail = f;
|
|
3357
|
+
});
|
|
3358
|
+
return Object.assign(promise, {
|
|
3359
|
+
done,
|
|
3360
|
+
fail,
|
|
3361
|
+
});
|
|
3362
|
+
}
|
|
3363
|
+
$.$mol_promise = $mol_promise;
|
|
3364
|
+
})($ || ($ = {}));
|
|
3365
|
+
|
|
3366
|
+
;
|
|
3367
|
+
"use strict";
|
|
3368
|
+
var $;
|
|
3369
|
+
(function ($) {
|
|
3370
|
+
class $mol_after_timeout extends $mol_object2 {
|
|
3371
|
+
delay;
|
|
3372
|
+
task;
|
|
3373
|
+
id;
|
|
3374
|
+
constructor(delay, task) {
|
|
3375
|
+
super();
|
|
3376
|
+
this.delay = delay;
|
|
3377
|
+
this.task = task;
|
|
3378
|
+
this.id = setTimeout(task, delay);
|
|
3379
|
+
}
|
|
3380
|
+
destructor() {
|
|
3381
|
+
clearTimeout(this.id);
|
|
3382
|
+
}
|
|
3383
|
+
}
|
|
3384
|
+
$.$mol_after_timeout = $mol_after_timeout;
|
|
3385
|
+
})($ || ($ = {}));
|
|
3386
|
+
|
|
3387
|
+
;
|
|
3388
|
+
"use strict";
|
|
3389
|
+
var $;
|
|
3390
|
+
(function ($_1) {
|
|
3391
|
+
$mol_test_mocks.push($ => {
|
|
3392
|
+
$.$mol_after_timeout = $mol_after_mock_timeout;
|
|
3393
|
+
});
|
|
3394
|
+
})($ || ($ = {}));
|
|
3395
|
+
|
|
3396
|
+
;
|
|
3397
|
+
"use strict";
|
|
3398
|
+
var $;
|
|
3399
|
+
(function ($) {
|
|
3400
|
+
function $mol_wait_timeout_async(timeout) {
|
|
3401
|
+
const promise = $mol_promise();
|
|
3402
|
+
const task = new this.$mol_after_timeout(timeout, () => promise.done());
|
|
3403
|
+
return Object.assign(promise, {
|
|
3404
|
+
destructor: () => task.destructor()
|
|
3405
|
+
});
|
|
3406
|
+
}
|
|
3407
|
+
$.$mol_wait_timeout_async = $mol_wait_timeout_async;
|
|
3408
|
+
function $mol_wait_timeout(timeout) {
|
|
3409
|
+
return this.$mol_wire_sync(this).$mol_wait_timeout_async(timeout);
|
|
3410
|
+
}
|
|
3411
|
+
$.$mol_wait_timeout = $mol_wait_timeout;
|
|
3412
|
+
})($ || ($ = {}));
|
|
3413
|
+
|
|
3414
|
+
;
|
|
3415
|
+
"use strict";
|
|
3416
|
+
var $;
|
|
3417
|
+
(function ($) {
|
|
3418
|
+
class $mol_run_error extends $mol_error_mix {
|
|
3419
|
+
}
|
|
3420
|
+
$.$mol_run_error = $mol_run_error;
|
|
3421
|
+
const child_process = $node['child_process'];
|
|
3422
|
+
$.$mol_run_spawn = child_process.spawn.bind(child_process);
|
|
3423
|
+
function $mol_run_async({ dir, timeout, command, env }) {
|
|
3424
|
+
const args_raw = typeof command === 'string' ? command.split(' ') : command;
|
|
3425
|
+
const [app, ...args] = args_raw;
|
|
3426
|
+
const sub = this.$mol_run_spawn(app, args, {
|
|
3427
|
+
shell: true,
|
|
3428
|
+
cwd: dir,
|
|
3429
|
+
env
|
|
3430
|
+
});
|
|
3431
|
+
this.$mol_log3_come({
|
|
3432
|
+
place: '$mol_run_async',
|
|
3433
|
+
pid: sub.pid,
|
|
3434
|
+
message: 'Run',
|
|
3435
|
+
command: args_raw.join(' '),
|
|
3436
|
+
dir: $node.path.relative('', dir),
|
|
3437
|
+
});
|
|
3438
|
+
let killed = false;
|
|
3439
|
+
let timer;
|
|
3440
|
+
const std_data = [];
|
|
3441
|
+
const error_data = [];
|
|
3442
|
+
const add = (std_chunk, error_chunk) => {
|
|
3443
|
+
if (std_chunk)
|
|
3444
|
+
std_data.push(std_chunk);
|
|
3445
|
+
if (error_chunk)
|
|
3446
|
+
error_data.push(error_chunk);
|
|
3447
|
+
if (!timeout)
|
|
3448
|
+
return;
|
|
3449
|
+
clearTimeout(timer);
|
|
3450
|
+
timer = setTimeout(() => {
|
|
3451
|
+
const signal = killed ? 'SIGKILL' : 'SIGTERM';
|
|
3452
|
+
killed = true;
|
|
3453
|
+
add();
|
|
3454
|
+
sub.kill(signal);
|
|
3455
|
+
}, timeout);
|
|
3456
|
+
};
|
|
3457
|
+
add();
|
|
3458
|
+
sub.stdout?.on('data', data => add(data));
|
|
3459
|
+
sub.stderr?.on('data', data => add(undefined, data));
|
|
3460
|
+
const promise = new Promise((done, fail) => {
|
|
3461
|
+
const close = (error, status = null, signal = null) => {
|
|
3462
|
+
if (!timer && timeout)
|
|
3463
|
+
return;
|
|
3464
|
+
clearTimeout(timer);
|
|
3465
|
+
timer = undefined;
|
|
3466
|
+
const res = {
|
|
3467
|
+
pid: sub.pid,
|
|
3468
|
+
status,
|
|
3469
|
+
signal,
|
|
3470
|
+
get stdout() { return Buffer.concat(std_data); },
|
|
3471
|
+
get stderr() { return Buffer.concat(error_data); }
|
|
3472
|
+
};
|
|
3473
|
+
this.$mol_log3_done({
|
|
3474
|
+
place: '$mol_run_async',
|
|
3475
|
+
pid: sub.pid,
|
|
3476
|
+
message: 'Run',
|
|
3477
|
+
status,
|
|
3478
|
+
command: args_raw.join(' '),
|
|
3479
|
+
dir: $node.path.relative('', dir),
|
|
3480
|
+
});
|
|
3481
|
+
if (error || status || killed)
|
|
3482
|
+
return fail(new $mol_run_error((res.stderr.toString() || res.stdout.toString() || 'Run error') + (killed ? ', timeout' : ''), { signal, timeout: killed }, ...error ? [error] : []));
|
|
3483
|
+
done(res);
|
|
3484
|
+
};
|
|
3485
|
+
sub.on('disconnect', () => close(new Error('Disconnected')));
|
|
3486
|
+
sub.on('error', err => close(err));
|
|
3487
|
+
sub.on('exit', (status, signal) => close(null, status, signal));
|
|
3488
|
+
});
|
|
3489
|
+
return Object.assign(promise, { destructor: () => {
|
|
3490
|
+
clearTimeout(timer);
|
|
3491
|
+
sub.kill('SIGKILL');
|
|
3492
|
+
} });
|
|
3493
|
+
}
|
|
3494
|
+
$.$mol_run_async = $mol_run_async;
|
|
3495
|
+
function $mol_run(options) {
|
|
3496
|
+
if (!options.env)
|
|
3497
|
+
options = { ...options, env: this.$mol_env() };
|
|
3498
|
+
return $mol_wire_sync(this).$mol_run_async(options);
|
|
3499
|
+
}
|
|
3500
|
+
$.$mol_run = $mol_run;
|
|
3501
|
+
})($ || ($ = {}));
|
|
3502
|
+
|
|
3503
|
+
;
|
|
3504
|
+
"use strict";
|
|
3505
|
+
var $;
|
|
3506
|
+
(function ($_1) {
|
|
3507
|
+
$mol_test({
|
|
3508
|
+
async 'exec timeout auto kill child process'($) {
|
|
3509
|
+
let close_mock = () => { };
|
|
3510
|
+
const context_mock = $.$mol_ambient({
|
|
3511
|
+
$mol_run_spawn: () => ({
|
|
3512
|
+
on(name, cb) {
|
|
3513
|
+
if (name === 'exit')
|
|
3514
|
+
close_mock = cb;
|
|
3515
|
+
},
|
|
3516
|
+
kill() { close_mock(); }
|
|
3517
|
+
})
|
|
3518
|
+
});
|
|
3519
|
+
let message = '';
|
|
3520
|
+
try {
|
|
3521
|
+
const res = await $mol_wire_async(context_mock).$mol_run({ command: 'sleep 10', dir: '.', timeout: 10 });
|
|
3522
|
+
}
|
|
3523
|
+
catch (e) {
|
|
3524
|
+
message = e.message;
|
|
3525
|
+
}
|
|
3526
|
+
$mol_assert_equal(message, 'Run error, timeout');
|
|
3527
|
+
}
|
|
3528
|
+
});
|
|
3529
|
+
})($ || ($ = {}));
|
|
3530
|
+
|
|
3531
|
+
;
|
|
3532
|
+
"use strict";
|
|
3533
|
+
var $;
|
|
3534
|
+
(function ($) {
|
|
3535
|
+
function $mol_exec(dir, command, ...args) {
|
|
3536
|
+
return this.$mol_run({ command: [command, ...args], dir });
|
|
3537
|
+
}
|
|
3538
|
+
$.$mol_exec = $mol_exec;
|
|
3539
|
+
})($ || ($ = {}));
|
|
3540
|
+
|
|
2314
3541
|
;
|
|
2315
3542
|
"use strict";
|
|
2316
3543
|
var $;
|