@ocap/indexdb-memory 1.29.14 → 1.29.15

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.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { BaseIndexDB } from "@ocap/indexdb";
2
- import { IIndexDB, IListAccountsResult, IListAssetsResult, IListDelegationsResult, IListFactoriesResult, IListRollupBlocksResult, IListRollupValidatorsResult, IListRollupsResult, IListStakesResult, IListTokenFactoriesResult, IListTokensResult, IListTransactionsResult, TRequestListAssets, TRequestListDelegations, TRequestListFactories, TRequestListRollupBlocks, TRequestListRollupValidators, TRequestListRollups, TRequestListStakes, TRequestListTokenFactories, TRequestListTokens, TRequestListTopAccounts, TRequestListTransactions } from "@ocap/types";
2
+ import { IIndexDB, IListAccountsResult, IListAssetsResult, IListDelegationsResult, IListFactoriesResult, IListRollupBlocksResult, IListRollupValidatorsResult, IListRollupsResult, IListStakesResult, IListTokenFactoriesResult, IListTokensResult, IListTransactionsResult, TRequestListAssets, TRequestListDelegations, TRequestListFactories, TRequestListRollupBlocks, TRequestListRollupValidators, TRequestListRollups, TRequestListStakes, TRequestListTokenFactories, TRequestListTokens, TRequestListTopAccounts, TRequestListTransactions, TSearchResult } from "@ocap/types";
3
3
 
4
4
  //#region src/db/base.d.ts
