mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-22 01:25:00 +02:00
Add FirstMatchValue and Filter functions (#10042)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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>,
|
||||
|
||||
Reference in New Issue
Block a user