@talismn/util 1.1.0 → 2.0.1

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/index.d.ts CHANGED
@@ -1,19 +1,144 @@
1
- import { OperatorFunction, Observable, Subject, ReplaySubject } from 'rxjs';
2
- import BigNumber from 'bignumber.js';
3
-
4
- declare const addTrailingSlash: (url: string) => string;
5
-
1
+ import BigNumber from "bignumber.js";
2
+ import { Observable, OperatorFunction, ReplaySubject, Subject } from "rxjs";
3
+ //#region src/addTrailingSlash.d.ts
4
+ export declare const addTrailingSlash: (url: string) => string;
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
+ export 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
- declare const BigMath: {
11
- abs(x: bigint): bigint;
12
- sign(x: bigint): 0n | 1n | -1n;
13
- min(value: bigint, ...values: bigint[]): bigint;
14
- max(value: bigint, ...values: bigint[]): bigint;
20
+ export declare const BigMath: {
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
+ export type HexString = `0x${string}`;
29
+ export declare const REGEX_HEX_STRING: RegExp;
30
+ export 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
+ export declare const hexToU8a: (hex?: string | null) => Uint8Array;
38
+ export declare const u8aToHex: (value?: Uint8Array | null) => HexString;
39
+ export declare const stringToU8a: (value?: string | null) => Uint8Array;
40
+ export declare const u8aToString: (value?: Uint8Array | null) => string;
41
+ export declare const hexToString: (hex?: string | null) => string;
42
+ export declare const hexToNumber: (hex?: string | null) => number;
43
+ export declare const numberToU8a: (value?: number | null) => Uint8Array;
44
+ /** Coerces hex strings, utf-8 strings, number arrays and buffers to Uint8Array (polkadot-js semantics) */
45
+ export declare const u8aToU8a: (value?: string | number[] | Uint8Array | null) => Uint8Array;
46
+ export declare const u8aConcat: (...items: (string | number[] | Uint8Array)[]) => Uint8Array;
47
+ export declare const u8aEq: (a: string | Uint8Array, b: string | Uint8Array) => boolean;
48
+ export 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
+ export declare const isAsciiPrintable: (value?: string | Uint8Array | null) => boolean;
54
+ /** Wraps bytes with `<Bytes>...</Bytes>` for raw-message signing, unless already wrapped */
55
+ export declare const u8aWrapBytes: (value: string | Uint8Array) => Uint8Array;
56
+ export 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
+ export declare const DEFAULT_TIME_SLICE_BUDGET_MS = 10;
64
+ export 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;
73
+ };
74
+ export 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
+ export 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
+ export declare const createTimeSlicer: ({ budgetMs, signal, now, label }?: TimeSlicerOptions) => TimeSlicer;
108
+ //#endregion
109
+ //#region src/chunkedArray.d.ts
110
+ export 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;
15
119
  };
16
-
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
+ export 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
+ export 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
+ export 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
+ export 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.
@@ -21,34 +146,33 @@ declare const BigMath: {
21
146
  * This pattern is often used when dealing with asynchronous operations that involve multiple steps or when
22
147
  * the result of an operation cannot be immediately determined.
23
148
  */
24
- declare function Deferred<T>(): {
25
- promise: Promise<T>;
26
- resolve: (value: T | PromiseLike<T>) => void;
27
- reject: (reason?: unknown) => void;
28
- isPending: () => boolean;
29
- isResolved: () => boolean;
30
- isRejected: () => boolean;
149
+ export declare function Deferred<T>(): {
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];
37
- 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];
41
- type NonFunctionProperties<T> = Pick<T, NonFunctionPropertyNames<T>>;
42
-
160
+ export type FunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T];
161
+ export type FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>>;
162
+ export type NonFunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T];
163
+ export type NonFunctionProperties<T> = Pick<T, NonFunctionPropertyNames<T>>;
164
+ //#endregion
165
+ //#region src/firstThenDebounce.d.ts
43
166
  /**
44
167
  * An rxjs operator which:
45
168
  *
46
169
  * 1. Emits the first value it receives from the source observable, then:
47
170
  * 2. Debounces any future values by `timeout` ms.
48
171
  */
