UNPKG

tinybird-sdk

Version:
1 lines 845 B
"use strict";var _json2Csv=require("json-2-csv");Object.defineProperty(exports,"__esModule",{value:!0}),exports.validateAPIToken=exports.sanitizeSQL=exports.rowsToNDJSON=exports.rowsToCSV=exports.isValidSQLQuery=void 0;const validateAPIToken=a=>a&&"string"==typeof a&&a.length&&3===a.split(".").length&&"p"===a.split(".")[0];exports.validateAPIToken=validateAPIToken;const rowsToNDJSON=a=>(Array.isArray(a)||(a=[a]),a.map(JSON.stringify).join("\n"));exports.rowsToNDJSON=rowsToNDJSON;const rowsToCSV=a=>(0,_json2Csv.json2csvAsync)(a,{prependHeader:!1});exports.rowsToCSV=rowsToCSV;const isValidSQLQuery=a=>0===_formatSQL(a).indexOf("select");exports.isValidSQLQuery=isValidSQLQuery;const sanitizeSQL=a=>encodeURIComponent(`select * from (${_formatSQL(a)}) format JSON`);exports.sanitizeSQL=sanitizeSQL;const _formatSQL=a=>a.toLowerCase().trim();