@hypequery/cli 0.0.5 → 0.0.7

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 (68) hide show
  1. package/LICENSE +201 -0
  2. package/package.json +11 -11
  3. package/dist/bin/cli.d.ts +0 -3
  4. package/dist/bin/cli.d.ts.map +0 -1
  5. package/dist/bin/cli.js +0 -86
  6. package/dist/cli.d.ts +0 -4
  7. package/dist/cli.d.ts.map +0 -1
  8. package/dist/cli.js +0 -162
  9. package/dist/commands/create-api-types.d.ts +0 -6
  10. package/dist/commands/create-api-types.d.ts.map +0 -1
  11. package/dist/commands/create-api-types.js +0 -149
  12. package/dist/commands/dev.d.ts +0 -12
  13. package/dist/commands/dev.d.ts.map +0 -1
  14. package/dist/commands/dev.js +0 -249
  15. package/dist/commands/generate.d.ts +0 -8
  16. package/dist/commands/generate.d.ts.map +0 -1
  17. package/dist/commands/generate.js +0 -175
  18. package/dist/commands/init.d.ts +0 -9
  19. package/dist/commands/init.d.ts.map +0 -1
  20. package/dist/commands/init.js +0 -362
  21. package/dist/commands/toolkit.d.ts +0 -6
  22. package/dist/commands/toolkit.d.ts.map +0 -1
  23. package/dist/commands/toolkit.js +0 -159
  24. package/dist/generators/clickhouse.d.ts +0 -7
  25. package/dist/generators/clickhouse.d.ts.map +0 -1
  26. package/dist/generators/clickhouse.js +0 -229
  27. package/dist/generators/index.d.ts +0 -7
  28. package/dist/generators/index.d.ts.map +0 -1
  29. package/dist/generators/index.js +0 -13
  30. package/dist/templates/client.d.ts +0 -5
  31. package/dist/templates/client.d.ts.map +0 -1
  32. package/dist/templates/client.js +0 -6
  33. package/dist/templates/env.d.ts +0 -14
  34. package/dist/templates/env.d.ts.map +0 -1
  35. package/dist/templates/env.js +0 -37
  36. package/dist/templates/gitignore.d.ts +0 -13
  37. package/dist/templates/gitignore.d.ts.map +0 -1
  38. package/dist/templates/gitignore.js +0 -22
  39. package/dist/templates/queries.d.ts +0 -8
  40. package/dist/templates/queries.d.ts.map +0 -1
  41. package/dist/templates/queries.js +0 -27
  42. package/dist/test-utils.d.ts +0 -86
  43. package/dist/test-utils.d.ts.map +0 -1
  44. package/dist/test-utils.js +0 -153
  45. package/dist/utils/clickhouse-client.d.ts +0 -11
  46. package/dist/utils/clickhouse-client.d.ts.map +0 -1
  47. package/dist/utils/clickhouse-client.js +0 -86
  48. package/dist/utils/detect-database.d.ts +0 -21
  49. package/dist/utils/detect-database.d.ts.map +0 -1
  50. package/dist/utils/detect-database.js +0 -224
  51. package/dist/utils/ensure-ts-runtime.d.ts +0 -4
  52. package/dist/utils/ensure-ts-runtime.d.ts.map +0 -1
  53. package/dist/utils/ensure-ts-runtime.js +0 -66
  54. package/dist/utils/error-messages.d.ts +0 -6
  55. package/dist/utils/error-messages.d.ts.map +0 -1
  56. package/dist/utils/error-messages.js +0 -19
  57. package/dist/utils/find-files.d.ts +0 -21
  58. package/dist/utils/find-files.d.ts.map +0 -1
  59. package/dist/utils/find-files.js +0 -183
  60. package/dist/utils/load-api.d.ts +0 -2
  61. package/dist/utils/load-api.d.ts.map +0 -1
  62. package/dist/utils/load-api.js +0 -308
  63. package/dist/utils/logger.d.ts +0 -54
  64. package/dist/utils/logger.d.ts.map +0 -1
  65. package/dist/utils/logger.js +0 -122
  66. package/dist/utils/prompts.d.ts +0 -39
  67. package/dist/utils/prompts.d.ts.map +0 -1
  68. package/dist/utils/prompts.js +0 -282
