@ledgerhq/coin-module-framework 4.0.1 → 4.0.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ledgerhq/coin-module-framework
2
2
 
3
+ ## 4.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#748](https://github.com/LedgerHQ/coin-modules/pull/748) [`fd7b76b`](https://github.com/LedgerHQ/coin-modules/commit/fd7b76bded8d5519b723c53989ecf29714cbfc39) Thanks [@francois-guerin-ledger](https://github.com/francois-guerin-ledger)! - chore: remove casts from `coin-stellar` tests
8
+
3
9
  ## 4.0.1
4
10
 
5
11
  ### Patch Changes
@@ -7,14 +7,53 @@ export type DeepPartial<T> = T extends (infer U)[] ? DeepPartial<U>[] : T extend
7
7
  [K in keyof T]?: DeepPartial<T[K]>;
8
8
  } : T;
9
9
  /**
10
- * Re-types a function so its return value is wrapped in `Promise<DeepPartial<…>>`,
11
- * while keeping the original parameter types intact.
12
- *
13
- * Useful for typing Jest mock functions that return partial RPC/API data:
14
- * ```ts
15
- * const mock = jest.fn() as jest.MockedFunction<DeepPartialReturn<SomeApi["method"]>>;
16
- * mock.mockResolvedValue({ onlyTheFieldsWeNeed: true });
17
- * ```
10
+ * Re-types a function so its return value is `DeepPartial<ReturnType<F>>` (sync)
11
+ * or `Promise<DeepPartial<Awaited<ReturnType<F>>>>` (async), while keeping the
12
+ * original parameter types intact.
13
+ *
14
+ * Use with `jest.mocked<DeepPartialReturn<F>>(spy)` to let `mockReturnValue` /
15
+ * `mockResolvedValue` accept partial stubs - no cast, no `any` at call sites.
16
+ *
17
+ * Works for both synchronous and asynchronous functions.
18
+ *
19
+ * @example
20
+ * // Async: network module function mocked via jest.mock
21
+ * import { broadcastTransaction } from './network'
22
+ * jest.mock('./network', () => ({ broadcastTransaction: jest.fn() }))
23
+ *
24
+ * jest
25
+ * .mocked<DeepPartialReturn<typeof broadcastTransaction>>(broadcastTransaction)
26
+ * .mockResolvedValue({ hash: 'abc123' }) // ✓ partial BroadcastResult accepted
27
+ *
28
+ * @example
29
+ * // Sync: SDK client prototype method returning a fluent builder
30
+ * // spyOn installs the spy; mocked re-types it - they cannot be combined
31
+ * import { SdkClient } from './sdk'
32
+ *
33
+ * jest.spyOn(SdkClient.prototype, 'transactions')
34
+ * const spy = jest.mocked<DeepPartialReturn<typeof SdkClient.prototype.transactions>>(
35
+ * SdkClient.prototype.transactions
36
+ * )
37
+ * spy.mockReturnValue({ forAccount: jest.fn().mockReturnThis(), call: jest.fn() }) // ✓
38
+ */
39
+ export type DeepPartialReturn<F extends (...args: never[]) => unknown> = ReturnType<F> extends Promise<infer R> ? (...args: Parameters<F>) => Promise<DeepPartial<R>> : (...args: Parameters<F>) => DeepPartial<ReturnType<F>>;
40
+ /**
41
+ * Re-types a class constructor so that `mockImplementation` accepts a factory
42
+ * returning a partial instance - `DeepPartial<InstanceType<C>>` instead of the
43
+ * full class - while keeping the original constructor parameter types.
44
+ *
45
+ * Use with `jest.mocked<DeepPartialCtor<typeof MyClass>>(MyClass)` after
46
+ * `jest.mock('./sdk')`.
47
+ *
48
+ * @example
49
+ * import { SdkClient } from './sdk'
50
+ * jest.mock('./sdk')
51
+ *
52
+ * jest.mocked<DeepPartialCtor<typeof SdkClient>>(SdkClient)
53
+ * .mockImplementation(() => ({
54
+ * getBalance: jest.fn(),
55
+ * getTransactions: jest.fn(),
56
+ * })) // ✓ partial SdkClient instance accepted
18
57
  */
19
- export type DeepPartialReturn<F extends (...args: never[]) => unknown> = (...args: Parameters<F>) => Promise<DeepPartial<Awaited<ReturnType<F>>>>;
58
+ export type DeepPartialCtor<C extends new (...args: never[]) => unknown> = new (...args: ConstructorParameters<C>) => DeepPartial<InstanceType<C>>;
20
59
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/test/utils.ts"],"names":[],"mappings":"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CAAC,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GACnD,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;AAE5D;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,KAAK,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,IAAI,KACzE,GAAG,IAAI,EAAE,qBAAqB,CAAC,CAAC,CAAC,KAC9B,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA"}
@@ -7,14 +7,53 @@ export type DeepPartial<T> = T extends (infer U)[] ? DeepPartial<U>[] : T extend
7
7
  [K in keyof T]?: DeepPartial<T[K]>;
