@ledgerhq/coin-module-framework 4.0.1 → 4.3.0
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 +28 -0
- package/lib/api/getBalance/rejectBalanceOptions.d.ts +1 -1
- package/lib/api/getBalance/rejectBalanceOptions.d.ts.map +1 -1
- package/lib/api/getBalance/rejectBalanceOptions.js +1 -1
- package/lib/api/getBalance/rejectBalanceOptions.js.map +1 -1
- package/lib/api/types.d.ts +49 -6
- package/lib/api/types.d.ts.map +1 -1
- package/lib/errors.d.ts +60 -4
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +112 -4
- package/lib/errors.js.map +1 -1
- package/lib/logic/craftTransactionData.d.ts +1 -1
- package/lib/logic/craftTransactionData.d.ts.map +1 -1
- package/lib/test/utils.d.ts +48 -9
- package/lib/test/utils.d.ts.map +1 -1
- package/lib/utils.d.ts +1 -1
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js.map +1 -1
- package/lib-es/api/getBalance/rejectBalanceOptions.d.ts +1 -1
- package/lib-es/api/getBalance/rejectBalanceOptions.d.ts.map +1 -1
- package/lib-es/api/getBalance/rejectBalanceOptions.js +1 -1
- package/lib-es/api/getBalance/rejectBalanceOptions.js.map +1 -1
- package/lib-es/api/types.d.ts +49 -6
- package/lib-es/api/types.d.ts.map +1 -1
- package/lib-es/errors.d.ts +60 -4
- package/lib-es/errors.d.ts.map +1 -1
- package/lib-es/errors.js +96 -3
- package/lib-es/errors.js.map +1 -1
- package/lib-es/logic/craftTransactionData.d.ts +1 -1
- package/lib-es/logic/craftTransactionData.d.ts.map +1 -1
- package/lib-es/test/utils.d.ts +48 -9
- package/lib-es/test/utils.d.ts.map +1 -1
- package/lib-es/utils.d.ts +1 -1
- package/lib-es/utils.d.ts.map +1 -1
- package/lib-es/utils.js.map +1 -1
- package/package.json +7 -2
- package/src/api/getBalance/rejectBalanceOptions.test.ts +1 -1
- package/src/api/getBalance/rejectBalanceOptions.ts +2 -2
- package/src/api/types.ts +55 -7
- package/src/errors.ts +106 -3
- package/src/logic/craftTransactionData.ts +1 -1
- package/src/test/utils.ts +54 -11
- package/src/utils.ts +1 -1
package/src/test/utils.ts
CHANGED
|
@@ -15,15 +15,58 @@ export type DeepPartial<T> = T extends (infer U)[]
|
|
|
15
15
|
: T
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* Re-types a function so its return value is
|
|
19
|
-
* while keeping the
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
18
|
+
* Re-types a function so its return value is `DeepPartial<ReturnType<F>>` (sync)
|
|
19
|
+
* or `Promise<DeepPartial<Awaited<ReturnType<F>>>>` (async), while keeping the
|
|
20
|
+
* original parameter types intact.
|
|
21
|
+
*
|
|
22
|
+
* Use with `jest.mocked<DeepPartialReturn<F>>(spy)` to let `mockReturnValue` /
|
|
23
|
+
* `mockResolvedValue` accept partial stubs - no cast, no `any` at call sites.
|
|
24
|
+
*
|
|
25
|
+
* Works for both synchronous and asynchronous functions.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* // Async: network module function mocked via jest.mock
|
|
29
|
+
* import { broadcastTransaction } from './network'
|
|
30
|
+
* jest.mock('./network', () => ({ broadcastTransaction: jest.fn() }))
|
|
31
|
+
*
|
|
32
|
+
* jest
|
|
33
|
+
* .mocked<DeepPartialReturn<typeof broadcastTransaction>>(broadcastTransaction)
|
|
34
|
+
* .mockResolvedValue({ hash: 'abc123' }) // ✓ partial BroadcastResult accepted
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* // Sync: SDK client prototype method returning a fluent builder
|
|
38
|
+
* // spyOn installs the spy; mocked re-types it - they cannot be combined
|
|
39
|
+
* import { SdkClient } from './sdk'
|
|
40
|
+
*
|
|
41
|
+
* jest.spyOn(SdkClient.prototype, 'transactions')
|
|
42
|
+
* const spy = jest.mocked<DeepPartialReturn<typeof SdkClient.prototype.transactions>>(
|
|
43
|
+
* SdkClient.prototype.transactions
|
|
44
|
+
* )
|
|
45
|
+
* spy.mockReturnValue({ forAccount: jest.fn().mockReturnThis(), call: jest.fn() }) // ✓
|
|
46
|
+
*/
|
|
47
|
+
export type DeepPartialReturn<F extends (...args: never[]) => unknown> =
|
|
48
|
+
ReturnType<F> extends Promise<infer R>
|
|
49
|
+
? (...args: Parameters<F>) => Promise<DeepPartial<R>>
|
|
50
|
+
: (...args: Parameters<F>) => DeepPartial<ReturnType<F>>
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Re-types a class constructor so that `mockImplementation` accepts a factory
|
|
54
|
+
* returning a partial instance - `DeepPartial<InstanceType<C>>` instead of the
|
|
55
|
+
* full class - while keeping the original constructor parameter types.
|
|
56
|
+
*
|
|
57
|
+
* Use with `jest.mocked<DeepPartialCtor<typeof MyClass>>(MyClass)` after
|
|
58
|
+
* `jest.mock('./sdk')`.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* import { SdkClient } from './sdk'
|
|
62
|
+
* jest.mock('./sdk')
|
|
63
|
+
*
|
|
64
|
+
* jest.mocked<DeepPartialCtor<typeof SdkClient>>(SdkClient)
|
|
65
|
+
* .mockImplementation(() => ({
|
|
66
|
+
* getBalance: jest.fn(),
|
|
67
|
+
* getTransactions: jest.fn(),
|
|
68
|
+
* })) // ✓ partial SdkClient instance accepted
|
|
26
69
|
*/
|
|
27
|
-
export type
|
|
28
|
-
...args:
|
|
29
|
-
) =>
|
|
70
|
+
export type DeepPartialCtor<C extends new (...args: never[]) => unknown> = new (
|
|
71
|
+
...args: ConstructorParameters<C>
|
|
72
|
+
) => DeepPartial<InstanceType<C>>
|
package/src/utils.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2024 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import type { SendTransactionIntent, StakingTransactionIntent, TransactionIntent } from './api'
|
|
4
5
|
import BigNumber from 'bignumber.js'
|
|
5
|
-
import { SendTransactionIntent, StakingTransactionIntent, TransactionIntent } from './api'
|
|
6
6
|
|
|
7
7
|
export function fromBigNumberToBigInt(bigNumber: BigNumber | undefined): bigint | undefined
|
|
8
8
|
export function fromBigNumberToBigInt(
|