@hypequery/cli 1.1.1 → 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 (77) hide show
  1. package/README.md +71 -149
  2. package/dist/bin/cli.js +21 -81
  3. package/dist/cli.d.ts +3 -0
  4. package/dist/cli.d.ts.map +1 -1
  5. package/dist/cli.js +74 -105
  6. package/dist/commands/dev.d.ts +1 -0
  7. package/dist/commands/dev.d.ts.map +1 -1
  8. package/dist/commands/dev.js +180 -255
  9. package/dist/commands/generate-datasets.d.ts +14 -0
  10. package/dist/commands/generate-datasets.d.ts.map +1 -0
  11. package/dist/commands/generate-datasets.js +96 -0
  12. package/dist/commands/generate.d.ts +2 -0
  13. package/dist/commands/generate.d.ts.map +1 -1
  14. package/dist/commands/generate.js +112 -167
  15. package/dist/commands/init.d.ts +7 -1
  16. package/dist/commands/init.d.ts.map +1 -1
  17. package/dist/commands/init.js +337 -390
  18. package/dist/generators/clickhouse.d.ts +1 -1
  19. package/dist/generators/clickhouse.d.ts.map +1 -1
  20. package/dist/generators/clickhouse.js +10 -269
  21. package/dist/generators/dataset-generator.d.ts +16 -0
  22. package/dist/generators/dataset-generator.d.ts.map +1 -0
  23. package/dist/generators/dataset-generator.js +213 -0
  24. package/dist/generators/index.js +4 -4
  25. package/dist/templates/api.d.ts +9 -0
  26. package/dist/templates/api.d.ts.map +1 -0
  27. package/dist/templates/api.js +26 -0
  28. package/dist/templates/auth-scaffold.d.ts +17 -0
  29. package/dist/templates/auth-scaffold.d.ts.map +1 -0
  30. package/dist/templates/auth-scaffold.js +41 -0
  31. package/dist/templates/client.js +10 -1
  32. package/dist/templates/datasets.d.ts +5 -0
  33. package/dist/templates/datasets.d.ts.map +1 -0
  34. package/dist/templates/datasets.js +23 -0
  35. package/dist/templates/env.d.ts +2 -1
  36. package/dist/templates/env.d.ts.map +1 -1
  37. package/dist/templates/env.js +19 -6
  38. package/dist/templates/gitignore.js +4 -1
  39. package/dist/templates/queries.d.ts +3 -0
  40. package/dist/templates/queries.d.ts.map +1 -1
  41. package/dist/templates/queries.js +66 -9
  42. package/dist/test-utils.d.ts +0 -72
  43. package/dist/test-utils.d.ts.map +1 -1
  44. package/dist/test-utils.js +12 -138
  45. package/dist/utils/clickhouse-client.js +11 -58
  46. package/dist/utils/clickhouse-sql.d.ts +6 -0
  47. package/dist/utils/clickhouse-sql.d.ts.map +1 -0
  48. package/dist/utils/clickhouse-sql.js +18 -0
  49. package/dist/utils/clickhouse-type-utils.d.ts +6 -0
  50. package/dist/utils/clickhouse-type-utils.d.ts.map +1 -0
  51. package/dist/utils/clickhouse-type-utils.js +59 -0
  52. package/dist/utils/dependency-installer.d.ts +5 -1
  53. package/dist/utils/dependency-installer.d.ts.map +1 -1
  54. package/dist/utils/dependency-installer.js +117 -134
  55. package/dist/utils/detect-database.js +84 -195
  56. package/dist/utils/find-files.d.ts +3 -1
  57. package/dist/utils/find-files.d.ts.map +1 -1
  58. package/dist/utils/find-files.js +82 -148
  59. package/dist/utils/load-api.d.ts.map +1 -1
  60. package/dist/utils/load-api.js +207 -396
  61. package/dist/utils/logger.js +38 -42
  62. package/dist/utils/prompts.d.ts +14 -5
  63. package/dist/utils/prompts.d.ts.map +1 -1
  64. package/dist/utils/prompts.js +170 -244
  65. package/dist/utils/runtime-guards.d.ts +4 -0
  66. package/dist/utils/runtime-guards.d.ts.map +1 -0
  67. package/dist/utils/runtime-guards.js +9 -0
  68. package/dist/utils/sha256.d.ts +2 -0
  69. package/dist/utils/sha256.d.ts.map +1 -0
  70. package/dist/utils/sha256.js +4 -0
  71. package/package.json +4 -4
  72. package/dist/utils/error-messages.d.ts +0 -6
  73. package/dist/utils/error-messages.d.ts.map +0 -1
  74. package/dist/utils/error-messages.js +0 -19
  75. package/dist/utils/load-hypequery-config.d.ts +0 -7
  76. package/dist/utils/load-hypequery-config.d.ts.map +0 -1
  77. package/dist/utils/load-hypequery-config.js +0 -89
