From 8df222616d5730259a2f4e6c1d8f733f25b0819e Mon Sep 17 00:00:00 2001 From: FredericoFalcao Date: Thu, 12 Jun 2025 12:26:17 +0300 Subject: [PATCH] docs: remove duplicate JavaScript version entry --- .gitignore | 4 ++ DbContinuousIntegrationWrapper.sh | 14 ++++--- Makefile | 16 +++++--- README.md | 4 +- install/SYS_PRD_BND.Npm.sql | 8 ++++ install/SYS_PRD_BND.Tables.sql | 1 + package.json.php | 29 ++++++++++++++ plt/generateJSTriggerCode.inc.php | 32 +++++++++++++++ plt/index.php | 64 ++++++++++++++++++++++++++++-- plt/runSandboxedJavascript.inc.php | 41 +++++++++++++++++++ 10 files changed, 196 insertions(+), 17 deletions(-) create mode 100644 install/SYS_PRD_BND.Npm.sql create mode 100644 package.json.php create mode 100644 plt/generateJSTriggerCode.inc.php create mode 100644 plt/runSandboxedJavascript.inc.php diff --git a/.gitignore b/.gitignore index e2c5124..2793078 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,7 @@ test_code.php modules/ requirements.txt +package.json +package-lock.json +npm.sync +node_modules/ diff --git a/DbContinuousIntegrationWrapper.sh b/DbContinuousIntegrationWrapper.sh index 15137df..902a20d 100755 --- a/DbContinuousIntegrationWrapper.sh +++ b/DbContinuousIntegrationWrapper.sh @@ -2,10 +2,12 @@ cd "$(dirname ${BASH_SOURCE[0]})" while [[ 1 ]] do - killall DbContinuousIntegrationWrapper.sh - /usr/bin/php composer.json.php > composer.json - touch -t $(/usr/bin/mysql -se "SELECT DATE_FORMAT(LastUpdated, '%Y%m%d%H%i.%s') FROM SYS_PRD_BND.Composer ORDER BY LastUpdated DESC LIMIT 1") composer.json - make - /usr/bin/php DbContinuousIntegration.php - sleep 10 + killall DbContinuousIntegrationWrapper.sh + /usr/bin/php composer.json.php > composer.json + touch -t $(/usr/bin/mysql -se "SELECT DATE_FORMAT(LastUpdated, '%Y%m%d%H%i.%s') FROM SYS_PRD_BND.Composer ORDER BY LastUpdated DESC LIMIT 1") composer.json + /usr/bin/php package.json.php > package.json + touch -t $(/usr/bin/mysql -se "SELECT DATE_FORMAT(LastUpdated, '%Y%m%d%H%i.%s') FROM SYS_PRD_BND.Npm ORDER BY LastUpdated DESC LIMIT 1") package.json + make + /usr/bin/php DbContinuousIntegration.php + sleep 10 done diff --git a/Makefile b/Makefile index a66e13c..b92ef18 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,18 @@ #!/bin/bash +all: composer.sync requirements.sync npm.sync + composer.sync: composer.json COMPOSER_ALLOW_SUPERUSER=1 composer update > $@ 2>&1 requirements.sync: requirements.txt - pip install -r requirements.txt $@ + pip install -r requirements.txt > $@ 2>&1 + +npm.sync: package.json + npm install > $@ 2>&1 + install: - echo "Add this line to crontab -e" - echo '@reboot /bin/bash /root/DbContinuousIntegration/DbContinuousIntegrationWrapper.sh 2> /dev/null > /dev/null &' - echo - echo 'CREATE TABLE SYS_PRD_BND.Tables (Name, onUpdate_phpCode, onUpdate_pyCode, LastUpdated);' | sudo mysql +@echo "Add this line to crontab -e" +@echo '@reboot /bin/bash /root/DbContinuousIntegration/DbContinuousIntegrationWrapper.sh 2> /dev/null > /dev/null &' +@echo +@echo 'CREATE TABLE SYS_PRD_BND.Tables (Name, onUpdate_phpCode, onUpdate_pyCode, onUpdate_jsCode, LastUpdated);' | sudo mysql diff --git a/README.md b/README.md index 9c72025..f6e28f6 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,11 @@ v0.4 - has an "export" and "import" module that converts sql data into a "git repo" / folder with code -v0.3 - supports Javacript / ECMA Script, and npm package manager ## AS IS: -v0.2 - has a function called "sql_read_hidrate()" that gives the foreign keys hidrated +v0.3 - supports Javascript / ECMA Script, and npm package manager +v0.2 - has a function called "sql_read_hidrate()" that gives the foreign keys hidrated - (useful for trigger functions like telegram outbox that need data like recipients hidrated) v0.1 - works. diff --git a/install/SYS_PRD_BND.Npm.sql b/install/SYS_PRD_BND.Npm.sql new file mode 100644 index 0000000..1972a5d --- /dev/null +++ b/install/SYS_PRD_BND.Npm.sql @@ -0,0 +1,8 @@ +USE SYS_PRD_BND; +CREATE TABLE `Npm` ( + `PackageName` varchar(255) NOT NULL, + `AliasName` varchar(255) DEFAULT NULL, + `VersionOrTag` varchar(25) DEFAULT NULL, + `LastUpdated` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + PRIMARY KEY (`PackageName`) +); diff --git a/install/SYS_PRD_BND.Tables.sql b/install/SYS_PRD_BND.Tables.sql index ed59025..7e9624a 100644 --- a/install/SYS_PRD_BND.Tables.sql +++ b/install/SYS_PRD_BND.Tables.sql @@ -3,6 +3,7 @@ CREATE TABLE `Tables` ( `Name` varchar(255) NOT NULL, `onUpdate_phpCode` text DEFAULT NULL, `onUpdate_pyCode` text DEFAULT NULL, + `onUpdate_jsCode` text DEFAULT NULL, `LastError` text DEFAULT NULL, `LastUpdated` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), PRIMARY KEY (`Name`) diff --git a/package.json.php b/package.json.php new file mode 100644 index 0000000..0963a18 --- /dev/null +++ b/package.json.php @@ -0,0 +1,29 @@ + PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, +]; + +try { + $pdo = new PDO($dsn, "root", "", $options); + + $stmt = $pdo->query("SELECT PackageName, VersionOrTag FROM Npm ORDER BY PackageName"); + $dependencies = []; + foreach ($stmt as $row) { + $ver = $row['VersionOrTag']; + $dependencies[$row['PackageName']] = $ver ?: '*'; + } + + $packageJson = [ + 'type' => 'module', + 'dependencies' => (object)$dependencies, + ]; + + file_put_contents('php://stdout', json_encode($packageJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); + file_put_contents('php://stderr', "✅ package.json generated successfully.\n"); + +} catch (PDOException $e) { + file_put_contents('php://stderr', "❌ Database error: " . $e->getMessage() . "\n"); +} diff --git a/plt/generateJSTriggerCode.inc.php b/plt/generateJSTriggerCode.inc.php new file mode 100644 index 0000000..219a2cb --- /dev/null +++ b/plt/generateJSTriggerCode.inc.php @@ -0,0 +1,32 @@ + ' ' . $l, explode("\n", $jsCode))); + + $javascript = << ['pipe', 'w'], + 2 => ['pipe', 'w'], + ]; + + $process = proc_open($command, $descriptorspec, $pipes); + + if (!is_resource($process)) { + unlink($tempFile); + throw new Exception('Failed to execute sandboxed JavaScript code.'); + } + + $stdout = stream_get_contents($pipes[1]); + fclose($pipes[1]); + + $stderr = stream_get_contents($pipes[2]); + fclose($pipes[2]); + + $exitCode = proc_close($process); + + unlink($tempFile); + + return $exitCode; +}