8
8
  } : T;
9
9
  /**
10
- * Re-types a function so its return value is wrapped in `Promise<DeepPartial<…>>`,
11
- * while keeping the original parameter types intact.
12
- *
13
- * Useful for typing Jest mock functions that return partial RPC/API data:
14
- * ```ts
15
- * const mock = jest.fn() as jest.MockedFunction<DeepPartialReturn<SomeApi["method"]>>;
16
- * mock.mockResolvedValue({ onlyTheFieldsWeNeed: true });
17
- * ```
10
+ * Re-types a function so its return value is `DeepPartial<ReturnType<F>>` (sync)
11
+ * or `Promise<DeepPartial<Awaited<ReturnType<F>>>>` (async), while keeping the
12
+ * original parameter types intact.
13
+ *
14
+ * Use with `jest.mocked<DeepPartialReturn<F>>(spy)` to let `mockReturnValue` /
15
+ * `mockResolvedValue` accept partial stubs - no cast, no `any` at call sites.
16
+ *
17
+ * Works for both synchronous and asynchronous functions.
18
+ *
19
+ * @example
20
+ * // Async: network module function mocked via jest.mock
21
+ * import { broadcastTransaction } from './network'
22
+ * jest.mock('./network', () => ({ broadcastTransaction: jest.fn() }))
23
+ *
24
+ * jest
25
+ * .mocked<DeepPartialReturn<typeof broadcastTransaction>>(broadcastTransaction)
26
+ * .mockResolvedValue({ hash: 'abc123' }) // ✓ partial BroadcastResult accepted
27
+ *
28
+ * @example
29
+ * // Sync: SDK client prototype method returning a fluent builder
30
+ * // spyOn installs the spy; mocked re-types it - they cannot be combined
31
+ * import { SdkClient } from './sdk'
32
+ *
33
+ * jest.spyOn(SdkClient.prototype, 'transactions')
34
+ * const spy = jest.mocked<DeepPartialReturn<typeof SdkClient.prototype.transactions>>(
35
+ * SdkClient.prototype.transactions
36
+ * )
37
+ * spy.mockReturnValue({ forAccount: jest.fn().mockReturnThis(), call: jest.fn() }) // ✓
38
+ */
39
+ export type DeepPartialReturn<F extends (...args: never[]) => unknown> = ReturnType<F> extends Promise<infer R> ? (...args: Parameters<F>) => Promise<DeepPartial<R>> : (...args: Parameters<F>) => DeepPartial<ReturnType<F>>;
40
+ /**
41
+ * Re-types a class constructor so that `mockImplementation` accepts a factory
42
+ * returning a partial instance - `DeepPartial<InstanceType<C>>` instead of the
43
+ * full class - while keeping the original constructor parameter types.
44
+ *
45
+ * Use with `jest.mocked<DeepPartialCtor<typeof MyClass>>(MyClass)` after
46
+ * `jest.mock('./sdk')`.
47
+ *
48
+ * @example
49
+ * import { SdkClient } from './sdk'
50
+ * jest.mock('./sdk')
51
+ *
52
+ * jest.mocked<DeepPartialCtor<typeof SdkClient>>(SdkClient)
53
+ * .mockImplementation(() => ({
54
+ * getBalance: jest.fn(),
55
+ * getTransactions: jest.fn(),
56
+ * })) // ✓ partial SdkClient instance accepted
18
57
  */
19
- export type DeepPartialReturn<F extends (...args: never[]) => unknown> = (...args: Parameters<F>) => Promise<DeepPartial<Awaited<ReturnType<F>>>>;
58
+ export type DeepPartialCtor<C extends new (...args: never[]) => unknown> = new (...args: ConstructorParameters<C>) => DeepPartial<InstanceType<C>>;
20
59
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/test/utils.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CA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,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;AAE5D;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,KAAK,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,IAAI,KACzE,GAAG,IAAI,EAAE,qBAAqB,CAAC,CAAC,CAAC,KAC9B,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/coin-module-framework",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
4
4
  "description": "Ledger framework for Coin integration",
5
5
  "keywords": [
6
6
  "Ledger",
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 wrapped in `Promise<DeepPartial<…>>`,
19
- * while keeping the original parameter types intact.
20
- *
21
- * Useful for typing Jest mock functions that return partial RPC/API data:
22
- * ```ts
23
- * const mock = jest.fn() as jest.MockedFunction<DeepPartialReturn<SomeApi["method"]>>;
24
- * mock.mockResolvedValue({ onlyTheFieldsWeNeed: true });
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 DeepPartialReturn<F extends (...args: never[]) => unknown> = (
28
- ...args: Parameters<F>
29
- ) => Promise<DeepPartial<Awaited<ReturnType<F>>>>
70
+ export type DeepPartialCtor<C extends new (...args: never[]) => unknown> = new (
71
+ ...args: ConstructorParameters<C>
72
+ ) => DeepPartial<InstanceType<C>>