@hypequery/cli 1.1.2 → 1.2.0
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/README.md +26 -2
- package/dist/bin/cli.js +21 -81
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +72 -116
- package/dist/commands/dev.d.ts +1 -0
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +180 -255
- package/dist/commands/generate-datasets.d.ts +14 -0
- package/dist/commands/generate-datasets.d.ts.map +1 -0
- package/dist/commands/generate-datasets.js +96 -0
- package/dist/commands/generate.d.ts +2 -0
- package/dist/commands/generate.d.ts.map +1 -1
- package/dist/commands/generate.js +112 -167
- package/dist/commands/init.d.ts +7 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +337 -370
- package/dist/generators/clickhouse.d.ts +1 -1
- package/dist/generators/clickhouse.d.ts.map +1 -1
- package/dist/generators/clickhouse.js +10 -269
- package/dist/generators/dataset-generator.d.ts +16 -0
- package/dist/generators/dataset-generator.d.ts.map +1 -0
- package/dist/generators/dataset-generator.js +213 -0
- package/dist/generators/index.js +3 -3
- package/dist/templates/api.d.ts +9 -0
- package/dist/templates/api.d.ts.map +1 -0
- package/dist/templates/api.js +26 -0
- package/dist/templates/auth-scaffold.d.ts +17 -0
- package/dist/templates/auth-scaffold.d.ts.map +1 -0
- package/dist/templates/auth-scaffold.js +41 -0
- package/dist/templates/client.js +10 -1
- package/dist/templates/datasets.d.ts +5 -0
- package/dist/templates/datasets.d.ts.map +1 -0
- package/dist/templates/datasets.js +23 -0
- package/dist/templates/env.js +19 -8
- package/dist/templates/gitignore.js +4 -1
- package/dist/templates/queries.d.ts +3 -0
- package/dist/templates/queries.d.ts.map +1 -1
- package/dist/templates/queries.js +66 -10
- package/dist/test-utils.d.ts +0 -71
- package/dist/test-utils.d.ts.map +1 -1
- package/dist/test-utils.js +12 -137
- package/dist/utils/clickhouse-client.js +10 -57
- package/dist/utils/clickhouse-sql.d.ts +6 -0
- package/dist/utils/clickhouse-sql.d.ts.map +1 -0
- package/dist/utils/clickhouse-sql.js +18 -0
- package/dist/utils/clickhouse-type-utils.d.ts +6 -0
- package/dist/utils/clickhouse-type-utils.d.ts.map +1 -0
- package/dist/utils/clickhouse-type-utils.js +59 -0
- package/dist/utils/dependency-installer.d.ts +4 -2
- package/dist/utils/dependency-installer.d.ts.map +1 -1
- package/dist/utils/dependency-installer.js +93 -170
- package/dist/utils/detect-database.js +84 -195
- package/dist/utils/find-files.d.ts +3 -1
- package/dist/utils/find-files.d.ts.map +1 -1
- package/dist/utils/find-files.js +82 -148
- package/dist/utils/load-api.d.ts.map +1 -1
- package/dist/utils/load-api.js +207 -396
- package/dist/utils/logger.js +38 -42
- package/dist/utils/prompts.d.ts +14 -0
- package/dist/utils/prompts.d.ts.map +1 -1
- package/dist/utils/prompts.js +170 -219
- package/dist/utils/runtime-guards.d.ts +4 -0
- package/dist/utils/runtime-guards.d.ts.map +1 -0
- package/dist/utils/runtime-guards.js +9 -0
- package/dist/utils/sha256.d.ts +2 -0
- package/dist/utils/sha256.d.ts.map +1 -0
- package/dist/utils/sha256.js +4 -0
- package/package.json +3 -8
- package/dist/utils/error-messages.d.ts +0 -6
- package/dist/utils/error-messages.d.ts.map +0 -1
- package/dist/utils/error-messages.js +0 -19
- package/dist/utils/load-hypequery-config.d.ts +0 -7
- package/dist/utils/load-hypequery-config.d.ts.map +0 -1
- package/dist/utils/load-hypequery-config.js +0 -89
|
@@ -1,175 +1,120 @@
|
|
|
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
1
|
import path from 'node:path';
|
|
38
2
|
import ora from 'ora';
|
|
39
3
|
import { logger } from '../utils/logger.js';
|
|
40
4
|
import { findSchemaFile } from '../utils/find-files.js';
|
|
41
5
|
import { detectDatabase, getTableCount } from '../utils/detect-database.js';
|
|
42
6
|
import { getTypeGenerator } from '../generators/index.js';
|
|
43
|
-
export function generateCommand() {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
case 7:
|
|
86
|
-
_b.trys.push([7, 10, , 11]);
|
|
87
|
-
generator = getTypeGenerator(dbType);
|
|
88
|
-
return [4 /*yield*/, getTableCount(dbType)];
|
|
89
|
-
case 8:
|
|
90
|
-
tableCount = _b.sent();
|
|
91
|
-
spinner.succeed("Connected to ".concat(dbType === 'clickhouse' ? 'ClickHouse' : dbType));
|
|
92
|
-
logger.success("Found ".concat(tableCount, " tables"));
|
|
93
|
-
typeSpinner = ora('Generating types...').start();
|
|
94
|
-
return [4 /*yield*/, generator({
|
|
95
|
-
outputPath: outputPath,
|
|
96
|
-
includeTables: parsedTables,
|
|
97
|
-
})];
|
|
98
|
-
case 9:
|
|
99
|
-
_b.sent();
|
|
100
|
-
typeSpinner.succeed("Generated types for ".concat(tableCount, " tables"));
|
|
101
|
-
logger.success("Updated ".concat(path.relative(process.cwd(), outputPath)));
|
|
102
|
-
logger.newline();
|
|
103
|
-
logger.header('Types regenerated successfully!');
|
|
104
|
-
logger.newline();
|
|
105
|
-
return [3 /*break*/, 11];
|
|
106
|
-
case 10:
|
|
107
|
-
error_1 = _b.sent();
|
|
108
|
-
spinner.fail('Failed to generate types');
|
|
109
|
-
logger.newline();
|
|
110
|
-
if (error_1 instanceof Error) {
|
|
111
|
-
logger.error(error_1.message);
|
|
112
|
-
// Provide specific guidance based on error type
|
|
113
|
-
if (error_1.message.includes('ECONNREFUSED')) {
|
|
114
|
-
logger.newline();
|
|
115
|
-
logger.info('This usually means:');
|
|
116
|
-
logger.indent('• ClickHouse is not running');
|
|
117
|
-
logger.indent('• Wrong host/port in configuration');
|
|
118
|
-
logger.indent('• Firewall blocking connection');
|
|
119
|
-
logger.newline();
|
|
120
|
-
logger.info('Check your configuration:');
|
|
121
|
-
logger.indent('CLICKHOUSE_URL=' + (process.env.CLICKHOUSE_URL || process.env.CLICKHOUSE_HOST || 'not set'));
|
|
122
|
-
logger.newline();
|
|
123
|
-
logger.info('Docs: https://hypequery.com/docs/troubleshooting#connection-errors');
|
|
124
|
-
}
|
|
125
|
-
else if (error_1.message.includes('ETIMEDOUT') || error_1.message.includes('timeout')) {
|
|
126
|
-
logger.newline();
|
|
127
|
-
logger.info('Database connection timed out');
|
|
128
|
-
logger.newline();
|
|
129
|
-
logger.info('This usually means:');
|
|
130
|
-
logger.indent('• Database is running but not responding');
|
|
131
|
-
logger.indent('• Network latency is too high');
|
|
132
|
-
logger.indent('• Firewall is dropping packets');
|
|
133
|
-
logger.newline();
|
|
134
|
-
logger.info('Try:');
|
|
135
|
-
logger.indent('• Check if database is under heavy load');
|
|
136
|
-
logger.indent('• Verify network connectivity');
|
|
137
|
-
logger.indent('• Check firewall rules');
|
|
138
|
-
}
|
|
139
|
-
else if (error_1.message.toLowerCase().includes('ssl') || error_1.message.toLowerCase().includes('tls')) {
|
|
140
|
-
logger.newline();
|
|
141
|
-
logger.info('SSL/TLS connection error');
|
|
142
|
-
logger.newline();
|
|
143
|
-
logger.info('This usually means:');
|
|
144
|
-
logger.indent('• SSL certificate validation failed');
|
|
145
|
-
logger.indent('• Incorrect SSL configuration');
|
|
146
|
-
logger.newline();
|
|
147
|
-
logger.info('Try:');
|
|
148
|
-
logger.indent('• Check if your connection string requires SSL');
|
|
149
|
-
logger.indent('• Verify SSL certificate is valid');
|
|
150
|
-
logger.indent('• Check SSL-related environment variables');
|
|
151
|
-
}
|
|
152
|
-
else if (error_1.message.toLowerCase().includes('authentication') || error_1.message.toLowerCase().includes('auth')) {
|
|
153
|
-
logger.newline();
|
|
154
|
-
logger.info('Authentication failed');
|
|
155
|
-
logger.newline();
|
|
156
|
-
logger.info('This usually means:');
|
|
157
|
-
logger.indent('• Invalid username or password');
|
|
158
|
-
logger.indent('• User does not have required permissions');
|
|
159
|
-
logger.newline();
|
|
160
|
-
logger.info('Check your configuration:');
|
|
161
|
-
logger.indent('CLICKHOUSE_USERNAME=' + (process.env.CLICKHOUSE_USERNAME || 'not set'));
|
|
162
|
-
logger.indent('CLICKHOUSE_PASSWORD=' + (process.env.CLICKHOUSE_PASSWORD ? '***' : 'not set'));
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
logger.error(String(error_1));
|
|
167
|
-
}
|
|
168
|
-
logger.newline();
|
|
169
|
-
process.exit(1);
|
|
170
|
-
return [3 /*break*/, 11];
|
|
171
|
-
case 11: return [2 /*return*/];
|
|
172
|
-
}
|
|
7
|
+
export async function generateCommand(options = {}) {
|
|
8
|
+
// Determine output path
|
|
9
|
+
let outputPath;
|
|
10
|
+
if (options.output) {
|
|
11
|
+
outputPath = path.resolve(process.cwd(), options.output);
|
|
12
|
+
}
|
|
13
|
+
else if (options.path) {
|
|
14
|
+
outputPath = path.resolve(process.cwd(), options.path, 'schema.ts');
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
// Try to find existing schema file
|
|
18
|
+
const existingSchema = await findSchemaFile();
|
|
19
|
+
if (existingSchema) {
|
|
20
|
+
outputPath = existingSchema;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
// Default to analytics/schema.ts
|
|
24
|
+
outputPath = path.join(process.cwd(), 'analytics', 'schema.ts');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const parsedTables = options.tables
|
|
28
|
+
? options.tables
|
|
29
|
+
.split(',')
|
|
30
|
+
.map((table) => table.trim())
|
|
31
|
+
.filter(Boolean)
|
|
32
|
+
: undefined;
|
|
33
|
+
const requestedDbType = options.database;
|
|
34
|
+
const dbType = requestedDbType ?? (await detectDatabase());
|
|
35
|
+
logger.newline();
|
|
36
|
+
logger.header(options.commandName ?? 'hypequery generate');
|
|
37
|
+
const spinner = ora(`Connecting to ${dbType}...`).start();
|
|
38
|
+
try {
|
|
39
|
+
const generator = getTypeGenerator(dbType);
|
|
40
|
+
// Get table count
|
|
41
|
+
const tableCount = await getTableCount(dbType);
|
|
42
|
+
spinner.succeed(`Connected to ${dbType === 'clickhouse' ? 'ClickHouse' : dbType}`);
|
|
43
|
+
logger.success(`Found ${tableCount} tables`);
|
|
44
|
+
// Generate types
|
|
45
|
+
const typeSpinner = ora('Generating types...').start();
|
|
46
|
+
await generator({
|
|
47
|
+
outputPath,
|
|
48
|
+
includeTables: parsedTables,
|
|
173
49
|
});
|
|
174
|
-
|
|
50
|
+
typeSpinner.succeed(`Generated types for ${tableCount} tables`);
|
|
51
|
+
logger.success(`Updated ${path.relative(process.cwd(), outputPath)}`);
|
|
52
|
+
logger.newline();
|
|
53
|
+
logger.header('Types regenerated successfully!');
|
|
54
|
+
logger.newline();
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
spinner.fail('Failed to generate types');
|
|
58
|
+
logger.newline();
|
|
59
|
+
if (error instanceof Error) {
|
|
60
|
+
logger.error(error.message);
|
|
61
|
+
// Provide specific guidance based on error type
|
|
62
|
+
if (error.message.includes('ECONNREFUSED')) {
|
|
63
|
+
logger.newline();
|
|
64
|
+
logger.info('This usually means:');
|
|
65
|
+
logger.indent('• ClickHouse is not running');
|
|
66
|
+
logger.indent('• Wrong host/port in configuration');
|
|
67
|
+
logger.indent('• Firewall blocking connection');
|
|
68
|
+
logger.newline();
|
|
69
|
+
logger.info('Check your configuration:');
|
|
70
|
+
logger.indent('CLICKHOUSE_URL=' + (process.env.CLICKHOUSE_URL || process.env.CLICKHOUSE_HOST || 'not set'));
|
|
71
|
+
logger.newline();
|
|
72
|
+
logger.info('Docs: https://hypequery.com/docs/troubleshooting#connection-errors');
|
|
73
|
+
}
|
|
74
|
+
else if (error.message.includes('ETIMEDOUT') || error.message.includes('timeout')) {
|
|
75
|
+
logger.newline();
|
|
76
|
+
logger.info('Database connection timed out');
|
|
77
|
+
logger.newline();
|
|
78
|
+
logger.info('This usually means:');
|
|
79
|
+
logger.indent('• Database is running but not responding');
|
|
80
|
+
logger.indent('• Network latency is too high');
|
|
81
|
+
logger.indent('• Firewall is dropping packets');
|
|
82
|
+
logger.newline();
|
|
83
|
+
logger.info('Try:');
|
|
84
|
+
logger.indent('• Check if database is under heavy load');
|
|
85
|
+
logger.indent('• Verify network connectivity');
|
|
86
|
+
logger.indent('• Check firewall rules');
|
|
87
|
+
}
|
|
88
|
+
else if (error.message.toLowerCase().includes('ssl') || error.message.toLowerCase().includes('tls')) {
|
|
89
|
+
logger.newline();
|
|
90
|
+
logger.info('SSL/TLS connection error');
|
|
91
|
+
logger.newline();
|
|
92
|
+
logger.info('This usually means:');
|
|
93
|
+
logger.indent('• SSL certificate validation failed');
|
|
94
|
+
logger.indent('• Incorrect SSL configuration');
|
|
95
|
+
logger.newline();
|
|
96
|
+
logger.info('Try:');
|
|
97
|
+
logger.indent('• Check if your connection string requires SSL');
|
|
98
|
+
logger.indent('• Verify SSL certificate is valid');
|
|
99
|
+
logger.indent('• Check SSL-related environment variables');
|
|
100
|
+
}
|
|
101
|
+
else if (error.message.toLowerCase().includes('authentication') || error.message.toLowerCase().includes('auth')) {
|
|
102
|
+
logger.newline();
|
|
103
|
+
logger.info('Authentication failed');
|
|
104
|
+
logger.newline();
|
|
105
|
+
logger.info('This usually means:');
|
|
106
|
+
logger.indent('• Invalid username or password');
|
|
107
|
+
logger.indent('• User does not have required permissions');
|
|
108
|
+
logger.newline();
|
|
109
|
+
logger.info('Check your configuration:');
|
|
110
|
+
logger.indent('CLICKHOUSE_USERNAME=' + (process.env.CLICKHOUSE_USERNAME || 'not set'));
|
|
111
|
+
logger.indent('CLICKHOUSE_PASSWORD=' + (process.env.CLICKHOUSE_PASSWORD ? '***' : 'not set'));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
logger.error(String(error));
|
|
116
|
+
}
|
|
117
|
+
logger.newline();
|
|
118
|
+
process.exit(1);
|
|
119
|
+
}
|
|
175
120
|
}
|
package/dist/commands/init.d.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
import { type InitStyle } from '../utils/prompts.js';
|
|
2
|
+
import { type AuthTemplateMode } from '../templates/queries.js';
|
|
1
3
|
export interface InitOptions {
|
|
2
4
|
path?: string;
|
|
5
|
+
style?: InitStyle;
|
|
6
|
+
allTables?: boolean;
|
|
7
|
+
tables?: string;
|
|
8
|
+
excludeTables?: string;
|
|
3
9
|
noExample?: boolean;
|
|
4
10
|
noInteractive?: boolean;
|
|
5
11
|
force?: boolean;
|
|
6
12
|
skipConnection?: boolean;
|
|
13
|
+
auth?: AuthTemplateMode;
|
|
7
14
|
}
|
|
8
15
|
export declare function initCommand(options?: InitOptions): Promise<void>;
|
|
9
16
|
//# sourceMappingURL=init.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAIA,OAAO,EAUL,KAAK,SAAS,EACf,MAAM,qBAAqB,CAAC;AAS7B,OAAO,EAA2B,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAQzF,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,IAAI,CAAC,EAAE,gBAAgB,CAAC;CACzB;AAwFD,wBAAsB,WAAW,CAAC,OAAO,GAAE,WAAgB,iBAsT1D"}
|