@avaprotocol/sdk-js 2.4.3 → 2.4.4

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.
@@ -1,6 +1,12 @@
1
1
  import * as avs_pb from "@/grpc_codegen/avs_pb";
2
2
  import Node from "./interface";
3
- import { NodeType, } from "@avaprotocol/types";
3
+ import CustomCodeNode from "./customCode";
4
+ import ETHTransferNode from "./ethTransfer";
5
+ import RestAPINode from "./restApi";
6
+ import GraphQLQueryNode from "./graphqlQuery";
7
+ import ContractReadNode from "./contractRead";
8
+ import ContractWriteNode from "./contractWrite";
9
+ import { NodeType, ExecutionMode, } from "@avaprotocol/types";
4
10
  import { convertInputToProtobuf, extractInputFromProtobuf } from "../../utils";
5
11
  class LoopNode extends Node {
6
12
  constructor(props) {
@@ -16,16 +22,13 @@ class LoopNode extends Node {
16
22
  const configData = loopNode.getConfig()?.toObject();
17
23
  const loopNodeData = loopNode.toObject();
18
24
  // Since LoopNodeData is now Config.AsObject, we need to merge the config properties
19
- // with the nested node data from the full object
25
+ // with the runner data from the protobuf structure
20
26
  const data = {
21
27
  ...configData,
22
- // Keep the nested node structures from the full object
23
- restApi: loopNodeData.restApi,
24
- customCode: loopNodeData.customCode,
25
- ethTransfer: loopNodeData.ethTransfer,
26
- contractRead: loopNodeData.contractRead,
27
- contractWrite: loopNodeData.contractWrite,
28
- graphqlDataQuery: loopNodeData.graphqlDataQuery,
28
+ // Extract runner data from the oneof runner field
29
+ runner: this.extractRunnerFromProtobuf(loopNodeData),
30
+ // Map execution mode from protobuf enum to ExecutionMode enum
31
+ executionMode: this.mapExecutionModeFromProtobuf(configData?.executionMode),
29
32
  };
30
33
  // Extract input data from top-level TaskNode.input field (not nested LoopNode.input)
31
34
  // This matches where we set it in toRequest() and where the Go backend looks for it
@@ -40,6 +43,65 @@ class LoopNode extends Node {
40
43
  input: input,
41
44
  });
42
45
  }
46
+ static extractRunnerFromProtobuf(loopNodeData) {
47
+ // Check which runner type is present in the oneof runner field
48
+ if (loopNodeData.restApi) {
49
+ return { type: "restApi", data: loopNodeData.restApi };
50
+ }
51
+ else if (loopNodeData.customCode) {
52
+ return { type: "customCode", data: loopNodeData.customCode };
53
+ }
54
+ else if (loopNodeData.ethTransfer) {
55
+ return { type: "ethTransfer", data: loopNodeData.ethTransfer };
56
+ }
57
+ else if (loopNodeData.contractRead) {
58
+ return { type: "contractRead", data: loopNodeData.contractRead };
59
+ }
60
+ else if (loopNodeData.contractWrite) {
61
+ return { type: "contractWrite", data: loopNodeData.contractWrite };
62
+ }
63
+ else if (loopNodeData.graphqlDataQuery) {
64
+ return { type: "graphqlDataQuery", data: loopNodeData.graphqlDataQuery };
65
+ }
66
+ return null;
67
+ }
68
+ static mapExecutionModeFromProtobuf(executionMode) {
69
+ // Map protobuf ExecutionMode enum to ExecutionMode enum
70
+ // EXECUTION_MODE_SEQUENTIAL = 0, EXECUTION_MODE_PARALLEL = 1
71
+ switch (executionMode) {
72
+ case 0:
73
+ return ExecutionMode.Sequential;
74
+ case 1:
75
+ return ExecutionMode.Parallel;
76
+ default:
77
+ return ExecutionMode.Sequential; // Default to sequential for safety
78
+ }
79
+ }
80
+ mapExecutionModeToProtobuf(executionMode) {
81
+ // Map ExecutionMode enum or string to protobuf ExecutionMode enum
82
+ // EXECUTION_MODE_SEQUENTIAL = 0, EXECUTION_MODE_PARALLEL = 1
83
+ if (!executionMode) {
84
+ return 0; // Default to sequential for safety
85
+ }
86
+ if (typeof executionMode === "string") {
87
+ switch (executionMode.toLowerCase()) {
88
+ case "parallel":
89
+ return 1;
90
+ case "sequential":
91
+ default:
92
+ return 0; // Default to sequential for safety
93
+ }
94
+ }
95
+ else {
96
+ switch (executionMode) {
97
+ case ExecutionMode.Parallel:
98
+ return 1;
99
+ case ExecutionMode.Sequential:
100
+ default:
101
+ return 0; // Default to sequential for safety
102
+ }
103
+ }
104
+ }
43
105
  toRequest() {
44
106
  const node = new avs_pb.TaskNode();
45
107
  const loopNode = new avs_pb.LoopNode();
@@ -51,6 +113,9 @@ class LoopNode extends Node {
51
113
  config.setSourceId(data.sourceId || "");
52
114
  config.setIterVal(data.iterVal || "");
53
115
  config.setIterKey(data.iterKey || "");
116
+ // Set execution mode - map ExecutionMode enum to protobuf enum
117
+ const executionMode = this.mapExecutionModeToProtobuf(data.executionMode);
118
+ config.setExecutionMode(executionMode);
54
119
  loopNode.setConfig(config);
55
120
  // Set input data on the top-level TaskNode, not the nested LoopNode
56
121
  // This matches where the Go backend's ExtractNodeInputData() looks for it
@@ -58,106 +123,97 @@ class LoopNode extends Node {
58
123
  if (inputValue) {
59
124
  node.setInput(inputValue);
60
125
  }
61
- // Handle nested nodes - these still use the nested structure within LoopNodeData
62
- if (data.ethTransfer) {
63
- const ethTransfer = new avs_pb.ETHTransferNode();
64
- if (data.ethTransfer.config) {
65
- const config = new avs_pb.ETHTransferNode.Config();
66
- config.setDestination(data.ethTransfer.config.destination);
67
- config.setAmount(data.ethTransfer.config.amount);
68
- ethTransfer.setConfig(config);
126
+ // Handle runner - check the runner field and set the appropriate oneof field
127
+ if (data.runner) {
128
+ this.setRunnerOnProtobuf(loopNode, data.runner);
129
+ }
130
+ node.setLoop(loopNode);
131
+ return node;
132
+ }
133
+ setRunnerOnProtobuf(loopNode, runner) {
134
+ if (!runner || !runner.type || !runner.data) {
135
+ return;
136
+ }
137
+ switch (runner.type) {
138
+ case "ethTransfer": {
139
+ const ethTransferData = runner.data;
140
+ if (ethTransferData.config) {
141
+ const ethConfig = ethTransferData.config;
142
+ const ethTransfer = ETHTransferNode.createProtobufNode({
143
+ destination: ethConfig.destination,
144
+ amount: ethConfig.amount,
145
+ });
146
+ loopNode.setEthTransfer(ethTransfer);
147
+ }
148
+ break;
69
149
  }
70
- loopNode.setEthTransfer(ethTransfer);
71
- }
72
- else if (data.contractWrite) {
73
- const contractWrite = new avs_pb.ContractWriteNode();
74
- if (data.contractWrite.config) {
75
- const config = new avs_pb.ContractWriteNode.Config();
76
- config.setContractAddress(data.contractWrite.config.contractAddress);
77
- config.setCallData(data.contractWrite.config.callData);
78
- config.setContractAbi(data.contractWrite.config.contractAbi);
79
- // Handle method calls array for ContractWrite
80
- const methodCalls = data.contractWrite.config.methodCallsList || [];
81
- methodCalls.forEach((methodCall) => {
82
- const methodCallMsg = new avs_pb.ContractWriteNode.MethodCall();
83
- methodCallMsg.setCallData(methodCall.callData);
84
- if (methodCall.methodName) {
85
- methodCallMsg.setMethodName(methodCall.methodName);
86
- }
87
- config.addMethodCalls(methodCallMsg);
88
- });
89
- contractWrite.setConfig(config);
150
+ case "contractWrite": {
151
+ const contractWriteData = runner.data;
152
+ if (contractWriteData.config) {
153
+ const writeConfig = contractWriteData.config;
154
+ const contractWrite = ContractWriteNode.createProtobufNode({
155
+ contractAddress: writeConfig.contractAddress,
156
+ callData: writeConfig.callData,
157
+ contractAbi: writeConfig.contractAbi,
158
+ methodCalls: writeConfig.methodCallsList || [],
159
+ });
160
+ loopNode.setContractWrite(contractWrite);
161
+ }
162
+ break;
90
163
  }
91
- loopNode.setContractWrite(contractWrite);
92
- }
93
- else if (data.contractRead) {
94
- const contractRead = new avs_pb.ContractReadNode();
95
- if (data.contractRead.config) {
96
- const config = new avs_pb.ContractReadNode.Config();
97
- config.setContractAddress(data.contractRead.config.contractAddress);
98
- config.setContractAbi(data.contractRead.config.contractAbi);
99
- // Handle method calls array
100
- const methodCalls = data.contractRead.config.methodCallsList || [];
101
- methodCalls.forEach((methodCall) => {
102
- const methodCallMsg = new avs_pb.ContractReadNode.MethodCall();
103
- methodCallMsg.setCallData(methodCall.callData);
104
- if (methodCall.methodName) {
105
- methodCallMsg.setMethodName(methodCall.methodName);
106
- }
107
- if (methodCall.applyToFields) {
108
- methodCallMsg.setApplyToFieldsList(methodCall.applyToFields);
109
- }
110
- config.addMethodCalls(methodCallMsg);
111
- });
112
- contractRead.setConfig(config);
164
+ case "contractRead": {
165
+ const contractReadData = runner.data;
166
+ if (contractReadData.config) {
167
+ const readConfig = contractReadData.config;
168
+ const contractRead = ContractReadNode.createProtobufNode({
169
+ contractAddress: readConfig.contractAddress,
170
+ contractAbi: readConfig.contractAbi,
171
+ methodCalls: readConfig.methodCallsList || [],
172
+ });
173
+ loopNode.setContractRead(contractRead);
174
+ }
175
+ break;
113
176
  }
114
- loopNode.setContractRead(contractRead);
115
- }
116
- else if (data.graphqlDataQuery) {
117
- const graphqlQuery = new avs_pb.GraphQLQueryNode();
118
- if (data.graphqlDataQuery.config) {
119
- const config = new avs_pb.GraphQLQueryNode.Config();
120
- config.setUrl(data.graphqlDataQuery.config.url);
121
- config.setQuery(data.graphqlDataQuery.config.query);
122
- if (data.graphqlDataQuery.config.variablesMap &&
123
- data.graphqlDataQuery.config.variablesMap.length > 0) {
124
- data.graphqlDataQuery.config.variablesMap.forEach(([key, value]) => {
125
- config.getVariablesMap().set(key, value);
177
+ case "graphqlDataQuery": {
178
+ const graphqlData = runner.data;
179
+ if (graphqlData.config) {
180
+ const gqlConfig = graphqlData.config;
181
+ const graphqlQuery = GraphQLQueryNode.createProtobufNode({
182
+ url: gqlConfig.url,
183
+ query: gqlConfig.query,
184
+ variablesMap: gqlConfig.variablesMap,
126
185
  });
186
+ loopNode.setGraphqlDataQuery(graphqlQuery);
127
187
  }
128
- graphqlQuery.setConfig(config);
188
+ break;
129
189
  }
130
- loopNode.setGraphqlDataQuery(graphqlQuery);
131
- }
132
- else if (data.restApi) {
133
- const restApi = new avs_pb.RestAPINode();
134
- if (data.restApi.config) {
135
- const config = new avs_pb.RestAPINode.Config();
136
- config.setUrl(data.restApi.config.url);
137
- config.setMethod(data.restApi.config.method);
138
- config.setBody(data.restApi.config.body || "");
139
- if (data.restApi.config.headersMap &&
140
- data.restApi.config.headersMap.length > 0) {
141
- data.restApi.config.headersMap.forEach(([key, value]) => {
142
- config.getHeadersMap().set(key, value);
190
+ case "restApi": {
191
+ const restApiData = runner.data;
192
+ if (restApiData.config) {
193
+ const apiConfig = restApiData.config;
194
+ const restApi = RestAPINode.createProtobufNode({
195
+ url: apiConfig.url,
196
+ method: apiConfig.method,
197
+ body: apiConfig.body || "",
198
+ headersMap: apiConfig.headersMap,
143
199
  });
200
+ loopNode.setRestApi(restApi);
144
201
  }
145
- restApi.setConfig(config);
202
+ break;
146
203
  }
147
- loopNode.setRestApi(restApi);
148
- }
149
- else if (data.customCode) {
150
- const customCode = new avs_pb.CustomCodeNode();
151
- if (data.customCode.config) {
152
- const config = new avs_pb.CustomCodeNode.Config();
153
- config.setLang(data.customCode.config.lang);
154
- config.setSource(data.customCode.config.source);
155
- customCode.setConfig(config);
204
+ case "customCode": {
205
+ const customCodeData = runner.data;
206
+ if (customCodeData.config) {
207
+ const codeConfig = customCodeData.config;
208
+ const customCode = CustomCodeNode.createProtobufNode({
209
+ lang: codeConfig.lang,
210
+ source: codeConfig.source,
211
+ });
212
+ loopNode.setCustomCode(customCode);
213
+ }
214
+ break;
156
215
  }
157
- loopNode.setCustomCode(customCode);
158
216
  }
159
- node.setLoop(loopNode);
160
- return node;
161
217
  }
162
218
  static fromOutputData(outputData) {
163
219
  // For immediate execution, data comes as CustomCode format
@@ -182,7 +238,7 @@ class LoopNode extends Node {
182
238
  try {
183
239
  return JSON.parse(loopObj.data);
184
240
  }
185
- catch (e) {
241
+ catch {
186
242
  // If JSON parsing fails, return the raw data
187
243
  return loopObj.data;
188
244
  }
@@ -3,6 +3,17 @@ import * as avs_pb from "@/grpc_codegen/avs_pb";
3
3
  import { RestAPINodeProps } from "@avaprotocol/types";
4
4
  declare class RestAPINode extends Node {
5
5
  constructor(props: RestAPINodeProps);
6
+ /**
7
+ * Create a protobuf RestAPINode from config data
8
+ * @param configData - The configuration data for the REST API node
9
+ * @returns Configured avs_pb.RestAPINode
10
+ */
11
+ static createProtobufNode(configData: {
12
+ url: string;
13
+ method: string;
14
+ body?: string;
15
+ headersMap?: Array<[string, string]>;
16
+ }): avs_pb.RestAPINode;
6
17
  static fromResponse(raw: avs_pb.TaskNode): RestAPINode;
7
18
  toRequest(): avs_pb.TaskNode;
8
19
  static fromOutputData(outputData: avs_pb.RunNodeWithInputsResp): any;
@@ -1 +1 @@
1
- {"version":3,"file":"restApi.d.ts","sourceRoot":"","sources":["../../../src/models/node/restApi.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,aAAa,CAAC;AAC/B,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAGL,gBAAgB,EAEjB,MAAM,oBAAoB,CAAC;AAS5B,cAAM,WAAY,SAAQ,IAAI;gBAChB,KAAK,EAAE,gBAAgB;IAInC,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,QAAQ,GAAG,WAAW;IAmBtD,SAAS,IAAI,MAAM,CAAC,QAAQ;IAyC5B,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM,CAAC,qBAAqB,GAAG,GAAG;CAerE;AAED,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"restApi.d.ts","sourceRoot":"","sources":["../../../src/models/node/restApi.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,aAAa,CAAC;AAC/B,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAGL,gBAAgB,EAEjB,MAAM,oBAAoB,CAAC;AAS5B,cAAM,WAAY,SAAQ,IAAI;gBAChB,KAAK,EAAE,gBAAgB;IAInC;;;;OAIG;IACH,MAAM,CAAC,kBAAkB,CAAC,UAAU,EAAE;QACpC,GAAG,EAAE,MAAM,CAAC;QACZ,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,UAAU,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;KACtC,GAAG,MAAM,CAAC,WAAW;IAmBtB,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,QAAQ,GAAG,WAAW;IAmBtD,SAAS,IAAI,MAAM,CAAC,QAAQ;IAwB5B,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM,CAAC,qBAAqB,GAAG,GAAG;CAerE;AAED,eAAe,WAAW,CAAC"}
@@ -7,6 +7,26 @@ class RestAPINode extends Node {
7
7
  constructor(props) {
8
8
  super({ ...props, type: NodeType.RestAPI, data: props.data });
9
9
  }
10
+ /**
11
+ * Create a protobuf RestAPINode from config data
12
+ * @param configData - The configuration data for the REST API node
13
+ * @returns Configured avs_pb.RestAPINode
14
+ */
15
+ static createProtobufNode(configData) {
16
+ const node = new avs_pb.RestAPINode();
17
+ const config = new avs_pb.RestAPINode.Config();
18
+ config.setUrl(configData.url);
19
+ config.setMethod(configData.method);
20
+ config.setBody(configData.body || "");
21
+ if (configData.headersMap && configData.headersMap.length > 0) {
22
+ const headersMap = config.getHeadersMap();
23
+ configData.headersMap.forEach(([key, value]) => {
24
+ headersMap.set(key, value);
25
+ });
26
+ }
27
+ node.setConfig(config);
28
+ return node;
29
+ }
10
30
  static fromResponse(raw) {
11
31
  // Convert the raw object to RestAPINodeProps, which should keep name and id
12
32
  const obj = raw.toObject();
@@ -27,19 +47,7 @@ class RestAPINode extends Node {
27
47
  const request = new avs_pb.TaskNode();
28
48
  request.setId(this.id);
29
49
  request.setName(this.name);
30
- const nodeData = new avs_pb.RestAPINode();
31
- const config = new avs_pb.RestAPINode.Config();
32
- config.setUrl(this.data.url);
33
- config.setMethod(this.data.method);
34
- config.setBody(this.data.body || "");
35
- if (this.data.headersMap &&
36
- this.data.headersMap.length > 0) {
37
- const headersMap = config.getHeadersMap();
38
- this.data.headersMap.forEach(([key, value]) => {
39
- headersMap.set(key, value);
40
- });
41
- }
42
- nodeData.setConfig(config);
50
+ const nodeData = RestAPINode.createProtobufNode(this.data);
43
51
  // Use the standard utility function to convert input field to protobuf format
44
52
  const inputValue = convertInputToProtobuf(this.input);
45
53
  if (inputValue) {
package/dist/utils.d.ts CHANGED
@@ -11,20 +11,6 @@ import { Value as ProtobufValue } from "google-protobuf/google/protobuf/struct_p
11
11
  * @returns The converted JavaScript value
12
12
  */
13
13
  export declare function convertProtobufValueToJs(value?: ProtobufValue): any;
14
- /**
15
- * Convert a protobuf Value to a JavaScript value
16
- *
17
- * **⚠️ DEPRECATED - Use convertProtobufValueToJs() for new code**
18
- *
19
- * This is a legacy compatibility version for existing code that may use
20
- * dynamically typed protobuf objects. It uses older has*() methods and
21
- * fallback logic. Only use this if you need backward compatibility.
22
- *
23
- * @deprecated Use convertProtobufValueToJs() instead for better type safety
24
- * @param value - The protobuf Value object (may be dynamically typed)
25
- * @returns The converted JavaScript value
26
- */
27
- export declare function convertProtobufValueToJS(value: any): any;
28
14
  /**
29
15
  * Convert a JavaScript value to a protobuf Value
30
16
  *
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,IAAI,aAAa,EAGvB,MAAM,2CAA2C,CAAC;AAGnD;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,CAAC,EAAE,aAAa,GAAG,GAAG,CAiCnE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,GAAG,GAAG,GAAG,CAkDxD;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,GAAG,GAAG,aAAa,CA6BlE;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAkB5E;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CA0BzE;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CASzE;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC1B,aAAa,GAAG,SAAS,CAK3B;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CACtC,UAAU,CAAC,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC/C,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAiCjC;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAsB7D"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,IAAI,aAAa,EAGvB,MAAM,2CAA2C,CAAC;AAGnD;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,CAAC,EAAE,aAAa,GAAG,GAAG,CAiCnE;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,GAAG,GAAG,aAAa,CA6BlE;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAkB5E;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CA0BzE;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CASzE;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC1B,aAAa,GAAG,SAAS,CAK3B;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CACtC,UAAU,CAAC,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC/C,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAiCjC;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAsB7D"}
package/dist/utils.js CHANGED
@@ -46,68 +46,6 @@ export function convertProtobufValueToJs(value) {
46
46
  return undefined;
47
47
  }
48
48
  }
49
- /**
50
- * Convert a protobuf Value to a JavaScript value
51
- *
52
- * **⚠️ DEPRECATED - Use convertProtobufValueToJs() for new code**
53
- *
54
- * This is a legacy compatibility version for existing code that may use
55
- * dynamically typed protobuf objects. It uses older has*() methods and
56
- * fallback logic. Only use this if you need backward compatibility.
57
- *
58
- * @deprecated Use convertProtobufValueToJs() instead for better type safety
59
- * @param value - The protobuf Value object (may be dynamically typed)
60
- * @returns The converted JavaScript value
61
- */
62
- export function convertProtobufValueToJS(value) {
63
- if (!value)
64
- return null;
65
- // Handle different value types based on protobuf Value structure
66
- if (value.hasNullValue && value.hasNullValue()) {
67
- return null;
68
- }
69
- if (value.hasNumberValue && value.hasNumberValue()) {
70
- return value.getNumberValue();
71
- }
72
- if (value.hasStringValue && value.hasStringValue()) {
73
- return value.getStringValue();
74
- }
75
- if (value.hasBoolValue && value.hasBoolValue()) {
76
- return value.getBoolValue();
77
- }
78
- if (value.hasStructValue && value.hasStructValue()) {
79
- const struct = value.getStructValue();
80
- const result = {};
81
- if (struct && struct.getFieldsMap) {
82
- const fieldsMap = struct.getFieldsMap();
83
- fieldsMap.forEach((fieldValue, key) => {
84
- result[key] = convertProtobufValueToJS(fieldValue);
85
- });
86
- }
87
- return result;
88
- }
89
- if (value.hasListValue && value.hasListValue()) {
90
- const list = value.getListValue();
91
- if (list && list.getValuesList) {
92
- return list
93
- .getValuesList()
94
- .map((item) => convertProtobufValueToJS(item));
95
- }
96
- return [];
97
- }
98
- // Fallback: try to extract primitive values directly
99
- if (typeof value.getNumberValue === "function") {
100
- return value.getNumberValue();
101
- }
102
- if (typeof value.getStringValue === "function") {
103
- return value.getStringValue();
104
- }
105
- if (typeof value.getBoolValue === "function") {
106
- return value.getBoolValue();
107
- }
108
- // If all else fails, return the raw value
109
- return value;
110
- }
111
49
  /**
112
50
  * Convert a JavaScript value to a protobuf Value
113
51
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avaprotocol/sdk-js",
3
- "version": "2.4.3",
3
+ "version": "2.4.4",
4
4
  "description": "A JavaScript/TypeScript SDK designed to simplify integration with Ava Protocol's AVS",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -31,7 +31,7 @@
31
31
  "prepare": "node ../../scripts/prepare-package.js"
32
32
  },
33
33
  "dependencies": {
34
- "@avaprotocol/types": "^2.2.16",
34
+ "@avaprotocol/types": "^2.2.17",
35
35
  "@grpc/grpc-js": "^1.11.3",
36
36
  "@grpc/proto-loader": "^0.7.13",
37
37
  "dotenv": "^16.4.5",