@talismn/util 0.5.6 → 0.5.8

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.
Files changed (44) hide show
  1. package/dist/index.d.mts +270 -0
  2. package/dist/index.d.ts +270 -0
  3. package/dist/index.js +490 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/index.mjs +421 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/package.json +23 -19
  8. package/dist/declarations/src/BigMath.d.ts +0 -10
  9. package/dist/declarations/src/FunctionPropertyNames.d.ts +0 -8
  10. package/dist/declarations/src/Prettify.d.ts +0 -3
  11. package/dist/declarations/src/addTrailingSlash.d.ts +0 -1
  12. package/dist/declarations/src/classNames.d.ts +0 -2
  13. package/dist/declarations/src/deferred.d.ts +0 -15
  14. package/dist/declarations/src/firstThenDebounce.d.ts +0 -8
  15. package/dist/declarations/src/formatDecimals.d.ts +0 -12
  16. package/dist/declarations/src/formatPrice.d.ts +0 -1
  17. package/dist/declarations/src/getLoadable.d.ts +0 -25
  18. package/dist/declarations/src/getQuery.d.ts +0 -45
  19. package/dist/declarations/src/getSharedObservable.d.ts +0 -13
  20. package/dist/declarations/src/hasOwnProperty.d.ts +0 -1
  21. package/dist/declarations/src/index.d.ts +0 -31
  22. package/dist/declarations/src/isAbortError.d.ts +0 -1
  23. package/dist/declarations/src/isArrayOf.d.ts +0 -1
  24. package/dist/declarations/src/isAscii.d.ts +0 -1
  25. package/dist/declarations/src/isBigInt.d.ts +0 -1
  26. package/dist/declarations/src/isBooleanTrue.d.ts +0 -1
  27. package/dist/declarations/src/isHexString.d.ts +0 -3
  28. package/dist/declarations/src/isNotNil.d.ts +0 -9
  29. package/dist/declarations/src/isPromise.d.ts +0 -1
  30. package/dist/declarations/src/isSubject.d.ts +0 -5
  31. package/dist/declarations/src/isTruthy.d.ts +0 -1
  32. package/dist/declarations/src/keepAlive.d.ts +0 -17
  33. package/dist/declarations/src/planckToTokens.d.ts +0 -3
  34. package/dist/declarations/src/replaySubjectFrom.d.ts +0 -12
  35. package/dist/declarations/src/sleep.d.ts +0 -1
  36. package/dist/declarations/src/splitSubject.d.ts +0 -11
  37. package/dist/declarations/src/throwAfter.d.ts +0 -1
  38. package/dist/declarations/src/tokensToPlanck.d.ts +0 -3
  39. package/dist/declarations/src/validateHexString.d.ts +0 -11
  40. package/dist/talismn-util.cjs.d.ts +0 -1
  41. package/dist/talismn-util.cjs.dev.js +0 -500
  42. package/dist/talismn-util.cjs.js +0 -7
  43. package/dist/talismn-util.cjs.prod.js +0 -500
  44. package/dist/talismn-util.esm.js +0 -463
