onchain-utility 0.0.11 → 0.0.13
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/dist/OnchainUtility.js +30 -0
- package/dist/OnchainUtility.mjs +30 -0
- package/dist/Tree.js +30 -0
- package/dist/Tree.mjs +30 -0
- package/package.json +1 -1
- package/src/Tree/index.ts +21 -0
package/dist/OnchainUtility.js
CHANGED
|
@@ -1350,6 +1350,21 @@ function generatedAcrossHierarchySort({
|
|
|
1350
1350
|
nodes
|
|
1351
1351
|
};
|
|
1352
1352
|
}
|
|
1353
|
+
function optimizeStructure({
|
|
1354
|
+
data,
|
|
1355
|
+
childrenKey = 'children',
|
|
1356
|
+
signKey = 'id'
|
|
1357
|
+
}) {
|
|
1358
|
+
if (data.length > 1) {
|
|
1359
|
+
return [{
|
|
1360
|
+
[childrenKey]: data,
|
|
1361
|
+
isCustom: true,
|
|
1362
|
+
[signKey]: 'custom-root'
|
|
1363
|
+
}];
|
|
1364
|
+
} else {
|
|
1365
|
+
return data;
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1353
1368
|
function _simpleGetRel({
|
|
1354
1369
|
data,
|
|
1355
1370
|
key,
|
|
@@ -1374,6 +1389,11 @@ function move({
|
|
|
1374
1389
|
onMoved,
|
|
1375
1390
|
onError
|
|
1376
1391
|
}) {
|
|
1392
|
+
data = optimizeStructure({
|
|
1393
|
+
childrenKey,
|
|
1394
|
+
data,
|
|
1395
|
+
signKey
|
|
1396
|
+
});
|
|
1377
1397
|
const layers = mergeAdjacent({
|
|
1378
1398
|
childrenKey,
|
|
1379
1399
|
data,
|
|
@@ -1448,6 +1468,11 @@ async function upgrade({
|
|
|
1448
1468
|
onUpgraded,
|
|
1449
1469
|
onError
|
|
1450
1470
|
}) {
|
|
1471
|
+
data = optimizeStructure({
|
|
1472
|
+
childrenKey,
|
|
1473
|
+
data,
|
|
1474
|
+
signKey
|
|
1475
|
+
});
|
|
1451
1476
|
const layers = mergeAdjacent({
|
|
1452
1477
|
childrenKey,
|
|
1453
1478
|
data,
|
|
@@ -1552,6 +1577,11 @@ async function downgrade({
|
|
|
1552
1577
|
childrenKey = 'children',
|
|
1553
1578
|
onError
|
|
1554
1579
|
}) {
|
|
1580
|
+
data = optimizeStructure({
|
|
1581
|
+
childrenKey,
|
|
1582
|
+
data,
|
|
1583
|
+
signKey
|
|
1584
|
+
});
|
|
1555
1585
|
const layers = mergeAdjacent({
|
|
1556
1586
|
childrenKey,
|
|
1557
1587
|
data,
|
package/dist/OnchainUtility.mjs
CHANGED
|
@@ -1348,6 +1348,21 @@ function generatedAcrossHierarchySort({
|
|
|
1348
1348
|
nodes
|
|
1349
1349
|
};
|
|
1350
1350
|
}
|
|
1351
|
+
function optimizeStructure({
|
|
1352
|
+
data,
|
|
1353
|
+
childrenKey = 'children',
|
|
1354
|
+
signKey = 'id'
|
|
1355
|
+
}) {
|
|
1356
|
+
if (data.length > 1) {
|
|
1357
|
+
return [{
|
|
1358
|
+
[childrenKey]: data,
|
|
1359
|
+
isCustom: true,
|
|
1360
|
+
[signKey]: 'custom-root'
|
|
1361
|
+
}];
|
|
1362
|
+
} else {
|
|
1363
|
+
return data;
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1351
1366
|
function _simpleGetRel({
|
|
1352
1367
|
data,
|
|
1353
1368
|
key,
|
|
@@ -1372,6 +1387,11 @@ function move({
|
|
|
1372
1387
|
onMoved,
|
|
1373
1388
|
onError
|
|
1374
1389
|
}) {
|
|
1390
|
+
data = optimizeStructure({
|
|
1391
|
+
childrenKey,
|
|
1392
|
+
data,
|
|
1393
|
+
signKey
|
|
1394
|
+
});
|
|
1375
1395
|
const layers = mergeAdjacent({
|
|
1376
1396
|
childrenKey,
|
|
1377
1397
|
data,
|
|
@@ -1446,6 +1466,11 @@ async function upgrade({
|
|
|
1446
1466
|
onUpgraded,
|
|
1447
1467
|
onError
|
|
1448
1468
|
}) {
|
|
1469
|
+
data = optimizeStructure({
|
|
1470
|
+
childrenKey,
|
|
1471
|
+
data,
|
|
1472
|
+
signKey
|
|
1473
|
+
});
|
|
1449
1474
|
const layers = mergeAdjacent({
|
|
1450
1475
|
childrenKey,
|
|
1451
1476
|
data,
|
|
@@ -1550,6 +1575,11 @@ async function downgrade({
|
|
|
1550
1575
|
childrenKey = 'children',
|
|
1551
1576
|
onError
|
|
1552
1577
|
}) {
|
|
1578
|
+
data = optimizeStructure({
|
|
1579
|
+
childrenKey,
|
|
1580
|
+
data,
|
|
1581
|
+
signKey
|
|
1582
|
+
});
|
|
1553
1583
|
const layers = mergeAdjacent({
|
|
1554
1584
|
childrenKey,
|
|
1555
1585
|
data,
|
package/dist/Tree.js
CHANGED
|
@@ -329,6 +329,21 @@ function generatedAcrossHierarchySort({
|
|
|
329
329
|
nodes
|
|
330
330
|
};
|
|
331
331
|
}
|
|
332
|
+
function optimizeStructure({
|
|
333
|
+
data,
|
|
334
|
+
childrenKey = 'children',
|
|
335
|
+
signKey = 'id'
|
|
336
|
+
}) {
|
|
337
|
+
if (data.length > 1) {
|
|
338
|
+
return [{
|
|
339
|
+
[childrenKey]: data,
|
|
340
|
+
isCustom: true,
|
|
341
|
+
[signKey]: 'custom-root'
|
|
342
|
+
}];
|
|
343
|
+
} else {
|
|
344
|
+
return data;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
332
347
|
function _simpleGetRel({
|
|
333
348
|
data,
|
|
334
349
|
key,
|
|
@@ -353,6 +368,11 @@ function move({
|
|
|
353
368
|
onMoved,
|
|
354
369
|
onError
|
|
355
370
|
}) {
|
|
371
|
+
data = optimizeStructure({
|
|
372
|
+
childrenKey,
|
|
373
|
+
data,
|
|
374
|
+
signKey
|
|
375
|
+
});
|
|
356
376
|
const layers = mergeAdjacent({
|
|
357
377
|
childrenKey,
|
|
358
378
|
data,
|
|
@@ -427,6 +447,11 @@ async function upgrade({
|
|
|
427
447
|
onUpgraded,
|
|
428
448
|
onError
|
|
429
449
|
}) {
|
|
450
|
+
data = optimizeStructure({
|
|
451
|
+
childrenKey,
|
|
452
|
+
data,
|
|
453
|
+
signKey
|
|
454
|
+
});
|
|
430
455
|
const layers = mergeAdjacent({
|
|
431
456
|
childrenKey,
|
|
432
457
|
data,
|
|
@@ -531,6 +556,11 @@ async function downgrade({
|
|
|
531
556
|
childrenKey = 'children',
|
|
532
557
|
onError
|
|
533
558
|
}) {
|
|
559
|
+
data = optimizeStructure({
|
|
560
|
+
childrenKey,
|
|
561
|
+
data,
|
|
562
|
+
signKey
|
|
563
|
+
});
|
|
534
564
|
const layers = mergeAdjacent({
|
|
535
565
|
childrenKey,
|
|
536
566
|
data,
|
package/dist/Tree.mjs
CHANGED
|
@@ -327,6 +327,21 @@ function generatedAcrossHierarchySort({
|
|
|
327
327
|
nodes
|
|
328
328
|
};
|
|
329
329
|
}
|
|
330
|
+
function optimizeStructure({
|
|
331
|
+
data,
|
|
332
|
+
childrenKey = 'children',
|
|
333
|
+
signKey = 'id'
|
|
334
|
+
}) {
|
|
335
|
+
if (data.length > 1) {
|
|
336
|
+
return [{
|
|
337
|
+
[childrenKey]: data,
|
|
338
|
+
isCustom: true,
|
|
339
|
+
[signKey]: 'custom-root'
|
|
340
|
+
}];
|
|
341
|
+
} else {
|
|
342
|
+
return data;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
330
345
|
function _simpleGetRel({
|
|
331
346
|
data,
|
|
332
347
|
key,
|
|
@@ -351,6 +366,11 @@ function move({
|
|
|
351
366
|
onMoved,
|
|
352
367
|
onError
|
|
353
368
|
}) {
|
|
369
|
+
data = optimizeStructure({
|
|
370
|
+
childrenKey,
|
|
371
|
+
data,
|
|
372
|
+
signKey
|
|
373
|
+
});
|
|
354
374
|
const layers = mergeAdjacent({
|
|
355
375
|
childrenKey,
|
|
356
376
|
data,
|
|
@@ -425,6 +445,11 @@ async function upgrade({
|
|
|
425
445
|
onUpgraded,
|
|
426
446
|
onError
|
|
427
447
|
}) {
|
|
448
|
+
data = optimizeStructure({
|
|
449
|
+
childrenKey,
|
|
450
|
+
data,
|
|
451
|
+
signKey
|
|
452
|
+
});
|
|
428
453
|
const layers = mergeAdjacent({
|
|
429
454
|
childrenKey,
|
|
430
455
|
data,
|
|
@@ -529,6 +554,11 @@ async function downgrade({
|
|
|
529
554
|
childrenKey = 'children',
|
|
530
555
|
onError
|
|
531
556
|
}) {
|
|
557
|
+
data = optimizeStructure({
|
|
558
|
+
childrenKey,
|
|
559
|
+
data,
|
|
560
|
+
signKey
|
|
561
|
+
});
|
|
532
562
|
const layers = mergeAdjacent({
|
|
533
563
|
childrenKey,
|
|
534
564
|
data,
|
package/package.json
CHANGED
package/src/Tree/index.ts
CHANGED
|
@@ -395,6 +395,24 @@ export function generatedAcrossHierarchySort<T extends Item>({
|
|
|
395
395
|
};
|
|
396
396
|
}
|
|
397
397
|
|
|
398
|
+
function optimizeStructure<T>({
|
|
399
|
+
data,
|
|
400
|
+
childrenKey = 'children',
|
|
401
|
+
signKey = 'id',
|
|
402
|
+
}: Params<T>): T[] {
|
|
403
|
+
if (data.length > 1) {
|
|
404
|
+
return [
|
|
405
|
+
{
|
|
406
|
+
[childrenKey]: data,
|
|
407
|
+
isCustom: true,
|
|
408
|
+
[signKey]: 'custom-root',
|
|
409
|
+
} as T,
|
|
410
|
+
];
|
|
411
|
+
} else {
|
|
412
|
+
return data;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
398
416
|
function _simpleGetRel<T extends Item>({
|
|
399
417
|
data,
|
|
400
418
|
key,
|
|
@@ -431,6 +449,7 @@ export function move<T extends Item>({
|
|
|
431
449
|
}: MoveParams<T> & {
|
|
432
450
|
isMoveUp?: boolean;
|
|
433
451
|
}) {
|
|
452
|
+
data = optimizeStructure({childrenKey, data, signKey});
|
|
434
453
|
const layers = mergeAdjacent({childrenKey, data, selectKeys, signKey});
|
|
435
454
|
for (const comb of layers) {
|
|
436
455
|
for (const keys of comb) {
|
|
@@ -510,6 +529,7 @@ export async function upgrade<T extends Item>({
|
|
|
510
529
|
}) => Promise<boolean> | boolean;
|
|
511
530
|
onUpgraded?: (upgrades: T[]) => void;
|
|
512
531
|
}) {
|
|
532
|
+
data = optimizeStructure({childrenKey, data, signKey});
|
|
513
533
|
const layers = mergeAdjacent({childrenKey, data, selectKeys, signKey});
|
|
514
534
|
const {crossLayerSort, getInsertIdx} = generatedAcrossHierarchySort({
|
|
515
535
|
signKey,
|
|
@@ -611,6 +631,7 @@ export async function downgrade<T extends Item>({
|
|
|
611
631
|
}) => Promise<boolean> | boolean;
|
|
612
632
|
onDowngraded?: (downgrades: T[]) => void;
|
|
613
633
|
}) {
|
|
634
|
+
data = optimizeStructure({childrenKey, data, signKey});
|
|
614
635
|
const layers = mergeAdjacent({childrenKey, data, selectKeys, signKey});
|
|
615
636
|
for (const comb of layers) {
|
|
616
637
|
for (const keys of comb) {
|