@talismn/util 1.1.0 → 2.0.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/LICENSE +253 -674
- package/dist/index.d.mts +339 -94
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +338 -93
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +894 -450
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +814 -385
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -7
package/dist/index.d.mts
CHANGED
|
@@ -1,19 +1,144 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import BigNumber$1 from "bignumber.js";
|
|
2
|
+
import { Observable, OperatorFunction, ReplaySubject, Subject } from "rxjs";
|
|
3
|
+
//#region src/addTrailingSlash.d.ts
|
|
4
4
|
declare const addTrailingSlash: (url: string) => string;
|
|
5
|
-
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/assert.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* @name assert
|
|
9
|
+
* @description Throws an Error with the given message if the condition is falsy.
|
|
10
|
+
* @example
|
|
11
|
+
* assert(chain, "Chain not found")
|
|
12
|
+
**/
|
|
13
|
+
declare function assert(condition: unknown, message: string | (() => string)): asserts condition;
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/BigMath.d.ts
|
|
6
16
|
/**
|
|
7
17
|
* Javascript's `Math` library for `BigInt`.
|
|
8
18
|
* Taken from https://stackoverflow.com/questions/51867270/is-there-a-library-similar-to-math-that-supports-javascript-bigint/64953280#64953280
|
|
9
19
|
*/
|
|
10
20
|
declare const BigMath: {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
21
|
+
abs(x: bigint): bigint;
|
|
22
|
+
sign(x: bigint): 0n | 1n | -1n;
|
|
23
|
+
min(value: bigint, ...values: bigint[]): bigint;
|
|
24
|
+
max(value: bigint, ...values: bigint[]): bigint;
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/isHexString.d.ts
|
|
28
|
+
type HexString = `0x${string}`;
|
|
29
|
+
declare const REGEX_HEX_STRING: RegExp;
|
|
30
|
+
declare const isHexString: (value: unknown) => value is HexString;
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/bytes.d.ts
|
|
33
|
+
/**
|
|
34
|
+
* Byte / hex primitives, drop-in equivalents of the `@polkadot/util` helpers we used to depend on.
|
|
35
|
+
* Semantics intentionally match polkadot-js for migration safety.
|
|
36
|
+
*/
|
|
37
|
+
declare const hexToU8a: (hex?: string | null) => Uint8Array;
|
|
38
|
+
declare const u8aToHex: (value?: Uint8Array | null) => HexString;
|
|
39
|
+
declare const stringToU8a: (value?: string | null) => Uint8Array;
|
|
40
|
+
declare const u8aToString: (value?: Uint8Array | null) => string;
|
|
41
|
+
declare const hexToString: (hex?: string | null) => string;
|
|
42
|
+
declare const hexToNumber: (hex?: string | null) => number;
|
|
43
|
+
declare const numberToU8a: (value?: number | null) => Uint8Array;
|
|
44
|
+
/** Coerces hex strings, utf-8 strings, number arrays and buffers to Uint8Array (polkadot-js semantics) */
|
|
45
|
+
declare const u8aToU8a: (value?: string | number[] | Uint8Array | null) => Uint8Array;
|
|
46
|
+
declare const u8aConcat: (...items: (string | number[] | Uint8Array)[]) => Uint8Array;
|
|
47
|
+
declare const u8aEq: (a: string | Uint8Array, b: string | Uint8Array) => boolean;
|
|
48
|
+
declare const u8aCmp: (a: string | Uint8Array, b: string | Uint8Array) => number;
|
|
49
|
+
/**
|
|
50
|
+
* Tests if the input is printable ASCII (code points 32-126). Hex strings are decoded to bytes
|
|
51
|
+
* first, other strings are checked character-wise (polkadot-js `isAscii` semantics).
|
|
52
|
+
*/
|
|
53
|
+
declare const isAsciiPrintable: (value?: string | Uint8Array | null) => boolean;
|
|
54
|
+
/** Wraps bytes with `<Bytes>...</Bytes>` for raw-message signing, unless already wrapped */
|
|
55
|
+
declare const u8aWrapBytes: (value: string | Uint8Array) => Uint8Array;
|
|
56
|
+
declare const u8aUnwrapBytes: (value: string | Uint8Array) => Uint8Array;
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/timeSlicer.d.ts
|
|
59
|
+
/**
|
|
60
|
+
* Default CPU budget for a single synchronous slice of chunked work.
|
|
61
|
+
* ~50-60% of a 60fps frame, leaving the rest for the host (user interactions, rendering).
|
|
62
|
+
*/
|
|
63
|
+
declare const DEFAULT_TIME_SLICE_BUDGET_MS = 10;
|
|
64
|
+
type TimeSlicerOptions = {
|
|
65
|
+
/** max synchronous work per slice, in milliseconds (default: DEFAULT_TIME_SLICE_BUDGET_MS) */
|
|
66
|
+
budgetMs?: number;
|
|
67
|
+
/** aborting this signal makes the slicer throw an AbortError at its next check point */
|
|
68
|
+
signal?: AbortSignal;
|
|
69
|
+
/** injectable clock for tests; defaults to performance.now, falling back to Date.now */
|
|
70
|
+
now?: () => number;
|
|
71
|
+
/** identifies this slicer in host JS-activity reports (see jsActivityHook) */
|
|
72
|
+
label?: string;
|
|
15
73
|
};
|
|
16
|
-
|
|
74
|
+
type TimeSlicer = {
|
|
75
|
+
readonly signal?: AbortSignal;
|
|
76
|
+
/** true when the current slice has consumed its budget */
|
|
77
|
+
shouldYield(): boolean;
|
|
78
|
+
/** unconditionally macrotask-yield, reset the slice, then throw if aborted */
|
|
79
|
+
yield(): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Call between work items. Returns `undefined` (no promise, no microtask) while within
|
|
82
|
+
* budget, so hot loops stay cheap:
|
|
83
|
+
*
|
|
84
|
+
* ```ts
|
|
85
|
+
* const yielded = slicer.yieldIfNeeded()
|
|
86
|
+
* if (yielded) await yielded
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* Throws synchronously if the signal is aborted.
|
|
90
|
+
*/
|
|
91
|
+
yieldIfNeeded(): Promise<void> | undefined;
|
|
92
|
+
/** throws an Error with name "AbortError" (recognized by isAbortError) if the signal is aborted */
|
|
93
|
+
throwIfAborted(): void;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Creates an AbortError-style error without relying on DOMException (not available on Hermes).
|
|
97
|
+
* Recognized by `isAbortError` from this package.
|
|
98
|
+
*/
|
|
99
|
+
declare const newAbortError: () => Error;
|
|
100
|
+
/**
|
|
101
|
+
* Tracks a time budget for cooperative scheduling: run synchronous work until the budget
|
|
102
|
+
* for the current slice is exhausted, then yield the thread back to the host event loop
|
|
103
|
+
* before continuing.
|
|
104
|
+
*
|
|
105
|
+
* A single slicer can be shared across multiple phases of work so the budget spans them.
|
|
106
|
+
*/
|
|
107
|
+
declare const createTimeSlicer: ({ budgetMs, signal, now, label }?: TimeSlicerOptions) => TimeSlicer;
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/chunkedArray.d.ts
|
|
110
|
+
type ChunkedOptions = {
|
|
111
|
+
/** max synchronous work per slice, in milliseconds (ignored when `slicer` is provided) */
|
|
112
|
+
budgetMs?: number;
|
|
113
|
+
/** abort in-flight work; the returned promise rejects with an AbortError (ignored when `slicer` is provided) */
|
|
114
|
+
signal?: AbortSignal;
|
|
115
|
+
/** share one slicer across multiple phases of work so the time budget spans them */
|
|
116
|
+
slicer?: TimeSlicer;
|
|
117
|
+
/** identifies this work in host JS-activity reports (ignored when `slicer` is provided) */
|
|
118
|
+
label?: string;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* `Array.prototype.forEach`, chunked: iterates synchronously until the time budget is
|
|
122
|
+
* exhausted, then yields the thread to the host event loop before continuing.
|
|
123
|
+
*
|
|
124
|
+
* Errors thrown by `fn` reject the promise; aborting rejects with an AbortError at the
|
|
125
|
+
* next between-items check point.
|
|
126
|
+
*/
|
|
127
|
+
declare const forEachWithYield: <T>(items: readonly T[], fn: (item: T, index: number) => void, options?: ChunkedOptions) => Promise<void>;
|
|
128
|
+
/** `Array.prototype.map`, chunked (see forEachWithYield for semantics) */
|
|
129
|
+
declare const mapWithYield: <T, R>(items: readonly T[], fn: (item: T, index: number) => R, options?: ChunkedOptions) => Promise<R[]>;
|
|
130
|
+
/** lodash `keyBy`, chunked (see forEachWithYield for semantics) */
|
|
131
|
+
declare const keyByWithYield: <T>(items: readonly T[], keyFn: (item: T, index: number) => string, options?: ChunkedOptions) => Promise<Record<string, T>>;
|
|
132
|
+
/**
|
|
133
|
+
* Chunked equivalent of lodash `isEqual(a, b)` for arrays: `a === b` fast path, length
|
|
134
|
+
* check, then per-item `a[i] === b[i] || isItemEqual(a[i], b[i])` within the time budget.
|
|
135
|
+
* The result is identical to `isEqual(a, b)`.
|
|
136
|
+
*/
|
|
137
|
+
declare const arrayItemsEqualWithYield: <T>(a: readonly T[] | undefined, b: readonly T[] | undefined, options?: ChunkedOptions & {
|
|
138
|
+
isItemEqual?: (x: T, y: T) => boolean;
|
|
139
|
+
}) => Promise<boolean>;
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/deferred.d.ts
|
|
17
142
|
/**
|
|
18
143
|
* In TypeScript, a deferred promise refers to a pattern that involves creating a promise that can be
|
|
19
144
|
* resolved or rejected at a later point in time, typically by code outside of the current function scope.
|
|
@@ -22,24 +147,22 @@ declare const BigMath: {
|
|
|
22
147
|
* the result of an operation cannot be immediately determined.
|
|
23
148
|
*/
|
|
24
149
|
declare function Deferred<T>(): {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
150
|
+
promise: Promise<T>;
|
|
151
|
+
resolve: (value: T | PromiseLike<T>) => void;
|
|
152
|
+
reject: (reason?: unknown) => void;
|
|
153
|
+
isPending: () => boolean;
|
|
154
|
+
isResolved: () => boolean;
|
|
155
|
+
isRejected: () => boolean;
|
|
31
156
|
};
|
|
32
|
-
|
|
157
|
+
//#endregion
|
|
158
|
+
//#region src/FunctionPropertyNames.d.ts
|
|
33
159
|
/** biome-ignore-all lint/complexity/noBannedTypes: legacy */
|
|
34
|
-
type FunctionPropertyNames<T> = {
|
|
35
|
-
[K in keyof T]: T[K] extends Function ? K : never;
|
|
36
|
-
}[keyof T];
|
|
160
|
+
type FunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T];
|
|
37
161
|
type FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>>;
|
|
38
|
-
type NonFunctionPropertyNames<T> = {
|
|
39
|
-
[K in keyof T]: T[K] extends Function ? never : K;
|
|
40
|
-
}[keyof T];
|
|
162
|
+
type NonFunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T];
|
|
41
163
|
type NonFunctionProperties<T> = Pick<T, NonFunctionPropertyNames<T>>;
|
|
42
|
-
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region src/firstThenDebounce.d.ts
|
|
43
166
|
/**
|
|
44
167
|
* An rxjs operator which:
|
|
45
168
|
*
|
|
@@ -47,7 +170,8 @@ type NonFunctionProperties<T> = Pick<T, NonFunctionPropertyNames<T>>;
|
|
|
47
170
|
* 2. Debounces any future values by `timeout` ms.
|
|
48
171
|
*/
|
|
49
172
|
declare const firstThenDebounce: <T>(timeout: number) => OperatorFunction<T, T>;
|
|
50
|
-
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region src/formatDecimals.d.ts
|
|
51
175
|
declare const MAX_DECIMALS_FORMAT = 12;
|
|
52
176
|
/**
|
|
53
177
|
* Custom decimal number formatting for Talisman
|
|
@@ -58,40 +182,43 @@ declare const MAX_DECIMALS_FORMAT = 12;
|
|
|
58
182
|
* @param options formatting options
|
|
59
183
|
* @returns the formatted value
|
|
60
184
|
*/
|
|
61
|
-
declare const formatDecimals: (num?: string | number | null | BigNumber, digits?: number, options?: Partial<Intl.NumberFormatOptions>, locale?: string) => string;
|
|
62
|
-
|
|
185
|
+
declare const formatDecimals: (num?: string | number | null | BigNumber$1, digits?: number, options?: Partial<Intl.NumberFormatOptions>, locale?: string) => string;
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region src/formatPrice.d.ts
|
|
63
188
|
declare const formatPrice: (price: number, currency: string, compact: boolean) => string;
|
|
64
|
-
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/getLoadable.d.ts
|
|
65
191
|
type LoadableError = {
|
|
66
|
-
|
|
67
|
-
|
|
192
|
+
name: string;
|
|
193
|
+
message: string;
|
|
68
194
|
};
|
|
69
195
|
type Loadable<T = unknown> = {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
196
|
+
status: "loading";
|
|
197
|
+
data?: T;
|
|
198
|
+
error?: undefined;
|
|
73
199
|
} | {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
200
|
+
status: "success";
|
|
201
|
+
data: T;
|
|
202
|
+
error?: undefined;
|
|
77
203
|
} | {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
204
|
+
status: "error";
|
|
205
|
+
data?: T;
|
|
206
|
+
error: LoadableError;
|
|
81
207
|
};
|
|
82
208
|
type LoadableStatus = Loadable["status"];
|
|
83
209
|
type LoadableOptions = {
|
|
84
|
-
|
|
85
|
-
|
|
210
|
+
getError?: (error: unknown) => LoadableError;
|
|
211
|
+
refreshInterval?: number;
|
|
86
212
|
};
|
|
87
213
|
declare function getLoadable$<T>(factory: () => Promise<T>, options?: LoadableOptions): Observable<Loadable<T>>;
|
|
88
|
-
|
|
214
|
+
//#endregion
|
|
215
|
+
//#region src/getLoadableQuery.d.ts
|
|
89
216
|
type GetLoadableQueryParams<TArgs extends unknown[], TResult> = {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
217
|
+
namespace: string;
|
|
218
|
+
args: TArgs;
|
|
219
|
+
queryFn: (args: TArgs, signal: AbortSignal) => Promise<TResult>;
|
|
220
|
+
refreshInterval?: number;
|
|
221
|
+
defaultValue?: TResult;
|
|
95
222
|
};
|
|
96
223
|
/**
|
|
97
224
|
* Thin wrapper around getQuery$ that returns Loadable<T> and optionally
|
|
@@ -100,28 +227,29 @@ type GetLoadableQueryParams<TArgs extends unknown[], TResult> = {
|
|
|
100
227
|
* TODO: consolidate with getQuery$
|
|
101
228
|
*/
|
|
102
229
|
declare const getLoadableQuery$: <TArgs extends unknown[], TResult>(params: GetLoadableQueryParams<TArgs, TResult>) => Observable<Loadable<TResult>>;
|
|
103
|
-
|
|
230
|
+
//#endregion
|
|
231
|
+
//#region src/getQuery.d.ts
|
|
104
232
|
type QueryStatus = "loading" | "loaded" | "error";
|
|
105
233
|
type QueryResult<T, S extends QueryStatus = "loading" | "loaded" | "error"> = S extends "loading" ? {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
234
|
+
status: "loading";
|
|
235
|
+
data: T | undefined;
|
|
236
|
+
error: undefined;
|
|
109
237
|
} : S extends "loaded" ? {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
238
|
+
status: "loaded";
|
|
239
|
+
data: T;
|
|
240
|
+
error: undefined;
|
|
113
241
|
} : {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
242
|
+
status: "error";
|
|
243
|
+
data: undefined;
|
|
244
|
+
error: unknown;
|
|
117
245
|
};
|
|
118
246
|
type QueryOptions<Output, Args> = {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
247
|
+
namespace: string;
|
|
248
|
+
args: Args;
|
|
249
|
+
queryFn: (args: Args, signal: AbortSignal) => Promise<Output>;
|
|
250
|
+
defaultValue?: Output;
|
|
251
|
+
refreshInterval?: number;
|
|
252
|
+
serializer?: (args: Args) => string;
|
|
125
253
|
};
|
|
126
254
|
/**
|
|
127
255
|
* Creates a shared observable for executing queries with caching, loading states, and automatic refresh capabilities.
|
|
@@ -145,13 +273,18 @@ type QueryOptions<Output, Args> = {
|
|
|
145
273
|
*
|
|
146
274
|
* @deprecated use getLoadableQuery$ instead
|
|
147
275
|
*/
|
|
148
|
-
declare const getQuery$: <Output, Args>({ namespace, args, queryFn, defaultValue, refreshInterval, serializer
|
|
149
|
-
|
|
276
|
+
declare const getQuery$: <Output, Args>({ namespace, args, queryFn, defaultValue, refreshInterval, serializer }: QueryOptions<Output, Args>) => Observable<QueryResult<Output>>;
|
|
277
|
+
//#endregion
|
|
278
|
+
//#region src/getSharedObservable.d.ts
|
|
150
279
|
/**
|
|
151
280
|
* When using react-rxjs hooks and state observables, the options are used as weak map keys.
|
|
152
281
|
* This means that if the options object is recreated on each render, the observable will be recreated as well.
|
|
153
282
|
* This utility function allows you to create a shared observable based on a namespace and arguments that, so react-rxjs can reuse the same observables
|
|
154
283
|
*
|
|
284
|
+
* Entries are reference-counted: an entry with no subscribers for CLEANUP_DELAY_MS is
|
|
285
|
+
* removed from the cache (its shareReplay source is already torn down by refCount at
|
|
286
|
+
* that point — only the replay buffer and the entry itself are dropped).
|
|
287
|
+
*
|
|
155
288
|
* @param namespace
|
|
156
289
|
* @param args
|
|
157
290
|
* @param createObservable
|
|
@@ -159,19 +292,26 @@ declare const getQuery$: <Output, Args>({ namespace, args, queryFn, defaultValue
|
|
|
159
292
|
* @returns
|
|
160
293
|
*/
|
|
161
294
|
declare const getSharedObservable: <Args, Output, ObsOutput = Observable<Output>>(namespace: string, args: Args, createObservable: (args: Args) => ObsOutput, serializer?: (args: Args) => string) => ObsOutput;
|
|
162
|
-
|
|
295
|
+
//#endregion
|
|
296
|
+
//#region src/hasOwnProperty.d.ts
|
|
163
297
|
declare function hasOwnProperty<X, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown>;
|
|
164
|
-
|
|
298
|
+
//#endregion
|
|
299
|
+
//#region src/isAbortError.d.ts
|
|
165
300
|
declare const isAbortError: (error: unknown) => boolean;
|
|
166
|
-
|
|
301
|
+
//#endregion
|
|
302
|
+
//#region src/isArrayOf.d.ts
|
|
167
303
|
declare function isArrayOf<T, P extends Array<unknown>>(array: unknown[], func: new (...args: P) => T): array is T[];
|
|
168
|
-
|
|
304
|
+
//#endregion
|
|
305
|
+
//#region src/isAscii.d.ts
|
|
169
306
|
declare const isAscii: (str: string) => boolean;
|
|
170
|
-
|
|
307
|
+
//#endregion
|
|
308
|
+
//#region src/isBigInt.d.ts
|
|
171
309
|
declare const isBigInt: (value: unknown) => value is bigint;
|
|
172
|
-
|
|
310
|
+
//#endregion
|
|
311
|
+
//#region src/isBooleanTrue.d.ts
|
|
173
312
|
declare const isBooleanTrue: <T>(x: T | null | undefined) => x is T;
|
|
174
|
-
|
|
313
|
+
//#endregion
|
|
314
|
+
//#region src/isErrorOfName.d.ts
|
|
175
315
|
/**
|
|
176
316
|
* Robust replacement for `error instanceof SomeErrorClass` when the class comes from a
|
|
177
317
|
* package that gets bundled into multiple chunks/contexts (e.g. viem, @solana/web3.js).
|
|
@@ -184,11 +324,8 @@ declare const isBooleanTrue: <T>(x: T | null | undefined) => x is T;
|
|
|
184
324
|
* duck-type the shape instead.
|
|
185
325
|
*/
|
|
186
326
|
declare const isErrorOfName: (error: unknown, ...names: string[]) => boolean;
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
declare const REGEX_HEX_STRING: RegExp;
|
|
190
|
-
declare const isHexString: (value: unknown) => value is HexString;
|
|
191
|
-
|
|
327
|
+
//#endregion
|
|
328
|
+
//#region src/isNotNil.d.ts
|
|
192
329
|
/**
|
|
193
330
|
* WARNING: This function only checks against null or undefined, it does not coerce the value.
|
|
194
331
|
* ie: false and 0 are considered not nil
|
|
@@ -198,16 +335,34 @@ declare const isHexString: (value: unknown) => value is HexString;
|
|
|
198
335
|
* @returns whether the value is neither null nor undefined
|
|
199
336
|
*/
|
|
200
337
|
declare const isNotNil: <T>(value: T | null | undefined) => value is T;
|
|
201
|
-
|
|
338
|
+
//#endregion
|
|
339
|
+
//#region src/isPromise.d.ts
|
|
202
340
|
declare const isPromise: <T = any>(value: any) => value is Promise<T>;
|
|
203
|
-
|
|
341
|
+
//#endregion
|
|
342
|
+
//#region src/isSubject.d.ts
|
|
204
343
|
/**
|
|
205
344
|
* Tests to see if an object is an RxJS {@link Subject}.
|
|
206
345
|
*/
|
|
207
346
|
declare function isSubject<T>(object?: Subject<T> | object): object is Subject<T>;
|
|
208
|
-
|
|
347
|
+
//#endregion
|
|
348
|
+
//#region src/isTruthy.d.ts
|
|
209
349
|
declare const isTruthy: <T>(value: T | null | undefined) => value is T;
|
|
210
|
-
|
|
350
|
+
//#endregion
|
|
351
|
+
//#region src/jsActivityHook.d.ts
|
|
352
|
+
/**
|
|
353
|
+
* Optional host-provided JS-activity hook.
|
|
354
|
+
*
|
|
355
|
+
* Host apps that run a JS-thread stall watchdog (e.g. talisapp's jsThreadWatchdog) can
|
|
356
|
+
* install `globalThis.__recordJsActivity` to receive lightweight "this just ran on the
|
|
357
|
+
* JS thread" markers from library code. When a stall is detected, the watchdog can then
|
|
358
|
+
* attribute the blocked time to whatever activity was recorded during the stall window.
|
|
359
|
+
*
|
|
360
|
+
* When no hook is installed this is a no-op (a single property read), so library code
|
|
361
|
+
* can call it unconditionally from hot paths.
|
|
362
|
+
*/
|
|
363
|
+
declare const reportJsActivity: (label: string, durationMs?: number) => void;
|
|
364
|
+
//#endregion
|
|
365
|
+
//#region src/keepAlive.d.ts
|
|
211
366
|
/**
|
|
212
367
|
* An RxJS operator that keeps the source observable alive for a specified duration
|
|
213
368
|
* after all subscribers have unsubscribed. This prevents expensive re-subscriptions
|
|
@@ -224,15 +379,67 @@ declare const isTruthy: <T>(value: T | null | undefined) => value is T;
|
|
|
224
379
|
* ```
|
|
225
380
|
*/
|
|
226
381
|
declare const keepAlive: <T>(timeout: number) => OperatorFunction<T, T>;
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
382
|
+
//#endregion
|
|
383
|
+
//#region src/lruMap.d.ts
|
|
384
|
+
/**
|
|
385
|
+
* A Map with a maximum size and least-recently-used eviction.
|
|
386
|
+
*
|
|
387
|
+
* Reads refresh recency; when an insert would exceed `maxSize`, the
|
|
388
|
+
* least-recently-used entry is evicted. Intended for long-lived in-memory
|
|
389
|
+
* caches that would otherwise grow without bound.
|
|
390
|
+
*/
|
|
391
|
+
declare class LruMap<K, V> {
|
|
392
|
+
#private;
|
|
393
|
+
constructor(maxSize: number);
|
|
394
|
+
get(key: K): V | undefined;
|
|
395
|
+
set(key: K, value: V): this;
|
|
396
|
+
has(key: K): boolean;
|
|
397
|
+
delete(key: K): boolean;
|
|
398
|
+
clear(): void;
|
|
399
|
+
get size(): number;
|
|
400
|
+
}
|
|
401
|
+
//#endregion
|
|
402
|
+
//#region src/mapChunked.d.ts
|
|
403
|
+
type ChunkedProjectContext = {
|
|
404
|
+
/** thread the slicer through chunked helpers (mapWithYield etc.) so the budget spans them */
|
|
405
|
+
slicer: TimeSlicer;
|
|
406
|
+
/** aborted when the work is cancelled (new upstream value or unsubscription) */
|
|
407
|
+
signal: AbortSignal;
|
|
408
|
+
};
|
|
409
|
+
/**
|
|
410
|
+
* `switchMap` for time-sliced (chunked) async work — latest-wins: a new upstream value or
|
|
411
|
+
* an unsubscription aborts the in-flight `project` via `ctx.signal` / the shared slicer,
|
|
412
|
+
* so cancelled work stops burning CPU at its next yield check point and its result is
|
|
413
|
+
* never emitted.
|
|
414
|
+
*
|
|
415
|
+
* Non-abort errors thrown by `project` error the stream (same as a throwing sync `map`).
|
|
416
|
+
*
|
|
417
|
+
* Note: pipelines using this operator already emit asynchronously (macrotask), so adding
|
|
418
|
+
* `observeOn(asyncScheduler)` downstream is redundant and only adds latency.
|
|
419
|
+
*/
|
|
420
|
+
declare const switchMapChunked: <T, R>(project: (value: T, ctx: ChunkedProjectContext, index: number) => Promise<R>, options?: {
|
|
421
|
+
budgetMs?: number;
|
|
422
|
+
label?: string;
|
|
423
|
+
}) => OperatorFunction<T, R>;
|
|
424
|
+
/**
|
|
425
|
+
* `concatMap` variant of switchMapChunked — ordered: upstream values queue and are
|
|
426
|
+
* processed one at a time; a new value does NOT cancel in-flight work (unsubscription
|
|
427
|
+
* still aborts it).
|
|
428
|
+
*/
|
|
429
|
+
declare const concatMapChunked: <T, R>(project: (value: T, ctx: ChunkedProjectContext, index: number) => Promise<R>, options?: {
|
|
430
|
+
budgetMs?: number;
|
|
431
|
+
label?: string;
|
|
432
|
+
}) => OperatorFunction<T, R>;
|
|
433
|
+
//#endregion
|
|
434
|
+
//#region src/Prettify.d.ts
|
|
435
|
+
type Prettify<T> = { [K in keyof T]: T[K]; } & {};
|
|
436
|
+
//#endregion
|
|
437
|
+
//#region src/planckToTokens.d.ts
|
|
232
438
|
declare function planckToTokens(planck: string, tokenDecimals: number): string;
|
|
233
439
|
declare function planckToTokens(planck: string, tokenDecimals?: number): string | undefined;
|
|
234
440
|
declare function planckToTokens(planck?: string, tokenDecimals?: number): string | undefined;
|
|
235
|
-
|
|
441
|
+
//#endregion
|
|
442
|
+
//#region src/replaySubjectFrom.d.ts
|
|
236
443
|
/**
|
|
237
444
|
* Turns a value into a {@link ReplaySubject} of size 1.
|
|
238
445
|
*
|
|
@@ -244,9 +451,11 @@ declare function planckToTokens(planck?: string, tokenDecimals?: number): string
|
|
|
244
451
|
* For any other type of value, it will be immediately published into the {@link ReplaySubject}.
|
|
245
452
|
*/
|
|
246
453
|
declare const replaySubjectFrom: <T>(initialValue: T | Promise<T> | ReplaySubject<T>) => ReplaySubject<T>;
|
|
247
|
-
|
|
454
|
+
//#endregion
|
|
455
|
+
//#region src/sleep.d.ts
|
|
248
456
|
declare const sleep: (ms: number) => Promise<void>;
|
|
249
|
-
|
|
457
|
+
//#endregion
|
|
458
|
+
//#region src/splitSubject.d.ts
|
|
250
459
|
/**
|
|
251
460
|
* Takes a subject and splits it into two parts:
|
|
252
461
|
*
|
|
@@ -257,7 +466,8 @@ declare const sleep: (ms: number) => Promise<void>;
|
|
|
257
466
|
* of these parts to external code and keep the other part private.
|
|
258
467
|
*/
|
|
259
468
|
declare function splitSubject<T>(subject: Subject<T>): readonly [(value: T) => void, Observable<T>];
|
|
260
|
-
|
|
469
|
+
//#endregion
|
|
470
|
+
//#region src/stripHexPrefix.d.ts
|
|
261
471
|
/**
|
|
262
472
|
* @name stripHexPrefix
|
|
263
473
|
* @description Removes a leading `0x` prefix from a string, if present.
|
|
@@ -268,13 +478,44 @@ declare function splitSubject<T>(subject: Subject<T>): readonly [(value: T) => v
|
|
|
268
478
|
* stripHexPrefix("1234") // "1234"
|
|
269
479
|
**/
|
|
270
480
|
declare const stripHexPrefix: (str: string) => string;
|
|
271
|
-
|
|
481
|
+
//#endregion
|
|
482
|
+
//#region src/throwAfter.d.ts
|
|
272
483
|
declare const throwAfter: (ms: number, reason: string) => Promise<never>;
|
|
273
|
-
|
|
484
|
+
//#endregion
|
|
485
|
+
//#region src/tokensToPlanck.d.ts
|
|
274
486
|
declare function tokensToPlanck(tokens: string, tokenDecimals: number): string;
|
|
275
487
|
declare function tokensToPlanck(tokens: string, tokenDecimals?: number): string | undefined;
|
|
276
488
|
declare function tokensToPlanck(tokens?: string, tokenDecimals?: number): string | undefined;
|
|
277
|
-
|
|
489
|
+
//#endregion
|
|
490
|
+
//#region src/validateArrayWithYield.d.ts
|
|
491
|
+
type ItemParseResult<T, E> = {
|
|
492
|
+
success: true;
|
|
493
|
+
data: T;
|
|
494
|
+
} | {
|
|
495
|
+
success: false;
|
|
496
|
+
error: E;
|
|
497
|
+
};
|
|
498
|
+
type ArrayValidationResult<T, E> = {
|
|
499
|
+
success: true;
|
|
500
|
+
data: T[];
|
|
501
|
+
} | {
|
|
502
|
+
success: false;
|
|
503
|
+
errors: {
|
|
504
|
+
index: number;
|
|
505
|
+
error: E;
|
|
506
|
+
}[];
|
|
507
|
+
};
|
|
508
|
+
/**
|
|
509
|
+
* Validates every item of an array within a cooperative time budget, yielding the thread
|
|
510
|
+
* to the host event loop whenever the budget for the current slice is exhausted.
|
|
511
|
+
*
|
|
512
|
+
* Like `z.array(schema).safeParse`, ALL items are validated and all failures collected
|
|
513
|
+
* (no fail-fast) — pass e.g. `(item) => SomeSchema.safeParse(item)` as `parseItem`.
|
|
514
|
+
* Zod-agnostic on purpose: this package has no zod dependency.
|
|
515
|
+
*/
|
|
516
|
+
declare const validateArrayWithYield: <T, E>(items: readonly unknown[], parseItem: (item: unknown, index: number) => ItemParseResult<T, E>, options?: ChunkedOptions) => Promise<ArrayValidationResult<T, E>>;
|
|
517
|
+
//#endregion
|
|
518
|
+
//#region src/validateHexString.d.ts
|
|
278
519
|
/**
|
|
279
520
|
* @name validateHexString
|
|
280
521
|
* @description Checks if a string is a hex string. Required to account for type differences between different polkadot libraries
|
|
@@ -286,5 +527,9 @@ declare function tokensToPlanck(tokens?: string, tokenDecimals?: number): string
|
|
|
286
527
|
* validateHexString(1234) // Error: Expected a string
|
|
287
528
|
**/
|
|
288
529
|
declare const validateHexString: (str: string) => `0x${string}`;
|
|
289
|
-
|
|
290
|
-
|
|
530
|
+
//#endregion
|
|
531
|
+
//#region src/yieldToEventLoop.d.ts
|
|
532
|
+
declare const yieldToEventLoop: () => Promise<void>;
|
|
533
|
+
//#endregion
|
|
534
|
+
export { ArrayValidationResult, BigMath, ChunkedOptions, ChunkedProjectContext, DEFAULT_TIME_SLICE_BUDGET_MS, Deferred, FunctionProperties, FunctionPropertyNames, GetLoadableQueryParams, HexString, ItemParseResult, Loadable, LoadableOptions, LoadableStatus, LruMap, MAX_DECIMALS_FORMAT, NonFunctionProperties, NonFunctionPropertyNames, Prettify, QueryResult, QueryStatus, REGEX_HEX_STRING, TimeSlicer, TimeSlicerOptions, addTrailingSlash, arrayItemsEqualWithYield, assert, concatMapChunked, createTimeSlicer, firstThenDebounce, forEachWithYield, formatDecimals, formatPrice, getLoadable$, getLoadableQuery$, getQuery$, getSharedObservable, hasOwnProperty, hexToNumber, hexToString, hexToU8a, isAbortError, isArrayOf, isAscii, isAsciiPrintable, isBigInt, isBooleanTrue, isErrorOfName, isHexString, isNotNil, isPromise, isSubject, isTruthy, keepAlive, keyByWithYield, mapWithYield, newAbortError, numberToU8a, planckToTokens, replaySubjectFrom, reportJsActivity, sleep, splitSubject, stringToU8a, stripHexPrefix, switchMapChunked, throwAfter, tokensToPlanck, u8aCmp, u8aConcat, u8aEq, u8aToHex, u8aToString, u8aToU8a, u8aUnwrapBytes, u8aWrapBytes, validateArrayWithYield, validateHexString, yieldToEventLoop };
|
|
535
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/addTrailingSlash.ts","../src/assert.ts","../src/BigMath.ts","../src/isHexString.ts","../src/bytes.ts","../src/timeSlicer.ts","../src/chunkedArray.ts","../src/deferred.ts","../src/FunctionPropertyNames.ts","../src/firstThenDebounce.ts","../src/formatDecimals.ts","../src/formatPrice.ts","../src/getLoadable.ts","../src/getLoadableQuery.ts","../src/getQuery.ts","../src/getSharedObservable.ts","../src/hasOwnProperty.ts","../src/isAbortError.ts","../src/isArrayOf.ts","../src/isAscii.ts","../src/isBigInt.ts","../src/isBooleanTrue.ts","../src/isErrorOfName.ts","../src/isNotNil.ts","../src/isPromise.ts","../src/isSubject.ts","../src/isTruthy.ts","../src/jsActivityHook.ts","../src/keepAlive.ts","../src/lruMap.ts","../src/mapChunked.ts","../src/Prettify.ts","../src/planckToTokens.ts","../src/replaySubjectFrom.ts","../src/sleep.ts","../src/splitSubject.ts","../src/stripHexPrefix.ts","../src/throwAfter.ts","../src/tokensToPlanck.ts","../src/validateArrayWithYield.ts","../src/validateHexString.ts","../src/yieldToEventLoop.ts"],"mappings":";;;cAAa,mBAAgB;;;;;;;;;iBCMb,OAAO,oBAAoB,2CAA2C;;;;;;;cCFzE;EACX,IAAG;EAGH,KAAI;EASJ,IAAG,kBAAc;EAIjB,IAAG,kBAAc;;;;KCrBP;cAEC,kBAAgB;cAEhB,cAAW,mBAAqB,SAAS;;;;;;;cCGzC,WAAQ,wBAA0B;cAWlC,WAAQ,QAAY,sBAAoB;cAOxC,cAAW,0BAA4B;cAGvC,cAAW,QAAY;cAGvB,cAAW;cAEX,cAAW;cAEX,cAAW,0BAA4B;;cAOvC,WAAQ,4BAAgC,sBAAoB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