mol_crypto_lib 0.1.1523 → 0.1.1524
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/node.d.ts +5 -0
- package/node.d.ts.map +1 -1
- package/node.deps.json +1 -1
- package/node.js +26 -11
- package/node.js.map +1 -1
- package/node.mjs +26 -11
- package/node.test.js +115 -36
- package/node.test.js.map +1 -1
- package/package.json +2 -1
package/node.mjs
CHANGED
@@ -1478,6 +1478,16 @@ var $;
|
|
1478
1478
|
$.$mol_tree2_to_string = $mol_tree2_to_string;
|
1479
1479
|
})($ || ($ = {}));
|
1480
1480
|
|
1481
|
+
;
|
1482
|
+
"use strict";
|
1483
|
+
var $;
|
1484
|
+
(function ($) {
|
1485
|
+
function $mol_maybe(value) {
|
1486
|
+
return (value == null) ? [] : [value];
|
1487
|
+
}
|
1488
|
+
$.$mol_maybe = $mol_maybe;
|
1489
|
+
})($ || ($ = {}));
|
1490
|
+
|
1481
1491
|
;
|
1482
1492
|
"use strict";
|
1483
1493
|
var $;
|
@@ -1545,33 +1555,38 @@ var $;
|
|
1545
1555
|
return $$.$mol_tree2_to_string(this);
|
1546
1556
|
}
|
1547
1557
|
insert(value, ...path) {
|
1558
|
+
return this.update($mol_maybe(value), ...path)[0];
|
1559
|
+
}
|
1560
|
+
update(value, ...path) {
|
1548
1561
|
if (path.length === 0)
|
1549
1562
|
return value;
|
1550
1563
|
const type = path[0];
|
1551
1564
|
if (typeof type === 'string') {
|
1552
1565
|
let replaced = false;
|
1553
|
-
const sub = this.kids.
|
1566
|
+
const sub = this.kids.flatMap((item, index) => {
|
1554
1567
|
if (item.type !== type)
|
1555
1568
|
return item;
|
1556
1569
|
replaced = true;
|
1557
|
-
return item.
|
1570
|
+
return item.update(value, ...path.slice(1));
|
1558
1571
|
}).filter(Boolean);
|
1559
1572
|
if (!replaced && value) {
|
1560
|
-
sub.push(this.struct(type, []).
|
1573
|
+
sub.push(...this.struct(type, []).update(value, ...path.slice(1)));
|
1561
1574
|
}
|
1562
|
-
return this.clone(sub);
|
1575
|
+
return [this.clone(sub)];
|
1563
1576
|
}
|
1564
1577
|
else if (typeof type === 'number') {
|
1565
|
-
const
|
1566
|
-
|
1567
|
-
|
1568
|
-
|
1578
|
+
const ins = (this.kids[type] || this.list([]))
|
1579
|
+
.update(value, ...path.slice(1));
|
1580
|
+
return [this.clone([
|
1581
|
+
...this.kids.slice(0, type),
|
1582
|
+
...ins,
|
1583
|
+
...this.kids.slice(type + 1),
|
1584
|
+
])];
|
1569
1585
|
}
|
1570
1586
|
else {
|
1571
1587
|
const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
|
1572
|
-
.
|
1573
|
-
|
1574
|
-
return this.clone(kids);
|
1588
|
+
.flatMap(item => item.update(value, ...path.slice(1)));
|
1589
|
+
return [this.clone(kids)];
|
1575
1590
|
}
|
1576
1591
|
}
|
1577
1592
|
select(...path) {
|
package/node.test.js
CHANGED
@@ -1469,6 +1469,16 @@ var $;
|
|
1469
1469
|
$.$mol_tree2_to_string = $mol_tree2_to_string;
|
1470
1470
|
})($ || ($ = {}));
|
1471
1471
|
|
1472
|
+
;
|
1473
|
+
"use strict";
|
1474
|
+
var $;
|
1475
|
+
(function ($) {
|
1476
|
+
function $mol_maybe(value) {
|
1477
|
+
return (value == null) ? [] : [value];
|
1478
|
+
}
|
1479
|
+
$.$mol_maybe = $mol_maybe;
|
1480
|
+
})($ || ($ = {}));
|
1481
|
+
|
1472
1482
|
;
|
1473
1483
|
"use strict";
|
1474
1484
|
var $;
|
@@ -1536,33 +1546,38 @@ var $;
|
|
1536
1546
|
return $$.$mol_tree2_to_string(this);
|
1537
1547
|
}
|
1538
1548
|
insert(value, ...path) {
|
1549
|
+
return this.update($mol_maybe(value), ...path)[0];
|
1550
|
+
}
|
1551
|
+
update(value, ...path) {
|
1539
1552
|
if (path.length === 0)
|
1540
1553
|
return value;
|
1541
1554
|
const type = path[0];
|
1542
1555
|
if (typeof type === 'string') {
|
1543
1556
|
let replaced = false;
|
1544
|
-
const sub = this.kids.
|
1557
|
+
const sub = this.kids.flatMap((item, index) => {
|
1545
1558
|
if (item.type !== type)
|
1546
1559
|
return item;
|
1547
1560
|
replaced = true;
|
1548
|
-
return item.
|
1561
|
+
return item.update(value, ...path.slice(1));
|
1549
1562
|
}).filter(Boolean);
|
1550
1563
|
if (!replaced && value) {
|
1551
|
-
sub.push(this.struct(type, []).
|
1564
|
+
sub.push(...this.struct(type, []).update(value, ...path.slice(1)));
|
1552
1565
|
}
|
1553
|
-
return this.clone(sub);
|
1566
|
+
return [this.clone(sub)];
|
1554
1567
|
}
|
1555
1568
|
else if (typeof type === 'number') {
|
1556
|
-
const
|
1557
|
-
|
1558
|
-
|
1559
|
-
|
1569
|
+
const ins = (this.kids[type] || this.list([]))
|
1570
|
+
.update(value, ...path.slice(1));
|
1571
|
+
return [this.clone([
|
1572
|
+
...this.kids.slice(0, type),
|
1573
|
+
...ins,
|
1574
|
+
...this.kids.slice(type + 1),
|
1575
|
+
])];
|
1560
1576
|
}
|
1561
1577
|
else {
|
1562
1578
|
const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
|
1563
|
-
.
|
1564
|
-
|
1565
|
-
return this.clone(kids);
|
1579
|
+
.flatMap(item => item.update(value, ...path.slice(1)));
|
1580
|
+
return [this.clone(kids)];
|
1566
1581
|
}
|
1567
1582
|
}
|
1568
1583
|
select(...path) {
|
@@ -4351,41 +4366,105 @@ var $;
|
|
4351
4366
|
});
|
4352
4367
|
})($ || ($ = {}));
|
4353
4368
|
|
4369
|
+
;
|
4370
|
+
"use strict";
|
4371
|
+
var $;
|
4372
|
+
(function ($) {
|
4373
|
+
$mol_test({
|
4374
|
+
'all cases of using maybe'() {
|
4375
|
+
$mol_assert_equal($mol_maybe(0)[0], 0);
|
4376
|
+
$mol_assert_equal($mol_maybe(false)[0], false);
|
4377
|
+
$mol_assert_equal($mol_maybe(null)[0], void 0);
|
4378
|
+
$mol_assert_equal($mol_maybe(void 0)[0], void 0);
|
4379
|
+
$mol_assert_equal($mol_maybe(void 0).map(v => v.toString())[0], void 0);
|
4380
|
+
$mol_assert_equal($mol_maybe(0).map(v => v.toString())[0], '0');
|
4381
|
+
},
|
4382
|
+
});
|
4383
|
+
})($ || ($ = {}));
|
4384
|
+
|
4354
4385
|
;
|
4355
4386
|
"use strict";
|
4356
4387
|
var $;
|
4357
4388
|
(function ($_1) {
|
4389
|
+
function check(tree, ideal) {
|
4390
|
+
$mol_assert_equal(tree.toString(), $$.$mol_tree2_from_string(ideal).toString());
|
4391
|
+
}
|
4358
4392
|
$mol_test({
|
4359
4393
|
'inserting'($) {
|
4360
|
-
|
4361
|
-
|
4362
|
-
|
4363
|
-
|
4364
|
-
|
4365
|
-
|
4366
|
-
|
4367
|
-
|
4368
|
-
|
4369
|
-
|
4370
|
-
|
4371
|
-
|
4372
|
-
|
4373
|
-
.insert($mol_tree2.struct('x'),
|
4374
|
-
|
4375
|
-
|
4376
|
-
|
4377
|
-
|
4394
|
+
check($.$mol_tree2_from_string(`
|
4395
|
+
a b c d
|
4396
|
+
`).insert($mol_tree2.struct('x'), 'a', 'b', 'c'), `
|
4397
|
+
a b x
|
4398
|
+
`);
|
4399
|
+
check($.$mol_tree2_from_string(`
|
4400
|
+
a b
|
4401
|
+
`).insert($mol_tree2.struct('x'), 'a', 'b', 'c', 'd'), `
|
4402
|
+
a b c x
|
4403
|
+
`);
|
4404
|
+
check($.$mol_tree2_from_string(`
|
4405
|
+
a b c d
|
4406
|
+
`)
|
4407
|
+
.insert($mol_tree2.struct('x'), 0, 0, 0), `
|
4408
|
+
a b x
|
4409
|
+
`);
|
4410
|
+
check($.$mol_tree2_from_string(`
|
4411
|
+
a b
|
4412
|
+
`)
|
4413
|
+
.insert($mol_tree2.struct('x'), 0, 0, 0, 0), `
|
4414
|
+
a b \\
|
4415
|
+
x
|
4416
|
+
`);
|
4417
|
+
check($.$mol_tree2_from_string(`
|
4418
|
+
a b c d
|
4419
|
+
`)
|
4420
|
+
.insert($mol_tree2.struct('x'), null, null, null), `
|
4421
|
+
a b x
|
4422
|
+
`);
|
4423
|
+
check($.$mol_tree2_from_string(`
|
4424
|
+
a b
|
4425
|
+
`)
|
4426
|
+
.insert($mol_tree2.struct('x'), null, null, null, null), `
|
4427
|
+
a b \\
|
4428
|
+
x
|
4429
|
+
`);
|
4430
|
+
},
|
4431
|
+
'updating'($) {
|
4432
|
+
check($.$mol_tree2_from_string(`
|
4433
|
+
a b c d
|
4434
|
+
`).update([], 'a', 'b', 'c')[0], `
|
4435
|
+
a b
|
4436
|
+
`);
|
4437
|
+
check($.$mol_tree2_from_string(`
|
4438
|
+
a b c d
|
4439
|
+
`).update([$mol_tree2.struct('x')])[0], `
|
4440
|
+
x
|
4441
|
+
`);
|
4442
|
+
check($.$mol_tree2_from_string(`
|
4443
|
+
a b c d
|
4444
|
+
`).update([$mol_tree2.struct('x'), $mol_tree2.struct('y')], 'a', 'b', 'c')[0], `
|
4445
|
+
a b
|
4446
|
+
x
|
4447
|
+
y
|
4448
|
+
`);
|
4378
4449
|
},
|
4379
4450
|
'deleting'($) {
|
4380
|
-
|
4381
|
-
|
4382
|
-
|
4383
|
-
|
4384
|
-
|
4385
|
-
|
4451
|
+
const base = $.$mol_tree2_from_string(`
|
4452
|
+
a b c d
|
4453
|
+
`);
|
4454
|
+
check(base.insert(null, 'a', 'b', 'c'), `
|
4455
|
+
a b
|
4456
|
+
`);
|
4457
|
+
check(base.update(base.select('a', 'b', 'c', null).kids, 'a', 'b', 'c')[0], `
|
4458
|
+
a b d
|
4459
|
+
`);
|
4460
|
+
check(base.insert(null, 0, 0, 0), `
|
4461
|
+
a b
|
4462
|
+
`);
|
4386
4463
|
},
|
4387
4464
|
'hack'($) {
|
4388
|
-
const res = $.$mol_tree2_from_string(`
|
4465
|
+
const res = $.$mol_tree2_from_string(`
|
4466
|
+
foo bar xxx
|
4467
|
+
`)
|
4389
4468
|
.hack({
|
4390
4469
|
'bar': (input, belt) => [input.struct('777', input.hack(belt))],
|
4391
4470
|
});
|