@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.
Files changed (74) hide show
  1. package/README.md +26 -2
  2. package/dist/bin/cli.js +21 -81
  3. package/dist/cli.d.ts.map +1 -1
  4. package/dist/cli.js +72 -116
  5. package/dist/commands/dev.d.ts +1 -0
  6. package/dist/commands/dev.d.ts.map +1 -1
  7. package/dist/commands/dev.js +180 -255
  8. package/dist/commands/generate-datasets.d.ts +14 -0
  9. package/dist/commands/generate-datasets.d.ts.map +1 -0
  10. package/dist/commands/generate-datasets.js +96 -0
  11. package/dist/commands/generate.d.ts +2 -0
  12. package/dist/commands/generate.d.ts.map +1 -1
  13. package/dist/commands/generate.js +112 -167
  14. package/dist/commands/init.d.ts +7 -0
  15. package/dist/commands/init.d.ts.map +1 -1
  16. package/dist/commands/init.js +337 -370
  17. package/dist/generators/clickhouse.d.ts +1 -1
  18. package/dist/generators/clickhouse.d.ts.map +1 -1
  19. package/dist/generators/clickhouse.js +10 -269
  20. package/dist/generators/dataset-generator.d.ts +16 -0
  21. package/dist/generators/dataset-generator.d.ts.map +1 -0
  22. package/dist/generators/dataset-generator.js +213 -0
  23. package/dist/generators/index.js +3 -3
  24. package/dist/templates/api.d.ts +9 -0
  25. package/dist/templates/api.d.ts.map +1 -0
  26. package/dist/templates/api.js +26 -0
  27. package/dist/templates/auth-scaffold.d.ts +17 -0
  28. package/dist/templates/auth-scaffold.d.ts.map +1 -0
  29. package/dist/templates/auth-scaffold.js +41 -0
  30. package/dist/templates/client.js +10 -1
  31. package/dist/templates/datasets.d.ts +5 -0
  32. package/dist/templates/datasets.d.ts.map +1 -0
  33. package/dist/templates/datasets.js +23 -0
  34. package/dist/templates/env.js +19 -8
  35. package/dist/templates/gitignore.js +4 -1
  36. package/dist/templates/queries.d.ts +3 -0
  37. package/dist/templates/queries.d.ts.map +1 -1
  38. package/dist/templates/queries.js +66 -10
  39. package/dist/test-utils.d.ts +0 -71
  40. package/dist/test-utils.d.ts.map +1 -1
  41. package/dist/test-utils.js +12 -137
  42. package/dist/utils/clickhouse-client.js +10 -57
  43. package/dist/utils/clickhouse-sql.d.ts +6 -0
  44. package/dist/utils/clickhouse-sql.d.ts.map +1 -0
  45. package/dist/utils/clickhouse-sql.js +18 -0
  46. package/dist/utils/clickhouse-type-utils.d.ts +6 -0
  47. package/dist/utils/clickhouse-type-utils.d.ts.map +1 -0
  48. package/dist/utils/clickhouse-type-utils.js +59 -0
  49. package/dist/utils/dependency-installer.d.ts +4 -2
  50. package/dist/utils/dependency-installer.d.ts.map +1 -1
  51. package/dist/utils/dependency-installer.js +93 -170
  52. package/dist/utils/detect-database.js +84 -195
  53. package/dist/utils/find-files.d.ts +3 -1
  54. package/dist/utils/find-files.d.ts.map +1 -1
  55. package/dist/utils/find-files.js +82 -148
  56. package/dist/utils/load-api.d.ts.map +1 -1
  57. package/dist/utils/load-api.js +207 -396
  58. package/dist/utils/logger.js +38 -42
  59. package/dist/utils/prompts.d.ts +14 -0
  60. package/dist/utils/prompts.d.ts.map +1 -1
  61. package/dist/utils/prompts.js +170 -219
  62. package/dist/utils/runtime-guards.d.ts +4 -0
  63. package/dist/utils/runtime-guards.d.ts.map +1 -0
  64. package/dist/utils/runtime-guards.js +9 -0
  65. package/dist/utils/sha256.d.ts +2 -0
  66. package/dist/utils/sha256.d.ts.map +1 -0
  67. package/dist/utils/sha256.js +4 -0
  68. package/package.json +3 -8
  69. package/dist/utils/error-messages.d.ts +0 -6
  70. package/dist/utils/error-messages.d.ts.map +0 -1
  71. package/dist/utils/error-messages.js +0 -19
  72. package/dist/utils/load-hypequery-config.d.ts +0 -7
  73. package/dist/utils/load-hypequery-config.d.ts.map +0 -1
  74. package/dist/utils/load-hypequery-config.js +0 -89
