@hypequery/cli 0.0.1 → 0.0.3
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 +8 -55
- package/dist/bin/cli.js +84 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +2 -29
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +1 -5
- package/dist/commands/generate.d.ts +2 -1
- package/dist/commands/generate.d.ts.map +1 -1
- package/dist/commands/generate.js +43 -61
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +28 -29
- package/dist/generators/clickhouse.d.ts +7 -0
- package/dist/generators/clickhouse.d.ts.map +1 -0
- package/dist/generators/clickhouse.js +229 -0
- package/dist/generators/index.d.ts +7 -0
- package/dist/generators/index.d.ts.map +1 -0
- package/dist/generators/index.js +13 -0
- package/dist/templates/queries.d.ts.map +1 -1
- package/dist/templates/queries.js +7 -1
- package/dist/utils/clickhouse-client.d.ts +11 -0
- package/dist/utils/clickhouse-client.d.ts.map +1 -0
- package/dist/utils/clickhouse-client.js +86 -0
- package/dist/utils/detect-database.d.ts.map +1 -1
- package/dist/utils/detect-database.js +19 -61
- package/dist/utils/ensure-ts-runtime.d.ts +4 -0
- package/dist/utils/ensure-ts-runtime.d.ts.map +1 -0
- package/dist/utils/ensure-ts-runtime.js +66 -0
- package/dist/utils/load-api.d.ts.map +1 -1
- package/dist/utils/load-api.js +22 -57
- package/package.json +16 -18
- package/LICENSE +0 -201
package/README.md
CHANGED
|
@@ -49,13 +49,7 @@ Or add to your `package.json` scripts:
|
|
|
49
49
|
|
|
50
50
|
## TypeScript Support
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
```bash
|
|
55
|
-
npm install -D tsx
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
The CLI will guide you if `tsx` is needed but not installed.
|
|
52
|
+
`hypequery dev` bundles a TypeScript runtime (powered by `tsx`), so pointing it at `analytics/queries.ts` or any `.ts/.tsx` file just works—no extra install or custom runner required. If your project already compiles to JavaScript you can keep targeting the generated `.js` file instead.
|
|
59
53
|
|
|
60
54
|
## Commands
|
|
61
55
|
|
|
@@ -138,14 +132,7 @@ npx @hypequery/cli dev --cache none
|
|
|
138
132
|
|
|
139
133
|
**Common Issues:**
|
|
140
134
|
|
|
141
|
-
If you see "Unexpected token" errors
|
|
142
|
-
```bash
|
|
143
|
-
# Make sure tsx is installed
|
|
144
|
-
npm install -D tsx
|
|
145
|
-
|
|
146
|
-
# The CLI will automatically restart with TypeScript support
|
|
147
|
-
npx @hypequery/cli dev
|
|
148
|
-
```
|
|
135
|
+
If you see "Unexpected token" errors while loading your queries, double-check that you're pointing the CLI at the TypeScript source file (e.g. `analytics/queries.ts`). The CLI bundles the loader and should not require additional dependencies.
|
|
149
136
|
|
|
150
137
|
### `hypequery generate`
|
|
151
138
|
|
|
@@ -159,6 +146,8 @@ npx @hypequery/cli generate
|
|
|
159
146
|
npx hypequery generate
|
|
160
147
|
```
|
|
161
148
|
|
|
149
|
+
The CLI bundles the ClickHouse driver directly, so you can run this command without installing `@hypequery/clickhouse`. Specify `--database <type>` once additional drivers become available.
|
|
150
|
+
|
|
162
151
|
**What it does:**
|
|
163
152
|
- Connects to ClickHouse
|
|
164
153
|
- Introspects your database schema
|
|
@@ -168,7 +157,7 @@ npx hypequery generate
|
|
|
168
157
|
**Options:**
|
|
169
158
|
- `-o, --output <path>` - Output file (default: `analytics/schema.ts`)
|
|
170
159
|
- `--tables <names>` - Only generate for specific tables (comma-separated)
|
|
171
|
-
- `--
|
|
160
|
+
- `--database <type>` - Override detected database (currently only `clickhouse`)
|
|
172
161
|
|
|
173
162
|
**Example:**
|
|
174
163
|
```bash
|
|
@@ -178,43 +167,8 @@ npx @hypequery/cli generate
|
|
|
178
167
|
# Generate specific tables
|
|
179
168
|
npx @hypequery/cli generate --tables users,events
|
|
180
169
|
|
|
181
|
-
#
|
|
182
|
-
npx @hypequery/cli generate --
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
### `hypequery create-api-types`
|
|
186
|
-
|
|
187
|
-
Generate a typed client map (perfect for `@hypequery/react`) from your serve export.
|
|
188
|
-
|
|
189
|
-
```bash
|
|
190
|
-
# Without installation
|
|
191
|
-
npx @hypequery/cli create-api-types
|
|
192
|
-
|
|
193
|
-
# With installation
|
|
194
|
-
npx hypequery create-api-types
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
**What it does:**
|
|
198
|
-
- Reads your queries file
|
|
199
|
-
- Extracts all query definitions
|
|
200
|
-
- Generates a TypeScript type map for type-safe client usage
|
|
201
|
-
- Perfect for frontend React hooks with `@hypequery/react`
|
|
202
|
-
|
|
203
|
-
**Options:**
|
|
204
|
-
- `[file]` - Path to your queries module (default: auto-detected from `analytics/queries.ts`, `src/analytics/queries.ts`, or `hypequery.ts`)
|
|
205
|
-
- `-o, --output <path>` - Output file (default: `<queries-dir>/client.ts`)
|
|
206
|
-
- `-n, --name <type>` - Exported type alias name (default: `HypequeryApi`)
|
|
207
|
-
|
|
208
|
-
**Example:**
|
|
209
|
-
```bash
|
|
210
|
-
# Auto-detect queries file
|
|
211
|
-
npx @hypequery/cli create-api-types
|
|
212
|
-
|
|
213
|
-
# Specify custom queries file and output
|
|
214
|
-
npx @hypequery/cli create-api-types src/queries.ts -o src/api-types.ts
|
|
215
|
-
|
|
216
|
-
# Custom type name
|
|
217
|
-
npx @hypequery/cli create-api-types --name MyApi
|
|
170
|
+
# Custom output path
|
|
171
|
+
npx @hypequery/cli generate --output src/schema.ts
|
|
218
172
|
```
|
|
219
173
|
|
|
220
174
|
## Package Scripts
|
|
@@ -226,8 +180,7 @@ Add these to your `package.json` for easy access:
|
|
|
226
180
|
"scripts": {
|
|
227
181
|
"db:init": "hypequery init",
|
|
228
182
|
"db:dev": "hypequery dev",
|
|
229
|
-
"db:generate": "hypequery generate"
|
|
230
|
-
"db:types": "hypequery create-api-types"
|
|
183
|
+
"db:generate": "hypequery generate"
|
|
231
184
|
}
|
|
232
185
|
}
|
|
233
186
|
```
|
package/dist/bin/cli.js
CHANGED
|
@@ -1,3 +1,86 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
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);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
2
38
|
import { program } from '../cli.js';
|
|
3
|
-
|
|
39
|
+
function loadEnv() {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
41
|
+
var dotenvx, _a, config, _b;
|
|
42
|
+
return __generator(this, function (_c) {
|
|
43
|
+
switch (_c.label) {
|
|
44
|
+
case 0:
|
|
45
|
+
_c.trys.push([0, 4, , 5]);
|
|
46
|
+
return [4 /*yield*/, import('@dotenvx/dotenvx')];
|
|
47
|
+
case 1:
|
|
48
|
+
dotenvx = _c.sent();
|
|
49
|
+
if (!((dotenvx === null || dotenvx === void 0 ? void 0 : dotenvx.config) && typeof dotenvx.config.load === 'function')) return [3 /*break*/, 3];
|
|
50
|
+
return [4 /*yield*/, dotenvx.config.load()];
|
|
51
|
+
case 2:
|
|
52
|
+
_c.sent();
|
|
53
|
+
return [2 /*return*/];
|
|
54
|
+
case 3: return [3 /*break*/, 5];
|
|
55
|
+
case 4:
|
|
56
|
+
_a = _c.sent();
|
|
57
|
+
return [3 /*break*/, 5];
|
|
58
|
+
case 5:
|
|
59
|
+
_c.trys.push([5, 7, , 8]);
|
|
60
|
+
return [4 /*yield*/, import('dotenv')];
|
|
61
|
+
case 6:
|
|
62
|
+
config = (_c.sent()).config;
|
|
63
|
+
config();
|
|
64
|
+
return [3 /*break*/, 8];
|
|
65
|
+
case 7:
|
|
66
|
+
_b = _c.sent();
|
|
67
|
+
return [3 /*break*/, 8];
|
|
68
|
+
case 8: return [2 /*return*/];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function main() {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
75
|
+
return __generator(this, function (_a) {
|
|
76
|
+
switch (_a.label) {
|
|
77
|
+
case 0: return [4 /*yield*/, loadEnv()];
|
|
78
|
+
case 1:
|
|
79
|
+
_a.sent();
|
|
80
|
+
program.parse(process.argv);
|
|
81
|
+
return [2 /*return*/];
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
main();
|
package/dist/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,QAAA,MAAM,OAAO,SAAgB,CAAC;AA6F9B,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
package/dist/cli.js
CHANGED
|
@@ -38,7 +38,6 @@ import { Command } from 'commander';
|
|
|
38
38
|
import { initCommand } from './commands/init.js';
|
|
39
39
|
import { devCommand } from './commands/dev.js';
|
|
40
40
|
import { generateCommand } from './commands/generate.js';
|
|
41
|
-
import { createApiTypesCommand } from './commands/create-api-types.js';
|
|
42
41
|
var program = new Command();
|
|
43
42
|
program
|
|
44
43
|
.name('hypequery')
|
|
@@ -110,7 +109,7 @@ program
|
|
|
110
109
|
.description('Regenerate types from ClickHouse')
|
|
111
110
|
.option('-o, --output <path>', 'Output file (default: analytics/schema.ts)')
|
|
112
111
|
.option('--tables <names>', 'Only generate for specific tables (comma-separated)')
|
|
113
|
-
.option('--
|
|
112
|
+
.option('--database <type>', 'Database driver to use (default: auto-detect)')
|
|
114
113
|
.action(function (options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
115
114
|
var error_3;
|
|
116
115
|
return __generator(this, function (_a) {
|
|
@@ -130,31 +129,6 @@ program
|
|
|
130
129
|
}
|
|
131
130
|
});
|
|
132
131
|
}); });
|
|
133
|
-
// create-api-types command
|
|
134
|
-
program
|
|
135
|
-
.command('create-api-types [file]')
|
|
136
|
-
.description('Generate a typed client map for serve APIs')
|
|
137
|
-
.option('-o, --output <path>', 'Output file (default: <queries-dir>/client.ts)')
|
|
138
|
-
.option('-n, --name <typeName>', 'Exported type name (default: HypequeryApi)')
|
|
139
|
-
.action(function (file, options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
140
|
-
var error_4;
|
|
141
|
-
return __generator(this, function (_a) {
|
|
142
|
-
switch (_a.label) {
|
|
143
|
-
case 0:
|
|
144
|
-
_a.trys.push([0, 2, , 3]);
|
|
145
|
-
return [4 /*yield*/, createApiTypesCommand(file, options)];
|
|
146
|
-
case 1:
|
|
147
|
-
_a.sent();
|
|
148
|
-
return [3 /*break*/, 3];
|
|
149
|
-
case 2:
|
|
150
|
-
error_4 = _a.sent();
|
|
151
|
-
console.error(error_4 instanceof Error ? error_4.message : error_4);
|
|
152
|
-
process.exit(1);
|
|
153
|
-
return [3 /*break*/, 3];
|
|
154
|
-
case 3: return [2 /*return*/];
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
}); });
|
|
158
132
|
// Help command
|
|
159
133
|
program
|
|
160
134
|
.command('help [command]')
|
|
@@ -181,8 +155,7 @@ program.on('--help', function () {
|
|
|
181
155
|
console.log(' hypequery init');
|
|
182
156
|
console.log(' hypequery dev');
|
|
183
157
|
console.log(' hypequery dev --port 3000');
|
|
184
|
-
console.log(' hypequery generate --
|
|
185
|
-
console.log(' hypequery create-api-types');
|
|
158
|
+
console.log(' hypequery generate --output analytics/schema.ts');
|
|
186
159
|
console.log('');
|
|
187
160
|
console.log('Docs: https://hypequery.com/docs');
|
|
188
161
|
});
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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"}
|
package/dist/commands/dev.js
CHANGED
|
@@ -60,7 +60,7 @@ export function devCommand(file_1) {
|
|
|
60
60
|
currentServer = null;
|
|
61
61
|
shouldWatch = options.watch !== false;
|
|
62
62
|
startServer = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
63
|
-
var api, tableCount, error_1, queryCount,
|
|
63
|
+
var api, tableCount, error_1, queryCount, serveDev, address, port, hostname, baseUrl, open_1, _a, error_2;
|
|
64
64
|
return __generator(this, function (_b) {
|
|
65
65
|
switch (_b.label) {
|
|
66
66
|
case 0:
|
|
@@ -91,10 +91,6 @@ export function devCommand(file_1) {
|
|
|
91
91
|
logger.success("Schema loaded from ClickHouse (".concat(tableCount, " tables)"));
|
|
92
92
|
}
|
|
93
93
|
logger.success("Registered ".concat(queryCount, " ").concat(queryCount === 1 ? 'query' : 'queries'));
|
|
94
|
-
if (options.cache !== 'none') {
|
|
95
|
-
cacheType = options.cache || 'memory';
|
|
96
|
-
logger.success("Caching enabled (".concat(cacheType, ")"));
|
|
97
|
-
}
|
|
98
94
|
logger.newline();
|
|
99
95
|
return [4 /*yield*/, import('@hypequery/serve')];
|
|
100
96
|
case 6:
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { type DatabaseType } from '../utils/detect-database.js';
|
|
1
2
|
export interface GenerateOptions {
|
|
2
3
|
output?: string;
|
|
3
4
|
tables?: string;
|
|
4
|
-
|
|
5
|
+
database?: DatabaseType;
|
|
5
6
|
}
|
|
6
7
|
export declare function generateCommand(options?: GenerateOptions): Promise<void>;
|
|
7
8
|
//# sourceMappingURL=generate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/commands/generate.ts"],"names":[],"mappings":"
|
|
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"}
|
|
@@ -38,21 +38,21 @@ import path from 'node:path';
|
|
|
38
38
|
import ora from 'ora';
|
|
39
39
|
import { logger } from '../utils/logger.js';
|
|
40
40
|
import { findSchemaFile } from '../utils/find-files.js';
|
|
41
|
-
import { getTableCount } from '../utils/detect-database.js';
|
|
41
|
+
import { detectDatabase, getTableCount } from '../utils/detect-database.js';
|
|
42
|
+
import { getTypeGenerator } from '../generators/index.js';
|
|
42
43
|
export function generateCommand() {
|
|
43
44
|
return __awaiter(this, arguments, void 0, function (options) {
|
|
44
|
-
var outputPath, existingSchema,
|
|
45
|
-
var _this = this;
|
|
45
|
+
var outputPath, existingSchema, parsedTables, requestedDbType, dbType, _a, spinner, generator, tableCount, typeSpinner, error_1;
|
|
46
46
|
if (options === void 0) { options = {}; }
|
|
47
|
-
return __generator(this, function (
|
|
48
|
-
switch (
|
|
47
|
+
return __generator(this, function (_b) {
|
|
48
|
+
switch (_b.label) {
|
|
49
49
|
case 0:
|
|
50
50
|
if (!options.output) return [3 /*break*/, 1];
|
|
51
51
|
outputPath = path.resolve(process.cwd(), options.output);
|
|
52
52
|
return [3 /*break*/, 3];
|
|
53
53
|
case 1: return [4 /*yield*/, findSchemaFile()];
|
|
54
54
|
case 2:
|
|
55
|
-
existingSchema =
|
|
55
|
+
existingSchema = _b.sent();
|
|
56
56
|
if (existingSchema) {
|
|
57
57
|
outputPath = existingSchema;
|
|
58
58
|
}
|
|
@@ -60,69 +60,51 @@ export function generateCommand() {
|
|
|
60
60
|
// Default to analytics/schema.ts
|
|
61
61
|
outputPath = path.join(process.cwd(), 'analytics', 'schema.ts');
|
|
62
62
|
}
|
|
63
|
-
|
|
63
|
+
_b.label = 3;
|
|
64
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;
|
|
65
81
|
logger.newline();
|
|
66
82
|
logger.header('hypequery generate');
|
|
67
|
-
spinner = ora(
|
|
68
|
-
|
|
69
|
-
case
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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));
|
|
75
92
|
logger.success("Found ".concat(tableCount, " tables"));
|
|
76
93
|
typeSpinner = ora('Generating types...').start();
|
|
77
|
-
return [4 /*yield*/,
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
case
|
|
82
|
-
|
|
94
|
+
return [4 /*yield*/, generator({
|
|
95
|
+
outputPath: outputPath,
|
|
96
|
+
includeTables: parsedTables,
|
|
97
|
+
})];
|
|
98
|
+
case 9:
|
|
99
|
+
_b.sent();
|
|
83
100
|
typeSpinner.succeed("Generated types for ".concat(tableCount, " tables"));
|
|
84
101
|
logger.success("Updated ".concat(path.relative(process.cwd(), outputPath)));
|
|
85
102
|
logger.newline();
|
|
86
103
|
logger.header('Types regenerated successfully!');
|
|
87
104
|
logger.newline();
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
logger.newline();
|
|
92
|
-
lastTableCount_1 = tableCount;
|
|
93
|
-
setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
94
|
-
var currentTableCount, regenerateSpinner;
|
|
95
|
-
return __generator(this, function (_a) {
|
|
96
|
-
switch (_a.label) {
|
|
97
|
-
case 0: return [4 /*yield*/, getTableCount('clickhouse')];
|
|
98
|
-
case 1:
|
|
99
|
-
currentTableCount = _a.sent();
|
|
100
|
-
if (!(currentTableCount !== lastTableCount_1)) return [3 /*break*/, 3];
|
|
101
|
-
logger.newline();
|
|
102
|
-
logger.reload("Schema changed (".concat(Math.abs(currentTableCount - lastTableCount_1), " ").concat(currentTableCount > lastTableCount_1 ? 'new' : 'removed', " tables)"));
|
|
103
|
-
regenerateSpinner = ora('Regenerating types...').start();
|
|
104
|
-
return [4 /*yield*/, generateTypes_1(outputPath)];
|
|
105
|
-
case 2:
|
|
106
|
-
_a.sent();
|
|
107
|
-
regenerateSpinner.succeed('Regenerated types');
|
|
108
|
-
logger.success("Updated ".concat(path.relative(process.cwd(), outputPath)));
|
|
109
|
-
logger.newline();
|
|
110
|
-
lastTableCount_1 = currentTableCount;
|
|
111
|
-
_a.label = 3;
|
|
112
|
-
case 3: return [2 /*return*/];
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
}); }, 30000); // Check every 30 seconds
|
|
116
|
-
// Keep process alive
|
|
117
|
-
process.on('SIGINT', function () {
|
|
118
|
-
logger.newline();
|
|
119
|
-
logger.info('Stopping watch mode...');
|
|
120
|
-
process.exit(0);
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
return [3 /*break*/, 9];
|
|
124
|
-
case 8:
|
|
125
|
-
error_1 = _a.sent();
|
|
105
|
+
return [3 /*break*/, 11];
|
|
106
|
+
case 10:
|
|
107
|
+
error_1 = _b.sent();
|
|
126
108
|
spinner.fail('Failed to generate types');
|
|
127
109
|
logger.newline();
|
|
128
110
|
if (error_1 instanceof Error) {
|
|
@@ -185,8 +167,8 @@ export function generateCommand() {
|
|
|
185
167
|
}
|
|
186
168
|
logger.newline();
|
|
187
169
|
process.exit(1);
|
|
188
|
-
return [3 /*break*/,
|
|
189
|
-
case
|
|
170
|
+
return [3 /*break*/, 11];
|
|
171
|
+
case 11: return [2 /*return*/];
|
|
190
172
|
}
|
|
191
173
|
});
|
|
192
174
|
});
|
|
@@ -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":"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"}
|
package/dist/commands/init.js
CHANGED
|
@@ -45,9 +45,10 @@ import { generateEnvTemplate, appendToEnv } from '../templates/env.js';
|
|
|
45
45
|
import { generateClientTemplate } from '../templates/client.js';
|
|
46
46
|
import { generateQueriesTemplate } from '../templates/queries.js';
|
|
47
47
|
import { appendToGitignore } from '../templates/gitignore.js';
|
|
48
|
+
import { getTypeGenerator } from '../generators/index.js';
|
|
48
49
|
export function initCommand() {
|
|
49
50
|
return __awaiter(this, arguments, void 0, function (options) {
|
|
50
|
-
var dbType, connectionConfig, hasValidConnection, tableCount, required, spinner, isValid, retry, continueWithout, outputDir, resolvedOutputDir, filesToCreate, existingFiles, _i, filesToCreate_1, file, _a, shouldOverwrite, generateExample, selectedTable, tables, envPath, envExists, existingEnv, newEnv, envPath, envExists, placeholderConfig, schemaPath, typeSpinner,
|
|
51
|
+
var dbType, connectionConfig, hasValidConnection, tableCount, required, spinner, isValid, retry, continueWithout, outputDir, resolvedOutputDir, filesToCreate, existingFiles, _i, filesToCreate_1, file, _a, shouldOverwrite, generateExample, selectedTable, tables, envPath, envExists, existingEnv, newEnv, envPath, envExists, placeholderConfig, schemaPath, typeSpinner, generator, error_1, clientPath, queriesPath, gitignorePath, gitignoreExists, existingGitignore, newGitignore, exampleQueryKey;
|
|
51
52
|
var _b;
|
|
52
53
|
if (options === void 0) { options = {}; }
|
|
53
54
|
return __generator(this, function (_c) {
|
|
@@ -263,38 +264,36 @@ export function initCommand() {
|
|
|
263
264
|
_c.label = 38;
|
|
264
265
|
case 38:
|
|
265
266
|
schemaPath = path.join(resolvedOutputDir, 'schema.ts');
|
|
266
|
-
if (!hasValidConnection) return [3 /*break*/,
|
|
267
|
+
if (!hasValidConnection) return [3 /*break*/, 43];
|
|
267
268
|
typeSpinner = ora('Generating TypeScript types...').start();
|
|
268
269
|
_c.label = 39;
|
|
269
270
|
case 39:
|
|
270
|
-
_c.trys.push([39,
|
|
271
|
-
|
|
271
|
+
_c.trys.push([39, 41, , 42]);
|
|
272
|
+
generator = getTypeGenerator('clickhouse');
|
|
273
|
+
return [4 /*yield*/, generator({ outputPath: schemaPath })];
|
|
272
274
|
case 40:
|
|
273
|
-
generateTypes = (_c.sent()).generateTypes;
|
|
274
|
-
return [4 /*yield*/, generateTypes(schemaPath)];
|
|
275
|
-
case 41:
|
|
276
275
|
_c.sent();
|
|
277
276
|
typeSpinner.succeed("Generated TypeScript types (".concat(path.relative(process.cwd(), schemaPath), ")"));
|
|
278
|
-
return [3 /*break*/,
|
|
279
|
-
case
|
|
277
|
+
return [3 /*break*/, 42];
|
|
278
|
+
case 41:
|
|
280
279
|
error_1 = _c.sent();
|
|
281
280
|
typeSpinner.fail('Failed to generate types');
|
|
282
281
|
logger.error(error_1 instanceof Error ? error_1.message : String(error_1));
|
|
283
282
|
process.exit(1);
|
|
284
|
-
return [3 /*break*/,
|
|
285
|
-
case
|
|
286
|
-
case
|
|
283
|
+
return [3 /*break*/, 42];
|
|
284
|
+
case 42: return [3 /*break*/, 45];
|
|
285
|
+
case 43:
|
|
287
286
|
// Create placeholder schema file
|
|
288
|
-
return [4 /*yield*/, writeFile(schemaPath, "// Generated by
|
|
289
|
-
case
|
|
287
|
+
return [4 /*yield*/, writeFile(schemaPath, "// Generated by hypequery\n// Run 'npx hypequery generate' after configuring your database connection\n\nexport interface IntrospectedSchema {\n // Your table types will appear here after generation\n}\n")];
|
|
288
|
+
case 44:
|
|
290
289
|
// Create placeholder schema file
|
|
291
290
|
_c.sent();
|
|
292
291
|
logger.success("Created placeholder schema (".concat(path.relative(process.cwd(), schemaPath), ")"));
|
|
293
|
-
_c.label =
|
|
294
|
-
case
|
|
292
|
+
_c.label = 45;
|
|
293
|
+
case 45:
|
|
295
294
|
clientPath = path.join(resolvedOutputDir, 'client.ts');
|
|
296
295
|
return [4 /*yield*/, writeFile(clientPath, generateClientTemplate())];
|
|
297
|
-
case
|
|
296
|
+
case 46:
|
|
298
297
|
_c.sent();
|
|
299
298
|
logger.success("Created ClickHouse client (".concat(path.relative(process.cwd(), clientPath), ")"));
|
|
300
299
|
queriesPath = path.join(resolvedOutputDir, 'queries.ts');
|
|
@@ -302,7 +301,7 @@ export function initCommand() {
|
|
|
302
301
|
hasExample: generateExample,
|
|
303
302
|
tableName: selectedTable || undefined,
|
|
304
303
|
}))];
|
|
305
|
-
case
|
|
304
|
+
case 47:
|
|
306
305
|
_c.sent();
|
|
307
306
|
logger.success("Created queries file (".concat(path.relative(process.cwd(), queriesPath), ")"));
|
|
308
307
|
if (generateExample && selectedTable) {
|
|
@@ -310,26 +309,26 @@ export function initCommand() {
|
|
|
310
309
|
}
|
|
311
310
|
gitignorePath = path.join(process.cwd(), '.gitignore');
|
|
312
311
|
return [4 /*yield*/, hasGitignore()];
|
|
313
|
-
case
|
|
312
|
+
case 48:
|
|
314
313
|
gitignoreExists = _c.sent();
|
|
315
|
-
if (!gitignoreExists) return [3 /*break*/,
|
|
314
|
+
if (!gitignoreExists) return [3 /*break*/, 52];
|
|
316
315
|
return [4 /*yield*/, readFile(gitignorePath, 'utf-8')];
|
|
317
|
-
case
|
|
316
|
+
case 49:
|
|
318
317
|
existingGitignore = _c.sent();
|
|
319
318
|
newGitignore = appendToGitignore(existingGitignore);
|
|
320
|
-
if (!(newGitignore !== existingGitignore)) return [3 /*break*/,
|
|
319
|
+
if (!(newGitignore !== existingGitignore)) return [3 /*break*/, 51];
|
|
321
320
|
return [4 /*yield*/, writeFile(gitignorePath, newGitignore)];
|
|
322
|
-
case
|
|
321
|
+
case 50:
|
|
323
322
|
_c.sent();
|
|
324
323
|
logger.success('Updated .gitignore');
|
|
325
|
-
_c.label =
|
|
326
|
-
case
|
|
327
|
-
case
|
|
328
|
-
case
|
|
324
|
+
_c.label = 51;
|
|
325
|
+
case 51: return [3 /*break*/, 54];
|
|
326
|
+
case 52: return [4 /*yield*/, writeFile(gitignorePath, appendToGitignore(''))];
|
|
327
|
+
case 53:
|
|
329
328
|
_c.sent();
|
|
330
329
|
logger.success('Created .gitignore');
|
|
331
|
-
_c.label =
|
|
332
|
-
case
|
|
330
|
+
_c.label = 54;
|
|
331
|
+
case 54:
|
|
333
332
|
// Step 13: Success message
|
|
334
333
|
logger.newline();
|
|
335
334
|
logger.header('Setup complete!');
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface ClickHouseGeneratorOptions {
|
|
2
|
+
outputPath: string;
|
|
3
|
+
includeTables?: string[];
|
|
4
|
+
excludeTables?: string[];
|
|
5
|
+
}
|
|
6
|
+
export declare function generateClickHouseTypes(options: ClickHouseGeneratorOptions): Promise<void>;
|
|
7
|
+
//# sourceMappingURL=clickhouse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clickhouse.d.ts","sourceRoot":"","sources":["../../src/generators/clickhouse.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,0BAA0B;IACzC,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AA4HD,wBAAsB,uBAAuB,CAAC,OAAO,EAAE,0BAA0B,iBA0ChF"}
|