@ocap/indexdb-memory 1.29.15 → 1.29.16
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/esm/db/base.mjs +87 -5
- package/lib/db/base.cjs +87 -5
- package/package.json +6 -6
package/esm/db/base.mjs
CHANGED
|
@@ -455,18 +455,21 @@ var LocalBaseIndexDB = class extends BaseIndexDB {
|
|
|
455
455
|
account: 1,
|
|
456
456
|
factory: 2,
|
|
457
457
|
asset: 3,
|
|
458
|
-
tokenFactory: 4
|
|
458
|
+
tokenFactory: 4,
|
|
459
|
+
stake: 5
|
|
459
460
|
};
|
|
460
461
|
const results = [];
|
|
461
462
|
const tokenMatches = getCollection(this.token).chain().where((x) => {
|
|
462
463
|
const name$1 = x.name;
|
|
463
464
|
const symbol = x.symbol;
|
|
464
|
-
|
|
465
|
+
const description = x.description;
|
|
466
|
+
return (name$1 ? name$1.toLowerCase().includes(lowerKw) : false) || (symbol ? symbol.toLowerCase().includes(lowerKw) : false) || (description ? description.toLowerCase().includes(lowerKw) : false);
|
|
465
467
|
}).limit(SEARCH_LIMIT_PER_TABLE).data();
|
|
466
468
|
for (const row of tokenMatches) {
|
|
467
469
|
const nameScore = row.name ? scoreMatch(row.name, lowerKw) : 0;
|
|
468
470
|
const symbolScore = row.symbol ? scoreMatch(row.symbol, lowerKw) : 0;
|
|
469
|
-
const
|
|
471
|
+
const descScore = row.description ? scoreMatch(row.description, lowerKw) : 0;
|
|
472
|
+
const score = Math.max(nameScore, symbolScore, descScore);
|
|
470
473
|
const title = nameScore >= symbolScore ? row.name || row.symbol || "" : row.symbol || row.name || "";
|
|
471
474
|
results.push({
|
|
472
475
|
type: "token",
|
|
@@ -509,10 +512,14 @@ var LocalBaseIndexDB = class extends BaseIndexDB {
|
|
|
509
512
|
}
|
|
510
513
|
const assetMatches = getCollection(this.asset).chain().where((x) => {
|
|
511
514
|
const moniker = x.moniker;
|
|
512
|
-
|
|
515
|
+
const tags = x.tags;
|
|
516
|
+
return (moniker ? moniker.toLowerCase().includes(lowerKw) : false) || Array.isArray(tags) && tags.some((t) => t.toLowerCase().includes(lowerKw));
|
|
513
517
|
}).limit(SEARCH_LIMIT_PER_TABLE).data();
|
|
514
518
|
for (const row of assetMatches) {
|
|
515
|
-
const
|
|
519
|
+
const monikerScore = row.moniker ? scoreMatch(row.moniker, lowerKw) : 0;
|
|
520
|
+
const tags = row.tags;
|
|
521
|
+
const tagScore = Array.isArray(tags) ? Math.max(0, ...tags.map((t) => scoreMatch(t, lowerKw))) : 0;
|
|
522
|
+
const score = Math.max(monikerScore, tagScore);
|
|
516
523
|
results.push({
|
|
517
524
|
type: "asset",
|
|
518
525
|
id: row.address,
|
|
@@ -539,6 +546,81 @@ var LocalBaseIndexDB = class extends BaseIndexDB {
|
|
|
539
546
|
priority: typePriority.tokenFactory
|
|
540
547
|
});
|
|
541
548
|
}
|
|
549
|
+
const stakeMatches = getCollection(this.stake).chain().where((x) => {
|
|
550
|
+
const message = x.message;
|
|
551
|
+
return message ? message.toLowerCase().includes(lowerKw) : false;
|
|
552
|
+
}).limit(SEARCH_LIMIT_PER_TABLE).data();
|
|
553
|
+
for (const row of stakeMatches) {
|
|
554
|
+
const score = scoreMatch(row.message, lowerKw);
|
|
555
|
+
results.push({
|
|
556
|
+
type: "stake",
|
|
557
|
+
id: row.address,
|
|
558
|
+
title: row.message || "",
|
|
559
|
+
score,
|
|
560
|
+
priority: typePriority.stake
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
if (/^(did:abt:)?(z[1-9A-HJ-NP-Za-km-z]|0x[0-9a-fA-F])/.test(trimmed)) {
|
|
564
|
+
const didPrefix = trimmed.replace(/^did:abt:/i, "");
|
|
565
|
+
if (didPrefix.length >= 4) {
|
|
566
|
+
const seen = new Set(results.map((r) => `${r.type}:${r.id}`));
|
|
567
|
+
const titleField = {
|
|
568
|
+
account: "moniker",
|
|
569
|
+
token: "name",
|
|
570
|
+
asset: "moniker",
|
|
571
|
+
factory: "name",
|
|
572
|
+
tokenFactory: "name",
|
|
573
|
+
stake: "message"
|
|
574
|
+
};
|
|
575
|
+
const collections = [
|
|
576
|
+
{
|
|
577
|
+
collection: this.account,
|
|
578
|
+
type: "account"
|
|
579
|
+
},
|
|
580
|
+
{
|
|
581
|
+
collection: this.token,
|
|
582
|
+
type: "token"
|
|
583
|
+
},
|
|
584
|
+
{
|
|
585
|
+
collection: this.asset,
|
|
586
|
+
type: "asset"
|
|
587
|
+
},
|
|
588
|
+
{
|
|
589
|
+
collection: this.factory,
|
|
590
|
+
type: "factory"
|
|
591
|
+
},
|
|
592
|
+
{
|
|
593
|
+
collection: this.tokenFactory,
|
|
594
|
+
type: "tokenFactory"
|
|
595
|
+
},
|
|
596
|
+
{
|
|
597
|
+
collection: this.stake,
|
|
598
|
+
type: "stake"
|
|
599
|
+
}
|
|
600
|
+
];
|
|
601
|
+
for (const { collection, type } of collections) {
|
|
602
|
+
const matches = getCollection(collection).chain().where((x) => {
|
|
603
|
+
const addr = x.address;
|
|
604
|
+
return addr ? addr.startsWith(didPrefix) : false;
|
|
605
|
+
}).limit(SEARCH_LIMIT_PER_TABLE).data();
|
|
606
|
+
for (const row of matches) {
|
|
607
|
+
const addr = row.address;
|
|
608
|
+
const key = `${type}:${addr}`;
|
|
609
|
+
if (!seen.has(key)) {
|
|
610
|
+
seen.add(key);
|
|
611
|
+
const title = row[titleField[type]] || addr;
|
|
612
|
+
results.push({
|
|
613
|
+
type,
|
|
614
|
+
id: addr,
|
|
615
|
+
title,
|
|
616
|
+
score: 2,
|
|
617
|
+
priority: typePriority[type] ?? 99
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
542
624
|
results.sort((a, b) => b.score - a.score || a.priority - b.priority);
|
|
543
625
|
return results.map(({ type, id, title }) => ({
|
|
544
626
|
type,
|
package/lib/db/base.cjs
CHANGED
|
@@ -459,18 +459,21 @@ var LocalBaseIndexDB = class extends _ocap_indexdb.BaseIndexDB {
|
|
|
459
459
|
account: 1,
|
|
460
460
|
factory: 2,
|
|
461
461
|
asset: 3,
|
|
462
|
-
tokenFactory: 4
|
|
462
|
+
tokenFactory: 4,
|
|
463
|
+
stake: 5
|
|
463
464
|
};
|
|
464
465
|
const results = [];
|
|
465
466
|
const tokenMatches = getCollection(this.token).chain().where((x) => {
|
|
466
467
|
const name$1 = x.name;
|
|
467
468
|
const symbol = x.symbol;
|
|
468
|
-
|
|
469
|
+
const description = x.description;
|
|
470
|
+
return (name$1 ? name$1.toLowerCase().includes(lowerKw) : false) || (symbol ? symbol.toLowerCase().includes(lowerKw) : false) || (description ? description.toLowerCase().includes(lowerKw) : false);
|
|
469
471
|
}).limit(SEARCH_LIMIT_PER_TABLE).data();
|
|
470
472
|
for (const row of tokenMatches) {
|
|
471
473
|
const nameScore = row.name ? scoreMatch(row.name, lowerKw) : 0;
|
|
472
474
|
const symbolScore = row.symbol ? scoreMatch(row.symbol, lowerKw) : 0;
|
|
473
|
-
const
|
|
475
|
+
const descScore = row.description ? scoreMatch(row.description, lowerKw) : 0;
|
|
476
|
+
const score = Math.max(nameScore, symbolScore, descScore);
|
|
474
477
|
const title = nameScore >= symbolScore ? row.name || row.symbol || "" : row.symbol || row.name || "";
|
|
475
478
|
results.push({
|
|
476
479
|
type: "token",
|
|
@@ -513,10 +516,14 @@ var LocalBaseIndexDB = class extends _ocap_indexdb.BaseIndexDB {
|
|
|
513
516
|
}
|
|
514
517
|
const assetMatches = getCollection(this.asset).chain().where((x) => {
|
|
515
518
|
const moniker = x.moniker;
|
|
516
|
-
|
|
519
|
+
const tags = x.tags;
|
|
520
|
+
return (moniker ? moniker.toLowerCase().includes(lowerKw) : false) || Array.isArray(tags) && tags.some((t) => t.toLowerCase().includes(lowerKw));
|
|
517
521
|
}).limit(SEARCH_LIMIT_PER_TABLE).data();
|
|
518
522
|
for (const row of assetMatches) {
|
|
519
|
-
const
|
|
523
|
+
const monikerScore = row.moniker ? scoreMatch(row.moniker, lowerKw) : 0;
|
|
524
|
+
const tags = row.tags;
|
|
525
|
+
const tagScore = Array.isArray(tags) ? Math.max(0, ...tags.map((t) => scoreMatch(t, lowerKw))) : 0;
|
|
526
|
+
const score = Math.max(monikerScore, tagScore);
|
|
520
527
|
results.push({
|
|
521
528
|
type: "asset",
|
|
522
529
|
id: row.address,
|
|
@@ -543,6 +550,81 @@ var LocalBaseIndexDB = class extends _ocap_indexdb.BaseIndexDB {
|
|
|
543
550
|
priority: typePriority.tokenFactory
|
|
544
551
|
});
|
|
545
552
|
}
|
|
553
|
+
const stakeMatches = getCollection(this.stake).chain().where((x) => {
|
|
554
|
+
const message = x.message;
|
|
555
|
+
return message ? message.toLowerCase().includes(lowerKw) : false;
|
|
556
|
+
}).limit(SEARCH_LIMIT_PER_TABLE).data();
|
|
557
|
+
for (const row of stakeMatches) {
|
|
558
|
+
const score = scoreMatch(row.message, lowerKw);
|
|
559
|
+
results.push({
|
|
560
|
+
type: "stake",
|
|
561
|
+
id: row.address,
|
|
562
|
+
title: row.message || "",
|
|
563
|
+
score,
|
|
564
|
+
priority: typePriority.stake
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
if (/^(did:abt:)?(z[1-9A-HJ-NP-Za-km-z]|0x[0-9a-fA-F])/.test(trimmed)) {
|
|
568
|
+
const didPrefix = trimmed.replace(/^did:abt:/i, "");
|
|
569
|
+
if (didPrefix.length >= 4) {
|
|
570
|
+
const seen = new Set(results.map((r) => `${r.type}:${r.id}`));
|
|
571
|
+
const titleField = {
|
|
572
|
+
account: "moniker",
|
|
573
|
+
token: "name",
|
|
574
|
+
asset: "moniker",
|
|
575
|
+
factory: "name",
|
|
576
|
+
tokenFactory: "name",
|
|
577
|
+
stake: "message"
|
|
578
|
+
};
|
|
579
|
+
const collections = [
|
|
580
|
+
{
|
|
581
|
+
collection: this.account,
|
|
582
|
+
type: "account"
|
|
583
|
+
},
|
|
584
|
+
{
|
|
585
|
+
collection: this.token,
|
|
586
|
+
type: "token"
|
|
587
|
+
},
|
|
588
|
+
{
|
|
589
|
+
collection: this.asset,
|
|
590
|
+
type: "asset"
|
|
591
|
+
},
|
|
592
|
+
{
|
|
593
|
+
collection: this.factory,
|
|
594
|
+
type: "factory"
|
|
595
|
+
},
|
|
596
|
+
{
|
|
597
|
+
collection: this.tokenFactory,
|
|
598
|
+
type: "tokenFactory"
|
|
599
|
+
},
|
|
600
|
+
{
|
|
601
|
+
collection: this.stake,
|
|
602
|
+
type: "stake"
|
|
603
|
+
}
|
|
604
|
+
];
|
|
605
|
+
for (const { collection, type } of collections) {
|
|
606
|
+
const matches = getCollection(collection).chain().where((x) => {
|
|
607
|
+
const addr = x.address;
|
|
608
|
+
return addr ? addr.startsWith(didPrefix) : false;
|
|
609
|
+
}).limit(SEARCH_LIMIT_PER_TABLE).data();
|
|
610
|
+
for (const row of matches) {
|
|
611
|
+
const addr = row.address;
|
|
612
|
+
const key = `${type}:${addr}`;
|
|
613
|
+
if (!seen.has(key)) {
|
|
614
|
+
seen.add(key);
|
|
615
|
+
const title = row[titleField[type]] || addr;
|
|
616
|
+
results.push({
|
|
617
|
+
type,
|
|
618
|
+
id: addr,
|
|
619
|
+
title,
|
|
620
|
+
score: 2,
|
|
621
|
+
priority: typePriority[type] ?? 99
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
}
|
|
546
628
|
results.sort((a, b) => b.score - a.score || a.priority - b.priority);
|
|
547
629
|
return results.map(({ type, id, title }) => ({
|
|
548
630
|
type,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ocap/indexdb-memory",
|
|
3
3
|
"description": "OCAP indexdb adapter that uses memory as backend, just for test purpose",
|
|
4
|
-
"version": "1.29.
|
|
4
|
+
"version": "1.29.16",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "wangshijun <shijun@arcblock.io> (https://www.arcblock.io)",
|
|
7
7
|
"bugs": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"wangshijun <shijun@arcblock.io> (https://www.arcblock.io)"
|
|
16
16
|
],
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@ocap/indexdb-test": "1.29.
|
|
18
|
+
"@ocap/indexdb-test": "1.29.16",
|
|
19
19
|
"@types/debug": "^4.1.12",
|
|
20
20
|
"@types/lodash": "^4.17.10",
|
|
21
21
|
"@types/lokijs": "^1.5.14",
|
|
@@ -79,10 +79,10 @@
|
|
|
79
79
|
},
|
|
80
80
|
"gitHead": "87990c8b5e215107fc587c1ced0d6b3e2cd2483e",
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"@arcblock/did": "1.29.
|
|
83
|
-
"@ocap/indexdb": "1.29.
|
|
84
|
-
"@ocap/types": "1.29.
|
|
85
|
-
"@ocap/util": "1.29.
|
|
82
|
+
"@arcblock/did": "1.29.16",
|
|
83
|
+
"@ocap/indexdb": "1.29.16",
|
|
84
|
+
"@ocap/types": "1.29.16",
|
|
85
|
+
"@ocap/util": "1.29.16",
|
|
86
86
|
"debug": "^4.4.3",
|
|
87
87
|
"lodash": "^4.17.23",
|
|
88
88
|
"lokijs": "^1.5.12"
|