@eclesia/indexer-engine 2.14.4 → 2.16.0
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/dist/_virtual/rolldown_runtime.cjs +20 -15
- package/dist/_virtual/rolldown_runtime.mjs +10 -30
- package/dist/constants.cjs +31 -2
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +27 -3
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +27 -3
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +27 -3
- package/dist/constants.mjs.map +1 -1
- package/dist/emitter/index.cjs +25 -7
- package/dist/emitter/index.cjs.map +1 -1
- package/dist/emitter/index.d.cts +8 -1
- package/dist/emitter/index.d.cts.map +1 -1
- package/dist/emitter/index.d.mts +8 -1
- package/dist/emitter/index.d.mts.map +1 -1
- package/dist/emitter/index.mjs +25 -7
- package/dist/emitter/index.mjs.map +1 -1
- package/dist/index.cjs +6 -0
- package/dist/index.d.cts +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +3 -3
- package/dist/indexer/index.cjs +498 -225
- package/dist/indexer/index.cjs.map +1 -1
- package/dist/indexer/index.d.cts +111 -7
- package/dist/indexer/index.d.cts.map +1 -1
- package/dist/indexer/index.d.mts +111 -7
- package/dist/indexer/index.d.mts.map +1 -1
- package/dist/indexer/index.mjs +496 -224
- package/dist/indexer/index.mjs.map +1 -1
- package/dist/metrics/index.cjs +14 -0
- package/dist/metrics/index.cjs.map +1 -1
- package/dist/metrics/index.d.cts +7 -0
- package/dist/metrics/index.d.cts.map +1 -1
- package/dist/metrics/index.d.mts +7 -0
- package/dist/metrics/index.d.mts.map +1 -1
- package/dist/metrics/index.mjs +14 -0
- package/dist/metrics/index.mjs.map +1 -1
- package/dist/mocks/index.cjs +3 -1
- package/dist/mocks/index.cjs.map +1 -1
- package/dist/mocks/index.d.cts +2 -2
- package/dist/mocks/index.d.mts +2 -2
- package/dist/mocks/index.mjs +4 -2
- package/dist/mocks/index.mjs.map +1 -1
- package/dist/mocks/rpc-client.cjs +185 -20
- package/dist/mocks/rpc-client.cjs.map +1 -1
- package/dist/mocks/rpc-client.d.cts +26 -10
- package/dist/mocks/rpc-client.d.cts.map +1 -1
- package/dist/mocks/rpc-client.d.mts +26 -10
- package/dist/mocks/rpc-client.d.mts.map +1 -1
- package/dist/mocks/rpc-client.mjs +184 -22
- package/dist/mocks/rpc-client.mjs.map +1 -1
- package/dist/promise-queue/index.cjs +10 -4
- package/dist/promise-queue/index.cjs.map +1 -1
- package/dist/promise-queue/index.d.cts +1 -4
- package/dist/promise-queue/index.d.cts.map +1 -1
- package/dist/promise-queue/index.d.mts +1 -4
- package/dist/promise-queue/index.d.mts.map +1 -1
- package/dist/promise-queue/index.mjs +10 -4
- package/dist/promise-queue/index.mjs.map +1 -1
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.cts +28 -5
- package/dist/types/index.d.cts.map +1 -1
- package/dist/types/index.d.mts +28 -5
- package/dist/types/index.d.mts.map +1 -1
- package/dist/types/index.mjs.map +1 -1
- package/dist/utils/index.cjs +6 -1
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +3 -2
- package/dist/utils/index.d.mts +3 -2
- package/dist/utils/index.mjs +7 -2
- package/dist/utils/index.mjs.map +1 -1
- package/dist/utils/text.cjs +31 -0
- package/dist/utils/text.cjs.map +1 -1
- package/dist/utils/text.d.cts +24 -1
- package/dist/utils/text.d.cts.map +1 -1
- package/dist/utils/text.d.mts +24 -1
- package/dist/utils/text.d.mts.map +1 -1
- package/dist/utils/text.mjs +30 -1
- package/dist/utils/text.mjs.map +1 -1
- package/dist/utils/timeout.cjs +32 -0
- package/dist/utils/timeout.cjs.map +1 -0
- package/dist/utils/timeout.d.cts +18 -0
- package/dist/utils/timeout.d.cts.map +1 -0
- package/dist/utils/timeout.d.mts +18 -0
- package/dist/utils/timeout.d.mts.map +1 -0
- package/dist/utils/timeout.mjs +30 -0
- package/dist/utils/timeout.mjs.map +1 -0
- package/package.json +35 -34
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/ascii.cjs +0 -32
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/ascii.cjs.map +0 -1
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/ascii.mjs +0 -29
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/ascii.mjs.map +0 -1
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/base64.cjs +0 -67
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/base64.cjs.map +0 -1
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/base64.mjs +0 -64
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/base64.mjs.map +0 -1
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/bech32.cjs +0 -80
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/bech32.cjs.map +0 -1
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/bech32.mjs +0 -77
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/bech32.mjs.map +0 -1
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/hex.cjs +0 -33
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/hex.cjs.map +0 -1
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/hex.mjs +0 -30
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/hex.mjs.map +0 -1
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/index.cjs +0 -106
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/index.cjs.map +0 -1
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/index.mjs +0 -103
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/index.mjs.map +0 -1
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/rfc3339.cjs +0 -52
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/rfc3339.cjs.map +0 -1
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/rfc3339.mjs +0 -49
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/rfc3339.mjs.map +0 -1
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/utf8.cjs +0 -31
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/utf8.cjs.map +0 -1
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/utf8.mjs +0 -28
- package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/utf8.mjs.map +0 -1
- package/dist/node_modules/.pnpm/base64-js@1.5.1/node_modules/base64-js/index.cjs +0 -98
- package/dist/node_modules/.pnpm/base64-js@1.5.1/node_modules/base64-js/index.cjs.map +0 -1
- package/dist/node_modules/.pnpm/base64-js@1.5.1/node_modules/base64-js/index.mjs +0 -95
- package/dist/node_modules/.pnpm/base64-js@1.5.1/node_modules/base64-js/index.mjs.map +0 -1
package/dist/types/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EclesiaIndexer } from "../indexer/index.cjs";
|
|
2
2
|
import { CircularBuffer } from "../promise-queue/index.cjs";
|
|
3
3
|
import { BlockResponse, BlockResultsResponse } from "@cosmjs/tendermint-rpc";
|
|
4
4
|
import { BlockResultsResponse as BlockResultsResponse$1, Event } from "@cosmjs/tendermint-rpc/build/comet38/responses";
|
|
@@ -7,10 +7,10 @@ import { TxBody } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
|
|
7
7
|
|
|
8
8
|
//#region src/types/index.d.ts
|
|
9
9
|
declare namespace index_d_exports {
|
|
10
|
-
export { BlockQueue, EcleciaIndexerConfig, EmitFunc, Events, FullBlockQueue, IndexingModule, LogEvent, MinimalBlockQueue, TxResult, UUIDEvent, WithHeightAndUUID };
|
|
10
|
+
export { BlockQueue, EcleciaIndexerConfig, EclesiaIndexerConfig, EmitFunc, Events, FullBlockQueue, IndexingModule, LogEvent, MinimalBlockQueue, TxResult, UUIDEvent, WithHeightAndUUID };
|
|
11
11
|
}
|
|
12
12
|
/** Configuration interface for the Eclesia indexer */
|
|
13
|
-
type
|
|
13
|
+
type EclesiaIndexerConfig = {
|
|
14
14
|
startHeight?: number;
|
|
15
15
|
endHeight?: number;
|
|
16
16
|
batchSize: number;
|
|
@@ -18,6 +18,7 @@ type EcleciaIndexerConfig = {
|
|
|
18
18
|
getNextHeight: () => number | PromiseLike<number>;
|
|
19
19
|
logLevel: "error" | "warn" | "info" | "http" | "verbose" | "debug" | "silly";
|
|
20
20
|
rpcUrl: string;
|
|
21
|
+
chainId?: string;
|
|
21
22
|
shouldProcessGenesis: () => Promise<boolean>;
|
|
22
23
|
genesisPath?: string;
|
|
23
24
|
usePolling?: boolean;
|
|
@@ -27,10 +28,19 @@ type EcleciaIndexerConfig = {
|
|
|
27
28
|
healthCheckPort?: number;
|
|
28
29
|
enablePrometheus?: boolean;
|
|
29
30
|
prometheusPort?: number;
|
|
31
|
+
healthCheckHost?: string;
|
|
32
|
+
prometheusHost?: string;
|
|
33
|
+
logFormat?: "text" | "json";
|
|
34
|
+
maxRetries?: number;
|
|
35
|
+
maxFailuresPerBlock?: number;
|
|
36
|
+
onGenesisStart?: () => Promise<void>;
|
|
37
|
+
onGenesisComplete?: () => Promise<void>;
|
|
30
38
|
init?: () => Promise<void>;
|
|
31
39
|
beginTransaction: () => Promise<void>;
|
|
32
40
|
endTransaction: (status: boolean) => Promise<void>;
|
|
33
41
|
};
|
|
42
|
+
/** @deprecated Misspelling kept for compatibility, use EclesiaIndexerConfig. Removed in 3.0. */
|
|
43
|
+
type EcleciaIndexerConfig = EclesiaIndexerConfig;
|
|
34
44
|
/** Queue for full indexing mode with validator data */
|
|
35
45
|
type FullBlockQueue = CircularBuffer<[BlockResponse, BlockResultsResponse, Uint8Array]>;
|
|
36
46
|
/** Queue for minimal indexing mode without validator data */
|
|
@@ -61,6 +71,7 @@ type Events = {
|
|
|
61
71
|
error: Error;
|
|
62
72
|
message: string;
|
|
63
73
|
retryCount?: number;
|
|
74
|
+
height?: number;
|
|
64
75
|
};
|
|
65
76
|
begin_block: {
|
|
66
77
|
value: {
|
|
@@ -106,13 +117,25 @@ type TxResult<T> = {
|
|
|
106
117
|
};
|
|
107
118
|
/** Interface that all indexing modules must implement */
|
|
108
119
|
interface IndexingModule {
|
|
109
|
-
indexer:
|
|
120
|
+
indexer: EclesiaIndexer;
|
|
110
121
|
name: string;
|
|
111
122
|
depends: string[];
|
|
112
123
|
provides: string[];
|
|
113
124
|
setup: () => Promise<void>;
|
|
114
125
|
init: (...args: any[]) => void;
|
|
115
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Global event map. Modules add their own events through declaration merging:
|
|
129
|
+
*
|
|
130
|
+
* declare global { interface EventMap extends MyModule.Events {} }
|
|
131
|
+
*
|
|
132
|
+
* Declared in a regular module (not an ambient .d.ts) so it is emitted into the
|
|
133
|
+
* published declarations and consumers get typed events without extra setup.
|
|
134
|
+
*/
|
|
135
|
+
declare global {
|
|
136
|
+
interface EventMap extends Events {}
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=index.d.ts.map
|
|
116
139
|
//#endregion
|
|
117
|
-
export {
|
|
140
|
+
export { EclesiaIndexerConfig, EmitFunc, WithHeightAndUUID, index_d_exports };
|
|
118
141
|
//# sourceMappingURL=index.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/types/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;KAsBY,oBAAA;;;;;gCAKoB
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/types/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;KAsBY,oBAAA;;;;;gCAKoB;;;;8BAIF;;;;;;;EATlB,gBAAA,CAAA,EAAA,OAAoB;EAKA,cAAA,CAAA,EAAA,MAAA;EAIF,eAAA,CAAA,EAAA,MAAA;EAcL,cAAA,CAAA,EAAA,MAAA;EACG,SAAA,CAAA,EAAA,MAAA,GAAA,MAAA;EACb,UAAA,CAAA,EAAA,MAAA;EACW,mBAAA,CAAA,EAAA,MAAA;EACa,cAAA,CAAA,EAAA,GAAA,GAJd,OAIc,CAAA,IAAA,CAAA;EAAO,iBAAA,CAAA,EAAA,GAAA,GAHlB,OAGkB,CAAA,IAAA,CAAA;EAIlC,IAAA,CAAA,EAAA,GAAA,GANG,OAMH,CAAA,IAAoB,CAAA;EAGpB,gBAAA,EAAc,GAAA,GARA,OAQA,CAAA,IAAA,CAAA;EAAmB,cAAA,EAAA,CAAA,MAAA,EAAA,OAAA,EAAA,GAPN,OAOM,CAAA,IAAA,CAAA;CAAe;;AAA/B,KAHjB,oBAAA,GAAuB,oBAGN;;AAGjB,KAHA,cAAA,GAAiB,cAGA,CAAA,CAHgB,aAGhB,EAH+B,oBAG/B,EAHqD,UAGrD,CAAA,CAAA;;AAAkC,KAAnD,iBAAA,GAAoB,cAA+B,CAAA,CAAf,aAAe,EAAA,oBAAA,CAAA,CAAA;;AAAjB,KAGlC,UAAA,GAAa,cAHqB,GAGJ,iBAHI;AAG9C;AAGY,KAAA,iBAAiB,CAAA,CAAA,CAAA,GAAA,QACf,MAAA,CAAA,GAAI,CAAJ,CAAM,CAAN,CAAA,GAAA;EAAI,IAAA,CAAA,EAAA,MAAA;EAAE,MAAA,CAAA,EAAA,MAAA;EAAC,SAAA,CAAA,EAAA,MAAA;AAQT,CAAA,EAA2C;;AAClD,KADO,QACP,CAAA,YAAA,MADgC,iBAChC,CADkD,QAClD,CAAA,CAAA,GAAA,CAAA,CAAA,EAAA,GAAA,EAAA,CAAA,EACA,iBADA,CACkB,QADlB,CAAA,CAC4B,GAD5B,CAAA,EAAA,GAEA,OAFA,CAAA,IAAA,GAAA,IAAA,EAAA,CAAA;AACkB,KAGX,QAAA,GAHW;EAAlB,IAAA,EAAA,KAAA,GAAA,MAAA,GAAA,SAAA,GAAA,OAAA,GAAA,SAAA,GAAA,WAAA;EAA4B,OAAA,EAAA,MAAA;CAC5B;AAAO,KAMA,SAAA,GANA;EAEA,IAAA,EAAA,MAAQ;EAIR,KAAA,CAAA,EAAA,MAAS;EAKT,MAAA,EAAA,OAAM;CACX;AACC,KAFI,MAAA,GAEJ;EAEG,GAAA,EAHJ,QAGI;EAOG,IAAA,EATN,SASM;EAA2C,aAAA,EAAA;IACvC,KAAA,EARP,KAQO;IAML,OAAA,EAAA,MAAA;IACQ,UAAA,CAAA,EAAA,MAAA;IAAuB,MAAA,CAAA,EAAA,MAAA;EAIjC,CAAA;EAAyC,WAAA,EAAA;IAGzC,KAAA,EAAA;MAAkC,MAAA,EAf/B,oBAe+B,CAAA,kBAAA,CAAA,GAfY,sBAeZ,CAAA,qBAAA,CAAA;MAK/B,UAAA,EAnBI,SAmBJ,EAAA,GAAA,SAAA;IAAM,CAAA;EAiBR,CAAA;EAMK,KAAA,EAAA;IAQhB,KAAA,EAAA;MAAA,KAAA,EA5CY,aA4CZ;MAY4B,aAAM,EAvDd,oBAuDc,GAvDS,sBAuDT;IAAA,CAAA;EAAA,CAAA;;WAnDxB,yCAAyC;;;WAGzC,kCAAkC;;;;;cAK/B;;;;;;;;;;;;;;;;;KAiBF;MACN;UACI;;;UAIO,cAAA;WACN;;;;eAII;;;;;;;;;;;;6BAec"}
|
package/dist/types/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EclesiaIndexer } from "../indexer/index.mjs";
|
|
2
2
|
import { CircularBuffer } from "../promise-queue/index.mjs";
|
|
3
3
|
import { BlockResponse, BlockResultsResponse } from "@cosmjs/tendermint-rpc";
|
|
4
4
|
import { BlockResultsResponse as BlockResultsResponse$1, Event } from "@cosmjs/tendermint-rpc/build/comet38/responses";
|
|
@@ -7,10 +7,10 @@ import { TxBody } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
|
|
7
7
|
|
|
8
8
|
//#region src/types/index.d.ts
|
|
9
9
|
declare namespace index_d_exports {
|
|
10
|
-
export { BlockQueue, EcleciaIndexerConfig, EmitFunc, Events, FullBlockQueue, IndexingModule, LogEvent, MinimalBlockQueue, TxResult, UUIDEvent, WithHeightAndUUID };
|
|
10
|
+
export { BlockQueue, EcleciaIndexerConfig, EclesiaIndexerConfig, EmitFunc, Events, FullBlockQueue, IndexingModule, LogEvent, MinimalBlockQueue, TxResult, UUIDEvent, WithHeightAndUUID };
|
|
11
11
|
}
|
|
12
12
|
/** Configuration interface for the Eclesia indexer */
|
|
13
|
-
type
|
|
13
|
+
type EclesiaIndexerConfig = {
|
|
14
14
|
startHeight?: number;
|
|
15
15
|
endHeight?: number;
|
|
16
16
|
batchSize: number;
|
|
@@ -18,6 +18,7 @@ type EcleciaIndexerConfig = {
|
|
|
18
18
|
getNextHeight: () => number | PromiseLike<number>;
|
|
19
19
|
logLevel: "error" | "warn" | "info" | "http" | "verbose" | "debug" | "silly";
|
|
20
20
|
rpcUrl: string;
|
|
21
|
+
chainId?: string;
|
|
21
22
|
shouldProcessGenesis: () => Promise<boolean>;
|
|
22
23
|
genesisPath?: string;
|
|
23
24
|
usePolling?: boolean;
|
|
@@ -27,10 +28,19 @@ type EcleciaIndexerConfig = {
|
|
|
27
28
|
healthCheckPort?: number;
|
|
28
29
|
enablePrometheus?: boolean;
|
|
29
30
|
prometheusPort?: number;
|
|
31
|
+
healthCheckHost?: string;
|
|
32
|
+
prometheusHost?: string;
|
|
33
|
+
logFormat?: "text" | "json";
|
|
34
|
+
maxRetries?: number;
|
|
35
|
+
maxFailuresPerBlock?: number;
|
|
36
|
+
onGenesisStart?: () => Promise<void>;
|
|
37
|
+
onGenesisComplete?: () => Promise<void>;
|
|
30
38
|
init?: () => Promise<void>;
|
|
31
39
|
beginTransaction: () => Promise<void>;
|
|
32
40
|
endTransaction: (status: boolean) => Promise<void>;
|
|
33
41
|
};
|
|
42
|
+
/** @deprecated Misspelling kept for compatibility, use EclesiaIndexerConfig. Removed in 3.0. */
|
|
43
|
+
type EcleciaIndexerConfig = EclesiaIndexerConfig;
|
|
34
44
|
/** Queue for full indexing mode with validator data */
|
|
35
45
|
type FullBlockQueue = CircularBuffer<[BlockResponse, BlockResultsResponse, Uint8Array]>;
|
|
36
46
|
/** Queue for minimal indexing mode without validator data */
|
|
@@ -61,6 +71,7 @@ type Events = {
|
|
|
61
71
|
error: Error;
|
|
62
72
|
message: string;
|
|
63
73
|
retryCount?: number;
|
|
74
|
+
height?: number;
|
|
64
75
|
};
|
|
65
76
|
begin_block: {
|
|
66
77
|
value: {
|
|
@@ -106,13 +117,25 @@ type TxResult<T> = {
|
|
|
106
117
|
};
|
|
107
118
|
/** Interface that all indexing modules must implement */
|
|
108
119
|
interface IndexingModule {
|
|
109
|
-
indexer:
|
|
120
|
+
indexer: EclesiaIndexer;
|
|
110
121
|
name: string;
|
|
111
122
|
depends: string[];
|
|
112
123
|
provides: string[];
|
|
113
124
|
setup: () => Promise<void>;
|
|
114
125
|
init: (...args: any[]) => void;
|
|
115
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Global event map. Modules add their own events through declaration merging:
|
|
129
|
+
*
|
|
130
|
+
* declare global { interface EventMap extends MyModule.Events {} }
|
|
131
|
+
*
|
|
132
|
+
* Declared in a regular module (not an ambient .d.ts) so it is emitted into the
|
|
133
|
+
* published declarations and consumers get typed events without extra setup.
|
|
134
|
+
*/
|
|
135
|
+
declare global {
|
|
136
|
+
interface EventMap extends Events {}
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=index.d.ts.map
|
|
116
139
|
//#endregion
|
|
117
|
-
export {
|
|
140
|
+
export { EclesiaIndexerConfig, EmitFunc, WithHeightAndUUID, index_d_exports };
|
|
118
141
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/types/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;KAsBY,oBAAA;;;;;gCAKoB
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/types/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;KAsBY,oBAAA;;;;;gCAKoB;;;;8BAIF;;;;;;;EATlB,gBAAA,CAAA,EAAA,OAAoB;EAKA,cAAA,CAAA,EAAA,MAAA;EAIF,eAAA,CAAA,EAAA,MAAA;EAcL,cAAA,CAAA,EAAA,MAAA;EACG,SAAA,CAAA,EAAA,MAAA,GAAA,MAAA;EACb,UAAA,CAAA,EAAA,MAAA;EACW,mBAAA,CAAA,EAAA,MAAA;EACa,cAAA,CAAA,EAAA,GAAA,GAJd,OAIc,CAAA,IAAA,CAAA;EAAO,iBAAA,CAAA,EAAA,GAAA,GAHlB,OAGkB,CAAA,IAAA,CAAA;EAIlC,IAAA,CAAA,EAAA,GAAA,GANG,OAMH,CAAA,IAAoB,CAAA;EAGpB,gBAAA,EAAc,GAAA,GARA,OAQA,CAAA,IAAA,CAAA;EAAmB,cAAA,EAAA,CAAA,MAAA,EAAA,OAAA,EAAA,GAPN,OAOM,CAAA,IAAA,CAAA;CAAe;;AAA/B,KAHjB,oBAAA,GAAuB,oBAGN;;AAGjB,KAHA,cAAA,GAAiB,cAGA,CAAA,CAHgB,aAGhB,EAH+B,oBAG/B,EAHqD,UAGrD,CAAA,CAAA;;AAAkC,KAAnD,iBAAA,GAAoB,cAA+B,CAAA,CAAf,aAAe,EAAA,oBAAA,CAAA,CAAA;;AAAjB,KAGlC,UAAA,GAAa,cAHqB,GAGJ,iBAHI;AAG9C;AAGY,KAAA,iBAAiB,CAAA,CAAA,CAAA,GAAA,QACf,MAAA,CAAA,GAAI,CAAJ,CAAM,CAAN,CAAA,GAAA;EAAI,IAAA,CAAA,EAAA,MAAA;EAAE,MAAA,CAAA,EAAA,MAAA;EAAC,SAAA,CAAA,EAAA,MAAA;AAQT,CAAA,EAA2C;;AAClD,KADO,QACP,CAAA,YAAA,MADgC,iBAChC,CADkD,QAClD,CAAA,CAAA,GAAA,CAAA,CAAA,EAAA,GAAA,EAAA,CAAA,EACA,iBADA,CACkB,QADlB,CAAA,CAC4B,GAD5B,CAAA,EAAA,GAEA,OAFA,CAAA,IAAA,GAAA,IAAA,EAAA,CAAA;AACkB,KAGX,QAAA,GAHW;EAAlB,IAAA,EAAA,KAAA,GAAA,MAAA,GAAA,SAAA,GAAA,OAAA,GAAA,SAAA,GAAA,WAAA;EAA4B,OAAA,EAAA,MAAA;CAC5B;AAAO,KAMA,SAAA,GANA;EAEA,IAAA,EAAA,MAAQ;EAIR,KAAA,CAAA,EAAA,MAAS;EAKT,MAAA,EAAA,OAAM;CACX;AACC,KAFI,MAAA,GAEJ;EAEG,GAAA,EAHJ,QAGI;EAOG,IAAA,EATN,SASM;EAA2C,aAAA,EAAA;IACvC,KAAA,EARP,KAQO;IAML,OAAA,EAAA,MAAA;IACQ,UAAA,CAAA,EAAA,MAAA;IAAuB,MAAA,CAAA,EAAA,MAAA;EAIjC,CAAA;EAAyC,WAAA,EAAA;IAGzC,KAAA,EAAA;MAAkC,MAAA,EAf/B,oBAe+B,CAAA,kBAAA,CAAA,GAfY,sBAeZ,CAAA,qBAAA,CAAA;MAK/B,UAAA,EAnBI,SAmBJ,EAAA,GAAA,SAAA;IAAM,CAAA;EAiBR,CAAA;EAMK,KAAA,EAAA;IAQhB,KAAA,EAAA;MAAA,KAAA,EA5CY,aA4CZ;MAY4B,aAAM,EAvDd,oBAuDc,GAvDS,sBAuDT;IAAA,CAAA;EAAA,CAAA;;WAnDxB,yCAAyC;;;WAGzC,kCAAkC;;;;;cAK/B;;;;;;;;;;;;;;;;;KAiBF;MACN;UACI;;;UAIO,cAAA;WACN;;;;eAII;;;;;;;;;;;;6BAec"}
|
package/dist/types/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/types/index.ts"],"sourcesContent":["/* eslint-disable @stylistic/no-multi-spaces */\nimport {\n BlockResponse, BlockResultsResponse,\n} from \"@cosmjs/tendermint-rpc\";\nimport {\n BlockResultsResponse as BlockResultsResponse38, Event,\n} from \"@cosmjs/tendermint-rpc/build/comet38/responses\";\nimport {\n Validator,\n} from \"cosmjs-types/cosmos/staking/v1beta1/staking\";\nimport {\n TxBody,\n} from \"cosmjs-types/cosmos/tx/v1beta1/tx\";\n\nimport {\n
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/types/index.ts"],"sourcesContent":["/* eslint-disable @stylistic/no-multi-spaces */\nimport {\n BlockResponse, BlockResultsResponse,\n} from \"@cosmjs/tendermint-rpc\";\nimport {\n BlockResultsResponse as BlockResultsResponse38, Event,\n} from \"@cosmjs/tendermint-rpc/build/comet38/responses\";\nimport {\n Validator,\n} from \"cosmjs-types/cosmos/staking/v1beta1/staking\";\nimport {\n TxBody,\n} from \"cosmjs-types/cosmos/tx/v1beta1/tx\";\n\nimport {\n EclesiaIndexer,\n} from \"../indexer\";\nimport {\n CircularBuffer,\n} from \"../promise-queue\";\n\n/** Configuration interface for the Eclesia indexer */\nexport type EclesiaIndexerConfig = {\n startHeight?: number // Block height to start indexing from\n endHeight?: number // Block height to stop indexing at (optional)\n batchSize: number // Number of blocks to process in parallel\n modules: string[] // List of module names to enable\n getNextHeight: () => number | PromiseLike<number> // Function to determine next block to process\n logLevel: \"error\" | \"warn\" | \"info\" | \"http\" | \"verbose\" | \"debug\" | \"silly\" // Logging verbosity level\n rpcUrl: string // Tendermint RPC endpoint URL\n chainId?: string // Refuse to index if the RPC reports a different network\n shouldProcessGenesis: () => Promise<boolean> // Whether to process genesis state\n genesisPath?: string // Path to genesis file\n usePolling?: boolean // Use polling instead of WebSocket subscription\n pollingInterval?: number // Interval between polls in milliseconds\n minimal?: boolean // Use minimal indexing mode (blocks only)\n enableHealthcheck?: boolean // Enable health check HTTP server\n healthCheckPort?: number // Port for health check HTTP server (default: 8888)\n enablePrometheus?: boolean // Enable Prometheus metrics server\n prometheusPort?: number // Port for Prometheus metrics server (default: 9090)\n healthCheckHost?: string // Address the health check server binds to (default: 0.0.0.0)\n prometheusHost?: string // Address the metrics server binds to (default: 0.0.0.0)\n logFormat?: \"text\" | \"json\" // Console log format (default: text)\n maxRetries?: number // Emit fatal-error after this many consecutive failed restarts; unlimited when unset\n maxFailuresPerBlock?: number // Consecutive processing failures on one block before fatal-error (default: 5)\n onGenesisStart?: () => Promise<void> // Called before the genesis import begins, outside any transaction\n onGenesisComplete?: () => Promise<void> // Called inside the final genesis transaction, right before it commits\n init?: () => Promise<void> // Custom initialization function\n beginTransaction: () => Promise<void> // Function to begin database transaction\n endTransaction: (status: boolean) => Promise<void> // Function to end database transaction\n};\n\n/** @deprecated Misspelling kept for compatibility, use EclesiaIndexerConfig. Removed in 3.0. */\nexport type EcleciaIndexerConfig = EclesiaIndexerConfig;\n\n/** Queue for full indexing mode with validator data */\nexport type FullBlockQueue = CircularBuffer<[BlockResponse, BlockResultsResponse, Uint8Array]>;\n\n/** Queue for minimal indexing mode without validator data */\nexport type MinimalBlockQueue = CircularBuffer<[BlockResponse, BlockResultsResponse]>;\n\n/** Union type for block queues */\nexport type BlockQueue = FullBlockQueue | MinimalBlockQueue;\n\n/** Utility type to add height, timestamp, and UUID to event types */\nexport type WithHeightAndUUID<T> = {\n [K in keyof T]: T[K] & {\n uuid?: string // Unique identifier for event tracking\n height?: number // Block height when event occurred\n timestamp?: string // Block timestamp when event occurred\n };\n};\n\n/** Function signature for emitting events asynchronously */\nexport type EmitFunc<K extends keyof WithHeightAndUUID<EventMap>> = (\n t: K,\n e: WithHeightAndUUID<EventMap>[K],\n) => Promise<void | void[]>;\n\nexport type LogEvent = {\n type: \"log\" | \"info\" | \"warning\" | \"error\" | \"verbose\" | \"transient\"\n message: string\n};\nexport type UUIDEvent = {\n uuid: string\n error?: string\n status: boolean\n};\nexport type Events = {\n log: LogEvent\n uuid: UUIDEvent\n \"fatal-error\": {\n error: Error\n message: string\n retryCount?: number\n height?: number // Set when one block failed repeatedly\n }\n begin_block: {\n value: {\n events: BlockResultsResponse[\"beginBlockEvents\"] | BlockResultsResponse38[\"finalizeBlockEvents\"]\n validators: Validator[] | undefined\n }\n }\n\n block: {\n value: {\n block: BlockResponse\n block_results: BlockResultsResponse | BlockResultsResponse38\n }\n }\n end_block: {\n value: BlockResultsResponse[\"endBlockEvents\"] | BlockResultsResponse38[\"finalizeBlockEvents\"]\n }\n tx_events: {\n value: BlockResultsResponse[\"results\"] | BlockResultsResponse38[\"results\"]\n }\n tx_memo: {\n value: {\n txHash: string\n txBody: TxBody\n }\n }\n _unhandled: {\n type: string\n event: unknown\n }\n \"periodic/small\": {\n value: null\n }\n \"periodic/medium\": {\n value: null\n }\n \"periodic/large\": {\n value: null\n }\n};\nexport type TxResult<T> = {\n tx: T\n events: Event[]\n};\n\n/** Interface that all indexing modules must implement */\nexport interface IndexingModule {\n indexer: EclesiaIndexer // Reference to the main indexer instance\n name: string // Unique module name\n depends: string[] // Array of module names this module depends on\n provides: string[] // Array of capabilities this module provides\n setup: () => Promise<void> // Async setup function for database schema initialization\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n init: (...args: any[]) => void // Initialization function called by the indexer\n}\n\n/**\n * Global event map. Modules add their own events through declaration merging:\n *\n * declare global { interface EventMap extends MyModule.Events {} }\n *\n * Declared in a regular module (not an ambient .d.ts) so it is emitted into the\n * published declarations and consumers get typed events without extra setup.\n */\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n interface EventMap extends Events {\n }\n}\n"],"mappings":""}
|
package/dist/utils/index.cjs
CHANGED
|
@@ -2,14 +2,19 @@ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
|
2
2
|
const require_bech32 = require('./bech32.cjs');
|
|
3
3
|
const require_bigint = require('./bigint.cjs');
|
|
4
4
|
const require_text = require('./text.cjs');
|
|
5
|
+
const require_timeout = require('./timeout.cjs');
|
|
5
6
|
|
|
6
7
|
//#region src/utils/index.ts
|
|
7
8
|
var utils_exports = /* @__PURE__ */ require_rolldown_runtime.__export({
|
|
8
9
|
chainAddressfromKeyhash: () => require_bech32.chainAddressfromKeyhash,
|
|
9
10
|
decodeAttr: () => require_text.decodeAttr,
|
|
11
|
+
hasBlockEventMode: () => require_text.hasBlockEventMode,
|
|
10
12
|
keyHashfromAddress: () => require_bech32.keyHashfromAddress,
|
|
13
|
+
redactUrl: () => require_text.redactUrl,
|
|
14
|
+
retryDelay: () => require_timeout.retryDelay,
|
|
11
15
|
toHexString: () => require_bech32.toHexString,
|
|
12
|
-
toPlainObject: () => require_bigint.toPlainObject
|
|
16
|
+
toPlainObject: () => require_bigint.toPlainObject,
|
|
17
|
+
withTimeout: () => require_timeout.withTimeout
|
|
13
18
|
});
|
|
14
19
|
|
|
15
20
|
//#endregion
|
package/dist/utils/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/utils/index.ts"],"sourcesContent":["/* eslint-disable @stylistic/no-multi-spaces */\n// Utility function exports\nexport * from \"./bech32\"; // Bech32 address encoding/decoding utilities\nexport * from \"./bigint\"; // BigInt handling utilities\nexport * from \"./text\"; // Text processing and encoding utilities\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/utils/index.ts"],"sourcesContent":["/* eslint-disable @stylistic/no-multi-spaces */\n// Utility function exports\nexport * from \"./bech32\"; // Bech32 address encoding/decoding utilities\nexport * from \"./bigint\"; // BigInt handling utilities\nexport * from \"./text\"; // Text processing and encoding utilities\nexport * from \"./timeout\"; // Promise timeout helper\n"],"mappings":""}
|
package/dist/utils/index.d.cts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { chainAddressfromKeyhash, keyHashfromAddress, toHexString } from "./bech32.cjs";
|
|
2
2
|
import { toPlainObject } from "./bigint.cjs";
|
|
3
|
-
import { decodeAttr } from "./text.cjs";
|
|
3
|
+
import { BlockEventMode, ModeTaggedEvent, decodeAttr, hasBlockEventMode, redactUrl } from "./text.cjs";
|
|
4
|
+
import { retryDelay, withTimeout } from "./timeout.cjs";
|
|
4
5
|
|
|
5
6
|
//#region src/utils/index.d.ts
|
|
6
7
|
declare namespace index_d_exports {
|
|
7
|
-
export { chainAddressfromKeyhash, decodeAttr, keyHashfromAddress, toHexString, toPlainObject };
|
|
8
|
+
export { BlockEventMode, ModeTaggedEvent, chainAddressfromKeyhash, decodeAttr, hasBlockEventMode, keyHashfromAddress, redactUrl, retryDelay, toHexString, toPlainObject, withTimeout };
|
|
8
9
|
}
|
|
9
10
|
//#endregion
|
|
10
11
|
export { index_d_exports };
|
package/dist/utils/index.d.mts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { chainAddressfromKeyhash, keyHashfromAddress, toHexString } from "./bech32.mjs";
|
|
2
2
|
import { toPlainObject } from "./bigint.mjs";
|
|
3
|
-
import { decodeAttr } from "./text.mjs";
|
|
3
|
+
import { BlockEventMode, ModeTaggedEvent, decodeAttr, hasBlockEventMode, redactUrl } from "./text.mjs";
|
|
4
|
+
import { retryDelay, withTimeout } from "./timeout.mjs";
|
|
4
5
|
|
|
5
6
|
//#region src/utils/index.d.ts
|
|
6
7
|
declare namespace index_d_exports {
|
|
7
|
-
export { chainAddressfromKeyhash, decodeAttr, keyHashfromAddress, toHexString, toPlainObject };
|
|
8
|
+
export { BlockEventMode, ModeTaggedEvent, chainAddressfromKeyhash, decodeAttr, hasBlockEventMode, keyHashfromAddress, redactUrl, retryDelay, toHexString, toPlainObject, withTimeout };
|
|
8
9
|
}
|
|
9
10
|
//#endregion
|
|
10
11
|
export { index_d_exports };
|
package/dist/utils/index.mjs
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { __export } from "../_virtual/rolldown_runtime.mjs";
|
|
2
2
|
import { chainAddressfromKeyhash, keyHashfromAddress, toHexString } from "./bech32.mjs";
|
|
3
3
|
import { toPlainObject } from "./bigint.mjs";
|
|
4
|
-
import { decodeAttr } from "./text.mjs";
|
|
4
|
+
import { decodeAttr, hasBlockEventMode, redactUrl } from "./text.mjs";
|
|
5
|
+
import { retryDelay, withTimeout } from "./timeout.mjs";
|
|
5
6
|
|
|
6
7
|
//#region src/utils/index.ts
|
|
7
8
|
var utils_exports = /* @__PURE__ */ __export({
|
|
8
9
|
chainAddressfromKeyhash: () => chainAddressfromKeyhash,
|
|
9
10
|
decodeAttr: () => decodeAttr,
|
|
11
|
+
hasBlockEventMode: () => hasBlockEventMode,
|
|
10
12
|
keyHashfromAddress: () => keyHashfromAddress,
|
|
13
|
+
redactUrl: () => redactUrl,
|
|
14
|
+
retryDelay: () => retryDelay,
|
|
11
15
|
toHexString: () => toHexString,
|
|
12
|
-
toPlainObject: () => toPlainObject
|
|
16
|
+
toPlainObject: () => toPlainObject,
|
|
17
|
+
withTimeout: () => withTimeout
|
|
13
18
|
});
|
|
14
19
|
|
|
15
20
|
//#endregion
|
package/dist/utils/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/utils/index.ts"],"sourcesContent":["/* eslint-disable @stylistic/no-multi-spaces */\n// Utility function exports\nexport * from \"./bech32\"; // Bech32 address encoding/decoding utilities\nexport * from \"./bigint\"; // BigInt handling utilities\nexport * from \"./text\"; // Text processing and encoding utilities\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/utils/index.ts"],"sourcesContent":["/* eslint-disable @stylistic/no-multi-spaces */\n// Utility function exports\nexport * from \"./bech32\"; // Bech32 address encoding/decoding utilities\nexport * from \"./bigint\"; // BigInt handling utilities\nexport * from \"./text\"; // Text processing and encoding utilities\nexport * from \"./timeout\"; // Promise timeout helper\n"],"mappings":""}
|
package/dist/utils/text.cjs
CHANGED
|
@@ -11,7 +11,38 @@ const decodeAttr = (x) => {
|
|
|
11
11
|
else if (x instanceof Uint8Array) return Buffer.from(x).toString();
|
|
12
12
|
else return "";
|
|
13
13
|
};
|
|
14
|
+
const MODE_SPELLINGS = {
|
|
15
|
+
BeginBlock: ["BeginBlock", "begin_block"],
|
|
16
|
+
EndBlock: ["EndBlock", "end_block"]
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Checks whether a finalize_block event carries the given `mode` attribute.
|
|
20
|
+
* The SDK emits `mode=BeginBlock` / `mode=EndBlock`; the snake_case spellings
|
|
21
|
+
* are accepted as well so forks that lowercase the value keep working.
|
|
22
|
+
* @param event - Event with an attributes array
|
|
23
|
+
* @param mode - Which phase of the block the event must belong to
|
|
24
|
+
* @returns true when the event has a matching `mode` attribute
|
|
25
|
+
*/
|
|
26
|
+
const hasBlockEventMode = (event, mode) => {
|
|
27
|
+
const accepted = MODE_SPELLINGS[mode];
|
|
28
|
+
return event.attributes.some((a) => decodeAttr(a.key) === "mode" && accepted.includes(decodeAttr(a.value)));
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Returns a URL that is safe to log: the password part of any credentials is masked.
|
|
32
|
+
* Strings that do not parse as a URL are returned unchanged.
|
|
33
|
+
*/
|
|
34
|
+
const redactUrl = (url) => {
|
|
35
|
+
try {
|
|
36
|
+
const parsed = new URL(url);
|
|
37
|
+
if (parsed.password) parsed.password = "***";
|
|
38
|
+
return parsed.toString();
|
|
39
|
+
} catch (_e) {
|
|
40
|
+
return url;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
14
43
|
|
|
15
44
|
//#endregion
|
|
16
45
|
exports.decodeAttr = decodeAttr;
|
|
46
|
+
exports.hasBlockEventMode = hasBlockEventMode;
|
|
47
|
+
exports.redactUrl = redactUrl;
|
|
17
48
|
//# sourceMappingURL=text.cjs.map
|
package/dist/utils/text.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.cjs","names":[],"sources":["../../src/utils/text.ts"],"sourcesContent":["/**\n * Decodes blockchain event attributes from various formats to strings\n * Handles both string and Uint8Array inputs from Tendermint events\n * @param x - The attribute value to decode (string or Uint8Array)\n * @returns Decoded string value\n */\nexport const decodeAttr = (x: Uint8Array | string) => {\n if (typeof x === \"string\") {\n return x;\n }\n else if (x instanceof Uint8Array) {\n return Buffer.from(x).toString();\n }\n else {\n return \"\";\n }\n};\n"],"mappings":";;;;;;;;AAMA,MAAa,cAAc,MAA2B;AACpD,KAAI,OAAO,MAAM,SACf,QAAO;UAEA,aAAa,WACpB,QAAO,OAAO,KAAK,EAAE,CAAC,UAAU;KAGhC,QAAO"}
|
|
1
|
+
{"version":3,"file":"text.cjs","names":["MODE_SPELLINGS: Record<BlockEventMode, readonly string[]>"],"sources":["../../src/utils/text.ts"],"sourcesContent":["/**\n * Decodes blockchain event attributes from various formats to strings\n * Handles both string and Uint8Array inputs from Tendermint events\n * @param x - The attribute value to decode (string or Uint8Array)\n * @returns Decoded string value\n */\nexport const decodeAttr = (x: Uint8Array | string) => {\n if (typeof x === \"string\") {\n return x;\n }\n else if (x instanceof Uint8Array) {\n return Buffer.from(x).toString();\n }\n else {\n return \"\";\n }\n};\n\n/** Minimal shape of an ABCI event, compatible with both CometBFT 0.37 and 0.38 response types */\nexport type ModeTaggedEvent = {\n attributes: readonly {\n key: Uint8Array | string\n value: Uint8Array | string\n }[]\n};\n\n/** Values Cosmos SDK 0.50+ stamps on `finalize_block_events` to mark their origin (baseapp.go) */\nexport type BlockEventMode = \"BeginBlock\" | \"EndBlock\";\n\nconst MODE_SPELLINGS: Record<BlockEventMode, readonly string[]> = {\n BeginBlock: [\"BeginBlock\", \"begin_block\"],\n EndBlock: [\"EndBlock\", \"end_block\"],\n};\n\n/**\n * Checks whether a finalize_block event carries the given `mode` attribute.\n * The SDK emits `mode=BeginBlock` / `mode=EndBlock`; the snake_case spellings\n * are accepted as well so forks that lowercase the value keep working.\n * @param event - Event with an attributes array\n * @param mode - Which phase of the block the event must belong to\n * @returns true when the event has a matching `mode` attribute\n */\nexport const hasBlockEventMode = (event: ModeTaggedEvent, mode: BlockEventMode): boolean => {\n const accepted = MODE_SPELLINGS[mode];\n return event.attributes.some(a => decodeAttr(a.key) === \"mode\" && accepted.includes(decodeAttr(a.value)));\n};\n\n/**\n * Returns a URL that is safe to log: the password part of any credentials is masked.\n * Strings that do not parse as a URL are returned unchanged.\n */\nexport const redactUrl = (url: string): string => {\n try {\n const parsed = new URL(url);\n if (parsed.password) {\n parsed.password = \"***\";\n }\n return parsed.toString();\n }\n catch (_e) {\n return url;\n }\n};\n"],"mappings":";;;;;;;;AAMA,MAAa,cAAc,MAA2B;AACpD,KAAI,OAAO,MAAM,SACf,QAAO;UAEA,aAAa,WACpB,QAAO,OAAO,KAAK,EAAE,CAAC,UAAU;KAGhC,QAAO;;AAeX,MAAMA,iBAA4D;CAChE,YAAY,CAAC,cAAc,cAAc;CACzC,UAAU,CAAC,YAAY,YAAY;CACpC;;;;;;;;;AAUD,MAAa,qBAAqB,OAAwB,SAAkC;CAC1F,MAAM,WAAW,eAAe;AAChC,QAAO,MAAM,WAAW,MAAK,MAAK,WAAW,EAAE,IAAI,KAAK,UAAU,SAAS,SAAS,WAAW,EAAE,MAAM,CAAC,CAAC;;;;;;AAO3G,MAAa,aAAa,QAAwB;AAChD,KAAI;EACF,MAAM,SAAS,IAAI,IAAI,IAAI;AAC3B,MAAI,OAAO,SACT,QAAO,WAAW;AAEpB,SAAO,OAAO,UAAU;UAEnB,IAAI;AACT,SAAO"}
|
package/dist/utils/text.d.cts
CHANGED
|
@@ -6,6 +6,29 @@
|
|
|
6
6
|
* @returns Decoded string value
|
|
7
7
|
*/
|
|
8
8
|
declare const decodeAttr: (x: Uint8Array | string) => string;
|
|
9
|
+
/** Minimal shape of an ABCI event, compatible with both CometBFT 0.37 and 0.38 response types */
|
|
10
|
+
type ModeTaggedEvent = {
|
|
11
|
+
attributes: readonly {
|
|
12
|
+
key: Uint8Array | string;
|
|
13
|
+
value: Uint8Array | string;
|
|
14
|
+
}[];
|
|
15
|
+
};
|
|
16
|
+
/** Values Cosmos SDK 0.50+ stamps on `finalize_block_events` to mark their origin (baseapp.go) */
|
|
17
|
+
type BlockEventMode = "BeginBlock" | "EndBlock";
|
|
18
|
+
/**
|
|
19
|
+
* Checks whether a finalize_block event carries the given `mode` attribute.
|
|
20
|
+
* The SDK emits `mode=BeginBlock` / `mode=EndBlock`; the snake_case spellings
|
|
21
|
+
* are accepted as well so forks that lowercase the value keep working.
|
|
22
|
+
* @param event - Event with an attributes array
|
|
23
|
+
* @param mode - Which phase of the block the event must belong to
|
|
24
|
+
* @returns true when the event has a matching `mode` attribute
|
|
25
|
+
*/
|
|
26
|
+
declare const hasBlockEventMode: (event: ModeTaggedEvent, mode: BlockEventMode) => boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Returns a URL that is safe to log: the password part of any credentials is masked.
|
|
29
|
+
* Strings that do not parse as a URL are returned unchanged.
|
|
30
|
+
*/
|
|
31
|
+
declare const redactUrl: (url: string) => string;
|
|
9
32
|
//#endregion
|
|
10
|
-
export { decodeAttr };
|
|
33
|
+
export { BlockEventMode, ModeTaggedEvent, decodeAttr, hasBlockEventMode, redactUrl };
|
|
11
34
|
//# sourceMappingURL=text.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.d.cts","names":[],"sources":["../../src/utils/text.ts"],"sourcesContent":[],"mappings":";;AAMA
|
|
1
|
+
{"version":3,"file":"text.d.cts","names":[],"sources":["../../src/utils/text.ts"],"sourcesContent":[],"mappings":";;AAMA;AAaA;AAQA;AAeA;AASA;cA7Ca,gBAAiB;;KAalB,eAAA;;SAEH;WACE;;;;KAKC,cAAA;;;;;;;;;cAeC,2BAA4B,uBAAuB;;;;;cASnD"}
|
package/dist/utils/text.d.mts
CHANGED
|
@@ -6,6 +6,29 @@
|
|
|
6
6
|
* @returns Decoded string value
|
|
7
7
|
*/
|
|
8
8
|
declare const decodeAttr: (x: Uint8Array | string) => string;
|
|
9
|
+
/** Minimal shape of an ABCI event, compatible with both CometBFT 0.37 and 0.38 response types */
|
|
10
|
+
type ModeTaggedEvent = {
|
|
11
|
+
attributes: readonly {
|
|
12
|
+
key: Uint8Array | string;
|
|
13
|
+
value: Uint8Array | string;
|
|
14
|
+
}[];
|
|
15
|
+
};
|
|
16
|
+
/** Values Cosmos SDK 0.50+ stamps on `finalize_block_events` to mark their origin (baseapp.go) */
|
|
17
|
+
type BlockEventMode = "BeginBlock" | "EndBlock";
|
|
18
|
+
/**
|
|
19
|
+
* Checks whether a finalize_block event carries the given `mode` attribute.
|
|
20
|
+
* The SDK emits `mode=BeginBlock` / `mode=EndBlock`; the snake_case spellings
|
|
21
|
+
* are accepted as well so forks that lowercase the value keep working.
|
|
22
|
+
* @param event - Event with an attributes array
|
|
23
|
+
* @param mode - Which phase of the block the event must belong to
|
|
24
|
+
* @returns true when the event has a matching `mode` attribute
|
|
25
|
+
*/
|
|
26
|
+
declare const hasBlockEventMode: (event: ModeTaggedEvent, mode: BlockEventMode) => boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Returns a URL that is safe to log: the password part of any credentials is masked.
|
|
29
|
+
* Strings that do not parse as a URL are returned unchanged.
|
|
30
|
+
*/
|
|
31
|
+
declare const redactUrl: (url: string) => string;
|
|
9
32
|
//#endregion
|
|
10
|
-
export { decodeAttr };
|
|
33
|
+
export { BlockEventMode, ModeTaggedEvent, decodeAttr, hasBlockEventMode, redactUrl };
|
|
11
34
|
//# sourceMappingURL=text.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.d.mts","names":[],"sources":["../../src/utils/text.ts"],"sourcesContent":[],"mappings":";;AAMA
|
|
1
|
+
{"version":3,"file":"text.d.mts","names":[],"sources":["../../src/utils/text.ts"],"sourcesContent":[],"mappings":";;AAMA;AAaA;AAQA;AAeA;AASA;cA7Ca,gBAAiB;;KAalB,eAAA;;SAEH;WACE;;;;KAKC,cAAA;;;;;;;;;cAeC,2BAA4B,uBAAuB;;;;;cASnD"}
|
package/dist/utils/text.mjs
CHANGED
|
@@ -10,7 +10,36 @@ const decodeAttr = (x) => {
|
|
|
10
10
|
else if (x instanceof Uint8Array) return Buffer.from(x).toString();
|
|
11
11
|
else return "";
|
|
12
12
|
};
|
|
13
|
+
const MODE_SPELLINGS = {
|
|
14
|
+
BeginBlock: ["BeginBlock", "begin_block"],
|
|
15
|
+
EndBlock: ["EndBlock", "end_block"]
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Checks whether a finalize_block event carries the given `mode` attribute.
|
|
19
|
+
* The SDK emits `mode=BeginBlock` / `mode=EndBlock`; the snake_case spellings
|
|
20
|
+
* are accepted as well so forks that lowercase the value keep working.
|
|
21
|
+
* @param event - Event with an attributes array
|
|
22
|
+
* @param mode - Which phase of the block the event must belong to
|
|
23
|
+
* @returns true when the event has a matching `mode` attribute
|
|
24
|
+
*/
|
|
25
|
+
const hasBlockEventMode = (event, mode) => {
|
|
26
|
+
const accepted = MODE_SPELLINGS[mode];
|
|
27
|
+
return event.attributes.some((a) => decodeAttr(a.key) === "mode" && accepted.includes(decodeAttr(a.value)));
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Returns a URL that is safe to log: the password part of any credentials is masked.
|
|
31
|
+
* Strings that do not parse as a URL are returned unchanged.
|
|
32
|
+
*/
|
|
33
|
+
const redactUrl = (url) => {
|
|
34
|
+
try {
|
|
35
|
+
const parsed = new URL(url);
|
|
36
|
+
if (parsed.password) parsed.password = "***";
|
|
37
|
+
return parsed.toString();
|
|
38
|
+
} catch (_e) {
|
|
39
|
+
return url;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
13
42
|
|
|
14
43
|
//#endregion
|
|
15
|
-
export { decodeAttr };
|
|
44
|
+
export { decodeAttr, hasBlockEventMode, redactUrl };
|
|
16
45
|
//# sourceMappingURL=text.mjs.map
|
package/dist/utils/text.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.mjs","names":[],"sources":["../../src/utils/text.ts"],"sourcesContent":["/**\n * Decodes blockchain event attributes from various formats to strings\n * Handles both string and Uint8Array inputs from Tendermint events\n * @param x - The attribute value to decode (string or Uint8Array)\n * @returns Decoded string value\n */\nexport const decodeAttr = (x: Uint8Array | string) => {\n if (typeof x === \"string\") {\n return x;\n }\n else if (x instanceof Uint8Array) {\n return Buffer.from(x).toString();\n }\n else {\n return \"\";\n }\n};\n"],"mappings":";;;;;;;AAMA,MAAa,cAAc,MAA2B;AACpD,KAAI,OAAO,MAAM,SACf,QAAO;UAEA,aAAa,WACpB,QAAO,OAAO,KAAK,EAAE,CAAC,UAAU;KAGhC,QAAO"}
|
|
1
|
+
{"version":3,"file":"text.mjs","names":["MODE_SPELLINGS: Record<BlockEventMode, readonly string[]>"],"sources":["../../src/utils/text.ts"],"sourcesContent":["/**\n * Decodes blockchain event attributes from various formats to strings\n * Handles both string and Uint8Array inputs from Tendermint events\n * @param x - The attribute value to decode (string or Uint8Array)\n * @returns Decoded string value\n */\nexport const decodeAttr = (x: Uint8Array | string) => {\n if (typeof x === \"string\") {\n return x;\n }\n else if (x instanceof Uint8Array) {\n return Buffer.from(x).toString();\n }\n else {\n return \"\";\n }\n};\n\n/** Minimal shape of an ABCI event, compatible with both CometBFT 0.37 and 0.38 response types */\nexport type ModeTaggedEvent = {\n attributes: readonly {\n key: Uint8Array | string\n value: Uint8Array | string\n }[]\n};\n\n/** Values Cosmos SDK 0.50+ stamps on `finalize_block_events` to mark their origin (baseapp.go) */\nexport type BlockEventMode = \"BeginBlock\" | \"EndBlock\";\n\nconst MODE_SPELLINGS: Record<BlockEventMode, readonly string[]> = {\n BeginBlock: [\"BeginBlock\", \"begin_block\"],\n EndBlock: [\"EndBlock\", \"end_block\"],\n};\n\n/**\n * Checks whether a finalize_block event carries the given `mode` attribute.\n * The SDK emits `mode=BeginBlock` / `mode=EndBlock`; the snake_case spellings\n * are accepted as well so forks that lowercase the value keep working.\n * @param event - Event with an attributes array\n * @param mode - Which phase of the block the event must belong to\n * @returns true when the event has a matching `mode` attribute\n */\nexport const hasBlockEventMode = (event: ModeTaggedEvent, mode: BlockEventMode): boolean => {\n const accepted = MODE_SPELLINGS[mode];\n return event.attributes.some(a => decodeAttr(a.key) === \"mode\" && accepted.includes(decodeAttr(a.value)));\n};\n\n/**\n * Returns a URL that is safe to log: the password part of any credentials is masked.\n * Strings that do not parse as a URL are returned unchanged.\n */\nexport const redactUrl = (url: string): string => {\n try {\n const parsed = new URL(url);\n if (parsed.password) {\n parsed.password = \"***\";\n }\n return parsed.toString();\n }\n catch (_e) {\n return url;\n }\n};\n"],"mappings":";;;;;;;AAMA,MAAa,cAAc,MAA2B;AACpD,KAAI,OAAO,MAAM,SACf,QAAO;UAEA,aAAa,WACpB,QAAO,OAAO,KAAK,EAAE,CAAC,UAAU;KAGhC,QAAO;;AAeX,MAAMA,iBAA4D;CAChE,YAAY,CAAC,cAAc,cAAc;CACzC,UAAU,CAAC,YAAY,YAAY;CACpC;;;;;;;;;AAUD,MAAa,qBAAqB,OAAwB,SAAkC;CAC1F,MAAM,WAAW,eAAe;AAChC,QAAO,MAAM,WAAW,MAAK,MAAK,WAAW,EAAE,IAAI,KAAK,UAAU,SAAS,SAAS,WAAW,EAAE,MAAM,CAAC,CAAC;;;;;;AAO3G,MAAa,aAAa,QAAwB;AAChD,KAAI;EACF,MAAM,SAAS,IAAI,IAAI,IAAI;AAC3B,MAAI,OAAO,SACT,QAAO,WAAW;AAEpB,SAAO,OAAO,UAAU;UAEnB,IAAI;AACT,SAAO"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/utils/timeout.ts
|
|
3
|
+
/**
|
|
4
|
+
* Races a promise against a timer and clears the timer however the race settles,
|
|
5
|
+
* so a finished operation never leaves a pending timeout keeping the event loop alive.
|
|
6
|
+
* @param promise - The operation to bound
|
|
7
|
+
* @param ms - Milliseconds to wait before rejecting
|
|
8
|
+
* @param error - Error to reject with when the timer wins
|
|
9
|
+
* @returns The promise's value, or a rejection with `error` on timeout
|
|
10
|
+
*/
|
|
11
|
+
const withTimeout = (promise, ms, error) => {
|
|
12
|
+
let handle;
|
|
13
|
+
const timeout = new Promise((_resolve, reject) => {
|
|
14
|
+
handle = setTimeout(() => reject(error), ms);
|
|
15
|
+
});
|
|
16
|
+
return Promise.race([promise, timeout]).finally(() => {
|
|
17
|
+
if (handle) clearTimeout(handle);
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Restart delay for the n-th consecutive failure: exponential from `baseMs`, capped at `maxMs`.
|
|
22
|
+
* @param attempt - 1 for the first restart, 2 for the second, and so on
|
|
23
|
+
*/
|
|
24
|
+
const retryDelay = (attempt, baseMs, maxMs) => {
|
|
25
|
+
const exponent = Math.max(0, attempt - 1);
|
|
26
|
+
return Math.min(baseMs * Math.pow(2, exponent), maxMs);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
exports.retryDelay = retryDelay;
|
|
31
|
+
exports.withTimeout = withTimeout;
|
|
32
|
+
//# sourceMappingURL=timeout.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout.cjs","names":["handle: NodeJS.Timeout | undefined"],"sources":["../../src/utils/timeout.ts"],"sourcesContent":["/**\n * Races a promise against a timer and clears the timer however the race settles,\n * so a finished operation never leaves a pending timeout keeping the event loop alive.\n * @param promise - The operation to bound\n * @param ms - Milliseconds to wait before rejecting\n * @param error - Error to reject with when the timer wins\n * @returns The promise's value, or a rejection with `error` on timeout\n */\nexport const withTimeout = <T>(promise: Promise<T>, ms: number, error: Error): Promise<T> => {\n let handle: NodeJS.Timeout | undefined;\n const timeout = new Promise<never>((_resolve, reject) => {\n handle = setTimeout(() => reject(error), ms);\n });\n return Promise.race([promise, timeout]).finally(() => {\n if (handle) {\n clearTimeout(handle);\n }\n });\n};\n\n/**\n * Restart delay for the n-th consecutive failure: exponential from `baseMs`, capped at `maxMs`.\n * @param attempt - 1 for the first restart, 2 for the second, and so on\n */\nexport const retryDelay = (attempt: number, baseMs: number, maxMs: number): number => {\n const exponent = Math.max(0, attempt - 1);\n return Math.min(baseMs * Math.pow(2, exponent), maxMs);\n};\n"],"mappings":";;;;;;;;;;AAQA,MAAa,eAAkB,SAAqB,IAAY,UAA6B;CAC3F,IAAIA;CACJ,MAAM,UAAU,IAAI,SAAgB,UAAU,WAAW;AACvD,WAAS,iBAAiB,OAAO,MAAM,EAAE,GAAG;GAC5C;AACF,QAAO,QAAQ,KAAK,CAAC,SAAS,QAAQ,CAAC,CAAC,cAAc;AACpD,MAAI,OACF,cAAa,OAAO;GAEtB;;;;;;AAOJ,MAAa,cAAc,SAAiB,QAAgB,UAA0B;CACpF,MAAM,WAAW,KAAK,IAAI,GAAG,UAAU,EAAE;AACzC,QAAO,KAAK,IAAI,SAAS,KAAK,IAAI,GAAG,SAAS,EAAE,MAAM"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/utils/timeout.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Races a promise against a timer and clears the timer however the race settles,
|
|
4
|
+
* so a finished operation never leaves a pending timeout keeping the event loop alive.
|
|
5
|
+
* @param promise - The operation to bound
|
|
6
|
+
* @param ms - Milliseconds to wait before rejecting
|
|
7
|
+
* @param error - Error to reject with when the timer wins
|
|
8
|
+
* @returns The promise's value, or a rejection with `error` on timeout
|
|
9
|
+
*/
|
|
10
|
+
declare const withTimeout: <T>(promise: Promise<T>, ms: number, error: Error) => Promise<T>;
|
|
11
|
+
/**
|
|
12
|
+
* Restart delay for the n-th consecutive failure: exponential from `baseMs`, capped at `maxMs`.
|
|
13
|
+
* @param attempt - 1 for the first restart, 2 for the second, and so on
|
|
14
|
+
*/
|
|
15
|
+
declare const retryDelay: (attempt: number, baseMs: number, maxMs: number) => number;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { retryDelay, withTimeout };
|
|
18
|
+
//# sourceMappingURL=timeout.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout.d.cts","names":[],"sources":["../../src/utils/timeout.ts"],"sourcesContent":[],"mappings":";;AAQA;;;;;;;AAgBa,cAhBA,WAmBZ,EAAA,CAAA,CAAA,CAAA,CAAA,OAAA,EAnBuC,OAmBvC,CAnB+C,CAmB/C,CAAA,EAAA,EAAA,EAAA,MAAA,EAAA,KAAA,EAnBsE,KAmBtE,EAAA,GAnB8E,OAmB9E,CAnBsF,CAmBtF,CAAA;;;;;cAHY"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/utils/timeout.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Races a promise against a timer and clears the timer however the race settles,
|
|
4
|
+
* so a finished operation never leaves a pending timeout keeping the event loop alive.
|
|
5
|
+
* @param promise - The operation to bound
|
|
6
|
+
* @param ms - Milliseconds to wait before rejecting
|
|
7
|
+
* @param error - Error to reject with when the timer wins
|
|
8
|
+
* @returns The promise's value, or a rejection with `error` on timeout
|
|
9
|
+
*/
|
|
10
|
+
declare const withTimeout: <T>(promise: Promise<T>, ms: number, error: Error) => Promise<T>;
|
|
11
|
+
/**
|
|
12
|
+
* Restart delay for the n-th consecutive failure: exponential from `baseMs`, capped at `maxMs`.
|
|
13
|
+
* @param attempt - 1 for the first restart, 2 for the second, and so on
|
|
14
|
+
*/
|
|
15
|
+
declare const retryDelay: (attempt: number, baseMs: number, maxMs: number) => number;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { retryDelay, withTimeout };
|
|
18
|
+
//# sourceMappingURL=timeout.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout.d.mts","names":[],"sources":["../../src/utils/timeout.ts"],"sourcesContent":[],"mappings":";;AAQA;;;;;;;AAgBa,cAhBA,WAmBZ,EAAA,CAAA,CAAA,CAAA,CAAA,OAAA,EAnBuC,OAmBvC,CAnB+C,CAmB/C,CAAA,EAAA,EAAA,EAAA,MAAA,EAAA,KAAA,EAnBsE,KAmBtE,EAAA,GAnB8E,OAmB9E,CAnBsF,CAmBtF,CAAA;;;;;cAHY"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/utils/timeout.ts
|
|
2
|
+
/**
|
|
3
|
+
* Races a promise against a timer and clears the timer however the race settles,
|
|
4
|
+
* so a finished operation never leaves a pending timeout keeping the event loop alive.
|
|
5
|
+
* @param promise - The operation to bound
|
|
6
|
+
* @param ms - Milliseconds to wait before rejecting
|
|
7
|
+
* @param error - Error to reject with when the timer wins
|
|
8
|
+
* @returns The promise's value, or a rejection with `error` on timeout
|
|
9
|
+
*/
|
|
10
|
+
const withTimeout = (promise, ms, error) => {
|
|
11
|
+
let handle;
|
|
12
|
+
const timeout = new Promise((_resolve, reject) => {
|
|
13
|
+
handle = setTimeout(() => reject(error), ms);
|
|
14
|
+
});
|
|
15
|
+
return Promise.race([promise, timeout]).finally(() => {
|
|
16
|
+
if (handle) clearTimeout(handle);
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Restart delay for the n-th consecutive failure: exponential from `baseMs`, capped at `maxMs`.
|
|
21
|
+
* @param attempt - 1 for the first restart, 2 for the second, and so on
|
|
22
|
+
*/
|
|
23
|
+
const retryDelay = (attempt, baseMs, maxMs) => {
|
|
24
|
+
const exponent = Math.max(0, attempt - 1);
|
|
25
|
+
return Math.min(baseMs * Math.pow(2, exponent), maxMs);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { retryDelay, withTimeout };
|
|
30
|
+
//# sourceMappingURL=timeout.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout.mjs","names":["handle: NodeJS.Timeout | undefined"],"sources":["../../src/utils/timeout.ts"],"sourcesContent":["/**\n * Races a promise against a timer and clears the timer however the race settles,\n * so a finished operation never leaves a pending timeout keeping the event loop alive.\n * @param promise - The operation to bound\n * @param ms - Milliseconds to wait before rejecting\n * @param error - Error to reject with when the timer wins\n * @returns The promise's value, or a rejection with `error` on timeout\n */\nexport const withTimeout = <T>(promise: Promise<T>, ms: number, error: Error): Promise<T> => {\n let handle: NodeJS.Timeout | undefined;\n const timeout = new Promise<never>((_resolve, reject) => {\n handle = setTimeout(() => reject(error), ms);\n });\n return Promise.race([promise, timeout]).finally(() => {\n if (handle) {\n clearTimeout(handle);\n }\n });\n};\n\n/**\n * Restart delay for the n-th consecutive failure: exponential from `baseMs`, capped at `maxMs`.\n * @param attempt - 1 for the first restart, 2 for the second, and so on\n */\nexport const retryDelay = (attempt: number, baseMs: number, maxMs: number): number => {\n const exponent = Math.max(0, attempt - 1);\n return Math.min(baseMs * Math.pow(2, exponent), maxMs);\n};\n"],"mappings":";;;;;;;;;AAQA,MAAa,eAAkB,SAAqB,IAAY,UAA6B;CAC3F,IAAIA;CACJ,MAAM,UAAU,IAAI,SAAgB,UAAU,WAAW;AACvD,WAAS,iBAAiB,OAAO,MAAM,EAAE,GAAG;GAC5C;AACF,QAAO,QAAQ,KAAK,CAAC,SAAS,QAAQ,CAAC,CAAC,cAAc;AACpD,MAAI,OACF,cAAa,OAAO;GAEtB;;;;;;AAOJ,MAAa,cAAc,SAAiB,QAAgB,UAA0B;CACpF,MAAM,WAAW,KAAK,IAAI,GAAG,UAAU,EAAE;AACzC,QAAO,KAAK,IAAI,SAAS,KAAK,IAAI,GAAG,SAAS,EAAE,MAAM"}
|