UNPKG

@tanstack/db

Version:

A reactive client store for building super fast apps on sync

123 lines (122 loc) 3.92 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const functions = require("./functions.cjs"); function extractValueFromNamespacedRow(namespacedRow, columnRef, mainTableAlias, joinedTableAlias) { if (columnRef.includes(`.`)) { const [tableAlias, colName] = columnRef.split(`.`); const tableData = namespacedRow[tableAlias]; if (!tableData) { return null; } const value = tableData[colName]; return value; } else { if (mainTableAlias && namespacedRow[mainTableAlias]) { const mainTableData = namespacedRow[mainTableAlias]; if (typeof mainTableData === `object` && columnRef in mainTableData) { return mainTableData[columnRef]; } } if (joinedTableAlias && namespacedRow[joinedTableAlias]) { const joinedTableData = namespacedRow[joinedTableAlias]; if (typeof joinedTableData === `object` && columnRef in joinedTableData) { return joinedTableData[columnRef]; } } for (const [_tableAlias, tableData] of Object.entries(namespacedRow)) { if (tableData && typeof tableData === `object` && columnRef in tableData) { return tableData[columnRef]; } } return void 0; } } function evaluateOperandOnNamespacedRow(namespacedRow, operand, mainTableAlias, joinedTableAlias) { if (typeof operand === `string` && operand.startsWith(`@`)) { const columnRef = operand.substring(1); return extractValueFromNamespacedRow( namespacedRow, columnRef, mainTableAlias, joinedTableAlias ); } if (operand && typeof operand === `object` && `col` in operand) { const colRef = operand.col; if (typeof colRef === `string`) { const nestedValue = extractValueFromNamespacedRow( namespacedRow, colRef, mainTableAlias, joinedTableAlias ); if (nestedValue === void 0 && colRef in namespacedRow) { return namespacedRow[colRef]; } return nestedValue; } return void 0; } if (operand && typeof operand === `object` && functions.isFunctionCall(operand)) { const functionName = Object.keys(operand)[0]; const args = operand[functionName]; const evaluatedArgs = Array.isArray(args) ? args.map( (arg) => evaluateOperandOnNamespacedRow( namespacedRow, arg, mainTableAlias, joinedTableAlias ) ) : evaluateOperandOnNamespacedRow( namespacedRow, args, mainTableAlias, joinedTableAlias ); return functions.evaluateFunction( functionName, evaluatedArgs ); } if (operand && typeof operand === `object` && `value` in operand) { return operand.value; } return operand; } function extractJoinKey(row, operand, defaultTableAlias) { let keyValue; if (typeof operand === `string` && operand.startsWith(`@`)) { const columnRef = operand.substring(1); if (columnRef.includes(`.`)) { const [tableAlias, colName] = columnRef.split(`.`); if (tableAlias === defaultTableAlias) { keyValue = row[colName]; } else { keyValue = void 0; } } else { keyValue = row[columnRef]; } } else if (operand && typeof operand === `object` && `col` in operand) { const colRef = operand.col; if (typeof colRef === `string`) { if (colRef.includes(`.`)) { const [tableAlias, colName] = colRef.split(`.`); if (tableAlias === defaultTableAlias) { keyValue = row[colName]; } else { keyValue = void 0; } } else { keyValue = row[colRef]; } } } else { keyValue = operand; } return keyValue; } exports.evaluateOperandOnNamespacedRow = evaluateOperandOnNamespacedRow; exports.extractJoinKey = extractJoinKey; exports.extractValueFromNamespacedRow = extractValueFromNamespacedRow; //# sourceMappingURL=extractors.cjs.map