satoridb 1.1.6 → 1.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/add-to-path.sh CHANGED
@@ -1,25 +1,34 @@
1
1
  #!/bin/bash
2
2
 
3
3
  SATORI_PATH="$HOME/.satori/bin"
4
- PROFILE_FILES=("$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.profile")
5
-
6
- # Línea que añadiremos si no está
7
4
  EXPORT_LINE='export PATH="$HOME/.satori/bin:$PATH"'
8
5
 
9
- already_exists=false
10
-
11
- for profile in "${PROFILE_FILES[@]}"; do
12
- if [[ -f "$profile" ]] && grep -qF "$EXPORT_LINE" "$profile"; then
13
- echo "ℹ️ Ya existe PATH en $profile"
14
- already_exists=true
15
- break
6
+ # Detectar shell y archivo de configuración
7
+ detect_profile() {
8
+ if [ -n "$ZSH_VERSION" ]; then
9
+ echo "$HOME/.zshrc"
10
+ elif [ -n "$BASH_VERSION" ]; then
11
+ if [[ "$OSTYPE" == "darwin"* ]]; then
12
+ echo "$HOME/.bash_profile"
13
+ else
14
+ echo "$HOME/.bashrc"
15
+ fi
16
+ elif [ -n "$FISH_VERSION" ]; then
17
+ echo "$HOME/.config/fish/config.fish"
18
+ else
19
+ # Fallback general
20
+ echo "$HOME/.profile"
16
21
  fi
17
- done
22
+ }
18
23
 
19
- if ! $already_exists; then
20
- echo "✅ Añadiendo al PATH en ${PROFILE_FILES[0]}"
21
- echo -e "\n# Añadido por Satori\n$EXPORT_LINE" >> "${PROFILE_FILES[0]}"
22
- echo "🔄 Ejecuta: source ${PROFILE_FILES[0]}"
23
- else
24
+ PROFILE_FILE=$(detect_profile)
25
+
26
+ # Verificar si ya existe la línea
27
+ if [[ -f "$PROFILE_FILE" ]] && grep -qF "$EXPORT_LINE" "$PROFILE_FILE"; then
28
+ echo "ℹ️ Ya existe PATH en $PROFILE_FILE"
24
29
  echo "✅ PATH ya contiene ~/.satori/bin"
25
- fi
30
+ else
31
+ echo "✅ Añadiendo al PATH en $PROFILE_FILE"
32
+ echo -e "\n# Añadido por Satori\n$EXPORT_LINE" >> "$PROFILE_FILE"
33
+ echo "🔄 Ejecuta: source $PROFILE_FILE"
34
+ fi
package/cli.js CHANGED
@@ -1,13 +1,17 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  const path = require("path");
4
4
  const os = require("os");
5
5
  const fs = require("fs");
6
6
  const { spawnSync } = require("child_process");
7
+ const readline = require("readline");
8
+ const Satori = require("satori-node");
7
9
 
8
10
  const binName = os.platform() === "win32" ? "satori.exe" : "satori";
9
11
  const binPath = path.join(os.homedir(), ".satori", "bin", binName);
10
12
 
