UNPKG

@sidekick-coder/db

Version:

Cli Tool to manipulate data from diferent sources

81 lines (78 loc) 1.79 kB
'use strict'; // src/providers/notion/parseWhere.ts var dateOperatorsMap = { eq: "equals", ne: "does_not_equal", gt: "after", gte: "on_or_after", lt: "before", lte: "on_or_before" }; function parseWhere(where, properties) { const { and, or, ...rest } = where; const property = properties[rest.field]; const result = { and: [], or: [] }; if (rest.operator === "in") { const or2 = rest.value.map((v) => ({ property: rest.field, [property.type]: { equals: v } })); return { or: or2 }; } if (rest.operator === "exists") { return { property: rest.field, [property.type]: { is_not_empty: rest.value ? true : void 0, is_empty: rest.value ? void 0 : true } }; } if ((property == null ? void 0 : property.type) === "formula") { return { property: rest.field, [property.type]: { string: { contains: rest.value } } }; } if (property && (rest == null ? void 0 : rest.field) && (rest == null ? void 0 : rest.operator)) { const notionOperator = dateOperatorsMap[rest.operator] || "equals"; return { property: rest.field, [property.type]: { [notionOperator]: rest.value } }; } if (and == null ? void 0 : and.length) { and.forEach((w) => { result.and.push(parseWhere(w, properties)); }); } if (or == null ? void 0 : or.length) { or.forEach((w) => { result.or.push(parseWhere(w, properties)); }); } if (result.and.length === 1 && !result.or.length) { return result.and[0]; } if (!result.or.length) { delete result.or; } if (!result.and.length) { delete result.and; } return result; } exports.parseWhere = parseWhere;