@@ -1,224 +1,113 @@
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 { access } from 'node:fs/promises';
38
2
  import path from 'node:path';
39
3
  import { getClickHouseClient } from './clickhouse-client.js';
40
4
  /**
41
5
  * Auto-detect database type from environment or config files
42
6
  */
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
- });
7
+ export async function detectDatabase() {
8
+ // Check environment variables
9
+ if (process.env.CLICKHOUSE_HOST ||
10
+ process.env.CLICKHOUSE_URL ||
11
+ process.env.CLICKHOUSE_DATABASE) {
12
+ return 'clickhouse';
13
+ }
14
+ if (process.env.BIGQUERY_PROJECT_ID || process.env.GOOGLE_APPLICATION_CREDENTIALS) {
15
+ return 'bigquery';
16
+ }
17
+ // Check for .env file and parse it
18
+ try {
19
+ const envPath = path.join(process.cwd(), '.env');
20
+ await access(envPath);
21
+ const { readFile } = await import('node:fs/promises');
22
+ const envContent = await readFile(envPath, 'utf-8');
23
+ if (envContent.includes('CLICKHOUSE_') ||
24
+ envContent.includes('CLICKHOUSE_HOST')) {
25
+ return 'clickhouse';
26
+ }
27
+ if (envContent.includes('BIGQUERY_') ||
28
+ envContent.includes('GOOGLE_APPLICATION_CREDENTIALS')) {
29
+ return 'bigquery';
30
+ }
31
+ }
32
+ catch {
33
+ // .env doesn't exist, continue
34
+ }
35
+ return 'unknown';
87
36
  }
88
37
  /**
89
38
  * Validate database connection
90
39
  */
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
- });
40
+ export async function validateConnection(dbType) {
41
+ switch (dbType) {
42
+ case 'clickhouse':
43
+ return validateClickHouse();
44
+ case 'bigquery':
45
+ return validateBigQuery();
46
+ default:
47
+ return false;
48
+ }
105
49
  }
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
- }
50
+ async function validateClickHouse() {
51
+ try {
52
+ const client = getClickHouseClient();
53
+ const result = await client.query({
54
+ query: 'SELECT 1',
55
+ format: 'JSONEachRow',
129
56
  });
130
- });
57
+ await result.json();
58
+ return true;
59
+ }
60
+ catch {
61
+ return false;
62
+ }
131
63
  }
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
- });
64
+ async function validateBigQuery() {
65
+ // TODO: Implement when BigQuery support is added
66
+ return false;
139
67
  }
140
68
  /**
141
69
  * Get table count from database
142
70
  */
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
- });
71
+ export async function getTableCount(dbType) {
72
+ switch (dbType) {
73
+ case 'clickhouse':
74
+ return getClickHouseTableCount();
75
+ default:
76
+ return 0;
77
+ }
155
78
  }
156
79
  /**
157
80
  * Generic helper to execute ClickHouse queries with consistent error handling
158
81
  */
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
- }
82
+ async function executeClickHouseQuery(query, defaultValue) {
83
+ try {
84
+ const client = getClickHouseClient();
85
+ const result = await client.query({
86
+ query,
87
+ format: 'JSONEachRow',
180
88
  });
181
- });
89
+ return (await result.json());
90
+ }
91
+ catch {
92
+ return defaultValue;
93
+ }
182
94
  }
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
- });
95
+ async function getClickHouseTableCount() {
96
+ const tables = await executeClickHouseQuery('SHOW TABLES', []);
97
+ return Array.isArray(tables) ? tables.length : 0;
195
98
  }
196
99
  /**
197
100
  * Get list of tables from database
198
101
  */
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
- });
102
+ export async function getTables(dbType) {
103
+ switch (dbType) {
104
+ case 'clickhouse':
105
+ return getClickHouseTables();
106
+ default:
107
+ return [];
108
+ }
211
109
  }
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
- });
110
+ async function getClickHouseTables() {
111
+ const tables = await executeClickHouseQuery('SHOW TABLES', []);
112
+ return tables.map(t => t.name);
224
113
  }
@@ -2,10 +2,12 @@
2
2
  * Find the queries file in the project
3
3
  */
4
4
  export declare function findQueriesFile(customPath?: string): Promise<string | null>;
5
+ export declare function findApiFileForPath(directory: string): Promise<string | null>;
5
6
  /**
6
7
  * Find the schema file (generated types)
7
8
  */
