Skip to content

Commit

Permalink
fix: mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
koladilip committed Jun 18, 2024
1 parent a00190e commit f16571b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"dependencies": {
"@monaco-editor/react": "^4.6.0",
"@rudderstack/json-template-engine": "^0.13.6",
"@rudderstack/json-template-engine": "^0.13.8",
"@rudderstack/workflow-engine": "^0.8.4",
"axios": "^1.7.2",
"react": "^18.3.1",
Expand Down
26 changes: 15 additions & 11 deletions src/Mappings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import Playground from './Playground';
import Header from './Header';
import { ActionType, ActionsContext } from './action';
import { CodeType } from './types';
import { FlatMappingPaths, JsonTemplateEngine, PathType } from '@rudderstack/json-template-engine';
import {
Expression,
FlatMappingPaths,
JsonTemplateEngine,
PathType,
} from '@rudderstack/json-template-engine';

export const Mappings = () => {
useEffect(() => {
Expand All @@ -13,23 +18,22 @@ export const Mappings = () => {
const [action, setAction] = useState<ActionType>(ActionType.None);
const [codeName, setCodeName] = useState<string>('');

async function executeMappings(code: string, data: any, bindings: any) {
function parseMappings(code: string): Expression {
const mappings = JSON.parse(code) as FlatMappingPaths[];
return JsonTemplateEngine.create(mappings, { defaultPathType: PathType.JSON }).evaluate(
return JsonTemplateEngine.parse(mappings, { defaultPathType: PathType.JSON });
}

async function executeMappings(code: string, data: any, bindings: any) {
const expr = parseMappings(code);
return JsonTemplateEngine.create(expr, { defaultPathType: PathType.JSON }).evaluate(
data,
bindings,
);
}

function parseMappings(code: string) {
const mappings = JSON.parse(code) as FlatMappingPaths[];
return JsonTemplateEngine.parse(mappings);
}

function convertMappings(code: string) {
console.log(code);
const mappings = JSON.parse(code) as FlatMappingPaths[];
return JsonTemplateEngine.convertMappingsToTemplate(mappings, {
const expr = parseMappings(code);
return JsonTemplateEngine.reverseTranslate(expr, {
defaultPathType: PathType.JSON,
});
}
Expand Down

0 comments on commit f16571b

Please sign in to comment.