@mysten/sui 1.24.0 → 1.25.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 +6 -0
- package/dist/cjs/transactions/Arguments.d.ts +2 -2
- package/dist/cjs/transactions/Transaction.d.ts +4 -4
- package/dist/cjs/transactions/TransactionData.d.ts +2 -2
- package/dist/cjs/transactions/data/v1.d.ts +4 -4
- package/dist/cjs/transactions/data/v2.d.ts +4 -4
- package/dist/cjs/transactions/plugins/NamedPackagesPlugin.d.ts +5 -7
- package/dist/cjs/transactions/plugins/NamedPackagesPlugin.js +84 -43
- package/dist/cjs/transactions/plugins/NamedPackagesPlugin.js.map +3 -3
- package/dist/cjs/transactions/plugins/utils.d.ts +10 -6
- package/dist/cjs/transactions/plugins/utils.js +64 -37
- package/dist/cjs/transactions/plugins/utils.js.map +2 -2
- package/dist/cjs/utils/sui-types.d.ts +1 -2
- package/dist/cjs/utils/sui-types.js +3 -1
- package/dist/cjs/utils/sui-types.js.map +2 -2
- package/dist/cjs/version.d.ts +2 -2
- package/dist/cjs/version.js +2 -2
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/transactions/Arguments.d.ts +2 -2
- package/dist/esm/transactions/Transaction.d.ts +4 -4
- package/dist/esm/transactions/TransactionData.d.ts +2 -2
- package/dist/esm/transactions/data/v1.d.ts +4 -4
- package/dist/esm/transactions/data/v2.d.ts +4 -4
- package/dist/esm/transactions/plugins/NamedPackagesPlugin.d.ts +5 -7
- package/dist/esm/transactions/plugins/NamedPackagesPlugin.js +91 -44
- package/dist/esm/transactions/plugins/NamedPackagesPlugin.js.map +3 -3
- package/dist/esm/transactions/plugins/utils.d.ts +10 -6
- package/dist/esm/transactions/plugins/utils.js +64 -37
- package/dist/esm/transactions/plugins/utils.js.map +2 -2
- package/dist/esm/utils/sui-types.d.ts +1 -2
- package/dist/esm/utils/sui-types.js +3 -1
- package/dist/esm/utils/sui-types.js.map +2 -2
- package/dist/esm/version.d.ts +2 -2
- package/dist/esm/version.js +2 -2
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/transactions/plugins/NamedPackagesPlugin.ts +118 -62
- package/src/transactions/plugins/utils.ts +115 -47
- package/src/utils/sui-types.ts +6 -2
- package/src/version.ts +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/transactions/plugins/utils.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { isValidNamedPackage, isValidNamedType } from '../../utils/move-registry.js';\nimport type { TransactionDataBuilder } from '../TransactionData.js';\n\nexport type NamedPackagesPluginCache = {\n\tpackages: Record<string, string>;\n\ttypes: Record<string, string>;\n};\n\nconst NAME_SEPARATOR = '/';\n\nexport type NameResolutionRequest = {\n\tid: number;\n\ttype: 'package' | 'moveType';\n\tname: string;\n};\n\n/**\n * Looks up all `.move` names in a transaction block.\n * Returns a list of all the names found.\n */\nexport
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,2BAAsD;
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { isValidNamedPackage, isValidNamedType } from '../../utils/move-registry.js';\nimport { normalizeStructTag, parseStructTag } from '../../utils/sui-types.js';\nimport type { StructTag } from '../../utils/sui-types.js';\nimport type { TransactionDataBuilder } from '../TransactionData.js';\n\nexport type NamedPackagesPluginCache = {\n\tpackages: Record<string, string>;\n\ttypes: Record<string, string>;\n};\n\nconst NAME_SEPARATOR = '/';\n\nexport type NameResolutionRequest = {\n\tid: number;\n\ttype: 'package' | 'moveType';\n\tname: string;\n};\n\n/**\n * Looks up all `.move` names in a transaction block.\n * Returns a list of all the names found.\n */\nexport function findNamesInTransaction(builder: TransactionDataBuilder): {\n\tpackages: string[];\n\ttypes: string[];\n} {\n\tconst packages: Set<string> = new Set();\n\tconst types: Set<string> = new Set();\n\n\tfor (const command of builder.commands) {\n\t\tif (command.MakeMoveVec?.type) {\n\t\t\tgetNamesFromTypeList([command.MakeMoveVec.type]).forEach((type) => {\n\t\t\t\ttypes.add(type);\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tif (!('MoveCall' in command)) continue;\n\t\tconst tx = command.MoveCall;\n\n\t\tif (!tx) continue;\n\n\t\tconst pkg = tx.package.split('::')[0];\n\t\tif (hasMvrName(pkg)) {\n\t\t\tif (!isValidNamedPackage(pkg)) throw new Error(`Invalid package name: ${pkg}`);\n\t\t\tpackages.add(pkg);\n\t\t}\n\n\t\tgetNamesFromTypeList(tx.typeArguments ?? []).forEach((type) => {\n\t\t\ttypes.add(type);\n\t\t});\n\t}\n\n\treturn {\n\t\tpackages: [...packages],\n\t\ttypes: [...types],\n\t};\n}\n\n/**\n * Extracts all first-level types from a list of types.\n * E.g. for the input `['@mvr/demo::a::A<@mvr/demo::b::B>']`,\n * the output will be `['@mvr/demo::a::A', '@mvr/demo::b::B']`.\n */\nexport function getFirstLevelNamedTypes(types: string[]) {\n\tconst results: Set<string> = new Set();\n\n\tfor (const type of types) {\n\t\tfindMvrNames(type).forEach((name) => results.add(name));\n\t}\n\n\treturn results;\n}\n\n/**\n * Extracts all named types from a given type.\n */\nfunction findMvrNames(type: string | StructTag) {\n\tconst types: Set<string> = new Set();\n\n\tif (typeof type === 'string' && !hasMvrName(type)) return types;\n\n\tlet tag = isStructTag(type) ? type : parseStructTag(type);\n\n\tif (hasMvrName(tag.address)) types.add(`${tag.address}::${tag.module}::${tag.name}`);\n\n\tfor (const param of tag.typeParams) {\n\t\tfindMvrNames(param).forEach((name) => types.add(name));\n\t}\n\n\treturn types;\n}\n\n// /**\n// * Allows partial replacements of known types with their resolved equivalents.\n// * E.g. `@mvr/demo::a::A<@mvr/demo::b::B>` can be resolved, if we already have\n// * the address for `@mvr/demo::b::B` and the address for `@mvr/demo::a::A`,\n// * without the need to have the full type in the cache.\n// *\n// * Returns the fully composed resolved types (if any) in a `named-type -> normalized-type` map.\n// */\nexport function populateNamedTypesFromCache(types: string[], typeCache: Record<string, string>) {\n\tconst composedTypes: Record<string, string> = {};\n\n\ttypes.forEach((type) => {\n\t\tconst normalized = normalizeStructTag(findAndReplaceCachedTypes(type, typeCache));\n\t\tcomposedTypes[type] = normalized;\n\t});\n\n\treturn composedTypes;\n}\n\n/**\n * Traverses a type, and replaces any found names with their resolved equivalents,\n * based on the supplied type cache.\n */\nfunction findAndReplaceCachedTypes(\n\ttag: string | StructTag,\n\ttypeCache: Record<string, string>,\n): StructTag {\n\tconst type = isStructTag(tag) ? tag : parseStructTag(tag);\n\n\tlet typeTag = `${type.address}::${type.module}::${type.name}`;\n\tconst cacheHit = typeCache[typeTag];\n\n\treturn {\n\t\t...type,\n\t\taddress: cacheHit ? cacheHit.split('::')[0] : type.address,\n\t\ttypeParams: type.typeParams.map((param) => findAndReplaceCachedTypes(param, typeCache)),\n\t};\n}\n\n/**\n * Replace all names & types in a transaction block\n * with their resolved names/types.\n */\nexport function replaceNames(builder: TransactionDataBuilder, cache: NamedPackagesPluginCache) {\n\tfor (const command of builder.commands) {\n\t\t// Replacements for `MakeMoveVec` commands (that can include types)\n\t\tif (command.MakeMoveVec?.type) {\n\t\t\tif (!hasMvrName(command.MakeMoveVec.type)) continue;\n\t\t\tif (!cache.types[command.MakeMoveVec.type])\n\t\t\t\tthrow new Error(`No resolution found for type: ${command.MakeMoveVec.type}`);\n\t\t\tcommand.MakeMoveVec.type = cache.types[command.MakeMoveVec.type];\n\t\t}\n\t\t// Replacements for `MoveCall` commands (that can include packages & types)\n\t\tconst tx = command.MoveCall;\n\t\tif (!tx) continue;\n\n\t\tconst nameParts = tx.package.split('::');\n\t\tconst name = nameParts[0];\n\n\t\tif (hasMvrName(name) && !cache.packages[name])\n\t\t\tthrow new Error(`No address found for package: ${name}`);\n\n\t\t// Replace package name with address.\n\t\tif (hasMvrName(name)) {\n\t\t\tnameParts[0] = cache.packages[name];\n\t\t\ttx.package = nameParts.join('::');\n\t\t}\n\n\t\tconst types = tx.typeArguments;\n\t\tif (!types) continue;\n\n\t\tfor (let i = 0; i < types.length; i++) {\n\t\t\tif (!hasMvrName(types[i])) continue;\n\n\t\t\tif (!cache.types[types[i]]) throw new Error(`No resolution found for type: ${types[i]}`);\n\t\t\ttypes[i] = cache.types[types[i]];\n\t\t}\n\n\t\ttx.typeArguments = types;\n\t}\n}\n\nexport function batch<T>(arr: T[], size: number): T[][] {\n\tconst batches = [];\n\tfor (let i = 0; i < arr.length; i += size) {\n\t\tbatches.push(arr.slice(i, i + size));\n\t}\n\treturn batches;\n}\n\n/**\n * Returns a list of unique types that include a name\n * from the given list. This list is retrieved from the Transaction Data.\n */\nfunction getNamesFromTypeList(types: string[]) {\n\tconst names = new Set<string>();\n\tfor (const type of types) {\n\t\tif (hasMvrName(type)) {\n\t\t\tif (!isValidNamedType(type)) throw new Error(`Invalid type with names: ${type}`);\n\t\t\tnames.add(type);\n\t\t}\n\t}\n\treturn names;\n}\n\nfunction hasMvrName(nameOrType: string) {\n\treturn (\n\t\tnameOrType.includes(NAME_SEPARATOR) || nameOrType.includes('@') || nameOrType.includes('.sui')\n\t);\n}\n\nfunction isStructTag(type: string | StructTag): type is StructTag {\n\treturn (\n\t\ttypeof type === 'object' &&\n\t\t'address' in type &&\n\t\t'module' in type &&\n\t\t'name' in type &&\n\t\t'typeParams' in type\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,2BAAsD;AACtD,uBAAmD;AASnD,MAAM,iBAAiB;AAYhB,SAAS,uBAAuB,SAGrC;AACD,QAAM,WAAwB,oBAAI,I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
|
export declare const SUI_ADDRESS_LENGTH = 32;
|
|
4
4
|
export declare function isValidSuiAddress(value: string): value is string;
|
|
5
5
|
export declare function isValidSuiObjectId(value: string): boolean;
|
|
6
|
-
type StructTag = {
|
|
6
|
+
export type StructTag = {
|
|
7
7
|
address: string;
|
|
8
8
|
module: string;
|
|
9
9
|
name: string;
|
|
@@ -24,4 +24,3 @@ export declare function normalizeStructTag(type: string | StructTag): string;
|
|
|
24
24
|
*/
|
|
25
25
|
export declare function normalizeSuiAddress(value: string, forceAdd0x?: boolean): string;
|
|
26
26
|
export declare function normalizeSuiObjectId(value: string, forceAdd0x?: boolean): string;
|
|
27
|
-
export {};
|
|
@@ -29,6 +29,7 @@ __export(sui_types_exports, {
|
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(sui_types_exports);
|
|
31
31
|
var import_bcs = require("@mysten/bcs");
|
|
32
|
+
var import_move_registry = require("./move-registry.js");
|
|
32
33
|
const TX_DIGEST_LENGTH = 32;
|
|
33
34
|
function isValidTransactionDigest(value) {
|
|
34
35
|
try {
|
|
@@ -51,13 +52,14 @@ function parseTypeTag(type) {
|
|
|
51
52
|
}
|
|
52
53
|
function parseStructTag(type) {
|
|
53
54
|
const [address, module2] = type.split("::");
|
|
55
|
+
const isMvrPackage = (0, import_move_registry.isValidNamedPackage)(address);
|
|
54
56
|
const rest = type.slice(address.length + module2.length + 4);
|
|
55
57
|
const name = rest.includes("<") ? rest.slice(0, rest.indexOf("<")) : rest;
|
|
56
58
|
const typeParams = rest.includes("<") ? (0, import_bcs.splitGenericParameters)(rest.slice(rest.indexOf("<") + 1, rest.lastIndexOf(">"))).map(
|
|
57
59
|
(typeParam) => parseTypeTag(typeParam.trim())
|
|
58
60
|
) : [];
|
|
59
61
|
return {
|
|
60
|
-
address: normalizeSuiAddress(address),
|
|
62
|
+
address: isMvrPackage ? address : normalizeSuiAddress(address),
|
|
61
63
|
module: module2,
|
|
62
64
|
name,
|
|
63
65
|
typeParams
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/utils/sui-types.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase58, splitGenericParameters } from '@mysten/bcs';\n\nconst TX_DIGEST_LENGTH = 32;\n\n/** Returns whether the tx digest is valid based on the serialization format */\nexport function isValidTransactionDigest(value: string): value is string {\n\ttry {\n\t\tconst buffer = fromBase58(value);\n\t\treturn buffer.length === TX_DIGEST_LENGTH;\n\t} catch (e) {\n\t\treturn false;\n\t}\n}\n\n// TODO - can we automatically sync this with rust length definition?\n// Source of truth is\n// https://github.com/MystenLabs/sui/blob/acb2b97ae21f47600e05b0d28127d88d0725561d/crates/sui-types/src/base_types.rs#L67\n// which uses the Move account address length\n// https://github.com/move-language/move/blob/67ec40dc50c66c34fd73512fcc412f3b68d67235/language/move-core/types/src/account_address.rs#L23 .\n\nexport const SUI_ADDRESS_LENGTH = 32;\nexport function isValidSuiAddress(value: string): value is string {\n\treturn isHex(value) && getHexByteLength(value) === SUI_ADDRESS_LENGTH;\n}\n\nexport function isValidSuiObjectId(value: string): boolean {\n\treturn isValidSuiAddress(value);\n}\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAmD;AAEnD,MAAM,mBAAmB;AAGlB,SAAS,yBAAyB,OAAgC;AACxE,MAAI;AACH,UAAM,aAAS,uBAAW,KAAK;AAC/B,WAAO,OAAO,WAAW;AAAA,EAC1B,SAAS,GAAG;AACX,WAAO;AAAA,EACR;AACD;AAQO,MAAM,qBAAqB;AAC3B,SAAS,kBAAkB,OAAgC;AACjE,SAAO,MAAM,KAAK,KAAK,iBAAiB,KAAK,MAAM;AACpD;AAEO,SAAS,mBAAmB,OAAwB;AAC1D,SAAO,kBAAkB,KAAK;AAC/B;AASA,SAAS,aAAa,MAAkC;AACvD,MAAI,CAAC,KAAK,SAAS,IAAI,EAAG,QAAO;AAEjC,SAAO,eAAe,IAAI;AAC3B;AAEO,SAAS,eAAe,MAAyB;AACvD,QAAM,CAAC,SAASA,OAAM,IAAI,KAAK,MAAM,IAAI;AAEzC,QAAM,OAAO,KAAK,MAAM,QAAQ,SAASA,QAAO,SAAS,CAAC;AAC1D,QAAM,OAAO,KAAK,SAAS,GAAG,IAAI,KAAK,MAAM,GAAG,KAAK,QAAQ,GAAG,CAAC,IAAI;AACrE,QAAM,aAAa,KAAK,SAAS,GAAG,QACjC,mCAAuB,KAAK,MAAM,KAAK,QAAQ,GAAG,IAAI,GAAG,KAAK,YAAY,GAAG,CAAC,CAAC,EAAE;AAAA,IACjF,CAAC,cAAc,aAAa,UAAU,KAAK,CAAC;AAAA,EAC7C,IACC,CAAC;AAEJ,SAAO;AAAA,IACN,SAAS,oBAAoB,OAAO;AAAA,
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase58, splitGenericParameters } from '@mysten/bcs';\n\nimport { isValidNamedPackage } from './move-registry.js';\n\nconst TX_DIGEST_LENGTH = 32;\n\n/** Returns whether the tx digest is valid based on the serialization format */\nexport function isValidTransactionDigest(value: string): value is string {\n\ttry {\n\t\tconst buffer = fromBase58(value);\n\t\treturn buffer.length === TX_DIGEST_LENGTH;\n\t} catch (e) {\n\t\treturn false;\n\t}\n}\n\n// TODO - can we automatically sync this with rust length definition?\n// Source of truth is\n// https://github.com/MystenLabs/sui/blob/acb2b97ae21f47600e05b0d28127d88d0725561d/crates/sui-types/src/base_types.rs#L67\n// which uses the Move account address length\n// https://github.com/move-language/move/blob/67ec40dc50c66c34fd73512fcc412f3b68d67235/language/move-core/types/src/account_address.rs#L23 .\n\nexport const SUI_ADDRESS_LENGTH = 32;\nexport function isValidSuiAddress(value: string): value is string {\n\treturn isHex(value) && getHexByteLength(value) === SUI_ADDRESS_LENGTH;\n}\n\nexport function isValidSuiObjectId(value: string): boolean {\n\treturn isValidSuiAddress(value);\n}\n\nexport type StructTag = {\n\taddress: string;\n\tmodule: string;\n\tname: string;\n\ttypeParams: (string | StructTag)[];\n};\n\nfunction parseTypeTag(type: string): string | StructTag {\n\tif (!type.includes('::')) return type;\n\n\treturn parseStructTag(type);\n}\n\nexport function parseStructTag(type: string): StructTag {\n\tconst [address, module] = type.split('::');\n\n\tconst isMvrPackage = isValidNamedPackage(address);\n\n\tconst rest = type.slice(address.length + module.length + 4);\n\tconst name = rest.includes('<') ? rest.slice(0, rest.indexOf('<')) : rest;\n\tconst typeParams = rest.includes('<')\n\t\t? splitGenericParameters(rest.slice(rest.indexOf('<') + 1, rest.lastIndexOf('>'))).map(\n\t\t\t\t(typeParam) => parseTypeTag(typeParam.trim()),\n\t\t\t)\n\t\t: [];\n\n\treturn {\n\t\taddress: isMvrPackage ? address : normalizeSuiAddress(address),\n\t\tmodule,\n\t\tname,\n\t\ttypeParams,\n\t};\n}\n\nexport function normalizeStructTag(type: string | StructTag): string {\n\tconst { address, module, name, typeParams } =\n\t\ttypeof type === 'string' ? parseStructTag(type) : type;\n\n\tconst formattedTypeParams =\n\t\ttypeParams?.length > 0\n\t\t\t? `<${typeParams\n\t\t\t\t\t.map((typeParam) =>\n\t\t\t\t\t\ttypeof typeParam === 'string' ? typeParam : normalizeStructTag(typeParam),\n\t\t\t\t\t)\n\t\t\t\t\t.join(',')}>`\n\t\t\t: '';\n\n\treturn `${address}::${module}::${name}${formattedTypeParams}`;\n}\n\n/**\n * Perform the following operations:\n * 1. Make the address lower case\n * 2. Prepend `0x` if the string does not start with `0x`.\n * 3. Add more zeros if the length of the address(excluding `0x`) is less than `SUI_ADDRESS_LENGTH`\n *\n * WARNING: if the address value itself starts with `0x`, e.g., `0x0x`, the default behavior\n * is to treat the first `0x` not as part of the address. The default behavior can be overridden by\n * setting `forceAdd0x` to true\n *\n */\nexport function normalizeSuiAddress(value: string, forceAdd0x: boolean = false): string {\n\tlet address = value.toLowerCase();\n\tif (!forceAdd0x && address.startsWith('0x')) {\n\t\taddress = address.slice(2);\n\t}\n\treturn `0x${address.padStart(SUI_ADDRESS_LENGTH * 2, '0')}`;\n}\n\nexport function normalizeSuiObjectId(value: string, forceAdd0x: boolean = false): string {\n\treturn normalizeSuiAddress(value, forceAdd0x);\n}\n\nfunction isHex(value: string): boolean {\n\treturn /^(0x|0X)?[a-fA-F0-9]+$/.test(value) && value.length % 2 === 0;\n}\n\nfunction getHexByteLength(value: string): number {\n\treturn /^(0x|0X)/.test(value) ? (value.length - 2) / 2 : value.length / 2;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAmD;AAEnD,2BAAoC;AAEpC,MAAM,mBAAmB;AAGlB,SAAS,yBAAyB,OAAgC;AACxE,MAAI;AACH,UAAM,aAAS,uBAAW,KAAK;AAC/B,WAAO,OAAO,WAAW;AAAA,EAC1B,SAAS,GAAG;AACX,WAAO;AAAA,EACR;AACD;AAQO,MAAM,qBAAqB;AAC3B,SAAS,kBAAkB,OAAgC;AACjE,SAAO,MAAM,KAAK,KAAK,iBAAiB,KAAK,MAAM;AACpD;AAEO,SAAS,mBAAmB,OAAwB;AAC1D,SAAO,kBAAkB,KAAK;AAC/B;AASA,SAAS,aAAa,MAAkC;AACvD,MAAI,CAAC,KAAK,SAAS,IAAI,EAAG,QAAO;AAEjC,SAAO,eAAe,IAAI;AAC3B;AAEO,SAAS,eAAe,MAAyB;AACvD,QAAM,CAAC,SAASA,OAAM,IAAI,KAAK,MAAM,IAAI;AAEzC,QAAM,mBAAe,0CAAoB,OAAO;AAEhD,QAAM,OAAO,KAAK,MAAM,QAAQ,SAASA,QAAO,SAAS,CAAC;AAC1D,QAAM,OAAO,KAAK,SAAS,GAAG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names": ["module"]
|
|
7
7
|
}
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const PACKAGE_VERSION = "1.
|
|
2
|
-
export declare const TARGETED_RPC_VERSION = "1.
|
|
1
|
+
export declare const PACKAGE_VERSION = "1.25.0";
|
|
2
|
+
export declare const TARGETED_RPC_VERSION = "1.46.0";
|
package/dist/cjs/version.js
CHANGED
|
@@ -22,6 +22,6 @@ __export(version_exports, {
|
|
|
22
22
|
TARGETED_RPC_VERSION: () => TARGETED_RPC_VERSION
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(version_exports);
|
|
25
|
-
const PACKAGE_VERSION = "1.
|
|
26
|
-
const TARGETED_RPC_VERSION = "1.
|
|
25
|
+
const PACKAGE_VERSION = "1.25.0";
|
|
26
|
+
const TARGETED_RPC_VERSION = "1.46.0";
|
|
27
27
|
//# sourceMappingURL=version.js.map
|
package/dist/cjs/version.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/version.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n// This file is generated by genversion.mjs. Do not edit it directly.\n\nexport const PACKAGE_VERSION = '1.
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n// This file is generated by genversion.mjs. Do not edit it directly.\n\nexport const PACKAGE_VERSION = '1.25.0';\nexport const TARGETED_RPC_VERSION = '1.46.0';\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,MAAM,kBAAkB;AACxB,MAAM,uBAAuB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -25,8 +25,8 @@ export declare const Arguments: {
|
|
|
25
25
|
type?: "object";
|
|
26
26
|
};
|
|
27
27
|
objectRef: (args_0: {
|
|
28
|
-
objectId: string;
|
|
29
28
|
version: string | number;
|
|
29
|
+
objectId: string;
|
|
30
30
|
digest: string;
|
|
31
31
|
}) => (tx: Transaction) => {
|
|
32
32
|
$kind: "Input";
|
|
@@ -34,8 +34,8 @@ export declare const Arguments: {
|
|
|
34
34
|
type?: "object";
|
|
35
35
|
};
|
|
36
36
|
receivingRef: (args_0: {
|
|
37
|
-
objectId: string;
|
|
38
37
|
version: string | number;
|
|
38
|
+
objectId: string;
|
|
39
39
|
digest: string;
|
|
40
40
|
}) => (tx: Transaction) => {
|
|
41
41
|
$kind: "Input";
|
|
@@ -290,8 +290,8 @@ export declare class Transaction {
|
|
|
290
290
|
})[];
|
|
291
291
|
gasConfig: {
|
|
292
292
|
payment?: {
|
|
293
|
-
objectId: string;
|
|
294
293
|
version: string | number | bigint;
|
|
294
|
+
objectId: string;
|
|
295
295
|
digest: string;
|
|
296
296
|
}[] | undefined;
|
|
297
297
|
owner?: string | undefined;
|
|
@@ -311,8 +311,8 @@ export declare class Transaction {
|
|
|
311
311
|
inputs: import("@mysten/bcs").EnumOutputShapeWithKeys<{
|
|
312
312
|
Object: import("@mysten/bcs").EnumOutputShapeWithKeys<{
|
|
313
313
|
ImmOrOwnedObject: {
|
|
314
|
-
objectId: string;
|
|
315
314
|
version: string | number;
|
|
315
|
+
objectId: string;
|
|
316
316
|
digest: string;
|
|
317
317
|
};
|
|
318
318
|
SharedObject: {
|
|
@@ -321,8 +321,8 @@ export declare class Transaction {
|
|
|
321
321
|
mutable: boolean;
|
|
322
322
|
};
|
|
323
323
|
Receiving: {
|
|
324
|
-
objectId: string;
|
|
325
324
|
version: string | number;
|
|
325
|
+
objectId: string;
|
|
326
326
|
digest: string;
|
|
327
327
|
};
|
|
328
328
|
}, "ImmOrOwnedObject" | "SharedObject" | "Receiving">;
|
|
@@ -576,8 +576,8 @@ export declare class Transaction {
|
|
|
576
576
|
}, "MoveCall" | "TransferObjects" | "SplitCoins" | "MergeCoins" | "Publish" | "MakeMoveVec" | "Upgrade" | "$Intent">[];
|
|
577
577
|
gasData: {
|
|
578
578
|
payment: {
|
|
579
|
-
objectId: string;
|
|
580
579
|
version: string | number;
|
|
580
|
+
objectId: string;
|
|
581
581
|
digest: string;
|
|
582
582
|
}[] | null;
|
|
583
583
|
owner: string | null;
|
|
@@ -16,8 +16,8 @@ export declare class TransactionDataBuilder implements TransactionData {
|
|
|
16
16
|
static getDigestFromBytes(bytes: Uint8Array): string;
|
|
17
17
|
get gasConfig(): {
|
|
18
18
|
payment: {
|
|
19
|
-
objectId: string;
|
|
20
19
|
version: string | number;
|
|
20
|
+
objectId: string;
|
|
21
21
|
digest: string;
|
|
22
22
|
}[] | null;
|
|
23
23
|
owner: string | null;
|
|
@@ -26,8 +26,8 @@ export declare class TransactionDataBuilder implements TransactionData {
|
|
|
26
26
|
};
|
|
27
27
|
set gasConfig(value: {
|
|
28
28
|
payment: {
|
|
29
|
-
objectId: string;
|
|
30
29
|
version: string | number;
|
|
30
|
+
objectId: string;
|
|
31
31
|
digest: string;
|
|
32
32
|
}[] | null;
|
|
33
33
|
owner: string | null;
|
|
@@ -9,8 +9,8 @@ export declare const ObjectRef: import("valibot").ObjectSchema<{
|
|
|
9
9
|
export declare const NormalizedCallArg: GenericSchema<import("@mysten/bcs").EnumInputShape<{
|
|
10
10
|
Object: import("@mysten/bcs").EnumInputShape<{
|
|
11
11
|
ImmOrOwned: {
|
|
12
|
-
objectId: string;
|
|
13
12
|
version: string | number | bigint;
|
|
13
|
+
objectId: string;
|
|
14
14
|
digest: string;
|
|
15
15
|
};
|
|
16
16
|
Shared: {
|
|
@@ -19,8 +19,8 @@ export declare const NormalizedCallArg: GenericSchema<import("@mysten/bcs").Enum
|
|
|
19
19
|
mutable: boolean;
|
|
20
20
|
};
|
|
21
21
|
Receiving: {
|
|
22
|
-
objectId: string;
|
|
23
22
|
version: string | number | bigint;
|
|
23
|
+
objectId: string;
|
|
24
24
|
digest: string;
|
|
25
25
|
};
|
|
26
26
|
}>;
|
|
@@ -28,8 +28,8 @@ export declare const NormalizedCallArg: GenericSchema<import("@mysten/bcs").Enum
|
|
|
28
28
|
}>, import("@mysten/bcs").EnumOutputShapeWithKeys<{
|
|
29
29
|
Object: import("@mysten/bcs").EnumOutputShapeWithKeys<{
|
|
30
30
|
ImmOrOwned: {
|
|
31
|
-
objectId: string;
|
|
32
31
|
version: string | number | bigint;
|
|
32
|
+
objectId: string;
|
|
33
33
|
digest: string;
|
|
34
34
|
};
|
|
35
35
|
Shared: {
|
|
@@ -38,8 +38,8 @@ export declare const NormalizedCallArg: GenericSchema<import("@mysten/bcs").Enum
|
|
|
38
38
|
mutable: boolean;
|
|
39
39
|
};
|
|
40
40
|
Receiving: {
|
|
41
|
-
objectId: string;
|
|
42
41
|
version: string | number | bigint;
|
|
42
|
+
objectId: string;
|
|
43
43
|
digest: string;
|
|
44
44
|
};
|
|
45
45
|
}, "Receiving" | "Shared" | "ImmOrOwned">;
|
|
@@ -23,8 +23,8 @@ export declare const SerializedTransactionDataV2: import("valibot").ObjectSchema
|
|
|
23
23
|
readonly inputs: import("valibot").ArraySchema<GenericSchema<EnumInputShape<{
|
|
24
24
|
Object: EnumInputShape<{
|
|
25
25
|
ImmOrOwnedObject: {
|
|
26
|
-
objectId: string;
|
|
27
26
|
version: string | number;
|
|
27
|
+
objectId: string;
|
|
28
28
|
digest: string;
|
|
29
29
|
};
|
|
30
30
|
SharedObject: {
|
|
@@ -33,8 +33,8 @@ export declare const SerializedTransactionDataV2: import("valibot").ObjectSchema
|
|
|
33
33
|
mutable: boolean;
|
|
34
34
|
};
|
|
35
35
|
Receiving: {
|
|
36
|
-
objectId: string;
|
|
37
36
|
version: string | number;
|
|
37
|
+
objectId: string;
|
|
38
38
|
digest: string;
|
|
39
39
|
};
|
|
40
40
|
}>;
|
|
@@ -53,8 +53,8 @@ export declare const SerializedTransactionDataV2: import("valibot").ObjectSchema
|
|
|
53
53
|
}>, EnumInputShape<{
|
|
54
54
|
Object: EnumInputShape<{
|
|
55
55
|
ImmOrOwnedObject: {
|
|
56
|
-
objectId: string;
|
|
57
56
|
version: string | number;
|
|
57
|
+
objectId: string;
|
|
58
58
|
digest: string;
|
|
59
59
|
};
|
|
60
60
|
SharedObject: {
|
|
@@ -63,8 +63,8 @@ export declare const SerializedTransactionDataV2: import("valibot").ObjectSchema
|
|
|
63
63
|
mutable: boolean;
|
|
64
64
|
};
|
|
65
65
|
Receiving: {
|
|
66
|
-
objectId: string;
|
|
67
66
|
version: string | number;
|
|
67
|
+
objectId: string;
|
|
68
68
|
digest: string;
|
|
69
69
|
};
|
|
70
70
|
}>;
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import type { SuiGraphQLClient } from '../../graphql/client.js';
|
|
2
1
|
import type { BuildTransactionOptions } from '../json-rpc-resolver.js';
|
|
3
2
|
import type { TransactionDataBuilder } from '../TransactionData.js';
|
|
4
3
|
import type { NamedPackagesPluginCache } from './utils.js';
|
|
5
4
|
export type NamedPackagesPluginOptions = {
|
|
6
5
|
/**
|
|
7
|
-
* The
|
|
8
|
-
* The endpoint should be the GraphQL endpoint of the network you are targeting.
|
|
9
|
-
* For non-mainnet networks, if the plugin doesn't work as expected, you need to validate that the
|
|
10
|
-
* RPC provider has support for the `packageByName` and `typeByName` queries (using external resolver).
|
|
6
|
+
* The URL of the MVR API to use for resolving names.
|
|
11
7
|
*/
|
|
12
|
-
|
|
8
|
+
url: string;
|
|
13
9
|
/**
|
|
14
10
|
* The number of names to resolve in each batch request.
|
|
15
11
|
* Needs to be calculated based on the GraphQL query limits.
|
|
@@ -19,6 +15,8 @@ export type NamedPackagesPluginOptions = {
|
|
|
19
15
|
* Local overrides for the resolution plugin. Pass this to pre-populate
|
|
20
16
|
* the cache with known packages / types (especially useful for local or CI testing).
|
|
21
17
|
*
|
|
18
|
+
* The type cache expects ONLY first-level types to ensure the cache is more composable.
|
|
19
|
+
*
|
|
22
20
|
* Expected format example:
|
|
23
21
|
* {
|
|
24
22
|
* packages: {
|
|
@@ -46,4 +44,4 @@ export type NamedPackagesPluginOptions = {
|
|
|
46
44
|
*
|
|
47
45
|
* You can also define `overrides` to pre-populate name resolutions locally (removes the GraphQL request).
|
|
48
46
|
*/
|
|
49
|
-
export declare const namedPackagesPlugin: ({
|
|
47
|
+
export declare const namedPackagesPlugin: ({ url, pageSize, overrides, }: NamedPackagesPluginOptions) => (transactionData: TransactionDataBuilder, _buildOptions: BuildTransactionOptions, next: () => Promise<void>) => Promise<void>;
|
|
@@ -1,57 +1,104 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { parseStructTag } from "../../utils/sui-types.js";
|
|
2
|
+
import {
|
|
3
|
+
batch,
|
|
4
|
+
findNamesInTransaction,
|
|
5
|
+
getFirstLevelNamedTypes,
|
|
6
|
+
populateNamedTypesFromCache,
|
|
7
|
+
replaceNames
|
|
8
|
+
} from "./utils.js";
|
|
2
9
|
const namedPackagesPlugin = ({
|
|
3
|
-
|
|
4
|
-
pageSize =
|
|
10
|
+
url,
|
|
11
|
+
pageSize = 50,
|
|
5
12
|
overrides = { packages: {}, types: {} }
|
|
6
13
|
}) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
Object.keys(overrides.types).forEach((type) => {
|
|
15
|
+
if (parseStructTag(type).typeParams.length > 0)
|
|
16
|
+
throw new Error(
|
|
17
|
+
"Type overrides must be first-level only. If you want to supply generic types, just pass each type individually."
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
const cache = overrides;
|
|
11
21
|
return async (transactionData, _buildOptions, next) => {
|
|
12
|
-
const names =
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
const names = findNamesInTransaction(transactionData);
|
|
23
|
+
const [packages, types] = await Promise.all([
|
|
24
|
+
resolvePackages(
|
|
25
|
+
names.packages.filter((x) => !cache.packages[x]),
|
|
26
|
+
url,
|
|
27
|
+
pageSize
|
|
28
|
+
),
|
|
29
|
+
resolveTypes(
|
|
30
|
+
[...getFirstLevelNamedTypes(names.types)].filter((x) => !cache.types[x]),
|
|
31
|
+
url,
|
|
32
|
+
pageSize
|
|
33
|
+
)
|
|
34
|
+
]);
|
|
35
|
+
Object.assign(cache.packages, packages);
|
|
36
|
+
Object.assign(cache.types, types);
|
|
37
|
+
const composedTypes = populateNamedTypesFromCache(names.types, cache.types);
|
|
38
|
+
replaceNames(transactionData, {
|
|
39
|
+
packages: { ...cache.packages },
|
|
40
|
+
// we include the "composed" type cache too.
|
|
41
|
+
types: composedTypes
|
|
23
42
|
});
|
|
24
|
-
replaceNames(transactionData, cache);
|
|
25
43
|
await next();
|
|
26
44
|
};
|
|
27
|
-
async function
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
async function resolvePackages(packages, apiUrl, pageSize2) {
|
|
46
|
+
if (packages.length === 0) return {};
|
|
47
|
+
const batches = batch(packages, pageSize2);
|
|
48
|
+
const results = {};
|
|
49
|
+
await Promise.all(
|
|
50
|
+
batches.map(async (batch2) => {
|
|
51
|
+
const response = await fetch(`${apiUrl}/v1/resolution/bulk`, {
|
|
52
|
+
method: "POST",
|
|
53
|
+
headers: { "Content-Type": "application/json" },
|
|
54
|
+
body: JSON.stringify({
|
|
55
|
+
names: batch2
|
|
56
|
+
})
|
|
57
|
+
});
|
|
58
|
+
if (!response.ok) {
|
|
59
|
+
const errorBody = await response.json().catch(() => ({}));
|
|
60
|
+
throw new Error(`Failed to resolve packages: ${errorBody?.message}`);
|
|
61
|
+
}
|
|
62
|
+
const data = await response.json();
|
|
63
|
+
if (!data?.resolution) return;
|
|
64
|
+
for (const pkg of Object.keys(data?.resolution)) {
|
|
65
|
+
const pkgData = data.resolution[pkg]?.package_id;
|
|
66
|
+
if (!pkgData) continue;
|
|
67
|
+
results[pkg] = pkgData;
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
);
|
|
71
|
+
return results;
|
|
72
|
+
}
|
|
73
|
+
async function resolveTypes(types, apiUrl, pageSize2) {
|
|
74
|
+
if (types.length === 0) return {};
|
|
75
|
+
const batches = batch(types, pageSize2);
|
|
76
|
+
const results = {};
|
|
77
|
+
await Promise.all(
|
|
78
|
+
batches.map(async (batch2) => {
|
|
79
|
+
const response = await fetch(`${apiUrl}/v1/struct-definition/bulk`, {
|
|
80
|
+
method: "POST",
|
|
81
|
+
headers: { "Content-Type": "application/json" },
|
|
82
|
+
body: JSON.stringify({
|
|
83
|
+
types: batch2
|
|
84
|
+
})
|
|
85
|
+
});
|
|
86
|
+
if (!response.ok) {
|
|
87
|
+
const errorBody = await response.json().catch(() => ({}));
|
|
88
|
+
throw new Error(`Failed to resolve types: ${errorBody?.message}`);
|
|
89
|
+
}
|
|
90
|
+
const data = await response.json();
|
|
91
|
+
if (!data?.resolution) return;
|
|
92
|
+
for (const type of Object.keys(data?.resolution)) {
|
|
93
|
+
const typeData = data.resolution[type]?.type_tag;
|
|
94
|
+
if (!typeData) continue;
|
|
95
|
+
results[type] = typeData;
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
);
|
|
51
99
|
return results;
|
|
52
100
|
}
|
|
53
101
|
};
|
|
54
|
-
const gqlQueryKey = (idx) => `key_${idx}`;
|
|
55
102
|
export {
|
|
56
103
|
namedPackagesPlugin
|
|
57
104
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/transactions/plugins/NamedPackagesPlugin.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { parseStructTag } from '../../utils/sui-types.js';\nimport type { BuildTransactionOptions } from '../json-rpc-resolver.js';\nimport type { TransactionDataBuilder } from '../TransactionData.js';\nimport type { NamedPackagesPluginCache } from './utils.js';\nimport {\n\tbatch,\n\tfindNamesInTransaction,\n\tgetFirstLevelNamedTypes,\n\tpopulateNamedTypesFromCache,\n\treplaceNames,\n} from './utils.js';\n\nexport type NamedPackagesPluginOptions = {\n\t/**\n\t * The URL of the MVR API to use for resolving names.\n\t */\n\turl: string;\n\t/**\n\t * The number of names to resolve in each batch request.\n\t * Needs to be calculated based on the GraphQL query limits.\n\t */\n\tpageSize?: number;\n\t/**\n\t * Local overrides for the resolution plugin. Pass this to pre-populate\n\t * the cache with known packages / types (especially useful for local or CI testing).\n\t *\n\t * The type cache expects ONLY first-level types to ensure the cache is more composable.\n\t *\n\t * \tExpected format example:\n\t * {\n\t * \t\tpackages: {\n\t * \t\t\t'@framework/std': '0x1234',\n\t * \t\t},\n\t * \t\ttypes: {\n\t * \t\t\t'@framework/std::string::String': '0x1234::string::String',\n\t * \t\t},\n\t * \t}\n\t *\n\t */\n\toverrides?: NamedPackagesPluginCache;\n};\n\n/**\n * @experimental This plugin is in experimental phase and there might be breaking changes in the future\n *\n * Adds named resolution so that you can use .move names in your transactions.\n * e.g. `@org/app::type::Type` will be resolved to `0x1234::type::Type`.\n * This plugin will resolve all names & types in the transaction block.\n *\n * To install this plugin globally in your app, use:\n * ```\n * Transaction.registerGlobalSerializationPlugin(\"namedPackagesPlugin\", namedPackagesPlugin({ suiGraphQLClient }));\n * ```\n *\n * You can also define `overrides` to pre-populate name resolutions locally (removes the GraphQL request).\n */\nexport const namedPackagesPlugin = ({\n\turl,\n\tpageSize = 50,\n\toverrides = { packages: {}, types: {} },\n}: NamedPackagesPluginOptions) => {\n\t// validate that types are first-level only.\n\tObject.keys(overrides.types).forEach((type) => {\n\t\tif (parseStructTag(type).typeParams.length > 0)\n\t\t\tthrow new Error(\n\t\t\t\t'Type overrides must be first-level only. If you want to supply generic types, just pass each type individually.',\n\t\t\t);\n\t});\n\n\tconst cache = overrides;\n\n\treturn async (\n\t\ttransactionData: TransactionDataBuilder,\n\t\t_buildOptions: BuildTransactionOptions,\n\t\tnext: () => Promise<void>,\n\t) => {\n\t\tconst names = findNamesInTransaction(transactionData);\n\n\t\tconst [packages, types] = await Promise.all([\n\t\t\tresolvePackages(\n\t\t\t\tnames.packages.filter((x) => !cache.packages[x]),\n\t\t\t\turl,\n\t\t\t\tpageSize,\n\t\t\t),\n\t\t\tresolveTypes(\n\t\t\t\t[...getFirstLevelNamedTypes(names.types)].filter((x) => !cache.types[x]),\n\t\t\t\turl,\n\t\t\t\tpageSize,\n\t\t\t),\n\t\t]);\n\n\t\t// save first-level mappings to cache.\n\t\tObject.assign(cache.packages, packages);\n\t\tObject.assign(cache.types, types);\n\n\t\tconst composedTypes = populateNamedTypesFromCache(names.types, cache.types);\n\n\t\t// when replacing names, we also need to replace the \"composed\" types collected above.\n\t\treplaceNames(transactionData, {\n\t\t\tpackages: { ...cache.packages },\n\t\t\t// we include the \"composed\" type cache too.\n\t\t\ttypes: composedTypes,\n\t\t});\n\n\t\tawait next();\n\t};\n\n\tasync function resolvePackages(packages: string[], apiUrl: string, pageSize: number) {\n\t\tif (packages.length === 0) return {};\n\n\t\tconst batches = batch(packages, pageSize);\n\t\tconst results: Record<string, string> = {};\n\n\t\tawait Promise.all(\n\t\t\tbatches.map(async (batch) => {\n\t\t\t\tconst response = await fetch(`${apiUrl}/v1/resolution/bulk`, {\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\theaders: { 'Content-Type': 'application/json' },\n\t\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\t\tnames: batch,\n\t\t\t\t\t}),\n\t\t\t\t});\n\n\t\t\t\tif (!response.ok) {\n\t\t\t\t\tconst errorBody = await response.json().catch(() => ({}));\n\t\t\t\t\tthrow new Error(`Failed to resolve packages: ${errorBody?.message}`);\n\t\t\t\t}\n\n\t\t\t\tconst data = await response.json();\n\n\t\t\t\tif (!data?.resolution) return;\n\n\t\t\t\tfor (const pkg of Object.keys(data?.resolution)) {\n\t\t\t\t\tconst pkgData = data.resolution[pkg]?.package_id;\n\n\t\t\t\t\tif (!pkgData) continue;\n\n\t\t\t\t\tresults[pkg] = pkgData;\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\n\t\treturn results;\n\t}\n\n\tasync function resolveTypes(types: string[], apiUrl: string, pageSize: number) {\n\t\tif (types.length === 0) return {};\n\n\t\tconst batches = batch(types, pageSize);\n\t\tconst results: Record<string, string> = {};\n\n\t\tawait Promise.all(\n\t\t\tbatches.map(async (batch) => {\n\t\t\t\tconst response = await fetch(`${apiUrl}/v1/struct-definition/bulk`, {\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\theaders: { 'Content-Type': 'application/json' },\n\t\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\t\ttypes: batch,\n\t\t\t\t\t}),\n\t\t\t\t});\n\n\t\t\t\tif (!response.ok) {\n\t\t\t\t\tconst errorBody = await response.json().catch(() => ({}));\n\t\t\t\t\tthrow new Error(`Failed to resolve types: ${errorBody?.message}`);\n\t\t\t\t}\n\n\t\t\t\tconst data = await response.json();\n\n\t\t\t\tif (!data?.resolution) return;\n\n\t\t\t\tfor (const type of Object.keys(data?.resolution)) {\n\t\t\t\t\tconst typeData = data.resolution[type]?.type_tag;\n\t\t\t\t\tif (!typeData) continue;\n\n\t\t\t\t\tresults[type] = typeData;\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\n\t\treturn results;\n\t}\n};\n"],
|
|
5
|
+
"m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;AAAA,QACjE;AAEA,cAAM,OAAO,MAAM,SAAS,KAAK;AAEjC,YAAI,CAAC,MAAM,WAAY;AAEvB,mBAAW,QAAQ,OAAO,KAAK,MAAM,UAAU,GAAG;AACjD,gBAAM,WAAW,KAAK,WAAW,IAAI,GAAG;AACxC,cAAI,CAAC,SAAU;AAEf,kBAAQ,IAAI,IAAI;AAAA,QACjB;AAAA,MACD,CAAC;AAAA,IACF;AAEA,WAAO;AAAA,EACR;AACD;",
|
|
6
|
+
"names": ["pageSize", "batch"]
|
|
7
7
|
}
|
|
@@ -12,16 +12,20 @@ export type NameResolutionRequest = {
|
|
|
12
12
|
* Looks up all `.move` names in a transaction block.
|
|
13
13
|
* Returns a list of all the names found.
|
|
14
14
|
*/
|
|
15
|
-
export declare
|
|
15
|
+
export declare function findNamesInTransaction(builder: TransactionDataBuilder): {
|
|
16
16
|
packages: string[];
|
|
17
17
|
types: string[];
|
|
18
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* Extracts all first-level types from a list of types.
|
|
21
|
+
* E.g. for the input `['@mvr/demo::a::A<@mvr/demo::b::B>']`,
|
|
22
|
+
* the output will be `['@mvr/demo::a::A', '@mvr/demo::b::B']`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getFirstLevelNamedTypes(types: string[]): Set<string>;
|
|
25
|
+
export declare function populateNamedTypesFromCache(types: string[], typeCache: Record<string, string>): Record<string, string>;
|
|
19
26
|
/**
|
|
20
27
|
* Replace all names & types in a transaction block
|
|
21
28
|
* with their resolved names/types.
|
|
22
29
|
*/
|
|
23
|
-
export declare
|
|
24
|
-
export declare
|
|
25
|
-
packages: string[];
|
|
26
|
-
types: string[];
|
|
27
|
-
}, batchSize: number) => NameResolutionRequest[][];
|
|
30
|
+
export declare function replaceNames(builder: TransactionDataBuilder, cache: NamedPackagesPluginCache): void;
|
|
31
|
+
export declare function batch<T>(arr: T[], size: number): T[][];
|