@taqueria/plugin-contract-types 0.73.12 → 0.78.10

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.
@@ -110,41 +110,173 @@ export const tas = {
110
110
 
111
111
  // src/type-utils-file-content.ts
112
112
  var typeUtilsFileContent = `
113
- import { ContractAbstraction, ContractMethod, ContractMethodObject, ContractProvider, Wallet } from '@taquito/taquito';
113
+ import { ContractAbstraction, ContractMethodObject, ContractProvider, Wallet } from '@taquito/taquito';
114
114
 
115
- type BaseContractType = { methods: unknown, methodsObject: unknown, storage: unknown };
115
+ // Support both old (methods) and new (methodsObject) contract type definitions
116
+ type BaseContractType = { methodsObject: unknown; storage: unknown; methods?: unknown };
116
117
 
117
- type ContractMethodsOf<T extends ContractProvider | Wallet, TContract extends BaseContractType> = {
118
- [M in keyof TContract['methods']]:
119
- TContract['methods'][M] extends (...args: infer A) => unknown
120
- ? (...args: A) => ContractMethod<T>
121
- : never
122
- };
123
118
  type ContractMethodsObjectsOf<T extends ContractProvider | Wallet, TContract extends BaseContractType> = {
124
- [M in keyof TContract['methodsObject']]:
125
- TContract['methodsObject'][M] extends (...args: infer A) => unknown
126
- ? (...args: A) => ContractMethodObject<T>
127
- : never
119
+ [M in keyof TContract['methodsObject']]: TContract['methodsObject'][M] extends (...args: infer A) => unknown
120
+ ? (...args: A) => ContractMethodObject<T>
121
+ : never;
128
122
  };
129
123
  type ContractStorageOf<TContract extends BaseContractType> = TContract['storage'];
130
124
 
131
- export type ContractAbstractionFromContractType<TContract extends BaseContractType> =
132
- ContractAbstraction<ContractProvider,
133
- ContractMethodsOf<ContractProvider, TContract>,
134
- ContractMethodsObjectsOf<ContractProvider, TContract>,
135
- {},
136
- {},
137
- ContractStorageOf<TContract>
138
- >;
139
-
140
- export type WalletContractAbstractionFromContractType<TContract extends BaseContractType> =
141
- ContractAbstraction<Wallet,
142
- ContractMethodsOf<Wallet, TContract>,
143
- ContractMethodsObjectsOf<Wallet, TContract>,
144
- {},
145
- {},
146
- ContractStorageOf<TContract>
147
- >;
125
+ // Type for the methods proxy - converts positional args to methodsObject call
126
+ type ContractMethodsOf<T extends ContractProvider | Wallet, TContract extends BaseContractType> =
127
+ TContract['methods'] extends object
128
+ ? {
129
+ [M in keyof TContract['methods']]: TContract['methods'][M] extends (...args: infer A) => unknown
130
+ ? (...args: A) => ContractMethodObject<T>
131
+ : never;
132
+ }
133
+ : ContractMethodsObjectsOf<T, TContract>;
134
+
135
+ export type ContractAbstractionFromContractType<TContract extends BaseContractType> = ContractAbstraction<
136
+ ContractProvider,
137
+ ContractMethodsObjectsOf<ContractProvider, TContract>,
138
+ {},
139
+ {},
140
+ ContractStorageOf<TContract>
141
+ >;
142
+
143
+ export type WalletContractAbstractionFromContractType<TContract extends BaseContractType> = ContractAbstraction<
144
+ Wallet,
145
+ ContractMethodsObjectsOf<Wallet, TContract>,
146
+ {},
147
+ {},
148
+ ContractStorageOf<TContract>
149
+ >;
150
+
151
+ // Extended contract type that includes the backwards-compatible methods property
152
+ export type ContractAbstractionWithMethods<TContract extends BaseContractType> = ContractAbstractionFromContractType<
153
+ TContract
154
+ > & {
155
+ methods: ContractMethodsOf<ContractProvider, TContract>;
156
+ };
157
+
158
+ export type WalletContractAbstractionWithMethods<TContract extends BaseContractType> =
159
+ WalletContractAbstractionFromContractType<TContract> & {
160
+ methods: ContractMethodsOf<Wallet, TContract>;
161
+ };
162
+
163
+ /**
164
+ * Extract parameter names from a Taquito TokenSchema
165
+ */
166
+ function extractParamNames(schema: unknown): string[] {
167
+ if (!schema || typeof schema !== 'object') return [];
168
+ const s = schema as Record<string, unknown>;
169
+ const schemaObj = s.schema;
170
+ if (!schemaObj || typeof schemaObj !== 'object') return ['param'];
171
+ const fieldSchema = schemaObj as Record<string, unknown>;
172
+ const keys = Object.keys(fieldSchema);
173
+ return keys.length > 0 ? keys : ['param'];
174
+ }
175
+
176
+ /**
177
+ * Creates a methods proxy that converts positional arguments to object arguments
178
+ */
179
+ function createMethodsProxy<T>(
180
+ methodsObject: Record<string, (args?: unknown) => ContractMethodObject<T>>,
181
+ parameterSchema: { generateSchema: () => unknown; isMultipleEntryPoint: boolean },
182
+ ): Record<string, (...args: unknown[]) => ContractMethodObject<T>> {
183
+ const schema = parameterSchema.generateSchema() as Record<string, unknown>;
184
+
185
+ return new Proxy({} as Record<string, (...args: unknown[]) => ContractMethodObject<T>>, {
186
+ get(_target, prop: string) {
187
+ if (typeof prop !== 'string' || !(prop in methodsObject)) return undefined;
188
+
189
+ let entrypointSchema: unknown;
190
+ if (parameterSchema.isMultipleEntryPoint && schema.schema) {
191
+ entrypointSchema = (schema.schema as Record<string, unknown>)[prop];
192
+ } else {
193
+ entrypointSchema = schema;
194
+ }
195
+
196
+ const paramNames = extractParamNames(entrypointSchema);
197
+
198
+ return (...positionalArgs: unknown[]): ContractMethodObject<T> => {
199
+ if (positionalArgs.length === 0) return methodsObject[prop]();
200
+ if (positionalArgs.length === 1) {
201
+ const arg = positionalArgs[0];
202
+ if (arg && typeof arg === 'object' && !Array.isArray(arg)) return methodsObject[prop](arg);
203
+ if (paramNames.length === 1) return methodsObject[prop]({ [paramNames[0]]: arg });
204
+ return methodsObject[prop](arg);
205
+ }
206
+ const argsObject: Record<string, unknown> = {};
207
+ positionalArgs.forEach((arg, index) => {
208
+ argsObject[paramNames[index] ?? \`_\${index}\`] = arg;
209
+ });
210
+ return methodsObject[prop](argsObject);
211
+ };
212
+ },
213
+ has(_target, prop: string) { return prop in methodsObject; },
214
+ ownKeys() { return Object.keys(methodsObject); },
215
+ getOwnPropertyDescriptor(_target, prop: string) {
216
+ if (prop in methodsObject) return { enumerable: true, configurable: true };
217
+ return undefined;
218
+ },
219
+ });
220
+ }
221
+
222
+ /**
223
+ * Wraps a Taquito v24+ ContractAbstraction to add backwards-compatible methods property.
224
+ *
225
+ * @example
226
+ * const contract = await Tezos.contract.at(address);
227
+ * const wrapped = wrapContractWithMethods(contract);
228
+ * await wrapped.methods.transfer("tz1...", 100).send(); // Works with positional args
229
+ */
230
+ export function wrapContractWithMethods<TContract extends BaseContractType>(
231
+ contract: ContractAbstractionFromContractType<TContract>,
232
+ ): ContractAbstractionWithMethods<TContract> {
233
+ if ('methods' in contract && contract.methods) {
234
+ return contract as ContractAbstractionWithMethods<TContract>;
235
+ }
236
+
237
+ const methodsProxy = createMethodsProxy(
238
+ contract.methodsObject as Record<string, (args?: unknown) => ContractMethodObject<ContractProvider>>,
239
+ contract.parameterSchema as { generateSchema: () => unknown; isMultipleEntryPoint: boolean },
240
+ );
241
+
242
+ return new Proxy(contract, {
243
+ get(target, prop) {
244
+ if (prop === 'methods') return methodsProxy;
245
+ return (target as Record<string | symbol, unknown>)[prop];
246
+ },
247
+ has(target, prop) {
248
+ if (prop === 'methods') return true;
249
+ return prop in target;
250
+ },
251
+ }) as ContractAbstractionWithMethods<TContract>;
252
+ }
253
+
254
+ /**
255
+ * Wallet version of wrapContractWithMethods
256
+ */
257
+ export function wrapWalletContractWithMethods<TContract extends BaseContractType>(
258
+ contract: WalletContractAbstractionFromContractType<TContract>,
259
+ ): WalletContractAbstractionWithMethods<TContract> {
260
+ if ('methods' in contract && contract.methods) {
261
+ return contract as WalletContractAbstractionWithMethods<TContract>;
262
+ }
263
+
264
+ const methodsProxy = createMethodsProxy(
265
+ contract.methodsObject as Record<string, (args?: unknown) => ContractMethodObject<Wallet>>,
266
+ contract.parameterSchema as { generateSchema: () => unknown; isMultipleEntryPoint: boolean },
267
+ );
268
+
269
+ return new Proxy(contract, {
270
+ get(target, prop) {
271
+ if (prop === 'methods') return methodsProxy;
272
+ return (target as Record<string | symbol, unknown>)[prop];
273
+ },
274
+ has(target, prop) {
275
+ if (prop === 'methods') return true;
276
+ return prop in target;
277
+ },
278
+ }) as WalletContractAbstractionWithMethods<TContract>;
279
+ }
148
280
  `;
149
281
 
150
282
  // src/cli-process.ts
@@ -239,4 +371,4 @@ var generateContractTypesProcessContractFiles = async ({
239
371
  export {
240
372
  generateContractTypesProcessContractFiles
241
373
  };
242
- //# sourceMappingURL=chunk-C3LWMIKT.js.map
374
+ //# sourceMappingURL=chunk-UITQITSS.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["src/cli-process.ts","src/type-aliases-file-content.ts","src/type-utils-file-content.ts"],"sourcesContent":["import fsRaw from 'fs';\nimport path from 'path';\nimport { promisify } from 'util';\nimport { normalizeContractName } from './generator/contract-name';\nimport { generateContractTypesFromMichelsonCode } from './generator/process';\nimport { TypeAliasData, TypeUtilsData } from './generator/typescript-output';\nimport { typeAliasesFileContent } from './type-aliases-file-content';\nimport { typeUtilsFileContent } from './type-utils-file-content';\n\nconst fs = {\n\tmkdir: promisify(fsRaw.mkdir),\n\tcopyFile: promisify(fsRaw.copyFile),\n\treaddir: promisify(fsRaw.readdir),\n\treadFile: promisify(fsRaw.readFile),\n\twriteFile: promisify(fsRaw.writeFile),\n\tstat: promisify(fsRaw.stat),\n\texists: fsRaw.existsSync,\n};\n\nconst getAllFiles = async (rootPath: string, filter: (fullPath: string) => boolean): Promise<string[]> => {\n\tconst allFiles = [] as string[];\n\n\tconst getAllFilesRecursive = async (dirPath: string) => {\n\t\tlet files = await fs.readdir(dirPath, { withFileTypes: true });\n\n\t\tfor (const f of files) {\n\t\t\tconst subPath = path.resolve(dirPath, f.name);\n\n\t\t\tif (f.isDirectory()) {\n\t\t\t\tawait getAllFilesRecursive(subPath);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (!filter(subPath)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tallFiles.push(subPath);\n\t\t}\n\t};\n\n\tawait getAllFilesRecursive(rootPath);\n\treturn allFiles;\n};\n\nexport const generateContractTypesProcessContractFiles = async ({\n\tinputTzContractDirectory,\n\tinputFiles,\n\toutputTypescriptDirectory,\n\tformat,\n\ttypeAliasMode,\n}: {\n\tinputTzContractDirectory: string;\n\tinputFiles?: string[];\n\toutputTypescriptDirectory: string;\n\tformat: 'tz' | 'json';\n\ttypeAliasMode: 'local' | 'file' | 'library' | 'simple';\n}): Promise<void> => {\n\tconsole.log(\n\t\t`Generating Types: ${path.resolve(inputTzContractDirectory)} => ${path.resolve(outputTypescriptDirectory)}`,\n\t);\n\n\tconst ext = '.' + format;\n\tconst filesAll = await getAllFiles(inputTzContractDirectory, x => x.endsWith(ext));\n\tconst files = inputFiles ? filesAll.filter(f => inputFiles.some(inputFile => f.endsWith(inputFile))) : filesAll;\n\n\tconsole.log(`Contracts Found: ${[``, ...files].join(`\\n\\t- `)}`);\n\n\tconst typeAliasImportPath = `@taquito/contract-type-generator`;\n\n\tconst typeAliasData: TypeAliasData = typeAliasMode === 'local'\n\t\t? { mode: typeAliasMode, fileContent: typeAliasesFileContent }\n\t\t: typeAliasMode === 'file'\n\t\t? { mode: typeAliasMode, importPath: `./type-aliases` }\n\t\t: typeAliasMode === 'library'\n\t\t? { mode: typeAliasMode, importPath: typeAliasImportPath }\n\t\t: { mode: 'simple' };\n\n\tif (typeAliasMode === 'file') {\n\t\t// Copy the type alias file\n\t\tawait fs.mkdir(outputTypescriptDirectory, { recursive: true });\n\t\tawait fs.writeFile(path.join(outputTypescriptDirectory, './type-aliases.ts'), typeAliasesFileContent);\n\t}\n\n\t// Copy the type utils file\n\tconst typeUtilsData: TypeUtilsData = { importPath: `./type-utils` };\n\tawait fs.mkdir(outputTypescriptDirectory, { recursive: true });\n\tawait fs.writeFile(path.join(outputTypescriptDirectory, './type-utils.ts'), typeUtilsFileContent);\n\n\tfor (const fullPath of files) {\n\t\tconst fileRelativePath = fullPath.replace(path.resolve(inputTzContractDirectory), '');\n\t\tconst fileName = fileRelativePath.replace(ext, '');\n\t\tconst inputFilePath = path.join(inputTzContractDirectory, fileRelativePath);\n\t\tconst typesOutputFilePath = path.join(outputTypescriptDirectory, fileRelativePath.replace(ext, `.types.ts`));\n\t\tconst codeContentOutputFilePath = path.join(outputTypescriptDirectory, fileRelativePath.replace(ext, `.code.ts`));\n\t\tconst schemaContentOutputFilePath = path.join(\n\t\t\toutputTypescriptDirectory,\n\t\t\tfileRelativePath.replace(ext, `.schema.json`),\n\t\t);\n\t\tconsole.log(`Processing ${fileRelativePath}...`);\n\n\t\ttry {\n\t\t\tconst contractTypeName = normalizeContractName(fileName);\n\n\t\t\tconst michelsonCode = await fs.readFile(inputFilePath, { encoding: `utf8` });\n\n\t\t\tconst {\n\t\t\t\tschemaOutput,\n\t\t\t\ttypescriptCodeOutput: { typesFileContent: typesFileContentRaw, contractCodeFileContent },\n\t\t\t} = generateContractTypesFromMichelsonCode(michelsonCode, contractTypeName, format, typeAliasData, typeUtilsData);\n\n\t\t\t// Correct relative paths for nested contracts\n\t\t\tconst nestedDirDepth = fileRelativePath.replace(/^.?\\/?/, '').split('/').length - 1;\n\t\t\tconst typesFileContent = nestedDirDepth <= 0\n\t\t\t\t? typesFileContentRaw\n\t\t\t\t: typesFileContentRaw.replace(\n\t\t\t\t\t/from '\\.\\//g,\n\t\t\t\t\t`from '${[...new Array(nestedDirDepth)].map(() => '../').join('')}`,\n\t\t\t\t);\n\n\t\t\t// Write output (ensure dir exists)\n\t\t\tawait fs.mkdir(path.dirname(typesOutputFilePath), { recursive: true });\n\t\t\tawait fs.writeFile(typesOutputFilePath, typesFileContent);\n\t\t\tawait fs.writeFile(codeContentOutputFilePath, contractCodeFileContent);\n\n\t\t\tconst debugSchema = false;\n\t\t\tif (debugSchema) {\n\t\t\t\tawait fs.writeFile(schemaContentOutputFilePath, JSON.stringify(schemaOutput, null, 2));\n\t\t\t}\n\t\t} catch (err: unknown) {\n\t\t\tconsole.error(`❌ Could not process ${fileRelativePath}`, { err });\n\t\t}\n\t}\n};\n","// This is required for copying the type aliases to a local file\nexport const typeAliasesFileContent = `\nimport { assertMichelsonInstruction, Expr, MichelsonCode } from '@taquito/michel-codec';\nimport { MichelsonMap } from '@taquito/taquito';\nimport { BigNumber } from 'bignumber.js';\n\nexport type Instruction = MichelsonCode;\n\nexport type unit = (true | undefined) & { __type: 'unit' };\n\nexport type address = string & { __type: 'address' };\nexport type bytes = string & { __type: 'bytes' };\nexport type contract = string & { __type: 'contract' };\nexport type operation = string & { __type: 'operation' };\nexport type key = string & { __type: 'key' };\nexport type key_hash = string & { __type: 'key_hash' };\nexport type signature = string & { __type: 'signature' };\nexport type ticket = string & { __type: 'ticket' };\n\nexport type timestamp = string & { __type: 'timestamp' };\n\nexport type int = BigNumber & { __type: 'int' };\nexport type nat = BigNumber & { __type: 'nat' };\n\nexport type mutez = BigNumber & { __type: 'mutez' };\nexport type tez = BigNumber & { __type: 'tez' };\n\ntype MapKey = Array<any> | object | string | boolean | number;\nexport type MMap<K extends MapKey, V> = Omit<MichelsonMap<K, V>, 'get'> & { get: (key: K) => V };\nexport type BigMap<K extends MapKey, V> = Omit<MichelsonMap<K, V>, 'get'> & { get: (key: K) => Promise<V> };\n\nexport type chest = string & { __type: 'chest' };\nexport type chest_key = string & { __type: 'chest_key' };\n\nconst createStringTypeTas = <T extends string>() => {\n\treturn (value: string): T => value as T;\n};\n\nconst createBigNumberTypeTas = <T extends BigNumber>() => {\n\treturn (value: number | BigNumber | string): T => new BigNumber(value) as T;\n};\n\ntype asMapParamOf<K, V> = K extends string ? { [key: string]: V } | Array<{ key: K; value: V }>\n\t: K extends number ? { [key: number]: V } | Array<{ key: K; value: V }>\n\t: Array<{ key: K; value: V }>;\n\nfunction asMap<K extends MapKey, V>(value: asMapParamOf<K, V>): MMap<K, V> {\n\tconst m = new MichelsonMap<K, V>();\n\tif (Array.isArray(value)) {\n\t\tconst vArray = value as Array<{ key: K; value: V }>;\n\t\tvArray.forEach(x => m.set(x.key, x.value));\n\t} else {\n\t\tconst vObject = value as { [key: string]: V };\n\t\tObject.keys(vObject).forEach(key => m.set(key as unknown as K, vObject[key]));\n\t}\n\treturn m as MMap<K, V>;\n}\nconst asBigMap = <K extends MapKey, V>(value: asMapParamOf<K, V>) => asMap(value) as unknown as BigMap<K, V>;\n\nfunction add<T extends BigNumber>(a: T, b: T): T {\n\treturn a.plus(b) as T;\n}\nfunction subtract<T extends BigNumber>(a: T, b: T): T {\n\treturn a.minus(b) as T;\n}\n\nfunction createLambdaTypeTas(expr: Expr): MichelsonCode {\n\tassertMichelsonInstruction(expr);\n return expr as MichelsonCode;\n}\n\n/** tas: Tezos 'as' casting for strict types */\nexport const tas = {\n\taddress: createStringTypeTas<address>(),\n\tbytes: createStringTypeTas<bytes>(),\n\tcontract: createStringTypeTas<contract>(),\n\tchest: createStringTypeTas<chest>(),\n\tchest_key: createStringTypeTas<chest_key>(),\n\ttimestamp: (value: string | Date): timestamp => new Date(value).toISOString() as timestamp,\n\n\tint: createBigNumberTypeTas<int>(),\n\tnat: createBigNumberTypeTas<nat>(),\n\tmutez: createBigNumberTypeTas<mutez>(),\n\ttez: createBigNumberTypeTas<tez>(),\n\n\tmap: asMap,\n\tbigMap: asBigMap,\n\n\t// Operations\n\tadd,\n\tsubtract,\n\n lambda: createLambdaTypeTas,\n\n\t// To number\n\tnumber: (value: string | BigNumber) => Number(value + ''),\n\tunit: () => true as unit,\n};\n`;\n","// This is required for copying the type utils to a local file\n// Updated for Taquito v24.0.0+ which removed ContractMethod and the methods property\nexport const typeUtilsFileContent = `\nimport { ContractAbstraction, ContractMethodObject, ContractProvider, Wallet } from '@taquito/taquito';\n\n// Support both old (methods) and new (methodsObject) contract type definitions\ntype BaseContractType = { methodsObject: unknown; storage: unknown; methods?: unknown };\n\ntype ContractMethodsObjectsOf<T extends ContractProvider | Wallet, TContract extends BaseContractType> = {\n [M in keyof TContract['methodsObject']]: TContract['methodsObject'][M] extends (...args: infer A) => unknown\n ? (...args: A) => ContractMethodObject<T>\n : never;\n};\ntype ContractStorageOf<TContract extends BaseContractType> = TContract['storage'];\n\n// Type for the methods proxy - converts positional args to methodsObject call\ntype ContractMethodsOf<T extends ContractProvider | Wallet, TContract extends BaseContractType> =\n TContract['methods'] extends object\n ? {\n [M in keyof TContract['methods']]: TContract['methods'][M] extends (...args: infer A) => unknown\n ? (...args: A) => ContractMethodObject<T>\n : never;\n }\n : ContractMethodsObjectsOf<T, TContract>;\n\nexport type ContractAbstractionFromContractType<TContract extends BaseContractType> = ContractAbstraction<\n ContractProvider,\n ContractMethodsObjectsOf<ContractProvider, TContract>,\n {},\n {},\n ContractStorageOf<TContract>\n>;\n\nexport type WalletContractAbstractionFromContractType<TContract extends BaseContractType> = ContractAbstraction<\n Wallet,\n ContractMethodsObjectsOf<Wallet, TContract>,\n {},\n {},\n ContractStorageOf<TContract>\n>;\n\n// Extended contract type that includes the backwards-compatible methods property\nexport type ContractAbstractionWithMethods<TContract extends BaseContractType> = ContractAbstractionFromContractType<\n TContract\n> & {\n methods: ContractMethodsOf<ContractProvider, TContract>;\n};\n\nexport type WalletContractAbstractionWithMethods<TContract extends BaseContractType> =\n WalletContractAbstractionFromContractType<TContract> & {\n methods: ContractMethodsOf<Wallet, TContract>;\n };\n\n/**\n * Extract parameter names from a Taquito TokenSchema\n */\nfunction extractParamNames(schema: unknown): string[] {\n if (!schema || typeof schema !== 'object') return [];\n const s = schema as Record<string, unknown>;\n const schemaObj = s.schema;\n if (!schemaObj || typeof schemaObj !== 'object') return ['param'];\n const fieldSchema = schemaObj as Record<string, unknown>;\n const keys = Object.keys(fieldSchema);\n return keys.length > 0 ? keys : ['param'];\n}\n\n/**\n * Creates a methods proxy that converts positional arguments to object arguments\n */\nfunction createMethodsProxy<T>(\n methodsObject: Record<string, (args?: unknown) => ContractMethodObject<T>>,\n parameterSchema: { generateSchema: () => unknown; isMultipleEntryPoint: boolean },\n): Record<string, (...args: unknown[]) => ContractMethodObject<T>> {\n const schema = parameterSchema.generateSchema() as Record<string, unknown>;\n\n return new Proxy({} as Record<string, (...args: unknown[]) => ContractMethodObject<T>>, {\n get(_target, prop: string) {\n if (typeof prop !== 'string' || !(prop in methodsObject)) return undefined;\n\n let entrypointSchema: unknown;\n if (parameterSchema.isMultipleEntryPoint && schema.schema) {\n entrypointSchema = (schema.schema as Record<string, unknown>)[prop];\n } else {\n entrypointSchema = schema;\n }\n\n const paramNames = extractParamNames(entrypointSchema);\n\n return (...positionalArgs: unknown[]): ContractMethodObject<T> => {\n if (positionalArgs.length === 0) return methodsObject[prop]();\n if (positionalArgs.length === 1) {\n const arg = positionalArgs[0];\n if (arg && typeof arg === 'object' && !Array.isArray(arg)) return methodsObject[prop](arg);\n if (paramNames.length === 1) return methodsObject[prop]({ [paramNames[0]]: arg });\n return methodsObject[prop](arg);\n }\n const argsObject: Record<string, unknown> = {};\n positionalArgs.forEach((arg, index) => {\n argsObject[paramNames[index] ?? \\`_\\${index}\\`] = arg;\n });\n return methodsObject[prop](argsObject);\n };\n },\n has(_target, prop: string) { return prop in methodsObject; },\n ownKeys() { return Object.keys(methodsObject); },\n getOwnPropertyDescriptor(_target, prop: string) {\n if (prop in methodsObject) return { enumerable: true, configurable: true };\n return undefined;\n },\n });\n}\n\n/**\n * Wraps a Taquito v24+ ContractAbstraction to add backwards-compatible methods property.\n *\n * @example\n * const contract = await Tezos.contract.at(address);\n * const wrapped = wrapContractWithMethods(contract);\n * await wrapped.methods.transfer(\"tz1...\", 100).send(); // Works with positional args\n */\nexport function wrapContractWithMethods<TContract extends BaseContractType>(\n contract: ContractAbstractionFromContractType<TContract>,\n): ContractAbstractionWithMethods<TContract> {\n if ('methods' in contract && contract.methods) {\n return contract as ContractAbstractionWithMethods<TContract>;\n }\n\n const methodsProxy = createMethodsProxy(\n contract.methodsObject as Record<string, (args?: unknown) => ContractMethodObject<ContractProvider>>,\n contract.parameterSchema as { generateSchema: () => unknown; isMultipleEntryPoint: boolean },\n );\n\n return new Proxy(contract, {\n get(target, prop) {\n if (prop === 'methods') return methodsProxy;\n return (target as Record<string | symbol, unknown>)[prop];\n },\n has(target, prop) {\n if (prop === 'methods') return true;\n return prop in target;\n },\n }) as ContractAbstractionWithMethods<TContract>;\n}\n\n/**\n * Wallet version of wrapContractWithMethods\n */\nexport function wrapWalletContractWithMethods<TContract extends BaseContractType>(\n contract: WalletContractAbstractionFromContractType<TContract>,\n): WalletContractAbstractionWithMethods<TContract> {\n if ('methods' in contract && contract.methods) {\n return contract as WalletContractAbstractionWithMethods<TContract>;\n }\n\n const methodsProxy = createMethodsProxy(\n contract.methodsObject as Record<string, (args?: unknown) => ContractMethodObject<Wallet>>,\n contract.parameterSchema as { generateSchema: () => unknown; isMultipleEntryPoint: boolean },\n );\n\n return new Proxy(contract, {\n get(target, prop) {\n if (prop === 'methods') return methodsProxy;\n return (target as Record<string | symbol, unknown>)[prop];\n },\n has(target, prop) {\n if (prop === 'methods') return true;\n return prop in target;\n },\n }) as WalletContractAbstractionWithMethods<TContract>;\n}\n`;\n"],"mappings":";;;;;;AAAA,OAAO,WAAW;AAClB,OAAO,UAAU;AACjB,SAAS,iBAAiB;;;ACDnB,IAAM,yBAAyB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACC/B,IAAM,uBAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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,UAAU,qBAAqB,gBAAgB;AACxD,YAAM,GAAG,UAAU,2BAA2B,uBAAuB;AAErE,YAAM,cAAc;AACpB,UAAI,aAAa;AAChB,cAAM,GAAG,UAAU,6BAA6B,KAAK,UAAU,cAAc,MAAM,CAAC,CAAC;AAAA,MACtF;AAAA,IACD,SAAS,KAAc;AACtB,cAAQ,MAAM,4BAAuB,gBAAgB,IAAI,EAAE,IAAI,CAAC;AAAA,IACjE;AAAA,EACD;AACD;","names":[]}
package/index.cjs CHANGED
@@ -808,41 +808,173 @@ export const tas = {
808
808
 
809
809
  // src/type-utils-file-content.ts
810
810
  var typeUtilsFileContent = `
811
- import { ContractAbstraction, ContractMethod, ContractMethodObject, ContractProvider, Wallet } from '@taquito/taquito';
811
+ import { ContractAbstraction, ContractMethodObject, ContractProvider, Wallet } from '@taquito/taquito';
812
812
 
813
- type BaseContractType = { methods: unknown, methodsObject: unknown, storage: unknown };
813
+ // Support both old (methods) and new (methodsObject) contract type definitions
814
+ type BaseContractType = { methodsObject: unknown; storage: unknown; methods?: unknown };
814
815
 
815
- type ContractMethodsOf<T extends ContractProvider | Wallet, TContract extends BaseContractType> = {
816
- [M in keyof TContract['methods']]:
817
- TContract['methods'][M] extends (...args: infer A) => unknown
818
- ? (...args: A) => ContractMethod<T>
819
- : never
820
- };
821
816
  type ContractMethodsObjectsOf<T extends ContractProvider | Wallet, TContract extends BaseContractType> = {
822
- [M in keyof TContract['methodsObject']]:
823
- TContract['methodsObject'][M] extends (...args: infer A) => unknown
824
- ? (...args: A) => ContractMethodObject<T>
825
- : never
817
+ [M in keyof TContract['methodsObject']]: TContract['methodsObject'][M] extends (...args: infer A) => unknown
818
+ ? (...args: A) => ContractMethodObject<T>
819
+ : never;
826
820
  };
827
821
  type ContractStorageOf<TContract extends BaseContractType> = TContract['storage'];
828
822
 
829
- export type ContractAbstractionFromContractType<TContract extends BaseContractType> =
830
- ContractAbstraction<ContractProvider,
831
- ContractMethodsOf<ContractProvider, TContract>,
832
- ContractMethodsObjectsOf<ContractProvider, TContract>,
833
- {},
834
- {},
835
- ContractStorageOf<TContract>
836
- >;
837
-
838
- export type WalletContractAbstractionFromContractType<TContract extends BaseContractType> =
839
- ContractAbstraction<Wallet,
840
- ContractMethodsOf<Wallet, TContract>,
841
- ContractMethodsObjectsOf<Wallet, TContract>,
842
- {},
843
- {},
844
- ContractStorageOf<TContract>
845
- >;
823
+ // Type for the methods proxy - converts positional args to methodsObject call
824
+ type ContractMethodsOf<T extends ContractProvider | Wallet, TContract extends BaseContractType> =
825
+ TContract['methods'] extends object
826
+ ? {
827
+ [M in keyof TContract['methods']]: TContract['methods'][M] extends (...args: infer A) => unknown
828
+ ? (...args: A) => ContractMethodObject<T>
829
+ : never;
830
+ }
831
+ : ContractMethodsObjectsOf<T, TContract>;
832
+
833
+ export type ContractAbstractionFromContractType<TContract extends BaseContractType> = ContractAbstraction<
834
+ ContractProvider,
835
+ ContractMethodsObjectsOf<ContractProvider, TContract>,
836
+ {},
837
+ {},
838
+ ContractStorageOf<TContract>
839
+ >;
840
+
841
+ export type WalletContractAbstractionFromContractType<TContract extends BaseContractType> = ContractAbstraction<
842
+ Wallet,
843
+ ContractMethodsObjectsOf<Wallet, TContract>,
844
+ {},
845
+ {},
846
+ ContractStorageOf<TContract>
847
+ >;
848
+
849
+ // Extended contract type that includes the backwards-compatible methods property
850
+ export type ContractAbstractionWithMethods<TContract extends BaseContractType> = ContractAbstractionFromContractType<
851
+ TContract
852
+ > & {
853
+ methods: ContractMethodsOf<ContractProvider, TContract>;
854
+ };
855
+
856
+ export type WalletContractAbstractionWithMethods<TContract extends BaseContractType> =
857
+ WalletContractAbstractionFromContractType<TContract> & {
858
+ methods: ContractMethodsOf<Wallet, TContract>;
859
+ };
860
+
861
+ /**
862
+ * Extract parameter names from a Taquito TokenSchema
863
+ */
864
+ function extractParamNames(schema: unknown): string[] {
865
+ if (!schema || typeof schema !== 'object') return [];
866
+ const s = schema as Record<string, unknown>;
867
+ const schemaObj = s.schema;
868
+ if (!schemaObj || typeof schemaObj !== 'object') return ['param'];
869
+ const fieldSchema = schemaObj as Record<string, unknown>;
870
+ const keys = Object.keys(fieldSchema);
871
+ return keys.length > 0 ? keys : ['param'];
872
+ }
873
+
874
+ /**
875
+ * Creates a methods proxy that converts positional arguments to object arguments
876
+ */
877
+ function createMethodsProxy<T>(
878
+ methodsObject: Record<string, (args?: unknown) => ContractMethodObject<T>>,
879
+ parameterSchema: { generateSchema: () => unknown; isMultipleEntryPoint: boolean },
880
+ ): Record<string, (...args: unknown[]) => ContractMethodObject<T>> {
881
+ const schema = parameterSchema.generateSchema() as Record<string, unknown>;
882
+
883
+ return new Proxy({} as Record<string, (...args: unknown[]) => ContractMethodObject<T>>, {
884
+ get(_target, prop: string) {
885
+ if (typeof prop !== 'string' || !(prop in methodsObject)) return undefined;
886
+
887
+ let entrypointSchema: unknown;
888
+ if (parameterSchema.isMultipleEntryPoint && schema.schema) {
889
+ entrypointSchema = (schema.schema as Record<string, unknown>)[prop];
890
+ } else {
891
+ entrypointSchema = schema;
892
+ }
893
+
894
+ const paramNames = extractParamNames(entrypointSchema);
895
+
896
+ return (...positionalArgs: unknown[]): ContractMethodObject<T> => {
897
+ if (positionalArgs.length === 0) return methodsObject[prop]();
898
+ if (positionalArgs.length === 1) {
899
+ const arg = positionalArgs[0];
900
+ if (arg && typeof arg === 'object' && !Array.isArray(arg)) return methodsObject[prop](arg);
901
+ if (paramNames.length === 1) return methodsObject[prop]({ [paramNames[0]]: arg });
902
+ return methodsObject[prop](arg);
903
+ }
904
+ const argsObject: Record<string, unknown> = {};
905
+ positionalArgs.forEach((arg, index) => {
906
+ argsObject[paramNames[index] ?? \`_\${index}\`] = arg;
907
+ });
908
+ return methodsObject[prop](argsObject);
909
+ };
910
+ },
911
+ has(_target, prop: string) { return prop in methodsObject; },
912
+ ownKeys() { return Object.keys(methodsObject); },
913
+ getOwnPropertyDescriptor(_target, prop: string) {
914
+ if (prop in methodsObject) return { enumerable: true, configurable: true };
915
+ return undefined;
916
+ },
917
+ });
918
+ }
919
+
920
+ /**
921
+ * Wraps a Taquito v24+ ContractAbstraction to add backwards-compatible methods property.
922
+ *
923
+ * @example
924
+ * const contract = await Tezos.contract.at(address);
925
+ * const wrapped = wrapContractWithMethods(contract);
926
+ * await wrapped.methods.transfer("tz1...", 100).send(); // Works with positional args
927
+ */
928
+ export function wrapContractWithMethods<TContract extends BaseContractType>(
929
+ contract: ContractAbstractionFromContractType<TContract>,
930
+ ): ContractAbstractionWithMethods<TContract> {
931
+ if ('methods' in contract && contract.methods) {
932
+ return contract as ContractAbstractionWithMethods<TContract>;
933
+ }
934
+
935
+ const methodsProxy = createMethodsProxy(
936
+ contract.methodsObject as Record<string, (args?: unknown) => ContractMethodObject<ContractProvider>>,
937
+ contract.parameterSchema as { generateSchema: () => unknown; isMultipleEntryPoint: boolean },
938
+ );
939
+
940
+ return new Proxy(contract, {
941
+ get(target, prop) {
942
+ if (prop === 'methods') return methodsProxy;
943
+ return (target as Record<string | symbol, unknown>)[prop];
944
+ },
945
+ has(target, prop) {
946
+ if (prop === 'methods') return true;
947
+ return prop in target;
948
+ },
949
+ }) as ContractAbstractionWithMethods<TContract>;
950
+ }
951
+
952
+ /**
953
+ * Wallet version of wrapContractWithMethods
954
+ */
955
+ export function wrapWalletContractWithMethods<TContract extends BaseContractType>(
956
+ contract: WalletContractAbstractionFromContractType<TContract>,
957
+ ): WalletContractAbstractionWithMethods<TContract> {
958
+ if ('methods' in contract && contract.methods) {
959
+ return contract as WalletContractAbstractionWithMethods<TContract>;
960
+ }
961
+
962
+ const methodsProxy = createMethodsProxy(
963
+ contract.methodsObject as Record<string, (args?: unknown) => ContractMethodObject<Wallet>>,
964
+ contract.parameterSchema as { generateSchema: () => unknown; isMultipleEntryPoint: boolean },
965
+ );
966
+
967
+ return new Proxy(contract, {
968
+ get(target, prop) {
969
+ if (prop === 'methods') return methodsProxy;
970
+ return (target as Record<string | symbol, unknown>)[prop];
971
+ },
972
+ has(target, prop) {
973
+ if (prop === 'methods') return true;
974
+ return prop in target;
975
+ },
976
+ }) as WalletContractAbstractionWithMethods<TContract>;
977
+ }
846
978
  `;
847
979
 
848
980
  // src/cli-process.ts