5
5
  declare class LocalBaseIndexDB extends BaseIndexDB implements IIndexDB {
@@ -15,6 +15,10 @@ declare class LocalBaseIndexDB extends BaseIndexDB implements IIndexDB {
15
15
  listRollupBlocks(params?: Partial<TRequestListRollupBlocks>): IListRollupBlocksResult;
16
16
  listRollupValidators(params?: Partial<TRequestListRollupValidators>): IListRollupValidatorsResult;
17
17
  listDelegations(params?: Partial<TRequestListDelegations>): IListDelegationsResult;
18
+ /**
19
+ * Search entities by semantic fields (moniker, name, symbol, description)
20
+ */
21
+ search(keyword: string): TSearchResult[];
18
22
  }
19
23
  //#endregion
20
24
  export { LocalBaseIndexDB as default };
package/esm/db/base.mjs CHANGED
@@ -9,6 +9,14 @@ import omit from "lodash/omit.js";
9
9
  //#region src/db/base.ts
10
10
  const debug = debugFactory(name);
11
11
  const MAX_REQUEST_FACTORY_ADDRESS_SIZE = 100;
12
+ const SEARCH_LIMIT_PER_TABLE = 5;
13
+ /** Score a match: 3=exact, 2=prefix, 1=contains */
14
+ function scoreMatch(fieldValue, keyword) {
15
+ const lower = fieldValue.toLowerCase();
16
+ if (lower === keyword) return 3;
17
+ if (lower.startsWith(keyword)) return 2;
18
+ return 1;
19
+ }
12
20
  /** Helper to safely get collection from IIndexTable */
13
21
  function getCollection(table) {
14
22
  return table.collection;
@@ -435,6 +443,109 @@ var LocalBaseIndexDB = class extends BaseIndexDB {
435
443
  paging: buildPagingResult(total, pagination, delegations.length)
436
444
  };
437
445
  }
446
+ /**
447
+ * Search entities by semantic fields (moniker, name, symbol, description)
448
+ */
449
+ search(keyword) {
450
+ const trimmed = keyword?.trim();
451
+ if (!trimmed) return [];
452
+ const lowerKw = trimmed.toLowerCase();
453
+ const typePriority = {
454
+ token: 0,
455
+ account: 1,
456
+ factory: 2,
457
+ asset: 3,
458
+ tokenFactory: 4
459
+ };
460
+ const results = [];
461
+ const tokenMatches = getCollection(this.token).chain().where((x) => {
462
+ const name$1 = x.name;
463
+ const symbol = x.symbol;
464
+ return (name$1 ? name$1.toLowerCase().includes(lowerKw) : false) || (symbol ? symbol.toLowerCase().includes(lowerKw) : false);
465
+ }).limit(SEARCH_LIMIT_PER_TABLE).data();
466
+ for (const row of tokenMatches) {
467
+ const nameScore = row.name ? scoreMatch(row.name, lowerKw) : 0;
468
+ const symbolScore = row.symbol ? scoreMatch(row.symbol, lowerKw) : 0;
469
+ const score = Math.max(nameScore, symbolScore);
470
+ const title = nameScore >= symbolScore ? row.name || row.symbol || "" : row.symbol || row.name || "";
471
+ results.push({
472
+ type: "token",
473
+ id: row.address,
474
+ title,
475
+ score,
476
+ priority: typePriority.token
477
+ });
478
+ }
479
+ const accountMatches = getCollection(this.account).chain().where((x) => {
480
+ const moniker = x.moniker;
481
+ return moniker ? moniker.toLowerCase().includes(lowerKw) : false;
482
+ }).limit(SEARCH_LIMIT_PER_TABLE).data();
483
+ for (const row of accountMatches) {
484
+ const score = scoreMatch(row.moniker, lowerKw);
485
+ results.push({
486
+ type: "account",
487
+ id: row.address,
488
+ title: row.moniker || "",
489
+ score,
490
+ priority: typePriority.account
491
+ });
492
+ }
493
+ const factoryMatches = getCollection(this.factory).chain().where((x) => {
494
+ const name$1 = x.name;
495
+ const description = x.description;
496
+ return (name$1 ? name$1.toLowerCase().includes(lowerKw) : false) || (description ? description.toLowerCase().includes(lowerKw) : false);
497
+ }).limit(SEARCH_LIMIT_PER_TABLE).data();
498
+ for (const row of factoryMatches) {
499
+ const nameScore = row.name ? scoreMatch(row.name, lowerKw) : 0;
500
+ const descScore = row.description ? scoreMatch(row.description, lowerKw) : 0;
501
+ const score = Math.max(nameScore, descScore);
502
+ results.push({
503
+ type: "factory",
504
+ id: row.address,
505
+ title: row.name || "",
506
+ score,
507
+ priority: typePriority.factory
508
+ });
509
+ }
510
+ const assetMatches = getCollection(this.asset).chain().where((x) => {
511
+ const moniker = x.moniker;
512
+ return moniker ? moniker.toLowerCase().includes(lowerKw) : false;
513
+ }).limit(SEARCH_LIMIT_PER_TABLE).data();
514
+ for (const row of assetMatches) {
515
+ const score = scoreMatch(row.moniker, lowerKw);
516
+ results.push({
517
+ type: "asset",
518
+ id: row.address,
519
+ title: row.moniker || "",
520
+ score,
521
+ priority: typePriority.asset
522
+ });
523
+ }
524
+ const tokenFactoryMatches = getCollection(this.tokenFactory).chain().where((x) => {
525
+ const name$1 = x.name;
526
+ const moniker = x.moniker;
527
+ return (name$1 ? name$1.toLowerCase().includes(lowerKw) : false) || (moniker ? moniker.toLowerCase().includes(lowerKw) : false);
528
+ }).limit(SEARCH_LIMIT_PER_TABLE).data();
529
+ for (const row of tokenFactoryMatches) {
530
+ const nameScore = row.name ? scoreMatch(row.name, lowerKw) : 0;
531
+ const monikerScore = row.moniker ? scoreMatch(row.moniker, lowerKw) : 0;
532
+ const score = Math.max(nameScore, monikerScore);
533
+ const title = nameScore >= monikerScore ? row.name || row.moniker || "" : row.moniker || row.name || "";
534
+ results.push({
535
+ type: "tokenFactory",
536
+ id: row.address,
537
+ title,
538
+ score,
539
+ priority: typePriority.tokenFactory
540
+ });
541
+ }
542
+ results.sort((a, b) => b.score - a.score || a.priority - b.priority);
543
+ return results.map(({ type, id, title }) => ({
544
+ type,
545
+ id,
546
+ title
547
+ }));
548
+ }
438
549
  };
439
550
  var base_default = LocalBaseIndexDB;
440
551
 
package/lib/db/base.cjs CHANGED
@@ -13,6 +13,14 @@ lodash_omit = require_rolldown_runtime.__toESM(lodash_omit);
13
13
  //#region src/db/base.ts
14
14
  const debug$1 = (0, debug.default)(require_package.name);
15
15
  const MAX_REQUEST_FACTORY_ADDRESS_SIZE = 100;