49
- declare const firstThenDebounce: <T>(timeout: number) => OperatorFunction<T, T>;
50
-
51
- declare const MAX_DECIMALS_FORMAT = 12;
172
+ export declare const firstThenDebounce: <T>(timeout: number) => OperatorFunction<T, T>;
173
+ //#endregion
174
+ //#region src/formatDecimals.d.ts
175
+ export declare const MAX_DECIMALS_FORMAT = 12;
52
176
  /**
53
177
  * Custom decimal number formatting for Talisman
54
178
  * note that the NumberFormat().format() call is the ressource heavy part, it's not worth trying to optimize other parts
@@ -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
-
63
- declare const formatPrice: (price: number, currency: string, compact: boolean) => string;
64
-
185
+ export declare const formatDecimals: (num?: string | number | null | BigNumber, digits?: number, options?: Partial<Intl.NumberFormatOptions>, locale?: string) => string;
186
+ //#endregion
187
+ //#region src/formatPrice.d.ts
188
+ export declare const formatPrice: (price: number, currency: string, compact: boolean) => string;
189
+ //#endregion
190
+ //#region src/getLoadable.d.ts
65
191
  type LoadableError = {
66
- name: string;
67
- message: string;
192
+ name: string;
193
+ message: string;
68
194
  };
69
- type Loadable<T = unknown> = {
70
- status: "loading";
71
- data?: T;
72
- error?: undefined;
195
+ export type Loadable<T = unknown> = {
196
+ status: "loading";
197
+ data?: T;
198
+ error?: undefined;
73
199
  } | {
74
- status: "success";
75
- data: T;
76
- error?: undefined;
200
+ status: "success";
201
+ data: T;
202
+ error?: undefined;
77
203
  } | {
78
- status: "error";
79
- data?: T;
80
- error: LoadableError;
204
+ status: "error";
205
+ data?: T;
206
+ error: LoadableError;
81
207
  };
82
- type LoadableStatus = Loadable["status"];
83
- type LoadableOptions = {
84
- getError?: (error: unknown) => LoadableError;
85
- refreshInterval?: number;
208
+ export type LoadableStatus = Loadable["status"];
209
+ export type LoadableOptions = {
210
+ getError?: (error: unknown) => LoadableError;
211
+ refreshInterval?: number;
86
212
  };
87
- declare function getLoadable$<T>(factory: () => Promise<T>, options?: LoadableOptions): Observable<Loadable<T>>;
88
-
89
- type GetLoadableQueryParams<TArgs extends unknown[], TResult> = {
90
- namespace: string;
91
- args: TArgs;
92
- queryFn: (args: TArgs, signal: AbortSignal) => Promise<TResult>;
93
- refreshInterval?: number;
94
- defaultValue?: TResult;
213
+ export declare function getLoadable$<T>(factory: () => Promise<T>, options?: LoadableOptions): Observable<Loadable<T>>;
214
+ //#endregion
215
+ //#region src/getLoadableQuery.d.ts
216
+ export type GetLoadableQueryParams<TArgs extends unknown[], TResult> = {
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
@@ -99,29 +226,30 @@ type GetLoadableQueryParams<TArgs extends unknown[], TResult> = {
99
226
  *
100
227
  * TODO: consolidate with getQuery$
101
228
  */
102
- declare const getLoadableQuery$: <TArgs extends unknown[], TResult>(params: GetLoadableQueryParams<TArgs, TResult>) => Observable<Loadable<TResult>>;
103
-
104
- type QueryStatus = "loading" | "loaded" | "error";
105
- type QueryResult<T, S extends QueryStatus = "loading" | "loaded" | "error"> = S extends "loading" ? {
106
- status: "loading";
107
- data: T | undefined;
108
- error: undefined;
229
+ export declare const getLoadableQuery$: <TArgs extends unknown[], TResult>(params: GetLoadableQueryParams<TArgs, TResult>) => Observable<Loadable<TResult>>;
230
+ //#endregion
231
+ //#region src/getQuery.d.ts
232
+ export type QueryStatus = "loading" | "loaded" | "error";
233
+ export type QueryResult<T, S extends QueryStatus = "loading" | "loaded" | "error"> = S extends "loading" ? {
234
+ status: "loading";
235
+ data: T | undefined;
236
+ error: undefined;
109
237
  } : S extends "loaded" ? {
110
- status: "loaded";
111
- data: T;
112
- error: undefined;
238
+ status: "loaded";
239
+ data: T;
240
+ error: undefined;
113
241
  } : {
114
- status: "error";
115
- data: undefined;
116
- error: unknown;
242
+ status: "error";
243
+ data: undefined;
244
+ error: unknown;
117
245
  };
118
246
  type QueryOptions<Output, Args> = {
119
- namespace: string;
120
- args: Args;
121
- queryFn: (args: Args, signal: AbortSignal) => Promise<Output>;
122
- defaultValue?: Output;
123
- refreshInterval?: number;
124
- serializer?: (args: Args) => string;
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,33 +273,45 @@ 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, }: QueryOptions<Output, Args>) => Observable<QueryResult<Output>>;
149
-
276
+ export 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
158
291
  * @param serializer
