@ethersphere/bee-js 13.0.0-upcoming.gcfb9756 → 13.0.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.
Files changed (201) hide show
  1. package/README.md +104 -103
  2. package/dist/cjs/api/bytes.js +3 -4
  3. package/dist/cjs/api/bzz.js +5 -6
  4. package/dist/cjs/api/chunk.js +3 -3
  5. package/dist/cjs/api/envelope.js +3 -2
  6. package/dist/cjs/api/feed.js +4 -5
  7. package/dist/cjs/api/pin.js +2 -2
  8. package/dist/cjs/api/soc.js +2 -2
  9. package/dist/cjs/bee.js +18 -19
  10. package/dist/cjs/chunk/soc.js +21 -63
  11. package/dist/cjs/feed/identifier.js +3 -4
  12. package/dist/cjs/feed/index.js +17 -19
  13. package/dist/cjs/feed/retrievable.js +2 -2
  14. package/dist/cjs/index.js +18 -8
  15. package/dist/cjs/manifest/manifest.js +97 -333
  16. package/dist/cjs/modules/balance.js +3 -3
  17. package/dist/cjs/modules/cheque.js +4 -4
  18. package/dist/cjs/modules/chunk.js +8 -8
  19. package/dist/cjs/modules/collection.js +6 -6
  20. package/dist/cjs/modules/connectivity.js +3 -3
  21. package/dist/cjs/modules/data.js +6 -6
  22. package/dist/cjs/modules/feed.js +10 -10
  23. package/dist/cjs/modules/file.js +3 -3
  24. package/dist/cjs/modules/grantee.js +9 -9
  25. package/dist/cjs/modules/messaging.js +15 -17
  26. package/dist/cjs/modules/pin.js +6 -6
  27. package/dist/cjs/modules/settlement.js +2 -2
  28. package/dist/cjs/modules/soc.js +3 -3
  29. package/dist/cjs/modules/stamp.js +7 -7
  30. package/dist/cjs/modules/tag.js +2 -2
  31. package/dist/cjs/modules/transaction.js +4 -4
  32. package/dist/cjs/modules/wallet.js +3 -3
  33. package/dist/cjs/types/schema/chequebook.js +5 -5
  34. package/dist/cjs/types/schema/connectivity.js +5 -5
  35. package/dist/cjs/types/schema/envelope.js +5 -5
  36. package/dist/cjs/types/schema/grantee.js +4 -4
  37. package/dist/cjs/types/schema/stake.js +2 -2
  38. package/dist/cjs/types/schema/stamps.js +4 -4
  39. package/dist/cjs/types/schema/states.js +2 -2
  40. package/dist/cjs/types/schema/transactions.js +3 -3
  41. package/dist/cjs/types/schema/upload.js +2 -2
  42. package/dist/cjs/utils/chunk-stream.browser.js +24 -16
  43. package/dist/cjs/utils/chunk-stream.js +17 -9
  44. package/dist/cjs/utils/constants.js +3 -3
  45. package/dist/cjs/utils/expose.js +4 -4
  46. package/dist/cjs/utils/headers.js +4 -4
  47. package/dist/cjs/utils/http.js +3 -1
  48. package/dist/cjs/utils/pss.js +2 -2
  49. package/dist/cjs/utils/resource-locator.js +2 -2
  50. package/dist/cjs/utils/schema.js +4 -4
  51. package/dist/cjs/utils/stamps.js +15 -130
  52. package/dist/cjs/utils/type.js +2 -2
  53. package/dist/codemod/index.js +141 -0
  54. package/dist/codemod/transforms/v13.js +524 -0
  55. package/dist/index.browser.min.js +2 -1
  56. package/dist/index.browser.min.js.LICENSE.txt +3 -0
  57. package/dist/index.browser.min.js.map +1 -1
  58. package/dist/mjs/api/bytes.js +1 -2
  59. package/dist/mjs/api/bzz.js +1 -2
  60. package/dist/mjs/api/chunk.js +1 -1
  61. package/dist/mjs/api/envelope.js +3 -2
  62. package/dist/mjs/api/feed.js +1 -2
  63. package/dist/mjs/api/pin.js +1 -1
  64. package/dist/mjs/api/soc.js +1 -1
  65. package/dist/mjs/bee.js +13 -14
  66. package/dist/mjs/chunk/soc.js +11 -49
  67. package/dist/mjs/feed/identifier.js +2 -3
  68. package/dist/mjs/feed/index.js +6 -8
  69. package/dist/mjs/feed/retrievable.js +1 -1
  70. package/dist/mjs/index.js +2 -5
  71. package/dist/mjs/manifest/manifest.js +95 -339
  72. package/dist/mjs/modules/balance.js +1 -1
  73. package/dist/mjs/modules/cheque.js +1 -1
  74. package/dist/mjs/modules/chunk.js +1 -1
  75. package/dist/mjs/modules/collection.js +1 -1
  76. package/dist/mjs/modules/connectivity.js +1 -1
  77. package/dist/mjs/modules/data.js +3 -3
  78. package/dist/mjs/modules/feed.js +1 -1
  79. package/dist/mjs/modules/file.js +1 -1
  80. package/dist/mjs/modules/grantee.js +1 -1
  81. package/dist/mjs/modules/messaging.js +3 -5
  82. package/dist/mjs/modules/pin.js +1 -1
  83. package/dist/mjs/modules/settlement.js +1 -1
  84. package/dist/mjs/modules/soc.js +1 -1
  85. package/dist/mjs/modules/stamp.js +1 -1
  86. package/dist/mjs/modules/tag.js +1 -1
  87. package/dist/mjs/modules/transaction.js +1 -1
  88. package/dist/mjs/modules/wallet.js +1 -1
  89. package/dist/mjs/types/schema/chequebook.js +1 -1
  90. package/dist/mjs/types/schema/connectivity.js +1 -1
  91. package/dist/mjs/types/schema/envelope.js +5 -5
  92. package/dist/mjs/types/schema/grantee.js +1 -1
  93. package/dist/mjs/types/schema/stake.js +1 -1
  94. package/dist/mjs/types/schema/stamps.js +1 -1
  95. package/dist/mjs/types/schema/states.js +1 -1
  96. package/dist/mjs/types/schema/transactions.js +1 -1
  97. package/dist/mjs/types/schema/upload.js +1 -1
  98. package/dist/mjs/utils/chunk-stream.browser.js +28 -18
  99. package/dist/mjs/utils/chunk-stream.js +21 -11
  100. package/dist/mjs/utils/constants.js +1 -1
  101. package/dist/mjs/utils/expose.js +1 -1
  102. package/dist/mjs/utils/headers.js +1 -1
  103. package/dist/mjs/utils/http.js +6 -1
  104. package/dist/mjs/utils/pss.js +1 -1
  105. package/dist/mjs/utils/resource-locator.js +1 -1
  106. package/dist/mjs/utils/schema.js +1 -1
  107. package/dist/mjs/utils/stamps.js +5 -99
  108. package/dist/mjs/utils/type.js +2 -2
  109. package/dist/types/api/balance.d.ts +1 -1
  110. package/dist/types/api/batches.d.ts +1 -1
  111. package/dist/types/api/bytes.d.ts +3 -3
  112. package/dist/types/api/bzz.d.ts +1 -2
  113. package/dist/types/api/chequebook.d.ts +1 -1
  114. package/dist/types/api/chunk.d.ts +1 -1
  115. package/dist/types/api/connectivity.d.ts +1 -1
  116. package/dist/types/api/consumed.d.ts +1 -1
  117. package/dist/types/api/envelope.d.ts +1 -1
  118. package/dist/types/api/feed.d.ts +1 -2
  119. package/dist/types/api/grantee.d.ts +1 -1
  120. package/dist/types/api/pin.d.ts +1 -1
  121. package/dist/types/api/pss.d.ts +1 -1
  122. package/dist/types/api/settlement.d.ts +1 -1
  123. package/dist/types/api/soc.d.ts +1 -1
  124. package/dist/types/api/stake.d.ts +1 -1
  125. package/dist/types/api/stamp.d.ts +1 -1
  126. package/dist/types/api/stewardship.d.ts +1 -1
  127. package/dist/types/api/tag.d.ts +1 -1
  128. package/dist/types/api/transaction.d.ts +1 -1
  129. package/dist/types/api/wallet.d.ts +1 -1
  130. package/dist/types/bee.d.ts +11 -13
  131. package/dist/types/chunk/soc.d.ts +3 -48
  132. package/dist/types/feed/identifier.d.ts +1 -1
  133. package/dist/types/feed/index.d.ts +1 -3
  134. package/dist/types/feed/retrievable.d.ts +1 -1
  135. package/dist/types/index.d.ts +17 -20
  136. package/dist/types/manifest/manifest.d.ts +24 -33
  137. package/dist/types/modules/balance.d.ts +1 -1
  138. package/dist/types/modules/cheque.d.ts +1 -1
  139. package/dist/types/modules/chequebook.d.ts +1 -1
  140. package/dist/types/modules/chunk.d.ts +1 -2
  141. package/dist/types/modules/collection.d.ts +2 -2
  142. package/dist/types/modules/connectivity.d.ts +1 -1
  143. package/dist/types/modules/context.d.ts +1 -1
  144. package/dist/types/modules/data.d.ts +3 -3
  145. package/dist/types/modules/feed.d.ts +1 -1
  146. package/dist/types/modules/file.d.ts +1 -2
  147. package/dist/types/modules/grantee.d.ts +1 -1
  148. package/dist/types/modules/messaging.d.ts +1 -2
  149. package/dist/types/modules/pin.d.ts +1 -1
  150. package/dist/types/modules/settlement.d.ts +1 -1
  151. package/dist/types/modules/soc.d.ts +1 -1
  152. package/dist/types/modules/stake.d.ts +1 -1
  153. package/dist/types/modules/stamp.d.ts +1 -1
  154. package/dist/types/modules/storage.d.ts +1 -1
  155. package/dist/types/modules/tag.d.ts +1 -1
  156. package/dist/types/modules/transaction.d.ts +1 -1
  157. package/dist/types/modules/wallet.d.ts +1 -1
  158. package/dist/types/types/debug.d.ts +1 -1
  159. package/dist/types/types/index.d.ts +2 -11
  160. package/dist/types/types/schema/chequebook.d.ts +1 -1
  161. package/dist/types/types/schema/connectivity.d.ts +1 -1
  162. package/dist/types/types/schema/grantee.d.ts +1 -1
  163. package/dist/types/types/schema/stake.d.ts +1 -1
  164. package/dist/types/types/schema/stamps.d.ts +1 -1
  165. package/dist/types/types/schema/states.d.ts +1 -1
  166. package/dist/types/types/schema/transactions.d.ts +1 -1
  167. package/dist/types/types/schema/upload.d.ts +1 -1
  168. package/dist/types/utils/chunk-stream.browser.d.ts +1 -1
  169. package/dist/types/utils/chunk-stream.d.ts +2 -2
  170. package/dist/types/utils/constants.d.ts +1 -1
  171. package/dist/types/utils/expose.d.ts +1 -1
  172. package/dist/types/utils/headers.d.ts +1 -1
  173. package/dist/types/utils/pss.d.ts +1 -1
  174. package/dist/types/utils/resource-locator.d.ts +1 -1
  175. package/dist/types/utils/schema.d.ts +1 -1
  176. package/dist/types/utils/stamps.d.ts +2 -27
  177. package/dist/types/utils/tar-uploader.browser.d.ts +1 -1
  178. package/dist/types/utils/tar-uploader.d.ts +1 -1
  179. package/dist/types/utils/type.d.ts +1 -1
  180. package/package.json +7 -2
  181. package/dist/cjs/chunk/bmt.js +0 -37
  182. package/dist/cjs/chunk/cac.js +0 -43
  183. package/dist/cjs/stamper/stamper.js +0 -44
  184. package/dist/cjs/utils/bytes.js +0 -116
  185. package/dist/cjs/utils/cid.js +0 -37
  186. package/dist/cjs/utils/redundancy.js +0 -133
  187. package/dist/cjs/utils/typed-bytes.js +0 -186
  188. package/dist/mjs/chunk/bmt.js +0 -34
  189. package/dist/mjs/chunk/cac.js +0 -34
  190. package/dist/mjs/stamper/stamper.js +0 -40
  191. package/dist/mjs/utils/bytes.js +0 -102
  192. package/dist/mjs/utils/cid.js +0 -32
  193. package/dist/mjs/utils/redundancy.js +0 -98
  194. package/dist/mjs/utils/typed-bytes.js +0 -167
  195. package/dist/types/chunk/bmt.d.ts +0 -16
  196. package/dist/types/chunk/cac.d.ts +0 -40
  197. package/dist/types/stamper/stamper.d.ts +0 -15
  198. package/dist/types/utils/bytes.d.ts +0 -19
  199. package/dist/types/utils/cid.d.ts +0 -10
  200. package/dist/types/utils/redundancy.d.ts +0 -21
  201. package/dist/types/utils/typed-bytes.d.ts +0 -69