@@ -1,149 +0,0 @@
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 fs from 'node:fs/promises';
38
- import path from 'node:path';
39
- import ora from 'ora';
40
- import { logger } from '../utils/logger.js';
41
- import { findQueriesFile } from '../utils/find-files.js';
42
- import { loadApiModule } from '../utils/load-api.js';
43
- import { displayQueriesFileNotFoundError } from '../utils/error-messages.js';
44
- var DEFAULT_TYPE_NAME = 'HypequeryApi';
45
- var ensureDotPrefix = function (value) { return (value.startsWith('.') ? value : "./".concat(value)); };
46
- var removeExtension = function (value) { return value.replace(/\.(tsx|ts|mts|cts|jsx|js|mjs|cjs)$/i, ''); };
47
- function getDefaultOutputPath(queriesFile) {
48
- var directory = path.dirname(queriesFile);
49
- return path.join(directory, 'client.ts');
50
- }
51
- function buildImportPath(from, to) {
52
- var relative = path.relative(path.dirname(from), to).replace(/\\/g, '/');
53
- return removeExtension(ensureDotPrefix(relative));
54
- }
55
- function buildClientFile(typeName, queries, importPath) {
56
- var lines = [];
57
- lines.push('// @generated by hypequery create-api-types');
58
- lines.push("// ".concat(new Date().toISOString()));
59
- lines.push('// Do not edit manually.');
60
- lines.push('');
61
- lines.push("import type { InferQueryInput, InferQueryResult } from '@hypequery/serve';");
62
- lines.push("import type * as HypequeryModule from '".concat(importPath, "';"));
63
- lines.push('');
64
- lines.push('type ServeApi = HypequeryModule extends { api: infer T }');
65
- lines.push(' ? T');
66
- lines.push(' : HypequeryModule extends { default: infer T }');
67
- lines.push(' ? T');
68
- lines.push(' : never;');
69
- lines.push('');
70
- lines.push("export type ".concat(typeName, " = {"));
71
- if (queries.length === 0) {
72
- lines.push(' // No queries registered yet');
73
- }
74
- else {
75
- for (var _i = 0, queries_1 = queries; _i < queries_1.length; _i++) {
76
- var query = queries_1[_i];
77
- lines.push(" ".concat(query, ": {"));
78
- lines.push(" input: InferQueryInput<ServeApi, '".concat(query, "'>;"));
79
- lines.push(" output: InferQueryResult<ServeApi, '".concat(query, "'>;"));
80
- lines.push(' };');
81
- }
82
- }
83
- lines.push('};');
84
- lines.push('');
85
- return lines.join('\n');
86
- }
87
- export function createApiTypesCommand(file_1) {
88
- return __awaiter(this, arguments, void 0, function (file, options) {
89
- var queriesFile, outputPath, typeName, spinner, api, queryKeys, importPath, fileContents, relativeOutput, error_1;
90
- var _a, _b, _c;
91
- if (options === void 0) { options = {}; }
92
- return __generator(this, function (_d) {
93
- switch (_d.label) {
94
- case 0: return [4 /*yield*/, findQueriesFile(file)];
95
- case 1:
96
- queriesFile = _d.sent();
97
- if (!queriesFile) {
98
- displayQueriesFileNotFoundError('create-api-types');
99
- process.exit(1);
100
- }
101
- outputPath = path.resolve(process.cwd(), (_a = options.output) !== null && _a !== void 0 ? _a : getDefaultOutputPath(queriesFile));
102
- typeName = (_b = options.name) !== null && _b !== void 0 ? _b : DEFAULT_TYPE_NAME;
103
- spinner = ora('Loading serve API...').start();
104
- _d.label = 2;
105
- case 2:
106
- _d.trys.push([2, 6, , 7]);
107
- return [4 /*yield*/, loadApiModule(queriesFile)];
108
- case 3:
109
- api = _d.sent();
110
- spinner.succeed('Loaded serve API');
111
- queryKeys = Object.keys((_c = api.queries) !== null && _c !== void 0 ? _c : {}).sort();
112
- importPath = buildImportPath(outputPath, queriesFile);
113
- fileContents = buildClientFile(typeName, queryKeys, importPath);
114
- return [4 /*yield*/, fs.mkdir(path.dirname(outputPath), { recursive: true })];
115
- case 4:
116
- _d.sent();
117
- return [4 /*yield*/, fs.writeFile(outputPath, fileContents, 'utf8')];
118
- case 5:
119
- _d.sent();
120
- relativeOutput = path.relative(process.cwd(), outputPath);
121
- logger.newline();
122
- if (queryKeys.length === 0) {
123
- logger.warn('Generated client for an empty serve catalog. Add queries to your API file.');
124
- }
125
- else {
126
- logger.success("Mapped ".concat(queryKeys.length, " ").concat(queryKeys.length === 1 ? 'query' : 'queries'));
127
- }
128
- logger.success("Wrote ".concat(relativeOutput));
129
- logger.newline();
130
- logger.info("Import the generated type and pass it to createHooks() or your HTTP client.");
131
- return [3 /*break*/, 7];
132
- case 6:
133
- error_1 = _d.sent();
134
- spinner.fail('Failed to generate client types');
135
- logger.newline();
136
- if (error_1 instanceof Error) {
137
- logger.error(error_1.message);
138
- }
139
- else {
140
- logger.error(String(error_1));
141
- }
142
- logger.newline();
143
- process.exit(1);
144
- return [3 /*break*/, 7];
145
- case 7: return [2 /*return*/];
146
- }
147
- });
148
- });
149
- }
@@ -1,12 +0,0 @@
1
- export interface DevOptions {
2
- port?: number;
3
- hostname?: string;
4
- watch?: boolean;
5
- quiet?: boolean;
6
- cache?: string;
7
- redisUrl?: string;
8
- open?: boolean;
9
- cors?: boolean;
10
- }
11
- export declare function devCommand(file?: string, options?: DevOptions): Promise<void>;
12
- //# sourceMappingURL=dev.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/commands/dev.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,wBAAsB,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,iBAqKvE"}
@@ -1,249 +0,0 @@
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 { watch } from 'node:fs';
38
- import path from 'node:path';
39
- import { logger } from '../utils/logger.js';
40
- import { findQueriesFile } from '../utils/find-files.js';
41
- import { getTableCount } from '../utils/detect-database.js';
42
- import { loadApiModule } from '../utils/load-api.js';
43
- import { displayQueriesFileNotFoundError } from '../utils/error-messages.js';
44
- export function devCommand(file_1) {
45
- return __awaiter(this, arguments, void 0, function (file, options) {
46
- var queriesFile, currentServer, shouldWatch, startServer, restartServer, shutdown, watchDir, debounceTimer_1, watcher_1;
47
- var _this = this;
48
- if (options === void 0) { options = {}; }
49
- return __generator(this, function (_a) {
50
- switch (_a.label) {
51
- case 0: return [4 /*yield*/, findQueriesFile(file)];
52
- case 1:
53
- queriesFile = _a.sent();
54
- if (!queriesFile) {
55
- displayQueriesFileNotFoundError('dev');
56
- process.exit(1);
57
- }
58
- logger.info("Found: ".concat(path.relative(process.cwd(), queriesFile)));
59
- logger.newline();
60
- currentServer = null;
61
- shouldWatch = options.watch !== false;
62
- startServer = function () { return __awaiter(_this, void 0, void 0, function () {
63
- var api, tableCount, error_1, queryCount, serveDev, address, port, hostname, baseUrl, open_1, _a, error_2;
64
- return __generator(this, function (_b) {
65
- switch (_b.label) {
66
- case 0:
67
- _b.trys.push([0, 13, , 14]);
68
- return [4 /*yield*/, loadApiModule(queriesFile)];
69
- case 1:
70
- api = _b.sent();
71
- tableCount = 0;
72
- _b.label = 2;
73
- case 2:
74
- _b.trys.push([2, 4, , 5]);
75
- return [4 /*yield*/, getTableCount('clickhouse')];
76
- case 3:
77
- tableCount = _b.sent();
78
- return [3 /*break*/, 5];
79
- case 4:
80
- error_1 = _b.sent();
81
- // Log but don't fail - table count is optional
82
- logger.warn('Could not retrieve table count from database');
83
- if (error_1 instanceof Error) {
84
- logger.indent("Reason: ".concat(error_1.message));
85
- }
86
- return [3 /*break*/, 5];
87
- case 5:
88
- queryCount = Object.keys(api.queries || {}).length;
89
- logger.header('hypequery dev');
90
- if (tableCount > 0) {
91
- logger.success("Schema loaded from ClickHouse (".concat(tableCount, " tables)"));
92
- }
93
- logger.success("Registered ".concat(queryCount, " ").concat(queryCount === 1 ? 'query' : 'queries'));
94
- logger.newline();
95
- return [4 /*yield*/, import('@hypequery/serve')];
96
- case 6:
97
- serveDev = (_b.sent()).serveDev;
98
- return [4 /*yield*/, serveDev(api, {
99
- port: options.port,
100
- hostname: options.hostname,
101
- quiet: true,
102
- })];
103
- case 7:
104
- currentServer = _b.sent();
105
- address = currentServer.server.address();
106
- port = typeof address === 'object' && address ? address.port : options.port || 4000;
107
- hostname = options.hostname || 'localhost';
108
- baseUrl = "http://".concat(hostname, ":").concat(port);
109
- logger.box([
110
- "Docs: ".concat(baseUrl, "/docs"),
111
- "OpenAPI: ".concat(baseUrl, "/openapi.json"),
112
- ]);
113
- logger.newline();
114
- logger.success("Ready in ".concat(process.uptime().toFixed(0), "ms"));
115
- logger.newline();
116
- // Query execution stats - coming soon
117
- logger.info('💡 Query execution stats: Coming soon!');
118
- logger.newline();
119
- if (shouldWatch) {
120
- logger.info('Watching for changes...');
121
- }
122
- if (!options.open) return [3 /*break*/, 12];
123
- _b.label = 8;
124
- case 8:
125
- _b.trys.push([8, 11, , 12]);
126
- return [4 /*yield*/, import('open')];
127
- case 9:
128
- open_1 = (_b.sent()).default;
129
- return [4 /*yield*/, open_1(baseUrl)];
130
- case 10:
131
- _b.sent();
132
- logger.success("Opened ".concat(baseUrl, " in browser"));
133
- return [3 /*break*/, 12];
134
- case 11:
135
- _a = _b.sent();
136
- // Log but don't fail - browser open is optional
137
- logger.warn('Could not open browser automatically');
138
- logger.indent("Visit: ".concat(baseUrl));
139
- return [3 /*break*/, 12];
140
- case 12: return [3 /*break*/, 14];
141
- case 13:
142
- error_2 = _b.sent();
143
- logger.error('Failed to start server');
144
- logger.newline();
145
- if (error_2 instanceof Error) {
146
- logger.info(error_2.message);
147
- if (error_2.stack) {
148
- logger.newline();
149
- logger.info('Stack trace:');
150
- logger.info(error_2.stack);
151
- }
152
- }
153
- else {
154
- logger.info(String(error_2));
155
- }
156
- logger.newline();
157
- if (!shouldWatch) {
158
- process.exit(1);
159
- }
160
- return [3 /*break*/, 14];
161
- case 14: return [2 /*return*/];
162
- }
163
- });
164
- }); };
165
- restartServer = function () { return __awaiter(_this, void 0, void 0, function () {
166
- return __generator(this, function (_a) {
167
- switch (_a.label) {
168
- case 0:
169
- if (!currentServer) return [3 /*break*/, 2];
170
- logger.newline();
171
- logger.reload('File changed, restarting...');
172
- logger.newline();
173
- return [4 /*yield*/, currentServer.stop()];
174
- case 1:
175
- _a.sent();
176
- _a.label = 2;
177
- case 2: return [4 /*yield*/, startServer()];
178
- case 3:
179
- _a.sent();
180
- return [2 /*return*/];
181
- }
182
- });
183
- }); };
184
- shutdown = function () { return __awaiter(_this, void 0, void 0, function () {
185
- return __generator(this, function (_a) {
186
- switch (_a.label) {
187
- case 0:
188
- logger.newline();
189
- logger.info('Shutting down dev server...');
190
- if (!currentServer) return [3 /*break*/, 2];
191
- return [4 /*yield*/, currentServer.stop()];
192
- case 1:
193
- _a.sent();
194
- _a.label = 2;
195
- case 2:
196
- process.exit(0);
197
- return [2 /*return*/];
198
- }
199
- });
200
- }); };
201
- // Start initial server
202
- return [4 /*yield*/, startServer()];
203
- case 2:
204
- // Start initial server
205
- _a.sent();
206
- // Watch for changes
207
- if (shouldWatch) {
208
- watchDir = path.dirname(queriesFile);
209
- debounceTimer_1 = null;
210
- watcher_1 = watch(watchDir, { recursive: true }, function (eventType, filename) {
211
- if (!filename)
212
- return;
213
- // Only watch .ts and .js files
214
- if (!filename.endsWith('.ts') && !filename.endsWith('.js')) {
215
- return;
216
- }
217
- // Debounce file changes
218
- if (debounceTimer_1) {
219
- clearTimeout(debounceTimer_1);
220
- }
221
- debounceTimer_1 = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
222
- return __generator(this, function (_a) {
223
- switch (_a.label) {
224
- case 0: return [4 /*yield*/, restartServer()];
225
- case 1:
226
- _a.sent();
227
- return [2 /*return*/];
228
- }
229
- });
230
- }); }, 100);
231
- });
232
- process.once('SIGINT', function () {
233
- watcher_1.close();
234
- shutdown();
235
- });
236
- process.once('SIGTERM', function () {
237
- watcher_1.close();
238
- shutdown();
239
- });
240
- }
241
- else {
242
- process.once('SIGINT', shutdown);
243
- process.once('SIGTERM', shutdown);
244
- }
245
- return [2 /*return*/];
246
- }
247
- });
248
- });
249
- }
@@ -1,8 +0,0 @@
1
- import { type DatabaseType } from '../utils/detect-database.js';
2
- export interface GenerateOptions {
3
- output?: string;
4
- tables?: string;
5
- database?: DatabaseType;
6
- }
7
- export declare function generateCommand(options?: GenerateOptions): Promise<void>;
8
- //# sourceMappingURL=generate.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/commands/generate.ts"],"names":[],"mappings":"AAIA,OAAO,EAAiC,KAAK,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAG/F,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,YAAY,CAAC;CACzB;AAED,wBAAsB,eAAe,CAAC,OAAO,GAAE,eAAoB,iBAwHlE"}
@@ -1,175 +0,0 @@
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 path from 'node:path';
38
- import ora from 'ora';
39
- import { logger } from '../utils/logger.js';
40
- import { findSchemaFile } from '../utils/find-files.js';
41
- import { detectDatabase, getTableCount } from '../utils/detect-database.js';
42
- import { getTypeGenerator } from '../generators/index.js';
43
- export function generateCommand() {
44
- return __awaiter(this, arguments, void 0, function (options) {
45
- var outputPath, existingSchema, parsedTables, requestedDbType, dbType, _a, spinner, generator, tableCount, typeSpinner, error_1;
46
- if (options === void 0) { options = {}; }
47
- return __generator(this, function (_b) {
48
- switch (_b.label) {
49
- case 0:
50
- if (!options.output) return [3 /*break*/, 1];
51
- outputPath = path.resolve(process.cwd(), options.output);
52
- return [3 /*break*/, 3];
53
- case 1: return [4 /*yield*/, findSchemaFile()];
54
- case 2:
55
- existingSchema = _b.sent();
56
- if (existingSchema) {
57
- outputPath = existingSchema;
58
- }
59
- else {
60
- // Default to analytics/schema.ts
61
- outputPath = path.join(process.cwd(), 'analytics', 'schema.ts');
62
- }
63
- _b.label = 3;
64
- case 3:
65
- parsedTables = options.tables
66
- ? options.tables
67
- .split(',')
68
- .map(function (table) { return table.trim(); })
69
- .filter(Boolean)
70
- : undefined;
71
- requestedDbType = options.database;
72
- if (!(requestedDbType !== null && requestedDbType !== void 0)) return [3 /*break*/, 4];
73
- _a = requestedDbType;
74
- return [3 /*break*/, 6];
75
- case 4: return [4 /*yield*/, detectDatabase()];
76
- case 5:
77
- _a = (_b.sent());
78
- _b.label = 6;
79
- case 6:
80
- dbType = _a;
81
- logger.newline();
82
- logger.header('hypequery generate');
83
- spinner = ora("Connecting to ".concat(dbType, "...")).start();
84
- _b.label = 7;
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_HOST=' + (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
- }
173
- });
174
- });
175
- }
@@ -1,9 +0,0 @@
1
- export interface InitOptions {
2
- database?: string;
3
- path?: string;
4
- noExample?: boolean;
5
- noInteractive?: boolean;
6
- force?: boolean;
7
- }
8
- export declare function initCommand(options?: InitOptions): Promise<void>;
9
- //# sourceMappingURL=init.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AA6BA,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,wBAAsB,WAAW,CAAC,OAAO,GAAE,WAAgB,iBA2R1D"}