global: snapshot

This commit is contained in:
nym21
2026-03-12 01:30:50 +01:00
parent 71dd7e9852
commit b97f32f86e
51 changed files with 916 additions and 652 deletions
+26 -25
View File
@@ -48,7 +48,6 @@
/**
* @typedef {Object} AddressTxidsParam
* @property {(Txid|null)=} afterTxid - Txid to paginate from (return transactions before this one)
* @property {number=} limit - Maximum number of results to return. Defaults to 25 if not specified.
*/
/**
* Address validation result
@@ -603,13 +602,17 @@
* @typedef {Object} PaginatedMetrics
* @property {number} currentPage - Current page number (0-indexed)
* @property {number} maxPage - Maximum valid page index (0-indexed)
* @property {string[]} metrics - List of metric names (max 1000 per page)
* @property {number} totalCount - Total number of metrics
* @property {number} perPage - Results per page
* @property {boolean} hasMore - Whether more pages are available after the current one
* @property {string[]} metrics - List of metric names
*/
/**
* Pagination parameters for paginated API endpoints
*
* @typedef {Object} Pagination
* @property {?number=} page - Pagination index
* @property {?number=} perPage - Results per page (default: 1000, max: 1000)
*/
/**
* Block counts for different time periods
@@ -8732,23 +8735,21 @@ class BrkClient extends BrkClientBase {
}
/**
* Address transaction IDs
* Address transactions
*
* Get transaction IDs for an address, newest first. Use after_txid for pagination.
* Get transaction history for an address, sorted with newest first. Returns up to 50 mempool transactions plus the first 25 confirmed transactions. Use ?after_txid=<txid> for pagination.
*
* *[Mempool.space docs](https://mempool.space/docs/api/rest#get-address-transactions)*
*
* Endpoint: `GET /api/address/{address}/txs`
*
* @param {Address} address
* @param {string=} [after_txid] - Txid to paginate from (return transactions before this one)
* @param {number=} [limit] - Maximum number of results to return. Defaults to 25 if not specified.
* @returns {Promise<Txid[]>}
* @param {Txid=} [after_txid] - Txid to paginate from (return transactions before this one)
* @returns {Promise<Transaction[]>}
*/
async getAddressTxs(address, after_txid, limit) {
async getAddressTxs(address, after_txid) {
const params = new URLSearchParams();
if (after_txid !== undefined) params.set('after_txid', String(after_txid));
if (limit !== undefined) params.set('limit', String(limit));
const query = params.toString();
const path = `/api/address/${address}/txs${query ? '?' + query : ''}`;
return this.getJson(path);
@@ -8757,21 +8758,19 @@ class BrkClient extends BrkClientBase {
/**
* Address confirmed transactions
*
* Get confirmed transaction IDs for an address, 25 per page. Use ?after_txid=<txid> for pagination.
* Get confirmed transactions for an address, 25 per page. Use ?after_txid=<txid> for pagination.
*
* *[Mempool.space docs](https://mempool.space/docs/api/rest#get-address-transactions-chain)*
*
* Endpoint: `GET /api/address/{address}/txs/chain`
*
* @param {Address} address
* @param {string=} [after_txid] - Txid to paginate from (return transactions before this one)
* @param {number=} [limit] - Maximum number of results to return. Defaults to 25 if not specified.
* @returns {Promise<Txid[]>}
* @param {Txid=} [after_txid] - Txid to paginate from (return transactions before this one)
* @returns {Promise<Transaction[]>}
*/
async getAddressConfirmedTxs(address, after_txid, limit) {
async getAddressConfirmedTxs(address, after_txid) {
const params = new URLSearchParams();
if (after_txid !== undefined) params.set('after_txid', String(after_txid));
if (limit !== undefined) params.set('limit', String(limit));
const query = params.toString();
const path = `/api/address/${address}/txs/chain${query ? '?' + query : ''}`;
return this.getJson(path);
@@ -9016,9 +9015,9 @@ class BrkClient extends BrkClientBase {
*
* @param {Metric} metric - Metric name
* @param {Index} index - Aggregation index
* @param {string=} [start] - Inclusive start: integer index, date (YYYY-MM-DD), or timestamp (ISO 8601). Negative integers count from end. Aliases: `from`, `f`, `s`
* @param {string=} [end] - Exclusive end: integer index, date (YYYY-MM-DD), or timestamp (ISO 8601). Negative integers count from end. Aliases: `to`, `t`, `e`
* @param {string=} [limit] - Maximum number of values to return (ignored if `end` is set). Aliases: `count`, `c`, `l`
* @param {RangeIndex=} [start] - Inclusive start: integer index, date (YYYY-MM-DD), or timestamp (ISO 8601). Negative integers count from end. Aliases: `from`, `f`, `s`
* @param {RangeIndex=} [end] - Exclusive end: integer index, date (YYYY-MM-DD), or timestamp (ISO 8601). Negative integers count from end. Aliases: `to`, `t`, `e`
* @param {Limit=} [limit] - Maximum number of values to return (ignored if `end` is set). Aliases: `count`, `c`, `l`
* @param {Format=} [format] - Format of the output
* @returns {Promise<AnyMetricData | string>}
*/
@@ -9045,9 +9044,9 @@ class BrkClient extends BrkClientBase {
*
* @param {Metric} metric - Metric name
* @param {Index} index - Aggregation index
* @param {string=} [start] - Inclusive start: integer index, date (YYYY-MM-DD), or timestamp (ISO 8601). Negative integers count from end. Aliases: `from`, `f`, `s`
* @param {string=} [end] - Exclusive end: integer index, date (YYYY-MM-DD), or timestamp (ISO 8601). Negative integers count from end. Aliases: `to`, `t`, `e`
* @param {string=} [limit] - Maximum number of values to return (ignored if `end` is set). Aliases: `count`, `c`, `l`
* @param {RangeIndex=} [start] - Inclusive start: integer index, date (YYYY-MM-DD), or timestamp (ISO 8601). Negative integers count from end. Aliases: `from`, `f`, `s`
* @param {RangeIndex=} [end] - Exclusive end: integer index, date (YYYY-MM-DD), or timestamp (ISO 8601). Negative integers count from end. Aliases: `to`, `t`, `e`
* @param {Limit=} [limit] - Maximum number of values to return (ignored if `end` is set). Aliases: `count`, `c`, `l`
* @param {Format=} [format] - Format of the output
* @returns {Promise<boolean[] | string>}
*/
@@ -9131,9 +9130,9 @@ class BrkClient extends BrkClientBase {
*
* @param {Metrics} [metrics] - Requested metrics
* @param {Index} [index] - Index to query
* @param {string=} [start] - Inclusive start: integer index, date (YYYY-MM-DD), or timestamp (ISO 8601). Negative integers count from end. Aliases: `from`, `f`, `s`
* @param {string=} [end] - Exclusive end: integer index, date (YYYY-MM-DD), or timestamp (ISO 8601). Negative integers count from end. Aliases: `to`, `t`, `e`
* @param {string=} [limit] - Maximum number of values to return (ignored if `end` is set). Aliases: `count`, `c`, `l`
* @param {RangeIndex=} [start] - Inclusive start: integer index, date (YYYY-MM-DD), or timestamp (ISO 8601). Negative integers count from end. Aliases: `from`, `f`, `s`
* @param {RangeIndex=} [end] - Exclusive end: integer index, date (YYYY-MM-DD), or timestamp (ISO 8601). Negative integers count from end. Aliases: `to`, `t`, `e`
* @param {Limit=} [limit] - Maximum number of values to return (ignored if `end` is set). Aliases: `count`, `c`, `l`
* @param {Format=} [format] - Format of the output
* @returns {Promise<AnyMetricData[] | string>}
*/
@@ -9237,11 +9236,13 @@ class BrkClient extends BrkClientBase {
* Endpoint: `GET /api/metrics/list`
*
* @param {number=} [page] - Pagination index
* @param {number=} [per_page] - Results per page (default: 1000, max: 1000)
* @returns {Promise<PaginatedMetrics>}
*/
async listMetrics(page) {
async listMetrics(page, per_page) {
const params = new URLSearchParams();
if (page !== undefined) params.set('page', String(page));
if (per_page !== undefined) params.set('per_page', String(per_page));
const query = params.toString();
const path = `/api/metrics/list${query ? '?' + query : ''}`;
return this.getJson(path);
+4 -2
View File
@@ -68,7 +68,9 @@ console.log("\n7. dateEntries():");
const dateEntries = price.dateEntries();
if (!(dateEntries[0][0] instanceof Date))
throw new Error("Expected Date entry key");
console.log(` First: [${dateEntries[0][0].toISOString()}, ${dateEntries[0][1]}]`);
console.log(
` First: [${dateEntries[0][0].toISOString()}, ${dateEntries[0][1]}]`,
);
// Test toMap() - returns Map<number, value>
console.log("\n8. toMap():");
@@ -95,7 +97,7 @@ if (count !== 5) throw new Error("Expected 5 iterations");
// Test with non-date-based index (height)
console.log("\n11. Testing height-based metric:");
const heightMetric = await client.metrics.prices.price.usd.by.height.last(3);
const heightMetric = await client.metrics.prices.spot.usd.by.height.last(3);
console.log(
` Total: ${heightMetric.total}, Start: ${heightMetric.start}, End: ${heightMetric.end}`,
);
+15 -1
View File
@@ -1,6 +1,7 @@
const DEFAULT_SEPARATORS = "_- ,:";
const DEFAULT_TRIGRAM_BUDGET = 6;
const DEFAULT_LIMIT = 100;
const DEFAULT_MIN_SCORE = 2;
/**
* Configuration for QuickMatch.
@@ -15,6 +16,9 @@ export class QuickMatchConfig {
/** @type {number} Number of trigram lookups for fuzzy matching (0-20) */
trigramBudget = DEFAULT_TRIGRAM_BUDGET;
/** @type {number} Minimum trigram score required for fuzzy matches */
minScore = DEFAULT_MIN_SCORE;
/**
* Set maximum number of results.
* @param {number} n
@@ -42,6 +46,16 @@ export class QuickMatchConfig {
this.separators = s;
return this;
}
/**
* Set minimum trigram score for fuzzy matches.
* Higher values require more trigram overlap, reducing noise.
* @param {number} n - Minimum score (default: 2, min: 1)
*/
withMinScore(n) {
this.minScore = Math.max(1, n);
return this;
}
}
/**
@@ -179,7 +193,7 @@ export class QuickMatch {
minItemLength,
});
const minScoreToInclude = Math.max(1, Math.ceil(hitCount / 2));
const minScoreToInclude = Math.max(config.minScore, Math.ceil(hitCount / 2));
return this.rankedResults(scores, minScoreToInclude, limit);
}