13
+ let satoriInstance = null;
14
+
11
15
  function run(args) {
12
16
  if (!fs.existsSync(binPath)) {
13
17
  console.log("❌ Satori no está instalado. Intenta reinstalar el paquete.");
@@ -21,10 +25,204 @@ function run(args) {
21
25
  }
22
26
  }
23
27
 
28
+ async function connectToSatori(host, user, password) {
29
+ try {
30
+ console.log(`🔗 Conectando a ${host}...`);
31
+ satoriInstance = new Satori(host, user, password);
32
+ await satoriInstance.connect();
33
+ console.log("✅ Conexión exitosa a SatoriDB");
34
+ return true;
35
+ } catch (error) {
36
+ console.log("❌ Error al conectar:", error.message);
37
+ return false;
38
+ }
39
+ }
40
+
41
+ async function executeCommand(command, args) {
42
+ if (!satoriInstance) {
43
+ console.log("❌ No hay conexión activa. Usa 'connect <host> <user> <password>' primero.");
44
+ return;
45
+ }
46
+
47
+ try {
48
+ switch (command) {
49
+ case "set":
50
+ if (args.length < 2) {
51
+ console.log("❌ Uso: set <key> <data>");
52
+ return;
53
+ }
54
+ const [key, data] = args;
55
+ await satoriInstance.set(key, data);
56
+ console.log(`✅ Datos guardados en clave: ${key}`);
57
+ break;
58
+
59
+ case "put":
60
+ if (args.length < 3) {
61
+ console.log("❌ Uso: put <key> <replace_field> <replace_value>");
62
+ return;
63
+ }
64
+ const [putKey, replaceField, replaceValue] = args;
65
+ await satoriInstance.put(putKey, replaceField, replaceValue);
66
+ console.log(`✅ Campo actualizado: ${putKey}.${replaceField} = ${replaceValue}`);
67
+ break;
68
+
69
+ case "get":
70
+ if (args.length < 1) {
71
+ console.log("❌ Uso: get <key>");
72
+ return;
73
+ }
74
+ const getKey = args[0];
75
+ const result = await satoriInstance.get(getKey);
76
+ console.log(`📄 Datos de ${getKey}:`, JSON.stringify(result, null, 2));
77
+ break;
78
+
79
+ case "delete":
80
+ if (args.length < 1) {
81
+ console.log("❌ Uso: delete <key>");
82
+ return;
83
+ }
84
+ const deleteKey = args[0];
85
+ await satoriInstance.delete(deleteKey);
86
+ console.log(`🗑️ Clave eliminada: ${deleteKey}`);
87
+ break;
88
+
89
+ case "list":
90
+ const keys = await satoriInstance.list();
91
+ console.log("📋 Claves disponibles:", keys);
92
+ break;
93
+
94
+ case "search":
95
+ if (args.length < 1) {
96
+ console.log("❌ Uso: search <query>");
97
+ return;
98
+ }
99
+ const query = args[0];
100
+ const searchResults = await satoriInstance.search(query);
101
+ console.log("🔍 Resultados de búsqueda:", JSON.stringify(searchResults, null, 2));
102
+ break;
103
+
104
+ case "help":
105
+ showHelp();
106
+ break;
107
+
108
+ case "exit":
109
+ case "quit":
110
+ console.log("👋 ¡Hasta luego!");
111
+ process.exit(0);
112
+ break;
113
+
114
+ default:
115
+ console.log("❌ Comando no reconocido. Usa 'help' para ver comandos disponibles.");
116
+ }
117
+ } catch (error) {
118
+ console.log("❌ Error ejecutando comando:", error.message);
119
+ }
120
+ }
121
+
122
+ function showHelp() {
123
+ console.log(`
124
+ 📚 Comandos disponibles:
125
+
126
+ 🔗 Conexión:
127
+ connect <host> <user> <password> - Conectar a SatoriDB
128
+
129
+ 📝 Operaciones de datos:
130
+ set <key> <data> - Guardar datos en una clave
131
+ put <key> <field> <value> - Actualizar un campo específico
132
+ get <key> - Obtener datos de una clave
133
+ delete <key> - Eliminar una clave
134
+ list - Listar todas las claves
135
+ search <query> - Buscar datos
136
+
137
+ 🛠️ Otros:
138
+ help - Mostrar esta ayuda
139
+ exit / quit - Salir de la CLI
140
+ clear - Limpiar pantalla
141
+
142
+ 💡 Ejemplo: set user:123 '{"name": "Juan", "age": 25}'
143
+ `);
144
+ }
145
+
146
+ function clearScreen() {
147
+ console.clear();
148
+ }
149
+
150
+ async function startInteractiveCLI() {
151
+ const rl = readline.createInterface({
152
+ input: process.stdin,
153
+ output: process.stdout,
154
+ prompt: 'satori> '
155
+ });
156
+
157
+ console.log("🚀 SatoriDB CLI Interactiva");
158
+ console.log("📝 Escribe 'help' para ver comandos disponibles");
159
+ console.log("💡 Usa 'connect <host> <user> <password>' para comenzar\n");
160
+
161
+ rl.prompt();
162
+
163
+ rl.on('line', async (line) => {
164
+ const trimmedLine = line.trim();
165
+
166
+ if (trimmedLine === '') {
167
+ rl.prompt();
168
+ return;
169
+ }
170
+
171
+ if (trimmedLine === 'clear') {
172
+ clearScreen();
173
+ rl.prompt();
174
+ return;
175
+ }
176
+
177
+ const parts = trimmedLine.split(' ');
178
+ const command = parts[0];
179
+ const args = parts.slice(1);
180
+
181
+ if (command === 'connect') {
182
+ if (args.length < 3) {
183
+ console.log("❌ Uso: connect <host> <user> <password>");
184
+ rl.prompt();
185
+ return;
186
+ }
187
+ const [host, user, password] = args;
188
+ const success = await connectToSatori(host, user, password);
189
+ if (success) {
190
+ console.log("✅ Ahora puedes usar comandos como 'set', 'get', 'put', etc.");
191
+ }
192
+ } else {
193
+ await executeCommand(command, args);
194
+ }
195
+
196
+ rl.prompt();
197
+ });
198
+
199
+ rl.on('close', () => {
200
+ console.log('\n👋 ¡Hasta luego!');
201
+ process.exit(0);
202
+ });
203
+ }
204
+
24
205
  const args = process.argv.slice(2);
206
+
25
207
  if (args[0] === "update") {
26
208
  console.log("🔄 Ejecutando actualización...");
27
209
  require("./postinstall");
210
+ } else if (args[0] === "run") {
211
+ run(args.slice(1));
212
+ } else if (args[0] === "connect") {
213
+ if (args.length < 4) {
214
+ console.log("❌ Uso: satoridb connect <host> <user> <password>");
215
+ process.exit(1);
216
+ }
217
+ const [host, user, password] = args.slice(1);
218
+ connectToSatori(host, user, password).then(success => {
219
+ if (success) {
220
+ startInteractiveCLI();
221
+ } else {
222
+ process.exit(1);
223
+ }
224
+ });
28
225
  } else {
29
- run(args);
30
- }
226
+ // Si no hay argumentos o argumentos no reconocidos, iniciar CLI interactiva
227
+ startInteractiveCLI();
228
+ }
package/package.json CHANGED
@@ -1,16 +1,17 @@
1
1
  {
2
2
  "name": "satoridb",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "description": "Install satori",
5
- "bin" : {
6
- "satori" : "./cli.js"
5
+ "bin": {
6
+ "satoridb": "./cli.js"
7
7
  },
8
8
  "scripts": {
9
- "postinstall" : "node postinstall.js"
9
+ "postinstall": "node postinstall.js"
10
10
  },
11
11
  "author": "",
12
12
  "license": "ISC",
13
13
  "dependencies": {
14
- "adm-zip": "^0.5.16"
14
+ "adm-zip": "^0.5.16",
15
+ "satori-node": "^1.0.51"
15
16
  }
16
17
  }
package/postinstall.js CHANGED
@@ -13,17 +13,18 @@ const baseURL = "https://www.satoridb.com";
13
13
  let fileName;
14
14
 
15
15
  if (platform === "linux") fileName = "lin/satori-linux.zip";
16
- else if (platform === "darwin") fileName = "mac/satori-mac.zip";
16
+ else if (platform === "darwin") fileName = "mac/satori-mac-universal.zip"; // <- ZIP universal
17
17
  else if (platform === "win32") fileName = "win/satori-win.zip";
18
18
  else {
19
19
  console.log("❌ Not supported platform:", platform);
20
20
  process.exit(1);
21
21
  }
22
22
 
23
+ const binName = platform === "win32" ? "satori.exe" : "satori";
24
+
23
25
  const tmpDir = path.join(os.tmpdir(), "satori-temp");
24
26
  const zipPath = path.join(tmpDir, fileName);
25
27
  const installDir = path.join(os.homedir(), ".satori", "bin");
26
- const binName = platform === "win32" ? "satori.exe" : "satori";
27
28
  const binFullPath = path.join(installDir, binName);
28
29
 
29
30