SELECT SUBSTR(META().id,8) AS clientName,
ARRAY_FLATTEN(ARRAY ARRAY_CONCAT([v],IFMISSINGORNULL(v1.data.[v],[])) FOR v IN versions END,1) AS versions
FROM default
LET v1 = (SELECT RAW d FROM default AS d WHERE type = "versions")[0]
WHERE type = "client";
OR
SELECT ARRAY_AGG({"clientName":SUBSTR(META().id,8) ,
"versions":ARRAY_FLATTEN(ARRAY ARRAY_CONCAT([v],IFMISSINGORNULL(v1.data.[v],[])) FOR v IN versions END,1) } ) AS doc
FROM default
LET v1 = (SELECT RAW d FROM default AS d WHERE type = "versions")[0]
WHERE type = "client";
SELECT ARRAY_AGG({"clientName":SUBSTR(META().id,8) ,
"versions":ARRAY_FLATTEN(ARRAY ARRAY_CONCAT([{"versionName":v,"type":"parent/major"}],
ARRAY {"versionName":v2,"type":"child/minor"}
FOR v2 IN IFMISSINGORNULL(v1.data.[v],[]) END)
FOR v IN versions END,1) } )
FROM default
LET v1 = (SELECT RAW d FROM default AS d WHERE type = "versions")[0]
WHERE type = "client";
SELECT ARRAY_AGG({"clientName":SUBSTR(META().id,8) ,
"versions":ARRAY_FLATTEN(ARRAY ARRAY_CONCAT([{"versionName":v,"type":"major"}],
ARRAY {"versionName":v2,"type":"minor"}
FOR v2 IN IFMISSINGORNULL(v1.data.[v],[]) END)
FOR v IN versions END,1) } )
FROM default
LET v1 = (SELECT RAW d FROM default AS d WHERE type = "versions")[0]
WHERE type = "client";