@hypequery/cli 0.0.8 → 0.0.9

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.
Files changed (61) hide show
  1. package/dist/bin/cli.d.ts +3 -0
  2. package/dist/bin/cli.d.ts.map +1 -0
  3. package/dist/bin/cli.js +86 -0
  4. package/dist/cli.d.ts +4 -0
  5. package/dist/cli.d.ts.map +1 -0
  6. package/dist/cli.js +163 -0
  7. package/dist/commands/dev.d.ts +12 -0
  8. package/dist/commands/dev.d.ts.map +1 -0
  9. package/dist/commands/dev.js +265 -0
  10. package/dist/commands/generate.d.ts +8 -0
  11. package/dist/commands/generate.d.ts.map +1 -0
  12. package/dist/commands/generate.js +175 -0
  13. package/dist/commands/init.d.ts +10 -0
  14. package/dist/commands/init.d.ts.map +1 -0
  15. package/dist/commands/init.js +408 -0
  16. package/dist/generators/clickhouse.d.ts +7 -0
  17. package/dist/generators/clickhouse.d.ts.map +1 -0
  18. package/dist/generators/clickhouse.js +229 -0
  19. package/dist/generators/index.d.ts +7 -0
  20. package/dist/generators/index.d.ts.map +1 -0
  21. package/dist/generators/index.js +13 -0
  22. package/dist/templates/client.d.ts +5 -0
  23. package/dist/templates/client.d.ts.map +1 -0
  24. package/dist/templates/client.js +6 -0
  25. package/dist/templates/env.d.ts +14 -0
  26. package/dist/templates/env.d.ts.map +1 -0
  27. package/dist/templates/env.js +37 -0
  28. package/dist/templates/gitignore.d.ts +13 -0
  29. package/dist/templates/gitignore.d.ts.map +1 -0
  30. package/dist/templates/gitignore.js +22 -0
  31. package/dist/templates/queries.d.ts +8 -0
  32. package/dist/templates/queries.d.ts.map +1 -0
  33. package/dist/templates/queries.js +27 -0
  34. package/dist/test-utils.d.ts +86 -0
  35. package/dist/test-utils.d.ts.map +1 -0
  36. package/dist/test-utils.js +153 -0
  37. package/dist/utils/clickhouse-client.d.ts +11 -0
  38. package/dist/utils/clickhouse-client.d.ts.map +1 -0
  39. package/dist/utils/clickhouse-client.js +86 -0
  40. package/dist/utils/dependency-installer.d.ts +2 -0
  41. package/dist/utils/dependency-installer.d.ts.map +1 -0
  42. package/dist/utils/dependency-installer.js +180 -0
  43. package/dist/utils/detect-database.d.ts +21 -0
  44. package/dist/utils/detect-database.d.ts.map +1 -0
  45. package/dist/utils/detect-database.js +224 -0
  46. package/dist/utils/error-messages.d.ts +6 -0
  47. package/dist/utils/error-messages.d.ts.map +1 -0
  48. package/dist/utils/error-messages.js +19 -0
  49. package/dist/utils/find-files.d.ts +21 -0
  50. package/dist/utils/find-files.d.ts.map +1 -0
  51. package/dist/utils/find-files.js +183 -0
  52. package/dist/utils/load-api.d.ts +2 -0
  53. package/dist/utils/load-api.d.ts.map +1 -0
  54. package/dist/utils/load-api.js +400 -0
  55. package/dist/utils/logger.d.ts +54 -0
  56. package/dist/utils/logger.d.ts.map +1 -0
  57. package/dist/utils/logger.js +122 -0
  58. package/dist/utils/prompts.d.ts +39 -0
  59. package/dist/utils/prompts.d.ts.map +1 -0
  60. package/dist/utils/prompts.js +282 -0
  61. package/package.json +2 -2
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clickhouse-client.d.ts","sourceRoot":"","sources":["../../src/utils/clickhouse-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEzE,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AASD,wBAAgB,0BAA0B,IAAI,mBAAmB,GAAG,IAAI,CAavE;AAED,wBAAgB,mBAAmB,IAAI,gBAAgB,CAmBtD;AAED,wBAAsB,+BAA+B,kBAKpD"}
@@ -0,0 +1,86 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { createClient } from '@clickhouse/client';
38
+ var client = null;
39
+ function readEnv(name, fallback) {
40
+ var value = process.env[name];
41
+ return value === undefined || value === '' ? fallback : value;
42
+ }
43
+ export function getClickHouseConfigFromEnv() {
44
+ var _a;
45
+ var url = (_a = readEnv('CLICKHOUSE_URL')) !== null && _a !== void 0 ? _a : readEnv('CLICKHOUSE_HOST');
46
+ if (!url) {
47
+ return null;
48
+ }
49
+ return {
50
+ url: url,
51
+ username: readEnv('CLICKHOUSE_USERNAME', readEnv('CLICKHOUSE_USER', 'default')),
52
+ password: readEnv('CLICKHOUSE_PASSWORD', readEnv('CLICKHOUSE_PASS', '')),
53
+ database: readEnv('CLICKHOUSE_DATABASE', 'default'),
54
+ };
55
+ }
56
+ export function getClickHouseClient() {
57
+ if (!client) {
58
+ var config = getClickHouseConfigFromEnv();
59
+ if (!config) {
60
+ throw new Error('ClickHouse connection details are missing. Set CLICKHOUSE_HOST (or CLICKHOUSE_URL), CLICKHOUSE_DATABASE, CLICKHOUSE_USERNAME, and CLICKHOUSE_PASSWORD.');
61
+ }
62
+ client = createClient({
63
+ url: config.url,
64
+ username: config.username,
65
+ password: config.password,
66
+ database: config.database,
67
+ });
68
+ }
69
+ return client;
70
+ }
71
+ export function resetClickHouseClientForTesting() {
72
+ return __awaiter(this, void 0, void 0, function () {
73
+ return __generator(this, function (_a) {
74
+ switch (_a.label) {
75
+ case 0:
76
+ if (!client) return [3 /*break*/, 2];
77
+ return [4 /*yield*/, client.close()];
78
+ case 1:
79
+ _a.sent();
80
+ client = null;
81
+ _a.label = 2;
82
+ case 2: return [2 /*return*/];
83
+ }
84
+ });
85
+ });
86
+ }
@@ -0,0 +1,2 @@
1
+ export declare function installServeDependencies(): Promise<void>;
2
+ //# sourceMappingURL=dependency-installer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependency-installer.d.ts","sourceRoot":"","sources":["../../src/utils/dependency-installer.ts"],"names":[],"mappings":"AAyEA,wBAAsB,wBAAwB,kBA4C7C"}
@@ -0,0 +1,180 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
38
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
39
+ if (ar || !(i in from)) {
40
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
41
+ ar[i] = from[i];
42
+ }
43
+ }
44
+ return to.concat(ar || Array.prototype.slice.call(from));
45
+ };
46
+ import { existsSync } from 'node:fs';
47
+ import { readFile } from 'node:fs/promises';
48
+ import path from 'node:path';
49
+ import { spawn } from 'node:child_process';
50
+ import { logger } from './logger.js';
51
+ var REQUIRED_PACKAGES = ['@hypequery/clickhouse', '@hypequery/serve'];
52
+ var MANUAL_COMMANDS = {
53
+ pnpm: 'pnpm add',
54
+ yarn: 'yarn add',
55
+ npm: 'npm install',
56
+ bun: 'bun add',
57
+ };
58
+ function hasDependency(pkg, name) {
59
+ var _a, _b, _c;
60
+ return Boolean((_b = (_a = pkg.dependencies) === null || _a === void 0 ? void 0 : _a[name]) !== null && _b !== void 0 ? _b : (_c = pkg.devDependencies) === null || _c === void 0 ? void 0 : _c[name]);
61
+ }
62
+ function readProjectPackageJson() {
63
+ return __awaiter(this, void 0, void 0, function () {
64
+ var file, _a;
65
+ return __generator(this, function (_b) {
66
+ switch (_b.label) {
67
+ case 0:
68
+ _b.trys.push([0, 2, , 3]);
69
+ return [4 /*yield*/, readFile(path.join(process.cwd(), 'package.json'), 'utf8')];
70
+ case 1:
71
+ file = _b.sent();
72
+ return [2 /*return*/, JSON.parse(file)];
73
+ case 2:
74
+ _a = _b.sent();
75
+ return [2 /*return*/, null];
76
+ case 3: return [2 /*return*/];
77
+ }
78
+ });
79
+ });
80
+ }
81
+ function detectPackageManager(pkgJson) {
82
+ var _a, _b;
83
+ var userAgent = (_a = process.env.npm_config_user_agent) !== null && _a !== void 0 ? _a : '';
84
+ if (userAgent.includes('pnpm'))
85
+ return 'pnpm';
86
+ if (userAgent.includes('yarn'))
87
+ return 'yarn';
88
+ if (userAgent.includes('bun'))
89
+ return 'bun';
90
+ var declared = (_b = pkgJson === null || pkgJson === void 0 ? void 0 : pkgJson.packageManager) !== null && _b !== void 0 ? _b : '';
91
+ if (declared.startsWith('pnpm'))
92
+ return 'pnpm';
93
+ if (declared.startsWith('yarn'))
94
+ return 'yarn';
95
+ if (declared.startsWith('bun'))
96
+ return 'bun';
97
+ var cwd = process.cwd();
98
+ if (existsSync(path.join(cwd, 'pnpm-lock.yaml')))
99
+ return 'pnpm';
100
+ if (existsSync(path.join(cwd, 'yarn.lock')))
101
+ return 'yarn';
102
+ if (existsSync(path.join(cwd, 'bun.lockb')))
103
+ return 'bun';
104
+ return 'npm';
105
+ }
106
+ function getInstallArgs(manager, packages) {
107
+ switch (manager) {
108
+ case 'pnpm':
109
+ return __spreadArray(['add'], packages, true);
110
+ case 'yarn':
111
+ return __spreadArray(['add'], packages, true);
112
+ case 'bun':
113
+ return __spreadArray(['add'], packages, true);
114
+ case 'npm':
115
+ default:
116
+ return __spreadArray(['install'], packages, true);
117
+ }
118
+ }
119
+ function formatManualCommand(manager, packages) {
120
+ return "".concat(MANUAL_COMMANDS[manager], " ").concat(packages.join(' '));
121
+ }
122
+ export function installServeDependencies() {
123
+ return __awaiter(this, void 0, void 0, function () {
124
+ var pkgJson, missing, manager, command, args, error_1;
125
+ return __generator(this, function (_a) {
126
+ switch (_a.label) {
127
+ case 0:
128
+ if (process.env.HYPEQUERY_SKIP_INSTALL === '1') {
129
+ return [2 /*return*/];
130
+ }
131
+ return [4 /*yield*/, readProjectPackageJson()];
132
+ case 1:
133
+ pkgJson = _a.sent();
134
+ if (!pkgJson) {
135
+ logger.warn('package.json not found. Install @hypequery/clickhouse and @hypequery/serve manually.');
136
+ return [2 /*return*/];
137
+ }
138
+ missing = REQUIRED_PACKAGES.filter(function (pkg) { return !hasDependency(pkgJson, pkg); });
139
+ if (missing.length === 0) {
140
+ return [2 /*return*/];
141
+ }
142
+ manager = detectPackageManager(pkgJson);
143
+ command = manager === 'npm' ? 'npm' : manager;
144
+ args = getInstallArgs(manager, missing);
145
+ logger.info("Installing ".concat(missing.join(', '), " with ").concat(manager, "..."));
146
+ _a.label = 2;
147
+ case 2:
148
+ _a.trys.push([2, 4, , 5]);
149
+ return [4 /*yield*/, new Promise(function (resolve, reject) {
150
+ var child = spawn(command, args, {
151
+ cwd: process.cwd(),
152
+ stdio: 'inherit',
153
+ });
154
+ child.on('error', reject);
155
+ child.on('close', function (code) {
156
+ if (code === 0) {
157
+ resolve();
158
+ }
159
+ else {
160
+ reject(new Error("".concat(command, " exited with code ").concat(code)));
161
+ }
162
+ });
163
+ })];
164
+ case 3:
165
+ _a.sent();
166
+ logger.success("Installed ".concat(missing.join(', ')));
167
+ return [3 /*break*/, 5];
168
+ case 4:
169
+ error_1 = _a.sent();
170
+ logger.warn('Failed to install hypequery packages automatically.');
171
+ logger.info("Run manually: ".concat(formatManualCommand(manager, missing)));
172
+ if (error_1 instanceof Error && error_1.message) {
173
+ logger.info(error_1.message);
174
+ }
175
+ return [3 /*break*/, 5];
176
+ case 5: return [2 /*return*/];
177
+ }
178
+ });
179
+ });
180
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Database type detection result
3
+ */
4
+ export type DatabaseType = 'clickhouse' | 'bigquery' | 'unknown';
5
+ /**
6
+ * Auto-detect database type from environment or config files
7
+ */
8
+ export declare function detectDatabase(): Promise<DatabaseType>;
9
+ /**
10
+ * Validate database connection
11
+ */
12
+ export declare function validateConnection(dbType: DatabaseType): Promise<boolean>;
13
+ /**
14
+ * Get table count from database
15
+ */
16
+ export declare function getTableCount(dbType: DatabaseType): Promise<number>;
17
+ /**
18
+ * Get list of tables from database
19
+ */
20
+ export declare function getTables(dbType: DatabaseType): Promise<string[]>;
21
+ //# sourceMappingURL=detect-database.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect-database.d.ts","sourceRoot":"","sources":["../../src/utils/detect-database.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,YAAY,GAAG,UAAU,GAAG,SAAS,CAAC;AAEjE;;GAEG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,YAAY,CAAC,CAyC5D;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAS/E;AAuBD;;GAEG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAOzE;AAyBD;;GAEG;AACH,wBAAsB,SAAS,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAOvE"}
@@ -0,0 +1,224 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { access } from 'node:fs/promises';
38
+ import path from 'node:path';
39
+ import { getClickHouseClient } from './clickhouse-client.js';
40
+ /**
41
+ * Auto-detect database type from environment or config files
42
+ */
43
+ export function detectDatabase() {
44
+ return __awaiter(this, void 0, void 0, function () {
45
+ var envPath, readFile, envContent, _a;
46
+ return __generator(this, function (_b) {
47
+ switch (_b.label) {
48
+ case 0:
49
+ // Check environment variables
50
+ if (process.env.CLICKHOUSE_HOST ||
51
+ process.env.CLICKHOUSE_URL ||
52
+ process.env.CLICKHOUSE_DATABASE) {
53
+ return [2 /*return*/, 'clickhouse'];
54
+ }
55
+ if (process.env.BIGQUERY_PROJECT_ID || process.env.GOOGLE_APPLICATION_CREDENTIALS) {
56
+ return [2 /*return*/, 'bigquery'];
57
+ }
58
+ _b.label = 1;
59
+ case 1:
60
+ _b.trys.push([1, 5, , 6]);
61
+ envPath = path.join(process.cwd(), '.env');
62
+ return [4 /*yield*/, access(envPath)];
63
+ case 2:
64
+ _b.sent();
65
+ return [4 /*yield*/, import('node:fs/promises')];
66
+ case 3:
67
+ readFile = (_b.sent()).readFile;
68
+ return [4 /*yield*/, readFile(envPath, 'utf-8')];
69
+ case 4:
70
+ envContent = _b.sent();
71
+ if (envContent.includes('CLICKHOUSE_') ||
72
+ envContent.includes('CLICKHOUSE_HOST')) {
73
+ return [2 /*return*/, 'clickhouse'];
74
+ }
75
+ if (envContent.includes('BIGQUERY_') ||
76
+ envContent.includes('GOOGLE_APPLICATION_CREDENTIALS')) {
77
+ return [2 /*return*/, 'bigquery'];
78
+ }
79
+ return [3 /*break*/, 6];
80
+ case 5:
81
+ _a = _b.sent();
82
+ return [3 /*break*/, 6];
83
+ case 6: return [2 /*return*/, 'unknown'];
84
+ }
85
+ });
86
+ });
87
+ }
88
+ /**
89
+ * Validate database connection
90
+ */
91
+ export function validateConnection(dbType) {
92
+ return __awaiter(this, void 0, void 0, function () {
93
+ return __generator(this, function (_a) {
94
+ switch (dbType) {
95
+ case 'clickhouse':
96
+ return [2 /*return*/, validateClickHouse()];
97
+ case 'bigquery':
98
+ return [2 /*return*/, validateBigQuery()];
99
+ default:
100
+ return [2 /*return*/, false];
101
+ }
102
+ return [2 /*return*/];
103
+ });
104
+ });
105
+ }
106
+ function validateClickHouse() {
107
+ return __awaiter(this, void 0, void 0, function () {
108
+ var client, result, _a;
109
+ return __generator(this, function (_b) {
110
+ switch (_b.label) {
111
+ case 0:
112
+ _b.trys.push([0, 3, , 4]);
113
+ client = getClickHouseClient();
114
+ return [4 /*yield*/, client.query({
115
+ query: 'SELECT 1',
116
+ format: 'JSONEachRow',
117
+ })];
118
+ case 1:
119
+ result = _b.sent();
120
+ return [4 /*yield*/, result.json()];
121
+ case 2:
122
+ _b.sent();
123
+ return [2 /*return*/, true];
124
+ case 3:
125
+ _a = _b.sent();
126
+ return [2 /*return*/, false];
127
+ case 4: return [2 /*return*/];
128
+ }
129
+ });
130
+ });
131
+ }
132
+ function validateBigQuery() {
133
+ return __awaiter(this, void 0, void 0, function () {
134
+ return __generator(this, function (_a) {
135
+ // TODO: Implement when BigQuery support is added
136
+ return [2 /*return*/, false];
137
+ });
138
+ });
139
+ }
140
+ /**
141
+ * Get table count from database
142
+ */
143
+ export function getTableCount(dbType) {
144
+ return __awaiter(this, void 0, void 0, function () {
145
+ return __generator(this, function (_a) {
146
+ switch (dbType) {
147
+ case 'clickhouse':
148
+ return [2 /*return*/, getClickHouseTableCount()];
149
+ default:
150
+ return [2 /*return*/, 0];
151
+ }
152
+ return [2 /*return*/];
153
+ });
154
+ });
155
+ }
156
+ /**
157
+ * Generic helper to execute ClickHouse queries with consistent error handling
158
+ */
159
+ function executeClickHouseQuery(query, defaultValue) {
160
+ return __awaiter(this, void 0, void 0, function () {
161
+ var client, result, _a;
162
+ return __generator(this, function (_b) {
163
+ switch (_b.label) {
164
+ case 0:
165
+ _b.trys.push([0, 3, , 4]);
166
+ client = getClickHouseClient();
167
+ return [4 /*yield*/, client.query({
168
+ query: query,
169
+ format: 'JSONEachRow',
170
+ })];
171
+ case 1:
172
+ result = _b.sent();
173
+ return [4 /*yield*/, result.json()];
174
+ case 2: return [2 /*return*/, (_b.sent())];
175
+ case 3:
176
+ _a = _b.sent();
177
+ return [2 /*return*/, defaultValue];
178
+ case 4: return [2 /*return*/];
179
+ }
180
+ });
181
+ });
182
+ }
183
+ function getClickHouseTableCount() {
184
+ return __awaiter(this, void 0, void 0, function () {
185
+ var tables;
186
+ return __generator(this, function (_a) {
187
+ switch (_a.label) {
188
+ case 0: return [4 /*yield*/, executeClickHouseQuery('SHOW TABLES', [])];
189
+ case 1:
190
+ tables = _a.sent();
191
+ return [2 /*return*/, Array.isArray(tables) ? tables.length : 0];
192
+ }
193
+ });
194
+ });
195
+ }
196
+ /**
197
+ * Get list of tables from database
198
+ */
199
+ export function getTables(dbType) {
200
+ return __awaiter(this, void 0, void 0, function () {
201
+ return __generator(this, function (_a) {
202
+ switch (dbType) {
203
+ case 'clickhouse':
204
+ return [2 /*return*/, getClickHouseTables()];
205
+ default:
206
+ return [2 /*return*/, []];
207
+ }
208
+ return [2 /*return*/];
209
+ });
210
+ });
211
+ }
212
+ function getClickHouseTables() {
213
+ return __awaiter(this, void 0, void 0, function () {
214
+ var tables;
215
+ return __generator(this, function (_a) {
216
+ switch (_a.label) {
217
+ case 0: return [4 /*yield*/, executeClickHouseQuery('SHOW TABLES', [])];
218
+ case 1:
219
+ tables = _a.sent();
220
+ return [2 /*return*/, tables.map(function (t) { return t.name; })];
221
+ }
222
+ });
223
+ });
224
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Display error when queries file cannot be found
3
+ * @param commandName - Name of the command for the usage example
4
+ */
5
+ export declare function displayQueriesFileNotFoundError(commandName: string): void;
6
+ //# sourceMappingURL=error-messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-messages.d.ts","sourceRoot":"","sources":["../../src/utils/error-messages.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,+BAA+B,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAazE"}
@@ -0,0 +1,19 @@
1
+ import { logger } from './logger.js';
2
+ /**
3
+ * Display error when queries file cannot be found
4
+ * @param commandName - Name of the command for the usage example
5
+ */
6
+ export function displayQueriesFileNotFoundError(commandName) {
7
+ logger.error('Could not find queries file');
8
+ logger.newline();
9
+ logger.info('Expected one of:');
10
+ logger.indent('• analytics/queries.ts');
11
+ logger.indent('• src/analytics/queries.ts');
12
+ logger.indent('• hypequery.ts');
13
+ logger.newline();
14
+ logger.info("Did you run 'hypequery init'?");
15
+ logger.newline();
16
+ logger.info('Or specify the file explicitly:');
17
+ logger.indent("hypequery ".concat(commandName, " ./path/to/queries.ts"));
18
+ logger.newline();
19
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Find the queries file in the project
3
+ */
4
+ export declare function findQueriesFile(customPath?: string): Promise<string | null>;
5
+ /**
6
+ * Find the schema file (generated types)
7
+ */
8
+ export declare function findSchemaFile(): Promise<string | null>;
9
+ /**
10
+ * Find the client file
11
+ */
12
+ export declare function findClientFile(): Promise<string | null>;
13
+ /**
14
+ * Check if .env file exists
15
+ */
16
+ export declare function hasEnvFile(): Promise<boolean>;
17
+ /**
18
+ * Check if .gitignore exists
19
+ */
20
+ export declare function hasGitignore(): Promise<boolean>;
21
+ //# sourceMappingURL=find-files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-files.d.ts","sourceRoot":"","sources":["../../src/utils/find-files.ts"],"names":[],"mappings":"AA+BA;;GAEG;AACH,wBAAsB,eAAe,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAcjF;AAED;;GAEG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAO7D;AAED;;GAEG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAO7D;AAED;;GAEG;AACH,wBAAsB,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC,CAOnD;AAED;;GAEG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC,CAOrD"}