@@ -0,0 +1,524 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.transform = transform;
37
+ const ts = __importStar(require("typescript"));
38
+ const METHOD_MAP = {
39
+ // bee.balance
40
+ getAllBalances: { namespace: 'balance', newName: 'getAll' },
41
+ getPeerBalance: { namespace: 'balance', newName: 'getPeer' },
42
+ getPastDueConsumptionBalances: { namespace: 'balance', newName: 'getAllPastDueConsumption' },
43
+ getPastDueConsumptionPeerBalance: { namespace: 'balance', newName: 'getAllPastDueConsumptionForPeer' },
44
+ // bee.chequebook
45
+ getChequebookAddress: { namespace: 'chequebook', newName: 'getAddress' },
46
+ getChequebookBalance: { namespace: 'chequebook', newName: 'getBalance' },
47
+ depositBZZToChequebook: { namespace: 'chequebook', newName: 'deposit' },
48
+ depositTokens: { namespace: 'chequebook', newName: 'deposit' },
49
+ withdrawBZZFromChequebook: { namespace: 'chequebook', newName: 'withdraw' },
50
+ withdrawTokens: { namespace: 'chequebook', newName: 'withdraw' },
51
+ // bee.cheque
52
+ getLastCheques: { namespace: 'cheque', newName: 'getAllLatest' },
53
+ getLastChequesForPeer: { namespace: 'cheque', newName: 'getAllLatestForPeer' },
54
+ getLastCashoutAction: { namespace: 'cheque', newName: 'getLastCashoutAction' },
55
+ cashoutLastCheque: { namespace: 'cheque', newName: 'cashoutLast' },
56
+ // bee.connectivity
57
+ checkConnection: { namespace: 'connectivity', newName: 'checkConnection' },
58
+ isConnected: { namespace: 'connectivity', newName: 'isConnected' },
59
+ isGateway: { namespace: 'connectivity', newName: 'isGateway' },
60
+ getNodeAddresses: { namespace: 'connectivity', newName: 'getNodeAddresses' },
61
+ getBlocklist: { namespace: 'connectivity', newName: 'getBlocklist' },
62
+ getPeers: { namespace: 'connectivity', newName: 'getPeers' },
63
+ removePeer: { namespace: 'connectivity', newName: 'removePeer' },
64
+ pingPeer: { namespace: 'connectivity', newName: 'ping' },
65
+ getTopology: { namespace: 'connectivity', newName: 'getTopology' },
66
+ // bee.data (/bytes)
67
+ uploadData: { namespace: 'data', newName: 'upload' },
68
+ downloadData: { namespace: 'data', newName: 'download' },
69
+ downloadReadableData: { namespace: 'data', newName: 'downloadReadable' },
70
+ probeData: { namespace: 'data', newName: 'probe' },
71
+ isReferenceRetrievable: { namespace: 'data', newName: 'isRetrievable' },
72
+ // bee.chunk (/chunks)
73
+ uploadChunk: { namespace: 'chunk', newName: 'upload' },
74
+ downloadChunk: { namespace: 'chunk', newName: 'download' },
75
+ // bee.file (single /bzz)
76
+ uploadFile: { namespace: 'file', newName: 'upload' },
77
+ downloadFile: { namespace: 'file', newName: 'download' },
78
+ downloadReadableFile: { namespace: 'file', newName: 'downloadReadable' },
79
+ // bee.collection (multi-file /bzz)
80
+ uploadCollection: { namespace: 'collection', newName: 'upload' },
81
+ uploadFiles: { namespace: 'collection', newName: 'uploadFromFileList' },
82
+ uploadFilesFromDirectory: { namespace: 'collection', newName: 'uploadFromDirectory' },
83
+ streamFiles: { namespace: 'collection', newName: 'stream' },
84
+ streamDirectory: { namespace: 'collection', newName: 'streamFromDirectory' },
85
+ hashDirectory: { namespace: 'collection', newName: 'hashDirectory' },
86
+ // bee.feed
87
+ makeFeedWriter: { namespace: 'feed', newName: 'makeWriter' },
88
+ makeFeedReader: { namespace: 'feed', newName: 'makeReader' },
89
+ createFeedManifest: { namespace: 'feed', newName: 'createManifest' },
90
+ fetchLatestFeedUpdate: { namespace: 'feed', newName: 'fetchLatestUpdate' },
91
+ isFeedRetrievable: { namespace: 'feed', newName: 'isRetrievable' },
92
+ // bee.grantee
93
+ createGrantees: { namespace: 'grantee', newName: 'create' },
94
+ getGrantees: { namespace: 'grantee', newName: 'get' },
95
+ patchGrantees: { namespace: 'grantee', newName: 'patch' },
96
+ // bee.messaging
97
+ pssSend: { namespace: 'messaging', newName: 'pssSend' },
98
+ pssReceive: { namespace: 'messaging', newName: 'pssReceive' },
99
+ pssSubscribe: { namespace: 'messaging', newName: 'pssSubscribe' },
100
+ gsocSend: { namespace: 'messaging', newName: 'gsocSend' },
101
+ gsocSubscribe: { namespace: 'messaging', newName: 'gsocSubscribe' },
102
+ gsocMine: { namespace: 'messaging', newName: 'gsocMine' },
103
+ // bee.pin
104
+ pin: { namespace: 'pin', newName: 'add' },
105
+ unpin: { namespace: 'pin', newName: 'remove' },
106
+ getAllPins: { namespace: 'pin', newName: 'getAll' },
107
+ getPin: { namespace: 'pin', newName: 'get' },
108
+ reuploadPinnedData: { namespace: 'pin', newName: 'reuploadData' },
109
+ // bee.settlement
110
+ getSettlements: { namespace: 'settlement', newName: 'get' },
111
+ getAllSettlements: { namespace: 'settlement', newName: 'getAll' },
112
+ // bee.soc
113
+ makeSOCWriter: { namespace: 'soc', newName: 'makeWriter' },
114
+ makeSOCReader: { namespace: 'soc', newName: 'makeReader' },
115
+ // bee.stake
116
+ getStake: { namespace: 'stake', newName: 'get' },
117
+ getWithdrawableStake: { namespace: 'stake', newName: 'getWithdrawable' },
118
+ depositStake: { namespace: 'stake', newName: 'deposit' },
119
+ withdrawSurplusStake: { namespace: 'stake', newName: 'withdrawSurplus' },
120
+ migrateStake: { namespace: 'stake', newName: 'migrate' },
121
+ getRedistributionState: { namespace: 'stake', newName: 'getRedistributionState' },
122
+ // bee.stamp
123
+ createPostageBatch: { namespace: 'stamp', newName: 'create' },
124
+ topUpBatch: { namespace: 'stamp', newName: 'topUp' },
125
+ diluteBatch: { namespace: 'stamp', newName: 'dilute' },
126
+ getPostageBatch: { namespace: 'stamp', newName: 'get' },
127
+ getGlobalPostageBatch: { namespace: 'stamp', newName: 'getGlobal' },
128
+ getPostageBatchBuckets: { namespace: 'stamp', newName: 'getBuckets' },
129
+ getAllPostageBatch: { namespace: 'stamp', newName: 'getAll' },
130
+ getAllGlobalPostageBatch: { namespace: 'stamp', newName: 'getAllGlobal' },
131
+ getPostageBatches: { namespace: 'stamp', newName: 'getAll' },
132
+ getGlobalPostageBatches: { namespace: 'stamp', newName: 'getAllGlobal' },
133
+ updatePostageBatchLabel: { namespace: 'stamp', newName: 'updateLabel' },
134
+ calculateTopUpForBzz: { namespace: 'stamp', newName: 'calculateTopUpForBZZ' },
135
+ // bee.storage
136
+ buyStorage: { namespace: 'storage', newName: 'buy' },
137
+ getStorageCost: { namespace: 'storage', newName: 'getCost' },
138
+ extendStorage: { namespace: 'storage', newName: 'extend' },
139
+ extendStorageSize: { namespace: 'storage', newName: 'extendSize' },
140
+ extendStorageDuration: { namespace: 'storage', newName: 'extendDuration' },
141
+ getExtensionCost: { namespace: 'storage', newName: 'getExtensionCost' },
142
+ getSizeExtensionCost: { namespace: 'storage', newName: 'getSizeExtensionCost' },
143
+ getDurationExtensionCost: { namespace: 'storage', newName: 'getDurationExtensionCost' },
144
+ renameStorage: { namespace: 'storage', newName: 'rename' },
145
+ // bee.status
146
+ getStatus: { namespace: 'status', newName: 'get' },
147
+ getHealth: { namespace: 'status', newName: 'getHealth' },
148
+ getReadiness: { namespace: 'status', newName: 'getReadiness' },
149
+ getNodeInfo: { namespace: 'status', newName: 'getNodeInfo' },
150
+ isSupportedExactVersion: { namespace: 'status', newName: 'isSupportedExactVersion' },
151
+ isSupportedApiVersion: { namespace: 'status', newName: 'isSupportedApiVersion' },
152
+ getVersions: { namespace: 'status', newName: 'getVersions' },
153
+ getReserveState: { namespace: 'status', newName: 'getReserveState' },
154
+ getChainState: { namespace: 'status', newName: 'getChainState' },
155
+ // bee.tag
156
+ createTag: { namespace: 'tag', newName: 'create' },
157
+ getAllTags: { namespace: 'tag', newName: 'getAll' },
158
+ retrieveTag: { namespace: 'tag', newName: 'get' },
159
+ deleteTag: { namespace: 'tag', newName: 'delete' },
160
+ updateTag: { namespace: 'tag', newName: 'update' },
161
+ // bee.transaction
162
+ getAllPendingTransactions: { namespace: 'transaction', newName: 'getAll' },
163
+ getPendingTransaction: { namespace: 'transaction', newName: 'get' },
164
+ rebroadcastPendingTransaction: { namespace: 'transaction', newName: 'rebroadcast' },
165
+ cancelPendingTransaction: { namespace: 'transaction', newName: 'cancel' },
166
+ // bee.wallet
167
+ getWalletBalance: { namespace: 'wallet', newName: 'getBalance' },
168
+ withdrawBZZToExternalWallet: { namespace: 'wallet', newName: 'withdrawBZZ' },
169
+ withdrawDAIToExternalWallet: { namespace: 'wallet', newName: 'withdrawDAI' },
170
+ };
171
+ function transform(sourceFile, checker) {
172
+ const source = sourceFile.text;
173
+ const isNewBee = (node) => !!node && ts.isNewExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === 'Bee';
174
+ // Does the type annotation mention `Bee` (`Bee`, `Bee | null`, `Bee | undefined`, …)?
175
+ const typeMentionsBee = (type) => {
176
+ if (!type)
177
+ return false;
178
+ if (ts.isTypeReferenceNode(type) && ts.isIdentifier(type.typeName) && type.typeName.text === 'Bee')
179
+ return true;
180
+ if (ts.isUnionTypeNode(type))
181
+ return type.types.some(typeMentionsBee);
182
+ return false;
183
+ };
184
+ // Syntactic pass — identify Bee bindings from annotations and `new Bee(...)` alone, so
185
+ // annotated/local code migrates even when the project's deps aren't installed (types
186
+ // unresolved). `beeNames` = bare identifiers; `beeFields` = `this.<field>`.
187
+ const beeNames = new Set();
188
+ const beeFields = new Set();
189
+ const collect = (node) => {
190
+ // `const bee = new Bee(...)` | `const bee: Bee = ...` | `let bee: Bee`
191
+ if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && (typeMentionsBee(node.type) || isNewBee(node.initializer))) {
192
+ beeNames.add(node.name.text);
193
+ }
194
+ // `bee = new Bee(...)` | `this.bee = new Bee(...)`
195
+ if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken && isNewBee(node.right)) {
196
+ if (ts.isIdentifier(node.left)) {
197
+ beeNames.add(node.left.text);
198
+ }
199
+ else if (ts.isPropertyAccessExpression(node.left) && node.left.expression.kind === ts.SyntaxKind.ThisKeyword) {
200
+ beeFields.add(node.left.name.text);
201
+ }
202
+ }
203
+ // function/method/ctor parameter: `(bee: Bee)`, `(beeApi: Bee | null)`; a ctor
204
+ // parameter-property (has modifiers) is also reachable as `this.<name>`.
205
+ if (ts.isParameter(node) && ts.isIdentifier(node.name) && typeMentionsBee(node.type)) {
206
+ beeNames.add(node.name.text);
207
+ if (node.modifiers?.length)
208
+ beeFields.add(node.name.text);
209
+ }
210
+ // class field: `bee = new Bee(...)` | `bee: Bee`
211
+ if (ts.isPropertyDeclaration(node) && ts.isIdentifier(node.name) && (typeMentionsBee(node.type) || isNewBee(node.initializer))) {
212
+ beeFields.add(node.name.text);
213
+ }
214
+ ts.forEachChild(node, collect);
215
+ };
216
+ collect(sourceFile);
217
+ // A receiver is a Bee if identified syntactically (above) OR resolved by the type checker
218
+ // to the `Bee` class declared by bee-js — the latter additionally catches imported/shared
219
+ // instances and factory calls (`getBee()`) when the project's types resolve.
220
+ const isBeeReceiver = (expr) => {
221
+ if (ts.isIdentifier(expr) && beeNames.has(expr.text))
222
+ return true;
223
+ if (ts.isPropertyAccessExpression(expr) &&
224
+ expr.expression.kind === ts.SyntaxKind.ThisKeyword &&
225
+ beeFields.has(expr.name.text)) {
226
+ return true;
227
+ }
228
+ const symbol = checker.getTypeAtLocation(expr).getSymbol();
229
+ if (!symbol || symbol.getName() !== 'Bee') {
230
+ return false;
231
+ }
232
+ return (symbol.getDeclarations() ?? []).some(decl => {
233
+ if (!ts.isClassDeclaration(decl)) {
234
+ return false;
235
+ }
236
+ const file = decl.getSourceFile().fileName;
237
+ return /[/\\]bee-js[/\\]/.test(file) || /[/\\]bee\.(d\.)?ts$/.test(file);
238
+ });
239
+ };
240
+ // ChunkBuilder.hash() now returns a Reference, not a raw Uint8Array.
241
+ const isChunkBuilderReceiver = (expr) => {
242
+ const symbol = checker.getTypeAtLocation(expr).getSymbol();
243
+ if (!symbol || symbol.getName() !== 'ChunkBuilder') {
244
+ return false;
245
+ }
246
+ return (symbol.getDeclarations() ?? []).some(decl => {
247
+ if (!ts.isClassDeclaration(decl)) {
248
+ return false;
249
+ }
250
+ const file = decl.getSourceFile().fileName;
251
+ return /[/\\]core-sdk[/\\]/.test(file) || /[/\\]splitter\.(d\.)?ts$/.test(file);
252
+ });
253
+ };
254
+ const replacements = [];
255
+ // MerkleTree was removed in v13; ChunkSplitter is the replacement.
256
+ let merkleTreeLocalName = null;
257
+ let merkleTreeImportNameNode = null;
258
+ for (const stmt of sourceFile.statements) {
259
+ if (ts.isImportDeclaration(stmt) &&
260
+ ts.isStringLiteral(stmt.moduleSpecifier) &&
261
+ stmt.moduleSpecifier.text === '@ethersphere/bee-js' &&
262
+ stmt.importClause?.namedBindings &&
263
+ ts.isNamedImports(stmt.importClause.namedBindings)) {
264
+ for (const element of stmt.importClause.namedBindings.elements) {
265
+ const importedNameNode = element.propertyName ?? element.name;
266
+ if (importedNameNode.text === 'MerkleTree') {
267
+ // Aliased imports keep their local name unchanged.
268
+ replacements.push({
269
+ start: importedNameNode.getStart(sourceFile),
270
+ end: importedNameNode.getEnd(),
271
+ text: 'ChunkSplitter',
272
+ });
273
+ if (!element.propertyName) {
274
+ merkleTreeLocalName = element.name.text;
275
+ merkleTreeImportNameNode = element.name;
276
+ }
277
+ }
278
+ }
279
+ }
280
+ // @upcoming/swarm-core is now @ethersphere/core-sdk.
281
+ if ((ts.isImportDeclaration(stmt) || ts.isExportDeclaration(stmt)) &&
282
+ stmt.moduleSpecifier &&
283
+ ts.isStringLiteral(stmt.moduleSpecifier) &&
284
+ stmt.moduleSpecifier.text === '@upcoming/swarm-core') {
285
+ const quote = stmt.moduleSpecifier.getText(sourceFile)[0];
286
+ replacements.push({
287
+ start: stmt.moduleSpecifier.getStart(sourceFile),
288
+ end: stmt.moduleSpecifier.getEnd(),
289
+ text: `${quote}@ethersphere/core-sdk${quote}`,
290
+ });
291
+ }
292
+ }
293
+ // Syntactic fallback: MerkleTree no longer type-checks, so isChunkBuilderReceiver alone
294
+ // won't find it.
295
+ const unwrap = (expr) => {
296
+ while (ts.isParenthesizedExpression(expr) || ts.isAwaitExpression(expr)) {
297
+ expr = expr.expression;
298
+ }
299
+ return expr;
300
+ };
301
+ const isChunkSplitterRootCall = (expr) => {
302
+ const inner = unwrap(expr);
303
+ return (merkleTreeLocalName !== null &&
304
+ ts.isCallExpression(inner) &&
305
+ ts.isPropertyAccessExpression(inner.expression) &&
306
+ ts.isIdentifier(inner.expression.expression) &&
307
+ inner.expression.expression.text === merkleTreeLocalName &&
308
+ (inner.expression.name.text === 'root' || inner.expression.name.text === 'finalize'));
309
+ };
310
+ const chunkBuilderVarNames = new Set();
311
+ const collectChunkBuilderVars = (node) => {
312
+ if (ts.isVariableDeclaration(node) &&
313
+ ts.isIdentifier(node.name) &&
314
+ node.initializer &&
315
+ isChunkSplitterRootCall(node.initializer)) {
316
+ chunkBuilderVarNames.add(node.name.text);
317
+ }
318
+ ts.forEachChild(node, collectChunkBuilderVars);
319
+ };
320
+ if (merkleTreeLocalName) {
321
+ collectChunkBuilderVars(sourceFile);
322
+ }
323
+ // bee-js's MantarayNode.collect()/.find()/.findClosest() return core-sdk's MantarayNode,
324
+ // not its own.
325
+ const isMantarayNodeType = (type, fileTest) => {
326
+ const symbol = type.getSymbol();
327
+ if (!symbol || symbol.getName() !== 'MantarayNode') {
328
+ return false;
329
+ }
330
+ return (symbol.getDeclarations() ?? []).some(decl => ts.isClassDeclaration(decl) && fileTest.test(decl.getSourceFile().fileName));
331
+ };
332
+ const isBeeMantarayNodeType = (type) => isMantarayNodeType(type, /[/\\]bee-js[/\\]/);
333
+ const isCoreMantarayNodeType = (type) => isMantarayNodeType(type, /[/\\]core-sdk[/\\]/);
334
+ // Tracks for-of loop vars whose element type is core-sdk's MantarayNode.
335
+ const coreFlavoredNames = new Set();
336
+ const collectCoreFlavoredBindings = (node) => {
337
+ if (ts.isForOfStatement(node) && ts.isVariableDeclarationList(node.initializer)) {
338
+ const decl = node.initializer.declarations[0];
339
+ if (decl && ts.isIdentifier(decl.name) && isCoreMantarayNodeType(checker.getTypeAtLocation(decl.name))) {
340
+ coreFlavoredNames.add(decl.name.text);
341
+ }
342
+ }
343
+ ts.forEachChild(node, collectCoreFlavoredBindings);
344
+ };
345
+ collectCoreFlavoredBindings(sourceFile);
346
+ let needsCoreMantarayNodeImport = false;
347
+ // Rewrites a parameter's type when called with a core-flavored argument.
348
+ const rewriteMantarayNodeParameters = (node) => {
349
+ if (ts.isCallExpression(node)) {
350
+ node.arguments.forEach((arg, index) => {
351
+ if (!ts.isIdentifier(arg) || !coreFlavoredNames.has(arg.text)) {
352
+ return;
353
+ }
354
+ const signature = checker.getResolvedSignature(node);
355
+ const decl = signature?.getDeclaration();
356
+ const param = decl && 'parameters' in decl ? decl.parameters[index] : undefined;
357
+ if (param?.type &&
358
+ ts.isTypeReferenceNode(param.type) &&
359
+ isBeeMantarayNodeType(checker.getTypeFromTypeNode(param.type))) {
360
+ replacements.push({
361
+ start: param.type.getStart(sourceFile),
362
+ end: param.type.getEnd(),
363
+ text: 'CoreMantarayNode',
364
+ });
365
+ needsCoreMantarayNodeImport = true;
366
+ }
367
+ });
368
+ }
369
+ ts.forEachChild(node, rewriteMantarayNodeParameters);
370
+ };
371
+ // Rewrites a Map/Array/Set's value type when a core-flavored value is inserted.
372
+ const rewriteMantarayNodeContainers = (node) => {
373
+ if (ts.isCallExpression(node) &&
374
+ ts.isPropertyAccessExpression(node.expression) &&
375
+ ['set', 'push', 'add'].includes(node.expression.name.text)) {
376
+ const valueArg = node.expression.name.text === 'set' ? node.arguments[1] : node.arguments[0];
377
+ if (valueArg && ts.isIdentifier(valueArg) && coreFlavoredNames.has(valueArg.text)) {
378
+ const receiverSymbol = checker.getSymbolAtLocation(node.expression.expression);
379
+ const receiverDecl = receiverSymbol?.declarations?.find(ts.isVariableDeclaration);
380
+ // Type args may be on the declaration or the constructor call.
381
+ const typeArguments = receiverDecl?.type && ts.isTypeReferenceNode(receiverDecl.type)
382
+ ? receiverDecl.type.typeArguments
383
+ : receiverDecl?.initializer && ts.isNewExpression(receiverDecl.initializer)
384
+ ? receiverDecl.initializer.typeArguments
385
+ : undefined;
386
+ if (typeArguments) {
387
+ for (const typeArg of typeArguments) {
388
+ if (ts.isTypeReferenceNode(typeArg) && isBeeMantarayNodeType(checker.getTypeFromTypeNode(typeArg))) {
389
+ replacements.push({
390
+ start: typeArg.getStart(sourceFile),
391
+ end: typeArg.getEnd(),
392
+ text: 'CoreMantarayNode',
393
+ });
394
+ needsCoreMantarayNodeImport = true;
395
+ }
396
+ }
397
+ }
398
+ }
399
+ }
400
+ ts.forEachChild(node, rewriteMantarayNodeContainers);
401
+ };
402
+ if (coreFlavoredNames.size > 0) {
403
+ rewriteMantarayNodeParameters(sourceFile);
404
+ rewriteMantarayNodeContainers(sourceFile);
405
+ }
406
+ if (needsCoreMantarayNodeImport) {
407
+ const coreSdkImport = sourceFile.statements.find((stmt) => ts.isImportDeclaration(stmt) &&
408
+ ts.isStringLiteral(stmt.moduleSpecifier) &&
409
+ stmt.moduleSpecifier.text === '@ethersphere/core-sdk');
410
+ if (coreSdkImport?.importClause?.namedBindings && ts.isNamedImports(coreSdkImport.importClause.namedBindings)) {
411
+ const elements = coreSdkImport.importClause.namedBindings.elements;
412
+ const lastSpecifier = elements[elements.length - 1];
413
+ if (lastSpecifier) {
414
+ replacements.push({
415
+ start: lastSpecifier.getEnd(),
416
+ end: lastSpecifier.getEnd(),
417
+ text: ', MantarayNode as CoreMantarayNode',
418
+ });
419
+ }
420
+ }
421
+ else {
422
+ const beeJsImport = sourceFile.statements.find((stmt) => ts.isImportDeclaration(stmt) &&
423
+ ts.isStringLiteral(stmt.moduleSpecifier) &&
424
+ stmt.moduleSpecifier.text === '@ethersphere/bee-js');
425
+ const insertAt = beeJsImport ? beeJsImport.getEnd() : 0;
426
+ replacements.push({
427
+ start: insertAt,
428
+ end: insertAt,
429
+ text: `\nimport { MantarayNode as CoreMantarayNode } from '@ethersphere/core-sdk'`,
430
+ });
431
+ }
432
+ }
433
+ const visit = (node) => {
434
+ // Any `<bee>.<method>` access — called or not — so bare method references migrate too.
435
+ if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name)) {
436
+ const mapping = METHOD_MAP[node.name.text];
437
+ if (mapping && isBeeReceiver(node.expression)) {
438
+ // Preserve optional chaining on the receiver: `bee?.uploadData` → `bee?.data.upload`.
439
+ const separator = node.questionDotToken ? '?.' : '.';
440
+ replacements.push({
441
+ start: node.getStart(sourceFile),
442
+ end: node.getEnd(),
443
+ text: `${node.expression.getText(sourceFile)}${separator}${mapping.namespace}.${mapping.newName}`,
444
+ });
445
+ }
446
+ }
447
+ // jest.spyOn uses a string literal, so the rewrite above doesn't catch it.
448
+ if (ts.isCallExpression(node) &&
449
+ ts.isPropertyAccessExpression(node.expression) &&
450
+ node.expression.name.text === 'spyOn' &&
451
+ node.arguments.length >= 2) {
452
+ const [receiverArg, methodArg] = node.arguments;
453
+ if (receiverArg && methodArg && ts.isStringLiteralLike(methodArg)) {
454
+ const mapping = METHOD_MAP[methodArg.text];
455
+ const quote = methodArg.getText(sourceFile)[0];
456
+ // Namespaces are per-instance properties, not on Bee.prototype, so spying there
457
+ // needs a throwaway instance to reach the namespace's own (shared) prototype.
458
+ if (mapping && ts.isPropertyAccessExpression(receiverArg) && receiverArg.name.text === 'prototype' && isBeeReceiver(receiverArg.expression)) {
459
+ const className = receiverArg.expression.getText(sourceFile);
460
+ replacements.push({
461
+ start: receiverArg.getStart(sourceFile),
462
+ end: receiverArg.getEnd(),
463
+ text: `Object.getPrototypeOf(new ${className}('http://localhost:1633').${mapping.namespace})`,
464
+ });
465
+ replacements.push({
466
+ start: methodArg.getStart(sourceFile),
467
+ end: methodArg.getEnd(),
468
+ text: `${quote}${mapping.newName}${quote}`,
469
+ });
470
+ }
471
+ else if (mapping && isBeeReceiver(receiverArg)) {
472
+ replacements.push({
473
+ start: receiverArg.getStart(sourceFile),
474
+ end: receiverArg.getEnd(),
475
+ text: `${receiverArg.getText(sourceFile)}.${mapping.namespace}`,
476
+ });
477
+ replacements.push({
478
+ start: methodArg.getStart(sourceFile),
479
+ end: methodArg.getEnd(),
480
+ text: `${quote}${mapping.newName}${quote}`,
481
+ });
482
+ }
483
+ }
484
+ }
485
+ // ChunkBuilder.hash() now returns a Reference; append the conversion back.
486
+ if (merkleTreeLocalName &&
487
+ ts.isCallExpression(node) &&
488
+ ts.isPropertyAccessExpression(node.expression) &&
489
+ node.expression.name.text === 'hash' &&
490
+ node.arguments.length === 0 &&
491
+ (isChunkSplitterRootCall(node.expression.expression) ||
492
+ (ts.isIdentifier(node.expression.expression) && chunkBuilderVarNames.has(node.expression.expression.text)) ||
493
+ isChunkBuilderReceiver(node.expression.expression))) {
494
+ replacements.push({
495
+ start: node.getEnd(),
496
+ end: node.getEnd(),
497
+ text: '.toUint8Array()',
498
+ });
499
+ }
500
+ // Renames remaining MerkleTree usages (import itself already handled above).
501
+ if (merkleTreeLocalName &&
502
+ ts.isIdentifier(node) &&
503
+ node.text === merkleTreeLocalName &&
504
+ node !== merkleTreeImportNameNode) {
505
+ replacements.push({
506
+ start: node.getStart(sourceFile),
507
+ end: node.getEnd(),
508
+ text: 'ChunkSplitter',
509
+ });
510
+ }
511
+ ts.forEachChild(node, visit);
512
+ };
513
+ visit(sourceFile);
514
+ if (replacements.length === 0) {
515
+ return null;
516
+ }
517
+ // Apply from end to start to preserve positions
518
+ replacements.sort((a, b) => b.start - a.start);
519
+ let result = source;
520
+ for (const { start, end, text } of replacements) {
521
+ result = result.slice(0, start) + text + result.slice(end);
522
+ }
523
+ return result;
524
+ }