159
292
  * @returns
160
293
  */
161
- declare const getSharedObservable: <Args, Output, ObsOutput = Observable<Output>>(namespace: string, args: Args, createObservable: (args: Args) => ObsOutput, serializer?: (args: Args) => string) => ObsOutput;
162
-
163
- declare function hasOwnProperty<X, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown>;
164
-
165
- declare const isAbortError: (error: unknown) => boolean;
166
-
167
- declare function isArrayOf<T, P extends Array<unknown>>(array: unknown[], func: new (...args: P) => T): array is T[];
168
-
169
- declare const isAscii: (str: string) => boolean;
170
-
171
- declare const isBigInt: (value: unknown) => value is bigint;
172
-
173
- declare const isBooleanTrue: <T>(x: T | null | undefined) => x is T;
174
-
294
+ export declare const getSharedObservable: <Args, Output, ObsOutput = Observable<Output>>(namespace: string, args: Args, createObservable: (args: Args) => ObsOutput, serializer?: (args: Args) => string) => ObsOutput;
295
+ //#endregion
296
+ //#region src/hasOwnProperty.d.ts
297
+ export declare function hasOwnProperty<X, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown>;
298
+ //#endregion
299
+ //#region src/isAbortError.d.ts
300
+ export declare const isAbortError: (error: unknown) => boolean;
301
+ //#endregion
302
+ //#region src/isArrayOf.d.ts
303
+ export declare function isArrayOf<T, P extends Array<unknown>>(array: unknown[], func: new (...args: P) => T): array is T[];
304
+ //#endregion
305
+ //#region src/isAscii.d.ts
306
+ export declare const isAscii: (str: string) => boolean;
307
+ //#endregion
308
+ //#region src/isBigInt.d.ts
309
+ export declare const isBigInt: (value: unknown) => value is bigint;
310
+ //#endregion
311
+ //#region src/isBooleanTrue.d.ts
312
+ export declare const isBooleanTrue: <T>(x: T | null | undefined) => x is T;
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).
@@ -183,12 +323,9 @@ declare const isBooleanTrue: <T>(x: T | null | undefined) => x is T;
183
323
  * `super({ name: 'ContractFunctionExecutionError' })`). For classes that don't set `.name`,
184
324
  * duck-type the shape instead.
185
325
  */
186
- declare const isErrorOfName: (error: unknown, ...names: string[]) => boolean;
187
-
188
- type HexString = `0x${string}`;
189
- declare const REGEX_HEX_STRING: RegExp;
190
- declare const isHexString: (value: unknown) => value is HexString;
191
-
326
+ export declare const isErrorOfName: (error: unknown, ...names: string[]) => boolean;
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
@@ -197,17 +334,35 @@ declare const isHexString: (value: unknown) => value is HexString;
197
334
  * @param value
198
335
  * @returns whether the value is neither null nor undefined
199
336
  */
200
- declare const isNotNil: <T>(value: T | null | undefined) => value is T;
201
-
202
- declare const isPromise: <T = any>(value: any) => value is Promise<T>;
203
-
337
+ export declare const isNotNil: <T>(value: T | null | undefined) => value is T;
338
+ //#endregion
339
+ //#region src/isPromise.d.ts
340
+ export declare const isPromise: <T = any>(value: any) => value is Promise<T>;
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
- declare function isSubject<T>(object?: Subject<T> | object): object is Subject<T>;
208
-
209
- declare const isTruthy: <T>(value: T | null | undefined) => value is T;
210
-
346
+ export declare function isSubject<T>(object?: Subject<T> | object): object is Subject<T>;
347
+ //#endregion
348
+ //#region src/isTruthy.d.ts
349
+ export declare const isTruthy: <T>(value: T | null | undefined) => value is T;
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
+ export 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
@@ -223,16 +378,68 @@ declare const isTruthy: <T>(value: T | null | undefined) => value is T;
223
378
  * );