@@ -0,0 +1,4 @@
1
+ export declare function isRecord(value: unknown): value is Record<string, unknown>;
2
+ export declare function isNodeErrorWithCode(error: unknown, code: string): error is NodeJS.ErrnoException;
3
+ export declare function isNotFoundError(error: unknown): error is NodeJS.ErrnoException;
4
+ //# sourceMappingURL=runtime-guards.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-guards.d.ts","sourceRoot":"","sources":["../../src/utils/runtime-guards.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzE;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,KAAK,IAAI,MAAM,CAAC,cAAc,CAEhG;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,cAAc,CAE9E"}
@@ -0,0 +1,9 @@
1
+ export function isRecord(value) {
2
+ return Boolean(value) && typeof value === 'object';
3
+ }
4
+ export function isNodeErrorWithCode(error, code) {
5
+ return isRecord(error) && error.code === code;
6
+ }
7
+ export function isNotFoundError(error) {
8
+ return isNodeErrorWithCode(error, 'ENOENT');
9
+ }
@@ -0,0 +1,2 @@
1
+ export declare function sha256(value: string | Buffer): string;
2
+ //# sourceMappingURL=sha256.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha256.d.ts","sourceRoot":"","sources":["../../src/utils/sha256.ts"],"names":[],"mappings":"AAEA,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,UAE5C"}
@@ -0,0 +1,4 @@
1
+ import { createHash } from 'node:crypto';
2
+ export function sha256(value) {
3
+ return createHash('sha256').update(value).digest('hex');
4
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hypequery/cli",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "Command-line interface for hypequery",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -11,7 +11,7 @@
11
11
  "dist"
12
12
  ],
13
13
  "dependencies": {
14
- "@clickhouse/client": "^1.16.0",
14
+ "@clickhouse/client": "^1.18.3",
15
15
  "chalk": "^5.3.0",
16
16
  "commander": "^12.0.0",
17
17
  "dotenv": "^16.4.7",
@@ -35,8 +35,8 @@
35
35
  "@vitest/coverage-v8": "^2.1.6",
36
36
  "typescript": "^5.7.3",
37
37
  "vitest": "^2.1.6",
38
- "@hypequery/clickhouse": "1.6.2",
39
- "@hypequery/serve": "0.2.0"
38
+ "@hypequery/clickhouse": "2.1.0",
39
+ "@hypequery/serve": "0.3.0"
40
40
  },
41
41
  "repository": {
42
42
  "type": "git",
@@ -1,6 +0,0 @@
1
- /**
2
- * Display error when queries file cannot be found
3
- * @param commandName - Name of the command for the usage example
4
- */
5
- export declare function displayQueriesFileNotFoundError(commandName: string): void;
6
- //# sourceMappingURL=error-messages.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"error-messages.d.ts","sourceRoot":"","sources":["../../src/utils/error-messages.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,+BAA+B,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAazE"}
@@ -1,19 +0,0 @@
1
- import { logger } from './logger.js';
2
- /**
3
- * Display error when queries file cannot be found
4
- * @param commandName - Name of the command for the usage example
5
- */
6
- export function displayQueriesFileNotFoundError(commandName) {
7
- logger.error('Could not find queries file');
8
- logger.newline();
9
- logger.info('Expected one of:');
10
- logger.indent('• analytics/queries.ts');
11
- logger.indent('• src/analytics/queries.ts');
12
- logger.indent('• hypequery.ts');
13
- logger.newline();
14
- logger.info("Did you run 'hypequery init'?");
15
- logger.newline();
16
- logger.info('Or specify the file explicitly:');
17
- logger.indent("hypequery ".concat(commandName, " ./path/to/queries.ts"));
18
- logger.newline();
19
- }
@@ -1,7 +0,0 @@
1
- import type { ResolvedHypequeryClickHouseConfig } from '@hypequery/clickhouse';
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
@@ -1 +0,0 @@
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,uBAAuB,CAAC;AAG/B,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"}
@@ -1,89 +0,0 @@
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
- }