@@ -1,45 +0,0 @@
1
- import { Observable } from "rxjs";
2
- export type QueryStatus = "loading" | "loaded" | "error";
3
- export type QueryResult<T, S extends QueryStatus = "loading" | "loaded" | "error"> = S extends "loading" ? {
4
- status: "loading";
5
- data: T | undefined;
6
- error: undefined;
7
- } : S extends "loaded" ? {
8
- status: "loaded";
9
- data: T;
10
- error: undefined;
11
- } : {
12
- status: "error";
13
- data: undefined;
14
- error: unknown;
15
- };
16
- type QueryOptions<Output, Args> = {
17
- namespace: string;
18
- args: Args;
19
- queryFn: (args: Args, signal: AbortSignal) => Promise<Output>;
20
- defaultValue?: Output;
21
- refreshInterval?: number;
22
- serializer?: (args: Args) => string;
23
- };
24
- /**
25
- * Creates a shared observable for executing queries with caching, loading states, and automatic refresh capabilities.
26
- *
27
- * @example
28
- * ```typescript
29
- * const userQuery$ = getQuery$({
30
- * namespace: 'users',
31
- * args: { userId: 123 },
32
- * queryFn: async ({ userId }) => fetchUser(userId),
33
- * defaultValue: null,
34
- * refreshInterval: 30000
35
- * });
36
- *
37
- * userQuery$.subscribe(result => {
38
- * if (result.status === 'loaded') {
39
- * console.log(result.data);
40
- * }
41
- * });
42
- * ```
43
- */
44
- export declare const getQuery$: <Output, Args>({ namespace, args, queryFn, defaultValue, refreshInterval, serializer, }: QueryOptions<Output, Args>) => Observable<QueryResult<Output>>;
45
- export {};
@@ -1,13 +0,0 @@
1
- import { Observable } from "rxjs";
2
- /**
3
- * When using react-rxjs hooks and state observables, the options are used as weak map keys.
4
- * This means that if the options object is recreated on each render, the observable will be recreated as well.
5
- * 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
6
- *
7
- * @param namespace
8
- * @param args
9
- * @param createObservable
10
- * @param serializer
11
- * @returns
12
- */
13
- export declare const getSharedObservable: <Args, Output, ObsOutput = Observable<Output>>(namespace: string, args: Args, createObservable: (args: Args) => ObsOutput, serializer?: (args: Args) => string) => ObsOutput;
@@ -1 +0,0 @@
1
- export declare function hasOwnProperty<X, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown>;
@@ -1,31 +0,0 @@
1
- export * from "./addTrailingSlash";
2
- export * from "./BigMath";
3
- export * from "./classNames";
4
- export * from "./deferred";
5
- export * from "./firstThenDebounce";
6
- export * from "./formatDecimals";
7
- export * from "./formatPrice";
8
- export * from "./FunctionPropertyNames";
9
- export * from "./getSharedObservable";
10
- export * from "./hasOwnProperty";
11
- export * from "./isAbortError";
12
- export * from "./isArrayOf";
13
- export * from "./isAscii";
14
- export * from "./isBigInt";
15
- export * from "./isBooleanTrue";
16
- export * from "./isHexString";
17
- export * from "./isNotNil";
18
- export * from "./isPromise";
19
- export * from "./isSubject";
20
- export * from "./isTruthy";
21
- export * from "./keepAlive";
22
- export * from "./planckToTokens";
23
- export * from "./Prettify";
24
- export * from "./replaySubjectFrom";
25
- export * from "./sleep";
26
- export * from "./splitSubject";
27
- export * from "./throwAfter";
28
- export * from "./tokensToPlanck";
29
- export * from "./validateHexString";
30
- export * from "./getLoadable";
31
- export * from "./getQuery";
@@ -1 +0,0 @@
1
- export declare const isAbortError: (error: unknown) => boolean;
@@ -1 +0,0 @@
1
- export declare function isArrayOf<T, P extends Array<unknown>>(array: unknown[], func: new (...args: P) => T): array is T[];
@@ -1 +0,0 @@
1
- export declare const isAscii: (str: string) => boolean;
@@ -1 +0,0 @@
1
- export declare const isBigInt: (value: unknown) => value is bigint;
@@ -1 +0,0 @@
1
- export declare const isBooleanTrue: <T>(x: T | null | undefined) => x is T;
@@ -1,3 +0,0 @@
1
- export type HexString = `0x${string}`;
2
- export declare const REGEX_HEX_STRING: RegExp;
3
- export declare const isHexString: (value: unknown) => value is HexString;
@@ -1,9 +0,0 @@
1
- /**
2
- * WARNING: This function only checks against null or undefined, it does not coerce the value.
3
- * ie: false and 0 are considered not nil
4
- * Use isTruthy instead for a regular coercion check.
5
- *
6
- * @param value
7
- * @returns whether the value is neither null nor undefined
8
- */
9
- export declare const isNotNil: <T>(value: T | null | undefined) => value is T;
@@ -1 +0,0 @@
1
- export declare const isPromise: <T = any>(value: any) => value is Promise<T>;
@@ -1,5 +0,0 @@
1
- import { Subject } from "rxjs";
2
- /**
3
- * Tests to see if an object is an RxJS {@link Subject}.
4
- */
5
- export declare function isSubject<T>(object?: Subject<T> | object): object is Subject<T>;
@@ -1 +0,0 @@
1
- export declare const isTruthy: <T>(value: T | null | undefined) => value is T;
@@ -1,17 +0,0 @@
1
- import type { OperatorFunction } from "rxjs";
2
- /**
3
- * An RxJS operator that keeps the source observable alive for a specified duration
4
- * after all subscribers have unsubscribed. This prevents expensive re-subscriptions
5
- * when subscribers come and go frequently.
6
- *
7
- * @param keepAliveMs - Duration in milliseconds to keep the source alive after last unsubscription
8
- * @returns MonoTypeOperatorFunction that can be used in pipe()
9
- *
10
- * @example
11
- * ```typescript
12
- * const data$ = expensive_api_call$.pipe(
13
- * keepAlive(3000) // Keep alive for 3 seconds
14
- * );
15
- * ```
16
- */
17
- export declare const keepAlive: <T>(timeout: number) => OperatorFunction<T, T>;
@@ -1,3 +0,0 @@
1
- export declare function planckToTokens(planck: string, tokenDecimals: number): string;
2
- export declare function planckToTokens(planck: string, tokenDecimals?: number): string | undefined;
3
- export declare function planckToTokens(planck?: string, tokenDecimals?: number): string | undefined;
@@ -1,12 +0,0 @@
1
- import { ReplaySubject } from "rxjs";
2
- /**
3
- * Turns a value into a {@link ReplaySubject} of size 1.
4
- *
5
- * If the value is already a {@link ReplaySubject}, it will be returned as-is.
6
- *
7
- * If the value is a {@link Promise}, it will be awaited,
8
- * and the awaited value will be published into the {@link ReplaySubject} when it becomes available.
9
- *
10
- * For any other type of value, it will be immediately published into the {@link ReplaySubject}.
11
- */
12
- export declare const replaySubjectFrom: <T>(initialValue: T | Promise<T> | ReplaySubject<T>) => ReplaySubject<T>;
@@ -1 +0,0 @@
1
- export declare const sleep: (ms: number) => Promise<void>;
@@ -1,11 +0,0 @@
1
- import { Observable, Subject } from "rxjs";
2
- /**
3
- * Takes a subject and splits it into two parts:
4
- *
5
- * 1. A function to submit new values into the subject.
6
- * 2. An observable for subscribing to new values from the subject.
7
- *
8
- * This can be helpful when, to avoid bugs, you want to expose only one
9
- * of these parts to external code and keep the other part private.
10
- */
11
- export declare function splitSubject<T>(subject: Subject<T>): readonly [(value: T) => void, Observable<T>];
@@ -1 +0,0 @@
1
- export declare const throwAfter: (ms: number, reason: string) => Promise<never>;
@@ -1,3 +0,0 @@
1
- export declare function tokensToPlanck(tokens: string, tokenDecimals: number): string;
2
- export declare function tokensToPlanck(tokens: string, tokenDecimals?: number): string | undefined;
3
- export declare function tokensToPlanck(tokens?: string, tokenDecimals?: number): string | undefined;
@@ -1,11 +0,0 @@
1
- /**
2
- * @name validateHexString
3
- * @description Checks if a string is a hex string. Required to account for type differences between different polkadot libraries
4
- * @param {string} str - string to check
5
- * @returns {`0x${string}`} - boolean
6
- * @example
7
- * validateHexString("0x1234") // "0x1234"
8
- * validateHexString("1234") // Error: Expected a hex string
9
- * validateHexString(1234) // Error: Expected a string
10
- **/
11
- export declare const validateHexString: (str: string) => `0x${string}`;
@@ -1 +0,0 @@
1
- export * from "./declarations/src/index";