@jsondb-cloud/cli 1.0.0 → 1.0.10

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.
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.loadConfig = loadConfig;
37
+ exports.saveConfig = saveConfig;
38
+ exports.clearConfig = clearConfig;
39
+ exports.getConfigPath = getConfigPath;
40
+ const fs = __importStar(require("fs"));
41
+ const path = __importStar(require("path"));
42
+ const os = __importStar(require("os"));
43
+ const CONFIG_DIR = path.join(os.homedir(), ".config", "jsondb");
44
+ const CONFIG_FILE = path.join(CONFIG_DIR, "credentials.json");
45
+ function loadConfig() {
46
+ // Environment variable takes precedence
47
+ const envKey = process.env.JSONDB_API_KEY;
48
+ if (envKey) {
49
+ return {
50
+ apiKey: envKey,
51
+ project: process.env.JSONDB_PROJECT || process.env.JSONDB_NAMESPACE || "v1",
52
+ baseUrl: process.env.JSONDB_BASE_URL || "https://api.jsondb.cloud",
53
+ };
54
+ }
55
+ try {
56
+ const data = fs.readFileSync(CONFIG_FILE, "utf-8");
57
+ return JSON.parse(data);
58
+ }
59
+ catch {
60
+ return null;
61
+ }
62
+ }
63
+ function saveConfig(config) {
64
+ if (!fs.existsSync(CONFIG_DIR)) {
65
+ fs.mkdirSync(CONFIG_DIR, { recursive: true });
66
+ }
67
+ fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), { mode: 0o600 });
68
+ }
69
+ function clearConfig() {
70
+ try {
71
+ fs.unlinkSync(CONFIG_FILE);
72
+ }
73
+ catch {
74
+ // File doesn't exist
75
+ }
76
+ }
77
+ function getConfigPath() {
78
+ return CONFIG_FILE;
79
+ }
@@ -0,0 +1,5 @@
1
+ export declare function success(msg: string): void;
2
+ export declare function error(msg: string, suggestion?: string): void;
3
+ export declare function warn(msg: string): void;
4
+ export declare function printJson(data: unknown, raw?: boolean): void;
5
+ export declare function printTable(headers: string[], rows: string[][]): void;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.success = success;
4
+ exports.error = error;
5
+ exports.warn = warn;
6
+ exports.printJson = printJson;
7
+ exports.printTable = printTable;
8
+ const isTTY = process.stdout.isTTY;
9
+ function success(msg) {
10
+ if (isTTY) {
11
+ console.log(`\x1b[32m✓\x1b[0m ${msg}`);
12
+ }
13
+ else {
14
+ console.log(`OK: ${msg}`);
15
+ }
16
+ }
17
+ function error(msg, suggestion) {
18
+ if (isTTY) {
19
+ console.error(`\x1b[31m✗\x1b[0m Error: ${msg}`);
20
+ if (suggestion)
21
+ console.error(` ${suggestion}`);
22
+ }
23
+ else {
24
+ console.error(`ERROR: ${msg}`);
25
+ if (suggestion)
26
+ console.error(suggestion);
27
+ }
28
+ }
29
+ function warn(msg) {
30
+ if (isTTY) {
31
+ console.log(`\x1b[33m⚠\x1b[0m ${msg}`);
32
+ }
33
+ else {
34
+ console.log(`WARN: ${msg}`);
35
+ }
36
+ }
37
+ function printJson(data, raw = false) {
38
+ if (raw || !isTTY) {
39
+ console.log(JSON.stringify(data));
40
+ }
41
+ else {
42
+ console.log(JSON.stringify(data, null, 2));
43
+ }
44
+ }
45
+ function printTable(headers, rows) {
46
+ const widths = headers.map((h, i) => Math.max(h.length, ...rows.map((r) => (r[i] || "").length)));
47
+ const sep = widths.map((w) => "-".repeat(w)).join(" ");
48
+ const header = headers.map((h, i) => h.padEnd(widths[i])).join(" ");
49
+ console.log(header);
50
+ console.log(sep);
51
+ for (const row of rows) {
52
+ console.log(row.map((c, i) => (c || "").padEnd(widths[i])).join(" "));
53
+ }
54
+ }
package/package.json CHANGED
@@ -1,14 +1,17 @@
1
1
  {
2
2
  "name": "@jsondb-cloud/cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.10",
4
4
  "description": "CLI tool for jsondb.cloud — push, pull, manage your JSON database from the terminal",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
7
7
  "bin": {
8
- "jsondbcloud": "./bin/jsondb.js",
9
- "jsondb": "./bin/jsondb.js"
8
+ "jsondbcloud": "bin/jsondb.js",
9
+ "jsondb": "bin/jsondb.js"
10
10
  },
11
- "files": ["dist", "bin"],
11
+ "files": [
12
+ "dist",
13
+ "bin"
14
+ ],
12
15
  "scripts": {
13
16
  "build": "tsc",
14
17
  "dev": "tsc --watch",
@@ -21,10 +24,17 @@
21
24
  "typescript": "^5.4.0",
22
25
  "@types/node": "^20.0.0"
23
26
  },
24
- "keywords": ["jsondb", "cli", "json", "database", "api", "rest"],
27
+ "keywords": [
28
+ "jsondb",
29
+ "cli",
30
+ "json",
31
+ "database",
32
+ "api",
33
+ "rest"
34
+ ],
25
35
  "repository": {
26
36
  "type": "git",
27
- "url": "https://github.com/JsonDBCloud/cli"
37
+ "url": "git+https://github.com/JsonDBCloud/cli.git"
28
38
  },
29
39
  "engines": {
30
40
  "node": ">=18.0.0"