mol_tree2 1.0.905 → 1.0.907
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.test.js +789 -745
- package/node.test.js.map +1 -1
- package/package.json +1 -1
package/node.test.js
CHANGED
|
@@ -2237,509 +2237,11 @@ require = (req => Object.assign(function require(name) {
|
|
|
2237
2237
|
return $node[name];
|
|
2238
2238
|
}, req))(require);
|
|
2239
2239
|
|
|
2240
|
-
;
|
|
2241
|
-
"use strict";
|
|
2242
|
-
var $;
|
|
2243
|
-
(function ($_1) {
|
|
2244
|
-
$mol_test({
|
|
2245
|
-
'FQN of anon function'($) {
|
|
2246
|
-
const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
|
|
2247
|
-
$mol_assert_equal($$.$mol_func_name_test.name, '');
|
|
2248
|
-
$mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
|
|
2249
|
-
$mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
|
|
2250
|
-
},
|
|
2251
|
-
});
|
|
2252
|
-
})($ || ($ = {}));
|
|
2253
|
-
|
|
2254
|
-
;
|
|
2255
|
-
"use strict";
|
|
2256
|
-
var $;
|
|
2257
|
-
(function ($) {
|
|
2258
|
-
class $mol_error_mix extends AggregateError {
|
|
2259
|
-
cause;
|
|
2260
|
-
name = $$.$mol_func_name(this.constructor).replace(/^\$/, '') + '_Error';
|
|
2261
|
-
constructor(message, cause = {}, ...errors) {
|
|
2262
|
-
super(errors, message, { cause });
|
|
2263
|
-
this.cause = cause;
|
|
2264
|
-
const stack_get = Object.getOwnPropertyDescriptor(this, 'stack')?.get ?? (() => super.stack);
|
|
2265
|
-
Object.defineProperty(this, 'stack', {
|
|
2266
|
-
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()
|
|
2267
|
-
.replace(/at /gm, ' at ')
|
|
2268
|
-
.replace(/^(?! +at )(.*)/gm, ' at | $1 (#)')).join('\n')
|
|
2269
|
-
});
|
|
2270
|
-
}
|
|
2271
|
-
static [Symbol.toPrimitive]() {
|
|
2272
|
-
return this.toString();
|
|
2273
|
-
}
|
|
2274
|
-
static toString() {
|
|
2275
|
-
return $$.$mol_func_name(this);
|
|
2276
|
-
}
|
|
2277
|
-
static make(...params) {
|
|
2278
|
-
return new this(...params);
|
|
2279
|
-
}
|
|
2280
|
-
}
|
|
2281
|
-
$.$mol_error_mix = $mol_error_mix;
|
|
2282
|
-
})($ || ($ = {}));
|
|
2283
|
-
|
|
2284
|
-
;
|
|
2285
|
-
"use strict";
|
|
2286
|
-
var $;
|
|
2287
|
-
(function ($) {
|
|
2288
|
-
$mol_test({
|
|
2289
|
-
'auto name'() {
|
|
2290
|
-
class Invalid extends $mol_error_mix {
|
|
2291
|
-
}
|
|
2292
|
-
const mix = new Invalid('foo');
|
|
2293
|
-
$mol_assert_equal(mix.name, 'Invalid_Error');
|
|
2294
|
-
},
|
|
2295
|
-
'simpe mix'() {
|
|
2296
|
-
const mix = new $mol_error_mix('foo', {}, new Error('bar'), new Error('lol'));
|
|
2297
|
-
$mol_assert_equal(mix.message, 'foo');
|
|
2298
|
-
$mol_assert_equal(mix.errors.map(e => e.message), ['bar', 'lol']);
|
|
2299
|
-
},
|
|
2300
|
-
'provide additional info'() {
|
|
2301
|
-
class Invalid extends $mol_error_mix {
|
|
2302
|
-
}
|
|
2303
|
-
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' }));
|
|
2304
|
-
const hints = [];
|
|
2305
|
-
if (mix instanceof $mol_error_mix) {
|
|
2306
|
-
for (const er of mix.errors) {
|
|
2307
|
-
if (er instanceof Invalid) {
|
|
2308
|
-
hints.push(er.cause?.hint ?? '');
|
|
2309
|
-
}
|
|
2310
|
-
}
|
|
2311
|
-
}
|
|
2312
|
-
$mol_assert_equal(hints, ['> 8 letters', 'need capital letter']);
|
|
2313
|
-
},
|
|
2314
|
-
});
|
|
2315
|
-
})($ || ($ = {}));
|
|
2316
|
-
|
|
2317
|
-
;
|
|
2318
|
-
"use strict";
|
|
2319
|
-
var $;
|
|
2320
|
-
(function ($) {
|
|
2321
|
-
function $mol_log3_area_lazy(event) {
|
|
2322
|
-
const self = this;
|
|
2323
|
-
const stack = self.$mol_log3_stack;
|
|
2324
|
-
const deep = stack.length;
|
|
2325
|
-
let logged = false;
|
|
2326
|
-
stack.push(() => {
|
|
2327
|
-
logged = true;
|
|
2328
|
-
self.$mol_log3_area.call(self, event);
|
|
2329
|
-
});
|
|
2330
|
-
return () => {
|
|
2331
|
-
if (logged)
|
|
2332
|
-
self.console.groupEnd();
|
|
2333
|
-
if (stack.length > deep)
|
|
2334
|
-
stack.length = deep;
|
|
2335
|
-
};
|
|
2336
|
-
}
|
|
2337
|
-
$.$mol_log3_area_lazy = $mol_log3_area_lazy;
|
|
2338
|
-
$.$mol_log3_stack = [];
|
|
2339
|
-
})($ || ($ = {}));
|
|
2340
|
-
|
|
2341
|
-
;
|
|
2342
|
-
"use strict";
|
|
2343
|
-
var $;
|
|
2344
|
-
(function ($) {
|
|
2345
|
-
class $mol_term_color {
|
|
2346
|
-
static reset = this.ansi(0, 0);
|
|
2347
|
-
static bold = this.ansi(1, 22);
|
|
2348
|
-
static italic = this.ansi(3, 23);
|
|
2349
|
-
static underline = this.ansi(4, 24);
|
|
2350
|
-
static inverse = this.ansi(7, 27);
|
|
2351
|
-
static hidden = this.ansi(8, 28);
|
|
2352
|
-
static strike = this.ansi(9, 29);
|
|
2353
|
-
static gray = this.ansi(90, 39);
|
|
2354
|
-
static red = this.ansi(91, 39);
|
|
2355
|
-
static green = this.ansi(92, 39);
|
|
2356
|
-
static yellow = this.ansi(93, 39);
|
|
2357
|
-
static blue = this.ansi(94, 39);
|
|
2358
|
-
static magenta = this.ansi(95, 39);
|
|
2359
|
-
static cyan = this.ansi(96, 39);
|
|
2360
|
-
static Gray = (str) => this.inverse(this.gray(str));
|
|
2361
|
-
static Red = (str) => this.inverse(this.red(str));
|
|
2362
|
-
static Green = (str) => this.inverse(this.green(str));
|
|
2363
|
-
static Yellow = (str) => this.inverse(this.yellow(str));
|
|
2364
|
-
static Blue = (str) => this.inverse(this.blue(str));
|
|
2365
|
-
static Magenta = (str) => this.inverse(this.magenta(str));
|
|
2366
|
-
static Cyan = (str) => this.inverse(this.cyan(str));
|
|
2367
|
-
static ansi(open, close) {
|
|
2368
|
-
if (typeof process === 'undefined')
|
|
2369
|
-
return String;
|
|
2370
|
-
if (!process.stdout.isTTY)
|
|
2371
|
-
return String;
|
|
2372
|
-
const prefix = `\x1b[${open}m`;
|
|
2373
|
-
const postfix = `\x1b[${close}m`;
|
|
2374
|
-
const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
|
|
2375
|
-
return function colorer(str) {
|
|
2376
|
-
str = String(str);
|
|
2377
|
-
if (str === '')
|
|
2378
|
-
return str;
|
|
2379
|
-
const suffix = str.replace(suffix_regexp, prefix);
|
|
2380
|
-
return prefix + suffix + postfix;
|
|
2381
|
-
};
|
|
2382
|
-
}
|
|
2383
|
-
}
|
|
2384
|
-
$.$mol_term_color = $mol_term_color;
|
|
2385
|
-
})($ || ($ = {}));
|
|
2386
|
-
|
|
2387
|
-
;
|
|
2388
|
-
"use strict";
|
|
2389
|
-
var $;
|
|
2390
|
-
(function ($) {
|
|
2391
|
-
function $mol_log3_node_make(level, output, type, color) {
|
|
2392
|
-
return function $mol_log3_logger(event) {
|
|
2393
|
-
if (!event.time)
|
|
2394
|
-
event = { time: new Date().toISOString(), ...event };
|
|
2395
|
-
let tree = this.$mol_tree2_from_json(event);
|
|
2396
|
-
tree = tree.struct(type, tree.kids);
|
|
2397
|
-
let str = color(tree.toString());
|
|
2398
|
-
this.console[level](str);
|
|
2399
|
-
const self = this;
|
|
2400
|
-
return () => self.console.groupEnd();
|
|
2401
|
-
};
|
|
2402
|
-
}
|
|
2403
|
-
$.$mol_log3_node_make = $mol_log3_node_make;
|
|
2404
|
-
$.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
|
|
2405
|
-
$.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
|
|
2406
|
-
$.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
|
|
2407
|
-
$.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
|
|
2408
|
-
$.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
|
|
2409
|
-
$.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
|
|
2410
|
-
})($ || ($ = {}));
|
|
2411
|
-
|
|
2412
|
-
;
|
|
2413
|
-
"use strict";
|
|
2414
|
-
var $;
|
|
2415
|
-
(function ($_1) {
|
|
2416
|
-
$mol_test_mocks.push($ => {
|
|
2417
|
-
$.$mol_log3_come = () => { };
|
|
2418
|
-
$.$mol_log3_done = () => { };
|
|
2419
|
-
$.$mol_log3_fail = () => { };
|
|
2420
|
-
$.$mol_log3_warn = () => { };
|
|
2421
|
-
$.$mol_log3_rise = () => { };
|
|
2422
|
-
$.$mol_log3_area = () => () => { };
|
|
2423
|
-
});
|
|
2424
|
-
})($ || ($ = {}));
|
|
2425
|
-
|
|
2426
|
-
;
|
|
2427
|
-
"use strict";
|
|
2428
|
-
var $;
|
|
2429
|
-
(function ($) {
|
|
2430
|
-
function $mol_env() {
|
|
2431
|
-
return {};
|
|
2432
|
-
}
|
|
2433
|
-
$.$mol_env = $mol_env;
|
|
2434
|
-
})($ || ($ = {}));
|
|
2435
|
-
|
|
2436
|
-
;
|
|
2437
|
-
"use strict";
|
|
2438
|
-
var $;
|
|
2439
|
-
(function ($) {
|
|
2440
|
-
$.$mol_env = function $mol_env() {
|
|
2441
|
-
return this.process.env;
|
|
2442
|
-
};
|
|
2443
|
-
})($ || ($ = {}));
|
|
2444
|
-
|
|
2445
|
-
;
|
|
2446
|
-
"use strict";
|
|
2447
|
-
var $;
|
|
2448
|
-
(function ($) {
|
|
2449
|
-
let $mol_wire_cursor;
|
|
2450
|
-
(function ($mol_wire_cursor) {
|
|
2451
|
-
$mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
|
|
2452
|
-
$mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
|
|
2453
|
-
$mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
|
|
2454
|
-
$mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
|
|
2455
|
-
})($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
|
|
2456
|
-
})($ || ($ = {}));
|
|
2457
|
-
|
|
2458
|
-
;
|
|
2459
|
-
"use strict";
|
|
2460
|
-
var $;
|
|
2461
|
-
(function ($) {
|
|
2462
|
-
class $mol_wire_pub extends Object {
|
|
2463
|
-
data = [];
|
|
2464
|
-
static get [Symbol.species]() {
|
|
2465
|
-
return Array;
|
|
2466
|
-
}
|
|
2467
|
-
sub_from = 0;
|
|
2468
|
-
get sub_list() {
|
|
2469
|
-
const res = [];
|
|
2470
|
-
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
2471
|
-
res.push(this.data[i]);
|
|
2472
|
-
}
|
|
2473
|
-
return res;
|
|
2474
|
-
}
|
|
2475
|
-
get sub_empty() {
|
|
2476
|
-
return this.sub_from === this.data.length;
|
|
2477
|
-
}
|
|
2478
|
-
sub_on(sub, pub_pos) {
|
|
2479
|
-
const pos = this.data.length;
|
|
2480
|
-
this.data.push(sub, pub_pos);
|
|
2481
|
-
return pos;
|
|
2482
|
-
}
|
|
2483
|
-
sub_off(sub_pos) {
|
|
2484
|
-
if (!(sub_pos < this.data.length)) {
|
|
2485
|
-
$mol_fail(new Error(`Wrong pos ${sub_pos}`));
|
|
2486
|
-
}
|
|
2487
|
-
const end = this.data.length - 2;
|
|
2488
|
-
if (sub_pos !== end) {
|
|
2489
|
-
this.peer_move(end, sub_pos);
|
|
2490
|
-
}
|
|
2491
|
-
this.data.pop();
|
|
2492
|
-
this.data.pop();
|
|
2493
|
-
if (this.data.length === this.sub_from)
|
|
2494
|
-
this.reap();
|
|
2495
|
-
}
|
|
2496
|
-
reap() { }
|
|
2497
|
-
promote() {
|
|
2498
|
-
$mol_wire_auto()?.track_next(this);
|
|
2499
|
-
}
|
|
2500
|
-
fresh() { }
|
|
2501
|
-
complete() { }
|
|
2502
|
-
get incompleted() {
|
|
2503
|
-
return false;
|
|
2504
|
-
}
|
|
2505
|
-
emit(quant = $mol_wire_cursor.stale) {
|
|
2506
|
-
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
2507
|
-
;
|
|
2508
|
-
this.data[i].absorb(quant);
|
|
2509
|
-
}
|
|
2510
|
-
}
|
|
2511
|
-
peer_move(from_pos, to_pos) {
|
|
2512
|
-
const peer = this.data[from_pos];
|
|
2513
|
-
const self_pos = this.data[from_pos + 1];
|
|
2514
|
-
this.data[to_pos] = peer;
|
|
2515
|
-
this.data[to_pos + 1] = self_pos;
|
|
2516
|
-
peer.peer_repos(self_pos, to_pos);
|
|
2517
|
-
}
|
|
2518
|
-
peer_repos(peer_pos, self_pos) {
|
|
2519
|
-
this.data[peer_pos + 1] = self_pos;
|
|
2520
|
-
}
|
|
2521
|
-
}
|
|
2522
|
-
$.$mol_wire_pub = $mol_wire_pub;
|
|
2523
|
-
})($ || ($ = {}));
|
|
2524
|
-
|
|
2525
|
-
;
|
|
2526
|
-
"use strict";
|
|
2527
|
-
|
|
2528
|
-
;
|
|
2529
|
-
"use strict";
|
|
2530
|
-
var $;
|
|
2531
|
-
(function ($) {
|
|
2532
|
-
$.$mol_wire_auto_sub = null;
|
|
2533
|
-
function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
|
|
2534
|
-
return $.$mol_wire_auto_sub = next;
|
|
2535
|
-
}
|
|
2536
|
-
$.$mol_wire_auto = $mol_wire_auto;
|
|
2537
|
-
$.$mol_wire_affected = [];
|
|
2538
|
-
})($ || ($ = {}));
|
|
2539
|
-
|
|
2540
|
-
;
|
|
2541
|
-
"use strict";
|
|
2542
|
-
|
|
2543
|
-
;
|
|
2544
|
-
"use strict";
|
|
2545
|
-
|
|
2546
|
-
;
|
|
2547
|
-
"use strict";
|
|
2548
|
-
|
|
2549
|
-
;
|
|
2550
|
-
"use strict";
|
|
2551
|
-
|
|
2552
|
-
;
|
|
2553
|
-
"use strict";
|
|
2554
|
-
var $;
|
|
2555
|
-
(function ($) {
|
|
2556
|
-
const factories = new WeakMap();
|
|
2557
|
-
function factory(val) {
|
|
2558
|
-
let make = factories.get(val);
|
|
2559
|
-
if (make)
|
|
2560
|
-
return make;
|
|
2561
|
-
make = $mol_func_name_from((...args) => new val(...args), val);
|
|
2562
|
-
factories.set(val, make);
|
|
2563
|
-
return make;
|
|
2564
|
-
}
|
|
2565
|
-
function $mol_wire_sync(obj) {
|
|
2566
|
-
return new Proxy(obj, {
|
|
2567
|
-
get(obj, field) {
|
|
2568
|
-
let val = obj[field];
|
|
2569
|
-
if (typeof val !== 'function')
|
|
2570
|
-
return val;
|
|
2571
|
-
const temp = $mol_wire_task.getter(val);
|
|
2572
|
-
return function $mol_wire_sync(...args) {
|
|
2573
|
-
const fiber = temp(obj, args);
|
|
2574
|
-
return fiber.sync();
|
|
2575
|
-
};
|
|
2576
|
-
},
|
|
2577
|
-
construct(obj, args) {
|
|
2578
|
-
const temp = $mol_wire_task.getter(factory(obj));
|
|
2579
|
-
return temp(obj, args).sync();
|
|
2580
|
-
},
|
|
2581
|
-
apply(obj, self, args) {
|
|
2582
|
-
const temp = $mol_wire_task.getter(obj);
|
|
2583
|
-
return temp(self, args).sync();
|
|
2584
|
-
},
|
|
2585
|
-
});
|
|
2586
|
-
}
|
|
2587
|
-
$.$mol_wire_sync = $mol_wire_sync;
|
|
2588
|
-
})($ || ($ = {}));
|
|
2589
|
-
|
|
2590
|
-
;
|
|
2591
|
-
"use strict";
|
|
2592
|
-
var $;
|
|
2593
|
-
(function ($_1) {
|
|
2594
|
-
$mol_test({
|
|
2595
|
-
'test types'($) {
|
|
2596
|
-
class A {
|
|
2597
|
-
static a() {
|
|
2598
|
-
return Promise.resolve('');
|
|
2599
|
-
}
|
|
2600
|
-
static b() {
|
|
2601
|
-
return $mol_wire_sync(this).a();
|
|
2602
|
-
}
|
|
2603
|
-
}
|
|
2604
|
-
},
|
|
2605
|
-
async 'test method from host'($) {
|
|
2606
|
-
let count = 0;
|
|
2607
|
-
class A {
|
|
2608
|
-
static a() {
|
|
2609
|
-
return $mol_wire_sync(this).b();
|
|
2610
|
-
}
|
|
2611
|
-
static b() { return Promise.resolve(++count); }
|
|
2612
|
-
}
|
|
2613
|
-
$mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
|
|
2614
|
-
},
|
|
2615
|
-
async 'test function'($) {
|
|
2616
|
-
let count = 0;
|
|
2617
|
-
class A {
|
|
2618
|
-
static a() {
|
|
2619
|
-
return $mol_wire_sync(this.b)();
|
|
2620
|
-
}
|
|
2621
|
-
static b() { return Promise.resolve(++count); }
|
|
2622
|
-
}
|
|
2623
|
-
$mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
|
|
2624
|
-
},
|
|
2625
|
-
async 'test construct itself'($) {
|
|
2626
|
-
class A {
|
|
2627
|
-
static instances = [];
|
|
2628
|
-
static a() {
|
|
2629
|
-
const a = new ($mol_wire_sync(A))();
|
|
2630
|
-
this.instances.push(a);
|
|
2631
|
-
$mol_wire_sync(this).b();
|
|
2632
|
-
}
|
|
2633
|
-
static b() { return Promise.resolve(); }
|
|
2634
|
-
}
|
|
2635
|
-
await $mol_wire_async(A).a();
|
|
2636
|
-
$mol_assert_equal(A.instances.length, 2);
|
|
2637
|
-
$mol_assert_equal(A.instances[0] instanceof A);
|
|
2638
|
-
$mol_assert_equal(A.instances[0], A.instances[1]);
|
|
2639
|
-
}
|
|
2640
|
-
});
|
|
2641
|
-
})($ || ($ = {}));
|
|
2642
|
-
|
|
2643
2240
|
;
|
|
2644
2241
|
"use strict";
|
|
2645
2242
|
var $;
|
|
2646
2243
|
(function ($) {
|
|
2647
|
-
|
|
2648
|
-
}
|
|
2649
|
-
$.$mol_run_error = $mol_run_error;
|
|
2650
|
-
const child_process = $node['child_process'];
|
|
2651
|
-
$.$mol_run_spawn = child_process.spawn.bind(child_process);
|
|
2652
|
-
$.$mol_run_spawn_sync = child_process.spawnSync.bind(child_process);
|
|
2653
|
-
function $mol_run_async({ dir, timeout, command, env }) {
|
|
2654
|
-
const args_raw = typeof command === 'string' ? command.split(' ') : command;
|
|
2655
|
-
const [app, ...args] = args_raw;
|
|
2656
|
-
if (!env?.MOL_RUN_ASYNC) {
|
|
2657
|
-
this.$mol_log3_come({
|
|
2658
|
-
place: '$mol_run_sync',
|
|
2659
|
-
message: 'Run',
|
|
2660
|
-
command: args_raw.join(' '),
|
|
2661
|
-
dir: $node.path.relative('', dir),
|
|
2662
|
-
});
|
|
2663
|
-
const res = this.$mol_run_spawn_sync(app, args, { shell: true, cwd: dir, env });
|
|
2664
|
-
if (res.status)
|
|
2665
|
-
$mol_fail(new Error(res.stderr.toString() || 'Exit(' + res.status + ')'));
|
|
2666
|
-
return res;
|
|
2667
|
-
}
|
|
2668
|
-
const sub = this.$mol_run_spawn(app, args, {
|
|
2669
|
-
shell: true,
|
|
2670
|
-
cwd: dir,
|
|
2671
|
-
env
|
|
2672
|
-
});
|
|
2673
|
-
this.$mol_log3_come({
|
|
2674
|
-
place: '$mol_run_async',
|
|
2675
|
-
pid: sub.pid,
|
|
2676
|
-
message: 'Run',
|
|
2677
|
-
command: args_raw.join(' '),
|
|
2678
|
-
dir: $node.path.relative('', dir),
|
|
2679
|
-
});
|
|
2680
|
-
let killed = false;
|
|
2681
|
-
let timer;
|
|
2682
|
-
const std_data = [];
|
|
2683
|
-
const error_data = [];
|
|
2684
|
-
const add = (std_chunk, error_chunk) => {
|
|
2685
|
-
if (std_chunk)
|
|
2686
|
-
std_data.push(std_chunk);
|
|
2687
|
-
if (error_chunk)
|
|
2688
|
-
error_data.push(error_chunk);
|
|
2689
|
-
if (!timeout)
|
|
2690
|
-
return;
|
|
2691
|
-
clearTimeout(timer);
|
|
2692
|
-
timer = setTimeout(() => {
|
|
2693
|
-
const signal = killed ? 'SIGKILL' : 'SIGTERM';
|
|
2694
|
-
killed = true;
|
|
2695
|
-
add();
|
|
2696
|
-
sub.kill(signal);
|
|
2697
|
-
}, timeout);
|
|
2698
|
-
};
|
|
2699
|
-
add();
|
|
2700
|
-
sub.stdout?.on('data', data => add(data));
|
|
2701
|
-
sub.stderr?.on('data', data => add(undefined, data));
|
|
2702
|
-
const promise = new Promise((done, fail) => {
|
|
2703
|
-
const close = (error, status = null, signal = null) => {
|
|
2704
|
-
if (!timer && timeout)
|
|
2705
|
-
return;
|
|
2706
|
-
clearTimeout(timer);
|
|
2707
|
-
timer = undefined;
|
|
2708
|
-
const res = {
|
|
2709
|
-
pid: sub.pid,
|
|
2710
|
-
status,
|
|
2711
|
-
signal,
|
|
2712
|
-
get stdout() { return Buffer.concat(std_data); },
|
|
2713
|
-
get stderr() { return Buffer.concat(error_data); }
|
|
2714
|
-
};
|
|
2715
|
-
this.$mol_log3_done({
|
|
2716
|
-
place: '$mol_run_async',
|
|
2717
|
-
pid: sub.pid,
|
|
2718
|
-
message: 'Run',
|
|
2719
|
-
status,
|
|
2720
|
-
command: args_raw.join(' '),
|
|
2721
|
-
dir: $node.path.relative('', dir),
|
|
2722
|
-
});
|
|
2723
|
-
if (error || status || killed)
|
|
2724
|
-
return fail(new $mol_run_error((res.stderr.toString() || res.stdout.toString() || 'Run error') + (killed ? ', timeout' : ''), { signal, timeout: killed }, ...error ? [error] : []));
|
|
2725
|
-
done(res);
|
|
2726
|
-
};
|
|
2727
|
-
sub.on('disconnect', () => close(new Error('Disconnected')));
|
|
2728
|
-
sub.on('error', err => close(err));
|
|
2729
|
-
sub.on('exit', (status, signal) => close(null, status, signal));
|
|
2730
|
-
});
|
|
2731
|
-
return Object.assign(promise, { destructor: () => {
|
|
2732
|
-
clearTimeout(timer);
|
|
2733
|
-
sub.kill('SIGKILL');
|
|
2734
|
-
} });
|
|
2735
|
-
}
|
|
2736
|
-
$.$mol_run_async = $mol_run_async;
|
|
2737
|
-
function $mol_run(options) {
|
|
2738
|
-
if (!options.env)
|
|
2739
|
-
options = { ...options, env: this.$mol_env() };
|
|
2740
|
-
return $mol_wire_sync(this).$mol_run_async(options);
|
|
2741
|
-
}
|
|
2742
|
-
$.$mol_run = $mol_run;
|
|
2244
|
+
$.$mol_dom_context = new $node.jsdom.JSDOM('', { url: 'https://localhost/' }).window;
|
|
2743
2245
|
})($ || ($ = {}));
|
|
2744
2246
|
|
|
2745
2247
|
;
|
|
@@ -2747,46 +2249,15 @@ var $;
|
|
|
2747
2249
|
var $;
|
|
2748
2250
|
(function ($_1) {
|
|
2749
2251
|
$mol_test({
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
close_mock = cb;
|
|
2757
|
-
},
|
|
2758
|
-
kill() { close_mock(); }
|
|
2759
|
-
})
|
|
2760
|
-
});
|
|
2761
|
-
let message = '';
|
|
2762
|
-
try {
|
|
2763
|
-
const res = await $mol_wire_async(context_mock).$mol_run({ command: 'sleep 10', dir: '.', timeout: 10, env: { 'MOL_RUN_ASYNC': '1' } });
|
|
2764
|
-
}
|
|
2765
|
-
catch (e) {
|
|
2766
|
-
message = e.message;
|
|
2767
|
-
}
|
|
2768
|
-
$mol_assert_equal(message, 'Run error, timeout');
|
|
2769
|
-
}
|
|
2252
|
+
'FQN of anon function'($) {
|
|
2253
|
+
const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
|
|
2254
|
+
$mol_assert_equal($$.$mol_func_name_test.name, '');
|
|
2255
|
+
$mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
|
|
2256
|
+
$mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
|
|
2257
|
+
},
|
|
2770
2258
|
});
|
|
2771
2259
|
})($ || ($ = {}));
|
|
2772
2260
|
|
|
2773
|
-
;
|
|
2774
|
-
"use strict";
|
|
2775
|
-
var $;
|
|
2776
|
-
(function ($) {
|
|
2777
|
-
function $mol_exec(dir, command, ...args) {
|
|
2778
|
-
return this.$mol_run({ command: [command, ...args], dir });
|
|
2779
|
-
}
|
|
2780
|
-
$.$mol_exec = $mol_exec;
|
|
2781
|
-
})($ || ($ = {}));
|
|
2782
|
-
|
|
2783
|
-
;
|
|
2784
|
-
"use strict";
|
|
2785
|
-
var $;
|
|
2786
|
-
(function ($) {
|
|
2787
|
-
$.$mol_dom_context = new $node.jsdom.JSDOM('', { url: 'https://localhost/' }).window;
|
|
2788
|
-
})($ || ($ = {}));
|
|
2789
|
-
|
|
2790
2261
|
;
|
|
2791
2262
|
"use strict";
|
|
2792
2263
|
var $;
|
|
@@ -2848,6 +2319,18 @@ var $;
|
|
|
2848
2319
|
;
|
|
2849
2320
|
"use strict";
|
|
2850
2321
|
|
|
2322
|
+
;
|
|
2323
|
+
"use strict";
|
|
2324
|
+
|
|
2325
|
+
;
|
|
2326
|
+
"use strict";
|
|
2327
|
+
|
|
2328
|
+
;
|
|
2329
|
+
"use strict";
|
|
2330
|
+
|
|
2331
|
+
;
|
|
2332
|
+
"use strict";
|
|
2333
|
+
|
|
2851
2334
|
;
|
|
2852
2335
|
"use strict";
|
|
2853
2336
|
var $;
|
|
@@ -3733,44 +3216,153 @@ var $;
|
|
|
3733
3216
|
console.error(error);
|
|
3734
3217
|
return val;
|
|
3735
3218
|
}
|
|
3736
|
-
};
|
|
3219
|
+
};
|
|
3220
|
+
})($ || ($ = {}));
|
|
3221
|
+
|
|
3222
|
+
;
|
|
3223
|
+
"use strict";
|
|
3224
|
+
var $;
|
|
3225
|
+
(function ($) {
|
|
3226
|
+
$mol_test({
|
|
3227
|
+
'must be false'() {
|
|
3228
|
+
$mol_assert_not(0);
|
|
3229
|
+
},
|
|
3230
|
+
'must be true'() {
|
|
3231
|
+
$mol_assert_ok(1);
|
|
3232
|
+
},
|
|
3233
|
+
'two must be equal'() {
|
|
3234
|
+
$mol_assert_equal(2, 2);
|
|
3235
|
+
},
|
|
3236
|
+
'three must be equal'() {
|
|
3237
|
+
$mol_assert_equal(2, 2, 2);
|
|
3238
|
+
},
|
|
3239
|
+
'two must be unique'() {
|
|
3240
|
+
$mol_assert_unique([2], [3]);
|
|
3241
|
+
},
|
|
3242
|
+
'three must be unique'() {
|
|
3243
|
+
$mol_assert_unique([1], [2], [3]);
|
|
3244
|
+
},
|
|
3245
|
+
'two must be alike'() {
|
|
3246
|
+
$mol_assert_like([3], [3]);
|
|
3247
|
+
},
|
|
3248
|
+
'three must be alike'() {
|
|
3249
|
+
$mol_assert_like([3], [3], [3]);
|
|
3250
|
+
},
|
|
3251
|
+
'two object must be alike'() {
|
|
3252
|
+
$mol_assert_like({ a: 1 }, { a: 1 });
|
|
3253
|
+
},
|
|
3254
|
+
'three object must be alike'() {
|
|
3255
|
+
$mol_assert_like({ a: 1 }, { a: 1 }, { a: 1 });
|
|
3256
|
+
},
|
|
3257
|
+
});
|
|
3258
|
+
})($ || ($ = {}));
|
|
3259
|
+
|
|
3260
|
+
;
|
|
3261
|
+
"use strict";
|
|
3262
|
+
var $;
|
|
3263
|
+
(function ($) {
|
|
3264
|
+
function $mol_log3_area_lazy(event) {
|
|
3265
|
+
const self = this;
|
|
3266
|
+
const stack = self.$mol_log3_stack;
|
|
3267
|
+
const deep = stack.length;
|
|
3268
|
+
let logged = false;
|
|
3269
|
+
stack.push(() => {
|
|
3270
|
+
logged = true;
|
|
3271
|
+
self.$mol_log3_area.call(self, event);
|
|
3272
|
+
});
|
|
3273
|
+
return () => {
|
|
3274
|
+
if (logged)
|
|
3275
|
+
self.console.groupEnd();
|
|
3276
|
+
if (stack.length > deep)
|
|
3277
|
+
stack.length = deep;
|
|
3278
|
+
};
|
|
3279
|
+
}
|
|
3280
|
+
$.$mol_log3_area_lazy = $mol_log3_area_lazy;
|
|
3281
|
+
$.$mol_log3_stack = [];
|
|
3282
|
+
})($ || ($ = {}));
|
|
3283
|
+
|
|
3284
|
+
;
|
|
3285
|
+
"use strict";
|
|
3286
|
+
var $;
|
|
3287
|
+
(function ($) {
|
|
3288
|
+
class $mol_term_color {
|
|
3289
|
+
static reset = this.ansi(0, 0);
|
|
3290
|
+
static bold = this.ansi(1, 22);
|
|
3291
|
+
static italic = this.ansi(3, 23);
|
|
3292
|
+
static underline = this.ansi(4, 24);
|
|
3293
|
+
static inverse = this.ansi(7, 27);
|
|
3294
|
+
static hidden = this.ansi(8, 28);
|
|
3295
|
+
static strike = this.ansi(9, 29);
|
|
3296
|
+
static gray = this.ansi(90, 39);
|
|
3297
|
+
static red = this.ansi(91, 39);
|
|
3298
|
+
static green = this.ansi(92, 39);
|
|
3299
|
+
static yellow = this.ansi(93, 39);
|
|
3300
|
+
static blue = this.ansi(94, 39);
|
|
3301
|
+
static magenta = this.ansi(95, 39);
|
|
3302
|
+
static cyan = this.ansi(96, 39);
|
|
3303
|
+
static Gray = (str) => this.inverse(this.gray(str));
|
|
3304
|
+
static Red = (str) => this.inverse(this.red(str));
|
|
3305
|
+
static Green = (str) => this.inverse(this.green(str));
|
|
3306
|
+
static Yellow = (str) => this.inverse(this.yellow(str));
|
|
3307
|
+
static Blue = (str) => this.inverse(this.blue(str));
|
|
3308
|
+
static Magenta = (str) => this.inverse(this.magenta(str));
|
|
3309
|
+
static Cyan = (str) => this.inverse(this.cyan(str));
|
|
3310
|
+
static ansi(open, close) {
|
|
3311
|
+
if (typeof process === 'undefined')
|
|
3312
|
+
return String;
|
|
3313
|
+
if (!process.stdout.isTTY)
|
|
3314
|
+
return String;
|
|
3315
|
+
const prefix = `\x1b[${open}m`;
|
|
3316
|
+
const postfix = `\x1b[${close}m`;
|
|
3317
|
+
const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
|
|
3318
|
+
return function colorer(str) {
|
|
3319
|
+
str = String(str);
|
|
3320
|
+
if (str === '')
|
|
3321
|
+
return str;
|
|
3322
|
+
const suffix = str.replace(suffix_regexp, prefix);
|
|
3323
|
+
return prefix + suffix + postfix;
|
|
3324
|
+
};
|
|
3325
|
+
}
|
|
3326
|
+
}
|
|
3327
|
+
$.$mol_term_color = $mol_term_color;
|
|
3737
3328
|
})($ || ($ = {}));
|
|
3738
3329
|
|
|
3739
3330
|
;
|
|
3740
3331
|
"use strict";
|
|
3741
3332
|
var $;
|
|
3742
3333
|
(function ($) {
|
|
3743
|
-
$
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
}
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
}
|
|
3334
|
+
function $mol_log3_node_make(level, output, type, color) {
|
|
3335
|
+
return function $mol_log3_logger(event) {
|
|
3336
|
+
if (!event.time)
|
|
3337
|
+
event = { time: new Date().toISOString(), ...event };
|
|
3338
|
+
let tree = this.$mol_tree2_from_json(event);
|
|
3339
|
+
tree = tree.struct(type, tree.kids);
|
|
3340
|
+
let str = color(tree.toString());
|
|
3341
|
+
this.console[level](str);
|
|
3342
|
+
const self = this;
|
|
3343
|
+
return () => self.console.groupEnd();
|
|
3344
|
+
};
|
|
3345
|
+
}
|
|
3346
|
+
$.$mol_log3_node_make = $mol_log3_node_make;
|
|
3347
|
+
$.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
|
|
3348
|
+
$.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
|
|
3349
|
+
$.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
|
|
3350
|
+
$.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
|
|
3351
|
+
$.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
|
|
3352
|
+
$.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
|
|
3353
|
+
})($ || ($ = {}));
|
|
3354
|
+
|
|
3355
|
+
;
|
|
3356
|
+
"use strict";
|
|
3357
|
+
var $;
|
|
3358
|
+
(function ($_1) {
|
|
3359
|
+
$mol_test_mocks.push($ => {
|
|
3360
|
+
$.$mol_log3_come = () => { };
|
|
3361
|
+
$.$mol_log3_done = () => { };
|
|
3362
|
+
$.$mol_log3_fail = () => { };
|
|
3363
|
+
$.$mol_log3_warn = () => { };
|
|
3364
|
+
$.$mol_log3_rise = () => { };
|
|
3365
|
+
$.$mol_log3_area = () => () => { };
|
|
3774
3366
|
});
|
|
3775
3367
|
})($ || ($ = {}));
|
|
3776
3368
|
|
|
@@ -3830,16 +3422,232 @@ var $;
|
|
|
3830
3422
|
'autobind'() {
|
|
3831
3423
|
class Foo {
|
|
3832
3424
|
}
|
|
3833
|
-
const proxy = $mol_delegate({}, () => new Foo);
|
|
3834
|
-
$mol_assert_ok(proxy instanceof Foo);
|
|
3835
|
-
$mol_assert_ok(proxy instanceof $mol_delegate);
|
|
3836
|
-
},
|
|
3837
|
-
});
|
|
3425
|
+
const proxy = $mol_delegate({}, () => new Foo);
|
|
3426
|
+
$mol_assert_ok(proxy instanceof Foo);
|
|
3427
|
+
$mol_assert_ok(proxy instanceof $mol_delegate);
|
|
3428
|
+
},
|
|
3429
|
+
});
|
|
3430
|
+
})($ || ($ = {}));
|
|
3431
|
+
|
|
3432
|
+
;
|
|
3433
|
+
"use strict";
|
|
3434
|
+
|
|
3435
|
+
;
|
|
3436
|
+
"use strict";
|
|
3437
|
+
var $;
|
|
3438
|
+
(function ($) {
|
|
3439
|
+
class $mol_error_mix extends AggregateError {
|
|
3440
|
+
cause;
|
|
3441
|
+
name = $$.$mol_func_name(this.constructor).replace(/^\$/, '') + '_Error';
|
|
3442
|
+
constructor(message, cause = {}, ...errors) {
|
|
3443
|
+
super(errors, message, { cause });
|
|
3444
|
+
this.cause = cause;
|
|
3445
|
+
const stack_get = Object.getOwnPropertyDescriptor(this, 'stack')?.get ?? (() => super.stack);
|
|
3446
|
+
Object.defineProperty(this, 'stack', {
|
|
3447
|
+
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()
|
|
3448
|
+
.replace(/at /gm, ' at ')
|
|
3449
|
+
.replace(/^(?! +at )(.*)/gm, ' at | $1 (#)')).join('\n')
|
|
3450
|
+
});
|
|
3451
|
+
}
|
|
3452
|
+
static [Symbol.toPrimitive]() {
|
|
3453
|
+
return this.toString();
|
|
3454
|
+
}
|
|
3455
|
+
static toString() {
|
|
3456
|
+
return $$.$mol_func_name(this);
|
|
3457
|
+
}
|
|
3458
|
+
static make(...params) {
|
|
3459
|
+
return new this(...params);
|
|
3460
|
+
}
|
|
3461
|
+
}
|
|
3462
|
+
$.$mol_error_mix = $mol_error_mix;
|
|
3463
|
+
})($ || ($ = {}));
|
|
3464
|
+
|
|
3465
|
+
;
|
|
3466
|
+
"use strict";
|
|
3467
|
+
var $;
|
|
3468
|
+
(function ($) {
|
|
3469
|
+
$mol_test({
|
|
3470
|
+
'auto name'() {
|
|
3471
|
+
class Invalid extends $mol_error_mix {
|
|
3472
|
+
}
|
|
3473
|
+
const mix = new Invalid('foo');
|
|
3474
|
+
$mol_assert_equal(mix.name, 'Invalid_Error');
|
|
3475
|
+
},
|
|
3476
|
+
'simpe mix'() {
|
|
3477
|
+
const mix = new $mol_error_mix('foo', {}, new Error('bar'), new Error('lol'));
|
|
3478
|
+
$mol_assert_equal(mix.message, 'foo');
|
|
3479
|
+
$mol_assert_equal(mix.errors.map(e => e.message), ['bar', 'lol']);
|
|
3480
|
+
},
|
|
3481
|
+
'provide additional info'() {
|
|
3482
|
+
class Invalid extends $mol_error_mix {
|
|
3483
|
+
}
|
|
3484
|
+
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' }));
|
|
3485
|
+
const hints = [];
|
|
3486
|
+
if (mix instanceof $mol_error_mix) {
|
|
3487
|
+
for (const er of mix.errors) {
|
|
3488
|
+
if (er instanceof Invalid) {
|
|
3489
|
+
hints.push(er.cause?.hint ?? '');
|
|
3490
|
+
}
|
|
3491
|
+
}
|
|
3492
|
+
}
|
|
3493
|
+
$mol_assert_equal(hints, ['> 8 letters', 'need capital letter']);
|
|
3494
|
+
},
|
|
3495
|
+
});
|
|
3496
|
+
})($ || ($ = {}));
|
|
3497
|
+
|
|
3498
|
+
;
|
|
3499
|
+
"use strict";
|
|
3500
|
+
var $;
|
|
3501
|
+
(function ($_1) {
|
|
3502
|
+
let $$;
|
|
3503
|
+
(function ($$) {
|
|
3504
|
+
let $;
|
|
3505
|
+
})($$ = $_1.$$ || ($_1.$$ = {}));
|
|
3506
|
+
$_1.$mol_object_field = Symbol('$mol_object_field');
|
|
3507
|
+
class $mol_object extends $mol_object2 {
|
|
3508
|
+
static make(config) {
|
|
3509
|
+
return super.create(obj => {
|
|
3510
|
+
for (let key in config)
|
|
3511
|
+
obj[key] = config[key];
|
|
3512
|
+
});
|
|
3513
|
+
}
|
|
3514
|
+
}
|
|
3515
|
+
$_1.$mol_object = $mol_object;
|
|
3516
|
+
})($ || ($ = {}));
|
|
3517
|
+
|
|
3518
|
+
;
|
|
3519
|
+
"use strict";
|
|
3520
|
+
var $;
|
|
3521
|
+
(function ($) {
|
|
3522
|
+
$mol_test({
|
|
3523
|
+
'init with overload'() {
|
|
3524
|
+
class X extends $mol_object {
|
|
3525
|
+
foo() {
|
|
3526
|
+
return 1;
|
|
3527
|
+
}
|
|
3528
|
+
}
|
|
3529
|
+
var x = X.make({
|
|
3530
|
+
foo: () => 2,
|
|
3531
|
+
});
|
|
3532
|
+
$mol_assert_equal(x.foo(), 2);
|
|
3533
|
+
},
|
|
3534
|
+
});
|
|
3535
|
+
})($ || ($ = {}));
|
|
3536
|
+
|
|
3537
|
+
;
|
|
3538
|
+
"use strict";
|
|
3539
|
+
var $;
|
|
3540
|
+
(function ($) {
|
|
3541
|
+
function $mol_env() {
|
|
3542
|
+
return {};
|
|
3543
|
+
}
|
|
3544
|
+
$.$mol_env = $mol_env;
|
|
3545
|
+
})($ || ($ = {}));
|
|
3546
|
+
|
|
3547
|
+
;
|
|
3548
|
+
"use strict";
|
|
3549
|
+
var $;
|
|
3550
|
+
(function ($) {
|
|
3551
|
+
$.$mol_env = function $mol_env() {
|
|
3552
|
+
return this.process.env;
|
|
3553
|
+
};
|
|
3554
|
+
})($ || ($ = {}));
|
|
3555
|
+
|
|
3556
|
+
;
|
|
3557
|
+
"use strict";
|
|
3558
|
+
var $;
|
|
3559
|
+
(function ($) {
|
|
3560
|
+
let $mol_wire_cursor;
|
|
3561
|
+
(function ($mol_wire_cursor) {
|
|
3562
|
+
$mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
|
|
3563
|
+
$mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
|
|
3564
|
+
$mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
|
|
3565
|
+
$mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
|
|
3566
|
+
})($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
|
|
3567
|
+
})($ || ($ = {}));
|
|
3568
|
+
|
|
3569
|
+
;
|
|
3570
|
+
"use strict";
|
|
3571
|
+
var $;
|
|
3572
|
+
(function ($) {
|
|
3573
|
+
class $mol_wire_pub extends Object {
|
|
3574
|
+
data = [];
|
|
3575
|
+
static get [Symbol.species]() {
|
|
3576
|
+
return Array;
|
|
3577
|
+
}
|
|
3578
|
+
sub_from = 0;
|
|
3579
|
+
get sub_list() {
|
|
3580
|
+
const res = [];
|
|
3581
|
+
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
3582
|
+
res.push(this.data[i]);
|
|
3583
|
+
}
|
|
3584
|
+
return res;
|
|
3585
|
+
}
|
|
3586
|
+
get sub_empty() {
|
|
3587
|
+
return this.sub_from === this.data.length;
|
|
3588
|
+
}
|
|
3589
|
+
sub_on(sub, pub_pos) {
|
|
3590
|
+
const pos = this.data.length;
|
|
3591
|
+
this.data.push(sub, pub_pos);
|
|
3592
|
+
return pos;
|
|
3593
|
+
}
|
|
3594
|
+
sub_off(sub_pos) {
|
|
3595
|
+
if (!(sub_pos < this.data.length)) {
|
|
3596
|
+
$mol_fail(new Error(`Wrong pos ${sub_pos}`));
|
|
3597
|
+
}
|
|
3598
|
+
const end = this.data.length - 2;
|
|
3599
|
+
if (sub_pos !== end) {
|
|
3600
|
+
this.peer_move(end, sub_pos);
|
|
3601
|
+
}
|
|
3602
|
+
this.data.pop();
|
|
3603
|
+
this.data.pop();
|
|
3604
|
+
if (this.data.length === this.sub_from)
|
|
3605
|
+
this.reap();
|
|
3606
|
+
}
|
|
3607
|
+
reap() { }
|
|
3608
|
+
promote() {
|
|
3609
|
+
$mol_wire_auto()?.track_next(this);
|
|
3610
|
+
}
|
|
3611
|
+
fresh() { }
|
|
3612
|
+
complete() { }
|
|
3613
|
+
get incompleted() {
|
|
3614
|
+
return false;
|
|
3615
|
+
}
|
|
3616
|
+
emit(quant = $mol_wire_cursor.stale) {
|
|
3617
|
+
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
3618
|
+
;
|
|
3619
|
+
this.data[i].absorb(quant);
|
|
3620
|
+
}
|
|
3621
|
+
}
|
|
3622
|
+
peer_move(from_pos, to_pos) {
|
|
3623
|
+
const peer = this.data[from_pos];
|
|
3624
|
+
const self_pos = this.data[from_pos + 1];
|
|
3625
|
+
this.data[to_pos] = peer;
|
|
3626
|
+
this.data[to_pos + 1] = self_pos;
|
|
3627
|
+
peer.peer_repos(self_pos, to_pos);
|
|
3628
|
+
}
|
|
3629
|
+
peer_repos(peer_pos, self_pos) {
|
|
3630
|
+
this.data[peer_pos + 1] = self_pos;
|
|
3631
|
+
}
|
|
3632
|
+
}
|
|
3633
|
+
$.$mol_wire_pub = $mol_wire_pub;
|
|
3838
3634
|
})($ || ($ = {}));
|
|
3839
3635
|
|
|
3840
3636
|
;
|
|
3841
3637
|
"use strict";
|
|
3842
3638
|
|
|
3639
|
+
;
|
|
3640
|
+
"use strict";
|
|
3641
|
+
var $;
|
|
3642
|
+
(function ($) {
|
|
3643
|
+
$.$mol_wire_auto_sub = null;
|
|
3644
|
+
function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
|
|
3645
|
+
return $.$mol_wire_auto_sub = next;
|
|
3646
|
+
}
|
|
3647
|
+
$.$mol_wire_auto = $mol_wire_auto;
|
|
3648
|
+
$.$mol_wire_affected = [];
|
|
3649
|
+
})($ || ($ = {}));
|
|
3650
|
+
|
|
3843
3651
|
;
|
|
3844
3652
|
"use strict";
|
|
3845
3653
|
var $;
|
|
@@ -4567,55 +4375,255 @@ var $;
|
|
|
4567
4375
|
break reuse;
|
|
4568
4376
|
return existen;
|
|
4569
4377
|
}
|
|
4570
|
-
const key = (host?.[Symbol.toStringTag] ?? host) + ('.' + task.name + '<#>');
|
|
4571
|
-
const next = new $mol_wire_task(key, task, host, args);
|
|
4572
|
-
if (existen?.temp) {
|
|
4573
|
-
$$.$mol_log3_warn({
|
|
4574
|
-
place: '$mol_wire_task',
|
|
4575
|
-
message: `Non idempotency`,
|
|
4576
|
-
sub,
|
|
4577
|
-
pubs: [...sub?.pub_list ?? [], existen],
|
|
4578
|
-
next,
|
|
4579
|
-
hint: 'Ignore it',
|
|
4580
|
-
});
|
|
4378
|
+
const key = (host?.[Symbol.toStringTag] ?? host) + ('.' + task.name + '<#>');
|
|
4379
|
+
const next = new $mol_wire_task(key, task, host, args);
|
|
4380
|
+
if (existen?.temp) {
|
|
4381
|
+
$$.$mol_log3_warn({
|
|
4382
|
+
place: '$mol_wire_task',
|
|
4383
|
+
message: `Non idempotency`,
|
|
4384
|
+
sub,
|
|
4385
|
+
pubs: [...sub?.pub_list ?? [], existen],
|
|
4386
|
+
next,
|
|
4387
|
+
hint: 'Ignore it',
|
|
4388
|
+
});
|
|
4389
|
+
}
|
|
4390
|
+
return next;
|
|
4391
|
+
};
|
|
4392
|
+
}
|
|
4393
|
+
get temp() {
|
|
4394
|
+
return true;
|
|
4395
|
+
}
|
|
4396
|
+
complete() {
|
|
4397
|
+
if ($mol_promise_like(this.cache))
|
|
4398
|
+
return;
|
|
4399
|
+
this.destructor();
|
|
4400
|
+
}
|
|
4401
|
+
put(next) {
|
|
4402
|
+
const prev = this.cache;
|
|
4403
|
+
this.cache = next;
|
|
4404
|
+
if ($mol_promise_like(next)) {
|
|
4405
|
+
this.cursor = $mol_wire_cursor.fresh;
|
|
4406
|
+
if (next !== prev)
|
|
4407
|
+
this.emit();
|
|
4408
|
+
if ($mol_owning_catch(this, next)) {
|
|
4409
|
+
try {
|
|
4410
|
+
next[Symbol.toStringTag] = this[Symbol.toStringTag];
|
|
4411
|
+
}
|
|
4412
|
+
catch {
|
|
4413
|
+
Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
|
|
4414
|
+
}
|
|
4415
|
+
}
|
|
4416
|
+
return next;
|
|
4417
|
+
}
|
|
4418
|
+
this.cursor = $mol_wire_cursor.final;
|
|
4419
|
+
if (this.sub_empty)
|
|
4420
|
+
this.destructor();
|
|
4421
|
+
else if (next !== prev)
|
|
4422
|
+
this.emit();
|
|
4423
|
+
return next;
|
|
4424
|
+
}
|
|
4425
|
+
}
|
|
4426
|
+
$.$mol_wire_task = $mol_wire_task;
|
|
4427
|
+
})($ || ($ = {}));
|
|
4428
|
+
|
|
4429
|
+
;
|
|
4430
|
+
"use strict";
|
|
4431
|
+
var $;
|
|
4432
|
+
(function ($) {
|
|
4433
|
+
function $mol_wire_async(obj) {
|
|
4434
|
+
let fiber;
|
|
4435
|
+
const temp = $mol_wire_task.getter(obj);
|
|
4436
|
+
return new Proxy(obj, {
|
|
4437
|
+
get(obj, field) {
|
|
4438
|
+
const val = obj[field];
|
|
4439
|
+
if (typeof val !== 'function')
|
|
4440
|
+
return val;
|
|
4441
|
+
let fiber;
|
|
4442
|
+
const temp = $mol_wire_task.getter(val);
|
|
4443
|
+
return function $mol_wire_async(...args) {
|
|
4444
|
+
fiber?.destructor();
|
|
4445
|
+
fiber = temp(obj, args);
|
|
4446
|
+
return fiber.async();
|
|
4447
|
+
};
|
|
4448
|
+
},
|
|
4449
|
+
apply(obj, self, args) {
|
|
4450
|
+
fiber?.destructor();
|
|
4451
|
+
fiber = temp(self, args);
|
|
4452
|
+
return fiber.async();
|
|
4453
|
+
},
|
|
4454
|
+
});
|
|
4455
|
+
}
|
|
4456
|
+
$.$mol_wire_async = $mol_wire_async;
|
|
4457
|
+
})($ || ($ = {}));
|
|
4458
|
+
|
|
4459
|
+
;
|
|
4460
|
+
"use strict";
|
|
4461
|
+
var $;
|
|
4462
|
+
(function ($_1) {
|
|
4463
|
+
$mol_test({
|
|
4464
|
+
'test types'($) {
|
|
4465
|
+
class A {
|
|
4466
|
+
static a() {
|
|
4467
|
+
return '';
|
|
4468
|
+
}
|
|
4469
|
+
static b() {
|
|
4470
|
+
return $mol_wire_async(this).a();
|
|
4471
|
+
}
|
|
4472
|
+
}
|
|
4473
|
+
},
|
|
4474
|
+
async 'Latest method calls wins'($) {
|
|
4475
|
+
class NameLogger extends $mol_object2 {
|
|
4476
|
+
static $ = $;
|
|
4477
|
+
static first = [];
|
|
4478
|
+
static last = [];
|
|
4479
|
+
static send(next) {
|
|
4480
|
+
$mol_wire_sync(this.first).push(next);
|
|
4481
|
+
$$.$mol_wait_timeout(0);
|
|
4482
|
+
this.last.push(next);
|
|
4483
|
+
}
|
|
4484
|
+
}
|
|
4485
|
+
const name = $mol_wire_async(NameLogger).send;
|
|
4486
|
+
name('john');
|
|
4487
|
+
const promise = name('jin');
|
|
4488
|
+
$.$mol_after_mock_warp();
|
|
4489
|
+
await promise;
|
|
4490
|
+
$mol_assert_equal(NameLogger.first, ['john', 'jin']);
|
|
4491
|
+
$mol_assert_equal(NameLogger.last, ['jin']);
|
|
4492
|
+
},
|
|
4493
|
+
async 'Latest function calls wins'($) {
|
|
4494
|
+
const first = [];
|
|
4495
|
+
const last = [];
|
|
4496
|
+
function send_name(next) {
|
|
4497
|
+
$mol_wire_sync(first).push(next);
|
|
4498
|
+
$$.$mol_wait_timeout(0);
|
|
4499
|
+
last.push(next);
|
|
4500
|
+
}
|
|
4501
|
+
const name = $mol_wire_async(send_name);
|
|
4502
|
+
name('john');
|
|
4503
|
+
const promise = name('jin');
|
|
4504
|
+
$.$mol_after_mock_warp();
|
|
4505
|
+
await promise;
|
|
4506
|
+
$mol_assert_equal(first, ['john', 'jin']);
|
|
4507
|
+
$mol_assert_equal(last, ['jin']);
|
|
4508
|
+
},
|
|
4509
|
+
});
|
|
4510
|
+
})($ || ($ = {}));
|
|
4511
|
+
|
|
4512
|
+
;
|
|
4513
|
+
"use strict";
|
|
4514
|
+
var $;
|
|
4515
|
+
(function ($) {
|
|
4516
|
+
function $mol_wire_method(host, field, descr) {
|
|
4517
|
+
if (!descr)
|
|
4518
|
+
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
|
4519
|
+
const orig = descr?.value ?? host[field];
|
|
4520
|
+
const sup = Reflect.getPrototypeOf(host);
|
|
4521
|
+
if (typeof sup[field] === 'function') {
|
|
4522
|
+
Object.defineProperty(orig, 'name', { value: sup[field].name });
|
|
4523
|
+
}
|
|
4524
|
+
const temp = $mol_wire_task.getter(orig);
|
|
4525
|
+
const value = function (...args) {
|
|
4526
|
+
const fiber = temp(this ?? null, args);
|
|
4527
|
+
return fiber.sync();
|
|
4528
|
+
};
|
|
4529
|
+
Object.defineProperty(value, 'name', { value: orig.name + ' ' });
|
|
4530
|
+
Object.assign(value, { orig });
|
|
4531
|
+
const descr2 = { ...descr, value };
|
|
4532
|
+
Reflect.defineProperty(host, field, descr2);
|
|
4533
|
+
return descr2;
|
|
4534
|
+
}
|
|
4535
|
+
$.$mol_wire_method = $mol_wire_method;
|
|
4536
|
+
})($ || ($ = {}));
|
|
4537
|
+
|
|
4538
|
+
;
|
|
4539
|
+
"use strict";
|
|
4540
|
+
var $;
|
|
4541
|
+
(function ($) {
|
|
4542
|
+
const factories = new WeakMap();
|
|
4543
|
+
function factory(val) {
|
|
4544
|
+
let make = factories.get(val);
|
|
4545
|
+
if (make)
|
|
4546
|
+
return make;
|
|
4547
|
+
make = $mol_func_name_from((...args) => new val(...args), val);
|
|
4548
|
+
factories.set(val, make);
|
|
4549
|
+
return make;
|
|
4550
|
+
}
|
|
4551
|
+
function $mol_wire_sync(obj) {
|
|
4552
|
+
return new Proxy(obj, {
|
|
4553
|
+
get(obj, field) {
|
|
4554
|
+
let val = obj[field];
|
|
4555
|
+
if (typeof val !== 'function')
|
|
4556
|
+
return val;
|
|
4557
|
+
const temp = $mol_wire_task.getter(val);
|
|
4558
|
+
return function $mol_wire_sync(...args) {
|
|
4559
|
+
const fiber = temp(obj, args);
|
|
4560
|
+
return fiber.sync();
|
|
4561
|
+
};
|
|
4562
|
+
},
|
|
4563
|
+
construct(obj, args) {
|
|
4564
|
+
const temp = $mol_wire_task.getter(factory(obj));
|
|
4565
|
+
return temp(obj, args).sync();
|
|
4566
|
+
},
|
|
4567
|
+
apply(obj, self, args) {
|
|
4568
|
+
const temp = $mol_wire_task.getter(obj);
|
|
4569
|
+
return temp(self, args).sync();
|
|
4570
|
+
},
|
|
4571
|
+
});
|
|
4572
|
+
}
|
|
4573
|
+
$.$mol_wire_sync = $mol_wire_sync;
|
|
4574
|
+
})($ || ($ = {}));
|
|
4575
|
+
|
|
4576
|
+
;
|
|
4577
|
+
"use strict";
|
|
4578
|
+
var $;
|
|
4579
|
+
(function ($_1) {
|
|
4580
|
+
$mol_test({
|
|
4581
|
+
'test types'($) {
|
|
4582
|
+
class A {
|
|
4583
|
+
static a() {
|
|
4584
|
+
return Promise.resolve('');
|
|
4585
|
+
}
|
|
4586
|
+
static b() {
|
|
4587
|
+
return $mol_wire_sync(this).a();
|
|
4588
|
+
}
|
|
4589
|
+
}
|
|
4590
|
+
},
|
|
4591
|
+
async 'test method from host'($) {
|
|
4592
|
+
let count = 0;
|
|
4593
|
+
class A {
|
|
4594
|
+
static a() {
|
|
4595
|
+
return $mol_wire_sync(this).b();
|
|
4596
|
+
}
|
|
4597
|
+
static b() { return Promise.resolve(++count); }
|
|
4598
|
+
}
|
|
4599
|
+
$mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
|
|
4600
|
+
},
|
|
4601
|
+
async 'test function'($) {
|
|
4602
|
+
let count = 0;
|
|
4603
|
+
class A {
|
|
4604
|
+
static a() {
|
|
4605
|
+
return $mol_wire_sync(this.b)();
|
|
4581
4606
|
}
|
|
4582
|
-
return
|
|
4583
|
-
}
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
put(next) {
|
|
4594
|
-
const prev = this.cache;
|
|
4595
|
-
this.cache = next;
|
|
4596
|
-
if ($mol_promise_like(next)) {
|
|
4597
|
-
this.cursor = $mol_wire_cursor.fresh;
|
|
4598
|
-
if (next !== prev)
|
|
4599
|
-
this.emit();
|
|
4600
|
-
if ($mol_owning_catch(this, next)) {
|
|
4601
|
-
try {
|
|
4602
|
-
next[Symbol.toStringTag] = this[Symbol.toStringTag];
|
|
4603
|
-
}
|
|
4604
|
-
catch {
|
|
4605
|
-
Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
|
|
4606
|
-
}
|
|
4607
|
+
static b() { return Promise.resolve(++count); }
|
|
4608
|
+
}
|
|
4609
|
+
$mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
|
|
4610
|
+
},
|
|
4611
|
+
async 'test construct itself'($) {
|
|
4612
|
+
class A {
|
|
4613
|
+
static instances = [];
|
|
4614
|
+
static a() {
|
|
4615
|
+
const a = new ($mol_wire_sync(A))();
|
|
4616
|
+
this.instances.push(a);
|
|
4617
|
+
$mol_wire_sync(this).b();
|
|
4607
4618
|
}
|
|
4608
|
-
return
|
|
4619
|
+
static b() { return Promise.resolve(); }
|
|
4609
4620
|
}
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
this.emit();
|
|
4615
|
-
return next;
|
|
4621
|
+
await $mol_wire_async(A).a();
|
|
4622
|
+
$mol_assert_equal(A.instances.length, 2);
|
|
4623
|
+
$mol_assert_equal(A.instances[0] instanceof A);
|
|
4624
|
+
$mol_assert_equal(A.instances[0], A.instances[1]);
|
|
4616
4625
|
}
|
|
4617
|
-
}
|
|
4618
|
-
$.$mol_wire_task = $mol_wire_task;
|
|
4626
|
+
});
|
|
4619
4627
|
})($ || ($ = {}));
|
|
4620
4628
|
|
|
4621
4629
|
;
|
|
@@ -4764,56 +4772,120 @@ var $;
|
|
|
4764
4772
|
"use strict";
|
|
4765
4773
|
var $;
|
|
4766
4774
|
(function ($) {
|
|
4767
|
-
|
|
4768
|
-
if (!descr)
|
|
4769
|
-
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
|
4770
|
-
const orig = descr?.value ?? host[field];
|
|
4771
|
-
const sup = Reflect.getPrototypeOf(host);
|
|
4772
|
-
if (typeof sup[field] === 'function') {
|
|
4773
|
-
Object.defineProperty(orig, 'name', { value: sup[field].name });
|
|
4774
|
-
}
|
|
4775
|
-
const temp = $mol_wire_task.getter(orig);
|
|
4776
|
-
const value = function (...args) {
|
|
4777
|
-
const fiber = temp(this ?? null, args);
|
|
4778
|
-
return fiber.sync();
|
|
4779
|
-
};
|
|
4780
|
-
Object.defineProperty(value, 'name', { value: orig.name + ' ' });
|
|
4781
|
-
Object.assign(value, { orig });
|
|
4782
|
-
const descr2 = { ...descr, value };
|
|
4783
|
-
Reflect.defineProperty(host, field, descr2);
|
|
4784
|
-
return descr2;
|
|
4775
|
+
class $mol_run_error extends $mol_error_mix {
|
|
4785
4776
|
}
|
|
4786
|
-
$.$
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
|
|
4806
|
-
|
|
4777
|
+
$.$mol_run_error = $mol_run_error;
|
|
4778
|
+
$.$mol_run_spawn = (...args) => $node['child_process'].spawn(...args);
|
|
4779
|
+
$.$mol_run_spawn_sync = (...args) => $node['child_process'].spawnSync(...args);
|
|
4780
|
+
class $mol_run extends $mol_object {
|
|
4781
|
+
static async_enabled() {
|
|
4782
|
+
return Boolean(this.$.$mol_env()['MOL_RUN_ASYNC']);
|
|
4783
|
+
}
|
|
4784
|
+
static spawn(options) {
|
|
4785
|
+
const sync = !this.async_enabled() || !Boolean($mol_wire_auto());
|
|
4786
|
+
const env = options.env ?? this.$.$mol_env();
|
|
4787
|
+
return $mol_wire_sync(this).spawn_async({ ...options, sync, env });
|
|
4788
|
+
}
|
|
4789
|
+
static spawn_async({ dir, sync, timeout, command, env }) {
|
|
4790
|
+
const args_raw = typeof command === 'string' ? command.split(' ') : command;
|
|
4791
|
+
const [app, ...args] = args_raw;
|
|
4792
|
+
const opts = { shell: true, cwd: dir, env };
|
|
4793
|
+
const log_object = {
|
|
4794
|
+
place: `${this}.spawn()`,
|
|
4795
|
+
message: 'Run',
|
|
4796
|
+
command: args_raw.join(' '),
|
|
4797
|
+
dir: $node.path.relative('', dir),
|
|
4798
|
+
};
|
|
4799
|
+
if (sync) {
|
|
4800
|
+
this.$.$mol_log3_come({
|
|
4801
|
+
hint: 'Run inside fiber',
|
|
4802
|
+
...log_object
|
|
4803
|
+
});
|
|
4804
|
+
let error;
|
|
4805
|
+
let res;
|
|
4806
|
+
try {
|
|
4807
|
+
res = this.$.$mol_run_spawn_sync(app, args, opts);
|
|
4808
|
+
error = res.error;
|
|
4809
|
+
}
|
|
4810
|
+
catch (err) {
|
|
4811
|
+
error = err;
|
|
4812
|
+
}
|
|
4813
|
+
if (!res || error || res.status) {
|
|
4814
|
+
throw new $mol_run_error(this.error_message(res), { ...log_object, status: res?.status, signal: res?.signal }, ...(error ? [error] : []));
|
|
4815
|
+
}
|
|
4816
|
+
return res;
|
|
4817
|
+
}
|
|
4818
|
+
let sub;
|
|
4819
|
+
try {
|
|
4820
|
+
sub = this.$.$mol_run_spawn(app, args, {
|
|
4821
|
+
...opts,
|
|
4822
|
+
stdio: ['pipe', 'inherit', 'inherit'],
|
|
4823
|
+
});
|
|
4824
|
+
}
|
|
4825
|
+
catch (error) {
|
|
4826
|
+
throw new $mol_run_error(this.error_message(undefined), log_object, error);
|
|
4827
|
+
}
|
|
4828
|
+
const pid = sub.pid ?? 0;
|
|
4829
|
+
this.$.$mol_log3_come({
|
|
4830
|
+
...log_object,
|
|
4831
|
+
pid,
|
|
4832
|
+
});
|
|
4833
|
+
let timeout_kill = false;
|
|
4834
|
+
let timer;
|
|
4835
|
+
const std_data = [];
|
|
4836
|
+
const error_data = [];
|
|
4837
|
+
const add = (std_chunk, error_chunk) => {
|
|
4838
|
+
if (std_chunk)
|
|
4839
|
+
std_data.push(std_chunk);
|
|
4840
|
+
if (error_chunk)
|
|
4841
|
+
error_data.push(error_chunk);
|
|
4842
|
+
if (!timeout)
|
|
4843
|
+
return;
|
|
4844
|
+
clearTimeout(timer);
|
|
4845
|
+
timer = setTimeout(() => {
|
|
4846
|
+
const signal = timeout_kill ? 'SIGKILL' : 'SIGTERM';
|
|
4847
|
+
timeout_kill = true;
|
|
4848
|
+
add();
|
|
4849
|
+
sub.kill(signal);
|
|
4850
|
+
}, timeout);
|
|
4851
|
+
};
|
|
4852
|
+
add();
|
|
4853
|
+
sub.stdout?.on('data', data => add(data));
|
|
4854
|
+
sub.stderr?.on('data', data => add(undefined, data));
|
|
4855
|
+
const result_promise = new Promise((done, fail) => {
|
|
4856
|
+
const close = (error, status = null, signal = null) => {
|
|
4857
|
+
if (!timer && timeout)
|
|
4858
|
+
return;
|
|
4859
|
+
clearTimeout(timer);
|
|
4860
|
+
timer = undefined;
|
|
4861
|
+
const res = {
|
|
4862
|
+
pid,
|
|
4863
|
+
signal,
|
|
4864
|
+
get stdout() { return Buffer.concat(std_data); },
|
|
4865
|
+
get stderr() { return Buffer.concat(error_data); }
|
|
4866
|
+
};
|
|
4867
|
+
if (error || status || timeout_kill)
|
|
4868
|
+
return fail(new $mol_run_error(this.error_message(res) + (timeout_kill ? ', timeout' : ''), { ...log_object, pid, status, signal, timeout_kill }, ...error ? [error] : []));
|
|
4869
|
+
this.$.$mol_log3_done({
|
|
4870
|
+
...log_object,
|
|
4871
|
+
pid,
|
|
4872
|
+
});
|
|
4873
|
+
done(res);
|
|
4807
4874
|
};
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4875
|
+
sub.on('disconnect', () => close(new Error('Disconnected')));
|
|
4876
|
+
sub.on('error', err => close(err));
|
|
4877
|
+
sub.on('exit', (status, signal) => close(null, status, signal));
|
|
4878
|
+
});
|
|
4879
|
+
return Object.assign(result_promise, { destructor: () => {
|
|
4880
|
+
clearTimeout(timer);
|
|
4881
|
+
sub.kill('SIGKILL');
|
|
4882
|
+
} });
|
|
4883
|
+
}
|
|
4884
|
+
static error_message(res) {
|
|
4885
|
+
return res?.stderr.toString() || res?.stdout.toString() || 'Run error';
|
|
4886
|
+
}
|
|
4815
4887
|
}
|
|
4816
|
-
$.$
|
|
4888
|
+
$.$mol_run = $mol_run;
|
|
4817
4889
|
})($ || ($ = {}));
|
|
4818
4890
|
|
|
4819
4891
|
;
|
|
@@ -4821,54 +4893,65 @@ var $;
|
|
|
4821
4893
|
var $;
|
|
4822
4894
|
(function ($_1) {
|
|
4823
4895
|
$mol_test({
|
|
4824
|
-
'
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
4831
|
-
|
|
4896
|
+
async 'exec timeout auto kill child process'($) {
|
|
4897
|
+
let close_mock = () => { };
|
|
4898
|
+
const error_message = 'Run error, timeout';
|
|
4899
|
+
function mol_run_spawn_sync_mock() {
|
|
4900
|
+
return {
|
|
4901
|
+
output: [],
|
|
4902
|
+
stdout: error_message,
|
|
4903
|
+
stderr: '',
|
|
4904
|
+
status: 0,
|
|
4905
|
+
signal: null,
|
|
4906
|
+
pid: 123,
|
|
4907
|
+
};
|
|
4832
4908
|
}
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4909
|
+
function mol_run_spawn_mock() {
|
|
4910
|
+
return {
|
|
4911
|
+
on(name, cb) {
|
|
4912
|
+
if (name === 'exit')
|
|
4913
|
+
close_mock = cb;
|
|
4914
|
+
},
|
|
4915
|
+
kill() { close_mock(); }
|
|
4916
|
+
};
|
|
4917
|
+
}
|
|
4918
|
+
const context_mock = $.$mol_ambient({
|
|
4919
|
+
$mol_run_spawn_sync: mol_run_spawn_sync_mock,
|
|
4920
|
+
$mol_run_spawn: mol_run_spawn_mock
|
|
4921
|
+
});
|
|
4922
|
+
class $mol_run_mock extends $mol_run {
|
|
4923
|
+
static get $() { return context_mock; }
|
|
4924
|
+
static async_enabled() {
|
|
4925
|
+
return true;
|
|
4843
4926
|
}
|
|
4844
4927
|
}
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
async 'Latest function calls wins'($) {
|
|
4854
|
-
const first = [];
|
|
4855
|
-
const last = [];
|
|
4856
|
-
function send_name(next) {
|
|
4857
|
-
$mol_wire_sync(first).push(next);
|
|
4858
|
-
$$.$mol_wait_timeout(0);
|
|
4859
|
-
last.push(next);
|
|
4928
|
+
let message = '';
|
|
4929
|
+
try {
|
|
4930
|
+
const res = await $mol_wire_async($mol_run_mock).spawn({
|
|
4931
|
+
command: 'sleep 10',
|
|
4932
|
+
dir: '.',
|
|
4933
|
+
timeout: 10,
|
|
4934
|
+
env: { 'MOL_RUN_ASYNC': '1' }
|
|
4935
|
+
});
|
|
4860
4936
|
}
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
$mol_assert_equal(first, ['john', 'jin']);
|
|
4867
|
-
$mol_assert_equal(last, ['jin']);
|
|
4868
|
-
},
|
|
4937
|
+
catch (e) {
|
|
4938
|
+
message = e.message;
|
|
4939
|
+
}
|
|
4940
|
+
$mol_assert_equal(message, error_message);
|
|
4941
|
+
}
|
|
4869
4942
|
});
|
|
4870
4943
|
})($ || ($ = {}));
|
|
4871
4944
|
|
|
4945
|
+
;
|
|
4946
|
+
"use strict";
|
|
4947
|
+
var $;
|
|
4948
|
+
(function ($) {
|
|
4949
|
+
function $mol_exec(dir, command, ...args) {
|
|
4950
|
+
return this.$mol_run.spawn({ command: [command, ...args], dir });
|
|
4951
|
+
}
|
|
4952
|
+
$.$mol_exec = $mol_exec;
|
|
4953
|
+
})($ || ($ = {}));
|
|
4954
|
+
|
|
4872
4955
|
;
|
|
4873
4956
|
"use strict";
|
|
4874
4957
|
var $;
|
|
@@ -5392,45 +5475,6 @@ var $;
|
|
|
5392
5475
|
});
|
|
5393
5476
|
})($ || ($ = {}));
|
|
5394
5477
|
|
|
5395
|
-
;
|
|
5396
|
-
"use strict";
|
|
5397
|
-
var $;
|
|
5398
|
-
(function ($_1) {
|
|
5399
|
-
let $$;
|
|
5400
|
-
(function ($$) {
|
|
5401
|
-
let $;
|
|
5402
|
-
})($$ = $_1.$$ || ($_1.$$ = {}));
|
|
5403
|
-
$_1.$mol_object_field = Symbol('$mol_object_field');
|
|
5404
|
-
class $mol_object extends $mol_object2 {
|
|
5405
|
-
static make(config) {
|
|
5406
|
-
return super.create(obj => {
|
|
5407
|
-
for (let key in config)
|
|
5408
|
-
obj[key] = config[key];
|
|
5409
|
-
});
|
|
5410
|
-
}
|
|
5411
|
-
}
|
|
5412
|
-
$_1.$mol_object = $mol_object;
|
|
5413
|
-
})($ || ($ = {}));
|
|
5414
|
-
|
|
5415
|
-
;
|
|
5416
|
-
"use strict";
|
|
5417
|
-
var $;
|
|
5418
|
-
(function ($) {
|
|
5419
|
-
$mol_test({
|
|
5420
|
-
'init with overload'() {
|
|
5421
|
-
class X extends $mol_object {
|
|
5422
|
-
foo() {
|
|
5423
|
-
return 1;
|
|
5424
|
-
}
|
|
5425
|
-
}
|
|
5426
|
-
var x = X.make({
|
|
5427
|
-
foo: () => 2,
|
|
5428
|
-
});
|
|
5429
|
-
$mol_assert_equal(x.foo(), 2);
|
|
5430
|
-
},
|
|
5431
|
-
});
|
|
5432
|
-
})($ || ($ = {}));
|
|
5433
|
-
|
|
5434
5478
|
;
|
|
5435
5479
|
"use strict";
|
|
5436
5480
|
var $;
|