224
379
  * ```
225
380
  */
226
- declare const keepAlive: <T>(timeout: number) => OperatorFunction<T, T>;
227
-
228
- type Prettify<T> = {
229
- [K in keyof T]: T[K];
230
- } & {};
231
-
232
- declare function planckToTokens(planck: string, tokenDecimals: number): string;
233
- declare function planckToTokens(planck: string, tokenDecimals?: number): string | undefined;
234
- declare function planckToTokens(planck?: string, tokenDecimals?: number): string | undefined;
235
-
381
+ export declare const keepAlive: <T>(timeout: number) => OperatorFunction<T, T>;
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
+ export 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
+ export 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
+ export 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
+ export 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
+ export type Prettify<T> = { [K in keyof T]: T[K]; } & {};
436
+ //#endregion
437
+ //#region src/planckToTokens.d.ts
438
+ export declare function planckToTokens(planck: string, tokenDecimals: number): string;
439
+ export declare function planckToTokens(planck: string, tokenDecimals?: number): string | undefined;
440
+ export declare function planckToTokens(planck?: string, tokenDecimals?: number): string | undefined;
441
+ //#endregion
442
+ //#region src/replaySubjectFrom.d.ts
236
443
  /**
237
444
  * Turns a value into a {@link ReplaySubject} of size 1.
238
445
  *
@@ -243,10 +450,12 @@ declare function planckToTokens(planck?: string, tokenDecimals?: number): string
243
450
  *
244
451
  * For any other type of value, it will be immediately published into the {@link ReplaySubject}.
245
452
  */
246
- declare const replaySubjectFrom: <T>(initialValue: T | Promise<T> | ReplaySubject<T>) => ReplaySubject<T>;
247
-
248
- declare const sleep: (ms: number) => Promise<void>;
249
-
453
+ export declare const replaySubjectFrom: <T>(initialValue: T | Promise<T> | ReplaySubject<T>) => ReplaySubject<T>;
454
+ //#endregion
455
+ //#region src/sleep.d.ts
456
+ export declare const sleep: (ms: number) => Promise<void>;
457
+ //#endregion
458
+ //#region src/splitSubject.d.ts
250
459
  /**
251
460
  * Takes a subject and splits it into two parts:
252
461
  *
@@ -256,8 +465,9 @@ declare const sleep: (ms: number) => Promise<void>;
256
465
  * This can be helpful when, to avoid bugs, you want to expose only one
257
466
  * of these parts to external code and keep the other part private.
258
467
  */
259
- declare function splitSubject<T>(subject: Subject<T>): readonly [(value: T) => void, Observable<T>];
260
-
468
+ export declare function splitSubject<T>(subject: Subject<T>): readonly [(value: T) => void, Observable<T>];
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.
@@ -267,14 +477,45 @@ declare function splitSubject<T>(subject: Subject<T>): readonly [(value: T) => v
267
477
  * stripHexPrefix("0x1234") // "1234"
268
478
  * stripHexPrefix("1234") // "1234"
269
479
  **/
270
- declare const stripHexPrefix: (str: string) => string;
271
-
272
- declare const throwAfter: (ms: number, reason: string) => Promise<never>;
273
-
274
- declare function tokensToPlanck(tokens: string, tokenDecimals: number): string;
275
- declare function tokensToPlanck(tokens: string, tokenDecimals?: number): string | undefined;
276
- declare function tokensToPlanck(tokens?: string, tokenDecimals?: number): string | undefined;
277
-
480
+ export declare const stripHexPrefix: (str: string) => string;
481
+ //#endregion
482
+ //#region src/throwAfter.d.ts
483
+ export declare const throwAfter: (ms: number, reason: string) => Promise<never>;
484
+ //#endregion
485
+ //#region src/tokensToPlanck.d.ts
486
+ export declare function tokensToPlanck(tokens: string, tokenDecimals: number): string;
487
+ export declare function tokensToPlanck(tokens: string, tokenDecimals?: number): string | undefined;
488
+ export declare function tokensToPlanck(tokens?: string, tokenDecimals?: number): string | undefined;
489
+ //#endregion
490
+ //#region src/validateArrayWithYield.d.ts
491
+ export type ItemParseResult<T, E> = {
492
+ success: true;
493
+ data: T;
494
+ } | {
495
+ success: false;
496
+ error: E;
497
+ };
498
+ export 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
+ export 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
@@ -285,6 +526,9 @@ declare function tokensToPlanck(tokens?: string, tokenDecimals?: number): string
285
526
  * validateHexString("1234") // Error: Expected a hex string
286
527
  * validateHexString(1234) // Error: Expected a string
287
528
  **/
288
- declare const validateHexString: (str: string) => `0x${string}`;
289
-
290
- export { BigMath, Deferred, type FunctionProperties, type FunctionPropertyNames, type GetLoadableQueryParams, type HexString, type Loadable, type LoadableOptions, type LoadableStatus, MAX_DECIMALS_FORMAT, type NonFunctionProperties, type NonFunctionPropertyNames, type Prettify, type QueryResult, type QueryStatus, REGEX_HEX_STRING, addTrailingSlash, firstThenDebounce, formatDecimals, formatPrice, getLoadable$, getLoadableQuery$, getQuery$, getSharedObservable, hasOwnProperty, isAbortError, isArrayOf, isAscii, isBigInt, isBooleanTrue, isErrorOfName, isHexString, isNotNil, isPromise, isSubject, isTruthy, keepAlive, planckToTokens, replaySubjectFrom, sleep, splitSubject, stripHexPrefix, throwAfter, tokensToPlanck, validateHexString };
529
+ export declare const validateHexString: (str: string) => `0x${string}`;
530
+ //#endregion
531
+ //#region src/yieldToEventLoop.d.ts
532
+ export declare const yieldToEventLoop: () => Promise<void>;
533
+ //#endregion
534
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","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":";;;qBAAa,mBAAgB;;;;;;;;;wBCMb,OAAO,oBAAoB,2CAA2C;;;;;;;qBCFzE;EACX,IAAG;EAGH,KAAI;EASJ,IAAG,kBAAc;EAIjB,IAAG,kBAAc;;;;YCrBP;qBAEC,kBAAgB;qBAEhB,cAAW,mBAAqB,SAAS;;;;;;;qBCGzC,WAAQ,wBAA0B;qBAWlC,WAAQ,QAAY,sBAAoB;qBAOxC,cAAW,0BAA4B;qBAGvC,cAAW,QAAY;qBAGvB,cAAW;qBAEX,cAAW;qBAEX,cAAW,0BAA4B;;qBAOvC,WAAQ,4BAAgC,sBAAoB;qBAO5D,eAAS,4BAAmC,kBAAgB;qBAW5D,QAAK,YAAgB,YAAU,YAAc;qBAO7C,SAAM,YAAgB,YAAU,YAAc;;;;;qBAe9C,mBAAgB,iBAAqB;;qBAgBrC,eAAY,gBAAoB,eAAa;qBAK7C,iBAAc,gBAAoB,eAAa;;;;;;;qBChG/C;YAED;;EAEV;;EAEA,SAAS;;EAET;;EAEA;;YAGU;WACD,SAAS;;EAElB;;EAEA,SAAS;;;;;;;;;;;;EAYT,iBAAiB;;EAEjB;;;;;;qBAOW,qBAAoB;;;;;;;;qBAapB,qBAAgB,UAAA,QAAA,KAAA,UAK1B,sBAAyB;;;YC5DhB;;EAEV;;EAEA,SAAS;;EAET,SAAS;;EAET;;;;;;;;;qBAcW,mBAA0B,GAAC,gBACtB,KAAG,KACd,MAAM,GAAG,wBAAsB,UAC1B,mBACT;;qBAeU,eAAsB,GAAG,GAAC,gBACrB,KAAG,KACd,MAAM,GAAG,kBAAkB,GAAC,UACvB,mBACT,QAAQ;;qBAOE,iBAAwB,GAAC,gBACpB,KAAG,QACX,MAAM,GAAG,0BAAwB,UAC/B,mBAC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