@ocap/indexdb 1.30.12 → 1.30.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/esm/main.d.mts +2 -1
- package/esm/main.mjs +2 -1
- package/esm/search-result.d.mts +16 -0
- package/esm/search-result.mjs +193 -0
- package/lib/main.cjs +2 -0
- package/lib/main.d.cts +2 -1
- package/lib/search-result.cjs +200 -0
- package/lib/search-result.d.cts +16 -0
- package/package.json +4 -4
package/esm/main.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import BaseIndexDB from "./db.mjs";
|
|
2
2
|
import BaseIndex from "./index.mjs";
|
|
3
|
+
import { SearchResultFormatOptions, formatSearchResult } from "./search-result.mjs";
|
|
3
4
|
import { DelegationContext, FactoryContext, FormatPaginationParams, FormattedPagination, IndexDBForTx, PagingInput, RollupBlockContext, RollupContext, TokenFactoryContext, TokenStateInfo, TokenWithBalance, TxData, createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, formatDelegationAfterRead, formatNextPagination, formatPagination, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, isDefaultTokenChanged, parseDateTime } from "./util.mjs";
|
|
4
|
-
export { BaseIndex, BaseIndexDB, DelegationContext, FactoryContext, FormatPaginationParams, FormattedPagination, IndexDBForTx, PagingInput, RollupBlockContext, RollupContext, TokenFactoryContext, TokenStateInfo, TokenWithBalance, TxData, createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, formatDelegationAfterRead, formatNextPagination, formatPagination, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, isDefaultTokenChanged, parseDateTime };
|
|
5
|
+
export { BaseIndex, BaseIndexDB, DelegationContext, FactoryContext, FormatPaginationParams, FormattedPagination, IndexDBForTx, PagingInput, RollupBlockContext, RollupContext, type SearchResultFormatOptions, TokenFactoryContext, TokenStateInfo, TokenWithBalance, TxData, createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, formatDelegationAfterRead, formatNextPagination, formatPagination, formatSearchResult, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, isDefaultTokenChanged, parseDateTime };
|
package/esm/main.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import db_default from "./db.mjs";
|
|
2
2
|
import src_default from "./index.mjs";
|
|
3
|
+
import { formatSearchResult } from "./search-result.mjs";
|
|
3
4
|
import { createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, formatDelegationAfterRead, formatNextPagination, formatPagination, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, isDefaultTokenChanged, parseDateTime } from "./util.mjs";
|
|
4
5
|
|
|
5
|
-
export { src_default as BaseIndex, db_default as BaseIndexDB, createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, formatDelegationAfterRead, formatNextPagination, formatPagination, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, isDefaultTokenChanged, parseDateTime };
|
|
6
|
+
export { src_default as BaseIndex, db_default as BaseIndexDB, createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, formatDelegationAfterRead, formatNextPagination, formatPagination, formatSearchResult, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, isDefaultTokenChanged, parseDateTime };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TSearchResult } from "@ocap/types";
|
|
2
|
+
|
|
3
|
+
//#region src/search-result.d.ts
|
|
4
|
+
type Row = Record<string, unknown>;
|
|
5
|
+
interface SearchResultFormatOptions {
|
|
6
|
+
id?: string;
|
|
7
|
+
}
|
|
8
|
+
declare const compactParts: (parts: unknown[]) => string;
|
|
9
|
+
declare const formatSearchTitle: (type: string, row: Row, id?: string) => string;
|
|
10
|
+
declare const formatSearchSubtitle: (type: string, row: Row, id?: string) => string;
|
|
11
|
+
declare const formatSearchDescription: (type: string, row: Row) => string;
|
|
12
|
+
declare const formatSearchTags: (type: string, row: Row) => string[];
|
|
13
|
+
declare const formatSearchTimestamp: (type: string, row: Row) => string;
|
|
14
|
+
declare const formatSearchResult: (type: string, row: Row, options?: SearchResultFormatOptions) => TSearchResult;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { SearchResultFormatOptions, compactParts, formatSearchDescription, formatSearchResult, formatSearchSubtitle, formatSearchTags, formatSearchTimestamp, formatSearchTitle };
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
//#region src/search-result.ts
|
|
2
|
+
const ENTITY_LABELS = {
|
|
3
|
+
tx: "Transaction",
|
|
4
|
+
rollupBlock: "Rollup Block",
|
|
5
|
+
account: "Account",
|
|
6
|
+
asset: "Asset",
|
|
7
|
+
token: "Token",
|
|
8
|
+
factory: "Factory",
|
|
9
|
+
tokenFactory: "Token Factory",
|
|
10
|
+
stake: "Stake",
|
|
11
|
+
delegation: "Delegation",
|
|
12
|
+
rollup: "Rollup"
|
|
13
|
+
};
|
|
14
|
+
const getString = (row, ...keys) => {
|
|
15
|
+
for (const key of keys) {
|
|
16
|
+
const value = row[key];
|
|
17
|
+
if (typeof value === "string" && value.length > 0) return value;
|
|
18
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
19
|
+
}
|
|
20
|
+
return "";
|
|
21
|
+
};
|
|
22
|
+
const getNumber = (row, ...keys) => {
|
|
23
|
+
for (const key of keys) {
|
|
24
|
+
const value = row[key];
|
|
25
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
26
|
+
if (typeof value === "string" && value.trim() !== "" && Number.isFinite(Number(value))) return Number(value);
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
};
|
|
30
|
+
const getArray = (row, ...keys) => {
|
|
31
|
+
for (const key of keys) {
|
|
32
|
+
const value = row[key];
|
|
33
|
+
if (Array.isArray(value)) return value.filter((item) => typeof item === "string" && item.length > 0);
|
|
34
|
+
if (typeof value === "string" && value.length > 0) try {
|
|
35
|
+
const parsed = JSON.parse(value);
|
|
36
|
+
if (Array.isArray(parsed)) return parsed.filter((item) => typeof item === "string" && item.length > 0);
|
|
37
|
+
} catch {
|
|
38
|
+
return [value];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return [];
|
|
42
|
+
};
|
|
43
|
+
const compactParts = (parts) => parts.map((part) => {
|
|
44
|
+
if (typeof part === "string") return part.trim();
|
|
45
|
+
if (typeof part === "number" || typeof part === "boolean") return String(part);
|
|
46
|
+
return "";
|
|
47
|
+
}).filter(Boolean).join(" - ");
|
|
48
|
+
const getEntityId = (type, row, options) => {
|
|
49
|
+
if (options.id) return options.id;
|
|
50
|
+
if (type === "tx" || type === "rollupBlock") return getString(row, "hash");
|
|
51
|
+
return getString(row, "address", "id");
|
|
52
|
+
};
|
|
53
|
+
const formatTokenTitle = (row, fallback) => {
|
|
54
|
+
const name = getString(row, "name");
|
|
55
|
+
const symbol = getString(row, "symbol");
|
|
56
|
+
if (name && symbol) return `${name} (${symbol})`;
|
|
57
|
+
return name || symbol || fallback;
|
|
58
|
+
};
|
|
59
|
+
const formatSearchTitle = (type, row, id = "") => {
|
|
60
|
+
const explicitTitle = getString(row, "title");
|
|
61
|
+
if (explicitTitle) return explicitTitle;
|
|
62
|
+
const fallback = id || getString(row, "address", "hash", "id") || ENTITY_LABELS[type] || type;
|
|
63
|
+
switch (type) {
|
|
64
|
+
case "tx": return getString(row, "type") || "Transaction";
|
|
65
|
+
case "rollupBlock": {
|
|
66
|
+
const height = getString(row, "height");
|
|
67
|
+
return height ? `Rollup Block #${height}` : "Rollup Block";
|
|
68
|
+
}
|
|
69
|
+
case "account": return getString(row, "moniker") || fallback;
|
|
70
|
+
case "asset": return getString(row, "moniker") || fallback;
|
|
71
|
+
case "token": return formatTokenTitle(row, fallback);
|
|
72
|
+
case "factory": return getString(row, "name") || fallback;
|
|
73
|
+
case "tokenFactory": return getString(row, "name", "moniker") || fallback;
|
|
74
|
+
case "stake": return getString(row, "message") || "Stake";
|
|
75
|
+
case "delegation": return "Delegation";
|
|
76
|
+
case "rollup": return getString(row, "moniker", "name") || "Rollup";
|
|
77
|
+
default: return getString(row, "title") || fallback;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const formatSearchSubtitle = (type, row, id = "") => {
|
|
81
|
+
if (type === "delegation") {
|
|
82
|
+
const from = getString(row, "from", "from_");
|
|
83
|
+
const to = getString(row, "to", "to_");
|
|
84
|
+
return compactParts([from && to ? `${from} -> ${to}` : "", id]);
|
|
85
|
+
}
|
|
86
|
+
return id || getString(row, "address", "hash", "id");
|
|
87
|
+
};
|
|
88
|
+
const formatSearchDescription = (type, row) => {
|
|
89
|
+
switch (type) {
|
|
90
|
+
case "tx": {
|
|
91
|
+
const sender = getString(row, "sender");
|
|
92
|
+
const receiver = getString(row, "receiver");
|
|
93
|
+
const validity = typeof row.valid === "boolean" ? row.valid ? "Valid" : "Invalid" : typeof row.valid === "number" ? row.valid ? "Valid" : "Invalid" : "";
|
|
94
|
+
const height = getString(row, "height");
|
|
95
|
+
return compactParts([
|
|
96
|
+
sender && receiver ? `${sender} -> ${receiver}` : "",
|
|
97
|
+
validity,
|
|
98
|
+
height ? `Height ${height}` : ""
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
101
|
+
case "rollupBlock": {
|
|
102
|
+
const txs = getArray(row, "txs");
|
|
103
|
+
return compactParts([
|
|
104
|
+
getString(row, "rollup"),
|
|
105
|
+
getString(row, "proposer"),
|
|
106
|
+
txs.length ? `${txs.length} txs` : ""
|
|
107
|
+
]);
|
|
108
|
+
}
|
|
109
|
+
case "account": {
|
|
110
|
+
const numTxs = getNumber(row, "numTxs");
|
|
111
|
+
const numAssets = getNumber(row, "numAssets");
|
|
112
|
+
return compactParts([
|
|
113
|
+
numTxs !== null ? `${numTxs} txs` : "",
|
|
114
|
+
numAssets !== null ? `${numAssets} assets` : "",
|
|
115
|
+
getString(row, "balance") ? `Balance ${getString(row, "balance")}` : ""
|
|
116
|
+
]);
|
|
117
|
+
}
|
|
118
|
+
case "asset": return compactParts([getString(row, "owner") ? `Owner ${getString(row, "owner")}` : "", getString(row, "parent") ? `Factory ${getString(row, "parent")}` : ""]);
|
|
119
|
+
case "token": return compactParts([getString(row, "totalSupply") ? `Supply ${getString(row, "totalSupply")}` : "", getString(row, "issuer") ? `Issuer ${getString(row, "issuer")}` : ""]);
|
|
120
|
+
case "factory": {
|
|
121
|
+
const minted = getNumber(row, "numMinted");
|
|
122
|
+
const limit = getNumber(row, "limit", "limit_");
|
|
123
|
+
return compactParts([
|
|
124
|
+
getString(row, "owner") ? `Owner ${getString(row, "owner")}` : "",
|
|
125
|
+
minted !== null ? `${minted} minted` : "",
|
|
126
|
+
limit !== null ? `Limit ${limit}` : ""
|
|
127
|
+
]);
|
|
128
|
+
}
|
|
129
|
+
case "tokenFactory": return compactParts([
|
|
130
|
+
getString(row, "status") ? `Status ${getString(row, "status")}` : "",
|
|
131
|
+
getString(row, "currentSupply") ? `Supply ${getString(row, "currentSupply")}` : "",
|
|
132
|
+
getString(row, "reserveBalance") ? `Reserve ${getString(row, "reserveBalance")}` : ""
|
|
133
|
+
]);
|
|
134
|
+
case "stake": {
|
|
135
|
+
const sender = getString(row, "sender");
|
|
136
|
+
const receiver = getString(row, "receiver");
|
|
137
|
+
const revocable = typeof row.revocable === "boolean" ? row.revocable ? "Revocable" : "Irrevocable" : typeof row.revocable === "number" ? row.revocable ? "Revocable" : "Irrevocable" : "";
|
|
138
|
+
return compactParts([sender && receiver ? `${sender} -> ${receiver}` : "", revocable]);
|
|
139
|
+
}
|
|
140
|
+
case "delegation": {
|
|
141
|
+
const from = getString(row, "from", "from_");
|
|
142
|
+
const to = getString(row, "to", "to_");
|
|
143
|
+
return compactParts([from && to ? `${from} -> ${to}` : "", getString(row, "validUntil") ? `Valid until ${getString(row, "validUntil")}` : ""]);
|
|
144
|
+
}
|
|
145
|
+
case "rollup": return compactParts([
|
|
146
|
+
getString(row, "tokenAddress") ? `Token ${getString(row, "tokenAddress")}` : "",
|
|
147
|
+
getString(row, "totalDepositAmount") ? `Deposits ${getString(row, "totalDepositAmount")}` : "",
|
|
148
|
+
getString(row, "totalWithdrawAmount") ? `Withdrawals ${getString(row, "totalWithdrawAmount")}` : ""
|
|
149
|
+
]);
|
|
150
|
+
default: return getString(row, "description");
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
const formatSearchTags = (type, row) => {
|
|
154
|
+
const tags = /* @__PURE__ */ new Set();
|
|
155
|
+
const label = ENTITY_LABELS[type];
|
|
156
|
+
if (label) tags.add(label);
|
|
157
|
+
if (type === "tx") {
|
|
158
|
+
const txType = getString(row, "type");
|
|
159
|
+
if (txType) tags.add(txType);
|
|
160
|
+
if (typeof row.valid === "boolean") tags.add(row.valid ? "Valid" : "Invalid");
|
|
161
|
+
if (typeof row.valid === "number") tags.add(row.valid ? "Valid" : "Invalid");
|
|
162
|
+
}
|
|
163
|
+
if (type === "asset") for (const tag of getArray(row, "tags")) tags.add(tag);
|
|
164
|
+
if (type === "token") {
|
|
165
|
+
const tokenType = getString(row, "type");
|
|
166
|
+
if (tokenType) tags.add(tokenType);
|
|
167
|
+
}
|
|
168
|
+
if (type === "tokenFactory") {
|
|
169
|
+
const status = getString(row, "status");
|
|
170
|
+
if (status) tags.add(status);
|
|
171
|
+
}
|
|
172
|
+
return Array.from(tags);
|
|
173
|
+
};
|
|
174
|
+
const formatSearchTimestamp = (type, row) => {
|
|
175
|
+
if (type === "tx") return getString(row, "time");
|
|
176
|
+
if (type === "asset") return getString(row, "consumedTime", "renaissanceTime", "genesisTime");
|
|
177
|
+
return getString(row, "renaissanceTime", "genesisTime", "time");
|
|
178
|
+
};
|
|
179
|
+
const formatSearchResult = (type, row, options = {}) => {
|
|
180
|
+
const id = getEntityId(type, row, options);
|
|
181
|
+
return {
|
|
182
|
+
type,
|
|
183
|
+
id,
|
|
184
|
+
title: formatSearchTitle(type, row, id),
|
|
185
|
+
subtitle: formatSearchSubtitle(type, row, id),
|
|
186
|
+
description: formatSearchDescription(type, row),
|
|
187
|
+
tags: formatSearchTags(type, row),
|
|
188
|
+
timestamp: formatSearchTimestamp(type, row)
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
//#endregion
|
|
193
|
+
export { compactParts, formatSearchDescription, formatSearchResult, formatSearchSubtitle, formatSearchTags, formatSearchTimestamp, formatSearchTitle };
|
package/lib/main.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_db = require('./db.cjs');
|
|
2
2
|
const require_index = require('./index.cjs');
|
|
3
|
+
const require_search_result = require('./search-result.cjs');
|
|
3
4
|
const require_util = require('./util.cjs');
|
|
4
5
|
|
|
5
6
|
exports.BaseIndex = require_index.default;
|
|
@@ -18,6 +19,7 @@ exports.createIndexedTransaction = require_util.createIndexedTransaction;
|
|
|
18
19
|
exports.formatDelegationAfterRead = require_util.formatDelegationAfterRead;
|
|
19
20
|
exports.formatNextPagination = require_util.formatNextPagination;
|
|
20
21
|
exports.formatPagination = require_util.formatPagination;
|
|
22
|
+
exports.formatSearchResult = require_search_result.formatSearchResult;
|
|
21
23
|
exports.formatTokenMeta = require_util.formatTokenMeta;
|
|
22
24
|
exports.formatTxAfterRead = require_util.formatTxAfterRead;
|
|
23
25
|
exports.formatTxBeforeInsert = require_util.formatTxBeforeInsert;
|
package/lib/main.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import BaseIndexDB from "./db.cjs";
|
|
2
2
|
import BaseIndex from "./index.cjs";
|
|
3
|
+
import { SearchResultFormatOptions, formatSearchResult } from "./search-result.cjs";
|
|
3
4
|
import { DelegationContext, FactoryContext, FormatPaginationParams, FormattedPagination, IndexDBForTx, PagingInput, RollupBlockContext, RollupContext, TokenFactoryContext, TokenStateInfo, TokenWithBalance, TxData, createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, formatDelegationAfterRead, formatNextPagination, formatPagination, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, isDefaultTokenChanged, parseDateTime } from "./util.cjs";
|
|
4
|
-
export { BaseIndex, BaseIndexDB, DelegationContext, FactoryContext, FormatPaginationParams, FormattedPagination, IndexDBForTx, PagingInput, RollupBlockContext, RollupContext, TokenFactoryContext, TokenStateInfo, TokenWithBalance, TxData, createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, formatDelegationAfterRead, formatNextPagination, formatPagination, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, isDefaultTokenChanged, parseDateTime };
|
|
5
|
+
export { BaseIndex, BaseIndexDB, DelegationContext, FactoryContext, FormatPaginationParams, FormattedPagination, IndexDBForTx, PagingInput, RollupBlockContext, RollupContext, type SearchResultFormatOptions, TokenFactoryContext, TokenStateInfo, TokenWithBalance, TxData, createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, formatDelegationAfterRead, formatNextPagination, formatPagination, formatSearchResult, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, isDefaultTokenChanged, parseDateTime };
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/search-result.ts
|
|
3
|
+
const ENTITY_LABELS = {
|
|
4
|
+
tx: "Transaction",
|
|
5
|
+
rollupBlock: "Rollup Block",
|
|
6
|
+
account: "Account",
|
|
7
|
+
asset: "Asset",
|
|
8
|
+
token: "Token",
|
|
9
|
+
factory: "Factory",
|
|
10
|
+
tokenFactory: "Token Factory",
|
|
11
|
+
stake: "Stake",
|
|
12
|
+
delegation: "Delegation",
|
|
13
|
+
rollup: "Rollup"
|
|
14
|
+
};
|
|
15
|
+
const getString = (row, ...keys) => {
|
|
16
|
+
for (const key of keys) {
|
|
17
|
+
const value = row[key];
|
|
18
|
+
if (typeof value === "string" && value.length > 0) return value;
|
|
19
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
20
|
+
}
|
|
21
|
+
return "";
|
|
22
|
+
};
|
|
23
|
+
const getNumber = (row, ...keys) => {
|
|
24
|
+
for (const key of keys) {
|
|
25
|
+
const value = row[key];
|
|
26
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
27
|
+
if (typeof value === "string" && value.trim() !== "" && Number.isFinite(Number(value))) return Number(value);
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
};
|
|
31
|
+
const getArray = (row, ...keys) => {
|
|
32
|
+
for (const key of keys) {
|
|
33
|
+
const value = row[key];
|
|
34
|
+
if (Array.isArray(value)) return value.filter((item) => typeof item === "string" && item.length > 0);
|
|
35
|
+
if (typeof value === "string" && value.length > 0) try {
|
|
36
|
+
const parsed = JSON.parse(value);
|
|
37
|
+
if (Array.isArray(parsed)) return parsed.filter((item) => typeof item === "string" && item.length > 0);
|
|
38
|
+
} catch {
|
|
39
|
+
return [value];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return [];
|
|
43
|
+
};
|
|
44
|
+
const compactParts = (parts) => parts.map((part) => {
|
|
45
|
+
if (typeof part === "string") return part.trim();
|
|
46
|
+
if (typeof part === "number" || typeof part === "boolean") return String(part);
|
|
47
|
+
return "";
|
|
48
|
+
}).filter(Boolean).join(" - ");
|
|
49
|
+
const getEntityId = (type, row, options) => {
|
|
50
|
+
if (options.id) return options.id;
|
|
51
|
+
if (type === "tx" || type === "rollupBlock") return getString(row, "hash");
|
|
52
|
+
return getString(row, "address", "id");
|
|
53
|
+
};
|
|
54
|
+
const formatTokenTitle = (row, fallback) => {
|
|
55
|
+
const name = getString(row, "name");
|
|
56
|
+
const symbol = getString(row, "symbol");
|
|
57
|
+
if (name && symbol) return `${name} (${symbol})`;
|
|
58
|
+
return name || symbol || fallback;
|
|
59
|
+
};
|
|
60
|
+
const formatSearchTitle = (type, row, id = "") => {
|
|
61
|
+
const explicitTitle = getString(row, "title");
|
|
62
|
+
if (explicitTitle) return explicitTitle;
|
|
63
|
+
const fallback = id || getString(row, "address", "hash", "id") || ENTITY_LABELS[type] || type;
|
|
64
|
+
switch (type) {
|
|
65
|
+
case "tx": return getString(row, "type") || "Transaction";
|
|
66
|
+
case "rollupBlock": {
|
|
67
|
+
const height = getString(row, "height");
|
|
68
|
+
return height ? `Rollup Block #${height}` : "Rollup Block";
|
|
69
|
+
}
|
|
70
|
+
case "account": return getString(row, "moniker") || fallback;
|
|
71
|
+
case "asset": return getString(row, "moniker") || fallback;
|
|
72
|
+
case "token": return formatTokenTitle(row, fallback);
|
|
73
|
+
case "factory": return getString(row, "name") || fallback;
|
|
74
|
+
case "tokenFactory": return getString(row, "name", "moniker") || fallback;
|
|
75
|
+
case "stake": return getString(row, "message") || "Stake";
|
|
76
|
+
case "delegation": return "Delegation";
|
|
77
|
+
case "rollup": return getString(row, "moniker", "name") || "Rollup";
|
|
78
|
+
default: return getString(row, "title") || fallback;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const formatSearchSubtitle = (type, row, id = "") => {
|
|
82
|
+
if (type === "delegation") {
|
|
83
|
+
const from = getString(row, "from", "from_");
|
|
84
|
+
const to = getString(row, "to", "to_");
|
|
85
|
+
return compactParts([from && to ? `${from} -> ${to}` : "", id]);
|
|
86
|
+
}
|
|
87
|
+
return id || getString(row, "address", "hash", "id");
|
|
88
|
+
};
|
|
89
|
+
const formatSearchDescription = (type, row) => {
|
|
90
|
+
switch (type) {
|
|
91
|
+
case "tx": {
|
|
92
|
+
const sender = getString(row, "sender");
|
|
93
|
+
const receiver = getString(row, "receiver");
|
|
94
|
+
const validity = typeof row.valid === "boolean" ? row.valid ? "Valid" : "Invalid" : typeof row.valid === "number" ? row.valid ? "Valid" : "Invalid" : "";
|
|
95
|
+
const height = getString(row, "height");
|
|
96
|
+
return compactParts([
|
|
97
|
+
sender && receiver ? `${sender} -> ${receiver}` : "",
|
|
98
|
+
validity,
|
|
99
|
+
height ? `Height ${height}` : ""
|
|
100
|
+
]);
|
|
101
|
+
}
|
|
102
|
+
case "rollupBlock": {
|
|
103
|
+
const txs = getArray(row, "txs");
|
|
104
|
+
return compactParts([
|
|
105
|
+
getString(row, "rollup"),
|
|
106
|
+
getString(row, "proposer"),
|
|
107
|
+
txs.length ? `${txs.length} txs` : ""
|
|
108
|
+
]);
|
|
109
|
+
}
|
|
110
|
+
case "account": {
|
|
111
|
+
const numTxs = getNumber(row, "numTxs");
|
|
112
|
+
const numAssets = getNumber(row, "numAssets");
|
|
113
|
+
return compactParts([
|
|
114
|
+
numTxs !== null ? `${numTxs} txs` : "",
|
|
115
|
+
numAssets !== null ? `${numAssets} assets` : "",
|
|
116
|
+
getString(row, "balance") ? `Balance ${getString(row, "balance")}` : ""
|
|
117
|
+
]);
|
|
118
|
+
}
|
|
119
|
+
case "asset": return compactParts([getString(row, "owner") ? `Owner ${getString(row, "owner")}` : "", getString(row, "parent") ? `Factory ${getString(row, "parent")}` : ""]);
|
|
120
|
+
case "token": return compactParts([getString(row, "totalSupply") ? `Supply ${getString(row, "totalSupply")}` : "", getString(row, "issuer") ? `Issuer ${getString(row, "issuer")}` : ""]);
|
|
121
|
+
case "factory": {
|
|
122
|
+
const minted = getNumber(row, "numMinted");
|
|
123
|
+
const limit = getNumber(row, "limit", "limit_");
|
|
124
|
+
return compactParts([
|
|
125
|
+
getString(row, "owner") ? `Owner ${getString(row, "owner")}` : "",
|
|
126
|
+
minted !== null ? `${minted} minted` : "",
|
|
127
|
+
limit !== null ? `Limit ${limit}` : ""
|
|
128
|
+
]);
|
|
129
|
+
}
|
|
130
|
+
case "tokenFactory": return compactParts([
|
|
131
|
+
getString(row, "status") ? `Status ${getString(row, "status")}` : "",
|
|
132
|
+
getString(row, "currentSupply") ? `Supply ${getString(row, "currentSupply")}` : "",
|
|
133
|
+
getString(row, "reserveBalance") ? `Reserve ${getString(row, "reserveBalance")}` : ""
|
|
134
|
+
]);
|
|
135
|
+
case "stake": {
|
|
136
|
+
const sender = getString(row, "sender");
|
|
137
|
+
const receiver = getString(row, "receiver");
|
|
138
|
+
const revocable = typeof row.revocable === "boolean" ? row.revocable ? "Revocable" : "Irrevocable" : typeof row.revocable === "number" ? row.revocable ? "Revocable" : "Irrevocable" : "";
|
|
139
|
+
return compactParts([sender && receiver ? `${sender} -> ${receiver}` : "", revocable]);
|
|
140
|
+
}
|
|
141
|
+
case "delegation": {
|
|
142
|
+
const from = getString(row, "from", "from_");
|
|
143
|
+
const to = getString(row, "to", "to_");
|
|
144
|
+
return compactParts([from && to ? `${from} -> ${to}` : "", getString(row, "validUntil") ? `Valid until ${getString(row, "validUntil")}` : ""]);
|
|
145
|
+
}
|
|
146
|
+
case "rollup": return compactParts([
|
|
147
|
+
getString(row, "tokenAddress") ? `Token ${getString(row, "tokenAddress")}` : "",
|
|
148
|
+
getString(row, "totalDepositAmount") ? `Deposits ${getString(row, "totalDepositAmount")}` : "",
|
|
149
|
+
getString(row, "totalWithdrawAmount") ? `Withdrawals ${getString(row, "totalWithdrawAmount")}` : ""
|
|
150
|
+
]);
|
|
151
|
+
default: return getString(row, "description");
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
const formatSearchTags = (type, row) => {
|
|
155
|
+
const tags = /* @__PURE__ */ new Set();
|
|
156
|
+
const label = ENTITY_LABELS[type];
|
|
157
|
+
if (label) tags.add(label);
|
|
158
|
+
if (type === "tx") {
|
|
159
|
+
const txType = getString(row, "type");
|
|
160
|
+
if (txType) tags.add(txType);
|
|
161
|
+
if (typeof row.valid === "boolean") tags.add(row.valid ? "Valid" : "Invalid");
|
|
162
|
+
if (typeof row.valid === "number") tags.add(row.valid ? "Valid" : "Invalid");
|
|
163
|
+
}
|
|
164
|
+
if (type === "asset") for (const tag of getArray(row, "tags")) tags.add(tag);
|
|
165
|
+
if (type === "token") {
|
|
166
|
+
const tokenType = getString(row, "type");
|
|
167
|
+
if (tokenType) tags.add(tokenType);
|
|
168
|
+
}
|
|
169
|
+
if (type === "tokenFactory") {
|
|
170
|
+
const status = getString(row, "status");
|
|
171
|
+
if (status) tags.add(status);
|
|
172
|
+
}
|
|
173
|
+
return Array.from(tags);
|
|
174
|
+
};
|
|
175
|
+
const formatSearchTimestamp = (type, row) => {
|
|
176
|
+
if (type === "tx") return getString(row, "time");
|
|
177
|
+
if (type === "asset") return getString(row, "consumedTime", "renaissanceTime", "genesisTime");
|
|
178
|
+
return getString(row, "renaissanceTime", "genesisTime", "time");
|
|
179
|
+
};
|
|
180
|
+
const formatSearchResult = (type, row, options = {}) => {
|
|
181
|
+
const id = getEntityId(type, row, options);
|
|
182
|
+
return {
|
|
183
|
+
type,
|
|
184
|
+
id,
|
|
185
|
+
title: formatSearchTitle(type, row, id),
|
|
186
|
+
subtitle: formatSearchSubtitle(type, row, id),
|
|
187
|
+
description: formatSearchDescription(type, row),
|
|
188
|
+
tags: formatSearchTags(type, row),
|
|
189
|
+
timestamp: formatSearchTimestamp(type, row)
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
//#endregion
|
|
194
|
+
exports.compactParts = compactParts;
|
|
195
|
+
exports.formatSearchDescription = formatSearchDescription;
|
|
196
|
+
exports.formatSearchResult = formatSearchResult;
|
|
197
|
+
exports.formatSearchSubtitle = formatSearchSubtitle;
|
|
198
|
+
exports.formatSearchTags = formatSearchTags;
|
|
199
|
+
exports.formatSearchTimestamp = formatSearchTimestamp;
|
|
200
|
+
exports.formatSearchTitle = formatSearchTitle;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TSearchResult } from "@ocap/types";
|
|
2
|
+
|
|
3
|
+
//#region src/search-result.d.ts
|
|
4
|
+
type Row = Record<string, unknown>;
|
|
5
|
+
interface SearchResultFormatOptions {
|
|
6
|
+
id?: string;
|
|
7
|
+
}
|
|
8
|
+
declare const compactParts: (parts: unknown[]) => string;
|
|
9
|
+
declare const formatSearchTitle: (type: string, row: Row, id?: string) => string;
|
|
10
|
+
declare const formatSearchSubtitle: (type: string, row: Row, id?: string) => string;
|
|
11
|
+
declare const formatSearchDescription: (type: string, row: Row) => string;
|
|
12
|
+
declare const formatSearchTags: (type: string, row: Row) => string[];
|
|
13
|
+
declare const formatSearchTimestamp: (type: string, row: Row) => string;
|
|
14
|
+
declare const formatSearchResult: (type: string, row: Row, options?: SearchResultFormatOptions) => TSearchResult;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { SearchResultFormatOptions, compactParts, formatSearchDescription, formatSearchResult, formatSearchSubtitle, formatSearchTags, formatSearchTimestamp, formatSearchTitle };
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.30.
|
|
6
|
+
"version": "1.30.13",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"description": "Defines the basic interface for OCAP IndexDB",
|
|
9
9
|
"main": "./lib/main.cjs",
|
|
@@ -52,9 +52,9 @@
|
|
|
52
52
|
"tsdown": "^0.18.4"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@ocap/state": "1.30.
|
|
56
|
-
"@ocap/types": "1.30.
|
|
57
|
-
"@ocap/util": "1.30.
|
|
55
|
+
"@ocap/state": "1.30.13",
|
|
56
|
+
"@ocap/types": "1.30.13",
|
|
57
|
+
"@ocap/util": "1.30.13",
|
|
58
58
|
"kareem": "^2.4.1",
|
|
59
59
|
"lodash": "^4.17.23"
|
|
60
60
|
}
|