16
+ const SEARCH_LIMIT_PER_TABLE = 5;
17
+ /** Score a match: 3=exact, 2=prefix, 1=contains */
18
+ function scoreMatch(fieldValue, keyword) {
19
+ const lower = fieldValue.toLowerCase();
20
+ if (lower === keyword) return 3;
21
+ if (lower.startsWith(keyword)) return 2;
22
+ return 1;
23
+ }
16
24
  /** Helper to safely get collection from IIndexTable */
17
25
  function getCollection(table) {
18
26
  return table.collection;
@@ -439,6 +447,109 @@ var LocalBaseIndexDB = class extends _ocap_indexdb.BaseIndexDB {
439
447
  paging: buildPagingResult(total, pagination, delegations.length)
440
448
  };
441
449
  }
450
+ /**
451
+ * Search entities by semantic fields (moniker, name, symbol, description)
452
+ */
453
+ search(keyword) {
454
+ const trimmed = keyword?.trim();
455
+ if (!trimmed) return [];
456
+ const lowerKw = trimmed.toLowerCase();
457
+ const typePriority = {
458
+ token: 0,
459
+ account: 1,
460
+ factory: 2,
461
+ asset: 3,
462
+ tokenFactory: 4
463
+ };
464
+ const results = [];
465
+ const tokenMatches = getCollection(this.token).chain().where((x) => {
466
+ const name$1 = x.name;
467
+ const symbol = x.symbol;
468
+ return (name$1 ? name$1.toLowerCase().includes(lowerKw) : false) || (symbol ? symbol.toLowerCase().includes(lowerKw) : false);
469
+ }).limit(SEARCH_LIMIT_PER_TABLE).data();
470
+ for (const row of tokenMatches) {
471
+ const nameScore = row.name ? scoreMatch(row.name, lowerKw) : 0;
472
+ const symbolScore = row.symbol ? scoreMatch(row.symbol, lowerKw) : 0;
473
+ const score = Math.max(nameScore, symbolScore);
474
+ const title = nameScore >= symbolScore ? row.name || row.symbol || "" : row.symbol || row.name || "";
475
+ results.push({
476
+ type: "token",
477
+ id: row.address,
478
+ title,
479
+ score,
480
+ priority: typePriority.token
481
+ });
482
+ }
483
+ const accountMatches = getCollection(this.account).chain().where((x) => {
484
+ const moniker = x.moniker;
485
+ return moniker ? moniker.toLowerCase().includes(lowerKw) : false;
486
+ }).limit(SEARCH_LIMIT_PER_TABLE).data();
487
+ for (const row of accountMatches) {
488
+ const score = scoreMatch(row.moniker, lowerKw);
489
+ results.push({
490
+ type: "account",
491
+ id: row.address,
492
+ title: row.moniker || "",
493
+ score,
494
+ priority: typePriority.account
495
+ });
496
+ }
497
+ const factoryMatches = getCollection(this.factory).chain().where((x) => {
498
+ const name$1 = x.name;
499
+ const description = x.description;
500
+ return (name$1 ? name$1.toLowerCase().includes(lowerKw) : false) || (description ? description.toLowerCase().includes(lowerKw) : false);
501
+ }).limit(SEARCH_LIMIT_PER_TABLE).data();
502
+ for (const row of factoryMatches) {
503
+ const nameScore = row.name ? scoreMatch(row.name, lowerKw) : 0;
504
+ const descScore = row.description ? scoreMatch(row.description, lowerKw) : 0;
505
+ const score = Math.max(nameScore, descScore);
506
+ results.push({
507
+ type: "factory",
508
+ id: row.address,
509
+ title: row.name || "",
510
+ score,
511
+ priority: typePriority.factory
512
+ });
513
+ }
514
+ const assetMatches = getCollection(this.asset).chain().where((x) => {
515
+ const moniker = x.moniker;
516
+ return moniker ? moniker.toLowerCase().includes(lowerKw) : false;
517
+ }).limit(SEARCH_LIMIT_PER_TABLE).data();
518
+ for (const row of assetMatches) {
519
+ const score = scoreMatch(row.moniker, lowerKw);
520
+ results.push({
521
+ type: "asset",
522
+ id: row.address,
523
+ title: row.moniker || "",
524
+ score,
525
+ priority: typePriority.asset
526
+ });
527
+ }
528
+ const tokenFactoryMatches = getCollection(this.tokenFactory).chain().where((x) => {
529
+ const name$1 = x.name;
530
+ const moniker = x.moniker;
531
+ return (name$1 ? name$1.toLowerCase().includes(lowerKw) : false) || (moniker ? moniker.toLowerCase().includes(lowerKw) : false);
532
+ }).limit(SEARCH_LIMIT_PER_TABLE).data();
533
+ for (const row of tokenFactoryMatches) {
534
+ const nameScore = row.name ? scoreMatch(row.name, lowerKw) : 0;
535
+ const monikerScore = row.moniker ? scoreMatch(row.moniker, lowerKw) : 0;
536
+ const score = Math.max(nameScore, monikerScore);
537
+ const title = nameScore >= monikerScore ? row.name || row.moniker || "" : row.moniker || row.name || "";
538
+ results.push({
539
+ type: "tokenFactory",
540
+ id: row.address,
541
+ title,
542
+ score,
543
+ priority: typePriority.tokenFactory
544
+ });
545
+ }
546
+ results.sort((a, b) => b.score - a.score || a.priority - b.priority);
547
+ return results.map(({ type, id, title }) => ({
548
+ type,
549
+ id,
550
+ title
551
+ }));
552
+ }
442
553
  };
