UNPKG

@forzalabs/remora

Version:

A powerful CLI tool for seamless data translation.

150 lines (149 loc) 6.14 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs = __importStar(require("fs")); const path = __importStar(require("path")); const uuid_1 = require("uuid"); const ProcessENVManager_1 = __importDefault(require("../engines/ProcessENVManager")); const Helper = { isDev: () => ProcessENVManager_1.default.getEnvVariable('NODE_ENV') !== 'production', uuid: () => (0, uuid_1.v4)(), asError: (error) => error instanceof Error ? error : new Error(error), readFile: (directory) => { const functionFiles = []; function read(directory) { const files = fs.readdirSync(directory); files.forEach(filename => { const fullPath = path.join(directory, filename); if (fs.statSync(fullPath).isDirectory()) { read(fullPath); } else if (filename.endsWith('.json')) { functionFiles.push({ name: path.parse(filename).name, relativePath: directory }); } }); } read(directory); return functionFiles; }, formatDateToYYYYMM(date) { if (!date) return ''; const year = date.getFullYear(); const month = ('0' + (date.getMonth() + 1)).slice(-2); return `${year}-${month}`; }, formatDuration: (milliseconds) => { if (!milliseconds || milliseconds < 0) return '0ms'; if (milliseconds < 1000) { return `${Math.round(milliseconds)}ms`; } const seconds = milliseconds / 1000; if (seconds < 60) { return `${seconds.toFixed(1)}s`; } const minutes = Math.floor(seconds / 60); const remainingSeconds = seconds % 60; if (minutes < 60) { return `${minutes}m ${remainingSeconds.toFixed(1)}s`; } const hours = Math.floor(minutes / 60); const remainingMinutes = minutes % 60; return `${hours}h ${remainingMinutes}m`; }, matchPattern: (pattern, items) => { let patternParts = []; let hasWildcard = false; let result = [...items]; if (pattern) { if (pattern.includes('%')) { hasWildcard = true; const parts = pattern.split('%').filter(part => part.length > 0); // Store all non-empty parts for pattern matching patternParts = parts; } } // Apply additional filtering for patterns with wildcards if (hasWildcard && patternParts.length > 0) { result = result.filter(key => { // Create a function to check if the key matches the SQL-like pattern const matchesPattern = (fileName, pattern) => { if (!pattern.includes('%')) { return fileName === pattern; } const parts = pattern.split('%'); let currentIndex = 0; for (let i = 0; i < parts.length; i++) { const part = parts[i]; if (part === '') continue; // Skip empty parts from consecutive %% or leading/trailing % if (i === 0 && !pattern.startsWith('%')) { // First part must be at the beginning if (!fileName.startsWith(part)) { return false; } currentIndex = part.length; } else if (i === parts.length - 1 && !pattern.endsWith('%')) { // Last part must be at the end if (!fileName.endsWith(part)) { return false; } } else { // Middle parts must exist somewhere after the current position const foundIndex = fileName.indexOf(part, currentIndex); if (foundIndex === -1) { return false; } currentIndex = foundIndex + part.length; } } return true; }; return matchesPattern(key, pattern); }); } return result; } }; exports.default = Helper;