From 1620fdaa1b7f7557223638054c449cbe786dbbd2 Mon Sep 17 00:00:00 2001 From: kemuru <102478601+kemuru@users.noreply.github.com> Date: Tue, 18 Jun 2024 01:32:57 +0200 Subject: [PATCH 1/6] chore(sdk): trying to make the curate v2 mappings work, adding logs --- .../src/dataMappings/actions/jsonAction.ts | 11 ++++- .../dataMappings/actions/subgraphAction.ts | 44 ++++++++++++++----- kleros-sdk/src/dataMappings/executeActions.ts | 10 +++++ .../dataMappings/utils/createResultObject.ts | 31 +++++++------ .../utils/replacePlaceholdersWithValues.ts | 14 +++++- .../Cases/CaseDetails/Evidence/index.tsx | 1 + 6 files changed, 83 insertions(+), 28 deletions(-) diff --git a/kleros-sdk/src/dataMappings/actions/jsonAction.ts b/kleros-sdk/src/dataMappings/actions/jsonAction.ts index 3857b4006..d9be35b5d 100644 --- a/kleros-sdk/src/dataMappings/actions/jsonAction.ts +++ b/kleros-sdk/src/dataMappings/actions/jsonAction.ts @@ -3,5 +3,14 @@ import { createResultObject } from "src/dataMappings/utils/createResultObject"; export const jsonAction = (mapping: JsonMapping) => { const { value: source, seek, populate } = mapping; - return createResultObject(source, seek, populate); + let sourceData; + + try { + sourceData = JSON.parse(source); + } catch (error) { + console.error("Failed to parse source as JSON:", source); + throw error; + } + + return createResultObject(sourceData, seek, populate); }; diff --git a/kleros-sdk/src/dataMappings/actions/subgraphAction.ts b/kleros-sdk/src/dataMappings/actions/subgraphAction.ts index 018579c04..41b6885b2 100644 --- a/kleros-sdk/src/dataMappings/actions/subgraphAction.ts +++ b/kleros-sdk/src/dataMappings/actions/subgraphAction.ts @@ -4,16 +4,36 @@ import { createResultObject } from "src/dataMappings/utils/createResultObject"; export const subgraphAction = async (mapping: SubgraphMapping) => { const { endpoint, query, variables, seek, populate } = mapping; - const response = await fetch(endpoint, { - method: "POST", - headers: { - "Content-Type": "application/json", - Accept: "application/json", - }, - body: JSON.stringify({ query, variables }), - }); - - const { data } = await response.json(); - - return createResultObject(data, seek, populate); + console.log("Subgraph action with mapping:", mapping); + + try { + const response = await fetch(endpoint, { + method: "POST", + headers: { + "Content-Type": "application/json", + Accept: "application/json", + }, + body: JSON.stringify({ query, variables }), + }); + + console.log("Response status:", response.status); + + if (!response.ok) { + throw new Error(`HTTP error! Status: ${response.status}`); + } + + const responseData = await response.json(); + console.log("Response data:", responseData); + + if (responseData.errors) { + throw new Error(`GraphQL errors: ${JSON.stringify(responseData.errors)}`); + } + + const { data } = responseData; + + return createResultObject(data, seek, populate); + } catch (error) { + console.error("Error fetching from GraphQL endpoint:", error); + throw error; + } }; diff --git a/kleros-sdk/src/dataMappings/executeActions.ts b/kleros-sdk/src/dataMappings/executeActions.ts index 049c31a87..cd6fdf744 100644 --- a/kleros-sdk/src/dataMappings/executeActions.ts +++ b/kleros-sdk/src/dataMappings/executeActions.ts @@ -16,8 +16,13 @@ import { ActionMapping } from "./utils/actionTypes"; import { replacePlaceholdersWithValues } from "./utils/replacePlaceholdersWithValues"; export const executeAction = async (mapping: ActionMapping, context = {}) => { + console.log("Executing action with mapping:", mapping); + console.log("Context before replacement:", context); + mapping = replacePlaceholdersWithValues(mapping, context); + console.log("Mapping after replacement:", mapping); + switch (mapping.type) { case "graphql": return await subgraphAction(validateSubgraphMapping(mapping)); @@ -39,9 +44,13 @@ export const executeAction = async (mapping: ActionMapping, context = {}) => { export const executeActions = async (mappings, initialContext = {}) => { const context = { ...initialContext }; + console.log("Initial context:", context); for (const mapping of mappings) { + console.log("Processing mapping:", mapping); const actionResult = await executeAction(mapping, context); + console.log("Action result:", actionResult); + if (actionResult) { Object.keys(actionResult).forEach((key) => { context[key] = actionResult[key]; @@ -49,5 +58,6 @@ export const executeActions = async (mappings, initialContext = {}) => { } } + console.log("Final context:", context); return context; }; diff --git a/kleros-sdk/src/dataMappings/utils/createResultObject.ts b/kleros-sdk/src/dataMappings/utils/createResultObject.ts index 184965e4f..742f1a23f 100644 --- a/kleros-sdk/src/dataMappings/utils/createResultObject.ts +++ b/kleros-sdk/src/dataMappings/utils/createResultObject.ts @@ -1,13 +1,23 @@ -// Can this be replaced by Mustache ? +// Can this be replaced by Mustache? export const createResultObject = (sourceData, seek, populate) => { const result = {}; + console.log("Creating result object from source data:", sourceData); seek.forEach((key, idx) => { let foundValue = sourceData; + const keyParts = key.split("."); + console.log(`Processing seek key: ${key}, split into parts:`, keyParts); - if (key.includes(".")) { - const keyParts = key.split("."); - for (const part of keyParts) { + for (const part of keyParts) { + if (part.includes("[")) { + const [arrayKey, index] = part.replace("]", "").split("["); + if (foundValue[arrayKey] && foundValue[arrayKey][index] !== undefined) { + foundValue = foundValue[arrayKey][index]; + } else { + foundValue = undefined; + break; + } + } else { if (foundValue[part] !== undefined) { foundValue = foundValue[part]; } else { @@ -15,20 +25,15 @@ export const createResultObject = (sourceData, seek, populate) => { break; } } - } else { - if (typeof sourceData !== "object" || key === "0") { - foundValue = sourceData; - } else { - foundValue = sourceData[key]; - } } - console.log(`Seek key: ${key}, Found value:`, foundValue); + console.log(`Found value for key ${key}:`, foundValue); if (foundValue !== undefined) { result[populate[idx]] = foundValue; - console.log(`Populate key: ${populate[idx]}, Value to add:`, foundValue); + console.log(`Populating result with key ${populate[idx]}:`, foundValue); } }); - console.log("Result object:", result); + + console.log("Final result object:", result); return result; }; diff --git a/kleros-sdk/src/dataMappings/utils/replacePlaceholdersWithValues.ts b/kleros-sdk/src/dataMappings/utils/replacePlaceholdersWithValues.ts index 1d8e16439..5da46d38d 100644 --- a/kleros-sdk/src/dataMappings/utils/replacePlaceholdersWithValues.ts +++ b/kleros-sdk/src/dataMappings/utils/replacePlaceholdersWithValues.ts @@ -1,13 +1,23 @@ export const replacePlaceholdersWithValues = (mapping: any, context: any) => { let mappingAsString = JSON.stringify(mapping); + console.log("Replacing placeholders in mapping:", mappingAsString); const replacedMapping = mappingAsString.replace(/\{\{(\w+)\}\}/g, (_, variableName) => { if (context.hasOwnProperty(variableName)) { - return context[variableName]; + const value = context[variableName]; + console.log(`Replacing placeholder: ${variableName} with value:`, value); + + if (typeof value === "string" && value.startsWith("{") && value.endsWith("}")) { + return JSON.stringify(value); + } else { + return typeof value === "bigint" ? value.toString() : value; + } } else { throw new Error(`Variable '${variableName}' not found in context.`); } }); - return JSON.parse(replacedMapping); + const parsedMapping = JSON.parse(replacedMapping.replace(/"(\{.*\})"/, "$1")); + console.log("Mapping after placeholder replacement:", parsedMapping); + return parsedMapping; }; diff --git a/web/src/pages/Cases/CaseDetails/Evidence/index.tsx b/web/src/pages/Cases/CaseDetails/Evidence/index.tsx index 3d75eada8..d637cb3bf 100644 --- a/web/src/pages/Cases/CaseDetails/Evidence/index.tsx +++ b/web/src/pages/Cases/CaseDetails/Evidence/index.tsx @@ -43,6 +43,7 @@ const Evidence: React.FC<{ arbitrable?: `0x${string}` }> = ({ arbitrable }) => { const [isModalOpen, setIsModalOpen] = useState(false); const { id } = useParams(); const { data: evidenceGroup } = useEvidenceGroup(id, arbitrable); + console.log({ evidenceGroup }, "evidenceGroup is the externalDisputeID"); const { data } = useEvidences(evidenceGroup?.toString()); const { address } = useAccount(); From 18ead60546f66c4fe92a8517e6e0157c62e2d6a4 Mon Sep 17 00:00:00 2001 From: kemuru <102478601+kemuru@users.noreply.github.com> Date: Tue, 18 Jun 2024 19:40:04 +0200 Subject: [PATCH 2/6] feat: simplify functions, remove logs --- .../src/dataMappings/actions/jsonAction.ts | 9 +--- .../dataMappings/actions/subgraphAction.ts | 44 +++++-------------- kleros-sdk/src/dataMappings/executeActions.ts | 9 ---- .../dataMappings/utils/createResultObject.ts | 38 +++++----------- .../utils/replacePlaceholdersWithValues.ts | 3 -- .../Cases/CaseDetails/Evidence/index.tsx | 1 - 6 files changed, 24 insertions(+), 80 deletions(-) diff --git a/kleros-sdk/src/dataMappings/actions/jsonAction.ts b/kleros-sdk/src/dataMappings/actions/jsonAction.ts index d9be35b5d..727ddb89e 100644 --- a/kleros-sdk/src/dataMappings/actions/jsonAction.ts +++ b/kleros-sdk/src/dataMappings/actions/jsonAction.ts @@ -3,14 +3,7 @@ import { createResultObject } from "src/dataMappings/utils/createResultObject"; export const jsonAction = (mapping: JsonMapping) => { const { value: source, seek, populate } = mapping; - let sourceData; - - try { - sourceData = JSON.parse(source); - } catch (error) { - console.error("Failed to parse source as JSON:", source); - throw error; - } + const sourceData = JSON.parse(source); return createResultObject(sourceData, seek, populate); }; diff --git a/kleros-sdk/src/dataMappings/actions/subgraphAction.ts b/kleros-sdk/src/dataMappings/actions/subgraphAction.ts index 41b6885b2..018579c04 100644 --- a/kleros-sdk/src/dataMappings/actions/subgraphAction.ts +++ b/kleros-sdk/src/dataMappings/actions/subgraphAction.ts @@ -4,36 +4,16 @@ import { createResultObject } from "src/dataMappings/utils/createResultObject"; export const subgraphAction = async (mapping: SubgraphMapping) => { const { endpoint, query, variables, seek, populate } = mapping; - console.log("Subgraph action with mapping:", mapping); - - try { - const response = await fetch(endpoint, { - method: "POST", - headers: { - "Content-Type": "application/json", - Accept: "application/json", - }, - body: JSON.stringify({ query, variables }), - }); - - console.log("Response status:", response.status); - - if (!response.ok) { - throw new Error(`HTTP error! Status: ${response.status}`); - } - - const responseData = await response.json(); - console.log("Response data:", responseData); - - if (responseData.errors) { - throw new Error(`GraphQL errors: ${JSON.stringify(responseData.errors)}`); - } - - const { data } = responseData; - - return createResultObject(data, seek, populate); - } catch (error) { - console.error("Error fetching from GraphQL endpoint:", error); - throw error; - } + const response = await fetch(endpoint, { + method: "POST", + headers: { + "Content-Type": "application/json", + Accept: "application/json", + }, + body: JSON.stringify({ query, variables }), + }); + + const { data } = await response.json(); + + return createResultObject(data, seek, populate); }; diff --git a/kleros-sdk/src/dataMappings/executeActions.ts b/kleros-sdk/src/dataMappings/executeActions.ts index cd6fdf744..2ea43cacd 100644 --- a/kleros-sdk/src/dataMappings/executeActions.ts +++ b/kleros-sdk/src/dataMappings/executeActions.ts @@ -16,13 +16,8 @@ import { ActionMapping } from "./utils/actionTypes"; import { replacePlaceholdersWithValues } from "./utils/replacePlaceholdersWithValues"; export const executeAction = async (mapping: ActionMapping, context = {}) => { - console.log("Executing action with mapping:", mapping); - console.log("Context before replacement:", context); - mapping = replacePlaceholdersWithValues(mapping, context); - console.log("Mapping after replacement:", mapping); - switch (mapping.type) { case "graphql": return await subgraphAction(validateSubgraphMapping(mapping)); @@ -44,12 +39,9 @@ export const executeAction = async (mapping: ActionMapping, context = {}) => { export const executeActions = async (mappings, initialContext = {}) => { const context = { ...initialContext }; - console.log("Initial context:", context); for (const mapping of mappings) { - console.log("Processing mapping:", mapping); const actionResult = await executeAction(mapping, context); - console.log("Action result:", actionResult); if (actionResult) { Object.keys(actionResult).forEach((key) => { @@ -58,6 +50,5 @@ export const executeActions = async (mappings, initialContext = {}) => { } } - console.log("Final context:", context); return context; }; diff --git a/kleros-sdk/src/dataMappings/utils/createResultObject.ts b/kleros-sdk/src/dataMappings/utils/createResultObject.ts index 742f1a23f..215926f6f 100644 --- a/kleros-sdk/src/dataMappings/utils/createResultObject.ts +++ b/kleros-sdk/src/dataMappings/utils/createResultObject.ts @@ -1,39 +1,23 @@ // Can this be replaced by Mustache? -export const createResultObject = (sourceData, seek, populate) => { +export const createResultObject = (sourceData, seek: string[], populate: string[]) => { const result = {}; - console.log("Creating result object from source data:", sourceData); - seek.forEach((key, idx) => { - let foundValue = sourceData; - const keyParts = key.split("."); - console.log(`Processing seek key: ${key}, split into parts:`, keyParts); - - for (const part of keyParts) { - if (part.includes("[")) { - const [arrayKey, index] = part.replace("]", "").split("["); - if (foundValue[arrayKey] && foundValue[arrayKey][index] !== undefined) { - foundValue = foundValue[arrayKey][index]; - } else { - foundValue = undefined; - break; - } - } else { - if (foundValue[part] !== undefined) { - foundValue = foundValue[part]; - } else { - foundValue = undefined; - break; - } + const getNestedValue = (obj: any, path: string) => { + return path.split(".").reduce((acc, part) => { + if (acc && part.includes("[")) { + const [key, index] = part.replace("]", "").split("["); + return acc[key]?.[index]; } - } + return acc ? acc[part] : undefined; + }, obj); + }; - console.log(`Found value for key ${key}:`, foundValue); + seek.forEach((key, idx) => { + const foundValue = getNestedValue(sourceData, key); if (foundValue !== undefined) { result[populate[idx]] = foundValue; - console.log(`Populating result with key ${populate[idx]}:`, foundValue); } }); - console.log("Final result object:", result); return result; }; diff --git a/kleros-sdk/src/dataMappings/utils/replacePlaceholdersWithValues.ts b/kleros-sdk/src/dataMappings/utils/replacePlaceholdersWithValues.ts index 5da46d38d..c0045ceac 100644 --- a/kleros-sdk/src/dataMappings/utils/replacePlaceholdersWithValues.ts +++ b/kleros-sdk/src/dataMappings/utils/replacePlaceholdersWithValues.ts @@ -1,11 +1,9 @@ export const replacePlaceholdersWithValues = (mapping: any, context: any) => { let mappingAsString = JSON.stringify(mapping); - console.log("Replacing placeholders in mapping:", mappingAsString); const replacedMapping = mappingAsString.replace(/\{\{(\w+)\}\}/g, (_, variableName) => { if (context.hasOwnProperty(variableName)) { const value = context[variableName]; - console.log(`Replacing placeholder: ${variableName} with value:`, value); if (typeof value === "string" && value.startsWith("{") && value.endsWith("}")) { return JSON.stringify(value); @@ -18,6 +16,5 @@ export const replacePlaceholdersWithValues = (mapping: any, context: any) => { }); const parsedMapping = JSON.parse(replacedMapping.replace(/"(\{.*\})"/, "$1")); - console.log("Mapping after placeholder replacement:", parsedMapping); return parsedMapping; }; diff --git a/web/src/pages/Cases/CaseDetails/Evidence/index.tsx b/web/src/pages/Cases/CaseDetails/Evidence/index.tsx index f9c3ad532..896d937e5 100644 --- a/web/src/pages/Cases/CaseDetails/Evidence/index.tsx +++ b/web/src/pages/Cases/CaseDetails/Evidence/index.tsx @@ -43,7 +43,6 @@ const Evidence: React.FC<{ arbitrable?: `0x${string}` }> = ({ arbitrable }) => { const [isModalOpen, setIsModalOpen] = useState(false); const { id } = useParams(); const { data: evidenceGroup } = useEvidenceGroup(id, arbitrable); - console.log({ evidenceGroup }, "evidenceGroup is the externalDisputeID"); const { data } = useEvidences(evidenceGroup?.toString()); const { address } = useAccount(); From 078c4ca936a379542d633f0e754dd8cd09c161a8 Mon Sep 17 00:00:00 2001 From: kemuru <102478601+kemuru@users.noreply.github.com> Date: Thu, 20 Jun 2024 19:20:52 +0200 Subject: [PATCH 3/6] chore: revert changes to jsonaction and replaceplaceholderswithvalues --- kleros-sdk/src/dataMappings/actions/jsonAction.ts | 4 +--- .../utils/replacePlaceholdersWithValues.ts | 11 ++--------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/kleros-sdk/src/dataMappings/actions/jsonAction.ts b/kleros-sdk/src/dataMappings/actions/jsonAction.ts index 727ddb89e..3857b4006 100644 --- a/kleros-sdk/src/dataMappings/actions/jsonAction.ts +++ b/kleros-sdk/src/dataMappings/actions/jsonAction.ts @@ -3,7 +3,5 @@ import { createResultObject } from "src/dataMappings/utils/createResultObject"; export const jsonAction = (mapping: JsonMapping) => { const { value: source, seek, populate } = mapping; - const sourceData = JSON.parse(source); - - return createResultObject(sourceData, seek, populate); + return createResultObject(source, seek, populate); }; diff --git a/kleros-sdk/src/dataMappings/utils/replacePlaceholdersWithValues.ts b/kleros-sdk/src/dataMappings/utils/replacePlaceholdersWithValues.ts index c0045ceac..1d8e16439 100644 --- a/kleros-sdk/src/dataMappings/utils/replacePlaceholdersWithValues.ts +++ b/kleros-sdk/src/dataMappings/utils/replacePlaceholdersWithValues.ts @@ -3,18 +3,11 @@ export const replacePlaceholdersWithValues = (mapping: any, context: any) => { const replacedMapping = mappingAsString.replace(/\{\{(\w+)\}\}/g, (_, variableName) => { if (context.hasOwnProperty(variableName)) { - const value = context[variableName]; - - if (typeof value === "string" && value.startsWith("{") && value.endsWith("}")) { - return JSON.stringify(value); - } else { - return typeof value === "bigint" ? value.toString() : value; - } + return context[variableName]; } else { throw new Error(`Variable '${variableName}' not found in context.`); } }); - const parsedMapping = JSON.parse(replacedMapping.replace(/"(\{.*\})"/, "$1")); - return parsedMapping; + return JSON.parse(replacedMapping); }; From 3ad99b19dce14404dc214c2c0762796810cef865 Mon Sep 17 00:00:00 2001 From: kemuru <102478601+kemuru@users.noreply.github.com> Date: Fri, 21 Jun 2024 02:24:23 +0200 Subject: [PATCH 4/6] fix: parse nested json strings in case there are any, while not breaking normal json structures --- .../src/dataMappings/utils/replacePlaceholdersWithValues.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kleros-sdk/src/dataMappings/utils/replacePlaceholdersWithValues.ts b/kleros-sdk/src/dataMappings/utils/replacePlaceholdersWithValues.ts index 1d8e16439..acb67a014 100644 --- a/kleros-sdk/src/dataMappings/utils/replacePlaceholdersWithValues.ts +++ b/kleros-sdk/src/dataMappings/utils/replacePlaceholdersWithValues.ts @@ -9,5 +9,6 @@ export const replacePlaceholdersWithValues = (mapping: any, context: any) => { } }); - return JSON.parse(replacedMapping); + const parsedReplacedMapping = JSON.parse(replacedMapping.replace(/"(\{.*?\})"/g, "$1")); + return parsedReplacedMapping; }; From f6f1e4ee282bea019ccfe2c316977637f9c491b9 Mon Sep 17 00:00:00 2001 From: kemuru <102478601+kemuru@users.noreply.github.com> Date: Fri, 21 Jun 2024 16:08:35 +0200 Subject: [PATCH 5/6] feat: replaceplaceholders replaced with mustache, jsonaction json parses in case the input is a stri --- .../src/dataMappings/actions/jsonAction.ts | 8 +++++-- .../dataMappings/utils/createResultObject.ts | 1 - .../utils/replacePlaceholdersWithValues.ts | 21 +++++++++++-------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/kleros-sdk/src/dataMappings/actions/jsonAction.ts b/kleros-sdk/src/dataMappings/actions/jsonAction.ts index 3857b4006..87e787131 100644 --- a/kleros-sdk/src/dataMappings/actions/jsonAction.ts +++ b/kleros-sdk/src/dataMappings/actions/jsonAction.ts @@ -2,6 +2,10 @@ import { JsonMapping } from "../utils/actionTypes"; import { createResultObject } from "src/dataMappings/utils/createResultObject"; export const jsonAction = (mapping: JsonMapping) => { - const { value: source, seek, populate } = mapping; - return createResultObject(source, seek, populate); + const { value, seek, populate } = mapping; + + // Parse the source if it's a JSON string + const parsedValue = typeof value === "string" ? JSON.parse(value) : value; + + return createResultObject(parsedValue, seek, populate); }; diff --git a/kleros-sdk/src/dataMappings/utils/createResultObject.ts b/kleros-sdk/src/dataMappings/utils/createResultObject.ts index 215926f6f..11b097c62 100644 --- a/kleros-sdk/src/dataMappings/utils/createResultObject.ts +++ b/kleros-sdk/src/dataMappings/utils/createResultObject.ts @@ -1,4 +1,3 @@ -// Can this be replaced by Mustache? export const createResultObject = (sourceData, seek: string[], populate: string[]) => { const result = {}; diff --git a/kleros-sdk/src/dataMappings/utils/replacePlaceholdersWithValues.ts b/kleros-sdk/src/dataMappings/utils/replacePlaceholdersWithValues.ts index acb67a014..a6d25add5 100644 --- a/kleros-sdk/src/dataMappings/utils/replacePlaceholdersWithValues.ts +++ b/kleros-sdk/src/dataMappings/utils/replacePlaceholdersWithValues.ts @@ -1,14 +1,17 @@ -export const replacePlaceholdersWithValues = (mapping: any, context: any) => { - let mappingAsString = JSON.stringify(mapping); +import mustache from "mustache"; - const replacedMapping = mappingAsString.replace(/\{\{(\w+)\}\}/g, (_, variableName) => { - if (context.hasOwnProperty(variableName)) { - return context[variableName]; +export const replacePlaceholdersWithValues = (mapping: any, context: any) => { + const replace = (obj) => { + if (typeof obj === "string") { + return mustache.render(obj, context); + } else if (Array.isArray(obj)) { + return obj.map(replace); + } else if (typeof obj === "object" && obj !== null) { + return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, replace(value)])); } else { - throw new Error(`Variable '${variableName}' not found in context.`); + return obj; } - }); + }; - const parsedReplacedMapping = JSON.parse(replacedMapping.replace(/"(\{.*?\})"/g, "$1")); - return parsedReplacedMapping; + return replace(mapping); }; From 78dbbf69139004d751475f44dd5811ef6a52329d Mon Sep 17 00:00:00 2001 From: kemuru <102478601+kemuru@users.noreply.github.com> Date: Tue, 25 Jun 2024 03:44:10 +0200 Subject: [PATCH 6/6] fix: allow replacing more than one array --- kleros-sdk/src/dataMappings/utils/createResultObject.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kleros-sdk/src/dataMappings/utils/createResultObject.ts b/kleros-sdk/src/dataMappings/utils/createResultObject.ts index 11b097c62..4c4ed2155 100644 --- a/kleros-sdk/src/dataMappings/utils/createResultObject.ts +++ b/kleros-sdk/src/dataMappings/utils/createResultObject.ts @@ -4,7 +4,7 @@ export const createResultObject = (sourceData, seek: string[], populate: string[ const getNestedValue = (obj: any, path: string) => { return path.split(".").reduce((acc, part) => { if (acc && part.includes("[")) { - const [key, index] = part.replace("]", "").split("["); + const [key, index] = part.replace(/\]/g, "").split("["); return acc[key]?.[index]; } return acc ? acc[part] : undefined;