@tinybirdco/sdk 0.0.3 → 0.0.6
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 +87 -14
- package/dist/api/deploy.d.ts +41 -3
- package/dist/api/deploy.d.ts.map +1 -1
- package/dist/api/deploy.js +141 -19
- package/dist/api/deploy.js.map +1 -1
- package/dist/api/deploy.test.js +77 -29
- package/dist/api/deploy.test.js.map +1 -1
- package/dist/api/local.d.ts +92 -0
- package/dist/api/local.d.ts.map +1 -0
- package/dist/api/local.js +176 -0
- package/dist/api/local.js.map +1 -0
- package/dist/api/local.test.d.ts +2 -0
- package/dist/api/local.test.d.ts.map +1 -0
- package/dist/api/local.test.js +182 -0
- package/dist/api/local.test.js.map +1 -0
- package/dist/api/resources.d.ts +178 -0
- package/dist/api/resources.d.ts.map +1 -0
- package/dist/api/resources.js +244 -0
- package/dist/api/resources.js.map +1 -0
- package/dist/api/resources.test.d.ts +2 -0
- package/dist/api/resources.test.d.ts.map +1 -0
- package/dist/api/resources.test.js +255 -0
- package/dist/api/resources.test.js.map +1 -0
- package/dist/cli/commands/build.d.ts +6 -4
- package/dist/cli/commands/build.d.ts.map +1 -1
- package/dist/cli/commands/build.js +95 -47
- package/dist/cli/commands/build.js.map +1 -1
- package/dist/cli/commands/deploy.d.ts +39 -0
- package/dist/cli/commands/deploy.d.ts.map +1 -0
- package/dist/cli/commands/deploy.js +90 -0
- package/dist/cli/commands/deploy.js.map +1 -0
- package/dist/cli/commands/dev.d.ts +9 -2
- package/dist/cli/commands/dev.d.ts.map +1 -1
- package/dist/cli/commands/dev.js +60 -31
- package/dist/cli/commands/dev.js.map +1 -1
- package/dist/cli/commands/init.d.ts +24 -1
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +174 -23
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/init.test.js +190 -30
- package/dist/cli/commands/init.test.js.map +1 -1
- package/dist/cli/config.d.ts +14 -0
- package/dist/cli/config.d.ts.map +1 -1
- package/dist/cli/config.js +7 -0
- package/dist/cli/config.js.map +1 -1
- package/dist/cli/config.test.js +29 -0
- package/dist/cli/config.test.js.map +1 -1
- package/dist/cli/index.js +107 -11
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/utils/package-manager.d.ts +8 -0
- package/dist/cli/utils/package-manager.d.ts.map +1 -0
- package/dist/cli/utils/package-manager.js +45 -0
- package/dist/cli/utils/package-manager.js.map +1 -0
- package/dist/cli/utils/package-manager.test.d.ts +2 -0
- package/dist/cli/utils/package-manager.test.d.ts.map +1 -0
- package/dist/cli/utils/package-manager.test.js +85 -0
- package/dist/cli/utils/package-manager.test.js.map +1 -0
- package/dist/codegen/index.d.ts +39 -0
- package/dist/codegen/index.d.ts.map +1 -0
- package/dist/codegen/index.js +300 -0
- package/dist/codegen/index.js.map +1 -0
- package/dist/codegen/index.test.d.ts +2 -0
- package/dist/codegen/index.test.d.ts.map +1 -0
- package/dist/codegen/index.test.js +310 -0
- package/dist/codegen/index.test.js.map +1 -0
- package/dist/codegen/type-mapper.d.ts +20 -0
- package/dist/codegen/type-mapper.d.ts.map +1 -0
- package/dist/codegen/type-mapper.js +238 -0
- package/dist/codegen/type-mapper.js.map +1 -0
- package/dist/codegen/type-mapper.test.d.ts +2 -0
- package/dist/codegen/type-mapper.test.d.ts.map +1 -0
- package/dist/codegen/type-mapper.test.js +167 -0
- package/dist/codegen/type-mapper.test.js.map +1 -0
- package/dist/codegen/utils.d.ts +46 -0
- package/dist/codegen/utils.d.ts.map +1 -0
- package/dist/codegen/utils.js +141 -0
- package/dist/codegen/utils.js.map +1 -0
- package/dist/codegen/utils.test.d.ts +2 -0
- package/dist/codegen/utils.test.d.ts.map +1 -0
- package/dist/codegen/utils.test.js +178 -0
- package/dist/codegen/utils.test.js.map +1 -0
- package/dist/generator/index.d.ts +3 -0
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/index.js +17 -1
- package/dist/generator/index.js.map +1 -1
- package/dist/generator/index.test.js +104 -1
- package/dist/generator/index.test.js.map +1 -1
- package/dist/generator/loader.d.ts +15 -0
- package/dist/generator/loader.d.ts.map +1 -1
- package/dist/generator/loader.js +24 -0
- package/dist/generator/loader.js.map +1 -1
- package/dist/test/handlers.d.ts +49 -0
- package/dist/test/handlers.d.ts.map +1 -1
- package/dist/test/handlers.js +45 -0
- package/dist/test/handlers.js.map +1 -1
- package/package.json +4 -2
- package/src/api/deploy.test.ts +135 -34
- package/src/api/deploy.ts +203 -23
- package/src/api/local.test.ts +250 -0
- package/src/api/local.ts +270 -0
- package/src/api/resources.test.ts +332 -0
- package/src/api/resources.ts +554 -0
- package/src/cli/commands/build.ts +115 -53
- package/src/cli/commands/deploy.ts +126 -0
- package/src/cli/commands/dev.ts +81 -36
- package/src/cli/commands/init.test.ts +239 -30
- package/src/cli/commands/init.ts +243 -26
- package/src/cli/config.test.ts +47 -0
- package/src/cli/config.ts +20 -0
- package/src/cli/index.ts +120 -11
- package/src/cli/utils/package-manager.test.ts +118 -0
- package/src/cli/utils/package-manager.ts +44 -0
- package/src/codegen/index.test.ts +367 -0
- package/src/codegen/index.ts +379 -0
- package/src/codegen/type-mapper.test.ts +224 -0
- package/src/codegen/type-mapper.ts +265 -0
- package/src/codegen/utils.test.ts +221 -0
- package/src/codegen/utils.ts +174 -0
- package/src/generator/index.test.ts +121 -1
- package/src/generator/index.ts +19 -1
- package/src/generator/loader.ts +43 -0
- package/src/test/handlers.ts +58 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type mapping from ClickHouse types to TypeScript SDK validators
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Map a ClickHouse type to a t.* validator call
|
|
6
|
+
*
|
|
7
|
+
* Handles:
|
|
8
|
+
* - Basic types: String, Int32, Float64, DateTime, etc.
|
|
9
|
+
* - Nullable wrapper: Nullable(String) -> t.string().nullable()
|
|
10
|
+
* - LowCardinality wrapper: LowCardinality(String) -> t.string().lowCardinality()
|
|
11
|
+
* - Parameterized types: DateTime('UTC'), FixedString(10), Decimal(10, 2)
|
|
12
|
+
* - Complex types: Array(String), Map(String, Int32)
|
|
13
|
+
* - Aggregate functions: SimpleAggregateFunction(sum, UInt64)
|
|
14
|
+
*/
|
|
15
|
+
export declare function clickhouseTypeToValidator(chType: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Map a pipe parameter type to a p.* validator call
|
|
18
|
+
*/
|
|
19
|
+
export declare function paramTypeToValidator(paramType: string, defaultValue?: string | number, required?: boolean): string;
|
|
20
|
+
//# sourceMappingURL=type-mapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-mapper.d.ts","sourceRoot":"","sources":["../../src/codegen/type-mapper.ts"],"names":[],"mappings":"AAAA;;GAEG;AAgBH;;;;;;;;;;GAUG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CA0KhE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,MAAM,EACjB,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,EAC9B,QAAQ,GAAE,OAAc,GACvB,MAAM,CAwDR"}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type mapping from ClickHouse types to TypeScript SDK validators
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Parse enum values from an enum type string
|
|
6
|
+
* e.g., "'a' = 1, 'b' = 2" -> ["a", "b"]
|
|
7
|
+
*/
|
|
8
|
+
function parseEnumValues(enumContent) {
|
|
9
|
+
const values = [];
|
|
10
|
+
const regex = /'([^']+)'\s*=\s*\d+/g;
|
|
11
|
+
let match;
|
|
12
|
+
while ((match = regex.exec(enumContent)) !== null) {
|
|
13
|
+
values.push(match[1]);
|
|
14
|
+
}
|
|
15
|
+
return values;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Map a ClickHouse type to a t.* validator call
|
|
19
|
+
*
|
|
20
|
+
* Handles:
|
|
21
|
+
* - Basic types: String, Int32, Float64, DateTime, etc.
|
|
22
|
+
* - Nullable wrapper: Nullable(String) -> t.string().nullable()
|
|
23
|
+
* - LowCardinality wrapper: LowCardinality(String) -> t.string().lowCardinality()
|
|
24
|
+
* - Parameterized types: DateTime('UTC'), FixedString(10), Decimal(10, 2)
|
|
25
|
+
* - Complex types: Array(String), Map(String, Int32)
|
|
26
|
+
* - Aggregate functions: SimpleAggregateFunction(sum, UInt64)
|
|
27
|
+
*/
|
|
28
|
+
export function clickhouseTypeToValidator(chType) {
|
|
29
|
+
// Trim whitespace
|
|
30
|
+
chType = chType.trim();
|
|
31
|
+
// Handle Nullable wrapper
|
|
32
|
+
const nullableMatch = chType.match(/^Nullable\((.+)\)$/);
|
|
33
|
+
if (nullableMatch) {
|
|
34
|
+
const innerType = clickhouseTypeToValidator(nullableMatch[1]);
|
|
35
|
+
return `${innerType}.nullable()`;
|
|
36
|
+
}
|
|
37
|
+
// Handle LowCardinality wrapper
|
|
38
|
+
const lowCardMatch = chType.match(/^LowCardinality\((.+)\)$/);
|
|
39
|
+
if (lowCardMatch) {
|
|
40
|
+
const innerType = clickhouseTypeToValidator(lowCardMatch[1]);
|
|
41
|
+
// If inner type already has .nullable(), we need to handle this specially
|
|
42
|
+
// LowCardinality(Nullable(X)) should become t.X().nullable().lowCardinality()
|
|
43
|
+
// But the recursive call already returns t.X().nullable()
|
|
44
|
+
return `${innerType}.lowCardinality()`;
|
|
45
|
+
}
|
|
46
|
+
// Simple type mappings
|
|
47
|
+
const simpleTypeMap = {
|
|
48
|
+
String: "t.string()",
|
|
49
|
+
UUID: "t.uuid()",
|
|
50
|
+
Int8: "t.int8()",
|
|
51
|
+
Int16: "t.int16()",
|
|
52
|
+
Int32: "t.int32()",
|
|
53
|
+
Int64: "t.int64()",
|
|
54
|
+
Int128: "t.int128()",
|
|
55
|
+
Int256: "t.int256()",
|
|
56
|
+
UInt8: "t.uint8()",
|
|
57
|
+
UInt16: "t.uint16()",
|
|
58
|
+
UInt32: "t.uint32()",
|
|
59
|
+
UInt64: "t.uint64()",
|
|
60
|
+
UInt128: "t.uint128()",
|
|
61
|
+
UInt256: "t.uint256()",
|
|
62
|
+
Float32: "t.float32()",
|
|
63
|
+
Float64: "t.float64()",
|
|
64
|
+
Bool: "t.bool()",
|
|
65
|
+
Boolean: "t.bool()",
|
|
66
|
+
Date: "t.date()",
|
|
67
|
+
Date32: "t.date32()",
|
|
68
|
+
DateTime: "t.dateTime()",
|
|
69
|
+
JSON: "t.json()",
|
|
70
|
+
Object: "t.json()",
|
|
71
|
+
IPv4: "t.ipv4()",
|
|
72
|
+
IPv6: "t.ipv6()",
|
|
73
|
+
};
|
|
74
|
+
if (simpleTypeMap[chType]) {
|
|
75
|
+
return simpleTypeMap[chType];
|
|
76
|
+
}
|
|
77
|
+
// DateTime with timezone: DateTime('UTC')
|
|
78
|
+
const dtTzMatch = chType.match(/^DateTime\('([^']+)'\)$/);
|
|
79
|
+
if (dtTzMatch) {
|
|
80
|
+
return `t.dateTime("${dtTzMatch[1]}")`;
|
|
81
|
+
}
|
|
82
|
+
// DateTime64 with precision and optional timezone
|
|
83
|
+
const dt64Match = chType.match(/^DateTime64\((\d+)(?:,\s*'([^']+)')?\)$/);
|
|
84
|
+
if (dt64Match) {
|
|
85
|
+
const precision = dt64Match[1];
|
|
86
|
+
const tz = dt64Match[2];
|
|
87
|
+
if (tz) {
|
|
88
|
+
return `t.dateTime64(${precision}, "${tz}")`;
|
|
89
|
+
}
|
|
90
|
+
return `t.dateTime64(${precision})`;
|
|
91
|
+
}
|
|
92
|
+
// DateTime64 without precision (defaults to 3)
|
|
93
|
+
if (chType === "DateTime64") {
|
|
94
|
+
return "t.dateTime64(3)";
|
|
95
|
+
}
|
|
96
|
+
// FixedString(N)
|
|
97
|
+
const fixedMatch = chType.match(/^FixedString\((\d+)\)$/);
|
|
98
|
+
if (fixedMatch) {
|
|
99
|
+
return `t.fixedString(${fixedMatch[1]})`;
|
|
100
|
+
}
|
|
101
|
+
// Decimal(P, S) or Decimal(P)
|
|
102
|
+
const decMatch = chType.match(/^Decimal\((\d+)(?:,\s*(\d+))?\)$/);
|
|
103
|
+
if (decMatch) {
|
|
104
|
+
const precision = decMatch[1];
|
|
105
|
+
const scale = decMatch[2] ?? "0";
|
|
106
|
+
return `t.decimal(${precision}, ${scale})`;
|
|
107
|
+
}
|
|
108
|
+
// Decimal32, Decimal64, Decimal128, Decimal256 with scale
|
|
109
|
+
const decNMatch = chType.match(/^Decimal(32|64|128|256)\((\d+)\)$/);
|
|
110
|
+
if (decNMatch) {
|
|
111
|
+
const bits = decNMatch[1];
|
|
112
|
+
const scale = decNMatch[2];
|
|
113
|
+
const precisionMap = {
|
|
114
|
+
"32": 9,
|
|
115
|
+
"64": 18,
|
|
116
|
+
"128": 38,
|
|
117
|
+
"256": 76,
|
|
118
|
+
};
|
|
119
|
+
return `t.decimal(${precisionMap[bits]}, ${scale})`;
|
|
120
|
+
}
|
|
121
|
+
// Array(T)
|
|
122
|
+
const arrMatch = chType.match(/^Array\((.+)\)$/);
|
|
123
|
+
if (arrMatch) {
|
|
124
|
+
const innerType = clickhouseTypeToValidator(arrMatch[1]);
|
|
125
|
+
return `t.array(${innerType})`;
|
|
126
|
+
}
|
|
127
|
+
// Tuple(T1, T2, ...) - simplified handling
|
|
128
|
+
const tupleMatch = chType.match(/^Tuple\((.+)\)$/);
|
|
129
|
+
if (tupleMatch) {
|
|
130
|
+
// For complex tuples, we just use a JSON type
|
|
131
|
+
// TODO: Could parse and generate t.tuple() for simple cases
|
|
132
|
+
return `t.json() /* Tuple: ${chType} */`;
|
|
133
|
+
}
|
|
134
|
+
// Map(K, V)
|
|
135
|
+
const mapMatch = chType.match(/^Map\(([^,]+),\s*(.+)\)$/);
|
|
136
|
+
if (mapMatch) {
|
|
137
|
+
const keyType = clickhouseTypeToValidator(mapMatch[1]);
|
|
138
|
+
const valueType = clickhouseTypeToValidator(mapMatch[2]);
|
|
139
|
+
return `t.map(${keyType}, ${valueType})`;
|
|
140
|
+
}
|
|
141
|
+
// Enum8('a' = 1, 'b' = 2)
|
|
142
|
+
const enum8Match = chType.match(/^Enum8\((.+)\)$/);
|
|
143
|
+
if (enum8Match) {
|
|
144
|
+
const values = parseEnumValues(enum8Match[1]);
|
|
145
|
+
if (values.length > 0) {
|
|
146
|
+
return `t.enum8(${values.map((v) => `"${v}"`).join(", ")})`;
|
|
147
|
+
}
|
|
148
|
+
return `t.string() /* Enum8 */`;
|
|
149
|
+
}
|
|
150
|
+
// Enum16('a' = 1, 'b' = 2)
|
|
151
|
+
const enum16Match = chType.match(/^Enum16\((.+)\)$/);
|
|
152
|
+
if (enum16Match) {
|
|
153
|
+
const values = parseEnumValues(enum16Match[1]);
|
|
154
|
+
if (values.length > 0) {
|
|
155
|
+
return `t.enum16(${values.map((v) => `"${v}"`).join(", ")})`;
|
|
156
|
+
}
|
|
157
|
+
return `t.string() /* Enum16 */`;
|
|
158
|
+
}
|
|
159
|
+
// SimpleAggregateFunction(func, T)
|
|
160
|
+
const simpleAggMatch = chType.match(/^SimpleAggregateFunction\((\w+),\s*(.+)\)$/);
|
|
161
|
+
if (simpleAggMatch) {
|
|
162
|
+
const func = simpleAggMatch[1];
|
|
163
|
+
const innerType = clickhouseTypeToValidator(simpleAggMatch[2]);
|
|
164
|
+
return `t.simpleAggregateFunction("${func}", ${innerType})`;
|
|
165
|
+
}
|
|
166
|
+
// AggregateFunction(func, T)
|
|
167
|
+
const aggMatch = chType.match(/^AggregateFunction\((\w+),\s*(.+)\)$/);
|
|
168
|
+
if (aggMatch) {
|
|
169
|
+
const func = aggMatch[1];
|
|
170
|
+
const innerType = clickhouseTypeToValidator(aggMatch[2]);
|
|
171
|
+
return `t.aggregateFunction("${func}", ${innerType})`;
|
|
172
|
+
}
|
|
173
|
+
// Nested - treat as JSON
|
|
174
|
+
if (chType.startsWith("Nested(")) {
|
|
175
|
+
return `t.json() /* ${chType} */`;
|
|
176
|
+
}
|
|
177
|
+
// Fallback for unknown types
|
|
178
|
+
return `t.string() /* TODO: Unknown type: ${chType} */`;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Map a pipe parameter type to a p.* validator call
|
|
182
|
+
*/
|
|
183
|
+
export function paramTypeToValidator(paramType, defaultValue, required = true) {
|
|
184
|
+
// Normalize type
|
|
185
|
+
paramType = paramType.trim();
|
|
186
|
+
// Simple type mappings
|
|
187
|
+
const typeMap = {
|
|
188
|
+
String: "p.string()",
|
|
189
|
+
UUID: "p.uuid()",
|
|
190
|
+
Int8: "p.int8()",
|
|
191
|
+
Int16: "p.int16()",
|
|
192
|
+
Int32: "p.int32()",
|
|
193
|
+
Int64: "p.int64()",
|
|
194
|
+
UInt8: "p.uint8()",
|
|
195
|
+
UInt16: "p.uint16()",
|
|
196
|
+
UInt32: "p.uint32()",
|
|
197
|
+
UInt64: "p.uint64()",
|
|
198
|
+
Float32: "p.float32()",
|
|
199
|
+
Float64: "p.float64()",
|
|
200
|
+
Boolean: "p.boolean()",
|
|
201
|
+
Bool: "p.boolean()",
|
|
202
|
+
Date: "p.date()",
|
|
203
|
+
DateTime: "p.dateTime()",
|
|
204
|
+
DateTime64: "p.dateTime64()",
|
|
205
|
+
};
|
|
206
|
+
let validator = typeMap[paramType];
|
|
207
|
+
// Handle parameterized DateTime types
|
|
208
|
+
if (!validator) {
|
|
209
|
+
if (paramType.startsWith("DateTime64")) {
|
|
210
|
+
validator = "p.dateTime64()";
|
|
211
|
+
}
|
|
212
|
+
else if (paramType.startsWith("DateTime")) {
|
|
213
|
+
validator = "p.dateTime()";
|
|
214
|
+
}
|
|
215
|
+
else if (paramType.startsWith("Array")) {
|
|
216
|
+
// Array parameters - default to string array
|
|
217
|
+
validator = "p.array(p.string())";
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
// Default to string for unknown types
|
|
221
|
+
validator = "p.string()";
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
// Add optional with default if not required or has a default value
|
|
225
|
+
if (!required || defaultValue !== undefined) {
|
|
226
|
+
if (defaultValue !== undefined) {
|
|
227
|
+
const formattedDefault = typeof defaultValue === "string" ? `"${defaultValue}"` : defaultValue;
|
|
228
|
+
// Replace () with .optional(value)
|
|
229
|
+
validator = validator.replace(/\(\)$/, `().optional(${formattedDefault})`);
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
// Just make it optional without a default
|
|
233
|
+
validator = validator.replace(/\(\)$/, "().optional()");
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return validator;
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=type-mapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-mapper.js","sourceRoot":"","sources":["../../src/codegen/type-mapper.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,SAAS,eAAe,CAAC,WAAmB;IAC1C,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,KAAK,GAAG,sBAAsB,CAAC;IACrC,IAAI,KAAK,CAAC;IACV,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QAClD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,yBAAyB,CAAC,MAAc;IACtD,kBAAkB;IAClB,MAAM,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;IAEvB,0BAA0B;IAC1B,MAAM,aAAa,GAAG,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;IACzD,IAAI,aAAa,EAAE,CAAC;QAClB,MAAM,SAAS,GAAG,yBAAyB,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9D,OAAO,GAAG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ACH,CAAC;IAED,mEAAmE;IACnE,IAAI,CAAC,QAAQ,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAC5C,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;YAC/B,MAAM,gBAAgB,GACpB,OAAO,YAAY,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,YAAY,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC;YACxE,mCAAmC;YACnC,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,eAAe,gBAAgB,GAAG,CAAC,CAAC;QAC7E,CAAC;aAAM,CAAC;YACN,0CAA0C;YAC1C,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-mapper.test.d.ts","sourceRoot":"","sources":["../../src/codegen/type-mapper.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { clickhouseTypeToValidator, paramTypeToValidator } from "./type-mapper.js";
|
|
3
|
+
describe("clickhouseTypeToValidator", () => {
|
|
4
|
+
describe("simple types", () => {
|
|
5
|
+
it("maps String to t.string()", () => {
|
|
6
|
+
expect(clickhouseTypeToValidator("String")).toBe("t.string()");
|
|
7
|
+
});
|
|
8
|
+
it("maps UUID to t.uuid()", () => {
|
|
9
|
+
expect(clickhouseTypeToValidator("UUID")).toBe("t.uuid()");
|
|
10
|
+
});
|
|
11
|
+
it("maps integer types", () => {
|
|
12
|
+
expect(clickhouseTypeToValidator("Int8")).toBe("t.int8()");
|
|
13
|
+
expect(clickhouseTypeToValidator("Int16")).toBe("t.int16()");
|
|
14
|
+
expect(clickhouseTypeToValidator("Int32")).toBe("t.int32()");
|
|
15
|
+
expect(clickhouseTypeToValidator("Int64")).toBe("t.int64()");
|
|
16
|
+
expect(clickhouseTypeToValidator("Int128")).toBe("t.int128()");
|
|
17
|
+
expect(clickhouseTypeToValidator("Int256")).toBe("t.int256()");
|
|
18
|
+
});
|
|
19
|
+
it("maps unsigned integer types", () => {
|
|
20
|
+
expect(clickhouseTypeToValidator("UInt8")).toBe("t.uint8()");
|
|
21
|
+
expect(clickhouseTypeToValidator("UInt16")).toBe("t.uint16()");
|
|
22
|
+
expect(clickhouseTypeToValidator("UInt32")).toBe("t.uint32()");
|
|
23
|
+
expect(clickhouseTypeToValidator("UInt64")).toBe("t.uint64()");
|
|
24
|
+
expect(clickhouseTypeToValidator("UInt128")).toBe("t.uint128()");
|
|
25
|
+
expect(clickhouseTypeToValidator("UInt256")).toBe("t.uint256()");
|
|
26
|
+
});
|
|
27
|
+
it("maps float types", () => {
|
|
28
|
+
expect(clickhouseTypeToValidator("Float32")).toBe("t.float32()");
|
|
29
|
+
expect(clickhouseTypeToValidator("Float64")).toBe("t.float64()");
|
|
30
|
+
});
|
|
31
|
+
it("maps Bool to t.bool()", () => {
|
|
32
|
+
expect(clickhouseTypeToValidator("Bool")).toBe("t.bool()");
|
|
33
|
+
expect(clickhouseTypeToValidator("Boolean")).toBe("t.bool()");
|
|
34
|
+
});
|
|
35
|
+
it("maps date types", () => {
|
|
36
|
+
expect(clickhouseTypeToValidator("Date")).toBe("t.date()");
|
|
37
|
+
expect(clickhouseTypeToValidator("Date32")).toBe("t.date32()");
|
|
38
|
+
expect(clickhouseTypeToValidator("DateTime")).toBe("t.dateTime()");
|
|
39
|
+
});
|
|
40
|
+
it("maps JSON to t.json()", () => {
|
|
41
|
+
expect(clickhouseTypeToValidator("JSON")).toBe("t.json()");
|
|
42
|
+
});
|
|
43
|
+
it("maps IP types", () => {
|
|
44
|
+
expect(clickhouseTypeToValidator("IPv4")).toBe("t.ipv4()");
|
|
45
|
+
expect(clickhouseTypeToValidator("IPv6")).toBe("t.ipv6()");
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
describe("Nullable wrapper", () => {
|
|
49
|
+
it("adds .nullable() for Nullable(String)", () => {
|
|
50
|
+
expect(clickhouseTypeToValidator("Nullable(String)")).toBe("t.string().nullable()");
|
|
51
|
+
});
|
|
52
|
+
it("adds .nullable() for Nullable(Int32)", () => {
|
|
53
|
+
expect(clickhouseTypeToValidator("Nullable(Int32)")).toBe("t.int32().nullable()");
|
|
54
|
+
});
|
|
55
|
+
it("adds .nullable() for Nullable(DateTime)", () => {
|
|
56
|
+
expect(clickhouseTypeToValidator("Nullable(DateTime)")).toBe("t.dateTime().nullable()");
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
describe("LowCardinality wrapper", () => {
|
|
60
|
+
it("adds .lowCardinality() for LowCardinality(String)", () => {
|
|
61
|
+
expect(clickhouseTypeToValidator("LowCardinality(String)")).toBe("t.string().lowCardinality()");
|
|
62
|
+
});
|
|
63
|
+
it("handles LowCardinality(Nullable(String))", () => {
|
|
64
|
+
expect(clickhouseTypeToValidator("LowCardinality(Nullable(String))")).toBe("t.string().nullable().lowCardinality()");
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
describe("parameterized types", () => {
|
|
68
|
+
it("handles DateTime with timezone", () => {
|
|
69
|
+
expect(clickhouseTypeToValidator("DateTime('UTC')")).toBe('t.dateTime("UTC")');
|
|
70
|
+
expect(clickhouseTypeToValidator("DateTime('America/New_York')")).toBe('t.dateTime("America/New_York")');
|
|
71
|
+
});
|
|
72
|
+
it("handles DateTime64 with precision", () => {
|
|
73
|
+
expect(clickhouseTypeToValidator("DateTime64(3)")).toBe("t.dateTime64(3)");
|
|
74
|
+
expect(clickhouseTypeToValidator("DateTime64(6)")).toBe("t.dateTime64(6)");
|
|
75
|
+
});
|
|
76
|
+
it("handles DateTime64 with precision and timezone", () => {
|
|
77
|
+
expect(clickhouseTypeToValidator("DateTime64(3, 'UTC')")).toBe('t.dateTime64(3, "UTC")');
|
|
78
|
+
});
|
|
79
|
+
it("handles FixedString(N)", () => {
|
|
80
|
+
expect(clickhouseTypeToValidator("FixedString(10)")).toBe("t.fixedString(10)");
|
|
81
|
+
expect(clickhouseTypeToValidator("FixedString(255)")).toBe("t.fixedString(255)");
|
|
82
|
+
});
|
|
83
|
+
it("handles Decimal(P, S)", () => {
|
|
84
|
+
expect(clickhouseTypeToValidator("Decimal(10, 2)")).toBe("t.decimal(10, 2)");
|
|
85
|
+
expect(clickhouseTypeToValidator("Decimal(18, 4)")).toBe("t.decimal(18, 4)");
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
describe("complex types", () => {
|
|
89
|
+
it("handles Array(T)", () => {
|
|
90
|
+
expect(clickhouseTypeToValidator("Array(String)")).toBe("t.array(t.string())");
|
|
91
|
+
expect(clickhouseTypeToValidator("Array(Int32)")).toBe("t.array(t.int32())");
|
|
92
|
+
});
|
|
93
|
+
it("handles nested Array types", () => {
|
|
94
|
+
expect(clickhouseTypeToValidator("Array(Array(String))")).toBe("t.array(t.array(t.string()))");
|
|
95
|
+
});
|
|
96
|
+
it("handles Array with Nullable elements", () => {
|
|
97
|
+
expect(clickhouseTypeToValidator("Array(Nullable(String))")).toBe("t.array(t.string().nullable())");
|
|
98
|
+
});
|
|
99
|
+
it("handles Map(K, V)", () => {
|
|
100
|
+
expect(clickhouseTypeToValidator("Map(String, Int32)")).toBe("t.map(t.string(), t.int32())");
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
describe("enum types", () => {
|
|
104
|
+
it("handles Enum8", () => {
|
|
105
|
+
expect(clickhouseTypeToValidator("Enum8('a' = 1, 'b' = 2)")).toBe('t.enum8("a", "b")');
|
|
106
|
+
});
|
|
107
|
+
it("handles Enum16", () => {
|
|
108
|
+
expect(clickhouseTypeToValidator("Enum16('pending' = 1, 'active' = 2, 'done' = 3)")).toBe('t.enum16("pending", "active", "done")');
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
describe("aggregate function types", () => {
|
|
112
|
+
it("handles SimpleAggregateFunction", () => {
|
|
113
|
+
expect(clickhouseTypeToValidator("SimpleAggregateFunction(sum, UInt64)")).toBe('t.simpleAggregateFunction("sum", t.uint64())');
|
|
114
|
+
});
|
|
115
|
+
it("handles AggregateFunction", () => {
|
|
116
|
+
expect(clickhouseTypeToValidator("AggregateFunction(uniq, String)")).toBe('t.aggregateFunction("uniq", t.string())');
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
describe("unknown types", () => {
|
|
120
|
+
it("returns string with TODO comment for unknown types", () => {
|
|
121
|
+
expect(clickhouseTypeToValidator("UnknownType")).toBe("t.string() /* TODO: Unknown type: UnknownType */");
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
describe("paramTypeToValidator", () => {
|
|
126
|
+
describe("simple types", () => {
|
|
127
|
+
it("maps String to p.string()", () => {
|
|
128
|
+
expect(paramTypeToValidator("String")).toBe("p.string()");
|
|
129
|
+
});
|
|
130
|
+
it("maps Int32 to p.int32()", () => {
|
|
131
|
+
expect(paramTypeToValidator("Int32")).toBe("p.int32()");
|
|
132
|
+
});
|
|
133
|
+
it("maps DateTime to p.dateTime()", () => {
|
|
134
|
+
expect(paramTypeToValidator("DateTime")).toBe("p.dateTime()");
|
|
135
|
+
});
|
|
136
|
+
it("maps Boolean to p.boolean()", () => {
|
|
137
|
+
expect(paramTypeToValidator("Boolean")).toBe("p.boolean()");
|
|
138
|
+
expect(paramTypeToValidator("Bool")).toBe("p.boolean()");
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
describe("optional parameters", () => {
|
|
142
|
+
it("adds .optional() for non-required params", () => {
|
|
143
|
+
expect(paramTypeToValidator("String", undefined, false)).toBe("p.string().optional()");
|
|
144
|
+
});
|
|
145
|
+
it("adds .optional(default) for params with defaults", () => {
|
|
146
|
+
expect(paramTypeToValidator("Int32", 10)).toBe("p.int32().optional(10)");
|
|
147
|
+
expect(paramTypeToValidator("String", "test")).toBe('p.string().optional("test")');
|
|
148
|
+
});
|
|
149
|
+
it("adds .optional(default) even for required params with defaults", () => {
|
|
150
|
+
expect(paramTypeToValidator("Int32", 5, true)).toBe("p.int32().optional(5)");
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
describe("DateTime variants", () => {
|
|
154
|
+
it("handles DateTime64", () => {
|
|
155
|
+
expect(paramTypeToValidator("DateTime64")).toBe("p.dateTime64()");
|
|
156
|
+
});
|
|
157
|
+
it("handles DateTime with timezone", () => {
|
|
158
|
+
expect(paramTypeToValidator("DateTime('UTC')")).toBe("p.dateTime()");
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
describe("unknown types", () => {
|
|
162
|
+
it("defaults to p.string() for unknown types", () => {
|
|
163
|
+
expect(paramTypeToValidator("UnknownType")).toBe("p.string()");
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
//# sourceMappingURL=type-mapper.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-mapper.test.js","sourceRoot":"","sources":["../../src/codegen/type-mapper.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAEnF,QAAQ,CAAC,2BAA2B,EAAE,GAAG,EAAE;IACzC,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;QAC5B,EAAE,CAAC,2BAA2B,EAAE,GAAG,EAAE;YACnC,MAAM,CAAC,yBAAyB,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACjE,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,uBAAuB,EAAE,GAAG,EAAE;YAC/B,MAAM,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC7D,CAAC,CAAC,CAAC;QAEH,EAAE,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,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for code generation
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Convert a string to camelCase
|
|
6
|
+
* Handles snake_case and kebab-case
|
|
7
|
+
*/
|
|
8
|
+
export declare function toCamelCase(str: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Convert a string to PascalCase
|
|
11
|
+
* Handles snake_case and kebab-case
|
|
12
|
+
*/
|
|
13
|
+
export declare function toPascalCase(str: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Escape a string for use in JavaScript/TypeScript code
|
|
16
|
+
*/
|
|
17
|
+
export declare function escapeString(str: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Parse a sorting key string into an array
|
|
20
|
+
* Handles comma-separated values and quoted identifiers
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseSortingKey(sortingKey?: string): string[];
|
|
23
|
+
/**
|
|
24
|
+
* Generate engine code from engine info
|
|
25
|
+
*/
|
|
26
|
+
export declare function generateEngineCode(engine: {
|
|
27
|
+
type: string;
|
|
28
|
+
sorting_key?: string;
|
|
29
|
+
partition_key?: string;
|
|
30
|
+
primary_key?: string;
|
|
31
|
+
ttl?: string;
|
|
32
|
+
ver?: string;
|
|
33
|
+
sign?: string;
|
|
34
|
+
version?: string;
|
|
35
|
+
summing_columns?: string;
|
|
36
|
+
}): string;
|
|
37
|
+
/**
|
|
38
|
+
* Indent a multi-line string
|
|
39
|
+
*/
|
|
40
|
+
export declare function indent(str: string, spaces: number): string;
|
|
41
|
+
/**
|
|
42
|
+
* Format SQL for inclusion in template literal
|
|
43
|
+
* Preserves newlines and indentation but escapes backticks
|
|
44
|
+
*/
|
|
45
|
+
export declare function formatSqlForTemplate(sql: string): string;
|
|
46
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/codegen/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAsB/C;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGhD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAOhD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAU7D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,GAAG,MAAM,CAwET;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAM1D;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAExD"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for code generation
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Convert a string to camelCase
|
|
6
|
+
* Handles snake_case and kebab-case
|
|
7
|
+
*/
|
|
8
|
+
export function toCamelCase(str) {
|
|
9
|
+
// Handle reserved keywords
|
|
10
|
+
const reserved = new Set([
|
|
11
|
+
"break", "case", "catch", "class", "const", "continue", "debugger",
|
|
12
|
+
"default", "delete", "do", "else", "enum", "export", "extends",
|
|
13
|
+
"false", "finally", "for", "function", "if", "import", "in",
|
|
14
|
+
"instanceof", "new", "null", "return", "super", "switch", "this",
|
|
15
|
+
"throw", "true", "try", "typeof", "undefined", "var", "void",
|
|
16
|
+
"while", "with", "yield", "let", "static", "implements", "interface",
|
|
17
|
+
"package", "private", "protected", "public", "await", "async",
|
|
18
|
+
]);
|
|
19
|
+
const result = str
|
|
20
|
+
.replace(/[-_](.)/g, (_, char) => char.toUpperCase())
|
|
21
|
+
.replace(/^[A-Z]/, (char) => char.toLowerCase());
|
|
22
|
+
// If the result is a reserved keyword or starts with a number, prefix with underscore
|
|
23
|
+
if (reserved.has(result) || /^\d/.test(result)) {
|
|
24
|
+
return `_${result}`;
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Convert a string to PascalCase
|
|
30
|
+
* Handles snake_case and kebab-case
|
|
31
|
+
*/
|
|
32
|
+
export function toPascalCase(str) {
|
|
33
|
+
const camel = toCamelCase(str);
|
|
34
|
+
return camel.charAt(0).toUpperCase() + camel.slice(1);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Escape a string for use in JavaScript/TypeScript code
|
|
38
|
+
*/
|
|
39
|
+
export function escapeString(str) {
|
|
40
|
+
return str
|
|
41
|
+
.replace(/\\/g, "\\\\")
|
|
42
|
+
.replace(/"/g, '\\"')
|
|
43
|
+
.replace(/\n/g, "\\n")
|
|
44
|
+
.replace(/\r/g, "\\r")
|
|
45
|
+
.replace(/\t/g, "\\t");
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Parse a sorting key string into an array
|
|
49
|
+
* Handles comma-separated values and quoted identifiers
|
|
50
|
+
*/
|
|
51
|
+
export function parseSortingKey(sortingKey) {
|
|
52
|
+
if (!sortingKey) {
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
// Split by comma, trim whitespace
|
|
56
|
+
return sortingKey
|
|
57
|
+
.split(",")
|
|
58
|
+
.map((s) => s.trim())
|
|
59
|
+
.filter((s) => s.length > 0);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Generate engine code from engine info
|
|
63
|
+
*/
|
|
64
|
+
export function generateEngineCode(engine) {
|
|
65
|
+
const sortingKey = parseSortingKey(engine.sorting_key);
|
|
66
|
+
// Build options object
|
|
67
|
+
const options = [];
|
|
68
|
+
// Sorting key is required for all MergeTree engines
|
|
69
|
+
if (sortingKey.length === 1) {
|
|
70
|
+
options.push(`sortingKey: "${sortingKey[0]}"`);
|
|
71
|
+
}
|
|
72
|
+
else if (sortingKey.length > 1) {
|
|
73
|
+
options.push(`sortingKey: [${sortingKey.map((k) => `"${k}"`).join(", ")}]`);
|
|
74
|
+
}
|
|
75
|
+
// Optional fields
|
|
76
|
+
if (engine.partition_key) {
|
|
77
|
+
options.push(`partitionKey: "${escapeString(engine.partition_key)}"`);
|
|
78
|
+
}
|
|
79
|
+
if (engine.primary_key && engine.primary_key !== engine.sorting_key) {
|
|
80
|
+
const primaryKey = parseSortingKey(engine.primary_key);
|
|
81
|
+
if (primaryKey.length === 1) {
|
|
82
|
+
options.push(`primaryKey: "${primaryKey[0]}"`);
|
|
83
|
+
}
|
|
84
|
+
else if (primaryKey.length > 1) {
|
|
85
|
+
options.push(`primaryKey: [${primaryKey.map((k) => `"${k}"`).join(", ")}]`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (engine.ttl) {
|
|
89
|
+
options.push(`ttl: "${escapeString(engine.ttl)}"`);
|
|
90
|
+
}
|
|
91
|
+
// Engine-specific options
|
|
92
|
+
if (engine.type === "ReplacingMergeTree" && engine.ver) {
|
|
93
|
+
options.push(`ver: "${engine.ver}"`);
|
|
94
|
+
}
|
|
95
|
+
if ((engine.type === "CollapsingMergeTree" ||
|
|
96
|
+
engine.type === "VersionedCollapsingMergeTree") &&
|
|
97
|
+
engine.sign) {
|
|
98
|
+
options.push(`sign: "${engine.sign}"`);
|
|
99
|
+
}
|
|
100
|
+
if (engine.type === "VersionedCollapsingMergeTree" && engine.version) {
|
|
101
|
+
options.push(`version: "${engine.version}"`);
|
|
102
|
+
}
|
|
103
|
+
if (engine.type === "SummingMergeTree" && engine.summing_columns) {
|
|
104
|
+
const columns = parseSortingKey(engine.summing_columns);
|
|
105
|
+
if (columns.length > 0) {
|
|
106
|
+
options.push(`columns: [${columns.map((c) => `"${c}"`).join(", ")}]`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// Map engine type to function name
|
|
110
|
+
const engineFunctionMap = {
|
|
111
|
+
MergeTree: "engine.mergeTree",
|
|
112
|
+
ReplacingMergeTree: "engine.replacingMergeTree",
|
|
113
|
+
SummingMergeTree: "engine.summingMergeTree",
|
|
114
|
+
AggregatingMergeTree: "engine.aggregatingMergeTree",
|
|
115
|
+
CollapsingMergeTree: "engine.collapsingMergeTree",
|
|
116
|
+
VersionedCollapsingMergeTree: "engine.versionedCollapsingMergeTree",
|
|
117
|
+
};
|
|
118
|
+
const engineFunc = engineFunctionMap[engine.type] ?? "engine.mergeTree";
|
|
119
|
+
if (options.length === 0) {
|
|
120
|
+
return `${engineFunc}({ sortingKey: [] })`;
|
|
121
|
+
}
|
|
122
|
+
return `${engineFunc}({\n ${options.join(",\n ")},\n })`;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Indent a multi-line string
|
|
126
|
+
*/
|
|
127
|
+
export function indent(str, spaces) {
|
|
128
|
+
const prefix = " ".repeat(spaces);
|
|
129
|
+
return str
|
|
130
|
+
.split("\n")
|
|
131
|
+
.map((line) => (line.trim() ? prefix + line : line))
|
|
132
|
+
.join("\n");
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Format SQL for inclusion in template literal
|
|
136
|
+
* Preserves newlines and indentation but escapes backticks
|
|
137
|
+
*/
|
|
138
|
+
export function formatSqlForTemplate(sql) {
|
|
139
|
+
return sql.replace(/`/g, "\\`").replace(/\${/g, "\\${");
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=utils.js.map
|