@hypequery/cli 1.1.0 → 1.1.2
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 +52 -154
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +15 -2
- package/dist/commands/generate.js +1 -1
- package/dist/commands/init.d.ts +0 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +140 -160
- package/dist/generators/clickhouse.d.ts +2 -0
- package/dist/generators/clickhouse.d.ts.map +1 -1
- package/dist/generators/clickhouse.js +84 -41
- package/dist/generators/index.js +1 -1
- package/dist/templates/client.js +1 -1
- package/dist/templates/env.d.ts +2 -1
- package/dist/templates/env.d.ts.map +1 -1
- package/dist/templates/env.js +5 -3
- package/dist/templates/queries.d.ts.map +1 -1
- package/dist/templates/queries.js +3 -2
- package/dist/test-utils.d.ts +0 -1
- package/dist/test-utils.d.ts.map +1 -1
- package/dist/test-utils.js +0 -1
- package/dist/utils/clickhouse-client.js +1 -1
- package/dist/utils/dependency-installer.d.ts +3 -1
- package/dist/utils/dependency-installer.d.ts.map +1 -1
- package/dist/utils/dependency-installer.js +75 -15
- package/dist/utils/load-api.d.ts +1 -0
- package/dist/utils/load-api.d.ts.map +1 -1
- package/dist/utils/load-api.js +79 -55
- package/dist/utils/load-hypequery-config.d.ts +7 -0
- package/dist/utils/load-hypequery-config.d.ts.map +1 -0
- package/dist/utils/load-hypequery-config.js +89 -0
- package/dist/utils/prompts.d.ts +0 -5
- package/dist/utils/prompts.d.ts.map +1 -1
- package/dist/utils/prompts.js +9 -34
- package/package.json +9 -4
package/dist/templates/client.js
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
* Generate client.ts file for ClickHouse
|
|
3
3
|
*/
|
|
4
4
|
export function generateClientTemplate() {
|
|
5
|
-
return "import { createQueryBuilder } from '@hypequery/clickhouse';\nimport type { IntrospectedSchema } from './schema';\n\nexport const db = createQueryBuilder<IntrospectedSchema>({\n
|
|
5
|
+
return "import { createQueryBuilder } from '@hypequery/clickhouse';\nimport type { IntrospectedSchema } from './schema.js';\n\nexport const db = createQueryBuilder<IntrospectedSchema>({\n url: process.env.CLICKHOUSE_URL ?? process.env.CLICKHOUSE_HOST!,\n database: process.env.CLICKHOUSE_DATABASE!,\n username: process.env.CLICKHOUSE_USERNAME!,\n password: process.env.CLICKHOUSE_PASSWORD,\n});\n";
|
|
6
6
|
}
|
package/dist/templates/env.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/templates/env.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/templates/env.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,MAAM,CAqBT;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,eAAe,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CA4B/E"}
|
package/dist/templates/env.js
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
* Generate .env file content for ClickHouse
|
|
3
3
|
*/
|
|
4
4
|
export function generateEnvTemplate(config) {
|
|
5
|
-
var
|
|
5
|
+
var _a, _b;
|
|
6
|
+
var connectionUrl = (_b = (_a = config.url) !== null && _a !== void 0 ? _a : config.host) !== null && _b !== void 0 ? _b : '';
|
|
7
|
+
var isPlaceholder = connectionUrl.includes('YOUR_');
|
|
6
8
|
if (isPlaceholder) {
|
|
7
|
-
return "# Hypequery Configuration\n# Replace these placeholder values with your actual ClickHouse credentials\n\
|
|
9
|
+
return "# Hypequery Configuration\n# Replace these placeholder values with your actual ClickHouse credentials\n\nCLICKHOUSE_URL=".concat(connectionUrl, "\nCLICKHOUSE_DATABASE=").concat(config.database, "\nCLICKHOUSE_USERNAME=").concat(config.username, "\nCLICKHOUSE_PASSWORD=").concat(config.password, "\n");
|
|
8
10
|
}
|
|
9
|
-
return "# Hypequery Configuration\
|
|
11
|
+
return "# Hypequery Configuration\nCLICKHOUSE_URL=".concat(connectionUrl, "\nCLICKHOUSE_DATABASE=").concat(config.database, "\nCLICKHOUSE_USERNAME=").concat(config.username, "\nCLICKHOUSE_PASSWORD=").concat(config.password, "\n");
|
|
10
12
|
}
|
|
11
13
|
/**
|
|
12
14
|
* Append to existing .env file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../src/templates/queries.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE;IAC/C,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../src/templates/queries.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE;IAC/C,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,MAAM,CAiET"}
|
|
@@ -5,14 +5,15 @@ export function generateQueriesTemplate(options) {
|
|
|
5
5
|
var hasExample = options.hasExample, tableName = options.tableName;
|
|
6
6
|
var metricKey = hasExample && tableName ? "".concat(camelCase(tableName), "Query") : 'exampleMetric';
|
|
7
7
|
var typeAlias = "".concat(pascalCase(metricKey), "Result");
|
|
8
|
-
var
|
|
8
|
+
var routePath = "/metrics/".concat(metricKey);
|
|
9
|
+
var template = "import { initServe } from '@hypequery/serve';\nimport type { InferApiType } from '@hypequery/serve';\nimport { z } from 'zod';\nimport { db } from './client.js';\n\nconst { query, serve } = initServe({\n context: () => ({ db }),\n});\n\n";
|
|
9
10
|
if (hasExample && tableName) {
|
|
10
11
|
template += "\nconst ".concat(camelCase(tableName), "Query = query({\n description: 'Example query using the ").concat(tableName, " table',\n query: async ({ ctx }) =>\n ctx.db\n .table('").concat(tableName, "')\n .select('*')\n .limit(10)\n .execute(),\n});");
|
|
11
12
|
}
|
|
12
13
|
else {
|
|
13
14
|
template += "\nconst exampleMetric = query({\n description: 'Example metric that returns a simple value',\n output: z.object({ ok: z.boolean() }),\n query: async () => ({ ok: true }),\n});";
|
|
14
15
|
}
|
|
15
|
-
template += "\nexport const api = serve({\n queries: {\n ".concat(metricKey, ",\n },\n});\n\nexport type ApiDefinition = InferApiType<typeof api>;\n\n/**\n * Inline usage example:\n *\n * const result = await api.execute('").concat(metricKey, "');\n * console.log(result);\n *\n * // import type { InferQueryResult } from '@hypequery/serve';\n * type ").concat(typeAlias, " = InferQueryResult<typeof api, '").concat(metricKey, "'>;\n *\n *
|
|
16
|
+
template += "\nexport const api = serve({\n queries: {\n ".concat(metricKey, ",\n },\n});\napi.route('").concat(routePath, "', api.queries.").concat(metricKey, ");\n\nexport type ApiDefinition = InferApiType<typeof api>;\n\n/**\n * Inline usage example:\n *\n * const result = await api.execute('").concat(metricKey, "');\n * console.log(result);\n *\n * // import type { InferQueryResult } from '@hypequery/serve';\n * type ").concat(typeAlias, " = InferQueryResult<typeof api, '").concat(metricKey, "'>;\n *\n * HTTP route:\n * ").concat(routePath, "\n *\n * Dev server:\n * npx hypequery dev analytics/queries.ts\n */\n");
|
|
16
17
|
return template;
|
|
17
18
|
}
|
|
18
19
|
/**
|
package/dist/test-utils.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import type { Mock } from 'vitest';
|
|
|
3
3
|
* Mock prompts module for testing
|
|
4
4
|
*/
|
|
5
5
|
export declare function createMockPrompts(): {
|
|
6
|
-
promptDatabaseType: Mock<(...args: any[]) => any>;
|
|
7
6
|
promptClickHouseConnection: Mock<(...args: any[]) => any>;
|
|
8
7
|
promptOutputDirectory: Mock<(...args: any[]) => any>;
|
|
9
8
|
promptGenerateExample: Mock<(...args: any[]) => any>;
|
package/dist/test-utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnC;;GAEG;AACH,wBAAgB,iBAAiB
|
|
1
|
+
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnC;;GAEG;AACH,wBAAgB,iBAAiB;;;;;;;;EAUhC;AAED;;GAEG;AACH,wBAAgB,uBAAuB;;;;EAMtC;AAED;;GAEG;AACH,wBAAgB,mBAAmB;;;;;EAOlC;AAED;;GAEG;AACH,wBAAgB,gBAAgB;;;;;;;;;;;;EAc/B;AAED;;GAEG;AACH,wBAAgB,iBAAiB;;;;;GAQhC;AAED;;GAEG;AACH,wBAAgB,YAAY;;;;;EAO3B;AAED;;GAEG;AACH,wBAAgB,cAAc;;;;EAuB7B;AAED;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IACtB,IAAI,EAAE,MAAM;gBAAZ,IAAI,EAAE,MAAM;CAIhC;AAED,wBAAgB,eAAe;;;EAc9B"}
|
package/dist/test-utils.js
CHANGED
|
@@ -57,7 +57,7 @@ export function getClickHouseClient() {
|
|
|
57
57
|
if (!client) {
|
|
58
58
|
var config = getClickHouseConfigFromEnv();
|
|
59
59
|
if (!config) {
|
|
60
|
-
throw new Error('ClickHouse connection details are missing. Set
|
|
60
|
+
throw new Error('ClickHouse connection details are missing. Set CLICKHOUSE_URL (or CLICKHOUSE_HOST), CLICKHOUSE_DATABASE, CLICKHOUSE_USERNAME, and CLICKHOUSE_PASSWORD.');
|
|
61
61
|
}
|
|
62
62
|
client = createClient({
|
|
63
63
|
url: config.url,
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export declare function
|
|
1
|
+
export declare function resolveScaffoldPackages(cliVersion: string | undefined): string[];
|
|
2
|
+
export declare function installScaffoldDependencies(): Promise<void>;
|
|
3
|
+
export declare const installServeDependencies: typeof installScaffoldDependencies;
|
|
2
4
|
//# sourceMappingURL=dependency-installer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependency-installer.d.ts","sourceRoot":"","sources":["../../src/utils/dependency-installer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dependency-installer.d.ts","sourceRoot":"","sources":["../../src/utils/dependency-installer.ts"],"names":[],"mappings":"AAkGA,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,CAUhF;AAsBD,wBAAsB,2BAA2B,kBAgDhD;AAED,eAAO,MAAM,wBAAwB,oCAA8B,CAAC"}
|
|
@@ -47,17 +47,28 @@ import { existsSync } from 'node:fs';
|
|
|
47
47
|
import { readFile } from 'node:fs/promises';
|
|
48
48
|
import path from 'node:path';
|
|
49
49
|
import { spawn } from 'node:child_process';
|
|
50
|
+
import { fileURLToPath } from 'node:url';
|
|
50
51
|
import { logger } from './logger.js';
|
|
51
|
-
var
|
|
52
|
+
var ZOD_SCAFFOLD_VERSION = '^3.23.8';
|
|
53
|
+
var STABLE_SCAFFOLD_PACKAGES = ['@hypequery/clickhouse', '@hypequery/serve', "zod@".concat(ZOD_SCAFFOLD_VERSION)];
|
|
54
|
+
var CLI_PACKAGE_PATH = fileURLToPath(new URL('../../package.json', import.meta.url));
|
|
52
55
|
var MANUAL_COMMANDS = {
|
|
53
56
|
pnpm: 'pnpm add',
|
|
54
57
|
yarn: 'yarn add',
|
|
55
58
|
npm: 'npm install',
|
|
56
59
|
bun: 'bun add',
|
|
57
60
|
};
|
|
58
|
-
function
|
|
61
|
+
function getDependencyVersion(pkg, name) {
|
|
59
62
|
var _a, _b, _c;
|
|
60
|
-
return
|
|
63
|
+
return (_b = (_a = pkg.dependencies) === null || _a === void 0 ? void 0 : _a[name]) !== null && _b !== void 0 ? _b : (_c = pkg.devDependencies) === null || _c === void 0 ? void 0 : _c[name];
|
|
64
|
+
}
|
|
65
|
+
function packageNameFromSpecifier(specifier) {
|
|
66
|
+
if (!specifier.startsWith('@')) {
|
|
67
|
+
var atIndex = specifier.lastIndexOf('@');
|
|
68
|
+
return atIndex > 0 ? specifier.slice(0, atIndex) : specifier;
|
|
69
|
+
}
|
|
70
|
+
var separatorIndex = specifier.indexOf('@', specifier.indexOf('/') + 1);
|
|
71
|
+
return separatorIndex === -1 ? specifier : specifier.slice(0, separatorIndex);
|
|
61
72
|
}
|
|
62
73
|
function readProjectPackageJson() {
|
|
63
74
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -78,6 +89,25 @@ function readProjectPackageJson() {
|
|
|
78
89
|
});
|
|
79
90
|
});
|
|
80
91
|
}
|
|
92
|
+
function readCliPackageJson() {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
94
|
+
var file, _a;
|
|
95
|
+
return __generator(this, function (_b) {
|
|
96
|
+
switch (_b.label) {
|
|
97
|
+
case 0:
|
|
98
|
+
_b.trys.push([0, 2, , 3]);
|
|
99
|
+
return [4 /*yield*/, readFile(CLI_PACKAGE_PATH, 'utf8')];
|
|
100
|
+
case 1:
|
|
101
|
+
file = _b.sent();
|
|
102
|
+
return [2 /*return*/, JSON.parse(file)];
|
|
103
|
+
case 2:
|
|
104
|
+
_a = _b.sent();
|
|
105
|
+
return [2 /*return*/, null];
|
|
106
|
+
case 3: return [2 /*return*/];
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
}
|
|
81
111
|
function detectPackageManager(pkgJson) {
|
|
82
112
|
var _a, _b;
|
|
83
113
|
var userAgent = (_a = process.env.npm_config_user_agent) !== null && _a !== void 0 ? _a : '';
|
|
@@ -119,23 +149,52 @@ function getInstallArgs(manager, packages) {
|
|
|
119
149
|
function formatManualCommand(manager, packages) {
|
|
120
150
|
return "".concat(MANUAL_COMMANDS[manager], " ").concat(packages.join(' '));
|
|
121
151
|
}
|
|
122
|
-
export function
|
|
152
|
+
export function resolveScaffoldPackages(cliVersion) {
|
|
153
|
+
if (cliVersion === null || cliVersion === void 0 ? void 0 : cliVersion.includes('canary')) {
|
|
154
|
+
return [
|
|
155
|
+
"@hypequery/clickhouse@".concat(cliVersion),
|
|
156
|
+
"@hypequery/serve@".concat(cliVersion),
|
|
157
|
+
"zod@".concat(ZOD_SCAFFOLD_VERSION),
|
|
158
|
+
];
|
|
159
|
+
}
|
|
160
|
+
return __spreadArray([], STABLE_SCAFFOLD_PACKAGES, true);
|
|
161
|
+
}
|
|
162
|
+
function shouldInstallPackage(pkgJson, specifier) {
|
|
163
|
+
var name = packageNameFromSpecifier(specifier);
|
|
164
|
+
var existingVersion = getDependencyVersion(pkgJson, name);
|
|
165
|
+
if (!existingVersion) {
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
var desiredHasPinnedVersion = specifier.startsWith('@')
|
|
169
|
+
? specifier.indexOf('@', specifier.indexOf('/') + 1) !== -1
|
|
170
|
+
: specifier.includes('@');
|
|
171
|
+
if (!desiredHasPinnedVersion) {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
var desiredVersion = specifier.slice(name.length + 1);
|
|
175
|
+
return existingVersion !== desiredVersion;
|
|
176
|
+
}
|
|
177
|
+
export function installScaffoldDependencies() {
|
|
123
178
|
return __awaiter(this, void 0, void 0, function () {
|
|
124
|
-
var pkgJson, missing, manager, command, args, error_1;
|
|
125
|
-
return __generator(this, function (
|
|
126
|
-
switch (
|
|
179
|
+
var _a, pkgJson, cliPkgJson, requestedPackages, missing, manager, command, args, error_1;
|
|
180
|
+
return __generator(this, function (_b) {
|
|
181
|
+
switch (_b.label) {
|
|
127
182
|
case 0:
|
|
128
183
|
if (process.env.HYPEQUERY_SKIP_INSTALL === '1') {
|
|
129
184
|
return [2 /*return*/];
|
|
130
185
|
}
|
|
131
|
-
return [4 /*yield*/,
|
|
186
|
+
return [4 /*yield*/, Promise.all([
|
|
187
|
+
readProjectPackageJson(),
|
|
188
|
+
readCliPackageJson(),
|
|
189
|
+
])];
|
|
132
190
|
case 1:
|
|
133
|
-
|
|
191
|
+
_a = _b.sent(), pkgJson = _a[0], cliPkgJson = _a[1];
|
|
134
192
|
if (!pkgJson) {
|
|
135
|
-
logger.warn('package.json not found. Install @hypequery/clickhouse
|
|
193
|
+
logger.warn('package.json not found. Install @hypequery/clickhouse, @hypequery/serve, and zod manually.');
|
|
136
194
|
return [2 /*return*/];
|
|
137
195
|
}
|
|
138
|
-
|
|
196
|
+
requestedPackages = resolveScaffoldPackages(cliPkgJson === null || cliPkgJson === void 0 ? void 0 : cliPkgJson.version);
|
|
197
|
+
missing = requestedPackages.filter(function (pkg) { return shouldInstallPackage(pkgJson, pkg); });
|
|
139
198
|
if (missing.length === 0) {
|
|
140
199
|
return [2 /*return*/];
|
|
141
200
|
}
|
|
@@ -143,9 +202,9 @@ export function installServeDependencies() {
|
|
|
143
202
|
command = manager === 'npm' ? 'npm' : manager;
|
|
144
203
|
args = getInstallArgs(manager, missing);
|
|
145
204
|
logger.info("Installing ".concat(missing.join(', '), " with ").concat(manager, "..."));
|
|
146
|
-
|
|
205
|
+
_b.label = 2;
|
|
147
206
|
case 2:
|
|
148
|
-
|
|
207
|
+
_b.trys.push([2, 4, , 5]);
|
|
149
208
|
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
150
209
|
var child = spawn(command, args, {
|
|
151
210
|
cwd: process.cwd(),
|
|
@@ -162,11 +221,11 @@ export function installServeDependencies() {
|
|
|
162
221
|
});
|
|
163
222
|
})];
|
|
164
223
|
case 3:
|
|
165
|
-
|
|
224
|
+
_b.sent();
|
|
166
225
|
logger.success("Installed ".concat(missing.join(', ')));
|
|
167
226
|
return [3 /*break*/, 5];
|
|
168
227
|
case 4:
|
|
169
|
-
error_1 =
|
|
228
|
+
error_1 = _b.sent();
|
|
170
229
|
logger.warn('Failed to install hypequery packages automatically.');
|
|
171
230
|
logger.info("Run manually: ".concat(formatManualCommand(manager, missing)));
|
|
172
231
|
if (error_1 instanceof Error && error_1.message) {
|
|
@@ -178,3 +237,4 @@ export function installServeDependencies() {
|
|
|
178
237
|
});
|
|
179
238
|
});
|
|
180
239
|
}
|
|
240
|
+
export var installServeDependencies = installScaffoldDependencies;
|
package/dist/utils/load-api.d.ts
CHANGED
|
@@ -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,
|
|
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"}
|
package/dist/utils/load-api.js
CHANGED
|
@@ -47,92 +47,116 @@ var TYPESCRIPT_EXTENSIONS = new Set(['.ts', '.tsx', '.mts', '.cts']);
|
|
|
47
47
|
var tsconfigCache = new Map();
|
|
48
48
|
export function loadApiModule(modulePath) {
|
|
49
49
|
return __awaiter(this, void 0, void 0, function () {
|
|
50
|
-
var resolved,
|
|
51
|
-
var
|
|
52
|
-
return __generator(this, function (
|
|
53
|
-
switch (
|
|
50
|
+
var resolved, mod, error_1, relativePath, api, relativePath, availableExports;
|
|
51
|
+
var _a;
|
|
52
|
+
return __generator(this, function (_b) {
|
|
53
|
+
switch (_b.label) {
|
|
54
54
|
case 0:
|
|
55
55
|
resolved = path.resolve(process.cwd(), modulePath);
|
|
56
|
-
|
|
56
|
+
_b.label = 1;
|
|
57
57
|
case 1:
|
|
58
|
-
|
|
58
|
+
_b.trys.push([1, 3, , 4]);
|
|
59
|
+
return [4 /*yield*/, loadModule(modulePath)];
|
|
60
|
+
case 2:
|
|
61
|
+
mod = _b.sent();
|
|
62
|
+
return [3 /*break*/, 4];
|
|
63
|
+
case 3:
|
|
64
|
+
error_1 = _b.sent();
|
|
65
|
+
if (error_1 instanceof Error && error_1.message.startsWith('File not found:')) {
|
|
66
|
+
relativePath = path.relative(process.cwd(), resolved);
|
|
67
|
+
throw new Error("File not found: ".concat(relativePath, "\n\n") +
|
|
68
|
+
"Make sure the file exists and the path is correct.\n" +
|
|
69
|
+
"You can specify a different file with:\n" +
|
|
70
|
+
" hypequery dev path/to/your/queries.ts");
|
|
71
|
+
}
|
|
72
|
+
throw error_1;
|
|
73
|
+
case 4:
|
|
74
|
+
api = (_a = mod.api) !== null && _a !== void 0 ? _a : mod.default;
|
|
75
|
+
if (!api || typeof api.handler !== 'function') {
|
|
76
|
+
relativePath = path.relative(process.cwd(), resolved);
|
|
77
|
+
availableExports = Object.keys(mod).filter(function (key) { return key !== '__esModule'; });
|
|
78
|
+
throw new Error("Invalid API module: ".concat(relativePath, "\n\n") +
|
|
79
|
+
"The module must export a 'defineServe' result as 'api'.\n\n" +
|
|
80
|
+
(availableExports.length > 0
|
|
81
|
+
? "Found exports: ".concat(availableExports.join(', '), "\n\n")
|
|
82
|
+
: "No exports found in the module.\n\n") +
|
|
83
|
+
"Expected format:\n\n" +
|
|
84
|
+
" import { initServe } from '@hypequery/serve';\n" +
|
|
85
|
+
" \n" +
|
|
86
|
+
" const { define, queries, query } = initServe({\n" +
|
|
87
|
+
" context: () => ({ db }),\n" +
|
|
88
|
+
" });\n" +
|
|
89
|
+
" \n" +
|
|
90
|
+
" export const api = define({\n" +
|
|
91
|
+
" queries: queries({\n" +
|
|
92
|
+
" myQuery: query.query(async ({ ctx }) => {\n" +
|
|
93
|
+
" // ...\n" +
|
|
94
|
+
" }),\n" +
|
|
95
|
+
" }),\n" +
|
|
96
|
+
" });\n");
|
|
97
|
+
}
|
|
98
|
+
return [2 /*return*/, api];
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
export function loadModule(modulePath) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
105
|
+
var resolved, _a, relativePath, extension, isTypeScript, moduleUrl, _b, importOverride, _c, error_2, relativePath;
|
|
106
|
+
return __generator(this, function (_d) {
|
|
107
|
+
switch (_d.label) {
|
|
108
|
+
case 0:
|
|
109
|
+
resolved = path.resolve(process.cwd(), modulePath);
|
|
110
|
+
_d.label = 1;
|
|
111
|
+
case 1:
|
|
112
|
+
_d.trys.push([1, 3, , 4]);
|
|
59
113
|
return [4 /*yield*/, access(resolved)];
|
|
60
114
|
case 2:
|
|
61
|
-
|
|
115
|
+
_d.sent();
|
|
62
116
|
return [3 /*break*/, 4];
|
|
63
117
|
case 3:
|
|
64
|
-
_a =
|
|
118
|
+
_a = _d.sent();
|
|
65
119
|
relativePath = path.relative(process.cwd(), resolved);
|
|
66
|
-
throw new Error("File not found: ".concat(relativePath
|
|
67
|
-
"Make sure the file exists and the path is correct.\n" +
|
|
68
|
-
"You can specify a different file with:\n" +
|
|
69
|
-
" hypequery dev path/to/your/queries.ts");
|
|
120
|
+
throw new Error("File not found: ".concat(relativePath));
|
|
70
121
|
case 4:
|
|
71
122
|
extension = path.extname(resolved).toLowerCase();
|
|
72
123
|
isTypeScript = TYPESCRIPT_EXTENSIONS.has(extension);
|
|
73
124
|
if (!isTypeScript) return [3 /*break*/, 6];
|
|
74
125
|
return [4 /*yield*/, bundleTypeScriptModule(resolved)];
|
|
75
126
|
case 5:
|
|
76
|
-
_b =
|
|
127
|
+
_b = _d.sent();
|
|
77
128
|
return [3 /*break*/, 7];
|
|
78
129
|
case 6:
|
|
79
130
|
_b = "".concat(pathToFileURL(resolved).href, "?t=").concat(Date.now());
|
|
80
|
-
|
|
131
|
+
_d.label = 7;
|
|
81
132
|
case 7:
|
|
82
133
|
moduleUrl = _b;
|
|
83
|
-
|
|
134
|
+
_d.label = 8;
|
|
84
135
|
case 8:
|
|
85
|
-
|
|
136
|
+
_d.trys.push([8, 13, , 14]);
|
|
86
137
|
importOverride = globalState.__hypequeryCliImportOverride;
|
|
87
138
|
if (!importOverride) return [3 /*break*/, 10];
|
|
88
139
|
return [4 /*yield*/, importOverride(moduleUrl)];
|
|
89
140
|
case 9:
|
|
90
|
-
_c =
|
|
141
|
+
_c = _d.sent();
|
|
91
142
|
return [3 /*break*/, 12];
|
|
92
143
|
case 10: return [4 /*yield*/, import(/* @vite-ignore */ moduleUrl)];
|
|
93
144
|
case 11:
|
|
94
|
-
_c =
|
|
95
|
-
|
|
96
|
-
case 12:
|
|
97
|
-
mod = _c;
|
|
98
|
-
return [3 /*break*/, 14];
|
|
145
|
+
_c = _d.sent();
|
|
146
|
+
_d.label = 12;
|
|
147
|
+
case 12: return [2 /*return*/, _c];
|
|
99
148
|
case 13:
|
|
100
|
-
|
|
149
|
+
error_2 = _d.sent();
|
|
101
150
|
relativePath = path.relative(process.cwd(), resolved);
|
|
102
151
|
throw new Error("Failed to load module: ".concat(relativePath, "\n\n") +
|
|
103
|
-
"Error: ".concat(
|
|
104
|
-
(
|
|
152
|
+
"Error: ".concat(error_2.message, "\n\n") +
|
|
153
|
+
(error_2.code === 'ERR_MODULE_NOT_FOUND'
|
|
105
154
|
? "This usually means:\n" +
|
|
106
155
|
" \u2022 A dependency is missing (run 'npm install')\n" +
|
|
107
156
|
" \u2022 An import path is incorrect\n"
|
|
108
157
|
: "") +
|
|
109
|
-
(
|
|
110
|
-
case 14:
|
|
111
|
-
api = (_d = mod.api) !== null && _d !== void 0 ? _d : mod.default;
|
|
112
|
-
if (!api || typeof api.handler !== 'function') {
|
|
113
|
-
relativePath = path.relative(process.cwd(), resolved);
|
|
114
|
-
availableExports = Object.keys(mod).filter(function (key) { return key !== '__esModule'; });
|
|
115
|
-
throw new Error("Invalid API module: ".concat(relativePath, "\n\n") +
|
|
116
|
-
"The module must export a 'defineServe' result as 'api'.\n\n" +
|
|
117
|
-
(availableExports.length > 0
|
|
118
|
-
? "Found exports: ".concat(availableExports.join(', '), "\n\n")
|
|
119
|
-
: "No exports found in the module.\n\n") +
|
|
120
|
-
"Expected format:\n\n" +
|
|
121
|
-
" import { initServe } from '@hypequery/serve';\n" +
|
|
122
|
-
" \n" +
|
|
123
|
-
" const { define, queries, query } = initServe({\n" +
|
|
124
|
-
" context: () => ({ db }),\n" +
|
|
125
|
-
" });\n" +
|
|
126
|
-
" \n" +
|
|
127
|
-
" export const api = define({\n" +
|
|
128
|
-
" queries: queries({\n" +
|
|
129
|
-
" myQuery: query.query(async ({ ctx }) => {\n" +
|
|
130
|
-
" // ...\n" +
|
|
131
|
-
" }),\n" +
|
|
132
|
-
" }),\n" +
|
|
133
|
-
" });\n");
|
|
134
|
-
}
|
|
135
|
-
return [2 /*return*/, api];
|
|
158
|
+
(error_2.stack ? "\nStack trace:\n".concat(error_2.stack, "\n") : ''));
|
|
159
|
+
case 14: return [2 /*return*/];
|
|
136
160
|
}
|
|
137
161
|
});
|
|
138
162
|
});
|
|
@@ -294,7 +318,7 @@ function installCleanupHooks() {
|
|
|
294
318
|
}
|
|
295
319
|
function bundleTypeScriptModule(entryPath) {
|
|
296
320
|
return __awaiter(this, void 0, void 0, function () {
|
|
297
|
-
var relativePath, tsconfigPath, result, output, tempDir, timestamp, tempFile, contents,
|
|
321
|
+
var relativePath, tsconfigPath, result, output, tempDir, timestamp, tempFile, contents, error_3;
|
|
298
322
|
var _a, _b, _c, _d;
|
|
299
323
|
return __generator(this, function (_e) {
|
|
300
324
|
switch (_e.label) {
|
|
@@ -345,9 +369,9 @@ function bundleTypeScriptModule(entryPath) {
|
|
|
345
369
|
tempFiles.add(tempFile);
|
|
346
370
|
return [2 /*return*/, "".concat(pathToFileURL(tempFile).href, "?t=").concat(timestamp)];
|
|
347
371
|
case 6:
|
|
348
|
-
|
|
372
|
+
error_3 = _e.sent();
|
|
349
373
|
throw new Error("Failed to compile ".concat(relativePath, " with esbuild.\n") +
|
|
350
|
-
"Original error: ".concat((_d =
|
|
374
|
+
"Original error: ".concat((_d = error_3 === null || error_3 === void 0 ? void 0 : error_3.message) !== null && _d !== void 0 ? _d : error_3));
|
|
351
375
|
case 7: return [2 /*return*/];
|
|
352
376
|
}
|
|
353
377
|
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ResolvedHypequeryClickHouseConfig } from '@hypequery/schema';
|
|
2
|
+
export declare const DEFAULT_HYPEQUERY_CONFIG_PATH = "hypequery.config.ts";
|
|
3
|
+
export declare const DEFAULT_MIGRATIONS_OUT_DIR = "./migrations";
|
|
4
|
+
export declare const DEFAULT_MIGRATIONS_TABLE = "_hypequery_migrations";
|
|
5
|
+
export declare const DEFAULT_MIGRATIONS_PREFIX: "timestamp";
|
|
6
|
+
export declare function loadHypequeryConfig(configPath?: string): Promise<ResolvedHypequeryClickHouseConfig>;
|
|
7
|
+
//# sourceMappingURL=load-hypequery-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-hypequery-config.d.ts","sourceRoot":"","sources":["../../src/utils/load-hypequery-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,iCAAiC,EAClC,MAAM,mBAAmB,CAAC;AAG3B,eAAO,MAAM,6BAA6B,wBAAwB,CAAC;AACnE,eAAO,MAAM,0BAA0B,iBAAiB,CAAC;AACzD,eAAO,MAAM,wBAAwB,0BAA0B,CAAC;AAChE,eAAO,MAAM,yBAAyB,EAAG,WAAoB,CAAC;AAE9D,wBAAsB,mBAAmB,CACvC,UAAU,SAAgC,GACzC,OAAO,CAAC,iCAAiC,CAAC,CA0C5C"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
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);
|
|
23
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
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;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
import { loadModule } from './load-api.js';
|
|
49
|
+
export var DEFAULT_HYPEQUERY_CONFIG_PATH = 'hypequery.config.ts';
|
|
50
|
+
export var DEFAULT_MIGRATIONS_OUT_DIR = './migrations';
|
|
51
|
+
export var DEFAULT_MIGRATIONS_TABLE = '_hypequery_migrations';
|
|
52
|
+
export var DEFAULT_MIGRATIONS_PREFIX = 'timestamp';
|
|
53
|
+
export function loadHypequeryConfig() {
|
|
54
|
+
return __awaiter(this, arguments, void 0, function (configPath) {
|
|
55
|
+
var mod, candidate, config;
|
|
56
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
57
|
+
if (configPath === void 0) { configPath = DEFAULT_HYPEQUERY_CONFIG_PATH; }
|
|
58
|
+
return __generator(this, function (_h) {
|
|
59
|
+
switch (_h.label) {
|
|
60
|
+
case 0: return [4 /*yield*/, loadModule(configPath)];
|
|
61
|
+
case 1:
|
|
62
|
+
mod = _h.sent();
|
|
63
|
+
candidate = (_a = mod.default) !== null && _a !== void 0 ? _a : mod.config;
|
|
64
|
+
if (!candidate || typeof candidate !== 'object') {
|
|
65
|
+
throw new Error("Invalid hypequery config: ".concat(configPath, "\n\n") +
|
|
66
|
+
"The config module must export a ClickHouse config as the default export.");
|
|
67
|
+
}
|
|
68
|
+
config = candidate;
|
|
69
|
+
if (config.dialect !== 'clickhouse') {
|
|
70
|
+
throw new Error("Invalid hypequery config: ".concat(configPath, "\n\n") +
|
|
71
|
+
"Expected \"dialect\" to be \"clickhouse\".");
|
|
72
|
+
}
|
|
73
|
+
if (typeof config.schema !== 'string' || config.schema.length === 0) {
|
|
74
|
+
throw new Error("Invalid hypequery config: ".concat(configPath, "\n\n") +
|
|
75
|
+
"Expected \"schema\" to be a non-empty string.");
|
|
76
|
+
}
|
|
77
|
+
if (!config.dbCredentials || typeof config.dbCredentials !== 'object') {
|
|
78
|
+
throw new Error("Invalid hypequery config: ".concat(configPath, "\n\n") +
|
|
79
|
+
"Expected \"dbCredentials\" to be defined.");
|
|
80
|
+
}
|
|
81
|
+
return [2 /*return*/, __assign(__assign({}, config), { migrations: {
|
|
82
|
+
out: (_c = (_b = config.migrations) === null || _b === void 0 ? void 0 : _b.out) !== null && _c !== void 0 ? _c : DEFAULT_MIGRATIONS_OUT_DIR,
|
|
83
|
+
table: (_e = (_d = config.migrations) === null || _d === void 0 ? void 0 : _d.table) !== null && _e !== void 0 ? _e : DEFAULT_MIGRATIONS_TABLE,
|
|
84
|
+
prefix: (_g = (_f = config.migrations) === null || _f === void 0 ? void 0 : _f.prefix) !== null && _g !== void 0 ? _g : DEFAULT_MIGRATIONS_PREFIX,
|
|
85
|
+
} })];
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
package/dist/utils/prompts.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../src/utils/prompts.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../src/utils/prompts.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,wBAAsB,0BAA0B,IAAI,OAAO,CAAC;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,IAAI,CAAC,CAkCR;AAED;;GAEG;AACH,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,MAAM,CAAC,CA6B7D;AAED;;GAEG;AACH,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,OAAO,CAAC,CAS9D;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA0BnF;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CASxE;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CASnE;AAED;;GAEG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,OAAO,CAAC,CAShE"}
|