@stellar/stellar-sdk 16.0.1 → 16.2.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/README.md +41 -2
- package/dist/stellar-sdk-axios.js +5401 -3690
- package/dist/stellar-sdk-axios.js.map +1 -1
- package/dist/stellar-sdk-axios.min.js +12 -11
- package/dist/stellar-sdk-axios.min.js.map +1 -1
- package/dist/stellar-sdk.js +4850 -3681
- package/dist/stellar-sdk.js.map +1 -1
- package/dist/stellar-sdk.min.js +17 -17
- package/dist/stellar-sdk.min.js.map +1 -1
- package/lib/axios/cjs/base/auth.js +147 -30
- package/lib/axios/cjs/base/auth.js.map +1 -1
- package/lib/axios/cjs/base/index.js +113 -0
- package/lib/axios/cjs/base/index.js.map +1 -0
- package/lib/axios/cjs/base/keypair.js +39 -0
- package/lib/axios/cjs/base/keypair.js.map +1 -1
- package/lib/axios/cjs/base/scval.js +34 -0
- package/lib/axios/cjs/base/scval.js.map +1 -1
- package/lib/axios/cjs/bindings/client.js +170 -0
- package/lib/axios/cjs/bindings/client.js.map +1 -1
- package/lib/axios/cjs/bindings/config.js +1 -1
- package/lib/axios/cjs/bindings/generator.js +45 -16
- package/lib/axios/cjs/bindings/generator.js.map +1 -1
- package/lib/axios/cjs/bindings/types.js +151 -1
- package/lib/axios/cjs/bindings/types.js.map +1 -1
- package/lib/axios/cjs/bindings/utils.js +10 -0
- package/lib/axios/cjs/bindings/utils.js.map +1 -1
- package/lib/axios/cjs/cli/index.js +19 -22
- package/lib/axios/cjs/cli/index.js.map +1 -1
- package/lib/axios/cjs/cli/util.js +1 -20
- package/lib/axios/cjs/cli/util.js.map +1 -1
- package/lib/axios/cjs/contract/assembled_transaction.js +39 -17
- package/lib/axios/cjs/contract/assembled_transaction.js.map +1 -1
- package/lib/axios/cjs/contract/basic_node_signer.js +8 -42
- package/lib/axios/cjs/contract/basic_node_signer.js.map +1 -1
- package/lib/axios/cjs/contract/client.js +56 -3
- package/lib/axios/cjs/contract/client.js.map +1 -1
- package/lib/axios/cjs/contract/event_spec.js +164 -0
- package/lib/axios/cjs/contract/event_spec.js.map +1 -0
- package/lib/axios/cjs/contract/index.js +2 -0
- package/lib/axios/cjs/contract/index.js.map +1 -1
- package/lib/axios/cjs/contract/sent_transaction.js +0 -20
- package/lib/axios/cjs/contract/sent_transaction.js.map +1 -1
- package/lib/axios/cjs/contract/signer.js +96 -0
- package/lib/axios/cjs/contract/signer.js.map +1 -0
- package/lib/axios/cjs/contract/spec.js +107 -3
- package/lib/axios/cjs/contract/spec.js.map +1 -1
- package/lib/axios/cjs/contract/types.js.map +1 -1
- package/lib/axios/cjs/errors/transaction_failed.js +62 -0
- package/lib/axios/cjs/errors/transaction_failed.js.map +1 -0
- package/lib/axios/cjs/errors/wrap_http_error.js +20 -0
- package/lib/axios/cjs/errors/wrap_http_error.js.map +1 -0
- package/lib/axios/cjs/federation/server.js +15 -35
- package/lib/axios/cjs/federation/server.js.map +1 -1
- package/lib/axios/cjs/horizon/account_response.js +0 -20
- package/lib/axios/cjs/horizon/account_response.js.map +1 -1
- package/lib/axios/cjs/horizon/horizon_api.js +5 -0
- package/lib/axios/cjs/horizon/horizon_api.js.map +1 -1
- package/lib/axios/cjs/horizon/horizon_axios_client.js +1 -1
- package/lib/axios/cjs/horizon/server.js +20 -26
- package/lib/axios/cjs/horizon/server.js.map +1 -1
- package/lib/axios/cjs/index.js +66 -65
- package/lib/axios/cjs/index.js.map +1 -1
- package/lib/axios/cjs/rpc/api.js.map +1 -1
- package/lib/axios/cjs/rpc/axios.js +1 -1
- package/lib/axios/cjs/rpc/server.js +181 -13
- package/lib/axios/cjs/rpc/server.js.map +1 -1
- package/lib/axios/cjs/rpc/transaction.js +2 -20
- package/lib/axios/cjs/rpc/transaction.js.map +1 -1
- package/lib/axios/cjs/webauth/challenge_transaction.js +7 -22
- package/lib/axios/cjs/webauth/challenge_transaction.js.map +1 -1
- package/lib/axios/cjs/webauth/utils.js +1 -20
- package/lib/axios/cjs/webauth/utils.js.map +1 -1
- package/lib/axios/esm/base/auth.d.ts +181 -13
- package/lib/axios/esm/base/auth.js +146 -31
- package/lib/axios/esm/base/auth.js.map +1 -1
- package/lib/axios/esm/base/index.d.ts +2 -2
- package/lib/axios/esm/base/index.js +44 -0
- package/lib/axios/esm/base/index.js.map +1 -0
- package/lib/axios/esm/base/keypair.d.ts +27 -0
- package/lib/axios/esm/base/keypair.js +39 -0
- package/lib/axios/esm/base/keypair.js.map +1 -1
- package/lib/axios/esm/base/scval.d.ts +4 -0
- package/lib/axios/esm/base/scval.js +34 -0
- package/lib/axios/esm/base/scval.js.map +1 -1
- package/lib/axios/esm/bindings/client.d.ts +39 -0
- package/lib/axios/esm/bindings/client.js +171 -1
- package/lib/axios/esm/bindings/client.js.map +1 -1
- package/lib/axios/esm/bindings/config.js +1 -1
- package/lib/axios/esm/bindings/generator.d.ts +34 -0
- package/lib/axios/esm/bindings/generator.js +45 -16
- package/lib/axios/esm/bindings/generator.js.map +1 -1
- package/lib/axios/esm/bindings/types.d.ts +42 -0
- package/lib/axios/esm/bindings/types.js +153 -3
- package/lib/axios/esm/bindings/types.js.map +1 -1
- package/lib/axios/esm/bindings/utils.d.ts +10 -0
- package/lib/axios/esm/bindings/utils.js +9 -1
- package/lib/axios/esm/bindings/utils.js.map +1 -1
- package/lib/axios/esm/cli/index.js +19 -22
- package/lib/axios/esm/cli/index.js.map +1 -1
- package/lib/axios/esm/cli/util.d.ts +1 -1
- package/lib/axios/esm/cli/util.js +1 -20
- package/lib/axios/esm/cli/util.js.map +1 -1
- package/lib/axios/esm/contract/assembled_transaction.d.ts +7 -5
- package/lib/axios/esm/contract/assembled_transaction.js +39 -17
- package/lib/axios/esm/contract/assembled_transaction.js.map +1 -1
- package/lib/axios/esm/contract/basic_node_signer.d.ts +3 -0
- package/lib/axios/esm/contract/basic_node_signer.js +8 -42
- package/lib/axios/esm/contract/basic_node_signer.js.map +1 -1
- package/lib/axios/esm/contract/client.d.ts +49 -3
- package/lib/axios/esm/contract/client.js +56 -3
- package/lib/axios/esm/contract/client.js.map +1 -1
- package/lib/axios/esm/contract/event_spec.d.ts +78 -0
- package/lib/axios/esm/contract/event_spec.js +159 -0
- package/lib/axios/esm/contract/event_spec.js.map +1 -0
- package/lib/axios/esm/contract/index.d.ts +3 -0
- package/lib/axios/esm/contract/index.js +1 -0
- package/lib/axios/esm/contract/index.js.map +1 -1
- package/lib/axios/esm/contract/sent_transaction.js +0 -20
- package/lib/axios/esm/contract/sent_transaction.js.map +1 -1
- package/lib/axios/esm/contract/signer.d.ts +104 -0
- package/lib/axios/esm/contract/signer.js +91 -0
- package/lib/axios/esm/contract/signer.js.map +1 -0
- package/lib/axios/esm/contract/spec.d.ts +84 -0
- package/lib/axios/esm/contract/spec.js +107 -3
- package/lib/axios/esm/contract/spec.js.map +1 -1
- package/lib/axios/esm/contract/types.d.ts +25 -8
- package/lib/axios/esm/contract/types.js.map +1 -1
- package/lib/axios/esm/errors/index.d.ts +1 -0
- package/lib/axios/esm/errors/transaction_failed.d.ts +55 -0
- package/lib/axios/esm/errors/transaction_failed.js +60 -0
- package/lib/axios/esm/errors/transaction_failed.js.map +1 -0
- package/lib/axios/esm/errors/wrap_http_error.d.ts +20 -0
- package/lib/axios/esm/errors/wrap_http_error.js +18 -0
- package/lib/axios/esm/errors/wrap_http_error.js.map +1 -0
- package/lib/axios/esm/federation/server.js +15 -35
- package/lib/axios/esm/federation/server.js.map +1 -1
- package/lib/axios/esm/horizon/account_response.js +0 -20
- package/lib/axios/esm/horizon/account_response.js.map +1 -1
- package/lib/axios/esm/horizon/horizon_api.d.ts +12 -1
- package/lib/axios/esm/horizon/horizon_api.js +5 -0
- package/lib/axios/esm/horizon/horizon_api.js.map +1 -1
- package/lib/axios/esm/horizon/horizon_axios_client.js +1 -1
- package/lib/axios/esm/horizon/server.d.ts +10 -4
- package/lib/axios/esm/horizon/server.js +20 -26
- package/lib/axios/esm/horizon/server.js.map +1 -1
- package/lib/axios/esm/index.js +27 -29
- package/lib/axios/esm/index.js.map +1 -1
- package/lib/axios/esm/rpc/api.d.ts +21 -0
- package/lib/axios/esm/rpc/api.js.map +1 -1
- package/lib/axios/esm/rpc/axios.js +1 -1
- package/lib/axios/esm/rpc/server.d.ts +115 -3
- package/lib/axios/esm/rpc/server.js +181 -13
- package/lib/axios/esm/rpc/server.js.map +1 -1
- package/lib/axios/esm/rpc/transaction.js +2 -20
- package/lib/axios/esm/rpc/transaction.js.map +1 -1
- package/lib/axios/esm/webauth/challenge_transaction.js +7 -22
- package/lib/axios/esm/webauth/challenge_transaction.js.map +1 -1
- package/lib/axios/esm/webauth/utils.js +1 -20
- package/lib/axios/esm/webauth/utils.js.map +1 -1
- package/lib/cjs/base/auth.js +147 -30
- package/lib/cjs/base/auth.js.map +1 -1
- package/lib/cjs/base/index.js +113 -0
- package/lib/cjs/base/index.js.map +1 -0
- package/lib/cjs/base/keypair.js +39 -0
- package/lib/cjs/base/keypair.js.map +1 -1
- package/lib/cjs/base/scval.js +34 -0
- package/lib/cjs/base/scval.js.map +1 -1
- package/lib/cjs/bindings/client.js +170 -0
- package/lib/cjs/bindings/client.js.map +1 -1
- package/lib/cjs/bindings/config.js +1 -1
- package/lib/cjs/bindings/generator.js +45 -16
- package/lib/cjs/bindings/generator.js.map +1 -1
- package/lib/cjs/bindings/types.js +151 -1
- package/lib/cjs/bindings/types.js.map +1 -1
- package/lib/cjs/bindings/utils.js +10 -0
- package/lib/cjs/bindings/utils.js.map +1 -1
- package/lib/cjs/cli/index.js +19 -22
- package/lib/cjs/cli/index.js.map +1 -1
- package/lib/cjs/cli/util.js +1 -20
- package/lib/cjs/cli/util.js.map +1 -1
- package/lib/cjs/contract/assembled_transaction.js +39 -17
- package/lib/cjs/contract/assembled_transaction.js.map +1 -1
- package/lib/cjs/contract/basic_node_signer.js +8 -42
- package/lib/cjs/contract/basic_node_signer.js.map +1 -1
- package/lib/cjs/contract/client.js +56 -3
- package/lib/cjs/contract/client.js.map +1 -1
- package/lib/cjs/contract/event_spec.js +164 -0
- package/lib/cjs/contract/event_spec.js.map +1 -0
- package/lib/cjs/contract/index.js +2 -0
- package/lib/cjs/contract/index.js.map +1 -1
- package/lib/cjs/contract/sent_transaction.js +0 -20
- package/lib/cjs/contract/sent_transaction.js.map +1 -1
- package/lib/cjs/contract/signer.js +96 -0
- package/lib/cjs/contract/signer.js.map +1 -0
- package/lib/cjs/contract/spec.js +107 -3
- package/lib/cjs/contract/spec.js.map +1 -1
- package/lib/cjs/contract/types.js.map +1 -1
- package/lib/cjs/errors/transaction_failed.js +62 -0
- package/lib/cjs/errors/transaction_failed.js.map +1 -0
- package/lib/cjs/errors/wrap_http_error.js +20 -0
- package/lib/cjs/errors/wrap_http_error.js.map +1 -0
- package/lib/cjs/federation/server.js +15 -35
- package/lib/cjs/federation/server.js.map +1 -1
- package/lib/cjs/horizon/account_response.js +0 -20
- package/lib/cjs/horizon/account_response.js.map +1 -1
- package/lib/cjs/horizon/horizon_api.js +5 -0
- package/lib/cjs/horizon/horizon_api.js.map +1 -1
- package/lib/cjs/horizon/horizon_axios_client.js +1 -1
- package/lib/cjs/horizon/server.js +20 -26
- package/lib/cjs/horizon/server.js.map +1 -1
- package/lib/cjs/index.js +66 -65
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/rpc/api.js.map +1 -1
- package/lib/cjs/rpc/axios.js +1 -1
- package/lib/cjs/rpc/server.js +181 -13
- package/lib/cjs/rpc/server.js.map +1 -1
- package/lib/cjs/rpc/transaction.js +2 -20
- package/lib/cjs/rpc/transaction.js.map +1 -1
- package/lib/cjs/webauth/challenge_transaction.js +7 -22
- package/lib/cjs/webauth/challenge_transaction.js.map +1 -1
- package/lib/cjs/webauth/utils.js +1 -20
- package/lib/cjs/webauth/utils.js.map +1 -1
- package/lib/esm/base/auth.d.ts +181 -13
- package/lib/esm/base/auth.js +146 -31
- package/lib/esm/base/auth.js.map +1 -1
- package/lib/esm/base/index.d.ts +2 -2
- package/lib/esm/base/index.js +44 -0
- package/lib/esm/base/index.js.map +1 -0
- package/lib/esm/base/keypair.d.ts +27 -0
- package/lib/esm/base/keypair.js +39 -0
- package/lib/esm/base/keypair.js.map +1 -1
- package/lib/esm/base/scval.d.ts +4 -0
- package/lib/esm/base/scval.js +34 -0
- package/lib/esm/base/scval.js.map +1 -1
- package/lib/esm/bindings/client.d.ts +39 -0
- package/lib/esm/bindings/client.js +171 -1
- package/lib/esm/bindings/client.js.map +1 -1
- package/lib/esm/bindings/config.js +1 -1
- package/lib/esm/bindings/generator.d.ts +34 -0
- package/lib/esm/bindings/generator.js +45 -16
- package/lib/esm/bindings/generator.js.map +1 -1
- package/lib/esm/bindings/types.d.ts +42 -0
- package/lib/esm/bindings/types.js +153 -3
- package/lib/esm/bindings/types.js.map +1 -1
- package/lib/esm/bindings/utils.d.ts +10 -0
- package/lib/esm/bindings/utils.js +9 -1
- package/lib/esm/bindings/utils.js.map +1 -1
- package/lib/esm/cli/index.js +19 -22
- package/lib/esm/cli/index.js.map +1 -1
- package/lib/esm/cli/util.d.ts +1 -1
- package/lib/esm/cli/util.js +1 -20
- package/lib/esm/cli/util.js.map +1 -1
- package/lib/esm/contract/assembled_transaction.d.ts +7 -5
- package/lib/esm/contract/assembled_transaction.js +39 -17
- package/lib/esm/contract/assembled_transaction.js.map +1 -1
- package/lib/esm/contract/basic_node_signer.d.ts +3 -0
- package/lib/esm/contract/basic_node_signer.js +8 -42
- package/lib/esm/contract/basic_node_signer.js.map +1 -1
- package/lib/esm/contract/client.d.ts +49 -3
- package/lib/esm/contract/client.js +56 -3
- package/lib/esm/contract/client.js.map +1 -1
- package/lib/esm/contract/event_spec.d.ts +78 -0
- package/lib/esm/contract/event_spec.js +159 -0
- package/lib/esm/contract/event_spec.js.map +1 -0
- package/lib/esm/contract/index.d.ts +3 -0
- package/lib/esm/contract/index.js +1 -0
- package/lib/esm/contract/index.js.map +1 -1
- package/lib/esm/contract/sent_transaction.js +0 -20
- package/lib/esm/contract/sent_transaction.js.map +1 -1
- package/lib/esm/contract/signer.d.ts +104 -0
- package/lib/esm/contract/signer.js +91 -0
- package/lib/esm/contract/signer.js.map +1 -0
- package/lib/esm/contract/spec.d.ts +84 -0
- package/lib/esm/contract/spec.js +107 -3
- package/lib/esm/contract/spec.js.map +1 -1
- package/lib/esm/contract/types.d.ts +25 -8
- package/lib/esm/contract/types.js.map +1 -1
- package/lib/esm/errors/index.d.ts +1 -0
- package/lib/esm/errors/transaction_failed.d.ts +55 -0
- package/lib/esm/errors/transaction_failed.js +60 -0
- package/lib/esm/errors/transaction_failed.js.map +1 -0
- package/lib/esm/errors/wrap_http_error.d.ts +20 -0
- package/lib/esm/errors/wrap_http_error.js +18 -0
- package/lib/esm/errors/wrap_http_error.js.map +1 -0
- package/lib/esm/federation/server.js +15 -35
- package/lib/esm/federation/server.js.map +1 -1
- package/lib/esm/horizon/account_response.js +0 -20
- package/lib/esm/horizon/account_response.js.map +1 -1
- package/lib/esm/horizon/horizon_api.d.ts +12 -1
- package/lib/esm/horizon/horizon_api.js +5 -0
- package/lib/esm/horizon/horizon_api.js.map +1 -1
- package/lib/esm/horizon/horizon_axios_client.js +1 -1
- package/lib/esm/horizon/server.d.ts +10 -4
- package/lib/esm/horizon/server.js +20 -26
- package/lib/esm/horizon/server.js.map +1 -1
- package/lib/esm/index.js +27 -29
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/rpc/api.d.ts +21 -0
- package/lib/esm/rpc/api.js.map +1 -1
- package/lib/esm/rpc/axios.js +1 -1
- package/lib/esm/rpc/server.d.ts +115 -3
- package/lib/esm/rpc/server.js +181 -13
- package/lib/esm/rpc/server.js.map +1 -1
- package/lib/esm/rpc/transaction.js +2 -20
- package/lib/esm/rpc/transaction.js.map +1 -1
- package/lib/esm/webauth/challenge_transaction.js +7 -22
- package/lib/esm/webauth/challenge_transaction.js.map +1 -1
- package/lib/esm/webauth/utils.js +1 -20
- package/lib/esm/webauth/utils.js.map +1 -1
- package/package.json +35 -30
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sources":["../../../src/bindings/client.ts"],"sourcesContent":["import { xdr } from \"../base/index.js\";\nimport { Spec } from \"../contract/index.js\";\nimport {\n parseTypeFromTypeDef,\n generateTypeImports,\n sanitizeIdentifier,\n formatJSDocComment,\n formatImports,\n} from \"./utils.js\";\n\n/**\n * Generates TypeScript client class for contract methods\n */\nexport class ClientGenerator {\n private spec: Spec;\n\n constructor(spec: Spec) {\n this.spec = spec;\n }\n\n /**\n * Generate client class\n */\n generate(): string {\n // Generate constructor method if it exists\n let deployMethod = \"\";\n try {\n const constructorFunc = this.spec.getFunc(\"__constructor\");\n deployMethod = this.generateDeployMethod(constructorFunc);\n } catch {\n // For specs without a constructor, generate a deploy method without params\n deployMethod = this.generateDeployMethod(undefined);\n }\n // Generate interface methods\n const interfaceMethods = this.spec\n .funcs()\n .filter((func) => func.name().toString() !== \"__constructor\")\n .map((func) => this.generateInterfaceMethod(func))\n .join(\"\\n\");\n\n const imports = this.generateImports();\n\n const specEntries = this.spec.entries.map(\n (entry) => `\"${entry.toXDR(\"base64\")}\"`,\n );\n\n const fromJSON = this.spec\n .funcs()\n .filter((func) => func.name().toString() !== \"__constructor\")\n .map((func) => this.generateFromJSONMethod(func))\n .join(\",\");\n\n return `${imports}\n\nexport interface Client {\n${interfaceMethods}\n}\n\nexport class Client extends ContractClient {\n constructor(public readonly options: ContractClientOptions) {\n super(\n new Spec([${specEntries.join(\", \")}]),\n options\n );\n }\n\n ${deployMethod}\n public readonly fromJSON = {\n ${fromJSON}\n };\n}`;\n }\n\n private generateImports(): string {\n const imports = generateTypeImports(\n this.spec.funcs().flatMap((func) => {\n const inputs = func.inputs();\n const outputs = func.outputs();\n const defs = inputs.map((input) => input.type()).concat(outputs);\n return defs;\n }),\n );\n\n return formatImports(imports, {\n includeTypeFileImports: true, // Client imports types\n additionalStellarContractImports: [\n \"Spec\",\n \"AssembledTransaction\",\n \"Client as ContractClient\",\n \"ClientOptions as ContractClientOptions\",\n \"MethodOptions\",\n ],\n });\n }\n\n /**\n * Generate interface method signature\n */\n private generateInterfaceMethod(func: xdr.ScSpecFunctionV0): string {\n const name = sanitizeIdentifier(func.name().toString());\n const inputs = func.inputs().map((input: any) => ({\n name: sanitizeIdentifier(input.name().toString()),\n type: parseTypeFromTypeDef(input.type(), true),\n }));\n const outputType =\n func.outputs().length > 0\n ? parseTypeFromTypeDef(func.outputs()[0])\n : \"void\";\n const docs = formatJSDocComment(func.doc().toString(), 2);\n const params = this.formatMethodParameters(inputs);\n\n return `${docs} ${name}(${params}): Promise<AssembledTransaction<${outputType}>>;`;\n }\n\n private generateFromJSONMethod(func: xdr.ScSpecFunctionV0): string {\n const name = sanitizeIdentifier(func.name().toString());\n const outputType =\n func.outputs().length > 0\n ? parseTypeFromTypeDef(func.outputs()[0])\n : \"void\";\n\n return ` ${name} : this.txFromJSON<${outputType}>`;\n }\n /**\n * Generate deploy method\n */\n private generateDeployMethod(\n constructorFunc: xdr.ScSpecFunctionV0 | undefined,\n ): string {\n // If no constructor, generate deploy with no params\n if (!constructorFunc) {\n const params = this.formatConstructorParameters([]);\n return ` static deploy<T = Client>(${params}): Promise<AssembledTransaction<T>> {\n return ContractClient.deploy(null, options);\n }`;\n }\n const inputs = constructorFunc.inputs().map((input) => ({\n name: sanitizeIdentifier(input.name().toString()),\n type: parseTypeFromTypeDef(input.type(), true),\n }));\n\n const params = this.formatConstructorParameters(inputs);\n const inputsDestructure =\n inputs.length > 0 ? `{ ${inputs.map((i) => i.name).join(\", \")} }, ` : \"\";\n\n return ` static deploy<T = Client>(${params}): Promise<AssembledTransaction<T>> {\n return ContractClient.deploy(${inputsDestructure}options);\n }`;\n }\n\n /**\n * Format method parameters\n */\n private formatMethodParameters(\n inputs: Array<{ name: string; type: string }>,\n ): string {\n const params: string[] = [];\n\n if (inputs.length > 0) {\n const inputsParam = `{ ${inputs.map((i) => `${i.name}: ${i.type}`).join(\"; \")} }`;\n params.push(\n `{ ${inputs.map((i) => i.name).join(\", \")} }: ${inputsParam}`,\n );\n }\n\n params.push(\"options?: MethodOptions\");\n\n return params.join(\", \");\n }\n\n /**\n * Format constructor parameters\n */\n private formatConstructorParameters(\n inputs: Array<{ name: string; type: string }>,\n ): string {\n const params: string[] = [];\n\n if (inputs.length > 0) {\n const inputsParam = `{ ${inputs.map((i) => `${i.name}: ${i.type}`).join(\"; \")} }`;\n params.push(\n `{ ${inputs.map((i) => i.name).join(\", \")} }: ${inputsParam}`,\n );\n }\n\n params.push(\n 'options: MethodOptions & Omit<ContractClientOptions, \\'contractId\\'> & { wasmHash: Buffer | string; salt?: Buffer | Uint8Array; format?: \"hex\" | \"base64\"; address?: string; }',\n );\n\n return params.join(\", \");\n }\n}\n"],"names":["generateTypeImports","formatImports","sanitizeIdentifier","parseTypeFromTypeDef","formatJSDocComment","params"],"mappings":";;;;AAaO,MAAM,eAAA,CAAgB;AAAA,EACnB,IAAA;AAAA,EAER,YAAY,IAAA,EAAY;AACtB,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,QAAA,GAAmB;AAEjB,IAAA,IAAI,YAAA,GAAe,EAAA;AACnB,IAAA,IAAI;AACF,MAAA,MAAM,eAAA,GAAkB,IAAA,CAAK,IAAA,CAAK,OAAA,CAAQ,eAAe,CAAA;AACzD,MAAA,YAAA,GAAe,IAAA,CAAK,qBAAqB,eAAe,CAAA;AAAA,IAC1D,CAAA,CAAA,MAAQ;AAEN,MAAA,YAAA,GAAe,IAAA,CAAK,qBAAqB,MAAS,CAAA;AAAA,IACpD;AAEA,IAAA,MAAM,gBAAA,GAAmB,IAAA,CAAK,IAAA,CAC3B,KAAA,EAAM,CACN,OAAO,CAAC,IAAA,KAAS,IAAA,CAAK,IAAA,EAAK,CAAE,QAAA,OAAe,eAAe,CAAA,CAC3D,GAAA,CAAI,CAAC,IAAA,KAAS,IAAA,CAAK,wBAAwB,IAAI,CAAC,CAAA,CAChD,IAAA,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AAE,IAAI,CAAA,EAAA,EAAK,EAAE,IAAI,CAAA,CAAE,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA,EAAA,CAAA;AAC7E,MAAA,MAAA,CAAO,IAAA;AAAA,QACL,CAAA,EAAA,EAAK,MAAA,CAAO,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,CAAE,IAAI,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA,IAAA,EAAO,WAAW,CAAA;AAAA,OAC7D;AAAA,IACF;AAEA,IAAA,MAAA,CAAO,KAAK,yBAAyB,CAAA;AAErC,IAAA,OAAO,MAAA,CAAO,KAAK,IAAI,CAAA;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA,EAKQ,4BACN,MAAA,EACQ;AACR,IAAA,MAAM,SAAmB,EAAC;AAE1B,IAAA,IAAI,MAAA,CAAO,SAAS,CAAA,EAAG;AACrB,MAAA,MAAM,cAAc,CAAA,EAAA,EAAK,MAAA,CAAO,GAAA,CAAI,CAAC,MAAM,CAAA,EAAG,CAAA,CAAE,IAAI,CAAA,EAAA,EAAK,EAAE,IAAI,CAAA,CAAE,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA,EAAA,CAAA;AAC7E,MAAA,MAAA,CAAO,IAAA;AAAA,QACL,CAAA,EAAA,EAAK,MAAA,CAAO,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,CAAE,IAAI,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA,IAAA,EAAO,WAAW,CAAA;AAAA,OAC7D;AAAA,IACF;AAEA,IAAA,MAAA,CAAO,IAAA;AAAA,MACL,CAAA,4KAAA;AAAA,KACF;AAEA,IAAA,OAAO,MAAA,CAAO,KAAK,IAAI,CAAA;AAAA,EACzB;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"client.js","sources":["../../../src/bindings/client.ts"],"sourcesContent":["import { xdr } from \"../base/index.js\";\nimport { Spec } from \"../contract/index.js\";\nimport {\n parseTypeFromTypeDef,\n generateTypeImports,\n sanitizeIdentifier,\n escapeStringLiteral,\n formatJSDocComment,\n formatImports,\n toCamelCase,\n} from \"./utils.js\";\n\n/**\n * Generates TypeScript client class for contract methods\n */\nexport class ClientGenerator {\n private spec: Spec;\n\n // event index (in declaration order) -> resolved (possibly disambiguated)\n // filter method name. Keyed by index rather than raw name because a\n // contract may declare several events with the same name.\n // Lazily computed on first use; see resolveEventFilterMethodNames().\n private eventFilterMethodNames: Map<number, string> | null = null;\n\n constructor(spec: Spec) {\n this.spec = spec;\n }\n\n /**\n * Generate client class\n */\n generate(): string {\n // Generate constructor method if it exists\n let deployMethod = \"\";\n try {\n const constructorFunc = this.spec.getFunc(\"__constructor\");\n deployMethod = this.generateDeployMethod(constructorFunc);\n } catch {\n // For specs without a constructor, generate a deploy method without params\n deployMethod = this.generateDeployMethod(undefined);\n }\n // Generate interface methods\n const interfaceMethods = this.spec\n .funcs()\n .filter((func) => func.name().toString() !== \"__constructor\")\n .map((func) => this.generateInterfaceMethod(func))\n .join(\"\\n\");\n\n const imports = this.generateImports();\n\n const specEntries = this.spec.entries.map(\n (entry) => `\"${entry.toXDR(\"base64\")}\"`,\n );\n\n const fromJSON = this.spec\n .funcs()\n .filter((func) => func.name().toString() !== \"__constructor\")\n .map((func) => this.generateFromJSONMethod(func))\n .join(\",\");\n\n const events = this.spec.events();\n const parseEventMethodName = this.parseEventMethodName();\n const eventMethods =\n events.length > 0\n ? `\\n${this.generateParseEventMethod(parseEventMethodName)}\\n${events\n .map((event, eventIndex) =>\n this.generateEventFilterMethod(event, eventIndex),\n )\n .join(\"\\n\")}`\n : \"\";\n\n return `${imports}\n\nexport interface Client {\n${interfaceMethods}\n}\n\nexport class Client extends ContractClient {\n constructor(public readonly options: ContractClientOptions) {\n super(\n new Spec([${specEntries.join(\", \")}]),\n options\n );\n }\n\n ${deployMethod}\n public readonly fromJSON = {\n ${fromJSON}\n };\n${eventMethods}\n}`;\n }\n\n private generateImports(): string {\n const imports = generateTypeImports(\n this.spec.funcs().flatMap((func) => {\n const inputs = func.inputs();\n const outputs = func.outputs();\n const defs = inputs.map((input) => input.type()).concat(outputs);\n return defs;\n }),\n );\n\n const events = this.spec.events();\n if (events.length > 0) {\n // parseEvent()'s return type is the ContractEvent union\n imports.typeFileImports.add(\"ContractEvent\");\n // parseEvent()'s topics/data parameters are typed using xdr.ScVal\n imports.stellarImports.add(\"xdr\");\n // Event filter helpers reference topic-list param types only; data\n // param types appear only in types.ts\n events.forEach((event) => {\n const topicParams = event\n .params()\n .filter(\n (param) =>\n param.location().value ===\n xdr.ScSpecEventParamLocationV0.scSpecEventParamLocationTopicList()\n .value,\n );\n topicParams.forEach((param) => {\n const nested = generateTypeImports([param.type()]);\n nested.typeFileImports.forEach((t) => imports.typeFileImports.add(t));\n nested.stellarContractImports.forEach((t) =>\n imports.stellarContractImports.add(t),\n );\n nested.stellarImports.forEach((t) => imports.stellarImports.add(t));\n imports.needsBufferImport =\n imports.needsBufferImport || nested.needsBufferImport;\n });\n });\n }\n\n return formatImports(imports, {\n includeTypeFileImports: true, // Client imports types\n additionalStellarContractImports: [\n \"Spec\",\n \"AssembledTransaction\",\n \"Client as ContractClient\",\n \"ClientOptions as ContractClientOptions\",\n \"MethodOptions\",\n ],\n });\n }\n\n /**\n * Generate the parseEvent method, which delegates to the underlying Spec\n * to decode a raw event's topics/data into a typed ContractEvent.\n */\n private generateParseEventMethod(methodName: string): string {\n return ` /**\n * Parse a raw contract event (topics + data) into a typed {@link ContractEvent}.\n */\n ${methodName}(topics: xdr.ScVal[] | string[], data: xdr.ScVal | string): ContractEvent | undefined {\n return this.spec.parseEvent(topics, data) as ContractEvent | undefined;\n }`;\n }\n\n private parseEventMethodName(): string {\n const reserved = new Set(\n this.spec\n .funcs()\n .filter((func) => func.name().toString() !== \"__constructor\")\n .map((func) => sanitizeIdentifier(func.name().toString())),\n );\n let candidate = \"parseEvent\";\n let suffix = 2;\n while (reserved.has(candidate)) {\n candidate = `parseEvent${suffix}`;\n suffix += 1;\n }\n return candidate;\n }\n\n /**\n * The `<camelCase>EventFilter` method name derived from an event name is\n * not injective (e.g. \"FooBar\" and \"foo_bar\" both produce\n * \"fooBarEventFilter\"), a contract may declare several events with the\n * very same name (composed modules each emitting their own \"transfer\"),\n * and it can just as easily collide with a generated contract function\n * name (e.g. an event \"transfer\" plus a function \"transferEventFilter\").\n * Since function member names are load-bearing (called directly by\n * users) and event filter names are already synthetic, function names\n * always win: they are reserved first, in spec-entry order. Events are\n * then resolved in spec-entry order, appending the smallest integer 2 or\n * greater needed to make the name unique (and reserving whatever name\n * results, so later events see it too). This is deterministic for a\n * given spec.\n */\n private resolveEventFilterMethodNames(): Map<number, string> {\n if (this.eventFilterMethodNames !== null) {\n return this.eventFilterMethodNames;\n }\n\n const reserved = new Set<string>();\n\n this.spec\n .funcs()\n .filter((func) => func.name().toString() !== \"__constructor\")\n .forEach((func) => {\n reserved.add(sanitizeIdentifier(func.name().toString()));\n });\n\n const resolved = new Map<number, string>();\n\n this.spec.events().forEach((event, eventIndex) => {\n const preferred = `${toCamelCase(sanitizeIdentifier(event.name().toString()))}EventFilter`;\n\n let candidate = preferred;\n let suffix = 2;\n while (reserved.has(candidate)) {\n candidate = `${preferred}${suffix}`;\n suffix += 1;\n }\n\n reserved.add(candidate);\n resolved.set(eventIndex, candidate);\n });\n\n this.eventFilterMethodNames = resolved;\n return resolved;\n }\n\n /**\n * Compute the resolved (possibly disambiguated) filter method name for an\n * event; see {@link resolveEventFilterMethodNames}.\n */\n private eventFilterMethodName(\n event: xdr.ScSpecEventV0,\n eventIndex: number,\n ): string {\n const resolved = this.resolveEventFilterMethodNames().get(eventIndex);\n /* istanbul ignore next -- every event in the spec is reserved a name */\n if (resolved === undefined) {\n return `${toCamelCase(sanitizeIdentifier(event.name().toString()))}EventFilter`;\n }\n return resolved;\n }\n\n /**\n * The resolved (possibly disambiguated) filter method name of every event\n * in the spec, in declaration order. Exposed so callers (e.g. the bindings\n * generator's diagnostics) can report renames and duplicates.\n */\n eventFilterMethodNamesInOrder(): string[] {\n return this.spec\n .events()\n .map((event, eventIndex) =>\n this.eventFilterMethodName(event, eventIndex),\n );\n }\n\n /**\n * Generate a per-event helper that builds a topics-filter row for\n * `Api.EventFilter.topics`, suitable for passing to server.getEvents.\n */\n private generateEventFilterMethod(\n event: xdr.ScSpecEventV0,\n eventIndex: number,\n ): string {\n const rawName = event.name().toString();\n const methodName = this.eventFilterMethodName(event, eventIndex);\n const preferredMethodName = `${toCamelCase(sanitizeIdentifier(rawName))}EventFilter`;\n // Which same-named event this is (0-based, declaration order) — needed\n // so eventTopicFilter targets the right spec when names are duplicated.\n const occurrence = this.spec\n .events()\n .slice(0, eventIndex)\n .filter((e) => e.name().toString() === rawName).length;\n const occurrenceNote =\n occurrence > 0\n ? ` This targets declaration ${occurrence + 1} of the \"${rawName}\" event in the contract spec.`\n : \"\";\n const renameNote =\n methodName !== preferredMethodName\n ? ` Note: renamed from \"${preferredMethodName}\" to avoid a collision with another generated name.`\n : \"\";\n const topicParams = event\n .params()\n .filter(\n (param) =>\n param.location().value ===\n xdr.ScSpecEventParamLocationV0.scSpecEventParamLocationTopicList()\n .value,\n );\n\n // eventTopicFilter looks values up by the raw param names, so the\n // parameter type must use them too — quoted when they aren't valid\n // identifiers.\n const fields = topicParams\n .map((param) => {\n const rawParamName = param.name().toString();\n const fieldName = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(rawParamName)\n ? rawParamName\n : `\"${escapeStringLiteral(rawParamName)}\"`;\n const fieldType = parseTypeFromTypeDef(param.type(), true);\n return `${fieldName}?: ${fieldType}`;\n })\n .join(\"; \");\n\n const doc = formatJSDocComment(\n `Build a topics filter row for the \"${rawName}\" event, for use in ` +\n `\\`Api.EventFilter.topics\\` when calling \\`server.getEvents\\`. ` +\n `Omitted fields match any value.${occurrenceNote}${renameNote}`,\n 2,\n );\n\n const escapedName = escapeStringLiteral(rawName);\n const occurrenceArg = occurrence > 0 ? `, ${occurrence}` : \"\";\n\n if (topicParams.length === 0) {\n return `${doc} ${methodName}(): string[] {\n return this.spec.eventTopicFilter(\"${escapedName}\"${occurrence > 0 ? `, undefined${occurrenceArg}` : \"\"});\n }`;\n }\n\n return `${doc} ${methodName}(topicValues?: { ${fields} }): string[] {\n return this.spec.eventTopicFilter(\"${escapedName}\", topicValues${occurrenceArg});\n }`;\n }\n\n /**\n * Generate interface method signature\n */\n private generateInterfaceMethod(func: xdr.ScSpecFunctionV0): string {\n const name = sanitizeIdentifier(func.name().toString());\n const inputs = func.inputs().map((input: any) => ({\n name: sanitizeIdentifier(input.name().toString()),\n type: parseTypeFromTypeDef(input.type(), true),\n }));\n const outputType =\n func.outputs().length > 0\n ? parseTypeFromTypeDef(func.outputs()[0])\n : \"void\";\n const docs = formatJSDocComment(func.doc().toString(), 2);\n const params = this.formatMethodParameters(inputs);\n\n return `${docs} ${name}(${params}): Promise<AssembledTransaction<${outputType}>>;`;\n }\n\n private generateFromJSONMethod(func: xdr.ScSpecFunctionV0): string {\n const name = sanitizeIdentifier(func.name().toString());\n const outputType =\n func.outputs().length > 0\n ? parseTypeFromTypeDef(func.outputs()[0])\n : \"void\";\n\n return ` ${name} : this.txFromJSON<${outputType}>`;\n }\n /**\n * Generate deploy method\n */\n private generateDeployMethod(\n constructorFunc: xdr.ScSpecFunctionV0 | undefined,\n ): string {\n // If no constructor, generate deploy with no params\n if (!constructorFunc) {\n const params = this.formatConstructorParameters([]);\n return ` static deploy<T = Client>(${params}): Promise<AssembledTransaction<T>> {\n return ContractClient.deploy(null, options);\n }`;\n }\n const inputs = constructorFunc.inputs().map((input) => ({\n name: sanitizeIdentifier(input.name().toString()),\n type: parseTypeFromTypeDef(input.type(), true),\n }));\n\n const params = this.formatConstructorParameters(inputs);\n const inputsDestructure =\n inputs.length > 0 ? `{ ${inputs.map((i) => i.name).join(\", \")} }, ` : \"\";\n\n return ` static deploy<T = Client>(${params}): Promise<AssembledTransaction<T>> {\n return ContractClient.deploy(${inputsDestructure}options);\n }`;\n }\n\n /**\n * Format method parameters\n */\n private formatMethodParameters(\n inputs: Array<{ name: string; type: string }>,\n ): string {\n const params: string[] = [];\n\n if (inputs.length > 0) {\n const inputsParam = `{ ${inputs.map((i) => `${i.name}: ${i.type}`).join(\"; \")} }`;\n params.push(\n `{ ${inputs.map((i) => i.name).join(\", \")} }: ${inputsParam}`,\n );\n }\n\n params.push(\"options?: MethodOptions\");\n\n return params.join(\", \");\n }\n\n /**\n * Format constructor parameters\n */\n private formatConstructorParameters(\n inputs: Array<{ name: string; type: string }>,\n ): string {\n const params: string[] = [];\n\n if (inputs.length > 0) {\n const inputsParam = `{ ${inputs.map((i) => `${i.name}: ${i.type}`).join(\"; \")} }`;\n params.push(\n `{ ${inputs.map((i) => i.name).join(\", \")} }: ${inputsParam}`,\n );\n }\n\n params.push(\n 'options: MethodOptions & Omit<ContractClientOptions, \\'contractId\\'> & { wasmHash: Buffer | string; salt?: Buffer | Uint8Array; format?: \"hex\" | \"base64\"; address?: string; }',\n );\n\n return params.join(\", \");\n }\n}\n"],"names":["generateTypeImports","xdr","formatImports","sanitizeIdentifier","toCamelCase","escapeStringLiteral","parseTypeFromTypeDef","formatJSDocComment","params"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAeO,MAAM,eAAA,CAAgB;AAAA,EACnB,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,sBAAA,GAAqD,IAAA;AAAA,EAE7D,YAAY,IAAA,EAAY;AACtB,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,QAAA,GAAmB;AAEjB,IAAA,IAAI,YAAA,GAAe,EAAA;AACnB,IAAA,IAAI;AACF,MAAA,MAAM,eAAA,GAAkB,IAAA,CAAK,IAAA,CAAK,OAAA,CAAQ,eAAe,CAAA;AACzD,MAAA,YAAA,GAAe,IAAA,CAAK,qBAAqB,eAAe,CAAA;AAAA,IAC1D,CAAA,CAAA,MAAQ;AAEN,MAAA,Y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AAA,CAAE,IAAI,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA,IAAA,EAAO,WAAW,CAAA;AAAA,OAC7D;AAAA,IACF;AAEA,IAAA,MAAA,CAAO,IAAA;AAAA,MACL,CAAA,4KAAA;AAAA,KACF;AAEA,IAAA,OAAO,MAAA,CAAO,KAAK,IAAI,CAAA;AAAA,EACzB;AACF;;;;"}
|
|
@@ -1,27 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
require('buffer');
|
|
4
|
-
require('../node_modules/.pnpm/@stellar_js-xdr@4.0.0/node_modules/@stellar/js-xdr/src/int.js');
|
|
5
|
-
require('../node_modules/.pnpm/@stellar_js-xdr@4.0.0/node_modules/@stellar/js-xdr/src/hyper.js');
|
|
6
|
-
require('../node_modules/.pnpm/@stellar_js-xdr@4.0.0/node_modules/@stellar/js-xdr/src/unsigned-int.js');
|
|
7
|
-
require('../node_modules/.pnpm/@stellar_js-xdr@4.0.0/node_modules/@stellar/js-xdr/src/unsigned-hyper.js');
|
|
8
|
-
require('../node_modules/.pnpm/@stellar_js-xdr@4.0.0/node_modules/@stellar/js-xdr/src/xdr-type.js');
|
|
9
4
|
require('../base/generated/curr_generated.js');
|
|
10
|
-
require('@noble/hashes/sha2.js');
|
|
11
|
-
require('../base/signing.js');
|
|
12
5
|
require('../base/keypair.js');
|
|
13
6
|
require('base32.js');
|
|
14
|
-
require('
|
|
15
|
-
require('../base/util/bignumber.js');
|
|
16
|
-
require('../base/transaction_builder.js');
|
|
17
|
-
require('../base/muxed_account.js');
|
|
7
|
+
require('@noble/hashes/sha2.js');
|
|
18
8
|
require('../base/scval.js');
|
|
19
|
-
require('../base/numbers/uint128.js');
|
|
20
|
-
require('../base/numbers/uint256.js');
|
|
21
|
-
require('../base/numbers/int128.js');
|
|
22
|
-
require('../base/numbers/int256.js');
|
|
23
9
|
require('../rpc/api.js');
|
|
24
10
|
var spec = require('../contract/spec.js');
|
|
11
|
+
var utils = require('./utils.js');
|
|
25
12
|
var config = require('./config.js');
|
|
26
13
|
var types = require('./types.js');
|
|
27
14
|
var client = require('./client.js');
|
|
@@ -170,6 +157,7 @@ class BindingGenerator {
|
|
|
170
157
|
const clientGenerator = new client.ClientGenerator(this.spec);
|
|
171
158
|
const types$1 = typeGenerator.generate();
|
|
172
159
|
const client$1 = clientGenerator.generate();
|
|
160
|
+
const diagnostics = this.eventDiagnostics(typeGenerator, clientGenerator);
|
|
173
161
|
let index = `export { Client } from "./client.js";`;
|
|
174
162
|
if (types$1.trim() !== "") {
|
|
175
163
|
index = index.concat(`
|
|
@@ -184,9 +172,50 @@ export * from "./types.js";`);
|
|
|
184
172
|
packageJson,
|
|
185
173
|
tsConfig,
|
|
186
174
|
readme,
|
|
187
|
-
gitignore
|
|
175
|
+
gitignore,
|
|
176
|
+
diagnostics
|
|
188
177
|
};
|
|
189
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Collect an {@link EventDiagnostic} for every event that a user should
|
|
181
|
+
* review in the generated output: duplicate declarations of the same raw
|
|
182
|
+
* name, and generated names renamed away from their preferred form to
|
|
183
|
+
* avoid a collision.
|
|
184
|
+
*/
|
|
185
|
+
eventDiagnostics(typeGenerator, clientGenerator) {
|
|
186
|
+
const events = this.spec.events();
|
|
187
|
+
const interfaceNames = typeGenerator.eventInterfaceNamesInOrder();
|
|
188
|
+
const filterMethodNames = clientGenerator.eventFilterMethodNamesInOrder();
|
|
189
|
+
const declarationCounts = /* @__PURE__ */ new Map();
|
|
190
|
+
events.forEach((event) => {
|
|
191
|
+
const rawName = event.name().toString();
|
|
192
|
+
declarationCounts.set(rawName, (declarationCounts.get(rawName) ?? 0) + 1);
|
|
193
|
+
});
|
|
194
|
+
const occurrenceSoFar = /* @__PURE__ */ new Map();
|
|
195
|
+
return events.flatMap((event, eventIndex) => {
|
|
196
|
+
const rawName = event.name().toString();
|
|
197
|
+
const occurrence = occurrenceSoFar.get(rawName) ?? 0;
|
|
198
|
+
occurrenceSoFar.set(rawName, occurrence + 1);
|
|
199
|
+
const declarations = declarationCounts.get(rawName);
|
|
200
|
+
const sanitized = utils.sanitizeIdentifier(rawName);
|
|
201
|
+
const interfaceRenamed = interfaceNames[eventIndex] !== `${utils.toPascalCase(sanitized)}Event`;
|
|
202
|
+
const filterMethodRenamed = filterMethodNames[eventIndex] !== `${utils.toCamelCase(sanitized)}EventFilter`;
|
|
203
|
+
if (declarations <= 1 && !interfaceRenamed && !filterMethodRenamed) {
|
|
204
|
+
return [];
|
|
205
|
+
}
|
|
206
|
+
return [
|
|
207
|
+
{
|
|
208
|
+
rawName,
|
|
209
|
+
occurrence,
|
|
210
|
+
declarations,
|
|
211
|
+
interfaceName: interfaceNames[eventIndex],
|
|
212
|
+
filterMethodName: filterMethodNames[eventIndex],
|
|
213
|
+
interfaceRenamed,
|
|
214
|
+
filterMethodRenamed
|
|
215
|
+
}
|
|
216
|
+
];
|
|
217
|
+
});
|
|
218
|
+
}
|
|
190
219
|
/**
|
|
191
220
|
* Validates that required generation options are provided.
|
|
192
221
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sources":["../../../src/bindings/generator.ts"],"sourcesContent":["import { Spec } from \"../contract/index.js\";\nimport { ConfigGenerator } from \"./config.js\";\nimport { TypeGenerator } from \"./types.js\";\nimport { ClientGenerator } from \"./client.js\";\nimport { specFromWasm } from \"../contract/wasm_spec_parser.js\";\nimport { fetchFromContractId, fetchFromWasmHash } from \"./wasm_fetcher.js\";\nimport { SAC_SPEC } from \"./sac-spec.js\";\nimport { Server } from \"../rpc/index.js\";\n\n/**\n * Options for generating TypeScript bindings.\n */\nexport type GenerateOptions = {\n /**\n * The name used for the generated package and client class.\n * Should be in kebab-case (e.g., \"my-contract\").\n */\n contractName: string;\n};\n\n/**\n * The output of the binding generation process.\n *\n * Contains all generated TypeScript source files and configuration files\n * needed to create a standalone npm package for interacting with a Stellar contract.\n */\nexport type GeneratedBindings = {\n /** The index.ts barrel export file that re-exports Client and types */\n index: string;\n /** The types.ts file containing TypeScript interfaces for contract structs, enums, and unions */\n types: string;\n /** The client.ts file containing the generated Client class with typed methods */\n client: string;\n /** The package.json for the generated npm package */\n packageJson: string;\n /** The tsconfig.json for TypeScript compilation */\n tsConfig: string;\n /** The README.md with usage documentation */\n readme: string;\n /** The .gitignore file for the generated package */\n gitignore: string;\n};\n\n/**\n * Generates TypeScript bindings for Stellar smart contracts.\n *\n * This class creates fully-typed TypeScript client code from a contract's specification,\n * allowing developers to interact with Stellar smart contracts with full IDE support\n * and compile-time type checking.\n *\n * @example\n * ```ts\n * // Create from a local WASM file\n * const wasmBuffer = fs.readFileSync(\"./my_contract.wasm\");\n * const generator = await BindingGenerator.fromWasm(wasmBuffer);\n * const bindings = generator.generate({ contractName: \"my-contract\" });\n * ```\n *\n * @example\n * ```ts\n * // Create from a contract deployed on the network\n * const generator = await BindingGenerator.fromContractId(\n * \"CABC...XYZ\",\n * \"https://soroban-testnet.stellar.org\",\n * Networks.TESTNET\n * );\n * const bindings = generator.generate({ contractName: \"my-contract\" });\n * ```\n *\n * @example\n * ```ts\n * // Create from a Spec object directly\n * const spec = new Spec(specEntries);\n * const generator = BindingGenerator.fromSpec(spec);\n * const bindings = generator.generate({ contractName: \"my-contract\" });\n * ```\n */\nexport class BindingGenerator {\n private spec: Spec;\n\n /**\n * Private constructor - use static factory methods instead.\n *\n * @param spec - The parsed contract specification\n */\n private constructor(spec: Spec) {\n this.spec = spec;\n }\n\n /**\n * Creates a BindingGenerator from an existing Spec object.\n *\n * Use this when you already have a parsed contract specification,\n * such as from manually constructed spec entries or from another source.\n *\n * @param spec - The contract specification containing function and type definitions\n * @returns A new BindingGenerator instance\n *\n * @example\n * ```ts\n * const spec = new Spec(specEntries);\n * const generator = BindingGenerator.fromSpec(spec);\n * ```\n */\n static fromSpec(spec: Spec): BindingGenerator {\n return new BindingGenerator(spec);\n }\n\n /**\n * Creates a BindingGenerator from a WASM binary buffer.\n *\n * Parses the contract specification directly from the WASM file's custom section.\n * This is the most common method when working with locally compiled contracts.\n *\n * @param wasmBuffer - The raw WASM binary as a Buffer\n * @returns A Promise resolving to a new BindingGenerator instance\n * @throws If the WASM file doesn't contain a valid contract spec\n *\n * @example\n * ```ts\n * const wasmBuffer = fs.readFileSync(\"./target/wasm32-unknown-unknown/release/my_contract.wasm\");\n * const generator = await BindingGenerator.fromWasm(wasmBuffer);\n * ```\n */\n static fromWasm(wasmBuffer: Buffer): BindingGenerator {\n const spec = new Spec(specFromWasm(wasmBuffer));\n return new BindingGenerator(spec);\n }\n\n /**\n * Creates a BindingGenerator by fetching WASM from the network using its hash.\n *\n * Retrieves the WASM bytecode from Stellar RPC using the WASM hash,\n * then parses the contract specification from it. Useful when you know\n * the hash of an installed WASM but don't have the binary locally.\n *\n * @param wasmHash - The hex-encoded hash of the installed WASM blob\n * @param rpcServer - The Stellar RPC server instance\n * @returns A Promise resolving to a new BindingGenerator instance\n * @throws If the WASM cannot be fetched or doesn't contain a valid spec\n *\n * @example\n * ```ts\n * const generator = await BindingGenerator.fromWasmHash(\n * \"a1b2c3...xyz\",\n * \"https://soroban-testnet.stellar.org\",\n * Networks.TESTNET\n * );\n * ```\n */\n static async fromWasmHash(\n wasmHash: string,\n rpcServer: Server,\n ): Promise<BindingGenerator> {\n const wasm = await fetchFromWasmHash(wasmHash, rpcServer);\n if (wasm.type !== \"wasm\") {\n throw new Error(\"Fetched contract is not of type 'wasm'\");\n }\n return BindingGenerator.fromWasm(wasm.wasmBytes);\n }\n\n /**\n * Creates a BindingGenerator by fetching contract info from a deployed contract ID.\n *\n * Retrieves the contract's WASM from the network using the contract ID,\n * then parses the specification. If the contract is a Stellar Asset Contract (SAC),\n * returns a generator with the standard SAC specification.\n *\n * @param contractId - The contract ID (C... address) of the deployed contract\n * @param rpcServer - The Stellar RPC server instance\n * @returns A Promise resolving to a new BindingGenerator instance\n * @throws If the contract cannot be found or fetched\n *\n * @example\n * ```ts\n * const generator = await BindingGenerator.fromContractId(\n * \"CABC123...XYZ\",\n * rpcServer\n * );\n * ```\n */\n static async fromContractId(\n contractId: string,\n rpcServer: Server,\n ): Promise<BindingGenerator> {\n const result = await fetchFromContractId(contractId, rpcServer);\n if (result.type === \"wasm\") {\n return BindingGenerator.fromWasm(result.wasmBytes);\n }\n // Stellar Asset Contract\n const spec = new Spec(SAC_SPEC);\n return BindingGenerator.fromSpec(spec);\n }\n\n /**\n * Generates TypeScript bindings for the contract.\n *\n * Produces all the files needed for a standalone npm package:\n * - `client.ts`: A typed Client class with methods for each contract function\n * - `types.ts`: TypeScript interfaces for all contract types (structs, enums, unions)\n * - `index.ts`: Barrel export file\n * - `package.json`, `tsconfig.json`, `README.md`, `.gitignore`: Package configuration\n *\n * The generated code does not write to disk - use the returned strings\n * to write files as needed.\n *\n * @param options - Configuration options for generation\n * - `contractName`: Required. The name for the generated package (kebab-case recommended)\n * @returns An object containing all generated file contents as strings\n * @throws If contractName is missing or empty\n *\n * @example\n * ```ts\n * const bindings = generator.generate({\n * contractName: \"my-token\",\n * contractAddress: \"CABC...XYZ\",\n * rpcUrl: \"https://soroban-testnet.stellar.org\",\n * networkPassphrase: Networks.TESTNET\n * });\n *\n * // Write files to disk\n * fs.writeFileSync(\"./src/client.ts\", bindings.client);\n * fs.writeFileSync(\"./src/types.ts\", bindings.types);\n * ```\n */\n generate(options: GenerateOptions): GeneratedBindings {\n this.validateOptions(options);\n\n const typeGenerator = new TypeGenerator(this.spec);\n const clientGenerator = new ClientGenerator(this.spec);\n\n const types = typeGenerator.generate();\n const client = clientGenerator.generate();\n\n let index = `export { Client } from \"./client.js\";`;\n if (types.trim() !== \"\") {\n index = index.concat(`\\nexport * from \"./types.js\";`);\n }\n\n // Generate config files\n const configGenerator = new ConfigGenerator();\n const { packageJson, tsConfig, readme, gitignore } =\n configGenerator.generate(options);\n\n return {\n index,\n types,\n client,\n packageJson,\n tsConfig,\n readme,\n gitignore,\n };\n }\n\n /**\n * Validates that required generation options are provided.\n *\n * @param options - The options to validate\n * @throws If contractName is missing or empty\n */\n private validateOptions(options: GenerateOptions): void {\n if (!options.contractName || options.contractName.trim() === \"\") {\n throw new Error(\"contractName is required and cannot be empty\");\n }\n }\n}\n"],"names":["spec","Spec","specFromWasm","fetchFromWasmHash","fetchFromContractId","SAC_SPEC","TypeGenerator","ClientGenerator","types","client","ConfigGenerator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EO,MAAM,gBAAA,CAAiB;AAAA,EACpB,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,YAAY,IAAA,EAAY;AAC9B,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,OAAO,SAAS,IAAA,EAA8B;AAC5C,IAAA,OAAO,IAAI,iBAAiB,IAAI,CAAA;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBA,OAAO,SAAS,UAAA,EAAsC;AACpD,IAAA,MAAMA,MAAA,GAAO,IAAIC,SAAA,CAAKC,6BAAA,CAAa,UAAU,CAAC,CAAA;AAC9C,IAAA,OAAO,IAAI,iBAAiBF,MAAI,CAAA;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAuBA,aAAa,YAAA,CACX,QAAA,EACA,SAAA,EAC2B;AAC3B,IAAA,MAAM,IAAA,GAAO,MAAMG,8BAAA,CAAkB,QAAA,EAAU,SAAS,CAAA;AACxD,IAAA,IAAI,IAAA,CAAK,SAAS,MAAA,EAAQ;AACxB,MAAA,MAAM,IAAI,MAAM,wCAAwC,CAAA;AA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AI;AACvB,MAAA,KAAA,GAAQ,MAAM,MAAA,CAAO;AAAA,2BAAA,CAA+B,CAAA;AAAA,IACtD;AAGA,IAAA,MAAM,eAAA,GAAkB,IAAIE,sBAAA,EAAgB;AAC5C,IAAA,MAAM,EAAE,aAAa,QAAA,EAAU,MAAA,EAAQ,WAAU,GAC/C,eAAA,CAAgB,SAAS,OAAO,CAAA;AAElC,IAAA,OAAO;AAAA,MACL,KAAA;AAAA,aACAF,OAAA;AAAA,cACAC,QAAA;AAAA,MACA,WAAA;AAAA,MACA,QAAA;AAAA,MACA,MAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQQ,gBAAgB,OAAA,EAAgC;AACtD,IAAA,IAAI,CAAC,OAAA,CAAQ,YAAA,IAAgB,QAAQ,YAAA,CAAa,IAAA,OAAW,EAAA,EAAI;AAC/D,MAAA,MAAM,IAAI,MAAM,8CAA8C,CAAA;AAAA,IAChE;AAAA,EACF;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"generator.js","sources":["../../../src/bindings/generator.ts"],"sourcesContent":["import { Spec } from \"../contract/index.js\";\nimport { ConfigGenerator } from \"./config.js\";\nimport { sanitizeIdentifier, toCamelCase, toPascalCase } from \"./utils.js\";\nimport { TypeGenerator } from \"./types.js\";\nimport { ClientGenerator } from \"./client.js\";\nimport { specFromWasm } from \"../contract/wasm_spec_parser.js\";\nimport { fetchFromContractId, fetchFromWasmHash } from \"./wasm_fetcher.js\";\nimport { SAC_SPEC } from \"./sac-spec.js\";\nimport { Server } from \"../rpc/index.js\";\n\n/**\n * Options for generating TypeScript bindings.\n */\nexport type GenerateOptions = {\n /**\n * The name used for the generated package and client class.\n * Should be in kebab-case (e.g., \"my-contract\").\n */\n contractName: string;\n};\n\n/**\n * A note about an event whose generated names need the user's attention:\n * either the contract declares the same event name more than once, or the\n * generated names were renamed away from their preferred form to avoid a\n * collision with another generated name.\n */\nexport type EventDiagnostic = {\n /** The event name exactly as declared in the contract spec */\n rawName: string;\n /** 0-based index of this declaration among same-named events */\n occurrence: number;\n /** Total number of declarations of this raw name in the spec */\n declarations: number;\n /** The exported interface name generated in types.ts */\n interfaceName: string;\n /** The filter method name generated on the Client class */\n filterMethodName: string;\n /** True if the interface name differs from its preferred form */\n interfaceRenamed: boolean;\n /** True if the filter method name differs from its preferred form */\n filterMethodRenamed: boolean;\n};\n\n/**\n * The output of the binding generation process.\n *\n * Contains all generated TypeScript source files and configuration files\n * needed to create a standalone npm package for interacting with a Stellar contract.\n */\nexport type GeneratedBindings = {\n /** The index.ts barrel export file that re-exports Client and types */\n index: string;\n /** The types.ts file containing TypeScript interfaces for contract structs, enums, and unions */\n types: string;\n /** The client.ts file containing the generated Client class with typed methods */\n client: string;\n /** The package.json for the generated npm package */\n packageJson: string;\n /** The tsconfig.json for TypeScript compilation */\n tsConfig: string;\n /** The README.md with usage documentation */\n readme: string;\n /** The .gitignore file for the generated package */\n gitignore: string;\n /**\n * Notes about events whose generated names need attention (duplicate\n * declarations or collision-driven renames); empty when there are none\n */\n diagnostics: EventDiagnostic[];\n};\n\n/**\n * Generates TypeScript bindings for Stellar smart contracts.\n *\n * This class creates fully-typed TypeScript client code from a contract's specification,\n * allowing developers to interact with Stellar smart contracts with full IDE support\n * and compile-time type checking.\n *\n * @example\n * ```ts\n * // Create from a local WASM file\n * const wasmBuffer = fs.readFileSync(\"./my_contract.wasm\");\n * const generator = await BindingGenerator.fromWasm(wasmBuffer);\n * const bindings = generator.generate({ contractName: \"my-contract\" });\n * ```\n *\n * @example\n * ```ts\n * // Create from a contract deployed on the network\n * const generator = await BindingGenerator.fromContractId(\n * \"CABC...XYZ\",\n * \"https://soroban-testnet.stellar.org\",\n * Networks.TESTNET\n * );\n * const bindings = generator.generate({ contractName: \"my-contract\" });\n * ```\n *\n * @example\n * ```ts\n * // Create from a Spec object directly\n * const spec = new Spec(specEntries);\n * const generator = BindingGenerator.fromSpec(spec);\n * const bindings = generator.generate({ contractName: \"my-contract\" });\n * ```\n */\nexport class BindingGenerator {\n private spec: Spec;\n\n /**\n * Private constructor - use static factory methods instead.\n *\n * @param spec - The parsed contract specification\n */\n private constructor(spec: Spec) {\n this.spec = spec;\n }\n\n /**\n * Creates a BindingGenerator from an existing Spec object.\n *\n * Use this when you already have a parsed contract specification,\n * such as from manually constructed spec entries or from another source.\n *\n * @param spec - The contract specification containing function and type definitions\n * @returns A new BindingGenerator instance\n *\n * @example\n * ```ts\n * const spec = new Spec(specEntries);\n * const generator = BindingGenerator.fromSpec(spec);\n * ```\n */\n static fromSpec(spec: Spec): BindingGenerator {\n return new BindingGenerator(spec);\n }\n\n /**\n * Creates a BindingGenerator from a WASM binary buffer.\n *\n * Parses the contract specification directly from the WASM file's custom section.\n * This is the most common method when working with locally compiled contracts.\n *\n * @param wasmBuffer - The raw WASM binary as a Buffer\n * @returns A Promise resolving to a new BindingGenerator instance\n * @throws If the WASM file doesn't contain a valid contract spec\n *\n * @example\n * ```ts\n * const wasmBuffer = fs.readFileSync(\"./target/wasm32-unknown-unknown/release/my_contract.wasm\");\n * const generator = await BindingGenerator.fromWasm(wasmBuffer);\n * ```\n */\n static fromWasm(wasmBuffer: Buffer): BindingGenerator {\n const spec = new Spec(specFromWasm(wasmBuffer));\n return new BindingGenerator(spec);\n }\n\n /**\n * Creates a BindingGenerator by fetching WASM from the network using its hash.\n *\n * Retrieves the WASM bytecode from Stellar RPC using the WASM hash,\n * then parses the contract specification from it. Useful when you know\n * the hash of an installed WASM but don't have the binary locally.\n *\n * @param wasmHash - The hex-encoded hash of the installed WASM blob\n * @param rpcServer - The Stellar RPC server instance\n * @returns A Promise resolving to a new BindingGenerator instance\n * @throws If the WASM cannot be fetched or doesn't contain a valid spec\n *\n * @example\n * ```ts\n * const generator = await BindingGenerator.fromWasmHash(\n * \"a1b2c3...xyz\",\n * \"https://soroban-testnet.stellar.org\",\n * Networks.TESTNET\n * );\n * ```\n */\n static async fromWasmHash(\n wasmHash: string,\n rpcServer: Server,\n ): Promise<BindingGenerator> {\n const wasm = await fetchFromWasmHash(wasmHash, rpcServer);\n if (wasm.type !== \"wasm\") {\n throw new Error(\"Fetched contract is not of type 'wasm'\");\n }\n return BindingGenerator.fromWasm(wasm.wasmBytes);\n }\n\n /**\n * Creates a BindingGenerator by fetching contract info from a deployed contract ID.\n *\n * Retrieves the contract's WASM from the network using the contract ID,\n * then parses the specification. If the contract is a Stellar Asset Contract (SAC),\n * returns a generator with the standard SAC specification.\n *\n * @param contractId - The contract ID (C... address) of the deployed contract\n * @param rpcServer - The Stellar RPC server instance\n * @returns A Promise resolving to a new BindingGenerator instance\n * @throws If the contract cannot be found or fetched\n *\n * @example\n * ```ts\n * const generator = await BindingGenerator.fromContractId(\n * \"CABC123...XYZ\",\n * rpcServer\n * );\n * ```\n */\n static async fromContractId(\n contractId: string,\n rpcServer: Server,\n ): Promise<BindingGenerator> {\n const result = await fetchFromContractId(contractId, rpcServer);\n if (result.type === \"wasm\") {\n return BindingGenerator.fromWasm(result.wasmBytes);\n }\n // Stellar Asset Contract\n const spec = new Spec(SAC_SPEC);\n return BindingGenerator.fromSpec(spec);\n }\n\n /**\n * Generates TypeScript bindings for the contract.\n *\n * Produces all the files needed for a standalone npm package:\n * - `client.ts`: A typed Client class with methods for each contract function\n * - `types.ts`: TypeScript interfaces for all contract types (structs, enums, unions)\n * - `index.ts`: Barrel export file\n * - `package.json`, `tsconfig.json`, `README.md`, `.gitignore`: Package configuration\n *\n * The generated code does not write to disk - use the returned strings\n * to write files as needed.\n *\n * @param options - Configuration options for generation\n * - `contractName`: Required. The name for the generated package (kebab-case recommended)\n * @returns An object containing all generated file contents as strings\n * @throws If contractName is missing or empty\n *\n * @example\n * ```ts\n * const bindings = generator.generate({\n * contractName: \"my-token\",\n * contractAddress: \"CABC...XYZ\",\n * rpcUrl: \"https://soroban-testnet.stellar.org\",\n * networkPassphrase: Networks.TESTNET\n * });\n *\n * // Write files to disk\n * fs.writeFileSync(\"./src/client.ts\", bindings.client);\n * fs.writeFileSync(\"./src/types.ts\", bindings.types);\n * ```\n */\n generate(options: GenerateOptions): GeneratedBindings {\n this.validateOptions(options);\n\n const typeGenerator = new TypeGenerator(this.spec);\n const clientGenerator = new ClientGenerator(this.spec);\n\n const types = typeGenerator.generate();\n const client = clientGenerator.generate();\n const diagnostics = this.eventDiagnostics(typeGenerator, clientGenerator);\n\n let index = `export { Client } from \"./client.js\";`;\n if (types.trim() !== \"\") {\n index = index.concat(`\\nexport * from \"./types.js\";`);\n }\n\n // Generate config files\n const configGenerator = new ConfigGenerator();\n const { packageJson, tsConfig, readme, gitignore } =\n configGenerator.generate(options);\n\n return {\n index,\n types,\n client,\n packageJson,\n tsConfig,\n readme,\n gitignore,\n diagnostics,\n };\n }\n\n /**\n * Collect an {@link EventDiagnostic} for every event that a user should\n * review in the generated output: duplicate declarations of the same raw\n * name, and generated names renamed away from their preferred form to\n * avoid a collision.\n */\n private eventDiagnostics(\n typeGenerator: TypeGenerator,\n clientGenerator: ClientGenerator,\n ): EventDiagnostic[] {\n const events = this.spec.events();\n const interfaceNames = typeGenerator.eventInterfaceNamesInOrder();\n const filterMethodNames = clientGenerator.eventFilterMethodNamesInOrder();\n\n const declarationCounts = new Map<string, number>();\n events.forEach((event) => {\n const rawName = event.name().toString();\n declarationCounts.set(rawName, (declarationCounts.get(rawName) ?? 0) + 1);\n });\n\n const occurrenceSoFar = new Map<string, number>();\n return events.flatMap((event, eventIndex) => {\n const rawName = event.name().toString();\n const occurrence = occurrenceSoFar.get(rawName) ?? 0;\n occurrenceSoFar.set(rawName, occurrence + 1);\n\n const declarations = declarationCounts.get(rawName)!;\n const sanitized = sanitizeIdentifier(rawName);\n const interfaceRenamed =\n interfaceNames[eventIndex] !== `${toPascalCase(sanitized)}Event`;\n const filterMethodRenamed =\n filterMethodNames[eventIndex] !==\n `${toCamelCase(sanitized)}EventFilter`;\n\n if (declarations <= 1 && !interfaceRenamed && !filterMethodRenamed) {\n return [];\n }\n return [\n {\n rawName,\n occurrence,\n declarations,\n interfaceName: interfaceNames[eventIndex],\n filterMethodName: filterMethodNames[eventIndex],\n interfaceRenamed,\n filterMethodRenamed,\n },\n ];\n });\n }\n\n /**\n * Validates that required generation options are provided.\n *\n * @param options - The options to validate\n * @throws If contractName is missing or empty\n */\n private validateOptions(options: GenerateOptions): void {\n if (!options.contractName || options.contractName.trim() === \"\") {\n throw new Error(\"contractName is required and cannot be empty\");\n }\n }\n}\n"],"names":["spec","Spec","specFromWasm","fetchFromWasmHash","fetchFromContractId","SAC_SPEC","TypeGenerator","ClientGenerator","types","client","ConfigGenerator","sanitizeIdentifier","toPascalCase","toCamelCase"],"mappings":";;;;;;;;;;;;;;;;;;AA0GO,MAAM,gBAAA,CAAiB;AAAA,EACpB,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,YAAY,IAAA,EAAY;AAC9B,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,OAAO,SAAS,IAAA,EAA8B;AAC5C,IAAA,OAAO,IAAI,iBAAiB,IAAI,CAAA;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBA,OAAO,SAAS,UAAA,EAAsC;AACpD,IAAA,MAAMA,MAAA,GAAO,IAAIC,SAAA,CAAKC,6BAAA,CAAa,UAAU,CAAC,CAAA;AAC9C,IAAA,OAAO,IAAI,iBAAiBF,MAAI,CAAA;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAuBA,aAAa,YAAA,CACX,QAAA,EACA,SAA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M,IAAI,MAAM,8CAA8C,CAAA;AAAA,IAChE;AAAA,EACF;AACF;;;;"}
|
|
@@ -24,6 +24,11 @@ var utils = require('./utils.js');
|
|
|
24
24
|
|
|
25
25
|
class TypeGenerator {
|
|
26
26
|
spec;
|
|
27
|
+
// event index (in event-entry declaration order) -> resolved (possibly
|
|
28
|
+
// disambiguated) interface name. Keyed by index rather than raw name
|
|
29
|
+
// because a contract may declare several events with the same name.
|
|
30
|
+
// Lazily computed on first use; see resolveEventInterfaceNames().
|
|
31
|
+
eventInterfaceNames = null;
|
|
27
32
|
constructor(spec) {
|
|
28
33
|
this.spec = spec;
|
|
29
34
|
}
|
|
@@ -31,11 +36,16 @@ class TypeGenerator {
|
|
|
31
36
|
* Generate all TypeScript type definitions
|
|
32
37
|
*/
|
|
33
38
|
generate() {
|
|
34
|
-
|
|
39
|
+
let eventIndex = 0;
|
|
40
|
+
const types = this.spec.entries.map(
|
|
41
|
+
(entry) => entry.switch() === curr_generated.default.ScSpecEntryKind.scSpecEntryEventV0() ? this.generateEvent(entry.eventV0(), eventIndex++) : this.generateEntry(entry)
|
|
42
|
+
).filter((t) => t).join("\n\n");
|
|
35
43
|
const imports = this.generateImports();
|
|
44
|
+
const eventUnion = this.generateContractEventUnion();
|
|
36
45
|
return `${imports}
|
|
37
46
|
|
|
38
47
|
${types}
|
|
48
|
+
${eventUnion}
|
|
39
49
|
`;
|
|
40
50
|
}
|
|
41
51
|
/**
|
|
@@ -54,6 +64,8 @@ class TypeGenerator {
|
|
|
54
64
|
return this.generateEnum(entry.udtEnumV0());
|
|
55
65
|
case curr_generated.default.ScSpecEntryKind.scSpecEntryUdtErrorEnumV0():
|
|
56
66
|
return this.generateErrorEnum(entry.udtErrorEnumV0());
|
|
67
|
+
// Events are handled directly in generate(), which numbers them in
|
|
68
|
+
// declaration order.
|
|
57
69
|
default:
|
|
58
70
|
return null;
|
|
59
71
|
}
|
|
@@ -75,6 +87,8 @@ class TypeGenerator {
|
|
|
75
87
|
return [];
|
|
76
88
|
case curr_generated.default.ScSpecEntryKind.scSpecEntryUdtErrorEnumV0():
|
|
77
89
|
return [];
|
|
90
|
+
case curr_generated.default.ScSpecEntryKind.scSpecEntryEventV0():
|
|
91
|
+
return entry.eventV0().params().map((param) => param.type());
|
|
78
92
|
default:
|
|
79
93
|
return [];
|
|
80
94
|
}
|
|
@@ -194,6 +208,142 @@ ${members}
|
|
|
194
208
|
value: enumCase.value()
|
|
195
209
|
};
|
|
196
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Compute the exported TS interface name for an event, e.g. "transfer"
|
|
213
|
+
* becomes "TransferEvent". Resolved (and disambiguated if necessary) via
|
|
214
|
+
* {@link resolveEventInterfaceNames}, so every call site agrees.
|
|
215
|
+
*/
|
|
216
|
+
eventInterfaceName(event, eventIndex) {
|
|
217
|
+
const resolved = this.resolveEventInterfaceNames().get(eventIndex);
|
|
218
|
+
if (resolved === void 0) {
|
|
219
|
+
return `${utils.toPascalCase(utils.sanitizeIdentifier(event.name().toString()))}Event`;
|
|
220
|
+
}
|
|
221
|
+
return resolved;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* The resolved (possibly disambiguated) interface name of every event in
|
|
225
|
+
* the spec, in declaration order. Exposed so callers (e.g. the bindings
|
|
226
|
+
* generator's diagnostics) can report renames and duplicates.
|
|
227
|
+
*/
|
|
228
|
+
eventInterfaceNamesInOrder() {
|
|
229
|
+
return this.spec.events().map((event, eventIndex) => this.eventInterfaceName(event, eventIndex));
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* True if the given event's resolved interface name differs from its
|
|
233
|
+
* preferred (unsuffixed) form, i.e. it was disambiguated away from a
|
|
234
|
+
* collision.
|
|
235
|
+
*/
|
|
236
|
+
eventInterfaceNameWasRenamed(event, eventIndex) {
|
|
237
|
+
const preferred = `${utils.toPascalCase(utils.sanitizeIdentifier(event.name().toString()))}Event`;
|
|
238
|
+
return this.eventInterfaceName(event, eventIndex) !== preferred;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* The name-normalization used for event interface names (and UDT type
|
|
242
|
+
* names) is not injective — e.g. events "FooBar" and "foo_bar" both
|
|
243
|
+
* produce the interface name "FooBarEvent", a contract may declare
|
|
244
|
+
* several events with the very same name (composed modules each emitting
|
|
245
|
+
* their own "transfer"), and an event can just as easily collide with a
|
|
246
|
+
* UDT (struct/union/enum) of the same generated name. Since UDT/function
|
|
247
|
+
* names are load-bearing (referenced directly in signatures) and
|
|
248
|
+
* event-derived names are already synthetic, UDT names always win: they
|
|
249
|
+
* are reserved first, in spec-entry order. Events are then resolved in
|
|
250
|
+
* spec-entry order, appending the smallest integer 2 or greater needed to
|
|
251
|
+
* make the name unique (and reserving whatever name results, so later
|
|
252
|
+
* events see it too). This is deterministic for a given spec.
|
|
253
|
+
*/
|
|
254
|
+
resolveEventInterfaceNames() {
|
|
255
|
+
if (this.eventInterfaceNames !== null) {
|
|
256
|
+
return this.eventInterfaceNames;
|
|
257
|
+
}
|
|
258
|
+
const reserved = /* @__PURE__ */ new Set(["ContractEvent"]);
|
|
259
|
+
for (const entry of this.spec.entries) {
|
|
260
|
+
switch (entry.switch()) {
|
|
261
|
+
case curr_generated.default.ScSpecEntryKind.scSpecEntryUdtStructV0():
|
|
262
|
+
reserved.add(
|
|
263
|
+
utils.sanitizeIdentifier(entry.udtStructV0().name().toString())
|
|
264
|
+
);
|
|
265
|
+
break;
|
|
266
|
+
case curr_generated.default.ScSpecEntryKind.scSpecEntryUdtUnionV0():
|
|
267
|
+
reserved.add(
|
|
268
|
+
utils.sanitizeIdentifier(entry.udtUnionV0().name().toString())
|
|
269
|
+
);
|
|
270
|
+
break;
|
|
271
|
+
case curr_generated.default.ScSpecEntryKind.scSpecEntryUdtEnumV0():
|
|
272
|
+
reserved.add(utils.sanitizeIdentifier(entry.udtEnumV0().name().toString()));
|
|
273
|
+
break;
|
|
274
|
+
case curr_generated.default.ScSpecEntryKind.scSpecEntryUdtErrorEnumV0():
|
|
275
|
+
reserved.add(
|
|
276
|
+
utils.sanitizeIdentifier(entry.udtErrorEnumV0().name().toString())
|
|
277
|
+
);
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
const resolved = /* @__PURE__ */ new Map();
|
|
282
|
+
let eventIndex = 0;
|
|
283
|
+
for (const entry of this.spec.entries) {
|
|
284
|
+
if (entry.switch() !== curr_generated.default.ScSpecEntryKind.scSpecEntryEventV0()) {
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
const event = entry.eventV0();
|
|
288
|
+
const preferred = `${utils.toPascalCase(utils.sanitizeIdentifier(event.name().toString()))}Event`;
|
|
289
|
+
let candidate = preferred;
|
|
290
|
+
let suffix = 2;
|
|
291
|
+
while (reserved.has(candidate)) {
|
|
292
|
+
candidate = `${preferred}${suffix}`;
|
|
293
|
+
suffix += 1;
|
|
294
|
+
}
|
|
295
|
+
reserved.add(candidate);
|
|
296
|
+
resolved.set(eventIndex, candidate);
|
|
297
|
+
eventIndex += 1;
|
|
298
|
+
}
|
|
299
|
+
this.eventInterfaceNames = resolved;
|
|
300
|
+
return resolved;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Generate TypeScript interface for a Soroban contract event
|
|
304
|
+
*/
|
|
305
|
+
generateEvent(event, eventIndex) {
|
|
306
|
+
const rawName = event.name().toString();
|
|
307
|
+
const name = this.eventInterfaceName(event, eventIndex);
|
|
308
|
+
const preferred = `${utils.toPascalCase(utils.sanitizeIdentifier(rawName))}Event`;
|
|
309
|
+
const renameNote = this.eventInterfaceNameWasRenamed(event, eventIndex) ? `
|
|
310
|
+
|
|
311
|
+
Note: renamed from "${preferred}" to avoid a collision with another generated name.` : "";
|
|
312
|
+
const doc = utils.formatJSDocComment(
|
|
313
|
+
(event.doc().toString() || `Event: ${rawName}`) + renameNote,
|
|
314
|
+
0
|
|
315
|
+
);
|
|
316
|
+
const fieldKey = (rawParamName) => /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(rawParamName) ? rawParamName : `"${utils.escapeStringLiteral(rawParamName)}"`;
|
|
317
|
+
const dataIsMapFormat = event.dataFormat().value === curr_generated.default.ScSpecEventDataFormat.scSpecEventDataFormatMap().value;
|
|
318
|
+
const dataFields = event.params().map((param) => {
|
|
319
|
+
const fieldName = fieldKey(param.name().toString());
|
|
320
|
+
const fieldType = utils.parseTypeFromTypeDef(param.type());
|
|
321
|
+
const fieldDoc = utils.formatJSDocComment(param.doc().toString(), 4);
|
|
322
|
+
const optional = dataIsMapFormat && param.location().value === curr_generated.default.ScSpecEventParamLocationV0.scSpecEventParamLocationData().value;
|
|
323
|
+
return `${fieldDoc} ${fieldName}${optional ? "?" : ""}: ${fieldType};`;
|
|
324
|
+
}).join("\n");
|
|
325
|
+
return `${doc}export interface ${name} {
|
|
326
|
+
name: "${utils.escapeStringLiteral(rawName)}";
|
|
327
|
+
data: {
|
|
328
|
+
${dataFields}
|
|
329
|
+
};
|
|
330
|
+
}`;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Generate the discriminated union of all contract events, if the spec defines any.
|
|
334
|
+
*/
|
|
335
|
+
generateContractEventUnion() {
|
|
336
|
+
const eventEntries = this.spec.entries.filter(
|
|
337
|
+
(entry) => entry.switch() === curr_generated.default.ScSpecEntryKind.scSpecEntryEventV0()
|
|
338
|
+
);
|
|
339
|
+
if (eventEntries.length === 0) {
|
|
340
|
+
return "";
|
|
341
|
+
}
|
|
342
|
+
const names = eventEntries.map(
|
|
343
|
+
(entry, eventIndex) => this.eventInterfaceName(entry.eventV0(), eventIndex)
|
|
344
|
+
);
|
|
345
|
+
return `export type ContractEvent = ${names.join(" | ")};`;
|
|
346
|
+
}
|
|
197
347
|
generateTupleStruct(udtStruct) {
|
|
198
348
|
const name = utils.sanitizeIdentifier(udtStruct.name().toString());
|
|
199
349
|
const doc = utils.formatJSDocComment(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sources":["../../../src/bindings/types.ts"],"sourcesContent":["import { xdr } from \"../base/index.js\";\nimport { Spec } from \"../contract/index.js\";\nimport {\n parseTypeFromTypeDef,\n generateTypeImports,\n sanitizeIdentifier,\n escapeStringLiteral,\n formatJSDocComment,\n formatImports,\n isTupleStruct,\n} from \"./utils.js\";\n\n/**\n * Interface for struct fields\n */\nexport interface StructField {\n doc: string;\n name: string;\n type: string;\n}\n\n/**\n * Interface for union cases\n */\nexport interface UnionCase {\n doc: string;\n name: string;\n types: string[];\n}\n\n/**\n * Interface for enum cases\n */\nexport interface EnumCase {\n doc: string;\n name: string;\n value: number;\n}\n\n/**\n * Generates TypeScript type definitions from Stellar contract specs\n */\nexport class TypeGenerator {\n private spec: Spec;\n\n constructor(spec: Spec) {\n this.spec = spec;\n }\n\n /**\n * Generate all TypeScript type definitions\n */\n generate(): string {\n // Generate types for each entry in the spec\n const types = this.spec.entries\n .map((entry) => this.generateEntry(entry))\n .filter((t) => t)\n .join(\"\\n\\n\");\n // Generate imports for all types\n const imports = this.generateImports();\n\n return `${imports}\n\n ${types}\n `;\n }\n\n /**\n * Generate TypeScript for a single spec entry\n */\n private generateEntry(entry: xdr.ScSpecEntry): string | null {\n switch (entry.switch()) {\n case xdr.ScSpecEntryKind.scSpecEntryUdtStructV0():\n if (isTupleStruct(entry.udtStructV0())) {\n return this.generateTupleStruct(entry.udtStructV0());\n }\n return this.generateStruct(entry.udtStructV0());\n case xdr.ScSpecEntryKind.scSpecEntryUdtUnionV0():\n return this.generateUnion(entry.udtUnionV0());\n case xdr.ScSpecEntryKind.scSpecEntryUdtEnumV0():\n return this.generateEnum(entry.udtEnumV0());\n case xdr.ScSpecEntryKind.scSpecEntryUdtErrorEnumV0():\n return this.generateErrorEnum(entry.udtErrorEnumV0());\n default:\n return null;\n }\n }\n\n private generateImports(): string {\n const imports = generateTypeImports(\n this.spec.entries.flatMap((entry) => {\n switch (entry.switch()) {\n case xdr.ScSpecEntryKind.scSpecEntryUdtStructV0():\n return entry\n .udtStructV0()\n .fields()\n .map((field) => field.type());\n case xdr.ScSpecEntryKind.scSpecEntryUdtUnionV0():\n return entry\n .udtUnionV0()\n .cases()\n .flatMap((unionCase) => {\n if (\n unionCase.switch() ===\n xdr.ScSpecUdtUnionCaseV0Kind.scSpecUdtUnionCaseTupleV0()\n ) {\n return unionCase.tupleCase().type();\n }\n return [];\n });\n case xdr.ScSpecEntryKind.scSpecEntryUdtEnumV0():\n // Enums do not have associated types\n return [];\n case xdr.ScSpecEntryKind.scSpecEntryUdtErrorEnumV0():\n // Enums do not have associated types\n return [];\n default:\n return [];\n }\n }),\n );\n\n return formatImports(imports, {\n includeTypeFileImports: false, // Types file doesn't import from itself\n });\n }\n\n /**\n * Generate TypeScript interface for a struct\n */\n private generateStruct(struct: xdr.ScSpecUdtStructV0): string {\n const name = sanitizeIdentifier(struct.name().toString());\n const doc = formatJSDocComment(\n struct.doc().toString() || `Struct: ${name}`,\n 0,\n );\n\n const fields = struct\n .fields()\n .map((field) => {\n const fieldName = sanitizeIdentifier(field.name().toString());\n const fieldType = parseTypeFromTypeDef(field.type());\n const fieldDoc = formatJSDocComment(field.doc().toString(), 2);\n\n return `${fieldDoc} ${fieldName}: ${fieldType};`;\n })\n .join(\"\\n\");\n\n return `${doc}export interface ${name} {\n${fields}\n}`;\n }\n\n /**\n * Generate TypeScript union type\n */\n private generateUnion(union: xdr.ScSpecUdtUnionV0): string {\n const name = sanitizeIdentifier(union.name().toString());\n const doc = formatJSDocComment(\n union.doc().toString() || `Union: ${name}`,\n 0,\n );\n const cases = union\n .cases()\n .map((unionCase) => this.generateUnionCase(unionCase));\n\n const caseTypes = cases\n .map((c) => {\n if (c.types.length > 0) {\n return `${formatJSDocComment(c.doc, 2)} { tag: \"${escapeStringLiteral(c.name)}\"; values: readonly [${c.types.join(\", \")}] }`;\n }\n return `${formatJSDocComment(c.doc, 2)} { tag: \"${escapeStringLiteral(c.name)}\"; values: void }`;\n })\n .join(\" |\\n\");\n\n return `${doc} export type ${name} =\n${caseTypes};`;\n }\n\n /**\n * Generate TypeScript enum\n */\n private generateEnum(enumEntry: xdr.ScSpecUdtEnumV0): string {\n const name = sanitizeIdentifier(enumEntry.name().toString());\n const doc = formatJSDocComment(\n enumEntry.doc().toString() || `Enum: ${name}`,\n 0,\n );\n\n const members = enumEntry\n .cases()\n .map((enumCase) => {\n const caseName = sanitizeIdentifier(enumCase.name().toString());\n const caseValue = enumCase.value();\n const caseDoc = enumCase.doc().toString() || `Enum Case: ${caseName}`;\n\n return `${formatJSDocComment(caseDoc, 2)} ${caseName} = ${caseValue}`;\n })\n .join(\",\\n\");\n\n return `${doc}export enum ${name} {\n${members}\n}`;\n }\n\n /**\n * Generate TypeScript error enum\n */\n private generateErrorEnum(errorEnum: xdr.ScSpecUdtErrorEnumV0): string {\n const name = sanitizeIdentifier(errorEnum.name().toString());\n const doc = formatJSDocComment(\n errorEnum.doc().toString() || `Error Enum: ${name}`,\n 0,\n );\n const cases = errorEnum\n .cases()\n .map((enumCase) => this.generateEnumCase(enumCase));\n\n const members = cases\n .map((c) => {\n return `${formatJSDocComment(c.doc, 2)} ${c.value} : { message: \"${escapeStringLiteral(c.name)}\" }`;\n })\n .join(\",\\n\");\n\n return `${doc}export const ${name} = {\n${members}\n}`;\n }\n\n /**\n * Generate union case\n */\n private generateUnionCase(unionCase: xdr.ScSpecUdtUnionCaseV0): UnionCase {\n switch (unionCase.switch()) {\n case xdr.ScSpecUdtUnionCaseV0Kind.scSpecUdtUnionCaseVoidV0(): {\n const voidCase = unionCase.voidCase();\n return {\n doc: voidCase.doc().toString(),\n name: voidCase.name().toString(),\n types: [],\n };\n }\n case xdr.ScSpecUdtUnionCaseV0Kind.scSpecUdtUnionCaseTupleV0(): {\n const tupleCase = unionCase.tupleCase();\n return {\n doc: tupleCase.doc().toString(),\n name: tupleCase.name().toString(),\n types: tupleCase.type().map((t) => parseTypeFromTypeDef(t)),\n };\n }\n default:\n throw new Error(`Unknown union case kind: ${unionCase.switch()}`);\n }\n }\n\n /**\n * Generate enum case\n */\n private generateEnumCase(enumCase: xdr.ScSpecUdtEnumCaseV0): EnumCase {\n return {\n doc: enumCase.doc().toString(),\n name: enumCase.name().toString(),\n value: enumCase.value(),\n };\n }\n\n private generateTupleStruct(udtStruct: xdr.ScSpecUdtStructV0): string {\n const name = sanitizeIdentifier(udtStruct.name().toString());\n const doc = formatJSDocComment(\n udtStruct.doc().toString() || `Tuple Struct: ${name}`,\n 0,\n );\n\n const types = udtStruct\n .fields()\n .map((field) => parseTypeFromTypeDef(field.type()))\n .join(\", \");\n\n return `${doc}export type ${name} = readonly [${types}];`;\n }\n}\n"],"names":["xdr","isTupleStruct","generateTypeImports","formatImports","sanitizeIdentifier","formatJSDocComment","parseTypeFromTypeDef","escapeStringLiteral"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA0CO,MAAM,aAAA,CAAc;AAAA,EACjB,IAAA;AAAA,EAER,YAAY,IAAA,EAAY;AACtB,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,QAAA,GAAmB;AAEjB,IAAA,MAAM,QAAQ,IAAA,CAAK,IAAA,CAAK,QACrB,GAAA,CAAI,CAAC,UAAU,IAAA,CAAK,aAAA,CAAc,KAAK,CAAC,EACxC,MAAA,CAAO,CAAC,MAAM,CAAC,CAAA,CACf,KAAK,MAAM,CAAA;AAEd,IAAA,MAAM,OAAA,GAAU,KAAK,eAAA,EAAgB;AAErC,IAAA,OAAO,GAAG,OAAO;;AAAA,IAAA,EAEf,KAAK;AAAA,IAAA,CAAA;AAAA,EAET;AAAA;AAAA;AAAA;AAAA,EAKQ,cAAc,KAAA,EAAuC;AAC3D,IAAA,QAAQ,KAAA,CAAM,QAAO;AAAG,MACtB,KAAKA,sBAAA,CAAI,eAAA,CAAgB,sBAAA,EAAuB;AAC9C,QAAA,IAAIC,mBAAA,CAAc,KAAA,CAAM,WAAA,EAAa,CAAA,EAAG;AACtC,UAAA,OAAO,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B,SAAA,CAAU,MAAA,EAAQ,CAAA,CAAE,CAAA;AAAA;AACpE,EACF;AAAA;AAAA;AAAA;AAAA,EAKQ,iBAAiB,QAAA,EAA6C;AACpE,IAAA,OAAO;AAAA,MACL,GAAA,EAAK,QAAA,CAAS,GAAA,EAAI,CAAE,QAAA,EAAS;AAAA,MAC7B,IAAA,EAAM,QAAA,CAAS,IAAA,EAAK,CAAE,QAAA,EAAS;AAAA,MAC/B,KAAA,EAAO,SAAS,KAAA;AAAM,KACxB;AAAA,EACF;AAAA,EAEQ,oBAAoB,SAAA,EAA0C;AACpE,IAAA,MAAM,OAAOF,wBAAA,CAAmB,SAAA,CAAU,IAAA,EAAK,CAAE,UAAU,CAAA;AAC3D,IAAA,MAAM,GAAA,GAAMC,wBAAA;AAAA,MACV,UAAU,GAAA,EAAI,CAAE,QAAA,EAAS,IAAK,iBAAiB,IAAI,CAAA,CAAA;AAAA,MACnD;AAAA,KACF;AAEA,IAAA,MAAM,KAAA,GAAQ,SAAA,CACX,MAAA,EAAO,CACP,IAAI,CAAC,KAAA,KAAUC,0BAAA,CAAqB,KAAA,CAAM,IAAA,EAAM,CAAC,CAAA,CACjD,KAAK,IAAI,CAAA;AAEZ,IAAA,OAAO,CAAA,EAAG,GAAG,CAAA,YAAA,EAAe,IAAI,gBAAgB,KAAK,CAAA,EAAA,CAAA;AAAA,EACvD;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../../../src/bindings/types.ts"],"sourcesContent":["import { xdr } from \"../base/index.js\";\nimport { Spec } from \"../contract/index.js\";\nimport {\n parseTypeFromTypeDef,\n generateTypeImports,\n sanitizeIdentifier,\n escapeStringLiteral,\n formatJSDocComment,\n formatImports,\n isTupleStruct,\n toPascalCase,\n} from \"./utils.js\";\n\n/**\n * Interface for struct fields\n */\nexport interface StructField {\n doc: string;\n name: string;\n type: string;\n}\n\n/**\n * Interface for union cases\n */\nexport interface UnionCase {\n doc: string;\n name: string;\n types: string[];\n}\n\n/**\n * Interface for enum cases\n */\nexport interface EnumCase {\n doc: string;\n name: string;\n value: number;\n}\n\n/**\n * Generates TypeScript type definitions from Stellar contract specs\n */\nexport class TypeGenerator {\n private spec: Spec;\n\n // event index (in event-entry declaration order) -> resolved (possibly\n // disambiguated) interface name. Keyed by index rather than raw name\n // because a contract may declare several events with the same name.\n // Lazily computed on first use; see resolveEventInterfaceNames().\n private eventInterfaceNames: Map<number, string> | null = null;\n\n constructor(spec: Spec) {\n this.spec = spec;\n }\n\n /**\n * Generate all TypeScript type definitions\n */\n generate(): string {\n // Generate types for each entry in the spec. Events are numbered in\n // declaration order so same-named events resolve to distinct interfaces.\n let eventIndex = 0;\n const types = this.spec.entries\n .map((entry) =>\n entry.switch() === xdr.ScSpecEntryKind.scSpecEntryEventV0()\n ? this.generateEvent(entry.eventV0(), eventIndex++)\n : this.generateEntry(entry),\n )\n .filter((t) => t)\n .join(\"\\n\\n\");\n // Generate imports for all types\n const imports = this.generateImports();\n // Generate the discriminated union of all contract events, if any\n const eventUnion = this.generateContractEventUnion();\n\n return `${imports}\n\n ${types}\n ${eventUnion}\n `;\n }\n\n /**\n * Generate TypeScript for a single spec entry\n */\n private generateEntry(entry: xdr.ScSpecEntry): string | null {\n switch (entry.switch()) {\n case xdr.ScSpecEntryKind.scSpecEntryUdtStructV0():\n if (isTupleStruct(entry.udtStructV0())) {\n return this.generateTupleStruct(entry.udtStructV0());\n }\n return this.generateStruct(entry.udtStructV0());\n case xdr.ScSpecEntryKind.scSpecEntryUdtUnionV0():\n return this.generateUnion(entry.udtUnionV0());\n case xdr.ScSpecEntryKind.scSpecEntryUdtEnumV0():\n return this.generateEnum(entry.udtEnumV0());\n case xdr.ScSpecEntryKind.scSpecEntryUdtErrorEnumV0():\n return this.generateErrorEnum(entry.udtErrorEnumV0());\n // Events are handled directly in generate(), which numbers them in\n // declaration order.\n default:\n return null;\n }\n }\n\n private generateImports(): string {\n const imports = generateTypeImports(\n this.spec.entries.flatMap((entry) => {\n switch (entry.switch()) {\n case xdr.ScSpecEntryKind.scSpecEntryUdtStructV0():\n return entry\n .udtStructV0()\n .fields()\n .map((field) => field.type());\n case xdr.ScSpecEntryKind.scSpecEntryUdtUnionV0():\n return entry\n .udtUnionV0()\n .cases()\n .flatMap((unionCase) => {\n if (\n unionCase.switch() ===\n xdr.ScSpecUdtUnionCaseV0Kind.scSpecUdtUnionCaseTupleV0()\n ) {\n return unionCase.tupleCase().type();\n }\n return [];\n });\n case xdr.ScSpecEntryKind.scSpecEntryUdtEnumV0():\n // Enums do not have associated types\n return [];\n case xdr.ScSpecEntryKind.scSpecEntryUdtErrorEnumV0():\n // Enums do not have associated types\n return [];\n case xdr.ScSpecEntryKind.scSpecEntryEventV0():\n return entry\n .eventV0()\n .params()\n .map((param) => param.type());\n default:\n return [];\n }\n }),\n );\n\n return formatImports(imports, {\n includeTypeFileImports: false, // Types file doesn't import from itself\n });\n }\n\n /**\n * Generate TypeScript interface for a struct\n */\n private generateStruct(struct: xdr.ScSpecUdtStructV0): string {\n const name = sanitizeIdentifier(struct.name().toString());\n const doc = formatJSDocComment(\n struct.doc().toString() || `Struct: ${name}`,\n 0,\n );\n\n const fields = struct\n .fields()\n .map((field) => {\n const fieldName = sanitizeIdentifier(field.name().toString());\n const fieldType = parseTypeFromTypeDef(field.type());\n const fieldDoc = formatJSDocComment(field.doc().toString(), 2);\n\n return `${fieldDoc} ${fieldName}: ${fieldType};`;\n })\n .join(\"\\n\");\n\n return `${doc}export interface ${name} {\n${fields}\n}`;\n }\n\n /**\n * Generate TypeScript union type\n */\n private generateUnion(union: xdr.ScSpecUdtUnionV0): string {\n const name = sanitizeIdentifier(union.name().toString());\n const doc = formatJSDocComment(\n union.doc().toString() || `Union: ${name}`,\n 0,\n );\n const cases = union\n .cases()\n .map((unionCase) => this.generateUnionCase(unionCase));\n\n const caseTypes = cases\n .map((c) => {\n if (c.types.length > 0) {\n return `${formatJSDocComment(c.doc, 2)} { tag: \"${escapeStringLiteral(c.name)}\"; values: readonly [${c.types.join(\", \")}] }`;\n }\n return `${formatJSDocComment(c.doc, 2)} { tag: \"${escapeStringLiteral(c.name)}\"; values: void }`;\n })\n .join(\" |\\n\");\n\n return `${doc} export type ${name} =\n${caseTypes};`;\n }\n\n /**\n * Generate TypeScript enum\n */\n private generateEnum(enumEntry: xdr.ScSpecUdtEnumV0): string {\n const name = sanitizeIdentifier(enumEntry.name().toString());\n const doc = formatJSDocComment(\n enumEntry.doc().toString() || `Enum: ${name}`,\n 0,\n );\n\n const members = enumEntry\n .cases()\n .map((enumCase) => {\n const caseName = sanitizeIdentifier(enumCase.name().toString());\n const caseValue = enumCase.value();\n const caseDoc = enumCase.doc().toString() || `Enum Case: ${caseName}`;\n\n return `${formatJSDocComment(caseDoc, 2)} ${caseName} = ${caseValue}`;\n })\n .join(\",\\n\");\n\n return `${doc}export enum ${name} {\n${members}\n}`;\n }\n\n /**\n * Generate TypeScript error enum\n */\n private generateErrorEnum(errorEnum: xdr.ScSpecUdtErrorEnumV0): string {\n const name = sanitizeIdentifier(errorEnum.name().toString());\n const doc = formatJSDocComment(\n errorEnum.doc().toString() || `Error Enum: ${name}`,\n 0,\n );\n const cases = errorEnum\n .cases()\n .map((enumCase) => this.generateEnumCase(enumCase));\n\n const members = cases\n .map((c) => {\n return `${formatJSDocComment(c.doc, 2)} ${c.value} : { message: \"${escapeStringLiteral(c.name)}\" }`;\n })\n .join(\",\\n\");\n\n return `${doc}export const ${name} = {\n${members}\n}`;\n }\n\n /**\n * Generate union case\n */\n private generateUnionCase(unionCase: xdr.ScSpecUdtUnionCaseV0): UnionCase {\n switch (unionCase.switch()) {\n case xdr.ScSpecUdtUnionCaseV0Kind.scSpecUdtUnionCaseVoidV0(): {\n const voidCase = unionCase.voidCase();\n return {\n doc: voidCase.doc().toString(),\n name: voidCase.name().toString(),\n types: [],\n };\n }\n case xdr.ScSpecUdtUnionCaseV0Kind.scSpecUdtUnionCaseTupleV0(): {\n const tupleCase = unionCase.tupleCase();\n return {\n doc: tupleCase.doc().toString(),\n name: tupleCase.name().toString(),\n types: tupleCase.type().map((t) => parseTypeFromTypeDef(t)),\n };\n }\n default:\n throw new Error(`Unknown union case kind: ${unionCase.switch()}`);\n }\n }\n\n /**\n * Generate enum case\n */\n private generateEnumCase(enumCase: xdr.ScSpecUdtEnumCaseV0): EnumCase {\n return {\n doc: enumCase.doc().toString(),\n name: enumCase.name().toString(),\n value: enumCase.value(),\n };\n }\n\n /**\n * Compute the exported TS interface name for an event, e.g. \"transfer\"\n * becomes \"TransferEvent\". Resolved (and disambiguated if necessary) via\n * {@link resolveEventInterfaceNames}, so every call site agrees.\n */\n private eventInterfaceName(\n event: xdr.ScSpecEventV0,\n eventIndex: number,\n ): string {\n const resolved = this.resolveEventInterfaceNames().get(eventIndex);\n /* istanbul ignore next -- every event in the spec is reserved a name */\n if (resolved === undefined) {\n return `${toPascalCase(sanitizeIdentifier(event.name().toString()))}Event`;\n }\n return resolved;\n }\n\n /**\n * The resolved (possibly disambiguated) interface name of every event in\n * the spec, in declaration order. Exposed so callers (e.g. the bindings\n * generator's diagnostics) can report renames and duplicates.\n */\n eventInterfaceNamesInOrder(): string[] {\n return this.spec\n .events()\n .map((event, eventIndex) => this.eventInterfaceName(event, eventIndex));\n }\n\n /**\n * True if the given event's resolved interface name differs from its\n * preferred (unsuffixed) form, i.e. it was disambiguated away from a\n * collision.\n */\n private eventInterfaceNameWasRenamed(\n event: xdr.ScSpecEventV0,\n eventIndex: number,\n ): boolean {\n const preferred = `${toPascalCase(sanitizeIdentifier(event.name().toString()))}Event`;\n return this.eventInterfaceName(event, eventIndex) !== preferred;\n }\n\n /**\n * The name-normalization used for event interface names (and UDT type\n * names) is not injective — e.g. events \"FooBar\" and \"foo_bar\" both\n * produce the interface name \"FooBarEvent\", a contract may declare\n * several events with the very same name (composed modules each emitting\n * their own \"transfer\"), and an event can just as easily collide with a\n * UDT (struct/union/enum) of the same generated name. Since UDT/function\n * names are load-bearing (referenced directly in signatures) and\n * event-derived names are already synthetic, UDT names always win: they\n * are reserved first, in spec-entry order. Events are then resolved in\n * spec-entry order, appending the smallest integer 2 or greater needed to\n * make the name unique (and reserving whatever name results, so later\n * events see it too). This is deterministic for a given spec.\n */\n private resolveEventInterfaceNames(): Map<number, string> {\n if (this.eventInterfaceNames !== null) {\n return this.eventInterfaceNames;\n }\n // Reserve names that are already taken by UDTs and other special entries. ContractEvent is a special entry for the discriminated union of all events.\n const reserved = new Set<string>([\"ContractEvent\"]);\n\n for (const entry of this.spec.entries) {\n switch (entry.switch()) {\n case xdr.ScSpecEntryKind.scSpecEntryUdtStructV0():\n reserved.add(\n sanitizeIdentifier(entry.udtStructV0().name().toString()),\n );\n break;\n case xdr.ScSpecEntryKind.scSpecEntryUdtUnionV0():\n reserved.add(\n sanitizeIdentifier(entry.udtUnionV0().name().toString()),\n );\n break;\n case xdr.ScSpecEntryKind.scSpecEntryUdtEnumV0():\n reserved.add(sanitizeIdentifier(entry.udtEnumV0().name().toString()));\n break;\n case xdr.ScSpecEntryKind.scSpecEntryUdtErrorEnumV0():\n reserved.add(\n sanitizeIdentifier(entry.udtErrorEnumV0().name().toString()),\n );\n break;\n default:\n break;\n }\n }\n\n const resolved = new Map<number, string>();\n\n let eventIndex = 0;\n for (const entry of this.spec.entries) {\n if (entry.switch() !== xdr.ScSpecEntryKind.scSpecEntryEventV0()) {\n continue;\n }\n const event = entry.eventV0();\n const preferred = `${toPascalCase(sanitizeIdentifier(event.name().toString()))}Event`;\n\n let candidate = preferred;\n let suffix = 2;\n while (reserved.has(candidate)) {\n candidate = `${preferred}${suffix}`;\n suffix += 1;\n }\n\n reserved.add(candidate);\n resolved.set(eventIndex, candidate);\n eventIndex += 1;\n }\n\n this.eventInterfaceNames = resolved;\n return resolved;\n }\n\n /**\n * Generate TypeScript interface for a Soroban contract event\n */\n private generateEvent(event: xdr.ScSpecEventV0, eventIndex: number): string {\n const rawName = event.name().toString();\n const name = this.eventInterfaceName(event, eventIndex);\n const preferred = `${toPascalCase(sanitizeIdentifier(rawName))}Event`;\n const renameNote = this.eventInterfaceNameWasRenamed(event, eventIndex)\n ? `\\n\\nNote: renamed from \"${preferred}\" to avoid a collision with another generated name.`\n : \"\";\n const doc = formatJSDocComment(\n (event.doc().toString() || `Event: ${rawName}`) + renameNote,\n 0,\n );\n\n // parseEvent keys its output by the raw param names, so the interface\n // must use them too — quoted when they aren't valid identifiers.\n const fieldKey = (rawParamName: string): string =>\n /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(rawParamName)\n ? rawParamName\n : `\"${escapeStringLiteral(rawParamName)}\"`;\n\n // Map-format data entries may be absent from an emitted event's map, in\n // which case parseEvent omits the key — so those fields are optional.\n const dataIsMapFormat =\n event.dataFormat().value ===\n xdr.ScSpecEventDataFormat.scSpecEventDataFormatMap().value;\n\n // parseEvent merges topic-list and data-located params into a single\n // flat `data` record; generate one field per param in declaration order.\n const dataFields = event\n .params()\n .map((param) => {\n const fieldName = fieldKey(param.name().toString());\n const fieldType = parseTypeFromTypeDef(param.type());\n const fieldDoc = formatJSDocComment(param.doc().toString(), 4);\n const optional =\n dataIsMapFormat &&\n param.location().value ===\n xdr.ScSpecEventParamLocationV0.scSpecEventParamLocationData().value;\n\n return `${fieldDoc} ${fieldName}${optional ? \"?\" : \"\"}: ${fieldType};`;\n })\n .join(\"\\n\");\n\n return `${doc}export interface ${name} {\n name: \"${escapeStringLiteral(rawName)}\";\n data: {\n${dataFields}\n };\n}`;\n }\n\n /**\n * Generate the discriminated union of all contract events, if the spec defines any.\n */\n private generateContractEventUnion(): string {\n const eventEntries = this.spec.entries.filter(\n (entry) => entry.switch() === xdr.ScSpecEntryKind.scSpecEntryEventV0(),\n );\n\n if (eventEntries.length === 0) {\n return \"\";\n }\n\n const names = eventEntries.map((entry, eventIndex) =>\n this.eventInterfaceName(entry.eventV0(), eventIndex),\n );\n\n return `export type ContractEvent = ${names.join(\" | \")};`;\n }\n\n private generateTupleStruct(udtStruct: xdr.ScSpecUdtStructV0): string {\n const name = sanitizeIdentifier(udtStruct.name().toString());\n const doc = formatJSDocComment(\n udtStruct.doc().toString() || `Tuple Struct: ${name}`,\n 0,\n );\n\n const types = udtStruct\n .fields()\n .map((field) => parseTypeFromTypeDef(field.type()))\n .join(\", \");\n\n return `${doc}export type ${name} = readonly [${types}];`;\n }\n}\n"],"names":["xdr","isTupleStruct","generateTypeImports","formatImports","sanitizeIdentifier","formatJSDocComment","parseTypeFromTypeDef","escapeStringLiteral","toPascalCase"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA2CO,MAAM,aAAA,CAAc;AAAA,EACjB,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,mBAAA,GAAkD,IAAA;AAAA,EAE1D,YAAY,IAAA,EAAY;AACtB,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,QAAA,GAAmB;AAGjB,IAAA,IAAI,UAAA,GAAa,CAAA;AACjB,IAAA,MAAM,KAAA,GAAQ,IAAA,CAAK,IAAA,CAAK,OAAA,CACrB,GAAA;AAAA,MAAI,CAAC,KAAA,KACJ,KAAA,CAAM,QAAO,KAAMA,sBAAA,CAAI,gBAAgB,kBAAA,EAAmB,GACtD,IAAA,CAAK,aAAA,CAAc,MAAM,OAAA,EAAQ,EAAG,YAAY,CAAA,GAChD,IAAA,CAAK,cAAc,KAAK;AAAA,MAE7B,MAAA,CAAO,CAAC,MAAM,CAAC,CAAA,CACf,KAAK,MAAM,CAAA;AAEd,IAAA,MAAM,OAAA,GAAU,KAAK,eAAA,EAAgB;AAErC,IAAA,MAAM,UAAA,GAAa,KAAK,0BAAA,EAA2B;AAEnD,IAAA,OAAO,GAAG,OAAO;;AAAA,IAAA,EAEf,KAAK;AAAA,IAAA,EACL,UAAU;AAAA,IAAA,CAAA;AAAA,EAEd;AAAA;AAAA;AAAA;AAAA,EAKQ,cAAc,KAAA,EAAuC;AAC3D,IAAA,QAAQ,KAAA,CAAM,QAAO;AAAG,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F;AAEA,IAAA,MAAM,KAAA,GAAQ,SAAA,CACX,MAAA,EAAO,CACP,IAAI,CAAC,KAAA,KAAUC,0BAAA,CAAqB,KAAA,CAAM,IAAA,EAAM,CAAC,CAAA,CACjD,KAAK,IAAI,CAAA;AAEZ,IAAA,OAAO,CAAA,EAAG,GAAG,CAAA,YAAA,EAAe,IAAI,gBAAgB,KAAK,CAAA,EAAA,CAAA;AAAA,EACvD;AACF;;;;"}
|
|
@@ -304,6 +304,14 @@ ${lines.join("\n")}
|
|
|
304
304
|
${indent} */
|
|
305
305
|
`;
|
|
306
306
|
}
|
|
307
|
+
function toPascalCase(identifier) {
|
|
308
|
+
const pascal = identifier.split(/[_$]+/).filter((part) => part.length > 0).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
309
|
+
return pascal === "" ? "Unnamed" : pascal;
|
|
310
|
+
}
|
|
311
|
+
function toCamelCase(identifier) {
|
|
312
|
+
const pascal = toPascalCase(identifier);
|
|
313
|
+
return pascal.charAt(0).toLowerCase() + pascal.slice(1);
|
|
314
|
+
}
|
|
307
315
|
function isTupleStruct(udtStruct) {
|
|
308
316
|
const fields = udtStruct.fields();
|
|
309
317
|
return fields.every(
|
|
@@ -319,4 +327,6 @@ exports.isNameReserved = isNameReserved;
|
|
|
319
327
|
exports.isTupleStruct = isTupleStruct;
|
|
320
328
|
exports.parseTypeFromTypeDef = parseTypeFromTypeDef;
|
|
321
329
|
exports.sanitizeIdentifier = sanitizeIdentifier;
|
|
330
|
+
exports.toCamelCase = toCamelCase;
|
|
331
|
+
exports.toPascalCase = toPascalCase;
|
|
322
332
|
//# sourceMappingURL=utils.js.map
|