@ocap/indexdb-memory 1.29.15 → 1.29.17

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 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
- return (name$1 ? name$1.toLowerCase().includes(lowerKw) : false) || (symbol ? symbol.toLowerCase().includes(lowerKw) : false);
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 score = Math.max(nameScore, symbolScore);
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
- return moniker ? moniker.toLowerCase().includes(lowerKw) : false;
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 score = scoreMatch(row.moniker, lowerKw);
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
- return (name$1 ? name$1.toLowerCase().includes(lowerKw) : false) || (symbol ? symbol.toLowerCase().includes(lowerKw) : false);
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 score = Math.max(nameScore, symbolScore);
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
- return moniker ? moniker.toLowerCase().includes(lowerKw) : false;
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 score = scoreMatch(row.moniker, lowerKw);
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,
@@ -1,14 +1,14 @@
1
1
  import LocalBaseIndexDB from "./base.cjs";
2
2
  import { IIndexDB, IIndexTable, IndexTableTypeMap } from "@ocap/types";
3
3
  import { md5 } from "@ocap/util/lib/md5";
4
- import Lokijs from "lokijs";
4
+ import Loki from "lokijs";
5
5
 
6
6
  //#region src/db/index.d.ts
7
7
  declare class MemoryIndexDB extends LocalBaseIndexDB implements IIndexDB {
8
8
  name: string;
9
9
  version: string;
10
10
  md5: typeof md5;
11
- db: Lokijs;
11
+ db: Loki;
12
12
  tx: IIndexTable<IndexTableTypeMap['tx']>;
13
13
  account: IIndexTable<IndexTableTypeMap['account']>;
14
14
  asset: IIndexTable<IndexTableTypeMap['asset']>;
@@ -1,18 +1,18 @@
1
1
  import { BaseIndex } from "@ocap/indexdb";
2
2
  import { IIndexTable } from "@ocap/types";
3
- import Lokijs from "lokijs";
3
+ import Loki from "lokijs";
4
4
 
5
5
  //#region src/table/base.d.ts
6
6
  type UniqueIndex = string | string[];
7
7
  declare class MemoryIndex<T = unknown> extends BaseIndex<T> implements IIndexTable<T> {
8
- collection: Lokijs.Collection<T & Record<string, unknown>>;
8
+ collection: Loki.Collection<T & Record<string, unknown>>;
9
9
  /**
10
10
  * @param name table name
11
11
  * @param uniqIndex primary key(s)
12
12
  * @param db LokiJS database instance
13
13
  */
14
- constructor(name: string, uniqIndex: UniqueIndex, db: Lokijs);
15
- count(...args: Parameters<Lokijs.Collection['count']>): number;
14
+ constructor(name: string, uniqIndex: UniqueIndex, db: Loki);
15
+ count(...args: Parameters<Loki.Collection['count']>): number;
16
16
  _insert(row: Record<string, unknown>): T & Record<string, unknown>;
17
17
  _get(key: string | Record<string, unknown>): (T & Record<string, unknown>) | null;
18
18
  _update(key: string | Record<string, unknown>, updates: Record<string, unknown>): T & Record<string, unknown>;
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.15",
4
+ "version": "1.29.17",
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.15",
18
+ "@ocap/indexdb-test": "1.29.17",
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.15",
83
- "@ocap/indexdb": "1.29.15",
84
- "@ocap/types": "1.29.15",
85
- "@ocap/util": "1.29.15",
82
+ "@arcblock/did": "1.29.17",
83
+ "@ocap/indexdb": "1.29.17",
84
+ "@ocap/types": "1.29.17",
85
+ "@ocap/util": "1.29.17",
86
86
  "debug": "^4.4.3",
87
87
  "lodash": "^4.17.23",
88
88
  "lokijs": "^1.5.12"