@bayoudhi/moose-lib-serverless 0.2.0 → 0.3.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.
- package/README.md +57 -0
- package/dist/compilerPlugin.js +1644 -0
- package/dist/index.d.mts +128 -141
- package/dist/index.d.ts +128 -141
- package/dist/index.js +673 -536
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +673 -536
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -4
|
@@ -0,0 +1,1644 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
4
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// stub-native:@514labs/kafka-javascript
|
|
8
|
+
var require_kafka_javascript = __commonJS({
|
|
9
|
+
"stub-native:@514labs/kafka-javascript"(exports2, module2) {
|
|
10
|
+
"use strict";
|
|
11
|
+
function createDeepProxy() {
|
|
12
|
+
var handler = {
|
|
13
|
+
get: function(_, prop) {
|
|
14
|
+
if (prop === "__esModule") return true;
|
|
15
|
+
if (prop === "default") return proxy;
|
|
16
|
+
if (typeof prop === "symbol") return void 0;
|
|
17
|
+
return proxy;
|
|
18
|
+
},
|
|
19
|
+
apply: function() {
|
|
20
|
+
return proxy;
|
|
21
|
+
},
|
|
22
|
+
construct: function() {
|
|
23
|
+
return proxy;
|
|
24
|
+
},
|
|
25
|
+
ownKeys: function() {
|
|
26
|
+
return ["length", "name", "prototype"];
|
|
27
|
+
},
|
|
28
|
+
getOwnPropertyDescriptor: function(target, prop) {
|
|
29
|
+
if (prop === "length" || prop === "name" || prop === "prototype") {
|
|
30
|
+
return Object.getOwnPropertyDescriptor(target, prop);
|
|
31
|
+
}
|
|
32
|
+
return void 0;
|
|
33
|
+
},
|
|
34
|
+
getPrototypeOf: function() {
|
|
35
|
+
return proxy;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var proxy = new Proxy(function() {
|
|
39
|
+
}, handler);
|
|
40
|
+
return proxy;
|
|
41
|
+
}
|
|
42
|
+
module2.exports = createDeepProxy();
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// src/compilerPlugin.ts
|
|
47
|
+
var __create = Object.create;
|
|
48
|
+
var __defProp = Object.defineProperty;
|
|
49
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
50
|
+
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
51
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
52
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
53
|
+
var __export = (target, all) => {
|
|
54
|
+
for (var name in all)
|
|
55
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
56
|
+
};
|
|
57
|
+
var __copyProps = (to, from, except, desc) => {
|
|
58
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
59
|
+
for (let key of __getOwnPropNames2(from))
|
|
60
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
61
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
62
|
+
}
|
|
63
|
+
return to;
|
|
64
|
+
};
|
|
65
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
66
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
67
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
68
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
69
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
70
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
71
|
+
mod
|
|
72
|
+
));
|
|
73
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
74
|
+
var compilerPlugin_exports = {};
|
|
75
|
+
__export(compilerPlugin_exports, {
|
|
76
|
+
default: () => compilerPlugin_default
|
|
77
|
+
});
|
|
78
|
+
module.exports = __toCommonJS(compilerPlugin_exports);
|
|
79
|
+
var import_typescript7 = __toESM(require("typescript"));
|
|
80
|
+
var import_typescript = __toESM(require("typescript"));
|
|
81
|
+
var import_path = __toESM(require("path"));
|
|
82
|
+
var import_process = __toESM(require("process"));
|
|
83
|
+
var import_node_fs = __toESM(require("fs"));
|
|
84
|
+
var isMooseFile = (sourceFile) => {
|
|
85
|
+
const location = import_path.default.resolve(sourceFile.fileName);
|
|
86
|
+
return location.includes("@514labs/moose-lib") || location.includes("@bayoudhi/moose-lib-serverless") || // workaround for e2e test
|
|
87
|
+
location.includes("packages/ts-moose-lib/dist") || // support local development with symlinked packages
|
|
88
|
+
location.includes("packages/ts-moose-lib/src");
|
|
89
|
+
};
|
|
90
|
+
var createTransformer = (transform2) => (program, _configOrHost, _extrasOrConfig, maybeProgramExtras) => {
|
|
91
|
+
if (maybeProgramExtras !== void 0) {
|
|
92
|
+
throw new Error(
|
|
93
|
+
`[moose] Your tsconfig.json has "transformProgram": true for the moose plugin, but this version requires "transformProgram": false (or remove it entirely).
|
|
94
|
+
|
|
95
|
+
Update your tsconfig.json plugins section:
|
|
96
|
+
"plugins": [
|
|
97
|
+
{ "transform": "./node_modules/@514labs/moose-lib/dist/compilerPlugin.js" },
|
|
98
|
+
{ "transform": "typia/lib/transform" }
|
|
99
|
+
]
|
|
100
|
+
|
|
101
|
+
Also remove "isolatedModules": true if present (incompatible with type-dependent transformations).`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
const transformFunction = transform2(program.getTypeChecker(), program);
|
|
105
|
+
return (context) => {
|
|
106
|
+
return (sourceFile) => {
|
|
107
|
+
const cwd = import_process.default.cwd();
|
|
108
|
+
if (sourceFile.isDeclarationFile || sourceFile.fileName.includes("/node_modules/")) {
|
|
109
|
+
return sourceFile;
|
|
110
|
+
}
|
|
111
|
+
if (sourceFile.fileName.startsWith("/") && !sourceFile.fileName.startsWith(cwd)) {
|
|
112
|
+
return sourceFile;
|
|
113
|
+
}
|
|
114
|
+
const result = transformFunction(context)(sourceFile);
|
|
115
|
+
try {
|
|
116
|
+
const printer = import_typescript.default.createPrinter();
|
|
117
|
+
const newFile = printer.printFile(result);
|
|
118
|
+
const fileName = sourceFile.fileName.split("/").pop() || sourceFile.fileName;
|
|
119
|
+
const dir = `${import_process.default.cwd()}/.moose/api-compile-step/`;
|
|
120
|
+
import_node_fs.default.mkdirSync(dir, { recursive: true });
|
|
121
|
+
import_node_fs.default.writeFileSync(`${dir}/${fileName}`, newFile);
|
|
122
|
+
} catch (_e) {
|
|
123
|
+
}
|
|
124
|
+
return result;
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
var avoidTypiaNameClash = "____moose____typia";
|
|
129
|
+
var import_typescript5 = __toESM(require("typescript"));
|
|
130
|
+
var import_typescript3 = __toESM(require("typescript"));
|
|
131
|
+
var import_typescript2 = __toESM(require("typescript"));
|
|
132
|
+
var UnknownType = class extends Error {
|
|
133
|
+
t;
|
|
134
|
+
fieldName;
|
|
135
|
+
typeName;
|
|
136
|
+
constructor(t, fieldName, typeName) {
|
|
137
|
+
super();
|
|
138
|
+
this.t = t;
|
|
139
|
+
this.fieldName = fieldName;
|
|
140
|
+
this.typeName = typeName;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
var NullType = class extends Error {
|
|
144
|
+
fieldName;
|
|
145
|
+
typeName;
|
|
146
|
+
constructor(fieldName, typeName) {
|
|
147
|
+
super();
|
|
148
|
+
this.fieldName = fieldName;
|
|
149
|
+
this.typeName = typeName;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
var UnsupportedEnum = class extends Error {
|
|
153
|
+
enumName;
|
|
154
|
+
constructor(enumName) {
|
|
155
|
+
super();
|
|
156
|
+
this.enumName = enumName;
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
var UnsupportedFeature = class extends Error {
|
|
160
|
+
featureName;
|
|
161
|
+
constructor(featureName) {
|
|
162
|
+
super();
|
|
163
|
+
this.featureName = featureName;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
var IndexType = class extends Error {
|
|
167
|
+
typeName;
|
|
168
|
+
indexSignatures;
|
|
169
|
+
constructor(typeName, indexSignatures) {
|
|
170
|
+
const explanation = "Index signatures (e.g. [key: string]: value) are not supported in data models.";
|
|
171
|
+
const suggestion = "Consider splitting this into separate types or using a single Record<K, V> type.";
|
|
172
|
+
const signatures = `Found index signatures: ${indexSignatures.join(", ")}`;
|
|
173
|
+
super(
|
|
174
|
+
`${explanation}
|
|
175
|
+
|
|
176
|
+
Type: ${typeName}
|
|
177
|
+
|
|
178
|
+
${signatures}
|
|
179
|
+
|
|
180
|
+
Suggestion: ${suggestion}`
|
|
181
|
+
);
|
|
182
|
+
this.typeName = typeName;
|
|
183
|
+
this.indexSignatures = indexSignatures;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
var isEnum = (t) => !!(t.getFlags() & import_typescript2.default.TypeFlags.EnumLiteral);
|
|
187
|
+
var enumConvert = (enumType) => {
|
|
188
|
+
const name = enumType.symbol.name;
|
|
189
|
+
const values = enumType.isUnion() ? (
|
|
190
|
+
// an enum is the union of the values
|
|
191
|
+
enumType.types
|
|
192
|
+
) : [enumType];
|
|
193
|
+
const allStrings = values.every((v) => v.isStringLiteral());
|
|
194
|
+
const allIntegers = values.every(
|
|
195
|
+
(v) => v.isNumberLiteral() && Number.isInteger(v.value)
|
|
196
|
+
);
|
|
197
|
+
if (!allIntegers && !allStrings) {
|
|
198
|
+
throw new UnsupportedEnum(name);
|
|
199
|
+
}
|
|
200
|
+
const enumMember = allStrings ? values.map((v) => ({
|
|
201
|
+
name: v.symbol.name,
|
|
202
|
+
value: { String: v.value }
|
|
203
|
+
})) : values.map((v) => ({
|
|
204
|
+
name: v.symbol.name,
|
|
205
|
+
value: { Int: v.value }
|
|
206
|
+
}));
|
|
207
|
+
return { name, values: enumMember };
|
|
208
|
+
};
|
|
209
|
+
var DecimalRegex = "^-?\\d+(\\.\\d+)?$";
|
|
210
|
+
var STRING_DATE_ANNOTATION = "stringDate";
|
|
211
|
+
var dateType = (checker) => checker.getTypeOfSymbol(
|
|
212
|
+
checker.resolveName("Date", void 0, import_typescript3.SymbolFlags.Type, false)
|
|
213
|
+
).getConstructSignatures()[0].getReturnType();
|
|
214
|
+
var throwUnknownType = (t, fieldName, typeName) => {
|
|
215
|
+
throw new UnknownType(t, fieldName, typeName);
|
|
216
|
+
};
|
|
217
|
+
var throwNullType = (fieldName, typeName) => {
|
|
218
|
+
throw new NullType(fieldName, typeName);
|
|
219
|
+
};
|
|
220
|
+
var throwIndexTypeError = (t, checker) => {
|
|
221
|
+
const interfaceName = t.symbol?.name || "unknown type";
|
|
222
|
+
const indexInfos = checker.getIndexInfosOfType(t);
|
|
223
|
+
const signatures = indexInfos.map((info) => {
|
|
224
|
+
const keyType = checker.typeToString(info.keyType);
|
|
225
|
+
const valueType = checker.typeToString(info.type);
|
|
226
|
+
return `[${keyType}]: ${valueType}`;
|
|
227
|
+
});
|
|
228
|
+
throw new IndexType(interfaceName, signatures);
|
|
229
|
+
};
|
|
230
|
+
var getPropertyDeep = (t, name) => {
|
|
231
|
+
const direct = t.getProperty(name);
|
|
232
|
+
if (direct !== void 0) return direct;
|
|
233
|
+
if (t.isIntersection()) {
|
|
234
|
+
for (const sub of t.types) {
|
|
235
|
+
const found = getPropertyDeep(sub, name);
|
|
236
|
+
if (found) return found;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return void 0;
|
|
240
|
+
};
|
|
241
|
+
var toArrayType = ([elementNullable, _, elementType]) => {
|
|
242
|
+
return {
|
|
243
|
+
elementNullable,
|
|
244
|
+
elementType
|
|
245
|
+
};
|
|
246
|
+
};
|
|
247
|
+
var isNumberType = (t, checker) => {
|
|
248
|
+
return checker.isTypeAssignableTo(t, checker.getNumberType());
|
|
249
|
+
};
|
|
250
|
+
var handleAggregated = (t, checker, fieldName, typeName) => {
|
|
251
|
+
const functionSymbol = t.getProperty("_aggregationFunction");
|
|
252
|
+
const argsTypesSymbol = t.getProperty("_argTypes");
|
|
253
|
+
if (functionSymbol === void 0 || argsTypesSymbol === void 0) {
|
|
254
|
+
return void 0;
|
|
255
|
+
}
|
|
256
|
+
const functionStringLiteral = checker.getNonNullableType(
|
|
257
|
+
checker.getTypeOfSymbol(functionSymbol)
|
|
258
|
+
);
|
|
259
|
+
const types = checker.getNonNullableType(
|
|
260
|
+
checker.getTypeOfSymbol(argsTypesSymbol)
|
|
261
|
+
);
|
|
262
|
+
if (functionStringLiteral.isStringLiteral() && checker.isTupleType(types)) {
|
|
263
|
+
const argumentTypes = (types.typeArguments || []).map(
|
|
264
|
+
(argT) => {
|
|
265
|
+
return tsTypeToDataType(argT, checker, fieldName, typeName, false)[2];
|
|
266
|
+
}
|
|
267
|
+
);
|
|
268
|
+
return { functionName: functionStringLiteral.value, argumentTypes };
|
|
269
|
+
} else {
|
|
270
|
+
console.log(
|
|
271
|
+
"[CompilerPlugin] Unexpected type inside Aggregated",
|
|
272
|
+
functionStringLiteral
|
|
273
|
+
);
|
|
274
|
+
return void 0;
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
var getTaggedType = (t, checker, propertyName) => {
|
|
278
|
+
const nonNull = t.getNonNullableType();
|
|
279
|
+
const ttlSymbol = nonNull.getProperty(propertyName);
|
|
280
|
+
if (ttlSymbol === void 0) return null;
|
|
281
|
+
return checker.getNonNullableType(checker.getTypeOfSymbol(ttlSymbol));
|
|
282
|
+
};
|
|
283
|
+
var getJsonMappedType = (t, checker) => {
|
|
284
|
+
const mappingSymbol = getPropertyDeep(t, "_clickhouse_mapped_type");
|
|
285
|
+
if (mappingSymbol === void 0) return null;
|
|
286
|
+
const mappedType = checker.getNonNullableType(
|
|
287
|
+
checker.getTypeOfSymbol(mappingSymbol)
|
|
288
|
+
);
|
|
289
|
+
if (!mappedType.isStringLiteral() || mappedType.value !== "JSON") {
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
let maxDynamicPaths = void 0;
|
|
293
|
+
let maxDynamicTypes = void 0;
|
|
294
|
+
let skipPaths = [];
|
|
295
|
+
let skipRegexes = [];
|
|
296
|
+
const settingsSymbol = getPropertyDeep(t, "_clickhouse_json_settings");
|
|
297
|
+
if (settingsSymbol !== void 0) {
|
|
298
|
+
const settingsType = checker.getNonNullableType(
|
|
299
|
+
checker.getTypeOfSymbol(settingsSymbol)
|
|
300
|
+
);
|
|
301
|
+
const maxPathsSymbol = getPropertyDeep(settingsType, "maxDynamicPaths");
|
|
302
|
+
if (maxPathsSymbol !== void 0) {
|
|
303
|
+
const maxPathsType = checker.getNonNullableType(
|
|
304
|
+
checker.getTypeOfSymbol(maxPathsSymbol)
|
|
305
|
+
);
|
|
306
|
+
if (maxPathsType.isNumberLiteral()) {
|
|
307
|
+
maxDynamicPaths = maxPathsType.value;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
const maxTypesSymbol = getPropertyDeep(settingsType, "maxDynamicTypes");
|
|
311
|
+
if (maxTypesSymbol !== void 0) {
|
|
312
|
+
const maxTypesType = checker.getNonNullableType(
|
|
313
|
+
checker.getTypeOfSymbol(maxTypesSymbol)
|
|
314
|
+
);
|
|
315
|
+
if (maxTypesType.isNumberLiteral()) {
|
|
316
|
+
maxDynamicTypes = maxTypesType.value;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
const skipPathsSymbol = getPropertyDeep(settingsType, "skipPaths");
|
|
320
|
+
if (skipPathsSymbol !== void 0) {
|
|
321
|
+
const skipPathsType = checker.getNonNullableType(
|
|
322
|
+
checker.getTypeOfSymbol(skipPathsSymbol)
|
|
323
|
+
);
|
|
324
|
+
if (checker.isTupleType(skipPathsType)) {
|
|
325
|
+
const tuple = skipPathsType;
|
|
326
|
+
skipPaths = (tuple.typeArguments || []).filter((t2) => t2.isStringLiteral()).map((t2) => t2.value);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
const skipRegexesSymbol = getPropertyDeep(settingsType, "skipRegexes");
|
|
330
|
+
if (skipRegexesSymbol !== void 0) {
|
|
331
|
+
const skipRegexesType = checker.getNonNullableType(
|
|
332
|
+
checker.getTypeOfSymbol(skipRegexesSymbol)
|
|
333
|
+
);
|
|
334
|
+
if (checker.isTupleType(skipRegexesType)) {
|
|
335
|
+
const tuple = skipRegexesType;
|
|
336
|
+
skipRegexes = (tuple.typeArguments || []).filter((t2) => t2.isStringLiteral()).map((t2) => t2.value);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
let base = t.getNonNullableType();
|
|
341
|
+
if (base.isIntersection()) {
|
|
342
|
+
const candidates = base.types.filter((sub) => {
|
|
343
|
+
const m = getPropertyDeep(sub, "_clickhouse_mapped_type");
|
|
344
|
+
if (!m) return true;
|
|
345
|
+
const mt = checker.getNonNullableType(checker.getTypeOfSymbol(m));
|
|
346
|
+
return !(mt.isStringLiteral() && mt.value === "JSON");
|
|
347
|
+
});
|
|
348
|
+
if (candidates.length > 0) base = candidates[0];
|
|
349
|
+
}
|
|
350
|
+
let typedPaths = [];
|
|
351
|
+
try {
|
|
352
|
+
const cols = toColumns(base, checker);
|
|
353
|
+
typedPaths = cols.map((c) => [c.name, c.data_type]);
|
|
354
|
+
} catch (_) {
|
|
355
|
+
typedPaths = [];
|
|
356
|
+
}
|
|
357
|
+
const hasAnyOption = typeof maxDynamicPaths === "number" || typeof maxDynamicTypes === "number" || typedPaths.length > 0 || skipPaths.length > 0 || skipRegexes.length > 0;
|
|
358
|
+
if (!hasAnyOption) return "Json";
|
|
359
|
+
const result = {
|
|
360
|
+
typed_paths: typedPaths,
|
|
361
|
+
skip_paths: skipPaths,
|
|
362
|
+
skip_regexps: skipRegexes
|
|
363
|
+
};
|
|
364
|
+
if (typeof maxDynamicPaths === "number") {
|
|
365
|
+
result.max_dynamic_paths = maxDynamicPaths;
|
|
366
|
+
}
|
|
367
|
+
if (typeof maxDynamicTypes === "number") {
|
|
368
|
+
result.max_dynamic_types = maxDynamicTypes;
|
|
369
|
+
}
|
|
370
|
+
return result;
|
|
371
|
+
};
|
|
372
|
+
var handleSimpleAggregated = (t, checker, fieldName, typeName) => {
|
|
373
|
+
const functionSymbol = t.getProperty("_simpleAggregationFunction");
|
|
374
|
+
const argTypeSymbol = t.getProperty("_argType");
|
|
375
|
+
if (functionSymbol === void 0 || argTypeSymbol === void 0) {
|
|
376
|
+
return void 0;
|
|
377
|
+
}
|
|
378
|
+
const functionStringLiteral = checker.getNonNullableType(
|
|
379
|
+
checker.getTypeOfSymbol(functionSymbol)
|
|
380
|
+
);
|
|
381
|
+
const argType = checker.getNonNullableType(
|
|
382
|
+
checker.getTypeOfSymbol(argTypeSymbol)
|
|
383
|
+
);
|
|
384
|
+
if (functionStringLiteral.isStringLiteral()) {
|
|
385
|
+
const argumentType = tsTypeToDataType(
|
|
386
|
+
argType,
|
|
387
|
+
checker,
|
|
388
|
+
fieldName,
|
|
389
|
+
typeName,
|
|
390
|
+
false
|
|
391
|
+
)[2];
|
|
392
|
+
return { functionName: functionStringLiteral.value, argumentType };
|
|
393
|
+
} else {
|
|
394
|
+
console.log(
|
|
395
|
+
"[CompilerPlugin] Unexpected type inside SimpleAggregated",
|
|
396
|
+
functionStringLiteral
|
|
397
|
+
);
|
|
398
|
+
return void 0;
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
var handleDefault = (t, checker) => {
|
|
402
|
+
const defaultType = getTaggedType(t, checker, "_clickhouse_default");
|
|
403
|
+
if (defaultType === null) {
|
|
404
|
+
return null;
|
|
405
|
+
}
|
|
406
|
+
if (!defaultType.isStringLiteral()) {
|
|
407
|
+
throw new UnsupportedFeature(
|
|
408
|
+
'ClickHouseDefault must use a string literal, e.g. ClickHouseDefault<"now()">'
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
return defaultType.value;
|
|
412
|
+
};
|
|
413
|
+
var handleMaterialized = (t, checker) => {
|
|
414
|
+
const materializedType = getTaggedType(
|
|
415
|
+
t,
|
|
416
|
+
checker,
|
|
417
|
+
"_clickhouse_materialized"
|
|
418
|
+
);
|
|
419
|
+
if (materializedType === null) {
|
|
420
|
+
return null;
|
|
421
|
+
}
|
|
422
|
+
if (!materializedType.isStringLiteral()) {
|
|
423
|
+
throw new UnsupportedFeature(
|
|
424
|
+
'ClickHouseMaterialized must use a string literal, e.g. ClickHouseMaterialized<"toDate(timestamp)">'
|
|
425
|
+
);
|
|
426
|
+
}
|
|
427
|
+
return materializedType.value;
|
|
428
|
+
};
|
|
429
|
+
var handleTtl = (t, checker) => {
|
|
430
|
+
const ttlType = getTaggedType(t, checker, "_clickhouse_ttl");
|
|
431
|
+
if (ttlType === null) {
|
|
432
|
+
return null;
|
|
433
|
+
}
|
|
434
|
+
if (!ttlType.isStringLiteral()) {
|
|
435
|
+
throw new UnsupportedFeature(
|
|
436
|
+
'ClickHouseTTL must use a string literal, e.g. ClickHouseTTL<"timestamp + INTERVAL 1 WEEK">'
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
return ttlType.value;
|
|
440
|
+
};
|
|
441
|
+
var handleNumberType = (t, checker, fieldName) => {
|
|
442
|
+
const decimalPrecisionSymbol = getPropertyDeep(t, "_clickhouse_precision");
|
|
443
|
+
const decimalScaleSymbol = getPropertyDeep(t, "_clickhouse_scale");
|
|
444
|
+
if (decimalPrecisionSymbol !== void 0 && decimalScaleSymbol !== void 0) {
|
|
445
|
+
const precisionType = checker.getNonNullableType(
|
|
446
|
+
checker.getTypeOfSymbol(decimalPrecisionSymbol)
|
|
447
|
+
);
|
|
448
|
+
const scaleType = checker.getNonNullableType(
|
|
449
|
+
checker.getTypeOfSymbol(decimalScaleSymbol)
|
|
450
|
+
);
|
|
451
|
+
if (precisionType.isNumberLiteral() && scaleType.isNumberLiteral()) {
|
|
452
|
+
return `Decimal(${precisionType.value}, ${scaleType.value})`;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
const tagSymbol = t.getProperty("typia.tag");
|
|
456
|
+
if (tagSymbol === void 0) {
|
|
457
|
+
return "Float64";
|
|
458
|
+
} else {
|
|
459
|
+
const typiaProps = checker.getNonNullableType(
|
|
460
|
+
checker.getTypeOfSymbol(tagSymbol)
|
|
461
|
+
);
|
|
462
|
+
const props = typiaProps.isIntersection() ? typiaProps.types : [typiaProps];
|
|
463
|
+
for (const prop of props) {
|
|
464
|
+
const valueSymbol = prop.getProperty("value");
|
|
465
|
+
if (valueSymbol === void 0) {
|
|
466
|
+
console.log(
|
|
467
|
+
`[CompilerPlugin] Props.value is undefined for ${fieldName}`
|
|
468
|
+
);
|
|
469
|
+
} else {
|
|
470
|
+
const valueTypeLiteral = checker.getTypeOfSymbol(valueSymbol);
|
|
471
|
+
const numberTypeMappings = {
|
|
472
|
+
float: "Float32",
|
|
473
|
+
double: "Float64",
|
|
474
|
+
int8: "Int8",
|
|
475
|
+
int16: "Int16",
|
|
476
|
+
int32: "Int32",
|
|
477
|
+
int64: "Int64",
|
|
478
|
+
uint8: "UInt8",
|
|
479
|
+
uint16: "UInt16",
|
|
480
|
+
uint32: "UInt32",
|
|
481
|
+
uint64: "UInt64"
|
|
482
|
+
};
|
|
483
|
+
const match = Object.entries(numberTypeMappings).find(
|
|
484
|
+
([k, _]) => isStringLiteral(valueTypeLiteral, checker, k)
|
|
485
|
+
);
|
|
486
|
+
if (match) {
|
|
487
|
+
return match[1];
|
|
488
|
+
} else {
|
|
489
|
+
const typeString = valueTypeLiteral.isStringLiteral() ? valueTypeLiteral.value : "unknown";
|
|
490
|
+
console.log(
|
|
491
|
+
`[CompilerPlugin] Other number types are not supported: ${typeString} in field ${fieldName}`
|
|
492
|
+
);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
return "Float64";
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
var isStringLiteral = (t, checker, lit) => checker.isTypeAssignableTo(t, checker.getStringLiteralType(lit));
|
|
500
|
+
var handleStringType = (t, checker, fieldName, annotations) => {
|
|
501
|
+
const fixedStringSizeSymbol = getPropertyDeep(
|
|
502
|
+
t,
|
|
503
|
+
"_clickhouse_fixed_string_size"
|
|
504
|
+
);
|
|
505
|
+
if (fixedStringSizeSymbol !== void 0) {
|
|
506
|
+
const sizeType = checker.getNonNullableType(
|
|
507
|
+
checker.getTypeOfSymbol(fixedStringSizeSymbol)
|
|
508
|
+
);
|
|
509
|
+
if (sizeType.isNumberLiteral()) {
|
|
510
|
+
return `FixedString(${sizeType.value})`;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
const tagSymbol = t.getProperty("typia.tag");
|
|
514
|
+
if (tagSymbol === void 0) {
|
|
515
|
+
if (t.isUnion() && t.types.every((v) => v.isStringLiteral())) {
|
|
516
|
+
annotations.push(["LowCardinality", true]);
|
|
517
|
+
}
|
|
518
|
+
return "String";
|
|
519
|
+
} else {
|
|
520
|
+
const typiaProps = checker.getNonNullableType(
|
|
521
|
+
checker.getTypeOfSymbol(tagSymbol)
|
|
522
|
+
);
|
|
523
|
+
const props = typiaProps.isIntersection() ? typiaProps.types : [typiaProps];
|
|
524
|
+
for (const prop of props) {
|
|
525
|
+
const valueSymbol = prop.getProperty("value");
|
|
526
|
+
if (valueSymbol === void 0) {
|
|
527
|
+
console.log(
|
|
528
|
+
`[CompilerPlugin] Props.value is undefined for ${fieldName}`
|
|
529
|
+
);
|
|
530
|
+
} else {
|
|
531
|
+
const valueTypeLiteral = checker.getTypeOfSymbol(valueSymbol);
|
|
532
|
+
if (isStringLiteral(valueTypeLiteral, checker, "uuid")) {
|
|
533
|
+
return "UUID";
|
|
534
|
+
} else if (isStringLiteral(valueTypeLiteral, checker, "date-time")) {
|
|
535
|
+
let precision = 9;
|
|
536
|
+
const precisionSymbol = t.getProperty("_clickhouse_precision");
|
|
537
|
+
if (precisionSymbol !== void 0) {
|
|
538
|
+
const precisionType = checker.getNonNullableType(
|
|
539
|
+
checker.getTypeOfSymbol(precisionSymbol)
|
|
540
|
+
);
|
|
541
|
+
if (precisionType.isNumberLiteral()) {
|
|
542
|
+
precision = precisionType.value;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
annotations.push([STRING_DATE_ANNOTATION, true]);
|
|
546
|
+
return `DateTime(${precision})`;
|
|
547
|
+
} else if (isStringLiteral(valueTypeLiteral, checker, "date")) {
|
|
548
|
+
let size = 4;
|
|
549
|
+
const sizeSymbol = t.getProperty("_clickhouse_byte_size");
|
|
550
|
+
if (sizeSymbol !== void 0) {
|
|
551
|
+
const sizeType = checker.getNonNullableType(
|
|
552
|
+
checker.getTypeOfSymbol(sizeSymbol)
|
|
553
|
+
);
|
|
554
|
+
if (sizeType.isNumberLiteral()) {
|
|
555
|
+
size = sizeType.value;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
if (size === 4) {
|
|
559
|
+
return "Date";
|
|
560
|
+
} else if (size === 2) {
|
|
561
|
+
return "Date16";
|
|
562
|
+
} else {
|
|
563
|
+
throw new UnsupportedFeature(`Date with size ${size}`);
|
|
564
|
+
}
|
|
565
|
+
} else if (isStringLiteral(valueTypeLiteral, checker, "ipv4")) {
|
|
566
|
+
return "IPv4";
|
|
567
|
+
} else if (isStringLiteral(valueTypeLiteral, checker, "ipv6")) {
|
|
568
|
+
return "IPv6";
|
|
569
|
+
} else if (isStringLiteral(valueTypeLiteral, checker, DecimalRegex)) {
|
|
570
|
+
let precision = 10;
|
|
571
|
+
let scale = 0;
|
|
572
|
+
const precisionSymbol = t.getProperty("_clickhouse_precision");
|
|
573
|
+
if (precisionSymbol !== void 0) {
|
|
574
|
+
const precisionType = checker.getNonNullableType(
|
|
575
|
+
checker.getTypeOfSymbol(precisionSymbol)
|
|
576
|
+
);
|
|
577
|
+
if (precisionType.isNumberLiteral()) {
|
|
578
|
+
precision = precisionType.value;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
const scaleSymbol = t.getProperty("_clickhouse_scale");
|
|
582
|
+
if (scaleSymbol !== void 0) {
|
|
583
|
+
const scaleType = checker.getNonNullableType(
|
|
584
|
+
checker.getTypeOfSymbol(scaleSymbol)
|
|
585
|
+
);
|
|
586
|
+
if (scaleType.isNumberLiteral()) {
|
|
587
|
+
scale = scaleType.value;
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
return `Decimal(${precision}, ${scale})`;
|
|
591
|
+
} else {
|
|
592
|
+
const typeString = valueTypeLiteral.isStringLiteral() ? valueTypeLiteral.value : "unknown";
|
|
593
|
+
console.log(
|
|
594
|
+
`[CompilerPlugin] Unknown format: ${typeString} in field ${fieldName}`
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
return "String";
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
var isStringAnyRecord = (t, checker) => {
|
|
603
|
+
const indexInfos = checker.getIndexInfosOfType(t);
|
|
604
|
+
if (indexInfos && indexInfos.length === 1) {
|
|
605
|
+
const indexInfo = indexInfos[0];
|
|
606
|
+
return indexInfo.keyType == checker.getStringType() && indexInfo.type == checker.getAnyType();
|
|
607
|
+
}
|
|
608
|
+
return false;
|
|
609
|
+
};
|
|
610
|
+
var isRecordType = (t, checker) => {
|
|
611
|
+
const indexInfos = checker.getIndexInfosOfType(t);
|
|
612
|
+
return indexInfos && indexInfos.length === 1;
|
|
613
|
+
};
|
|
614
|
+
var isSingleUnderscoreMetaObject = (t, checker) => {
|
|
615
|
+
const props = checker.getPropertiesOfType(t);
|
|
616
|
+
if (props.length !== 1) return false;
|
|
617
|
+
const onlyProp = props[0];
|
|
618
|
+
const name = onlyProp.name;
|
|
619
|
+
return typeof name === "string" && name.startsWith("_");
|
|
620
|
+
};
|
|
621
|
+
var handleRecordType = (t, checker, fieldName, typeName, isJwt) => {
|
|
622
|
+
const indexInfos = checker.getIndexInfosOfType(t);
|
|
623
|
+
if (indexInfos && indexInfos.length !== 1) {
|
|
624
|
+
throwIndexTypeError(t, checker);
|
|
625
|
+
}
|
|
626
|
+
const indexInfo = indexInfos[0];
|
|
627
|
+
const [, , keyType] = tsTypeToDataType(
|
|
628
|
+
indexInfo.keyType,
|
|
629
|
+
checker,
|
|
630
|
+
`${fieldName}_key`,
|
|
631
|
+
typeName,
|
|
632
|
+
isJwt
|
|
633
|
+
);
|
|
634
|
+
const [, , valueType] = tsTypeToDataType(
|
|
635
|
+
indexInfo.type,
|
|
636
|
+
checker,
|
|
637
|
+
`${fieldName}_value`,
|
|
638
|
+
typeName,
|
|
639
|
+
isJwt
|
|
640
|
+
);
|
|
641
|
+
return {
|
|
642
|
+
keyType,
|
|
643
|
+
valueType
|
|
644
|
+
};
|
|
645
|
+
};
|
|
646
|
+
var isNamedTuple = (t, checker) => {
|
|
647
|
+
const mappingSymbol = t.getProperty("_clickhouse_mapped_type");
|
|
648
|
+
if (mappingSymbol === void 0) {
|
|
649
|
+
return false;
|
|
650
|
+
}
|
|
651
|
+
return isStringLiteral(
|
|
652
|
+
checker.getNonNullableType(checker.getTypeOfSymbol(mappingSymbol)),
|
|
653
|
+
checker,
|
|
654
|
+
"namedTuple"
|
|
655
|
+
);
|
|
656
|
+
};
|
|
657
|
+
var getGeometryMappedType = (t, checker) => {
|
|
658
|
+
const mappingSymbol = getPropertyDeep(t, "_clickhouse_mapped_type");
|
|
659
|
+
if (mappingSymbol === void 0) return null;
|
|
660
|
+
const mapped = checker.getNonNullableType(
|
|
661
|
+
checker.getTypeOfSymbol(mappingSymbol)
|
|
662
|
+
);
|
|
663
|
+
const isPointTuple = (candidate) => {
|
|
664
|
+
if (candidate.isIntersection()) {
|
|
665
|
+
return candidate.types.some(isPointTuple);
|
|
666
|
+
}
|
|
667
|
+
if (!checker.isTupleType(candidate)) return false;
|
|
668
|
+
const tuple = candidate;
|
|
669
|
+
const args = tuple.typeArguments || [];
|
|
670
|
+
if (args.length !== 2) return false;
|
|
671
|
+
return isNumberType(args[0], checker) && isNumberType(args[1], checker);
|
|
672
|
+
};
|
|
673
|
+
const isArrayOf = (arrType, elementPredicate) => {
|
|
674
|
+
if (arrType.isIntersection()) {
|
|
675
|
+
return arrType.types.some((t2) => isArrayOf(t2, elementPredicate));
|
|
676
|
+
}
|
|
677
|
+
if (!checker.isArrayType(arrType)) return false;
|
|
678
|
+
const elementType = arrType.getNumberIndexType();
|
|
679
|
+
if (!elementType) return false;
|
|
680
|
+
return elementPredicate(elementType);
|
|
681
|
+
};
|
|
682
|
+
const expectAndValidate = (shapeName, validator) => {
|
|
683
|
+
if (!validator()) {
|
|
684
|
+
throw new UnsupportedFeature(
|
|
685
|
+
`Type annotated as ${shapeName} must be assignable to the expected geometry shape`
|
|
686
|
+
);
|
|
687
|
+
}
|
|
688
|
+
return shapeName;
|
|
689
|
+
};
|
|
690
|
+
if (mapped.isStringLiteral()) {
|
|
691
|
+
const v = mapped.value;
|
|
692
|
+
switch (v) {
|
|
693
|
+
case "Point":
|
|
694
|
+
return expectAndValidate("Point", () => isPointTuple(t));
|
|
695
|
+
case "Ring":
|
|
696
|
+
case "LineString":
|
|
697
|
+
return expectAndValidate(
|
|
698
|
+
v,
|
|
699
|
+
() => isArrayOf(t, (el) => isPointTuple(el))
|
|
700
|
+
);
|
|
701
|
+
case "MultiLineString":
|
|
702
|
+
case "Polygon":
|
|
703
|
+
return expectAndValidate(
|
|
704
|
+
v,
|
|
705
|
+
() => isArrayOf(t, (el) => isArrayOf(el, (inner) => isPointTuple(inner)))
|
|
706
|
+
);
|
|
707
|
+
case "MultiPolygon":
|
|
708
|
+
return expectAndValidate(
|
|
709
|
+
v,
|
|
710
|
+
() => isArrayOf(
|
|
711
|
+
t,
|
|
712
|
+
(el) => isArrayOf(el, (inner) => isArrayOf(inner, isPointTuple))
|
|
713
|
+
)
|
|
714
|
+
);
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
return null;
|
|
718
|
+
};
|
|
719
|
+
var checkColumnHasNoDefault = (c) => {
|
|
720
|
+
if (c.default !== null) {
|
|
721
|
+
throw new UnsupportedFeature(
|
|
722
|
+
"Default in inner field. Put ClickHouseDefault in top level field."
|
|
723
|
+
);
|
|
724
|
+
}
|
|
725
|
+
};
|
|
726
|
+
var handleNested = (t, checker, fieldName, jwt) => {
|
|
727
|
+
const columns = toColumns(t, checker);
|
|
728
|
+
columns.forEach(checkColumnHasNoDefault);
|
|
729
|
+
return {
|
|
730
|
+
name: getNestedName(t, fieldName),
|
|
731
|
+
columns,
|
|
732
|
+
jwt
|
|
733
|
+
};
|
|
734
|
+
};
|
|
735
|
+
var handleNamedTuple = (t, checker) => {
|
|
736
|
+
return {
|
|
737
|
+
fields: toColumns(t, checker).flatMap((c) => {
|
|
738
|
+
if (c.name === "_clickhouse_mapped_type") return [];
|
|
739
|
+
checkColumnHasNoDefault(c);
|
|
740
|
+
const t2 = c.required ? c.data_type : { nullable: c.data_type };
|
|
741
|
+
return [[c.name, t2]];
|
|
742
|
+
})
|
|
743
|
+
};
|
|
744
|
+
};
|
|
745
|
+
var tsTypeToDataType = (t, checker, fieldName, typeName, isJwt, typeNode) => {
|
|
746
|
+
const nonNull = t.getNonNullableType();
|
|
747
|
+
const nullable = nonNull != t;
|
|
748
|
+
const aggregationFunction = handleAggregated(t, checker, fieldName, typeName);
|
|
749
|
+
const simpleAggregationFunction = handleSimpleAggregated(
|
|
750
|
+
t,
|
|
751
|
+
checker,
|
|
752
|
+
fieldName,
|
|
753
|
+
typeName
|
|
754
|
+
);
|
|
755
|
+
let withoutTags = nonNull;
|
|
756
|
+
if (nonNull.isIntersection()) {
|
|
757
|
+
const nonTagTypes = nonNull.types.filter(
|
|
758
|
+
(candidate) => !isSingleUnderscoreMetaObject(candidate, checker)
|
|
759
|
+
);
|
|
760
|
+
if (nonTagTypes.length == 1) {
|
|
761
|
+
withoutTags = nonTagTypes[0];
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
let datePrecisionFromNode = void 0;
|
|
765
|
+
if (typeNode && (0, import_typescript3.isTypeReferenceNode)(typeNode)) {
|
|
766
|
+
const tn = typeNode.typeName;
|
|
767
|
+
const name = (0, import_typescript3.isIdentifier)(tn) ? tn.text : tn.right.text;
|
|
768
|
+
if (name === "DateTime64") {
|
|
769
|
+
const arg = typeNode.typeArguments?.[0];
|
|
770
|
+
if (arg && import_typescript3.default.isLiteralTypeNode(arg) && import_typescript3.default.isNumericLiteral(arg.literal)) {
|
|
771
|
+
datePrecisionFromNode = Number(arg.literal.text);
|
|
772
|
+
}
|
|
773
|
+
} else if (name === "DateTime") {
|
|
774
|
+
datePrecisionFromNode = void 0;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
const annotations = [];
|
|
778
|
+
const typeSymbolName = nonNull.symbol?.name || t.symbol?.name;
|
|
779
|
+
const isDateLike = typeSymbolName === "DateTime" || typeSymbolName === "DateTime64" || checker.isTypeAssignableTo(nonNull, dateType(checker));
|
|
780
|
+
let dataType;
|
|
781
|
+
if (isEnum(nonNull)) {
|
|
782
|
+
dataType = enumConvert(nonNull);
|
|
783
|
+
} else {
|
|
784
|
+
const jsonCandidate = getJsonMappedType(nonNull, checker);
|
|
785
|
+
if (jsonCandidate !== null) {
|
|
786
|
+
dataType = jsonCandidate;
|
|
787
|
+
} else if (isStringAnyRecord(nonNull, checker)) {
|
|
788
|
+
dataType = "Json";
|
|
789
|
+
} else if (isDateLike) {
|
|
790
|
+
if (datePrecisionFromNode !== void 0) {
|
|
791
|
+
dataType = `DateTime(${datePrecisionFromNode})`;
|
|
792
|
+
} else {
|
|
793
|
+
const precisionSymbol = getPropertyDeep(nonNull, "_clickhouse_precision") || getPropertyDeep(t, "_clickhouse_precision");
|
|
794
|
+
if (precisionSymbol !== void 0) {
|
|
795
|
+
const precisionType = checker.getNonNullableType(
|
|
796
|
+
checker.getTypeOfSymbol(precisionSymbol)
|
|
797
|
+
);
|
|
798
|
+
if (precisionType.isNumberLiteral()) {
|
|
799
|
+
dataType = `DateTime(${precisionType.value})`;
|
|
800
|
+
} else {
|
|
801
|
+
dataType = "DateTime";
|
|
802
|
+
}
|
|
803
|
+
} else {
|
|
804
|
+
dataType = "DateTime";
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
} else if (checker.isTypeAssignableTo(nonNull, checker.getStringType())) {
|
|
808
|
+
dataType = handleStringType(nonNull, checker, fieldName, annotations);
|
|
809
|
+
} else if (isNumberType(nonNull, checker)) {
|
|
810
|
+
dataType = handleNumberType(nonNull, checker, fieldName);
|
|
811
|
+
} else if (checker.isTypeAssignableTo(nonNull, checker.getBooleanType())) {
|
|
812
|
+
dataType = "Boolean";
|
|
813
|
+
} else if (getGeometryMappedType(nonNull, checker) !== null) {
|
|
814
|
+
dataType = getGeometryMappedType(nonNull, checker);
|
|
815
|
+
} else if (checker.isArrayType(withoutTags)) {
|
|
816
|
+
dataType = toArrayType(
|
|
817
|
+
tsTypeToDataType(
|
|
818
|
+
nonNull.getNumberIndexType(),
|
|
819
|
+
checker,
|
|
820
|
+
fieldName,
|
|
821
|
+
typeName,
|
|
822
|
+
isJwt,
|
|
823
|
+
void 0
|
|
824
|
+
)
|
|
825
|
+
);
|
|
826
|
+
} else if (isNamedTuple(nonNull, checker)) {
|
|
827
|
+
dataType = handleNamedTuple(nonNull, checker);
|
|
828
|
+
} else if (isRecordType(nonNull, checker)) {
|
|
829
|
+
dataType = handleRecordType(nonNull, checker, fieldName, typeName, isJwt);
|
|
830
|
+
} else if (withoutTags.isClassOrInterface() || (withoutTags.flags & import_typescript3.TypeFlags.Object) !== 0) {
|
|
831
|
+
dataType = handleNested(withoutTags, checker, fieldName, isJwt);
|
|
832
|
+
} else if (nonNull == checker.getNeverType()) {
|
|
833
|
+
dataType = throwNullType(fieldName, typeName);
|
|
834
|
+
} else {
|
|
835
|
+
dataType = throwUnknownType(t, fieldName, typeName);
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
if (aggregationFunction !== void 0) {
|
|
839
|
+
annotations.push(["aggregationFunction", aggregationFunction]);
|
|
840
|
+
}
|
|
841
|
+
if (simpleAggregationFunction !== void 0) {
|
|
842
|
+
annotations.push(["simpleAggregationFunction", simpleAggregationFunction]);
|
|
843
|
+
}
|
|
844
|
+
const lowCardinalitySymbol = t.getProperty("_LowCardinality");
|
|
845
|
+
if (lowCardinalitySymbol !== void 0) {
|
|
846
|
+
const lowCardinalityType = checker.getNonNullableType(
|
|
847
|
+
checker.getTypeOfSymbol(lowCardinalitySymbol)
|
|
848
|
+
);
|
|
849
|
+
if (lowCardinalityType == checker.getTrueType()) {
|
|
850
|
+
annotations.push(["LowCardinality", true]);
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
return [nullable, annotations, dataType];
|
|
854
|
+
};
|
|
855
|
+
var getNestedName = (t, fieldName) => {
|
|
856
|
+
const name = t.symbol.name;
|
|
857
|
+
return name === "__type" ? fieldName : name;
|
|
858
|
+
};
|
|
859
|
+
var hasWrapping = (typeNode, wrapperName) => {
|
|
860
|
+
if (typeNode !== void 0 && (0, import_typescript3.isTypeReferenceNode)(typeNode)) {
|
|
861
|
+
const typeName = typeNode.typeName;
|
|
862
|
+
const name = (0, import_typescript3.isIdentifier)(typeName) ? typeName.text : typeName.right.text;
|
|
863
|
+
return name === wrapperName && typeNode.typeArguments?.length === 1;
|
|
864
|
+
} else {
|
|
865
|
+
return false;
|
|
866
|
+
}
|
|
867
|
+
};
|
|
868
|
+
var hasKeyWrapping = (typeNode) => {
|
|
869
|
+
return hasWrapping(typeNode, "Key");
|
|
870
|
+
};
|
|
871
|
+
var hasJwtWrapping = (typeNode) => {
|
|
872
|
+
return hasWrapping(typeNode, "JWT");
|
|
873
|
+
};
|
|
874
|
+
var handleDefaultWrapping = (typeNode) => {
|
|
875
|
+
if (typeNode !== void 0 && (0, import_typescript3.isTypeReferenceNode)(typeNode)) {
|
|
876
|
+
const typeName = typeNode.typeName;
|
|
877
|
+
const name = (0, import_typescript3.isIdentifier)(typeName) ? typeName.text : typeName.right.text;
|
|
878
|
+
if (name === "WithDefault" && typeNode.typeArguments?.length === 2) {
|
|
879
|
+
const defaultValueType = typeNode.typeArguments[1];
|
|
880
|
+
if (import_typescript3.default.isLiteralTypeNode(defaultValueType) && import_typescript3.default.isStringLiteral(defaultValueType.literal)) {
|
|
881
|
+
return defaultValueType.literal.text;
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
return void 0;
|
|
886
|
+
};
|
|
887
|
+
var handleCodec = (t, checker) => {
|
|
888
|
+
const codecType = getTaggedType(t, checker, "_clickhouse_codec");
|
|
889
|
+
if (codecType === null) {
|
|
890
|
+
return null;
|
|
891
|
+
}
|
|
892
|
+
if (!codecType.isStringLiteral()) {
|
|
893
|
+
throw new UnsupportedFeature(
|
|
894
|
+
'ClickHouseCodec must use a string literal, e.g. ClickHouseCodec<"ZSTD(3)">'
|
|
895
|
+
);
|
|
896
|
+
}
|
|
897
|
+
return codecType.value;
|
|
898
|
+
};
|
|
899
|
+
var toColumns = (t, checker, options) => {
|
|
900
|
+
if (!options?.allowIndexSignatures && checker.getIndexInfosOfType(t).length !== 0) {
|
|
901
|
+
console.log("[CompilerPlugin]", checker.getIndexInfosOfType(t));
|
|
902
|
+
throwIndexTypeError(t, checker);
|
|
903
|
+
}
|
|
904
|
+
return checker.getPropertiesOfType(t).map((prop) => {
|
|
905
|
+
let declarations = prop.getDeclarations();
|
|
906
|
+
const node = declarations && declarations.length > 0 ? declarations[0] : void 0;
|
|
907
|
+
const type = node !== void 0 ? checker.getTypeOfSymbolAtLocation(prop, node) : checker.getTypeOfSymbol(prop);
|
|
908
|
+
const isKey = hasKeyWrapping(node?.type);
|
|
909
|
+
const isJwt = hasJwtWrapping(node?.type);
|
|
910
|
+
const defaultExpression = handleDefaultWrapping(node?.type);
|
|
911
|
+
const [nullable, annotations, dataType] = tsTypeToDataType(
|
|
912
|
+
type,
|
|
913
|
+
checker,
|
|
914
|
+
prop.name,
|
|
915
|
+
t.symbol?.name || "inline_type",
|
|
916
|
+
isJwt,
|
|
917
|
+
node?.type
|
|
918
|
+
);
|
|
919
|
+
const defaultValue = defaultExpression ?? handleDefault(type, checker);
|
|
920
|
+
const materializedValue = handleMaterialized(type, checker);
|
|
921
|
+
if (defaultValue && materializedValue) {
|
|
922
|
+
throw new UnsupportedFeature(
|
|
923
|
+
`Column '${prop.name}' cannot have both ClickHouseDefault and ClickHouseMaterialized. Use one or the other.`
|
|
924
|
+
);
|
|
925
|
+
}
|
|
926
|
+
const docComment = prop.getDocumentationComment(checker);
|
|
927
|
+
const comment = docComment.length > 0 ? (0, import_typescript3.displayPartsToString)(docComment) : null;
|
|
928
|
+
return {
|
|
929
|
+
name: prop.name,
|
|
930
|
+
data_type: dataType,
|
|
931
|
+
primary_key: isKey,
|
|
932
|
+
required: !nullable,
|
|
933
|
+
unique: false,
|
|
934
|
+
default: defaultValue,
|
|
935
|
+
materialized: materializedValue,
|
|
936
|
+
ttl: handleTtl(type, checker),
|
|
937
|
+
codec: handleCodec(type, checker),
|
|
938
|
+
annotations,
|
|
939
|
+
comment
|
|
940
|
+
};
|
|
941
|
+
});
|
|
942
|
+
};
|
|
943
|
+
var import_typescript4 = __toESM(require("typescript"));
|
|
944
|
+
var import_ImportProgrammer = require("typia/lib/programmers/ImportProgrammer");
|
|
945
|
+
var import_ValidateProgrammer = require("typia/lib/programmers/ValidateProgrammer");
|
|
946
|
+
var import_IsProgrammer = require("typia/lib/programmers/IsProgrammer");
|
|
947
|
+
var import_AssertProgrammer = require("typia/lib/programmers/AssertProgrammer");
|
|
948
|
+
var import_JsonSchemasProgrammer = require("typia/lib/programmers/json/JsonSchemasProgrammer");
|
|
949
|
+
var import_HttpAssertQueryProgrammer = require("typia/lib/programmers/http/HttpAssertQueryProgrammer");
|
|
950
|
+
var import_MetadataCollection = require("typia/lib/factories/MetadataCollection");
|
|
951
|
+
var import_MetadataFactory = require("typia/lib/factories/MetadataFactory");
|
|
952
|
+
var import_LiteralFactory = require("typia/lib/factories/LiteralFactory");
|
|
953
|
+
var createSyntheticModulo = () => {
|
|
954
|
+
const identifier = import_typescript4.default.factory.createIdentifier("typia");
|
|
955
|
+
identifier.getText = () => "typia";
|
|
956
|
+
return identifier;
|
|
957
|
+
};
|
|
958
|
+
var createTypiaContext = (program, transformer, sourceFile) => {
|
|
959
|
+
const importer = new import_ImportProgrammer.ImportProgrammer({
|
|
960
|
+
internalPrefix: avoidTypiaNameClash
|
|
961
|
+
});
|
|
962
|
+
return {
|
|
963
|
+
program,
|
|
964
|
+
checker: program.getTypeChecker(),
|
|
965
|
+
transformer,
|
|
966
|
+
importer,
|
|
967
|
+
modulo: createSyntheticModulo(),
|
|
968
|
+
sourceFile
|
|
969
|
+
};
|
|
970
|
+
};
|
|
971
|
+
var toTypiaContext = (ctx) => ({
|
|
972
|
+
program: ctx.program,
|
|
973
|
+
compilerOptions: ctx.program.getCompilerOptions(),
|
|
974
|
+
checker: ctx.checker,
|
|
975
|
+
printer: import_typescript4.default.createPrinter(),
|
|
976
|
+
options: {},
|
|
977
|
+
transformer: ctx.transformer,
|
|
978
|
+
importer: ctx.importer,
|
|
979
|
+
extras: {
|
|
980
|
+
// Not used by the programmers we call directly (CheckerProgrammer,
|
|
981
|
+
// HttpAssertQueryProgrammer, JsonSchemasProgrammer) - only used by
|
|
982
|
+
// FileTransformer which we bypass
|
|
983
|
+
addDiagnostic: () => 0
|
|
984
|
+
}
|
|
985
|
+
});
|
|
986
|
+
var generateValidateFunction = (ctx, type, typeName) => {
|
|
987
|
+
const typiaCtx = toTypiaContext(ctx);
|
|
988
|
+
return import_ValidateProgrammer.ValidateProgrammer.write({
|
|
989
|
+
context: typiaCtx,
|
|
990
|
+
modulo: ctx.modulo,
|
|
991
|
+
type,
|
|
992
|
+
name: typeName,
|
|
993
|
+
config: { equals: false }
|
|
994
|
+
});
|
|
995
|
+
};
|
|
996
|
+
var generateIsFunction = (ctx, type, typeName) => {
|
|
997
|
+
const typiaCtx = toTypiaContext(ctx);
|
|
998
|
+
return import_IsProgrammer.IsProgrammer.write({
|
|
999
|
+
context: typiaCtx,
|
|
1000
|
+
modulo: ctx.modulo,
|
|
1001
|
+
type,
|
|
1002
|
+
name: typeName,
|
|
1003
|
+
config: { equals: false }
|
|
1004
|
+
});
|
|
1005
|
+
};
|
|
1006
|
+
var generateAssertFunction = (ctx, type, typeName) => {
|
|
1007
|
+
const typiaCtx = toTypiaContext(ctx);
|
|
1008
|
+
return import_AssertProgrammer.AssertProgrammer.write({
|
|
1009
|
+
context: typiaCtx,
|
|
1010
|
+
modulo: ctx.modulo,
|
|
1011
|
+
type,
|
|
1012
|
+
name: typeName,
|
|
1013
|
+
config: { equals: false, guard: false }
|
|
1014
|
+
});
|
|
1015
|
+
};
|
|
1016
|
+
var generateHttpAssertQueryFunction = (ctx, type, typeName) => {
|
|
1017
|
+
const typiaCtx = toTypiaContext(ctx);
|
|
1018
|
+
return import_HttpAssertQueryProgrammer.HttpAssertQueryProgrammer.write({
|
|
1019
|
+
context: typiaCtx,
|
|
1020
|
+
modulo: ctx.modulo,
|
|
1021
|
+
type,
|
|
1022
|
+
name: typeName
|
|
1023
|
+
});
|
|
1024
|
+
};
|
|
1025
|
+
var DATE_SCHEMA = {
|
|
1026
|
+
type: "string",
|
|
1027
|
+
format: "date-time"
|
|
1028
|
+
};
|
|
1029
|
+
var isClickHouseInternalProperty = (name) => name.startsWith("_clickhouse_") || name === "_LowCardinality";
|
|
1030
|
+
var cleanJsonSchema = (schema) => {
|
|
1031
|
+
if (schema.$ref === "#/components/schemas/Date") {
|
|
1032
|
+
const { $ref, ...rest } = schema;
|
|
1033
|
+
return { ...DATE_SCHEMA, ...rest };
|
|
1034
|
+
}
|
|
1035
|
+
if (schema.type === "object") {
|
|
1036
|
+
const result = { ...schema };
|
|
1037
|
+
if (schema.properties) {
|
|
1038
|
+
const cleanedProperties = {};
|
|
1039
|
+
const cleanedRequired = [];
|
|
1040
|
+
for (const [key, value] of Object.entries(schema.properties)) {
|
|
1041
|
+
if (!isClickHouseInternalProperty(key)) {
|
|
1042
|
+
cleanedProperties[key] = cleanJsonSchema(value);
|
|
1043
|
+
if (schema.required?.includes(key)) {
|
|
1044
|
+
cleanedRequired.push(key);
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
result.properties = cleanedProperties;
|
|
1049
|
+
result.required = cleanedRequired.length > 0 ? cleanedRequired : void 0;
|
|
1050
|
+
}
|
|
1051
|
+
if (schema.additionalProperties && typeof schema.additionalProperties === "object") {
|
|
1052
|
+
result.additionalProperties = cleanJsonSchema(
|
|
1053
|
+
schema.additionalProperties
|
|
1054
|
+
);
|
|
1055
|
+
}
|
|
1056
|
+
return result;
|
|
1057
|
+
}
|
|
1058
|
+
if (schema.type === "array") {
|
|
1059
|
+
const result = { ...schema };
|
|
1060
|
+
if (schema.items) {
|
|
1061
|
+
result.items = cleanJsonSchema(schema.items);
|
|
1062
|
+
}
|
|
1063
|
+
if (schema.prefixItems && Array.isArray(schema.prefixItems)) {
|
|
1064
|
+
result.prefixItems = schema.prefixItems.map(cleanJsonSchema);
|
|
1065
|
+
}
|
|
1066
|
+
if (schema.additionalItems && typeof schema.additionalItems === "object") {
|
|
1067
|
+
result.additionalItems = cleanJsonSchema(schema.additionalItems);
|
|
1068
|
+
}
|
|
1069
|
+
return result;
|
|
1070
|
+
}
|
|
1071
|
+
if (schema.oneOf && Array.isArray(schema.oneOf)) {
|
|
1072
|
+
return {
|
|
1073
|
+
...schema,
|
|
1074
|
+
oneOf: schema.oneOf.map(cleanJsonSchema)
|
|
1075
|
+
};
|
|
1076
|
+
}
|
|
1077
|
+
if (schema.anyOf && Array.isArray(schema.anyOf)) {
|
|
1078
|
+
return {
|
|
1079
|
+
...schema,
|
|
1080
|
+
anyOf: schema.anyOf.map(cleanJsonSchema)
|
|
1081
|
+
};
|
|
1082
|
+
}
|
|
1083
|
+
if (schema.allOf && Array.isArray(schema.allOf)) {
|
|
1084
|
+
return {
|
|
1085
|
+
...schema,
|
|
1086
|
+
allOf: schema.allOf.map(cleanJsonSchema)
|
|
1087
|
+
};
|
|
1088
|
+
}
|
|
1089
|
+
return schema;
|
|
1090
|
+
};
|
|
1091
|
+
var cleanJsonSchemaCollection = (collection) => {
|
|
1092
|
+
const cleanedComponentsSchemas = {};
|
|
1093
|
+
if (collection.components.schemas) {
|
|
1094
|
+
for (const [name, schema] of Object.entries(
|
|
1095
|
+
collection.components.schemas
|
|
1096
|
+
)) {
|
|
1097
|
+
if (name === "Date") {
|
|
1098
|
+
cleanedComponentsSchemas[name] = DATE_SCHEMA;
|
|
1099
|
+
} else {
|
|
1100
|
+
cleanedComponentsSchemas[name] = cleanJsonSchema(schema);
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
const cleanedSchemas = collection.schemas.map(
|
|
1105
|
+
(s) => cleanJsonSchema(s)
|
|
1106
|
+
);
|
|
1107
|
+
return {
|
|
1108
|
+
...collection,
|
|
1109
|
+
components: {
|
|
1110
|
+
...collection.components,
|
|
1111
|
+
schemas: cleanedComponentsSchemas
|
|
1112
|
+
},
|
|
1113
|
+
schemas: cleanedSchemas
|
|
1114
|
+
};
|
|
1115
|
+
};
|
|
1116
|
+
var generateJsonSchemas = (ctx, type) => {
|
|
1117
|
+
const metadataResult = import_MetadataFactory.MetadataFactory.analyze({
|
|
1118
|
+
checker: ctx.checker,
|
|
1119
|
+
transformer: ctx.transformer,
|
|
1120
|
+
options: {
|
|
1121
|
+
absorb: true,
|
|
1122
|
+
constant: true,
|
|
1123
|
+
escape: false
|
|
1124
|
+
// Match CheckerProgrammer - this is key!
|
|
1125
|
+
},
|
|
1126
|
+
collection: new import_MetadataCollection.MetadataCollection({
|
|
1127
|
+
replace: import_MetadataCollection.MetadataCollection.replace
|
|
1128
|
+
}),
|
|
1129
|
+
type
|
|
1130
|
+
});
|
|
1131
|
+
if (!metadataResult.success) {
|
|
1132
|
+
const errors = metadataResult.errors.map((e) => `${e.name}: ${e.messages.join(", ")}`).join("; ");
|
|
1133
|
+
throw new Error(`Typia metadata analysis failed: ${errors}`);
|
|
1134
|
+
}
|
|
1135
|
+
const rawCollection = import_JsonSchemasProgrammer.JsonSchemasProgrammer.write({
|
|
1136
|
+
version: "3.1",
|
|
1137
|
+
metadatas: [metadataResult.data]
|
|
1138
|
+
});
|
|
1139
|
+
const collection = cleanJsonSchemaCollection(rawCollection);
|
|
1140
|
+
return import_typescript4.default.factory.createAsExpression(
|
|
1141
|
+
import_LiteralFactory.LiteralFactory.write(collection),
|
|
1142
|
+
import_typescript4.default.factory.createKeywordTypeNode(import_typescript4.default.SyntaxKind.AnyKeyword)
|
|
1143
|
+
);
|
|
1144
|
+
};
|
|
1145
|
+
var typesToArgsLength = /* @__PURE__ */ new Map([
|
|
1146
|
+
["OlapTable", 2],
|
|
1147
|
+
["Stream", 2],
|
|
1148
|
+
["DeadLetterQueue", 2],
|
|
1149
|
+
["IngestPipeline", 2],
|
|
1150
|
+
["IngestApi", 2],
|
|
1151
|
+
["Api", 2],
|
|
1152
|
+
["MaterializedView", 1],
|
|
1153
|
+
["Task", 2]
|
|
1154
|
+
]);
|
|
1155
|
+
var isNewMooseResourceWithTypeParam = (node, checker) => {
|
|
1156
|
+
if (!import_typescript5.default.isNewExpression(node)) {
|
|
1157
|
+
return false;
|
|
1158
|
+
}
|
|
1159
|
+
const declaration = checker.getResolvedSignature(node)?.declaration;
|
|
1160
|
+
if (!declaration || !isMooseFile(declaration.getSourceFile())) {
|
|
1161
|
+
return false;
|
|
1162
|
+
}
|
|
1163
|
+
const sym = checker.getSymbolAtLocation(node.expression);
|
|
1164
|
+
const typeName = sym?.name ?? "";
|
|
1165
|
+
if (!typesToArgsLength.has(typeName)) {
|
|
1166
|
+
return false;
|
|
1167
|
+
}
|
|
1168
|
+
if (!node.arguments) {
|
|
1169
|
+
return false;
|
|
1170
|
+
}
|
|
1171
|
+
const expectedArgLength = typesToArgsLength.get(typeName);
|
|
1172
|
+
const actualArgLength = node.arguments.length;
|
|
1173
|
+
const isUntransformed = actualArgLength === expectedArgLength - 1 || // name only
|
|
1174
|
+
actualArgLength === expectedArgLength;
|
|
1175
|
+
return isUntransformed && node.typeArguments?.length === 1;
|
|
1176
|
+
};
|
|
1177
|
+
var parseAsAny = (s) => import_typescript5.factory.createAsExpression(
|
|
1178
|
+
import_typescript5.factory.createCallExpression(
|
|
1179
|
+
import_typescript5.factory.createPropertyAccessExpression(
|
|
1180
|
+
import_typescript5.factory.createIdentifier("JSON"),
|
|
1181
|
+
import_typescript5.factory.createIdentifier("parse")
|
|
1182
|
+
),
|
|
1183
|
+
void 0,
|
|
1184
|
+
[import_typescript5.factory.createStringLiteral(s)]
|
|
1185
|
+
),
|
|
1186
|
+
import_typescript5.factory.createKeywordTypeNode(import_typescript5.default.SyntaxKind.AnyKeyword)
|
|
1187
|
+
);
|
|
1188
|
+
var transformNewMooseResource = (node, checker, ctx) => {
|
|
1189
|
+
const typeName = checker.getSymbolAtLocation(node.expression).name;
|
|
1190
|
+
const typeNode = node.typeArguments[0];
|
|
1191
|
+
let ingestPipelineHasTable = true;
|
|
1192
|
+
if (typeName === "IngestPipeline" && node.arguments && node.arguments.length >= 2) {
|
|
1193
|
+
const configArg = node.arguments[1];
|
|
1194
|
+
if (import_typescript5.default.isObjectLiteralExpression(configArg)) {
|
|
1195
|
+
const tableProperty = configArg.properties.find(
|
|
1196
|
+
(prop) => import_typescript5.default.isPropertyAssignment(prop) && import_typescript5.default.isIdentifier(prop.name) && prop.name.text === "table"
|
|
1197
|
+
);
|
|
1198
|
+
if (tableProperty) {
|
|
1199
|
+
const tableValue = tableProperty.initializer;
|
|
1200
|
+
ingestPipelineHasTable = tableValue.kind !== import_typescript5.default.SyntaxKind.FalseKeyword;
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
const allowIndexSignatures = ["IngestApi", "Stream"].includes(typeName) || typeName === "IngestPipeline" && !ingestPipelineHasTable;
|
|
1205
|
+
const typeAtLocation = checker.getTypeAtLocation(typeNode);
|
|
1206
|
+
const indexSignatures = checker.getIndexInfosOfType(typeAtLocation);
|
|
1207
|
+
const hasIndexSignature = allowIndexSignatures && indexSignatures.length > 0;
|
|
1208
|
+
if (typeName === "IngestPipeline" && ingestPipelineHasTable && indexSignatures.length > 0) {
|
|
1209
|
+
throw new Error(
|
|
1210
|
+
`IngestPipeline cannot use a type with index signatures when 'table' is configured. Extra fields would be silently dropped when writing to the ClickHouse table. Either:
|
|
1211
|
+
1. Remove the index signature from your type to use a fixed schema, or
|
|
1212
|
+
2. Set 'table: false' in your IngestPipeline config if you only need the API and stream`
|
|
1213
|
+
);
|
|
1214
|
+
}
|
|
1215
|
+
const typiaCtx = ctx.typiaContext;
|
|
1216
|
+
let internalArguments;
|
|
1217
|
+
if (typeName === "DeadLetterQueue") {
|
|
1218
|
+
internalArguments = [generateAssertFunction(typiaCtx, typeAtLocation)];
|
|
1219
|
+
} else {
|
|
1220
|
+
internalArguments = [
|
|
1221
|
+
generateJsonSchemas(typiaCtx, typeAtLocation),
|
|
1222
|
+
parseAsAny(
|
|
1223
|
+
JSON.stringify(
|
|
1224
|
+
toColumns(typeAtLocation, checker, {
|
|
1225
|
+
allowIndexSignatures
|
|
1226
|
+
})
|
|
1227
|
+
)
|
|
1228
|
+
)
|
|
1229
|
+
];
|
|
1230
|
+
}
|
|
1231
|
+
const resourceName = checker.getSymbolAtLocation(node.expression).name;
|
|
1232
|
+
const argLength = typesToArgsLength.get(resourceName);
|
|
1233
|
+
const needsExtraArg = node.arguments.length === argLength - 1;
|
|
1234
|
+
let updatedArgs = [
|
|
1235
|
+
...node.arguments,
|
|
1236
|
+
...needsExtraArg ? [import_typescript5.factory.createObjectLiteralExpression([], false)] : [],
|
|
1237
|
+
...internalArguments
|
|
1238
|
+
];
|
|
1239
|
+
if (resourceName === "OlapTable" || resourceName === "IngestPipeline") {
|
|
1240
|
+
const validatorsObject = import_typescript5.factory.createObjectLiteralExpression(
|
|
1241
|
+
[
|
|
1242
|
+
import_typescript5.factory.createPropertyAssignment(
|
|
1243
|
+
import_typescript5.factory.createIdentifier("validate"),
|
|
1244
|
+
wrapValidateFunction(
|
|
1245
|
+
generateValidateFunction(typiaCtx, typeAtLocation)
|
|
1246
|
+
)
|
|
1247
|
+
),
|
|
1248
|
+
import_typescript5.factory.createPropertyAssignment(
|
|
1249
|
+
import_typescript5.factory.createIdentifier("assert"),
|
|
1250
|
+
generateAssertFunction(typiaCtx, typeAtLocation)
|
|
1251
|
+
),
|
|
1252
|
+
import_typescript5.factory.createPropertyAssignment(
|
|
1253
|
+
import_typescript5.factory.createIdentifier("is"),
|
|
1254
|
+
generateIsFunction(typiaCtx, typeAtLocation)
|
|
1255
|
+
)
|
|
1256
|
+
],
|
|
1257
|
+
true
|
|
1258
|
+
);
|
|
1259
|
+
updatedArgs = [...updatedArgs, validatorsObject];
|
|
1260
|
+
if (resourceName === "IngestPipeline") {
|
|
1261
|
+
updatedArgs = [
|
|
1262
|
+
...updatedArgs,
|
|
1263
|
+
hasIndexSignature ? import_typescript5.factory.createTrue() : import_typescript5.factory.createFalse()
|
|
1264
|
+
];
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
if (resourceName === "IngestApi" || resourceName === "Stream") {
|
|
1268
|
+
updatedArgs = [
|
|
1269
|
+
...updatedArgs,
|
|
1270
|
+
import_typescript5.factory.createIdentifier("undefined"),
|
|
1271
|
+
// validators (not used for these types)
|
|
1272
|
+
hasIndexSignature ? import_typescript5.factory.createTrue() : import_typescript5.factory.createFalse()
|
|
1273
|
+
];
|
|
1274
|
+
}
|
|
1275
|
+
return import_typescript5.default.factory.updateNewExpression(
|
|
1276
|
+
node,
|
|
1277
|
+
node.expression,
|
|
1278
|
+
node.typeArguments,
|
|
1279
|
+
updatedArgs
|
|
1280
|
+
);
|
|
1281
|
+
};
|
|
1282
|
+
var wrapValidateFunction = (validateFn) => {
|
|
1283
|
+
return import_typescript5.factory.createArrowFunction(
|
|
1284
|
+
void 0,
|
|
1285
|
+
void 0,
|
|
1286
|
+
[
|
|
1287
|
+
import_typescript5.factory.createParameterDeclaration(
|
|
1288
|
+
void 0,
|
|
1289
|
+
void 0,
|
|
1290
|
+
import_typescript5.factory.createIdentifier("data"),
|
|
1291
|
+
void 0,
|
|
1292
|
+
import_typescript5.factory.createKeywordTypeNode(import_typescript5.default.SyntaxKind.UnknownKeyword),
|
|
1293
|
+
void 0
|
|
1294
|
+
)
|
|
1295
|
+
],
|
|
1296
|
+
void 0,
|
|
1297
|
+
import_typescript5.factory.createToken(import_typescript5.default.SyntaxKind.EqualsGreaterThanToken),
|
|
1298
|
+
import_typescript5.factory.createBlock(
|
|
1299
|
+
[
|
|
1300
|
+
import_typescript5.factory.createVariableStatement(
|
|
1301
|
+
void 0,
|
|
1302
|
+
import_typescript5.factory.createVariableDeclarationList(
|
|
1303
|
+
[
|
|
1304
|
+
import_typescript5.factory.createVariableDeclaration(
|
|
1305
|
+
import_typescript5.factory.createIdentifier("result"),
|
|
1306
|
+
void 0,
|
|
1307
|
+
void 0,
|
|
1308
|
+
import_typescript5.factory.createCallExpression(validateFn, void 0, [
|
|
1309
|
+
import_typescript5.factory.createIdentifier("data")
|
|
1310
|
+
])
|
|
1311
|
+
)
|
|
1312
|
+
],
|
|
1313
|
+
import_typescript5.default.NodeFlags.Const
|
|
1314
|
+
)
|
|
1315
|
+
),
|
|
1316
|
+
import_typescript5.factory.createReturnStatement(
|
|
1317
|
+
import_typescript5.factory.createObjectLiteralExpression(
|
|
1318
|
+
[
|
|
1319
|
+
import_typescript5.factory.createPropertyAssignment(
|
|
1320
|
+
import_typescript5.factory.createIdentifier("success"),
|
|
1321
|
+
import_typescript5.factory.createPropertyAccessExpression(
|
|
1322
|
+
import_typescript5.factory.createIdentifier("result"),
|
|
1323
|
+
import_typescript5.factory.createIdentifier("success")
|
|
1324
|
+
)
|
|
1325
|
+
),
|
|
1326
|
+
import_typescript5.factory.createPropertyAssignment(
|
|
1327
|
+
import_typescript5.factory.createIdentifier("data"),
|
|
1328
|
+
import_typescript5.factory.createConditionalExpression(
|
|
1329
|
+
import_typescript5.factory.createPropertyAccessExpression(
|
|
1330
|
+
import_typescript5.factory.createIdentifier("result"),
|
|
1331
|
+
import_typescript5.factory.createIdentifier("success")
|
|
1332
|
+
),
|
|
1333
|
+
import_typescript5.factory.createToken(import_typescript5.default.SyntaxKind.QuestionToken),
|
|
1334
|
+
import_typescript5.factory.createPropertyAccessExpression(
|
|
1335
|
+
import_typescript5.factory.createIdentifier("result"),
|
|
1336
|
+
import_typescript5.factory.createIdentifier("data")
|
|
1337
|
+
),
|
|
1338
|
+
import_typescript5.factory.createToken(import_typescript5.default.SyntaxKind.ColonToken),
|
|
1339
|
+
import_typescript5.factory.createIdentifier("undefined")
|
|
1340
|
+
)
|
|
1341
|
+
),
|
|
1342
|
+
import_typescript5.factory.createPropertyAssignment(
|
|
1343
|
+
import_typescript5.factory.createIdentifier("errors"),
|
|
1344
|
+
import_typescript5.factory.createConditionalExpression(
|
|
1345
|
+
import_typescript5.factory.createPropertyAccessExpression(
|
|
1346
|
+
import_typescript5.factory.createIdentifier("result"),
|
|
1347
|
+
import_typescript5.factory.createIdentifier("success")
|
|
1348
|
+
),
|
|
1349
|
+
import_typescript5.factory.createToken(import_typescript5.default.SyntaxKind.QuestionToken),
|
|
1350
|
+
import_typescript5.factory.createIdentifier("undefined"),
|
|
1351
|
+
import_typescript5.factory.createToken(import_typescript5.default.SyntaxKind.ColonToken),
|
|
1352
|
+
import_typescript5.factory.createPropertyAccessExpression(
|
|
1353
|
+
import_typescript5.factory.createIdentifier("result"),
|
|
1354
|
+
import_typescript5.factory.createIdentifier("errors")
|
|
1355
|
+
)
|
|
1356
|
+
)
|
|
1357
|
+
)
|
|
1358
|
+
],
|
|
1359
|
+
true
|
|
1360
|
+
)
|
|
1361
|
+
)
|
|
1362
|
+
],
|
|
1363
|
+
true
|
|
1364
|
+
)
|
|
1365
|
+
);
|
|
1366
|
+
};
|
|
1367
|
+
var import_typescript6 = __toESM(require("typescript"));
|
|
1368
|
+
var isApiV2 = (node, checker) => {
|
|
1369
|
+
if (!import_typescript6.default.isNewExpression(node)) {
|
|
1370
|
+
return false;
|
|
1371
|
+
}
|
|
1372
|
+
const declaration = checker.getResolvedSignature(node)?.declaration;
|
|
1373
|
+
if (!declaration || !isMooseFile(declaration.getSourceFile())) {
|
|
1374
|
+
return false;
|
|
1375
|
+
}
|
|
1376
|
+
const sym = checker.getSymbolAtLocation(node.expression);
|
|
1377
|
+
return sym?.name === "Api" || sym?.name === "ConsumptionApi";
|
|
1378
|
+
};
|
|
1379
|
+
var transformApiV2 = (node, checker, ctx) => {
|
|
1380
|
+
if (!isApiV2(node, checker)) {
|
|
1381
|
+
return node;
|
|
1382
|
+
}
|
|
1383
|
+
if (!node.arguments || node.arguments.length < 2 || !node.typeArguments) {
|
|
1384
|
+
return node;
|
|
1385
|
+
}
|
|
1386
|
+
const typiaCtx = ctx.typiaContext;
|
|
1387
|
+
const typeNode = node.typeArguments[0];
|
|
1388
|
+
const responseTypeNode = node.typeArguments[1] || import_typescript6.factory.createKeywordTypeNode(import_typescript6.default.SyntaxKind.AnyKeyword);
|
|
1389
|
+
const inputType = checker.getTypeAtLocation(typeNode);
|
|
1390
|
+
const responseType = checker.getTypeAtLocation(responseTypeNode);
|
|
1391
|
+
const handlerFunc = node.arguments[1];
|
|
1392
|
+
const assertQueryFunc = generateHttpAssertQueryFunction(typiaCtx, inputType);
|
|
1393
|
+
const wrappedHandler = import_typescript6.factory.createArrowFunction(
|
|
1394
|
+
void 0,
|
|
1395
|
+
void 0,
|
|
1396
|
+
[
|
|
1397
|
+
import_typescript6.factory.createParameterDeclaration(
|
|
1398
|
+
void 0,
|
|
1399
|
+
void 0,
|
|
1400
|
+
import_typescript6.factory.createIdentifier("params"),
|
|
1401
|
+
void 0,
|
|
1402
|
+
void 0,
|
|
1403
|
+
void 0
|
|
1404
|
+
),
|
|
1405
|
+
import_typescript6.factory.createParameterDeclaration(
|
|
1406
|
+
void 0,
|
|
1407
|
+
void 0,
|
|
1408
|
+
import_typescript6.factory.createIdentifier("utils"),
|
|
1409
|
+
void 0,
|
|
1410
|
+
void 0,
|
|
1411
|
+
void 0
|
|
1412
|
+
)
|
|
1413
|
+
],
|
|
1414
|
+
void 0,
|
|
1415
|
+
import_typescript6.factory.createToken(import_typescript6.default.SyntaxKind.EqualsGreaterThanToken),
|
|
1416
|
+
import_typescript6.factory.createBlock(
|
|
1417
|
+
[
|
|
1418
|
+
// const assertGuard = <generated http assert query function>
|
|
1419
|
+
import_typescript6.factory.createVariableStatement(
|
|
1420
|
+
void 0,
|
|
1421
|
+
import_typescript6.factory.createVariableDeclarationList(
|
|
1422
|
+
[
|
|
1423
|
+
import_typescript6.factory.createVariableDeclaration(
|
|
1424
|
+
import_typescript6.factory.createIdentifier("assertGuard"),
|
|
1425
|
+
void 0,
|
|
1426
|
+
void 0,
|
|
1427
|
+
assertQueryFunc
|
|
1428
|
+
)
|
|
1429
|
+
],
|
|
1430
|
+
import_typescript6.default.NodeFlags.Const
|
|
1431
|
+
)
|
|
1432
|
+
),
|
|
1433
|
+
// const searchParams = new URLSearchParams(params as any)
|
|
1434
|
+
import_typescript6.factory.createVariableStatement(
|
|
1435
|
+
void 0,
|
|
1436
|
+
import_typescript6.factory.createVariableDeclarationList(
|
|
1437
|
+
[
|
|
1438
|
+
import_typescript6.factory.createVariableDeclaration(
|
|
1439
|
+
import_typescript6.factory.createIdentifier("searchParams"),
|
|
1440
|
+
void 0,
|
|
1441
|
+
void 0,
|
|
1442
|
+
import_typescript6.factory.createNewExpression(
|
|
1443
|
+
import_typescript6.factory.createIdentifier("URLSearchParams"),
|
|
1444
|
+
void 0,
|
|
1445
|
+
[
|
|
1446
|
+
import_typescript6.factory.createAsExpression(
|
|
1447
|
+
import_typescript6.factory.createIdentifier("params"),
|
|
1448
|
+
import_typescript6.factory.createKeywordTypeNode(import_typescript6.default.SyntaxKind.AnyKeyword)
|
|
1449
|
+
)
|
|
1450
|
+
]
|
|
1451
|
+
)
|
|
1452
|
+
)
|
|
1453
|
+
],
|
|
1454
|
+
import_typescript6.default.NodeFlags.Const
|
|
1455
|
+
)
|
|
1456
|
+
),
|
|
1457
|
+
// const processedParams = assertGuard(searchParams)
|
|
1458
|
+
import_typescript6.factory.createVariableStatement(
|
|
1459
|
+
void 0,
|
|
1460
|
+
import_typescript6.factory.createVariableDeclarationList(
|
|
1461
|
+
[
|
|
1462
|
+
import_typescript6.factory.createVariableDeclaration(
|
|
1463
|
+
import_typescript6.factory.createIdentifier("processedParams"),
|
|
1464
|
+
void 0,
|
|
1465
|
+
void 0,
|
|
1466
|
+
import_typescript6.factory.createCallExpression(
|
|
1467
|
+
import_typescript6.factory.createIdentifier("assertGuard"),
|
|
1468
|
+
void 0,
|
|
1469
|
+
[import_typescript6.factory.createIdentifier("searchParams")]
|
|
1470
|
+
)
|
|
1471
|
+
)
|
|
1472
|
+
],
|
|
1473
|
+
import_typescript6.default.NodeFlags.Const
|
|
1474
|
+
)
|
|
1475
|
+
),
|
|
1476
|
+
import_typescript6.factory.createVariableStatement(
|
|
1477
|
+
void 0,
|
|
1478
|
+
import_typescript6.factory.createVariableDeclarationList(
|
|
1479
|
+
[
|
|
1480
|
+
import_typescript6.factory.createVariableDeclaration(
|
|
1481
|
+
import_typescript6.factory.createIdentifier("originalHandler"),
|
|
1482
|
+
void 0,
|
|
1483
|
+
import_typescript6.factory.createFunctionTypeNode(
|
|
1484
|
+
void 0,
|
|
1485
|
+
[
|
|
1486
|
+
import_typescript6.factory.createParameterDeclaration(
|
|
1487
|
+
void 0,
|
|
1488
|
+
void 0,
|
|
1489
|
+
"params",
|
|
1490
|
+
void 0,
|
|
1491
|
+
typeNode
|
|
1492
|
+
),
|
|
1493
|
+
import_typescript6.factory.createParameterDeclaration(
|
|
1494
|
+
void 0,
|
|
1495
|
+
void 0,
|
|
1496
|
+
"utils",
|
|
1497
|
+
void 0,
|
|
1498
|
+
import_typescript6.factory.createImportTypeNode(
|
|
1499
|
+
import_typescript6.factory.createLiteralTypeNode(
|
|
1500
|
+
import_typescript6.factory.createStringLiteral("@514labs/moose-lib")
|
|
1501
|
+
),
|
|
1502
|
+
void 0,
|
|
1503
|
+
import_typescript6.factory.createIdentifier("ApiUtil"),
|
|
1504
|
+
[],
|
|
1505
|
+
false
|
|
1506
|
+
)
|
|
1507
|
+
)
|
|
1508
|
+
],
|
|
1509
|
+
import_typescript6.factory.createKeywordTypeNode(import_typescript6.SyntaxKind.AnyKeyword)
|
|
1510
|
+
),
|
|
1511
|
+
import_typescript6.factory.createParenthesizedExpression(handlerFunc)
|
|
1512
|
+
)
|
|
1513
|
+
],
|
|
1514
|
+
import_typescript6.default.NodeFlags.Const
|
|
1515
|
+
)
|
|
1516
|
+
),
|
|
1517
|
+
// return originalHandler(processedParams, utils)
|
|
1518
|
+
import_typescript6.factory.createReturnStatement(
|
|
1519
|
+
import_typescript6.factory.createCallExpression(
|
|
1520
|
+
import_typescript6.factory.createIdentifier("originalHandler"),
|
|
1521
|
+
void 0,
|
|
1522
|
+
[
|
|
1523
|
+
import_typescript6.factory.createIdentifier("processedParams"),
|
|
1524
|
+
import_typescript6.factory.createIdentifier("utils")
|
|
1525
|
+
]
|
|
1526
|
+
)
|
|
1527
|
+
)
|
|
1528
|
+
],
|
|
1529
|
+
true
|
|
1530
|
+
)
|
|
1531
|
+
);
|
|
1532
|
+
const inputSchemaArg = node.arguments.length > 3 ? node.arguments[3] : generateJsonSchemas(typiaCtx, inputType);
|
|
1533
|
+
const responseSchemaArg = generateJsonSchemas(typiaCtx, responseType);
|
|
1534
|
+
const inputColumnsArg = toColumns(inputType, checker);
|
|
1535
|
+
const configArg = node.arguments.length > 2 ? node.arguments[2] : import_typescript6.factory.createObjectLiteralExpression([], false);
|
|
1536
|
+
return import_typescript6.factory.updateNewExpression(
|
|
1537
|
+
node,
|
|
1538
|
+
node.expression,
|
|
1539
|
+
node.typeArguments,
|
|
1540
|
+
[
|
|
1541
|
+
node.arguments[0],
|
|
1542
|
+
// name
|
|
1543
|
+
wrappedHandler,
|
|
1544
|
+
// wrapped handler
|
|
1545
|
+
configArg,
|
|
1546
|
+
// config object
|
|
1547
|
+
inputSchemaArg,
|
|
1548
|
+
// input schema
|
|
1549
|
+
parseAsAny(JSON.stringify(inputColumnsArg)),
|
|
1550
|
+
// input columns
|
|
1551
|
+
responseSchemaArg
|
|
1552
|
+
// response schema
|
|
1553
|
+
]
|
|
1554
|
+
);
|
|
1555
|
+
};
|
|
1556
|
+
var import_client = require("@clickhouse/client");
|
|
1557
|
+
var import_kafka_javascript = require_kafka_javascript();
|
|
1558
|
+
var { Kafka } = import_kafka_javascript.KafkaJS;
|
|
1559
|
+
function isTruthy(value) {
|
|
1560
|
+
if (!value) return false;
|
|
1561
|
+
switch (value.trim().toLowerCase()) {
|
|
1562
|
+
case "1":
|
|
1563
|
+
case "true":
|
|
1564
|
+
case "yes":
|
|
1565
|
+
case "on":
|
|
1566
|
+
return true;
|
|
1567
|
+
default:
|
|
1568
|
+
return false;
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
var compilerLog = (message) => {
|
|
1572
|
+
if (!isTruthy(process.env.MOOSE_DISABLE_COMPILER_LOGS)) {
|
|
1573
|
+
console.log(message);
|
|
1574
|
+
}
|
|
1575
|
+
};
|
|
1576
|
+
var applyTransformation = (node, ctx) => {
|
|
1577
|
+
if (isApiV2(node, ctx.typeChecker)) {
|
|
1578
|
+
compilerLog("[CompilerPlugin] Found API v2, transforming...");
|
|
1579
|
+
return transformApiV2(node, ctx.typeChecker, ctx);
|
|
1580
|
+
}
|
|
1581
|
+
if (isNewMooseResourceWithTypeParam(node, ctx.typeChecker)) {
|
|
1582
|
+
compilerLog(
|
|
1583
|
+
"[CompilerPlugin] Found Moose resource with type param, transforming..."
|
|
1584
|
+
);
|
|
1585
|
+
return transformNewMooseResource(node, ctx.typeChecker, ctx);
|
|
1586
|
+
}
|
|
1587
|
+
return void 0;
|
|
1588
|
+
};
|
|
1589
|
+
var transform = (typeChecker, program) => (transformationContext) => (sourceFile) => {
|
|
1590
|
+
compilerLog(
|
|
1591
|
+
`
|
|
1592
|
+
[CompilerPlugin] ========== Processing file: ${sourceFile.fileName} ==========`
|
|
1593
|
+
);
|
|
1594
|
+
let transformationCount = 0;
|
|
1595
|
+
const typiaContext = createTypiaContext(
|
|
1596
|
+
program,
|
|
1597
|
+
transformationContext,
|
|
1598
|
+
sourceFile
|
|
1599
|
+
);
|
|
1600
|
+
const ctx = {
|
|
1601
|
+
typeChecker,
|
|
1602
|
+
program,
|
|
1603
|
+
typiaContext
|
|
1604
|
+
};
|
|
1605
|
+
const visitNode = (node) => {
|
|
1606
|
+
const transformed = applyTransformation(node, ctx);
|
|
1607
|
+
if (transformed !== void 0) {
|
|
1608
|
+
transformationCount++;
|
|
1609
|
+
compilerLog(
|
|
1610
|
+
`[CompilerPlugin] Transformation #${transformationCount} applied at position ${node.pos}`
|
|
1611
|
+
);
|
|
1612
|
+
}
|
|
1613
|
+
const result = transformed ?? node;
|
|
1614
|
+
return import_typescript7.default.visitEachChild(result, visitNode, transformationContext);
|
|
1615
|
+
};
|
|
1616
|
+
const transformedSourceFile = import_typescript7.default.visitEachChild(
|
|
1617
|
+
sourceFile,
|
|
1618
|
+
visitNode,
|
|
1619
|
+
transformationContext
|
|
1620
|
+
);
|
|
1621
|
+
compilerLog(
|
|
1622
|
+
`[CompilerPlugin] Total transformations applied: ${transformationCount}`
|
|
1623
|
+
);
|
|
1624
|
+
const typiaImports = typiaContext.importer.toStatements();
|
|
1625
|
+
if (typiaImports.length === 0) {
|
|
1626
|
+
compilerLog(
|
|
1627
|
+
`[CompilerPlugin] ========== Completed processing ${sourceFile.fileName} (no import needed) ==========
|
|
1628
|
+
`
|
|
1629
|
+
);
|
|
1630
|
+
return transformedSourceFile;
|
|
1631
|
+
}
|
|
1632
|
+
compilerLog(
|
|
1633
|
+
`[CompilerPlugin] ========== Completed processing ${sourceFile.fileName} (with import) ==========
|
|
1634
|
+
`
|
|
1635
|
+
);
|
|
1636
|
+
return import_typescript7.factory.updateSourceFile(
|
|
1637
|
+
transformedSourceFile,
|
|
1638
|
+
import_typescript7.factory.createNodeArray([
|
|
1639
|
+
...typiaImports,
|
|
1640
|
+
...transformedSourceFile.statements
|
|
1641
|
+
])
|
|
1642
|
+
);
|
|
1643
|
+
};
|
|
1644
|
+
var compilerPlugin_default = createTransformer(transform);
|