UNPKG

payload

Version:

Node, React, Headless CMS and Application Framework built on Next.js

43 lines (42 loc) 1.27 kB
/** * Builds a `where` fragment that scopes order operations to docs sharing the * same join `on` field value. */ export function buildJoinScopeWhere(args) { const { joinOnFieldPath, scopeValue } = args; if (typeof scopeValue === 'undefined') { return null; } if (Array.isArray(scopeValue)) { return buildJoinScopeWhere({ joinOnFieldPath, scopeValue: scopeValue[0] }); } if (scopeValue && typeof scopeValue === 'object' && 'relationTo' in scopeValue && 'value' in scopeValue) { const relation = scopeValue.relationTo; const value = scopeValue.value; if (typeof relation === 'undefined' || typeof value === 'undefined') { return null; } return { and: [ { [`${joinOnFieldPath}.relationTo`]: { equals: relation } }, { [`${joinOnFieldPath}.value`]: { equals: value } } ] }; } return { [joinOnFieldPath]: { equals: scopeValue } }; } //# sourceMappingURL=buildJoinScopeWhere.js.map