@sudobility/types 1.9.52 → 1.9.54
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.cjs +10 -4
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -4
- package/dist/index.js.map +1 -1
- package/dist/types/blockchain/index.cjs +30 -0
- package/dist/types/blockchain/index.d.ts +14 -0
- package/dist/types/blockchain/index.d.ts.map +1 -0
- package/dist/types/blockchain/index.js +30 -0
- package/dist/types/blockchain/index.js.map +1 -0
- package/dist/types/blockchain/validation.cjs +57 -1
- package/dist/types/blockchain/validation.d.ts +57 -1
- package/dist/types/blockchain/validation.d.ts.map +1 -1
- package/dist/types/blockchain/validation.js +57 -1
- package/dist/types/blockchain/validation.js.map +1 -1
- package/dist/types/business/enums.cjs +110 -25
- package/dist/types/business/enums.d.ts +110 -2
- package/dist/types/business/enums.d.ts.map +1 -1
- package/dist/types/business/enums.js +110 -25
- package/dist/types/business/enums.js.map +1 -1
- package/dist/types/common.cjs +7 -1
- package/dist/types/common.d.ts +134 -20
- package/dist/types/common.d.ts.map +1 -1
- package/dist/types/common.js +7 -1
- package/dist/types/common.js.map +1 -1
- package/dist/types/subscription/entitlements.cjs +14 -0
- package/dist/types/subscription/entitlements.d.ts +11 -0
- package/dist/types/subscription/entitlements.d.ts.map +1 -0
- package/dist/types/subscription/entitlements.js +14 -0
- package/dist/types/subscription/entitlements.js.map +1 -0
- package/dist/types/subscription/period.cjs +29 -0
- package/dist/types/subscription/period.d.ts +18 -0
- package/dist/types/subscription/period.d.ts.map +1 -0
- package/dist/types/subscription/period.js +29 -0
- package/dist/types/subscription/period.js.map +1 -0
- package/dist/utils/async-helpers.cjs +124 -10
- package/dist/utils/async-helpers.d.ts +129 -8
- package/dist/utils/async-helpers.d.ts.map +1 -1
- package/dist/utils/async-helpers.js +124 -10
- package/dist/utils/async-helpers.js.map +1 -1
- package/dist/utils/formatting/currency.cjs +5 -2
- package/dist/utils/formatting/currency.d.ts +5 -1
- package/dist/utils/formatting/currency.d.ts.map +1 -1
- package/dist/utils/formatting/currency.js +5 -2
- package/dist/utils/formatting/currency.js.map +1 -1
- package/dist/utils/formatting/date.cjs +67 -8
- package/dist/utils/formatting/date.d.ts +67 -8
- package/dist/utils/formatting/date.d.ts.map +1 -1
- package/dist/utils/formatting/date.js +67 -8
- package/dist/utils/formatting/date.js.map +1 -1
- package/dist/utils/formatting/string.cjs +150 -17
- package/dist/utils/formatting/string.d.ts +150 -17
- package/dist/utils/formatting/string.d.ts.map +1 -1
- package/dist/utils/formatting/string.js +150 -17
- package/dist/utils/formatting/string.js.map +1 -1
- package/dist/utils/validation/type-validation.cjs +94 -11
- package/dist/utils/validation/type-validation.d.ts +94 -11
- package/dist/utils/validation/type-validation.d.ts.map +1 -1
- package/dist/utils/validation/type-validation.js +94 -11
- package/dist/utils/validation/type-validation.js.map +1 -1
- package/package.json +6 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subscription Period Types
|
|
3
|
+
*
|
|
4
|
+
* Standard subscription periods and utilities for period comparison.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Standard subscription periods
|
|
8
|
+
*/
|
|
9
|
+
export type SubscriptionPeriod = 'weekly' | 'monthly' | 'quarterly' | 'yearly' | 'lifetime';
|
|
10
|
+
/**
|
|
11
|
+
* Period ranking for comparison (higher = longer)
|
|
12
|
+
*/
|
|
13
|
+
export declare const PERIOD_RANKS: Record<SubscriptionPeriod, number>;
|
|
14
|
+
/**
|
|
15
|
+
* All supported periods in order
|
|
16
|
+
*/
|
|
17
|
+
export declare const ALL_PERIODS: SubscriptionPeriod[];
|
|
18
|
+
//# sourceMappingURL=period.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"period.d.ts","sourceRoot":"","sources":["../../../src/types/subscription/period.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAC1B,QAAQ,GACR,SAAS,GACT,WAAW,GACX,QAAQ,GACR,UAAU,CAAC;AAEf;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,kBAAkB,EAAE,MAAM,CAM3D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,kBAAkB,EAM3C,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Subscription Period Types
|
|
4
|
+
*
|
|
5
|
+
* Standard subscription periods and utilities for period comparison.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.ALL_PERIODS = exports.PERIOD_RANKS = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* Period ranking for comparison (higher = longer)
|
|
11
|
+
*/
|
|
12
|
+
exports.PERIOD_RANKS = {
|
|
13
|
+
weekly: 1,
|
|
14
|
+
monthly: 2,
|
|
15
|
+
quarterly: 3,
|
|
16
|
+
yearly: 4,
|
|
17
|
+
lifetime: 5,
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* All supported periods in order
|
|
21
|
+
*/
|
|
22
|
+
exports.ALL_PERIODS = [
|
|
23
|
+
'weekly',
|
|
24
|
+
'monthly',
|
|
25
|
+
'quarterly',
|
|
26
|
+
'yearly',
|
|
27
|
+
'lifetime',
|
|
28
|
+
];
|
|
29
|
+
//# sourceMappingURL=period.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"period.js","sourceRoot":"","sources":["../../../src/types/subscription/period.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAYH;;GAEG;AACU,QAAA,YAAY,GAAuC;IAC9D,MAAM,EAAE,CAAC;IACT,OAAO,EAAE,CAAC;IACV,SAAS,EAAE,CAAC;IACZ,MAAM,EAAE,CAAC;IACT,QAAQ,EAAE,CAAC;CACZ,CAAC;AAEF;;GAEG;AACU,QAAA,WAAW,GAAyB;IAC/C,QAAQ;IACR,SAAS;IACT,WAAW;IACX,QAAQ;IACR,UAAU;CACX,CAAC"}
|
|
@@ -1,14 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Common async operation patterns and helpers
|
|
4
|
-
* Reduces boilerplate code for common async operations
|
|
3
|
+
* Common async operation patterns and helpers.
|
|
4
|
+
* Reduces boilerplate code for common async operations.
|
|
5
|
+
*
|
|
6
|
+
* @since 1.0.0
|
|
5
7
|
*/
|
|
6
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
9
|
exports.debounceAsync = exports.clearExpiredCache = exports.withCache = exports.withTimeout = exports.safeParallel = exports.withLoadingState = exports.safeAsync = void 0;
|
|
8
10
|
const logger_1 = require("./logging/logger");
|
|
9
11
|
/**
|
|
10
|
-
* Safely execute an async operation with error handling
|
|
11
|
-
* Returns a result object instead of throwing
|
|
12
|
+
* Safely execute an async operation with error handling.
|
|
13
|
+
* Returns a result object instead of throwing.
|
|
14
|
+
*
|
|
15
|
+
* @template T - The success data type
|
|
16
|
+
* @param operation - Async function to execute
|
|
17
|
+
* @param context - Optional context string for logging
|
|
18
|
+
* @returns A promise resolving to an {@link AsyncResult}
|
|
19
|
+
* @since 1.0.0
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const result = await safeAsync(() => fetchUser(id), 'fetchUser');
|
|
24
|
+
* if (result.success) {
|
|
25
|
+
* console.log(result.data);
|
|
26
|
+
* } else {
|
|
27
|
+
* console.error(result.error?.message);
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
12
30
|
*/
|
|
13
31
|
const safeAsync = async (operation, context) => {
|
|
14
32
|
try {
|
|
@@ -23,7 +41,26 @@ const safeAsync = async (operation, context) => {
|
|
|
23
41
|
};
|
|
24
42
|
exports.safeAsync = safeAsync;
|
|
25
43
|
/**
|
|
26
|
-
* Execute async operation with loading state tracking
|
|
44
|
+
* Execute async operation with loading state tracking.
|
|
45
|
+
* Manages `setLoading` and `setError` callbacks automatically.
|
|
46
|
+
*
|
|
47
|
+
* @template T - The success data type
|
|
48
|
+
* @param operation - Async function to execute
|
|
49
|
+
* @param setLoading - Callback to update loading state
|
|
50
|
+
* @param setError - Callback to update error state
|
|
51
|
+
* @param context - Optional context string for logging
|
|
52
|
+
* @returns The operation result, or undefined on error
|
|
53
|
+
* @since 1.0.0
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const data = await withLoadingState(
|
|
58
|
+
* () => api.getUsers(),
|
|
59
|
+
* setIsLoading,
|
|
60
|
+
* setErrorMsg,
|
|
61
|
+
* 'getUsers'
|
|
62
|
+
* );
|
|
63
|
+
* ```
|
|
27
64
|
*/
|
|
28
65
|
const withLoadingState = async (operation, setLoading, setError, context) => {
|
|
29
66
|
setLoading(true);
|
|
@@ -44,7 +81,22 @@ const withLoadingState = async (operation, setLoading, setError, context) => {
|
|
|
44
81
|
};
|
|
45
82
|
exports.withLoadingState = withLoadingState;
|
|
46
83
|
/**
|
|
47
|
-
* Execute multiple async operations in parallel with error handling
|
|
84
|
+
* Execute multiple async operations in parallel with error handling.
|
|
85
|
+
* All operations run concurrently via `Promise.all`.
|
|
86
|
+
*
|
|
87
|
+
* @template T - Tuple of result types
|
|
88
|
+
* @param operations - Array of async functions to execute in parallel
|
|
89
|
+
* @param context - Optional context string for logging
|
|
90
|
+
* @returns A promise resolving to an {@link AsyncResult} of the tuple
|
|
91
|
+
* @since 1.0.0
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const result = await safeParallel(
|
|
96
|
+
* [() => fetchUser(1), () => fetchPosts(1)] as const,
|
|
97
|
+
* 'loadProfile'
|
|
98
|
+
* );
|
|
99
|
+
* ```
|
|
48
100
|
*/
|
|
49
101
|
const safeParallel = async (operations, context) => {
|
|
50
102
|
try {
|
|
@@ -59,7 +111,25 @@ const safeParallel = async (operations, context) => {
|
|
|
59
111
|
};
|
|
60
112
|
exports.safeParallel = safeParallel;
|
|
61
113
|
/**
|
|
62
|
-
* Execute async operation with timeout
|
|
114
|
+
* Execute async operation with a timeout.
|
|
115
|
+
* Rejects if the operation does not complete within `timeoutMs`.
|
|
116
|
+
*
|
|
117
|
+
* @template T - The success data type
|
|
118
|
+
* @param operation - Async function to execute
|
|
119
|
+
* @param timeoutMs - Maximum time in milliseconds
|
|
120
|
+
* @param context - Optional context string for logging
|
|
121
|
+
* @returns The operation result
|
|
122
|
+
* @throws Error if the operation times out
|
|
123
|
+
* @since 1.0.0
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* const data = await withTimeout(
|
|
128
|
+
* () => fetch('/api/data').then((r) => r.json()),
|
|
129
|
+
* 5000,
|
|
130
|
+
* 'fetchData'
|
|
131
|
+
* );
|
|
132
|
+
* ```
|
|
63
133
|
*/
|
|
64
134
|
const withTimeout = async (operation, timeoutMs, context) => {
|
|
65
135
|
const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error(`Operation timed out after ${timeoutMs}ms`)), timeoutMs));
|
|
@@ -73,9 +143,30 @@ const withTimeout = async (operation, timeoutMs, context) => {
|
|
|
73
143
|
};
|
|
74
144
|
exports.withTimeout = withTimeout;
|
|
75
145
|
/**
|
|
76
|
-
*
|
|
146
|
+
* In-memory cache for {@link withCache}.
|
|
77
147
|
*/
|
|
78
148
|
const cache = new Map();
|
|
149
|
+
/**
|
|
150
|
+
* Cache async operation results with TTL (time-to-live).
|
|
151
|
+
* Returns cached data if still valid; otherwise executes the operation
|
|
152
|
+
* and stores the result.
|
|
153
|
+
*
|
|
154
|
+
* @template T - The cached data type
|
|
155
|
+
* @param key - Unique cache key
|
|
156
|
+
* @param operation - Async function whose result is cached
|
|
157
|
+
* @param ttlMs - Cache TTL in milliseconds (default: 5 minutes)
|
|
158
|
+
* @returns The cached or freshly fetched data
|
|
159
|
+
* @since 1.0.0
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* const user = await withCache(
|
|
164
|
+
* `user-${id}`,
|
|
165
|
+
* () => api.getUser(id),
|
|
166
|
+
* 60_000 // 1 minute
|
|
167
|
+
* );
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
79
170
|
const withCache = async (key, operation, ttlMs = 5 * 60 * 1000 // 5 minutes default
|
|
80
171
|
) => {
|
|
81
172
|
const cached = cache.get(key);
|
|
@@ -89,7 +180,8 @@ const withCache = async (key, operation, ttlMs = 5 * 60 * 1000 // 5 minutes defa
|
|
|
89
180
|
};
|
|
90
181
|
exports.withCache = withCache;
|
|
91
182
|
/**
|
|
92
|
-
* Clear expired cache entries
|
|
183
|
+
* Clear expired cache entries from the in-memory cache.
|
|
184
|
+
* @since 1.0.0
|
|
93
185
|
*/
|
|
94
186
|
const clearExpiredCache = () => {
|
|
95
187
|
const now = Date.now();
|
|
@@ -101,9 +193,31 @@ const clearExpiredCache = () => {
|
|
|
101
193
|
};
|
|
102
194
|
exports.clearExpiredCache = clearExpiredCache;
|
|
103
195
|
/**
|
|
104
|
-
*
|
|
196
|
+
* Active debounce timers keyed by operation key.
|
|
105
197
|
*/
|
|
106
198
|
const debounceMap = new Map();
|
|
199
|
+
/**
|
|
200
|
+
* Debounce async function calls by key.
|
|
201
|
+
* Only the last call within the delay window will execute.
|
|
202
|
+
*
|
|
203
|
+
* @template T - Argument types
|
|
204
|
+
* @template R - Return type
|
|
205
|
+
* @param fn - The async function to debounce
|
|
206
|
+
* @param delay - Debounce delay in milliseconds
|
|
207
|
+
* @param key - Unique key identifying this debounced operation
|
|
208
|
+
* @returns A debounced version of `fn`
|
|
209
|
+
* @since 1.0.0
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```typescript
|
|
213
|
+
* const debouncedSearch = debounceAsync(
|
|
214
|
+
* (query: string) => api.search(query),
|
|
215
|
+
* 300,
|
|
216
|
+
* 'search'
|
|
217
|
+
* );
|
|
218
|
+
* await debouncedSearch('hello');
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
107
221
|
const debounceAsync = (fn, delay, key) => {
|
|
108
222
|
return (...args) => {
|
|
109
223
|
return new Promise(resolve => {
|
|
@@ -1,35 +1,156 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Common async operation patterns and helpers
|
|
3
|
-
* Reduces boilerplate code for common async operations
|
|
2
|
+
* Common async operation patterns and helpers.
|
|
3
|
+
* Reduces boilerplate code for common async operations.
|
|
4
|
+
*
|
|
5
|
+
* @since 1.0.0
|
|
4
6
|
*/
|
|
5
7
|
import { Optional } from '../types/common';
|
|
8
|
+
/**
|
|
9
|
+
* Result type for safe async operations.
|
|
10
|
+
* Contains either `data` on success or `error` on failure.
|
|
11
|
+
*
|
|
12
|
+
* @template T - The success data type
|
|
13
|
+
* @since 1.0.0
|
|
14
|
+
*/
|
|
6
15
|
type AsyncResult<T> = {
|
|
7
16
|
data?: T;
|
|
8
17
|
error?: Error;
|
|
9
18
|
success: boolean;
|
|
10
19
|
};
|
|
11
20
|
/**
|
|
12
|
-
* Safely execute an async operation with error handling
|
|
13
|
-
* Returns a result object instead of throwing
|
|
21
|
+
* Safely execute an async operation with error handling.
|
|
22
|
+
* Returns a result object instead of throwing.
|
|
23
|
+
*
|
|
24
|
+
* @template T - The success data type
|
|
25
|
+
* @param operation - Async function to execute
|
|
26
|
+
* @param context - Optional context string for logging
|
|
27
|
+
* @returns A promise resolving to an {@link AsyncResult}
|
|
28
|
+
* @since 1.0.0
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const result = await safeAsync(() => fetchUser(id), 'fetchUser');
|
|
33
|
+
* if (result.success) {
|
|
34
|
+
* console.log(result.data);
|
|
35
|
+
* } else {
|
|
36
|
+
* console.error(result.error?.message);
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
14
39
|
*/
|
|
15
40
|
declare const safeAsync: <T>(operation: () => Promise<T>, context?: string) => Promise<AsyncResult<T>>;
|
|
16
41
|
/**
|
|
17
|
-
* Execute async operation with loading state tracking
|
|
42
|
+
* Execute async operation with loading state tracking.
|
|
43
|
+
* Manages `setLoading` and `setError` callbacks automatically.
|
|
44
|
+
*
|
|
45
|
+
* @template T - The success data type
|
|
46
|
+
* @param operation - Async function to execute
|
|
47
|
+
* @param setLoading - Callback to update loading state
|
|
48
|
+
* @param setError - Callback to update error state
|
|
49
|
+
* @param context - Optional context string for logging
|
|
50
|
+
* @returns The operation result, or undefined on error
|
|
51
|
+
* @since 1.0.0
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const data = await withLoadingState(
|
|
56
|
+
* () => api.getUsers(),
|
|
57
|
+
* setIsLoading,
|
|
58
|
+
* setErrorMsg,
|
|
59
|
+
* 'getUsers'
|
|
60
|
+
* );
|
|
61
|
+
* ```
|
|
18
62
|
*/
|
|
19
63
|
declare const withLoadingState: <T>(operation: () => Promise<T>, setLoading: (loading: boolean) => void, setError: (error: Optional<string>) => void, context?: string) => Promise<Optional<T>>;
|
|
20
64
|
/**
|
|
21
|
-
* Execute multiple async operations in parallel with error handling
|
|
65
|
+
* Execute multiple async operations in parallel with error handling.
|
|
66
|
+
* All operations run concurrently via `Promise.all`.
|
|
67
|
+
*
|
|
68
|
+
* @template T - Tuple of result types
|
|
69
|
+
* @param operations - Array of async functions to execute in parallel
|
|
70
|
+
* @param context - Optional context string for logging
|
|
71
|
+
* @returns A promise resolving to an {@link AsyncResult} of the tuple
|
|
72
|
+
* @since 1.0.0
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const result = await safeParallel(
|
|
77
|
+
* [() => fetchUser(1), () => fetchPosts(1)] as const,
|
|
78
|
+
* 'loadProfile'
|
|
79
|
+
* );
|
|
80
|
+
* ```
|
|
22
81
|
*/
|
|
23
82
|
declare const safeParallel: <T extends readonly unknown[]>(operations: readonly [...{ [K in keyof T]: () => Promise<T[K]>; }], context?: string) => Promise<AsyncResult<T>>;
|
|
24
83
|
/**
|
|
25
|
-
* Execute async operation with timeout
|
|
84
|
+
* Execute async operation with a timeout.
|
|
85
|
+
* Rejects if the operation does not complete within `timeoutMs`.
|
|
86
|
+
*
|
|
87
|
+
* @template T - The success data type
|
|
88
|
+
* @param operation - Async function to execute
|
|
89
|
+
* @param timeoutMs - Maximum time in milliseconds
|
|
90
|
+
* @param context - Optional context string for logging
|
|
91
|
+
* @returns The operation result
|
|
92
|
+
* @throws Error if the operation times out
|
|
93
|
+
* @since 1.0.0
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const data = await withTimeout(
|
|
98
|
+
* () => fetch('/api/data').then((r) => r.json()),
|
|
99
|
+
* 5000,
|
|
100
|
+
* 'fetchData'
|
|
101
|
+
* );
|
|
102
|
+
* ```
|
|
26
103
|
*/
|
|
27
104
|
declare const withTimeout: <T>(operation: () => Promise<T>, timeoutMs: number, context?: string) => Promise<T>;
|
|
105
|
+
/**
|
|
106
|
+
* Cache async operation results with TTL (time-to-live).
|
|
107
|
+
* Returns cached data if still valid; otherwise executes the operation
|
|
108
|
+
* and stores the result.
|
|
109
|
+
*
|
|
110
|
+
* @template T - The cached data type
|
|
111
|
+
* @param key - Unique cache key
|
|
112
|
+
* @param operation - Async function whose result is cached
|
|
113
|
+
* @param ttlMs - Cache TTL in milliseconds (default: 5 minutes)
|
|
114
|
+
* @returns The cached or freshly fetched data
|
|
115
|
+
* @since 1.0.0
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* const user = await withCache(
|
|
120
|
+
* `user-${id}`,
|
|
121
|
+
* () => api.getUser(id),
|
|
122
|
+
* 60_000 // 1 minute
|
|
123
|
+
* );
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
28
126
|
declare const withCache: <T>(key: string, operation: () => Promise<T>, ttlMs?: number) => Promise<T>;
|
|
29
127
|
/**
|
|
30
|
-
* Clear expired cache entries
|
|
128
|
+
* Clear expired cache entries from the in-memory cache.
|
|
129
|
+
* @since 1.0.0
|
|
31
130
|
*/
|
|
32
131
|
declare const clearExpiredCache: () => void;
|
|
132
|
+
/**
|
|
133
|
+
* Debounce async function calls by key.
|
|
134
|
+
* Only the last call within the delay window will execute.
|
|
135
|
+
*
|
|
136
|
+
* @template T - Argument types
|
|
137
|
+
* @template R - Return type
|
|
138
|
+
* @param fn - The async function to debounce
|
|
139
|
+
* @param delay - Debounce delay in milliseconds
|
|
140
|
+
* @param key - Unique key identifying this debounced operation
|
|
141
|
+
* @returns A debounced version of `fn`
|
|
142
|
+
* @since 1.0.0
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* const debouncedSearch = debounceAsync(
|
|
147
|
+
* (query: string) => api.search(query),
|
|
148
|
+
* 300,
|
|
149
|
+
* 'search'
|
|
150
|
+
* );
|
|
151
|
+
* await debouncedSearch('hello');
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
33
154
|
declare const debounceAsync: <T extends unknown[], R>(fn: (...args: T) => Promise<R>, delay: number, key: string) => ((...args: T) => Promise<Optional<R>>);
|
|
34
155
|
export { safeAsync, withLoadingState, safeParallel, withTimeout, withCache, clearExpiredCache, debounceAsync, type AsyncResult, };
|
|
35
156
|
//# sourceMappingURL=async-helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-helpers.d.ts","sourceRoot":"","sources":["../../src/utils/async-helpers.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"async-helpers.d.ts","sourceRoot":"","sources":["../../src/utils/async-helpers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C;;;;;;GAMG;A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CAAC,CAAC,EAC3B,QAAO,MAAsB,KAC5B,OAAO,CAAC,CAAC,CAWX,CAAC;AAEF;;;GAGG;AACH,QAAA,MAAM,iBAAiB,QAAO,IAO7B,CAAC;AAOF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,QAAA,MAAM,aAAa,GAAI,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC,EAC3C,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EAC9B,OAAO,MAAM,EACb,KAAK,MAAM,KACV,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAsBvC,CAAC;AAEF,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,KAAK,WAAW,GACjB,CAAC"}
|
|
@@ -1,14 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Common async operation patterns and helpers
|
|
4
|
-
* Reduces boilerplate code for common async operations
|
|
3
|
+
* Common async operation patterns and helpers.
|
|
4
|
+
* Reduces boilerplate code for common async operations.
|
|
5
|
+
*
|
|
6
|
+
* @since 1.0.0
|
|
5
7
|
*/
|
|
6
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
9
|
exports.debounceAsync = exports.clearExpiredCache = exports.withCache = exports.withTimeout = exports.safeParallel = exports.withLoadingState = exports.safeAsync = void 0;
|
|
8
10
|
const logger_1 = require("./logging/logger");
|
|
9
11
|
/**
|
|
10
|
-
* Safely execute an async operation with error handling
|
|
11
|
-
* Returns a result object instead of throwing
|
|
12
|
+
* Safely execute an async operation with error handling.
|
|
13
|
+
* Returns a result object instead of throwing.
|
|
14
|
+
*
|
|
15
|
+
* @template T - The success data type
|
|
16
|
+
* @param operation - Async function to execute
|
|
17
|
+
* @param context - Optional context string for logging
|
|
18
|
+
* @returns A promise resolving to an {@link AsyncResult}
|
|
19
|
+
* @since 1.0.0
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const result = await safeAsync(() => fetchUser(id), 'fetchUser');
|
|
24
|
+
* if (result.success) {
|
|
25
|
+
* console.log(result.data);
|
|
26
|
+
* } else {
|
|
27
|
+
* console.error(result.error?.message);
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
12
30
|
*/
|
|
13
31
|
const safeAsync = async (operation, context) => {
|
|
14
32
|
try {
|
|
@@ -23,7 +41,26 @@ const safeAsync = async (operation, context) => {
|
|
|
23
41
|
};
|
|
24
42
|
exports.safeAsync = safeAsync;
|
|
25
43
|
/**
|
|
26
|
-
* Execute async operation with loading state tracking
|
|
44
|
+
* Execute async operation with loading state tracking.
|
|
45
|
+
* Manages `setLoading` and `setError` callbacks automatically.
|
|
46
|
+
*
|
|
47
|
+
* @template T - The success data type
|
|
48
|
+
* @param operation - Async function to execute
|
|
49
|
+
* @param setLoading - Callback to update loading state
|
|
50
|
+
* @param setError - Callback to update error state
|
|
51
|
+
* @param context - Optional context string for logging
|
|
52
|
+
* @returns The operation result, or undefined on error
|
|
53
|
+
* @since 1.0.0
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const data = await withLoadingState(
|
|
58
|
+
* () => api.getUsers(),
|
|
59
|
+
* setIsLoading,
|
|
60
|
+
* setErrorMsg,
|
|
61
|
+
* 'getUsers'
|
|
62
|
+
* );
|
|
63
|
+
* ```
|
|
27
64
|
*/
|
|
28
65
|
const withLoadingState = async (operation, setLoading, setError, context) => {
|
|
29
66
|
setLoading(true);
|
|
@@ -44,7 +81,22 @@ const withLoadingState = async (operation, setLoading, setError, context) => {
|
|
|
44
81
|
};
|
|
45
82
|
exports.withLoadingState = withLoadingState;
|
|
46
83
|
/**
|
|
47
|
-
* Execute multiple async operations in parallel with error handling
|
|
84
|
+
* Execute multiple async operations in parallel with error handling.
|
|
85
|
+
* All operations run concurrently via `Promise.all`.
|
|
86
|
+
*
|
|
87
|
+
* @template T - Tuple of result types
|
|
88
|
+
* @param operations - Array of async functions to execute in parallel
|
|
89
|
+
* @param context - Optional context string for logging
|
|
90
|
+
* @returns A promise resolving to an {@link AsyncResult} of the tuple
|
|
91
|
+
* @since 1.0.0
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const result = await safeParallel(
|
|
96
|
+
* [() => fetchUser(1), () => fetchPosts(1)] as const,
|
|
97
|
+
* 'loadProfile'
|
|
98
|
+
* );
|
|
99
|
+
* ```
|
|
48
100
|
*/
|
|
49
101
|
const safeParallel = async (operations, context) => {
|
|
50
102
|
try {
|
|
@@ -59,7 +111,25 @@ const safeParallel = async (operations, context) => {
|
|
|
59
111
|
};
|
|
60
112
|
exports.safeParallel = safeParallel;
|
|
61
113
|
/**
|
|
62
|
-
* Execute async operation with timeout
|
|
114
|
+
* Execute async operation with a timeout.
|
|
115
|
+
* Rejects if the operation does not complete within `timeoutMs`.
|
|
116
|
+
*
|
|
117
|
+
* @template T - The success data type
|
|
118
|
+
* @param operation - Async function to execute
|
|
119
|
+
* @param timeoutMs - Maximum time in milliseconds
|
|
120
|
+
* @param context - Optional context string for logging
|
|
121
|
+
* @returns The operation result
|
|
122
|
+
* @throws Error if the operation times out
|
|
123
|
+
* @since 1.0.0
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* const data = await withTimeout(
|
|
128
|
+
* () => fetch('/api/data').then((r) => r.json()),
|
|
129
|
+
* 5000,
|
|
130
|
+
* 'fetchData'
|
|
131
|
+
* );
|
|
132
|
+
* ```
|
|
63
133
|
*/
|
|
64
134
|
const withTimeout = async (operation, timeoutMs, context) => {
|
|
65
135
|
const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error(`Operation timed out after ${timeoutMs}ms`)), timeoutMs));
|
|
@@ -73,9 +143,30 @@ const withTimeout = async (operation, timeoutMs, context) => {
|
|
|
73
143
|
};
|
|
74
144
|
exports.withTimeout = withTimeout;
|
|
75
145
|
/**
|
|
76
|
-
*
|
|
146
|
+
* In-memory cache for {@link withCache}.
|
|
77
147
|
*/
|
|
78
148
|
const cache = new Map();
|
|
149
|
+
/**
|
|
150
|
+
* Cache async operation results with TTL (time-to-live).
|
|
151
|
+
* Returns cached data if still valid; otherwise executes the operation
|
|
152
|
+
* and stores the result.
|
|
153
|
+
*
|
|
154
|
+
* @template T - The cached data type
|
|
155
|
+
* @param key - Unique cache key
|
|
156
|
+
* @param operation - Async function whose result is cached
|
|
157
|
+
* @param ttlMs - Cache TTL in milliseconds (default: 5 minutes)
|
|
158
|
+
* @returns The cached or freshly fetched data
|
|
159
|
+
* @since 1.0.0
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* const user = await withCache(
|
|
164
|
+
* `user-${id}`,
|
|
165
|
+
* () => api.getUser(id),
|
|
166
|
+
* 60_000 // 1 minute
|
|
167
|
+
* );
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
79
170
|
const withCache = async (key, operation, ttlMs = 5 * 60 * 1000 // 5 minutes default
|
|
80
171
|
) => {
|
|
81
172
|
const cached = cache.get(key);
|
|
@@ -89,7 +180,8 @@ const withCache = async (key, operation, ttlMs = 5 * 60 * 1000 // 5 minutes defa
|
|
|
89
180
|
};
|
|
90
181
|
exports.withCache = withCache;
|
|
91
182
|
/**
|
|
92
|
-
* Clear expired cache entries
|
|
183
|
+
* Clear expired cache entries from the in-memory cache.
|
|
184
|
+
* @since 1.0.0
|
|
93
185
|
*/
|
|
94
186
|
const clearExpiredCache = () => {
|
|
95
187
|
const now = Date.now();
|
|
@@ -101,9 +193,31 @@ const clearExpiredCache = () => {
|
|
|
101
193
|
};
|
|
102
194
|
exports.clearExpiredCache = clearExpiredCache;
|
|
103
195
|
/**
|
|
104
|
-
*
|
|
196
|
+
* Active debounce timers keyed by operation key.
|
|
105
197
|
*/
|
|
106
198
|
const debounceMap = new Map();
|
|
199
|
+
/**
|
|
200
|
+
* Debounce async function calls by key.
|
|
201
|
+
* Only the last call within the delay window will execute.
|
|
202
|
+
*
|
|
203
|
+
* @template T - Argument types
|
|
204
|
+
* @template R - Return type
|
|
205
|
+
* @param fn - The async function to debounce
|
|
206
|
+
* @param delay - Debounce delay in milliseconds
|
|
207
|
+
* @param key - Unique key identifying this debounced operation
|
|
208
|
+
* @returns A debounced version of `fn`
|
|
209
|
+
* @since 1.0.0
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```typescript
|
|
213
|
+
* const debouncedSearch = debounceAsync(
|
|
214
|
+
* (query: string) => api.search(query),
|
|
215
|
+
* 300,
|
|
216
|
+
* 'search'
|
|
217
|
+
* );
|
|
218
|
+
* await debouncedSearch('hello');
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
107
221
|
const debounceAsync = (fn, delay, key) => {
|
|
108
222
|
return (...args) => {
|
|
109
223
|
return new Promise(resolve => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-helpers.js","sourceRoot":"","sources":["../../src/utils/async-helpers.ts"],"names":[],"mappings":";AAAA;;;
|
|
1
|
+
{"version":3,"file":"async-helpers.js","sourceRoot":"","sources":["../../src/utils/async-helpers.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,6CAA0C;AAgB1C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,SAAS,GAAG,KAAK,EACrB,SAA2B,EAC3B,OAAgB,EACS,EAAE;IAC3B,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,SAAS,EAAE,CAAC;QAC/B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IACjC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,QAAQ,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,C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C,OAAO,CAAC,EAAE;YAC3B,MAAM,eAAe,GAAG,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC7C,IAAI,eAAe,EAAE,CAAC;gBACpB,YAAY,CAAC,eAAe,CAAC,CAAC;YAChC,CAAC;YAED,MAAM,OAAO,GAAG,UAAU,CAAC,KAAK,IAAI,EAAE;gBACpC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBACxB,IAAI,CAAC;oBACH,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;oBACjC,OAAO,CAAC,MAAM,CAAC,CAAC;gBAClB,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,eAAM,CAAC,KAAK,CAAC,4BAA4B,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;oBACvD,OAAO,CAAC,SAAS,CAAC,CAAC;gBACrB,CAAC;YACH,CAAC,EAAE,KAAK,CAAC,CAAC;YAEV,WAAW,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;AASA,sCAAa"}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Currency formatting utilities for USDC and other tokens
|
|
3
|
+
* Currency formatting utilities for USDC and other tokens.
|
|
4
|
+
*
|
|
5
|
+
* @since 1.0.0
|
|
4
6
|
*/
|
|
5
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
8
|
exports.CLAIM_PERIOD_DAYS = exports.USDC_DECIMALS = void 0;
|
|
7
9
|
exports.formatUSDC = formatUSDC;
|
|
8
10
|
exports.parseUSDC = parseUSDC;
|
|
9
|
-
|
|
11
|
+
/** Number of decimal places for USDC token amounts. */
|
|
10
12
|
exports.USDC_DECIMALS = 6;
|
|
13
|
+
/** Revenue claim expiration period in days. */
|
|
11
14
|
exports.CLAIM_PERIOD_DAYS = 60;
|
|
12
15
|
/**
|
|
13
16
|
* Format USDC amount from smallest unit to human-readable string
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Currency formatting utilities for USDC and other tokens
|
|
2
|
+
* Currency formatting utilities for USDC and other tokens.
|
|
3
|
+
*
|
|
4
|
+
* @since 1.0.0
|
|
3
5
|
*/
|
|
6
|
+
/** Number of decimal places for USDC token amounts. */
|
|
4
7
|
export declare const USDC_DECIMALS = 6;
|
|
8
|
+
/** Revenue claim expiration period in days. */
|
|
5
9
|
export declare const CLAIM_PERIOD_DAYS = 60;
|
|
6
10
|
/**
|
|
7
11
|
* Format USDC amount from smallest unit to human-readable string
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../../../src/utils/formatting/currency.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../../../src/utils/formatting/currency.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,uDAAuD;AACvD,eAAO,MAAM,aAAa,IAAI,CAAC;AAE/B,+CAA+C;AAC/C,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEhD"}
|