@sentio/cli 4.3.0 → 4.3.1

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.js CHANGED
@@ -130816,27 +130816,24 @@ function normalizedModule(name, m) {
130816
130816
  functions: Object.entries(m.exposedFunctions ?? {}).map(([k, f]) => normalizedFunction(k, f))
130817
130817
  };
130818
130818
  }
130819
- function normalizedModulesToAbi(modules) {
130819
+ function normalizedModulesToAbi(modules, fallbackAddress) {
130820
130820
  const map = modules?.result ?? modules;
130821
- return (Array.isArray(map) ? map.map((m) => [m.name, m]) : Object.entries(map ?? {})).map(([n, m]) => ({
130822
- address: m.address,
130823
- module: normalizedModule(n, m)
130824
- }));
130821
+ return (Array.isArray(map) ? map.map((m) => [m.name, m]) : Object.entries(map ?? {})).map(([n, m]) => {
130822
+ const address = m.address ?? fallbackAddress;
130823
+ if (typeof address !== "string" || address === "") throw Error(`cannot resolve package address of module ${m.name ?? n}`);
130824
+ return {
130825
+ address,
130826
+ module: normalizedModule(n, m)
130827
+ };
130828
+ });
130829
+ }
130830
+ function isLegacyNormalizedModule(m) {
130831
+ return !!m && typeof m === "object" && !Array.isArray(m) && ("exposedFunctions" in m || "structs" in m);
130825
130832
  }
130826
130833
  function isLegacyNormalizedModules(parsed) {
130827
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return false;
130828
- const map = parsed.result ?? parsed;
130829
- if (!map || typeof map !== "object" || Array.isArray(map)) return false;
130830
- return Object.values(map).some((m) => m && typeof m === "object" && ("exposedFunctions" in m || "structs" in m));
130831
- }
130832
- function legacySuiPackageAddress(file, parsed) {
130833
- const base = path$1.basename(file, ".json");
130834
- if (base.startsWith("0x")) return base;
130835
130834
  const map = parsed?.result ?? parsed;
130836
- for (const module of Object.values(map ?? {})) {
130837
- const address = module?.address;
130838
- if (typeof address === "string" && address.startsWith("0x")) return address;
130839
- }
130835
+ if (!map || typeof map !== "object") return false;
130836
+ return (Array.isArray(map) ? map : Object.values(map)).some(isLegacyNormalizedModule);
130840
130837
  }
130841
130838
  function collectLegacySuiAbis(baseDir) {
130842
130839
  const result = [];
@@ -130856,31 +130853,31 @@ function collectLegacySuiAbis(baseDir) {
130856
130853
  continue;
130857
130854
  }
130858
130855
  if (!isLegacyNormalizedModules(parsed)) continue;
130859
- const address = legacySuiPackageAddress(fullPath, parsed);
130860
- if (!address) {
130861
- console.log(chalk.yellow(`Skipping legacy Sui ABI ${fullPath}: cannot resolve package address, re-download it manually`));
130862
- continue;
130863
- }
130864
- const isTestnet = path$1.relative(baseDir, fullPath).split(path$1.sep).includes("testnet");
130856
+ const base = path$1.basename(fullPath, ".json");
130865
130857
  result.push({
130866
130858
  file: fullPath,
130867
- address,
130868
- chain: isTestnet ? import_dist.SuiChainId.SUI_TESTNET : import_dist.SuiChainId.SUI_MAINNET
130859
+ modules: parsed,
130860
+ fallbackAddress: base.startsWith("0x") ? base : void 0
130869
130861
  });
130870
130862
  }
130871
130863
  };
130872
130864
  walk(baseDir);
130873
130865
  return result;
130874
130866
  }