443
554
  var base_default = LocalBaseIndexDB;
444
555
 
package/lib/db/base.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { BaseIndexDB } from "@ocap/indexdb";
2
- import { IIndexDB, IListAccountsResult, IListAssetsResult, IListDelegationsResult, IListFactoriesResult, IListRollupBlocksResult, IListRollupValidatorsResult, IListRollupsResult, IListStakesResult, IListTokenFactoriesResult, IListTokensResult, IListTransactionsResult, TRequestListAssets, TRequestListDelegations, TRequestListFactories, TRequestListRollupBlocks, TRequestListRollupValidators, TRequestListRollups, TRequestListStakes, TRequestListTokenFactories, TRequestListTokens, TRequestListTopAccounts, TRequestListTransactions } from "@ocap/types";
2
+ import { IIndexDB, IListAccountsResult, IListAssetsResult, IListDelegationsResult, IListFactoriesResult, IListRollupBlocksResult, IListRollupValidatorsResult, IListRollupsResult, IListStakesResult, IListTokenFactoriesResult, IListTokensResult, IListTransactionsResult, TRequestListAssets, TRequestListDelegations, TRequestListFactories, TRequestListRollupBlocks, TRequestListRollupValidators, TRequestListRollups, TRequestListStakes, TRequestListTokenFactories, TRequestListTokens, TRequestListTopAccounts, TRequestListTransactions, TSearchResult } from "@ocap/types";
3
3
 
4
4
  //#region src/db/base.d.ts
5
5
  declare class LocalBaseIndexDB extends BaseIndexDB implements IIndexDB {
@@ -15,6 +15,10 @@ declare class LocalBaseIndexDB extends BaseIndexDB implements IIndexDB {
15
15
  listRollupBlocks(params?: Partial<TRequestListRollupBlocks>): IListRollupBlocksResult;
16
16
  listRollupValidators(params?: Partial<TRequestListRollupValidators>): IListRollupValidatorsResult;
17
17
  listDelegations(params?: Partial<TRequestListDelegations>): IListDelegationsResult;
18
+ /**
19
+ * Search entities by semantic fields (moniker, name, symbol, description)
20
+ */
21
+ search(keyword: string): TSearchResult[];
18
22
  }
19
23
  //#endregion
20
24
  export { LocalBaseIndexDB as default };
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.14",
4
+ "version": "1.29.15",
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.14",
18
+ "@ocap/indexdb-test": "1.29.15",
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.14",
83
- "@ocap/indexdb": "1.29.14",
84
- "@ocap/types": "1.29.14",
85
- "@ocap/util": "1.29.14",
82
+ "@arcblock/did": "1.29.15",
83
+ "@ocap/indexdb": "1.29.15",
84
+ "@ocap/types": "1.29.15",
85
+ "@ocap/util": "1.29.15",
86
86
  "debug": "^4.4.3",
87
87
  "lodash": "^4.17.23",
88
88
  "lokijs": "^1.5.12"