UNPKG

@graphprotocol/graph-cli

Version:

CLI for building for and deploying to The Graph

32 lines (31 loc) 1.19 kB
export function disambiguateNames({ values, getName, setName, }) { const collisionCounter = new Map(); return values.map((value, index) => { const name = getName(value, index); const counter = collisionCounter.get(name); if (counter === undefined) { collisionCounter.set(name, 1); return setName(value, name); } collisionCounter.set(name, counter + 1); return setName(value, `${name}${counter}`); }); } export function isTupleType(t) { return t === 'tuple'; } export function containsTupleType(t) { return isTupleType(t) || isTupleArrayType(t) || isTupleMatrixType(t); } export function isTupleArrayType(t) { return t.match(/^tuple\[([0-9]+)?\]$/); } export function isTupleMatrixType(t) { return t.match(/^tuple\[([0-9]+)?\]\[([0-9]+)?\]$/); } export const unrollTuple = ({ path, value, }) => value.components.reduce((acc, component, index) => { const name = component.name || `value${index}`; return acc.concat(component.type === 'tuple' ? unrollTuple({ path: [...path, name], index, value: component }) : [{ path: [...path, name], type: component.type }]); }, []);