Add FirstMatchValue and Filter functions (#10042)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov
2025-10-07 23:17:04 +07:00
committed by GitHub
parent 0a682d03e3
commit f8205e57a1
29 changed files with 423 additions and 68 deletions
+18 -6
View File
@@ -90,12 +90,10 @@ function encodeValue (val: any): string {
return val ? 'true' : 'false'
case 'string':
return `"${val.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`
case 'object':
try {
return JSON.stringify(val)
} catch {
return String(val)
}
case 'object': {
const entries = Object.entries(val).map(([k, v]) => `${k}=${encodeValue(v)}`)
return `{${entries.join(',')}}`
}
}
return String(val)
@@ -384,6 +382,20 @@ function decodeValue (s: string): any {
if (inner === '') return []
return inner.split(',').map(decodeValue)
}
if (str.startsWith('{') && str.endsWith('}')) {
const inner = str.slice(1, -1).trim()
if (inner === '') return {}
const obj: Record<string, any> = {}
const entries = splitTopLevel(inner, ',')
for (const entry of entries) {
const eq = entry.indexOf('=')
if (eq === -1) continue
const key = entry.slice(0, eq).trim()
const val = entry.slice(eq + 1).trim()
obj[key] = decodeValue(val)
}
return obj
}
return str
}
+2
View File
@@ -277,6 +277,8 @@ export default plugin(processId, {
Time: '' as Asset
},
function: {
FirstMatchValue: '' as Ref<ProcessFunction>,
Filter: '' as Ref<ProcessFunction>,
FirstValue: '' as Ref<ProcessFunction>,
LastValue: '' as Ref<ProcessFunction>,
Random: '' as Ref<ProcessFunction>,