UNPKG

@maximai/maxim-js

Version:

Maxim AI JS SDK. Visit https://getmaxim.ai for more info.

49 lines 2.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createDataStructure = void 0; exports.sanitizeDataStructure = sanitizeDataStructure; exports.validateDataStructure = validateDataStructure; const createDataStructure = (dataStructure) => { sanitizeDataStructure(dataStructure); return dataStructure; }; exports.createDataStructure = createDataStructure; function sanitizeDataStructure(dataStructure) { let encounteredInput = false; let encounteredExpectedOutput = false; let encounteredContextToEvaluate = false; if (dataStructure) { for (const value of Object.values(dataStructure)) { if (value === "INPUT") { if (encounteredInput) throw new Error("Data structure contains more than one input", { cause: JSON.stringify({ dataStructure }, null, 2) }); else encounteredInput = true; } else if (value === "EXPECTED_OUTPUT") { if (encounteredExpectedOutput) throw new Error("Data structure contains more than one expectedOutput", { cause: JSON.stringify({ dataStructure }, null, 2) }); else encounteredExpectedOutput = true; } else if (value === "CONTEXT_TO_EVALUATE") { if (encounteredContextToEvaluate) throw new Error("Data structure contains more than one contextToEvaluate", { cause: JSON.stringify({ dataStructure }, null, 2) }); else encounteredContextToEvaluate = true; } } } } function validateDataStructure(dataStructure, againstDataStructure) { const dataStructureKeys = Object.keys(dataStructure); const againstDataStructureKeys = Object.keys(againstDataStructure); for (const key of dataStructureKeys) { if (!againstDataStructureKeys.includes(key)) { throw new Error(`The provided data structure contains key "${key}" which is not present in the dataset on the platform`, { cause: JSON.stringify({ providedDataStructureKeys: dataStructureKeys, platformDataStructureKeys: againstDataStructureKeys }, null, 2), }); } } } //# sourceMappingURL=dataset.js.map