8
- export declare function findSchemaFile(): Promise<string | null>;
9
+ export declare function findSchemaFile(directory?: string): Promise<string | null>;
10
+ export declare function findDatasetsFile(directory?: string): Promise<string | null>;
9
11
  /**
10
12
  * Find the client file
11
13
  */
@@ -1 +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"}
1
+ {"version":3,"file":"find-files.d.ts","sourceRoot":"","sources":["../../src/utils/find-files.ts"],"names":[],"mappings":"AAmCA;;GAEG;AACH,wBAAsB,eAAe,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAcjF;AAED,wBAAsB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAKlF;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAW/E;AAED,wBAAsB,gBAAgB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAYjF;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"}
@@ -1,79 +1,30 @@
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 { access } from 'node:fs/promises';
38
2
  import path from 'node:path';
39
3
  /**
40
4
  * Generic helper to find a file from a list of candidate paths
41
5
  */
42
- function findFile(candidates) {
43
- return __awaiter(this, void 0, void 0, function () {
44
- var _i, candidates_1, candidate, resolved, _a;
45
- return __generator(this, function (_b) {
46
- switch (_b.label) {
47
- case 0:
48
- _i = 0, candidates_1 = candidates;
49
- _b.label = 1;
50
- case 1:
51
- if (!(_i < candidates_1.length)) return [3 /*break*/, 6];
52
- candidate = candidates_1[_i];
53
- resolved = path.resolve(process.cwd(), candidate);
54
- _b.label = 2;
55
- case 2:
56
- _b.trys.push([2, 4, , 5]);
57
- return [4 /*yield*/, access(resolved)];
58
- case 3:
59
- _b.sent();
60
- return [2 /*return*/, resolved];
61
- case 4:
62
- _a = _b.sent();
63
- return [3 /*break*/, 5];
64
- case 5:
65
- _i++;
66
- return [3 /*break*/, 1];
67
- case 6: return [2 /*return*/, null];
68
- }
69
- });
70
- });
6
+ async function findFile(candidates) {
7
+ for (const candidate of candidates) {
8
+ const resolved = path.resolve(process.cwd(), candidate);
9
+ try {
10
+ await access(resolved);
11
+ return resolved;
12
+ }
13
+ catch {
14
+ // Continue checking
15
+ }
16
+ }
17
+ return null;
71
18
  }
72
19
  /**
73
20
  * Common query file locations to check
74
21
  */
75
- var DEFAULT_QUERY_PATHS = [
22
+ const DEFAULT_API_PATHS = [
76
23
  'hypequery.ts',
24
+ 'analytics/api.ts',
25
+ 'src/analytics/api.ts',
26
+ 'api.ts',
27
+ 'src/api.ts',
77
28
  'analytics/queries.ts',
78
29
  'src/analytics/queries.ts',
79
30
  'queries.ts',
@@ -82,102 +33,85 @@ var DEFAULT_QUERY_PATHS = [
82
33
  /**
83
34
  * Find the queries file in the project
84
35
  */
85
- export function findQueriesFile(customPath) {
86
- return __awaiter(this, void 0, void 0, function () {
87
- var resolved, _a;
88
- return __generator(this, function (_b) {
89
- switch (_b.label) {
90
- case 0:
91
- if (!customPath) return [3 /*break*/, 4];
92
- resolved = path.resolve(process.cwd(), customPath);
93
- _b.label = 1;
94
- case 1:
95
- _b.trys.push([1, 3, , 4]);
96
- return [4 /*yield*/, access(resolved)];
97
- case 2:
98
- _b.sent();
99
- return [2 /*return*/, resolved];
100
- case 3:
101
- _a = _b.sent();
102
- return [2 /*return*/, null];
103
- case 4:
104
- // Check default locations
105
- return [2 /*return*/, findFile(DEFAULT_QUERY_PATHS)];
106
- }
107
- });
108
- });
36
+ export async function findQueriesFile(customPath) {
37
+ // If custom path provided, check only that
38
+ if (customPath) {
39
+ const resolved = path.resolve(process.cwd(), customPath);
40
+ try {
41
+ await access(resolved);
42
+ return resolved;
43
+ }
44
+ catch {
45
+ return null;
46
+ }
47
+ }
48
+ // Check default locations
49
+ return findFile(DEFAULT_API_PATHS);
50
+ }
51
+ export async function findApiFileForPath(directory) {
52
+ return findFile([
53
+ path.join(directory, 'api.ts'),
54
+ path.join(directory, 'queries.ts'),
55
+ ]);
109
56
  }
110
57
  /**
111
58
  * Find the schema file (generated types)
112
59
  */
113
- export function findSchemaFile() {
114
- return __awaiter(this, void 0, void 0, function () {
115
- return __generator(this, function (_a) {
116
- return [2 /*return*/, findFile([
117
- 'analytics/schema.ts',
118
- 'src/analytics/schema.ts',
119
- 'schema.ts',
120
- 'src/schema.ts',
121
- ])];
122
- });
123
- });
60
+ export async function findSchemaFile(directory) {
61
+ if (directory) {
62
+ return path.resolve(process.cwd(), directory, 'schema.ts');
63
+ }
64
+ return findFile([
65
+ 'analytics/schema.ts',
66
+ 'src/analytics/schema.ts',
67
+ 'schema.ts',
68
+ 'src/schema.ts',
69
+ ]);
70
+ }
71
+ export async function findDatasetsFile(directory) {
72
+ if (directory) {
73
+ return path.resolve(process.cwd(), directory, 'datasets.ts');
74
+ }
75
+ return findFile([
76
+ 'analytics/datasets.ts',
77
+ 'src/analytics/datasets.ts',
78
+ 'datasets.ts',
79
+ 'src/datasets.ts',
80
+ 'src/datasets/generated.ts',
81
+ ]);
124
82
  }
125
83
  /**
126
84
  * Find the client file
127
85
  */
128
- export function findClientFile() {
129
- return __awaiter(this, void 0, void 0, function () {
130
- return __generator(this, function (_a) {
131
- return [2 /*return*/, findFile([
132
- 'analytics/client.ts',
133
- 'src/analytics/client.ts',
134
- 'client.ts',
135
- 'src/client.ts',
136
- ])];
137
- });
138
- });
86
+ export async function findClientFile() {
87
+ return findFile([
88
+ 'analytics/client.ts',
89
+ 'src/analytics/client.ts',
90
+ 'client.ts',
91
+ 'src/client.ts',
92
+ ]);
139
93
  }
140
94
  /**
141
95
  * Check if .env file exists
142
96
  */
143
- export function hasEnvFile() {
144
- return __awaiter(this, void 0, void 0, function () {
145
- var _a;
146
- return __generator(this, function (_b) {
147
- switch (_b.label) {
148
- case 0:
149
- _b.trys.push([0, 2, , 3]);
150
- return [4 /*yield*/, access(path.join(process.cwd(), '.env'))];
151
- case 1:
152
- _b.sent();
153
- return [2 /*return*/, true];
154
- case 2:
155
- _a = _b.sent();
156
- return [2 /*return*/, false];
157
- case 3: return [2 /*return*/];
158
- }
159
- });
160
- });
97
+ export async function hasEnvFile() {
98
+ try {
99
+ await access(path.join(process.cwd(), '.env'));
100
+ return true;
101
+ }
102
+ catch {
103
+ return false;
104
+ }
161
105
  }
162
106
  /**
163
107
  * Check if .gitignore exists
164
108
  */
165
- export function hasGitignore() {
166
- return __awaiter(this, void 0, void 0, function () {
167
- var _a;
168
- return __generator(this, function (_b) {
169
- switch (_b.label) {
170
- case 0:
171
- _b.trys.push([0, 2, , 3]);
172
- return [4 /*yield*/, access(path.join(process.cwd(), '.gitignore'))];
173
- case 1:
174
- _b.sent();
175
- return [2 /*return*/, true];
176
- case 2:
177
- _a = _b.sent();
178
- return [2 /*return*/, false];
179
- case 3: return [2 /*return*/];
180
- }
181
- });
182
- });
109
+ export async function hasGitignore() {
110
+ try {
111
+ await access(path.join(process.cwd(), '.gitignore'));
112
+ return true;
113
+ }
114
+ catch {
115
+ return false;
116
+ }
183
117
  }
@@ -1 +1 @@
1
- {"version":3,"file":"load-api.d.ts","sourceRoot":"","sources":["../../src/utils/load-api.ts"],"names":[],"mappings":"AAaA,wBAAsB,aAAa,CAAC,UAAU,EAAE,MAAM,gBAkDrD;AAED,wBAAsB,UAAU,CAAC,UAAU,EAAE,MAAM,gBAkClD"}
1
+ {"version":3,"file":"load-api.d.ts","sourceRoot":"","sources":["../../src/utils/load-api.ts"],"names":[],"mappings":"AAaA,wBAAsB,aAAa,CAAC,UAAU,EAAE,MAAM,gBA2DrD;AAED,wBAAsB,UAAU,CAAC,UAAU,EAAE,MAAM,gBAkClD"}