@talismn/util 0.5.4 → 0.5.6
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.
|
@@ -21,5 +21,25 @@ type QueryOptions<Output, Args> = {
|
|
|
21
21
|
refreshInterval?: number;
|
|
22
22
|
serializer?: (args: Args) => string;
|
|
23
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
|
+
*/
|
|
24
44
|
export declare const getQuery$: <Output, Args>({ namespace, args, queryFn, defaultValue, refreshInterval, serializer, }: QueryOptions<Output, Args>) => Observable<QueryResult<Output>>;
|
|
25
45
|
export {};
|
|
@@ -128,9 +128,11 @@ const formatDecimals = (num, digits = MIN_DIGITS, options = {}, locale = "en-US"
|
|
|
128
128
|
// format
|
|
129
129
|
|
|
130
130
|
return Intl.NumberFormat(locale, {
|
|
131
|
-
//compact notation (K, M, B) if above 9999
|
|
131
|
+
// compact notation (K, M, B) if above 9999
|
|
132
132
|
notation: truncatedValue.gt(9999) ? "compact" : "standard",
|
|
133
|
-
|
|
133
|
+
// NOTE: possible values are from `0` to `21`
|
|
134
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#maximumsignificantdigits
|
|
135
|
+
maximumSignificantDigits: Math.max(1, Math.min(digits + (truncatedValue.lt(1) ? 1 : 0), 21)),
|
|
134
136
|
...options
|
|
135
137
|
}).format(truncatedValue.toNumber());
|
|
136
138
|
};
|
|
@@ -388,6 +390,26 @@ const getGenericErrorMessage = error => {
|
|
|
388
390
|
return String(error) || "Unknown error";
|
|
389
391
|
};
|
|
390
392
|
|
|
393
|
+
/**
|
|
394
|
+
* Creates a shared observable for executing queries with caching, loading states, and automatic refresh capabilities.
|
|
395
|
+
*
|
|
396
|
+
* @example
|
|
397
|
+
* ```typescript
|
|
398
|
+
* const userQuery$ = getQuery$({
|
|
399
|
+
* namespace: 'users',
|
|
400
|
+
* args: { userId: 123 },
|
|
401
|
+
* queryFn: async ({ userId }) => fetchUser(userId),
|
|
402
|
+
* defaultValue: null,
|
|
403
|
+
* refreshInterval: 30000
|
|
404
|
+
* });
|
|
405
|
+
*
|
|
406
|
+
* userQuery$.subscribe(result => {
|
|
407
|
+
* if (result.status === 'loaded') {
|
|
408
|
+
* console.log(result.data);
|
|
409
|
+
* }
|
|
410
|
+
* });
|
|
411
|
+
* ```
|
|
412
|
+
*/
|
|
391
413
|
const getQuery$ = ({
|
|
392
414
|
namespace,
|
|
393
415
|
args,
|
|
@@ -128,9 +128,11 @@ const formatDecimals = (num, digits = MIN_DIGITS, options = {}, locale = "en-US"
|
|
|
128
128
|
// format
|
|
129
129
|
|
|
130
130
|
return Intl.NumberFormat(locale, {
|
|
131
|
-
//compact notation (K, M, B) if above 9999
|
|
131
|
+
// compact notation (K, M, B) if above 9999
|
|
132
132
|
notation: truncatedValue.gt(9999) ? "compact" : "standard",
|
|
133
|
-
|
|
133
|
+
// NOTE: possible values are from `0` to `21`
|
|
134
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#maximumsignificantdigits
|
|
135
|
+
maximumSignificantDigits: Math.max(1, Math.min(digits + (truncatedValue.lt(1) ? 1 : 0), 21)),
|
|
134
136
|
...options
|
|
135
137
|
}).format(truncatedValue.toNumber());
|
|
136
138
|
};
|
|
@@ -388,6 +390,26 @@ const getGenericErrorMessage = error => {
|
|
|
388
390
|
return String(error) || "Unknown error";
|
|
389
391
|
};
|
|
390
392
|
|
|
393
|
+
/**
|
|
394
|
+
* Creates a shared observable for executing queries with caching, loading states, and automatic refresh capabilities.
|
|
395
|
+
*
|
|
396
|
+
* @example
|
|
397
|
+
* ```typescript
|
|
398
|
+
* const userQuery$ = getQuery$({
|
|
399
|
+
* namespace: 'users',
|
|
400
|
+
* args: { userId: 123 },
|
|
401
|
+
* queryFn: async ({ userId }) => fetchUser(userId),
|
|
402
|
+
* defaultValue: null,
|
|
403
|
+
* refreshInterval: 30000
|
|
404
|
+
* });
|
|
405
|
+
*
|
|
406
|
+
* userQuery$.subscribe(result => {
|
|
407
|
+
* if (result.status === 'loaded') {
|
|
408
|
+
* console.log(result.data);
|
|
409
|
+
* }
|
|
410
|
+
* });
|
|
411
|
+
* ```
|
|
412
|
+
*/
|
|
391
413
|
const getQuery$ = ({
|
|
392
414
|
namespace,
|
|
393
415
|
args,
|
package/dist/talismn-util.esm.js
CHANGED
|
@@ -122,9 +122,11 @@ const formatDecimals = (num, digits = MIN_DIGITS, options = {}, locale = "en-US"
|
|
|
122
122
|
// format
|
|
123
123
|
|
|
124
124
|
return Intl.NumberFormat(locale, {
|
|
125
|
-
//compact notation (K, M, B) if above 9999
|
|
125
|
+
// compact notation (K, M, B) if above 9999
|
|
126
126
|
notation: truncatedValue.gt(9999) ? "compact" : "standard",
|
|
127
|
-
|
|
127
|
+
// NOTE: possible values are from `0` to `21`
|
|
128
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#maximumsignificantdigits
|
|
129
|
+
maximumSignificantDigits: Math.max(1, Math.min(digits + (truncatedValue.lt(1) ? 1 : 0), 21)),
|
|
128
130
|
...options
|
|
129
131
|
}).format(truncatedValue.toNumber());
|
|
130
132
|
};
|
|
@@ -382,6 +384,26 @@ const getGenericErrorMessage = error => {
|
|
|
382
384
|
return String(error) || "Unknown error";
|
|
383
385
|
};
|
|
384
386
|
|
|
387
|
+
/**
|
|
388
|
+
* Creates a shared observable for executing queries with caching, loading states, and automatic refresh capabilities.
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* ```typescript
|
|
392
|
+
* const userQuery$ = getQuery$({
|
|
393
|
+
* namespace: 'users',
|
|
394
|
+
* args: { userId: 123 },
|
|
395
|
+
* queryFn: async ({ userId }) => fetchUser(userId),
|
|
396
|
+
* defaultValue: null,
|
|
397
|
+
* refreshInterval: 30000
|
|
398
|
+
* });
|
|
399
|
+
*
|
|
400
|
+
* userQuery$.subscribe(result => {
|
|
401
|
+
* if (result.status === 'loaded') {
|
|
402
|
+
* console.log(result.data);
|
|
403
|
+
* }
|
|
404
|
+
* });
|
|
405
|
+
* ```
|
|
406
|
+
*/
|
|
385
407
|
const getQuery$ = ({
|
|
386
408
|
namespace,
|
|
387
409
|
args,
|