MCPcopy Create free account
hub / github.com/Thanas-R/Virdis / flattenExpression

Function flattenExpression

supabase/functions/gee-analytics/index.ts:99–122  ·  view source on GitHub ↗
(nested: any)

Source from the content-addressed store, hash-verified

97// ── Expression helpers ───────────────────────────────────────────
98
99function flattenExpression(nested: any): { values: Record<string, any>; result: string } {
100 const values: Record<string, any> = {};
101 let counter = 0;
102 function flatten(node: any): string {
103 if (node === null || node === undefined) {
104 const k = `_${counter++}`; values[k] = { constantValue: null }; return k;
105 }
106 if (node.functionInvocationValue) {
107 const fiv = node.functionInvocationValue;
108 const flatArgs: Record<string, any> = {};
109 for (const [argName, argVal] of Object.entries(fiv.arguments || {})) {
110 flatArgs[argName] = { valueReference: flatten(argVal as any) };
111 }
112 const k = `_${counter++}`;
113 values[k] = { functionInvocationValue: { functionName: fiv.functionName, arguments: flatArgs } };
114 return k;
115 }
116 if ("constantValue" in node) {
117 const k = `_${counter++}`; values[k] = { constantValue: node.constantValue }; return k;
118 }
119 const k = `_${counter++}`; values[k] = { constantValue: node }; return k;
120 }
121 return { values, result: flatten(nested) };
122}
123
124async function computeValue(token: string, projectId: string, expr: any): Promise<any> {
125 const flat = flattenExpression(expr);

Callers 1

computeValueFunction · 0.70

Calls 1

flattenFunction · 0.70

Tested by

no test coverage detected