@gala-chain/launchpad-sdk 3.29.0 → 3.31.2
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/CHANGELOG.md +35 -7
- package/README.md +105 -0
- package/dist/LaunchpadSDK.d.ts +8 -0
- package/dist/LaunchpadSDK.d.ts.map +1 -1
- package/dist/api/dto/TransferTokenDto.d.ts.map +1 -1
- package/dist/constants/version.generated.d.ts +1 -1
- package/dist/helpers/sdk.d.ts +1 -0
- package/dist/helpers/sdk.d.ts.map +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/services/BaseService.d.ts +32 -3
- package/dist/services/BaseService.d.ts.map +1 -1
- package/dist/services/BundleService.d.ts.map +1 -1
- package/dist/services/CommentService.d.ts.map +1 -1
- package/dist/services/DexPoolService.d.ts.map +1 -1
- package/dist/services/DexService.d.ts.map +1 -1
- package/dist/services/FaucetService.d.ts.map +1 -1
- package/dist/services/GSwapService.d.ts +57 -4
- package/dist/services/GSwapService.d.ts.map +1 -1
- package/dist/services/GalaChainService.d.ts.map +1 -1
- package/dist/services/ImageService.d.ts.map +1 -1
- package/dist/services/PoolService.d.ts.map +1 -1
- package/dist/services/PriceHistoryService.d.ts +4 -5
- package/dist/services/PriceHistoryService.d.ts.map +1 -1
- package/dist/services/SignatureService.d.ts +2 -3
- package/dist/services/SignatureService.d.ts.map +1 -1
- package/dist/services/TokenClassKeyService.d.ts +3 -4
- package/dist/services/TokenClassKeyService.d.ts.map +1 -1
- package/dist/services/TokenMetadataCache.d.ts +2 -2
- package/dist/services/TokenMetadataCache.d.ts.map +1 -1
- package/dist/services/TokenMetadataService.d.ts +3 -3
- package/dist/services/TokenMetadataService.d.ts.map +1 -1
- package/dist/services/TokenResolverService.d.ts +2 -2
- package/dist/services/TokenResolverService.d.ts.map +1 -1
- package/dist/services/TradeService.d.ts.map +1 -1
- package/dist/services/UserService.d.ts.map +1 -1
- package/dist/services/WebSocketService.d.ts +2 -2
- package/dist/services/WebSocketService.d.ts.map +1 -1
- package/dist/utils/SignatureHelper.d.ts.map +1 -1
- package/dist/utils/auto-pagination.d.ts +132 -0
- package/dist/utils/auto-pagination.d.ts.map +1 -0
- package/dist/utils/bignumber-helpers.d.ts +264 -0
- package/dist/utils/bignumber-helpers.d.ts.map +1 -0
- package/dist/utils/token-format-converter.d.ts +75 -3
- package/dist/utils/token-format-converter.d.ts.map +1 -1
- package/dist/utils/tokenNormalizer.d.ts +66 -0
- package/dist/utils/tokenNormalizer.d.ts.map +1 -1
- package/dist/utils/validation-helpers.d.ts +75 -0
- package/dist/utils/validation-helpers.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/utils/tokenFormatConverter.d.ts +0 -53
- package/dist/utils/tokenFormatConverter.d.ts.map +0 -1
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-Pagination Utility
|
|
3
|
+
*
|
|
4
|
+
* Generic utility for automatically paginating through API results.
|
|
5
|
+
* Eliminates duplicate pagination logic across multiple services.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import { Logger } from './Logger';
|
|
10
|
+
/**
|
|
11
|
+
* Result object from paginated API calls
|
|
12
|
+
* Expected structure for services using this utility
|
|
13
|
+
*/
|
|
14
|
+
export interface PaginatedResult<T> {
|
|
15
|
+
/** Array of items returned from this page */
|
|
16
|
+
items: T[];
|
|
17
|
+
/** Current page number */
|
|
18
|
+
page: number;
|
|
19
|
+
/** Page size/limit for this request */
|
|
20
|
+
limit: number;
|
|
21
|
+
/** Total count of all items across all pages */
|
|
22
|
+
total: number;
|
|
23
|
+
/** Total number of pages available */
|
|
24
|
+
totalPages: number;
|
|
25
|
+
/** Whether there is a next page available */
|
|
26
|
+
hasNext: boolean;
|
|
27
|
+
/** Whether there is a previous page available */
|
|
28
|
+
hasPrevious: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Options for auto-pagination
|
|
32
|
+
*/
|
|
33
|
+
export interface AutoPaginationOptions {
|
|
34
|
+
/** Maximum number of pages to fetch (safety limit to prevent infinite loops) */
|
|
35
|
+
maxPages?: number;
|
|
36
|
+
/** Logger instance for debug output */
|
|
37
|
+
logger?: Logger;
|
|
38
|
+
/** Page size to use for each request */
|
|
39
|
+
pageSize?: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Result object from auto-pagination
|
|
43
|
+
*/
|
|
44
|
+
export interface AutoPaginationResult<T> {
|
|
45
|
+
/** All items from all pages combined */
|
|
46
|
+
items: T[];
|
|
47
|
+
/** Total count from the API (across all pages) */
|
|
48
|
+
total: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Generic auto-pagination handler
|
|
52
|
+
*
|
|
53
|
+
* Automatically iterates through all pages of paginated API results
|
|
54
|
+
* and combines them into a single array. Handles common patterns like:
|
|
55
|
+
* - Safety limits to prevent infinite loops
|
|
56
|
+
* - Empty result detection
|
|
57
|
+
* - Debug logging of pagination progress
|
|
58
|
+
* - Preserves total count from the API
|
|
59
|
+
*
|
|
60
|
+
* @typeParam T - Type of items being paginated
|
|
61
|
+
* @param fetchFn Function that fetches a single page of results
|
|
62
|
+
* @param options Pagination options (maxPages, logger, pageSize)
|
|
63
|
+
* @returns Promise<AutoPaginationResult> All items and total count from the API
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const result = await autoPaginate(
|
|
68
|
+
* (page, limit) => service.fetchPools({ page, limit }),
|
|
69
|
+
* { maxPages: 1000, pageSize: 20, logger }
|
|
70
|
+
* );
|
|
71
|
+
* console.log(`Total: ${result.total}, Fetched: ${result.items.length}`);
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @since 3.32.0
|
|
75
|
+
*/
|
|
76
|
+
export declare function autoPaginate<T>(fetchFn: (page: number, limit: number) => Promise<PaginatedResult<T>>, options?: AutoPaginationOptions): Promise<AutoPaginationResult<T>>;
|
|
77
|
+
/**
|
|
78
|
+
* Build paginated result object for returning combined auto-paginated data
|
|
79
|
+
*
|
|
80
|
+
* Helper function to construct the standard paginated result structure
|
|
81
|
+
* when returning combined results from auto-pagination. Supports custom item
|
|
82
|
+
* key naming for service-specific result structures (pools, snapshots, etc.).
|
|
83
|
+
*
|
|
84
|
+
* Eliminates 5-7 line response object construction patterns found in:
|
|
85
|
+
* - DexPoolService.fetchAllDexPools() (lines 209-219)
|
|
86
|
+
* - PriceHistoryService.fetchAllPriceHistory() (lines 433-442)
|
|
87
|
+
* - Other services with similar patterns
|
|
88
|
+
*
|
|
89
|
+
* @typeParam T - Type of items in the result
|
|
90
|
+
* @param items Combined array of all items from all pages
|
|
91
|
+
* @param total Total count from last page (or sum of counts)
|
|
92
|
+
* @param itemsKey Optional field name for items (default: 'items'). Use for service-specific naming like 'pools', 'snapshots', 'comments'
|
|
93
|
+
* @returns PaginatedResult object with items flattened into a single "page"
|
|
94
|
+
*
|
|
95
|
+
* @example Basic usage (default 'items' key)
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const allItems = await autoPaginate(fetchFn);
|
|
98
|
+
* return buildPaginatedResult(allItems.items, allItems.total);
|
|
99
|
+
* // Returns: { items, page: 1, limit, total, totalPages: 1, hasNext: false, hasPrevious: false }
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @example With custom items key (eliminates manual response construction)
|
|
103
|
+
* ```typescript
|
|
104
|
+
* // DexPoolService - before (7 lines)
|
|
105
|
+
* const result = buildPaginatedResult(paginationResult.items, paginationResult.total);
|
|
106
|
+
* return {
|
|
107
|
+
* pools: result.items,
|
|
108
|
+
* page: result.page,
|
|
109
|
+
* limit: result.limit,
|
|
110
|
+
* total: result.total,
|
|
111
|
+
* totalPages: result.totalPages,
|
|
112
|
+
* hasNext: result.hasNext,
|
|
113
|
+
* hasPrevious: result.hasPrevious,
|
|
114
|
+
* };
|
|
115
|
+
*
|
|
116
|
+
* // DexPoolService - after (1 line)
|
|
117
|
+
* return buildPaginatedResult(paginationResult.items, paginationResult.total, 'pools');
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* @example Other service patterns
|
|
121
|
+
* ```typescript
|
|
122
|
+
* // PriceHistoryService
|
|
123
|
+
* return buildPaginatedResult(paginationResult.items, paginationResult.total, 'snapshots');
|
|
124
|
+
*
|
|
125
|
+
* // CommentService
|
|
126
|
+
* return buildPaginatedResult(allComments, totalCount, 'comments');
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* @since 3.32.0 - itemsKey parameter added in 3.32.0 for response structure flexibility
|
|
130
|
+
*/
|
|
131
|
+
export declare function buildPaginatedResult<T>(items: T[], total?: number, itemsKey?: 'items' | 'pools' | 'snapshots' | 'comments' | string): Record<string, any>;
|
|
132
|
+
//# sourceMappingURL=auto-pagination.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-pagination.d.ts","sourceRoot":"","sources":["../../src/utils/auto-pagination.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;;GAGG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,6CAA6C;IAC7C,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,gDAAgD;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,sCAAsC;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,6CAA6C;IAC7C,OAAO,EAAE,OAAO,CAAC;IACjB,iDAAiD;IACjD,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,gFAAgF;IAChF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uCAAuC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wCAAwC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB,CAAC,CAAC;IACrC,wCAAwC;IACxC,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,kDAAkD;IAClD,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAClC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,EACrE,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAyDlC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EACpC,KAAK,EAAE,CAAC,EAAE,EACV,KAAK,GAAE,MAAqB,EAC5B,QAAQ,GAAE,OAAO,GAAG,OAAO,GAAG,WAAW,GAAG,UAAU,GAAG,MAAgB,GACxE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAerB"}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BigNumber utility helpers for common calculations
|
|
3
|
+
*
|
|
4
|
+
* Consolidates repeated BigNumber patterns and operations to reduce
|
|
5
|
+
* code duplication across services, particularly in GSwapService.
|
|
6
|
+
*
|
|
7
|
+
* Common patterns extracted:
|
|
8
|
+
* - Slippage factor calculation
|
|
9
|
+
* - Min/max output calculation with slippage
|
|
10
|
+
* - Tick to sqrt ratio conversion (1.0001^(tick/2))
|
|
11
|
+
* - Price inversion
|
|
12
|
+
* - Safe BigNumber creation
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
import BigNumber from 'bignumber.js';
|
|
17
|
+
/**
|
|
18
|
+
* Create a BigNumber from a numeric value with safe defaults
|
|
19
|
+
*
|
|
20
|
+
* @param value The value to convert
|
|
21
|
+
* @param defaultValue Value to use if input is null/undefined/zero-length string (default: "0")
|
|
22
|
+
* @returns BigNumber instance
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const balance = toBigNumber(userData.balance || 0);
|
|
27
|
+
* const amount = toBigNumber(params.amount); // Uses "0" if undefined
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function toBigNumber(value: string | number | BigNumber | null | undefined, defaultValue?: string | number): BigNumber;
|
|
31
|
+
/**
|
|
32
|
+
* Create a BigNumber and immediately call toFixed()
|
|
33
|
+
*
|
|
34
|
+
* Convenience method for the pattern: `new BigNumber(value).toFixed()`
|
|
35
|
+
* Used for serializing calculated amounts back to strings.
|
|
36
|
+
*
|
|
37
|
+
* @param value The value to convert
|
|
38
|
+
* @param decimals Number of decimal places (default: undefined = max precision)
|
|
39
|
+
* @returns Fixed string representation
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const minOutput = toBigNumberFixed(calculated, 6); // "123.456789"
|
|
44
|
+
* const slippageAdjusted = toBigNumberFixed(amount.multipliedBy(0.99));
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function toBigNumberFixed(value: string | number | BigNumber | null | undefined, decimals?: number): string;
|
|
48
|
+
/**
|
|
49
|
+
* Calculate slippage-adjusted minimum output
|
|
50
|
+
*
|
|
51
|
+
* Consolidates the pattern:
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const slippageFactor = new BigNumber(1).minus(slippageTolerance);
|
|
54
|
+
* const minOutput = estimatedOutput.multipliedBy(slippageFactor);
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @param estimatedOutput The estimated output amount
|
|
58
|
+
* @param slippageTolerance Slippage tolerance as decimal (e.g., 0.01 for 1%)
|
|
59
|
+
* @returns Minimum acceptable output after slippage
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const quote = await sdk.getSwapQuote('GALA', 'GUSDC', '100');
|
|
64
|
+
* const minOutput = calculateSlippageAdjustedAmount(
|
|
65
|
+
* quote.estimatedOutput,
|
|
66
|
+
* 0.01 // 1% slippage
|
|
67
|
+
* );
|
|
68
|
+
* await sdk.executeSwap(..., minOutput.toFixed());
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function calculateSlippageAdjustedAmount(estimatedOutput: string | number | BigNumber, slippageTolerance?: number): BigNumber;
|
|
72
|
+
/**
|
|
73
|
+
* Calculate slippage factor (1 - tolerance)
|
|
74
|
+
*
|
|
75
|
+
* Consolidates: `new BigNumber(1).minus(tolerance)`
|
|
76
|
+
* Used as multiplier for slippage calculations.
|
|
77
|
+
*
|
|
78
|
+
* @param tolerance Slippage tolerance as decimal (e.g., 0.01 for 1%)
|
|
79
|
+
* @returns Slippage factor (e.g., 0.99 for 1% tolerance)
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const factor = calculateSlippageFactor(0.01); // BigNumber(0.99)
|
|
84
|
+
* const minAmount = estimatedAmount.multipliedBy(factor);
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export declare function calculateSlippageFactor(tolerance?: number): BigNumber;
|
|
88
|
+
/**
|
|
89
|
+
* Convert tick to sqrt ratio for liquidity calculations
|
|
90
|
+
*
|
|
91
|
+
* Consolidates the pattern: `new BigNumber(Math.pow(1.0001, tick / 2))`
|
|
92
|
+
* Used 8+ times in GSwapService for Uniswap V3 liquidity calculations.
|
|
93
|
+
*
|
|
94
|
+
* @param tick The tick value from the pool
|
|
95
|
+
* @returns Sqrt ratio as BigNumber
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const lowerSqrtRatio = tickToSqrtRatio(tickLower);
|
|
100
|
+
* const upperSqrtRatio = tickToSqrtRatio(tickUpper);
|
|
101
|
+
* const liquidityNeeded = calculateLiquidity(lowerSqrtRatio, upperSqrtRatio, ...);
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export declare function tickToSqrtRatio(tick: number): BigNumber;
|
|
105
|
+
/**
|
|
106
|
+
* Invert a price (calculate 1 / price)
|
|
107
|
+
*
|
|
108
|
+
* Consolidates: `new BigNumber(1).dividedBy(price)`
|
|
109
|
+
* Used for converting price direction (e.g., BTC/USD → USD/BTC).
|
|
110
|
+
*
|
|
111
|
+
* @param price The price to invert
|
|
112
|
+
* @param asFixed Whether to return as fixed string (default: false returns BigNumber)
|
|
113
|
+
* @returns Inverted price as BigNumber or string
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* const galuPrice = invertPrice('0.50'); // 2.0
|
|
118
|
+
* const displayPrice = invertPrice(price, true); // "2.0" (string)
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export declare function invertPrice(price: string | number | BigNumber, asFixed?: boolean): BigNumber | string;
|
|
122
|
+
/**
|
|
123
|
+
* Q96 constant for Uniswap V3 calculations (2^96)
|
|
124
|
+
*
|
|
125
|
+
* Consolidates: `new BigNumber(2).pow(96)`
|
|
126
|
+
* Used in tick-based liquidity calculations.
|
|
127
|
+
*
|
|
128
|
+
* @returns Q96 value as BigNumber
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const Q96 = getQ96Constant(); // 2^96
|
|
133
|
+
* const adjustedPrice = sqrtPrice.multipliedBy(sqrtPrice).dividedBy(Q96);
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
export declare function getQ96Constant(): BigNumber;
|
|
137
|
+
/**
|
|
138
|
+
* Find minimum of two BigNumber values
|
|
139
|
+
*
|
|
140
|
+
* Convenience wrapper for `BigNumber.min()` with safe input handling.
|
|
141
|
+
*
|
|
142
|
+
* @param a First value
|
|
143
|
+
* @param b Second value
|
|
144
|
+
* @returns The minimum value as BigNumber
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* const liquidity0 = calculateFromAmount0(...);
|
|
149
|
+
* const liquidity1 = calculateFromAmount1(...);
|
|
150
|
+
* const optimalLiquidity = minBigNumber(liquidity0, liquidity1);
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
export declare function minBigNumber(a: string | number | BigNumber, b: string | number | BigNumber): BigNumber;
|
|
154
|
+
/**
|
|
155
|
+
* Find maximum of two BigNumber values
|
|
156
|
+
*
|
|
157
|
+
* Convenience wrapper for `BigNumber.max()` with safe input handling.
|
|
158
|
+
*
|
|
159
|
+
* @param a First value
|
|
160
|
+
* @param b Second value
|
|
161
|
+
* @returns The maximum value as BigNumber
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* const amount0 = parseFloat(poolData.amount0);
|
|
166
|
+
* const amount1 = parseFloat(poolData.amount1);
|
|
167
|
+
* const maxAmount = maxBigNumber(amount0, amount1);
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
export declare function maxBigNumber(a: string | number | BigNumber, b: string | number | BigNumber): BigNumber;
|
|
171
|
+
/**
|
|
172
|
+
* Check if a value is zero
|
|
173
|
+
*
|
|
174
|
+
* Safe check for zero with BigNumber precision.
|
|
175
|
+
*
|
|
176
|
+
* @param value The value to check
|
|
177
|
+
* @returns true if value equals 0
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* if (isZero(amount)) {
|
|
182
|
+
* throw new Error('Amount cannot be zero');
|
|
183
|
+
* }
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
export declare function isZero(value: string | number | BigNumber): boolean;
|
|
187
|
+
/**
|
|
188
|
+
* Check if a value is positive
|
|
189
|
+
*
|
|
190
|
+
* @param value The value to check
|
|
191
|
+
* @returns true if value > 0
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```typescript
|
|
195
|
+
* if (isPositive(balance)) {
|
|
196
|
+
* // user has funds
|
|
197
|
+
* }
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
export declare function isPositive(value: string | number | BigNumber): boolean;
|
|
201
|
+
/**
|
|
202
|
+
* Check if a value is negative
|
|
203
|
+
*
|
|
204
|
+
* @param value The value to check
|
|
205
|
+
* @returns true if value < 0
|
|
206
|
+
*/
|
|
207
|
+
export declare function isNegative(value: string | number | BigNumber): boolean;
|
|
208
|
+
/**
|
|
209
|
+
* Check if value is between two bounds (inclusive)
|
|
210
|
+
*
|
|
211
|
+
* @param value The value to check
|
|
212
|
+
* @param min Lower bound (inclusive)
|
|
213
|
+
* @param max Upper bound (inclusive)
|
|
214
|
+
* @returns true if min <= value <= max
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```typescript
|
|
218
|
+
* if (isBetween(price, minPrice, maxPrice)) {
|
|
219
|
+
* // price is in valid range
|
|
220
|
+
* }
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
export declare function isBetween(value: string | number | BigNumber, min: string | number | BigNumber, max: string | number | BigNumber): boolean;
|
|
224
|
+
/**
|
|
225
|
+
* Calculate percentage of a value
|
|
226
|
+
*
|
|
227
|
+
* @param value The base value
|
|
228
|
+
* @param percentage The percentage to calculate (e.g., 10 for 10%)
|
|
229
|
+
* @returns The percentage amount
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```typescript
|
|
233
|
+
* const fee = calculatePercentage(amount, 0.3); // 0.3% fee
|
|
234
|
+
* const netAmount = amount.minus(fee);
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
export declare function calculatePercentage(value: string | number | BigNumber, percentage: number): BigNumber;
|
|
238
|
+
/**
|
|
239
|
+
* Increase a value by a percentage
|
|
240
|
+
*
|
|
241
|
+
* @param value The base value
|
|
242
|
+
* @param percentage The percentage to increase (e.g., 10 for 10% increase)
|
|
243
|
+
* @returns The increased value
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```typescript
|
|
247
|
+
* const withSlippage = increaseByPercentage(amount, 1); // 1% increase
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
export declare function increaseByPercentage(value: string | number | BigNumber, percentage: number): BigNumber;
|
|
251
|
+
/**
|
|
252
|
+
* Decrease a value by a percentage
|
|
253
|
+
*
|
|
254
|
+
* @param value The base value
|
|
255
|
+
* @param percentage The percentage to decrease (e.g., 1 for 1% decrease)
|
|
256
|
+
* @returns The decreased value
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* ```typescript
|
|
260
|
+
* const afterSlippage = decreaseByPercentage(amount, 1); // 1% decrease
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
export declare function decreaseByPercentage(value: string | number | BigNumber, percentage: number): BigNumber;
|
|
264
|
+
//# sourceMappingURL=bignumber-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bignumber-helpers.d.ts","sourceRoot":"","sources":["../../src/utils/bignumber-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS,EACrD,YAAY,GAAE,MAAM,GAAG,MAAY,GAClC,SAAS,CAKX;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS,EACrD,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM,CAER;AAED;;;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AAgB,SAAS,CACvB,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,EAClC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,EAChC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAC/B,OAAO,CAKT;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,EAClC,UAAU,EAAE,MAAM,GACjB,SAAS,CAEX;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,EAClC,UAAU,EAAE,MAAM,GACjB,SAAS,CAEX;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,EAClC,UAAU,EAAE,MAAM,GACjB,SAAS,CAEX"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* TokenFormatConverter -
|
|
2
|
+
* TokenFormatConverter - Unified token format conversion utilities
|
|
3
|
+
*
|
|
4
|
+
* Handles bidirectional conversions between:
|
|
5
|
+
* - Pipe-delimited ↔ Dollar-delimited formats (API conversions)
|
|
6
|
+
* - Token objects ↔ String formats (Launchpad ↔ GSwap conversions)
|
|
3
7
|
*
|
|
4
8
|
* ⚠️ CRITICAL ARCHITECTURAL NOTE:
|
|
5
9
|
* This utility is for FORMAT CONVERSION ONLY (pipe-delimited ↔ object/string).
|
|
@@ -12,10 +16,9 @@
|
|
|
12
16
|
*
|
|
13
17
|
* Launchpad SDK uses: { collection, category, type, additionalKey }
|
|
14
18
|
* GSwap SDK uses: "symbol|Unit|none|none" (pipe-delimited string)
|
|
15
|
-
*
|
|
16
|
-
* This utility handles bidirectional conversion between formats.
|
|
17
19
|
*/
|
|
18
20
|
import type { TokenClass } from '../types/gswap.dto';
|
|
21
|
+
import type { TokenClassKey } from '../types/common';
|
|
19
22
|
export declare class TokenFormatConverter {
|
|
20
23
|
/**
|
|
21
24
|
* Convert Launchpad token format to GSwap format (pipe-delimited string)
|
|
@@ -55,4 +58,73 @@ export declare class TokenFormatConverter {
|
|
|
55
58
|
*/
|
|
56
59
|
normalize(token: string | TokenClass): string;
|
|
57
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Convert pipe-delimited token ID to dollar-delimited format for API
|
|
63
|
+
*
|
|
64
|
+
* @param pipeToken Pipe-delimited format: "Token|Unit|GUSDC|eth:0x..."
|
|
65
|
+
* @returns Dollar-delimited format: "Token$Unit$GUSDC$eth:0x..."
|
|
66
|
+
* @throws Error if token is null or empty
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* pipeFormatToDollarFormat("Token|Unit|GUSDC|eth:0x123")
|
|
71
|
+
* // Returns: "Token$Unit$GUSDC$eth:0x123"
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare function pipeFormatToDollarFormat(pipeToken: string): string;
|
|
75
|
+
/**
|
|
76
|
+
* Convert dollar-delimited API response to pipe-delimited format
|
|
77
|
+
*
|
|
78
|
+
* @param dollarToken Dollar-delimited format: "Token$Unit$GUSDC$eth:0x..."
|
|
79
|
+
* @returns Pipe-delimited format: "Token|Unit|GUSDC|eth:0x..."
|
|
80
|
+
* @throws Error if token is null or empty
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* dollarFormatToPipeFormat("Token$Unit$GUSDC$eth:0x123")
|
|
85
|
+
* // Returns: "Token|Unit|GUSDC|eth:0x123"
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export declare function dollarFormatToPipeFormat(dollarToken: string): string;
|
|
89
|
+
/**
|
|
90
|
+
* Convert sort order from SDK format (uppercase) to API format (lowercase)
|
|
91
|
+
*
|
|
92
|
+
* @param sortOrder SDK sort order: 'ASC' | 'DESC'
|
|
93
|
+
* @returns API sort order: 'asc' | 'desc' | undefined
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* convertSortOrderToApi('ASC')
|
|
98
|
+
* // Returns: 'asc'
|
|
99
|
+
*
|
|
100
|
+
* convertSortOrderToApi(undefined)
|
|
101
|
+
* // Returns: undefined
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export declare function convertSortOrderToApi(sortOrder?: 'ASC' | 'DESC'): 'asc' | 'desc' | undefined;
|
|
105
|
+
/**
|
|
106
|
+
* Parse dollar-delimited token string into TokenClassKey components
|
|
107
|
+
*
|
|
108
|
+
* Dollar-delimited format: "Token$Unit$SYMBOL$additionalKey"
|
|
109
|
+
* Handles additionalKey that may contain $ characters by treating everything after the third $
|
|
110
|
+
* as part of additionalKey and rejoining with $.
|
|
111
|
+
* This consolidates 5+ identical dollar-delimited parsing patterns scattered across services.
|
|
112
|
+
*
|
|
113
|
+
* @param dollarToken Dollar-delimited token string to parse
|
|
114
|
+
* @returns TokenClassKey object with collection, category, type, additionalKey
|
|
115
|
+
* @throws ValidationError if the token format is invalid
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* const tokenClass = parseDollarDelimitedToken('Token$Unit$GUSDC$eth:0x...');
|
|
120
|
+
* // → { collection: "Token", category: "Unit", type: "GUSDC", additionalKey: "eth:0x..." }
|
|
121
|
+
*
|
|
122
|
+
* // Handles additionalKey with $ characters
|
|
123
|
+
* const complex = parseDollarDelimitedToken('Token$Unit$SYMBOL$eth:0x$1234$5678');
|
|
124
|
+
* // → { collection: "Token", category: "Unit", type: "SYMBOL", additionalKey: "eth:0x$1234$5678" }
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* @since 3.32.0
|
|
128
|
+
*/
|
|
129
|
+
export declare function parseDollarDelimitedToken(dollarToken: string): TokenClassKey;
|
|
58
130
|
//# sourceMappingURL=token-format-converter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token-format-converter.d.ts","sourceRoot":"","sources":["../../src/utils/token-format-converter.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"token-format-converter.d.ts","sourceRoot":"","sources":["../../src/utils/token-format-converter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGrD,qBAAa,oBAAoB;IAC/B;;;;;;;;OAQG;IACH,iBAAiB,CACf,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,GAAG,GAC/B,MAAM;IAuBT;;;;;;;;;OASG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,GAAG,GAAG,UAAU;IAmC1D;;;;OAIG;IACH,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIrC;;;;;;;;OAQG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM;CAY9C;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAMlE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAMpE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,SAAS,CAM5F;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,MAAM,GAAG,aAAa,CAyC5E"}
|
|
@@ -108,4 +108,70 @@ export declare function tokenClassKeyToString(tokenClass: TokenClassKey): string
|
|
|
108
108
|
* @throws ValidationError if validation fails
|
|
109
109
|
*/
|
|
110
110
|
export declare function validateTokenId(tokenId: TokenId): void;
|
|
111
|
+
/**
|
|
112
|
+
* Parses a vault address into a TokenClassKey
|
|
113
|
+
*
|
|
114
|
+
* Vault address format: "service|Token$Unit$SYMBOL$additionalKey$launchpad"
|
|
115
|
+
* This consolidates 5+ identical vault address parsing patterns scattered across services.
|
|
116
|
+
*
|
|
117
|
+
* Handles additionalKey that may contain $ characters by excluding the 'launchpad' suffix
|
|
118
|
+
* and joining all remaining parts.
|
|
119
|
+
*
|
|
120
|
+
* @param vaultAddress Vault address string to parse
|
|
121
|
+
* @returns TokenClassKey object
|
|
122
|
+
* @throws ValidationError if the vault address format is invalid
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* const tokenClass = parseVaultAddressToTokenClassKey(
|
|
127
|
+
* "service|Token$Unit$DRAGNRKTI$eth:0x...$launchpad"
|
|
128
|
+
* );
|
|
129
|
+
* // → { collection: "Token", category: "Unit", type: "DRAGNRKTI", additionalKey: "eth:0x..." }
|
|
130
|
+
* ```
|
|
131
|
+
*
|
|
132
|
+
* @since 3.32.0
|
|
133
|
+
*/
|
|
134
|
+
export declare function parseVaultAddressToTokenClassKey(vaultAddress: string): TokenClassKey;
|
|
135
|
+
/**
|
|
136
|
+
* Parses a vault address into a TokenInstanceKey
|
|
137
|
+
*
|
|
138
|
+
* Vault address format: "service|Token$Unit$SYMBOL$eth:address$launchpad"
|
|
139
|
+
* Instance is defaulted to "0" if not provided in the vault address.
|
|
140
|
+
*
|
|
141
|
+
* @param vaultAddress Vault address string to parse
|
|
142
|
+
* @returns TokenInstanceKey object with instance defaulted to "0"
|
|
143
|
+
* @throws ValidationError if the vault address format is invalid
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* const tokenInstance = parseVaultAddressToTokenInstance(
|
|
148
|
+
* "service|Token$Unit$DRAGNRKTI$eth:0x...$launchpad"
|
|
149
|
+
* );
|
|
150
|
+
* // → { collection: "Token", category: "Unit", type: "DRAGNRKTI", additionalKey: "eth:0x...", instance: "0" }
|
|
151
|
+
* ```
|
|
152
|
+
*
|
|
153
|
+
* @since 3.32.0
|
|
154
|
+
*/
|
|
155
|
+
export declare function parseVaultAddressToTokenInstance(vaultAddress: string): TokenInstanceKey;
|
|
156
|
+
/**
|
|
157
|
+
* Extracts the token symbol/type from a vault address
|
|
158
|
+
*
|
|
159
|
+
* Vault address format: "service|Token$Unit$SYMBOL$eth:address$launchpad"
|
|
160
|
+
* The symbol is the 3rd component (index 2) after splitting the token part by $.
|
|
161
|
+
*
|
|
162
|
+
* @param vaultAddress Vault address string to parse
|
|
163
|
+
* @returns Token symbol/type (e.g., "DRAGNRKTI", "GALA", "GUSDC")
|
|
164
|
+
* @throws ValidationError if the vault address format is invalid
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* const symbol = extractTokenSymbolFromVault(
|
|
169
|
+
* "service|Token$Unit$DRAGNRKTI$eth:0x...$launchpad"
|
|
170
|
+
* );
|
|
171
|
+
* // → "DRAGNRKTI"
|
|
172
|
+
* ```
|
|
173
|
+
*
|
|
174
|
+
* @since 3.32.0
|
|
175
|
+
*/
|
|
176
|
+
export declare function extractTokenSymbolFromVault(vaultAddress: string): string;
|
|
111
177
|
//# sourceMappingURL=tokenNormalizer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokenNormalizer.d.ts","sourceRoot":"","sources":["../../src/utils/tokenNormalizer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAG3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,OAAO,GAAG,gBAAgB,CA2D9E;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,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AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,aAAa,GAAG,MAAM,CAEvE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CActD;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,gCAAgC,CAAC,YAAY,EAAE,MAAM,GAAG,aAAa,CAyCpF;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,gCAAgC,CAAC,YAAY,EAAE,MAAM,GAAG,gBAAgB,CAMvF;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,2BAA2B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAGxE"}
|
|
@@ -366,4 +366,79 @@ export type TypeGuard<T> = (value: unknown) => value is T;
|
|
|
366
366
|
* ```
|
|
367
367
|
*/
|
|
368
368
|
export declare function createValidator<T>(typeGuard: TypeGuard<T>, dataTypeName: string, fieldName?: string, errorCode?: string): (value: unknown) => asserts value is T;
|
|
369
|
+
/**
|
|
370
|
+
* Result of mutual exclusivity validation
|
|
371
|
+
*/
|
|
372
|
+
export interface MutualExclusivityResult {
|
|
373
|
+
/** Which field was provided (if valid) */
|
|
374
|
+
chosen: string;
|
|
375
|
+
/** Whether fieldA was provided */
|
|
376
|
+
hasA: boolean;
|
|
377
|
+
/** Whether fieldB was provided */
|
|
378
|
+
hasB: boolean;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Validates that exactly one of two parameters is provided (mutual exclusivity)
|
|
382
|
+
*
|
|
383
|
+
* Consolidates 12+ instances of identical validation logic found across services:
|
|
384
|
+
* - PriceHistoryService: tokenName XOR tokenId (lines 451-470)
|
|
385
|
+
* - DexService: Similar patterns with token identification
|
|
386
|
+
* - Other services: Scattered mutual exclusivity validation
|
|
387
|
+
*
|
|
388
|
+
* ## Use Cases
|
|
389
|
+
*
|
|
390
|
+
* ### Validate Token Identification (Highest Priority)
|
|
391
|
+
* ```typescript
|
|
392
|
+
* // In service methods receiving either tokenName or tokenId (but not both)
|
|
393
|
+
* const { chosen, hasA } = validateMutualExclusive(
|
|
394
|
+
* options,
|
|
395
|
+
* 'tokenName',
|
|
396
|
+
* 'tokenId',
|
|
397
|
+
* { description: 'token identifier' }
|
|
398
|
+
* );
|
|
399
|
+
*
|
|
400
|
+
* if (hasA) {
|
|
401
|
+
* // Use tokenName
|
|
402
|
+
* const resolved = await this.tokenResolver.resolve(options.tokenName!);
|
|
403
|
+
* } else {
|
|
404
|
+
* // Use tokenId
|
|
405
|
+
* const formatted = this.converter.toTokenClassKey(options.tokenId!);
|
|
406
|
+
* }
|
|
407
|
+
* ```
|
|
408
|
+
*
|
|
409
|
+
* ### Generic Parameter Validation
|
|
410
|
+
* ```typescript
|
|
411
|
+
* // Validate address or transaction ID (mutually exclusive)
|
|
412
|
+
* const { chosen } = validateMutualExclusive(
|
|
413
|
+
* params,
|
|
414
|
+
* 'walletAddress',
|
|
415
|
+
* 'transactionId',
|
|
416
|
+
* { description: 'transaction reference' }
|
|
417
|
+
* );
|
|
418
|
+
* ```
|
|
419
|
+
*
|
|
420
|
+
* @param obj The object containing the fields to validate
|
|
421
|
+
* @param fieldA First field name (mutual exclusive with fieldB)
|
|
422
|
+
* @param fieldB Second field name (mutual exclusive with fieldA)
|
|
423
|
+
* @param options Validation options
|
|
424
|
+
* @returns Result object with chosen field and validation flags
|
|
425
|
+
*
|
|
426
|
+
* @throws {ConfigurationError} If neither field is provided or both are provided
|
|
427
|
+
*
|
|
428
|
+
* @example Token identifier validation
|
|
429
|
+
* ```typescript
|
|
430
|
+
* // PriceHistoryService.fetchAllPriceHistory() - replaces 20-line validation method
|
|
431
|
+
* const { hasA } = validateMutualExclusive(options, 'tokenName', 'tokenId', {
|
|
432
|
+
* description: 'token identifier'
|
|
433
|
+
* });
|
|
434
|
+
* ```
|
|
435
|
+
*
|
|
436
|
+
* @since 3.32.0
|
|
437
|
+
*/
|
|
438
|
+
export declare function validateMutualExclusive(obj: Record<string, any>, fieldA: string, fieldB: string, options?: {
|
|
439
|
+
/** Human-readable description for error messages (e.g., "token identifier") */
|
|
440
|
+
description?: string;
|
|
441
|
+
/** Whether empty strings should count as "not provided" (default: true) */
|
|
442
|
+
treatEmptyAsNull?: boolean;
|
|
443
|
+
}): MutualExclusivityResult;
|
|
369
444
|
//# sourceMappingURL=validation-helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation-helpers.d.ts","sourceRoot":"","sources":["../../src/utils/validation-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"validation-helpers.d.ts","sourceRoot":"","sources":["../../src/utils/validation-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE;QACV,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0FG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,qBAAqB,GACjC,IAAI,CAoBN;AAED;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB;IAC3B,wEAAwE;;IAExE,yEAAyE;;CAEjE,CAAC;AAEX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAEhE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAgB,c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