130875
- async function redownloadLegacySuiAbis(baseDir = path$1.resolve("abis", "sui")) {
130867
+ function convertLegacySuiAbis(baseDir = path$1.resolve("abis", "sui")) {
130876
130868
  const legacy = collectLegacySuiAbis(baseDir);
130877
130869
  if (legacy.length === 0) return;
130878
- console.log(chalk.yellow(`Found ${legacy.length} legacy Sui ABI file(s), re-downloading in the current format`));
130879
- let previousChain = "";
130880
- for (const { file, chain, address } of legacy) {
130881
- if (chain === previousChain) await new Promise((resolve) => setTimeout(resolve, 5e3));
130882
- else previousChain = chain;
130883
- writeABIFile((await getABI(chain, address, path$1.basename(file, ".json"))).abi, file);
130870
+ console.log(chalk.yellow(`Found ${legacy.length} legacy Sui ABI file(s), converting to the current format`));
130871
+ for (const { file, modules, fallbackAddress } of legacy) {
130872
+ let abi;
130873
+ try {
130874
+ abi = normalizedModulesToAbi(modules, fallbackAddress);
130875
+ } catch (e) {
130876
+ console.log(chalk.yellow(`Skipping legacy Sui ABI ${file}: ${e?.message ?? e}, re-download it with \`sentio add\``));
130877
+ continue;
130878
+ }
130879
+ import_lib$1.default.writeFileSync(file, JSON.stringify(abi, null, 2));
130880
+ console.log(chalk.green("Converted legacy Sui ABI", file));
130884
130881
  }
130885
130882
  }
130886
130883
  async function getABI(chain, address, name, credentials) {
@@ -131130,7 +131127,7 @@ async function codegen(genExample) {
131130
131127
  writeABIFile((await getABI(contract.chain, contract.address, contract.name)).abi, outputPath);
131131
131128
  }
131132
131129
  const outputBase = path$1.resolve("src", "types");
131133
- await redownloadLegacySuiAbis(path$1.resolve("abis", "sui"));
131130
+ convertLegacySuiAbis(path$1.resolve("abis", "sui"));
131134
131131
  for (const gen of CHAIN_TYPES) try {
131135
131132
  const codegen = await import(`@sentio/sdk/${gen}/codegen`);
131136
131133
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentio/cli",
3
- "version": "4.3.0",
3
+ "version": "4.3.1",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
package/src/abi.ts CHANGED
@@ -137,65 +137,60 @@ function normalizedModule(name: string, m: any): any {
137
137
  }
138
138
 
139
139
  // Convert the JSON-RPC normalized-modules shape (a `{ name: module }` map or an
140
- // array of modules) into the gRPC ABI array consumed by the v2 codegen.
141
- export function normalizedModulesToAbi(modules: any): Array<{ address: string; module: any }> {
140
+ // array of modules, optionally wrapped in `{ result }`) into the gRPC ABI array
141
+ // consumed by the v2 codegen. `fallbackAddress` fills in the package address of
142
+ // modules that don't carry one; modules that do keep their own.
143
+ export function normalizedModulesToAbi(
144
+ modules: any,
145
+ fallbackAddress?: string
146
+ ): Array<{ address: string; module: any }> {
142
147
  const map = modules?.result ?? modules
143
148
  const entries: Array<[string, any]> = Array.isArray(map)
144
149
  ? map.map((m: any) => [m.name, m])
145
150
  : Object.entries(map ?? {})
146
- return entries.map(([n, m]) => ({ address: m.address, module: normalizedModule(n, m) }))
151
+ return entries.map(([n, m]) => {
152
+ const address = m.address ?? fallbackAddress
153
+ if (typeof address !== 'string' || address === '') {
154
+ throw Error(`cannot resolve package address of module ${m.name ?? n}`)
155
+ }
156
+ return { address, module: normalizedModule(n, m) }
157
+ })
147
158
  }
148
159
 
149
- // A Sui ABI downloaded by an older CLI is the raw JSON-RPC
150
- // `getNormalizedMoveModulesByPackage` result: a `{ moduleName: { structs,
151
- // exposedFunctions, ... } }` map. The v2 codegen (see comment at top of file)
152
- // instead consumes the gRPC array shape produced by `normalizedModulesToAbi`.
153
- // Feeding a legacy-shaped file straight to codegen throws
154
- // (`modules.map is not a function`), so `sentio add`/`build`/`gen` fail whenever
155
- // a stale Sui ABI is already sitting in `abis/sui`. Detect that legacy shape.
156
- function isLegacyNormalizedModules(parsed: any): boolean {
157
- // The gRPC shape is an array; the legacy JSON-RPC shape is a plain object map.
158
- if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
159
- return false
160
- }
161
- const map = parsed.result ?? parsed
162
- if (!map || typeof map !== 'object' || Array.isArray(map)) {
160
+ function isLegacyNormalizedModule(m: any): boolean {
161
+ return !!m && typeof m === 'object' && !Array.isArray(m) && ('exposedFunctions' in m || 'structs' in m)
162
+ }
163
+
164
+ // A Sui ABI saved by an older CLI (or by hand from a JSON-RPC response) is the
165
+ // raw `getNormalizedMoveModulesByPackage` result: a `{ moduleName: { structs,
166
+ // exposedFunctions, ... } }` map or an array of such modules (the pre-gRPC
167
+ // codegen read both through Object.values), optionally wrapped in `{ result }`.
168
+ // The v2 codegen (see comment at top of file) instead consumes the gRPC array
169
+ // shape (`[{ address, module }]`) produced by `normalizedModulesToAbi`. Feeding
170
+ // a legacy-shaped file straight to codegen throws (`modules.map is not a
171
+ // function` for the map, `Cannot read properties of undefined` for the array),
172
+ // so `sentio add`/`build`/`gen` fail whenever a stale Sui ABI is already
173
+ // sitting in `abis/sui`. Detect every legacy variant.
174
+ export function isLegacyNormalizedModules(parsed: any): boolean {
175
+ const map = parsed?.result ?? parsed
176
+ if (!map || typeof map !== 'object') {
163
177
  return false
164
178
  }
165
- return Object.values(map).some((m: any) => m && typeof m === 'object' && ('exposedFunctions' in m || 'structs' in m))
179
+ return (Array.isArray(map) ? map : Object.values(map)).some(isLegacyNormalizedModule)
166
180
  }
167
181
 
168
- // A legacy-shaped Sui ABI file on disk, together with the package address and
169
- // network recovered from its name/content so it can be re-downloaded.
182
+ // A legacy-shaped Sui ABI file on disk together with its parsed content and the
183
+ // package address recovered from the 0x-prefixed file name (what `sentio add`
184
+ // uses by default), used for modules that don't carry their own address.
170
185
  export interface LegacySuiAbi {
171
186
  file: string
172
- address: string
173
- chain: SuiChainId.SUI_MAINNET | SuiChainId.SUI_TESTNET
174
- }
175
-
176
- // Recover the package address of a legacy Sui ABI: prefer the 0x-prefixed file
177
- // name (what `sentio add` uses by default), otherwise fall back to the `address`
178
- // carried by the normalized modules (covers files saved under a custom --name).
179
- function legacySuiPackageAddress(file: string, parsed: any): string | undefined {
180
- const base = path.basename(file, '.json')
181
- if (base.startsWith('0x')) {
182
- return base
183
- }
184
- const map = parsed?.result ?? parsed
185
- for (const module of Object.values(map ?? {})) {
186
- const address = (module as any)?.address
187
- if (typeof address === 'string' && address.startsWith('0x')) {
188
- return address
189
- }
190
- }
191
- return undefined
187
+ modules: any
188
+ fallbackAddress?: string
192
189
  }
193
190
 
194
- // Recursively collect every legacy-shaped Sui ABI under `baseDir`, resolving the
195
- // package address and network (testnet ABIs live under `<baseDir>/testnet`, see
196
- // getABIFilePath) for each. Pure/offline — the download happens in
197
- // `redownloadLegacySuiAbis`. Iota still consumes the legacy shape, so this must
198
- // only ever be pointed at the Sui directory.
191
+ // Recursively collect every legacy-shaped Sui ABI under `baseDir`. Pure/offline;
192
+ // the conversion happens in `convertLegacySuiAbis`. Iota still consumes the
193
+ // legacy shape, so this must only ever be pointed at the Sui directory.
199
194
  export function collectLegacySuiAbis(baseDir: string): LegacySuiAbi[] {
200
195
  const result: LegacySuiAbi[] = []
201
196
  const walk = (dir: string) => {
@@ -220,43 +215,39 @@ export function collectLegacySuiAbis(baseDir: string): LegacySuiAbi[] {
220
215
  if (!isLegacyNormalizedModules(parsed)) {
221
216
  continue
222
217
  }
223
- const address = legacySuiPackageAddress(fullPath, parsed)
224
- if (!address) {
225
- console.log(
226
- chalk.yellow(`Skipping legacy Sui ABI ${fullPath}: cannot resolve package address, re-download it manually`)
227
- )
228
- continue
229
- }
230
- const isTestnet = path.relative(baseDir, fullPath).split(path.sep).includes('testnet')
231
- result.push({ file: fullPath, address, chain: isTestnet ? SuiChainId.SUI_TESTNET : SuiChainId.SUI_MAINNET })
218
+ const base = path.basename(fullPath, '.json')
219
+ result.push({ file: fullPath, modules: parsed, fallbackAddress: base.startsWith('0x') ? base : undefined })
232
220
  }
233
221
  }
234
222
  walk(baseDir)
235
223
  return result
236
224
  }
237
225
 
238
- // Sui ABIs downloaded by an older CLI are stored in the legacy JSON-RPC map
239
- // shape, which the current gRPC codegen can't read (`modules.map is not a
240
- // function`), so a stale Sui ABI left in `abis/sui` makes `sentio add`/`build`/
241
- // `gen` fail for the whole project. Collect every such file, then re-download it
242
- // through getABI so it lands in the current shape with fresh on-chain data.
243
- // Fetched sequentially with a delay between same-network requests to stay under
244
- // Sui public-RPC rate limits, matching the "download missing ABI" loop.
245
- export async function redownloadLegacySuiAbis(baseDir = path.resolve('abis', 'sui')): Promise<void> {
226
+ // Sui ABIs saved by an older CLI are stored in the legacy JSON-RPC shape, which
227
+ // the current gRPC codegen can't read, so a stale Sui ABI left in `abis/sui`
228
+ // makes `sentio add`/`build`/`gen` fail for the whole project. Rewrite every
229
+ // such file in place through `normalizedModulesToAbi`. The legacy file already
230
+ // holds the full module ABI, so this is a pure local conversion: no network, no
231
+ // dependence on a hard-coded fullnode URL, and it also covers packages saved
232
+ // from networks the CLI can't re-download from.
233
+ export function convertLegacySuiAbis(baseDir = path.resolve('abis', 'sui')): void {
246
234
  const legacy = collectLegacySuiAbis(baseDir)
247
235
  if (legacy.length === 0) {
248
236
  return
249
237
  }
250
- console.log(chalk.yellow(`Found ${legacy.length} legacy Sui ABI file(s), re-downloading in the current format`))
251
- let previousChain = ''
252
- for (const { file, chain, address } of legacy) {
253
- if (chain === previousChain) {
254
- await new Promise((resolve) => setTimeout(resolve, 5000))
255
- } else {
256
- previousChain = chain
238
+ console.log(chalk.yellow(`Found ${legacy.length} legacy Sui ABI file(s), converting to the current format`))
239
+ for (const { file, modules, fallbackAddress } of legacy) {
240
+ let abi: ReturnType<typeof normalizedModulesToAbi>
241
+ try {
242
+ abi = normalizedModulesToAbi(modules, fallbackAddress)
243
+ } catch (e: any) {
244
+ console.log(
245
+ chalk.yellow(`Skipping legacy Sui ABI ${file}: ${e?.message ?? e}, re-download it with \`sentio add\``)
246
+ )
247
+ continue
257
248
  }
258
- const res = await getABI(chain, address, path.basename(file, '.json'))
259
- writeABIFile(res.abi, file)
249
+ fs.writeFileSync(file, JSON.stringify(abi, null, 2))
250
+ console.log(chalk.green('Converted legacy Sui ABI', file))
260
251
  }
261
252
  }
262
253
 
@@ -4,7 +4,7 @@ import fs from 'fs-extra'
4
4
  import { checkSdkCompatibility, getPackageRoot } from '../utils.js'
5
5
  import { Command } from '@commander-js/extra-typings'
6
6
  import { CHAIN_TYPES, loadProcessorConfig } from '../config.js'
7
- import { getABIFilePath, getABI, writeABIFile, redownloadLegacySuiAbis } from '../abi.js'
7
+ import { getABIFilePath, getABI, writeABIFile, convertLegacySuiAbis } from '../abi.js'
8
8
  import { execStep, execPackageManager } from '../execution.js'
9
9
  import { CommandOptionsType } from './types.js'
10
10
 
@@ -112,11 +112,11 @@ export async function codegen(genExample: boolean) {
112
112
 
113
113
  const outputBase = path.resolve('src', 'types')
114
114
 
115
- // Re-download any Sui ABIs saved by an older CLI in the legacy JSON-RPC map
116
- // shape; the current codegen only reads the gRPC array shape, so a stale file
117
- // left in abis/sui would otherwise make the Sui codegen throw for the whole
115
+ // Convert any Sui ABIs saved by an older CLI in the legacy JSON-RPC shape;
116
+ // the current codegen only reads the gRPC array shape, so a stale file left
117
+ // in abis/sui would otherwise make the Sui codegen throw for the whole
118
118
  // project.
119
- await redownloadLegacySuiAbis(path.resolve('abis', 'sui'))
119
+ convertLegacySuiAbis(path.resolve('abis', 'sui'))
120
120
 
121
121
  for (const gen of CHAIN_TYPES) {
122
122
  try {