@514labs/moose-lib 0.6.289 → 0.6.290-ci-8-g57f77993
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/dist/{browserCompatible-B8CAYjv5.d.ts → browserCompatible-BkdnWcKd.d.ts} +1 -1
- package/dist/{browserCompatible-ChWHzgtb.d.mts → browserCompatible-DPtRRKkt.d.mts} +1 -1
- package/dist/browserCompatible.d.mts +2 -2
- package/dist/browserCompatible.d.ts +2 -2
- package/dist/browserCompatible.js +2443 -2160
- package/dist/browserCompatible.js.map +1 -1
- package/dist/browserCompatible.mjs +2440 -2159
- package/dist/browserCompatible.mjs.map +1 -1
- package/dist/dmv2/index.d.mts +1 -1
- package/dist/dmv2/index.d.ts +1 -1
- package/dist/dmv2/index.js +2334 -2051
- package/dist/dmv2/index.js.map +1 -1
- package/dist/dmv2/index.mjs +2299 -2018
- package/dist/dmv2/index.mjs.map +1 -1
- package/dist/{index-rQOQo9sv.d.mts → index-BpS8KBOP.d.mts} +9 -1
- package/dist/{index-rQOQo9sv.d.ts → index-BpS8KBOP.d.ts} +9 -1
- package/dist/index.d.mts +31 -7
- package/dist/index.d.ts +31 -7
- package/dist/index.js +3037 -2718
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2938 -2618
- package/dist/index.mjs.map +1 -1
- package/dist/moose-runner.js +1702 -1136
- package/dist/moose-runner.js.map +1 -1
- package/dist/moose-runner.mjs +1693 -1129
- package/dist/moose-runner.mjs.map +1 -1
- package/package.json +1 -1
package/dist/moose-runner.js
CHANGED
|
@@ -9,6 +9,10 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
|
9
9
|
var __esm = (fn, res) => function __init() {
|
|
10
10
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
11
11
|
};
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
12
16
|
var __copyProps = (to, from, except, desc) => {
|
|
13
17
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
18
|
for (let key of __getOwnPropNames(from))
|
|
@@ -26,6 +30,344 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
30
|
mod
|
|
27
31
|
));
|
|
28
32
|
|
|
33
|
+
// src/dmv2/utils/stackTrace.ts
|
|
34
|
+
var init_stackTrace = __esm({
|
|
35
|
+
"src/dmv2/utils/stackTrace.ts"() {
|
|
36
|
+
"use strict";
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// src/dmv2/typedBase.ts
|
|
41
|
+
var init_typedBase = __esm({
|
|
42
|
+
"src/dmv2/typedBase.ts"() {
|
|
43
|
+
"use strict";
|
|
44
|
+
init_stackTrace();
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// src/dataModels/dataModelTypes.ts
|
|
49
|
+
var init_dataModelTypes = __esm({
|
|
50
|
+
"src/dataModels/dataModelTypes.ts"() {
|
|
51
|
+
"use strict";
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// src/sqlHelpers.ts
|
|
56
|
+
function sql(strings, ...values) {
|
|
57
|
+
return new Sql(strings, values);
|
|
58
|
+
}
|
|
59
|
+
function createClickhouseParameter(parameterIndex, value) {
|
|
60
|
+
return `{p${parameterIndex}:${mapToClickHouseType(value)}}`;
|
|
61
|
+
}
|
|
62
|
+
function emptyIfUndefined(value) {
|
|
63
|
+
return value === void 0 ? "" : value;
|
|
64
|
+
}
|
|
65
|
+
var isTable, isColumn, instanceofSql, Sql, toQuery, toQueryPreview, getValueFromParameter, mapToClickHouseType;
|
|
66
|
+
var init_sqlHelpers = __esm({
|
|
67
|
+
"src/sqlHelpers.ts"() {
|
|
68
|
+
"use strict";
|
|
69
|
+
isTable = (value) => typeof value === "object" && value !== null && "kind" in value && value.kind === "OlapTable";
|
|
70
|
+
isColumn = (value) => typeof value === "object" && "name" in value && "annotations" in value;
|
|
71
|
+
instanceofSql = (value) => typeof value === "object" && "values" in value && "strings" in value;
|
|
72
|
+
Sql = class {
|
|
73
|
+
values;
|
|
74
|
+
strings;
|
|
75
|
+
constructor(rawStrings, rawValues) {
|
|
76
|
+
if (rawStrings.length - 1 !== rawValues.length) {
|
|
77
|
+
if (rawStrings.length === 0) {
|
|
78
|
+
throw new TypeError("Expected at least 1 string");
|
|
79
|
+
}
|
|
80
|
+
throw new TypeError(
|
|
81
|
+
`Expected ${rawStrings.length} strings to have ${rawStrings.length - 1} values`
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
const valuesLength = rawValues.reduce(
|
|
85
|
+
(len, value) => len + (instanceofSql(value) ? value.values.length : isColumn(value) || isTable(value) ? 0 : 1),
|
|
86
|
+
0
|
|
87
|
+
);
|
|
88
|
+
this.values = new Array(valuesLength);
|
|
89
|
+
this.strings = new Array(valuesLength + 1);
|
|
90
|
+
this.strings[0] = rawStrings[0];
|
|
91
|
+
let i = 0, pos = 0;
|
|
92
|
+
while (i < rawValues.length) {
|
|
93
|
+
const child = rawValues[i++];
|
|
94
|
+
const rawString = rawStrings[i];
|
|
95
|
+
if (instanceofSql(child)) {
|
|
96
|
+
this.strings[pos] += child.strings[0];
|
|
97
|
+
let childIndex = 0;
|
|
98
|
+
while (childIndex < child.values.length) {
|
|
99
|
+
this.values[pos++] = child.values[childIndex++];
|
|
100
|
+
this.strings[pos] = child.strings[childIndex];
|
|
101
|
+
}
|
|
102
|
+
this.strings[pos] += rawString;
|
|
103
|
+
} else if (isColumn(child)) {
|
|
104
|
+
const aggregationFunction = child.annotations.find(
|
|
105
|
+
([k, _]) => k === "aggregationFunction"
|
|
106
|
+
);
|
|
107
|
+
if (aggregationFunction !== void 0) {
|
|
108
|
+
this.strings[pos] += `${aggregationFunction[1].functionName}Merge(\`${child.name}\`)`;
|
|
109
|
+
} else {
|
|
110
|
+
this.strings[pos] += `\`${child.name}\``;
|
|
111
|
+
}
|
|
112
|
+
this.strings[pos] += rawString;
|
|
113
|
+
} else if (isTable(child)) {
|
|
114
|
+
if (child.config.database) {
|
|
115
|
+
this.strings[pos] += `\`${child.config.database}\`.\`${child.name}\``;
|
|
116
|
+
} else {
|
|
117
|
+
this.strings[pos] += `\`${child.name}\``;
|
|
118
|
+
}
|
|
119
|
+
this.strings[pos] += rawString;
|
|
120
|
+
} else {
|
|
121
|
+
this.values[pos++] = child;
|
|
122
|
+
this.strings[pos] = rawString;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
toQuery = (sql3) => {
|
|
128
|
+
const parameterizedStubs = sql3.values.map(
|
|
129
|
+
(v, i) => createClickhouseParameter(i, v)
|
|
130
|
+
);
|
|
131
|
+
const query = sql3.strings.map(
|
|
132
|
+
(s, i) => s != "" ? `${s}${emptyIfUndefined(parameterizedStubs[i])}` : ""
|
|
133
|
+
).join("");
|
|
134
|
+
const query_params = sql3.values.reduce(
|
|
135
|
+
(acc, v, i) => ({
|
|
136
|
+
...acc,
|
|
137
|
+
[`p${i}`]: getValueFromParameter(v)
|
|
138
|
+
}),
|
|
139
|
+
{}
|
|
140
|
+
);
|
|
141
|
+
return [query, query_params];
|
|
142
|
+
};
|
|
143
|
+
toQueryPreview = (sql3) => {
|
|
144
|
+
try {
|
|
145
|
+
const formatValue = (v) => {
|
|
146
|
+
if (Array.isArray(v)) {
|
|
147
|
+
const [type, val] = v;
|
|
148
|
+
if (type === "Identifier") {
|
|
149
|
+
return `\`${String(val)}\``;
|
|
150
|
+
}
|
|
151
|
+
return `[${v.map((x) => formatValue(x)).join(", ")}]`;
|
|
152
|
+
}
|
|
153
|
+
if (v === null || v === void 0) return "NULL";
|
|
154
|
+
if (typeof v === "string") return `'${v.replace(/'/g, "''")}'`;
|
|
155
|
+
if (typeof v === "number") return String(v);
|
|
156
|
+
if (typeof v === "boolean") return v ? "true" : "false";
|
|
157
|
+
if (v instanceof Date)
|
|
158
|
+
return `'${v.toISOString().replace("T", " ").slice(0, 19)}'`;
|
|
159
|
+
try {
|
|
160
|
+
return JSON.stringify(v);
|
|
161
|
+
} catch {
|
|
162
|
+
return String(v);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
let out = sql3.strings[0] ?? "";
|
|
166
|
+
for (let i = 0; i < sql3.values.length; i++) {
|
|
167
|
+
const val = getValueFromParameter(sql3.values[i]);
|
|
168
|
+
out += formatValue(val);
|
|
169
|
+
out += sql3.strings[i + 1] ?? "";
|
|
170
|
+
}
|
|
171
|
+
return out.replace(/\s+/g, " ").trim();
|
|
172
|
+
} catch (error) {
|
|
173
|
+
console.log(`toQueryPreview error: ${error}`);
|
|
174
|
+
return "/* query preview unavailable */";
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
getValueFromParameter = (value) => {
|
|
178
|
+
if (Array.isArray(value)) {
|
|
179
|
+
const [type, val] = value;
|
|
180
|
+
if (type === "Identifier") return val;
|
|
181
|
+
}
|
|
182
|
+
return value;
|
|
183
|
+
};
|
|
184
|
+
mapToClickHouseType = (value) => {
|
|
185
|
+
if (typeof value === "number") {
|
|
186
|
+
return Number.isInteger(value) ? "Int" : "Float";
|
|
187
|
+
}
|
|
188
|
+
if (typeof value === "boolean") return "Bool";
|
|
189
|
+
if (value instanceof Date) return "DateTime";
|
|
190
|
+
if (Array.isArray(value)) {
|
|
191
|
+
const [type, _] = value;
|
|
192
|
+
return type;
|
|
193
|
+
}
|
|
194
|
+
return "String";
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// src/blocks/helpers.ts
|
|
200
|
+
var init_helpers = __esm({
|
|
201
|
+
"src/blocks/helpers.ts"() {
|
|
202
|
+
"use strict";
|
|
203
|
+
init_sqlHelpers();
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// src/dmv2/sdk/olapTable.ts
|
|
208
|
+
var import_node_stream, import_node_crypto;
|
|
209
|
+
var init_olapTable = __esm({
|
|
210
|
+
"src/dmv2/sdk/olapTable.ts"() {
|
|
211
|
+
"use strict";
|
|
212
|
+
init_typedBase();
|
|
213
|
+
init_dataModelTypes();
|
|
214
|
+
init_helpers();
|
|
215
|
+
init_internal();
|
|
216
|
+
import_node_stream = require("stream");
|
|
217
|
+
import_node_crypto = require("crypto");
|
|
218
|
+
init_sqlHelpers();
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
// src/dmv2/sdk/stream.ts
|
|
223
|
+
var import_node_crypto2;
|
|
224
|
+
var init_stream = __esm({
|
|
225
|
+
"src/dmv2/sdk/stream.ts"() {
|
|
226
|
+
"use strict";
|
|
227
|
+
init_typedBase();
|
|
228
|
+
init_internal();
|
|
229
|
+
import_node_crypto2 = require("crypto");
|
|
230
|
+
init_stackTrace();
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
// src/dmv2/sdk/workflow.ts
|
|
235
|
+
var init_workflow = __esm({
|
|
236
|
+
"src/dmv2/sdk/workflow.ts"() {
|
|
237
|
+
"use strict";
|
|
238
|
+
init_internal();
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
// src/dmv2/sdk/ingestApi.ts
|
|
243
|
+
var init_ingestApi = __esm({
|
|
244
|
+
"src/dmv2/sdk/ingestApi.ts"() {
|
|
245
|
+
"use strict";
|
|
246
|
+
init_typedBase();
|
|
247
|
+
init_internal();
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
// src/dmv2/sdk/consumptionApi.ts
|
|
252
|
+
var init_consumptionApi = __esm({
|
|
253
|
+
"src/dmv2/sdk/consumptionApi.ts"() {
|
|
254
|
+
"use strict";
|
|
255
|
+
init_typedBase();
|
|
256
|
+
init_internal();
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
// src/dmv2/sdk/ingestPipeline.ts
|
|
261
|
+
var init_ingestPipeline = __esm({
|
|
262
|
+
"src/dmv2/sdk/ingestPipeline.ts"() {
|
|
263
|
+
"use strict";
|
|
264
|
+
init_typedBase();
|
|
265
|
+
init_stream();
|
|
266
|
+
init_olapTable();
|
|
267
|
+
init_ingestApi();
|
|
268
|
+
init_helpers();
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
// src/dmv2/sdk/etlPipeline.ts
|
|
273
|
+
var init_etlPipeline = __esm({
|
|
274
|
+
"src/dmv2/sdk/etlPipeline.ts"() {
|
|
275
|
+
"use strict";
|
|
276
|
+
init_workflow();
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
// src/dmv2/sdk/sqlResource.ts
|
|
281
|
+
var init_sqlResource = __esm({
|
|
282
|
+
"src/dmv2/sdk/sqlResource.ts"() {
|
|
283
|
+
"use strict";
|
|
284
|
+
init_internal();
|
|
285
|
+
init_sqlHelpers();
|
|
286
|
+
init_stackTrace();
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
// src/dmv2/sdk/materializedView.ts
|
|
291
|
+
var init_materializedView = __esm({
|
|
292
|
+
"src/dmv2/sdk/materializedView.ts"() {
|
|
293
|
+
"use strict";
|
|
294
|
+
init_helpers();
|
|
295
|
+
init_sqlHelpers();
|
|
296
|
+
init_olapTable();
|
|
297
|
+
init_sqlResource();
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
// src/dmv2/sdk/view.ts
|
|
302
|
+
var init_view = __esm({
|
|
303
|
+
"src/dmv2/sdk/view.ts"() {
|
|
304
|
+
"use strict";
|
|
305
|
+
init_helpers();
|
|
306
|
+
init_sqlHelpers();
|
|
307
|
+
init_sqlResource();
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
// src/dmv2/sdk/lifeCycle.ts
|
|
312
|
+
var init_lifeCycle = __esm({
|
|
313
|
+
"src/dmv2/sdk/lifeCycle.ts"() {
|
|
314
|
+
"use strict";
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
// src/dmv2/sdk/webApp.ts
|
|
319
|
+
var init_webApp = __esm({
|
|
320
|
+
"src/dmv2/sdk/webApp.ts"() {
|
|
321
|
+
"use strict";
|
|
322
|
+
init_internal();
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
// src/dmv2/registry.ts
|
|
327
|
+
var init_registry = __esm({
|
|
328
|
+
"src/dmv2/registry.ts"() {
|
|
329
|
+
"use strict";
|
|
330
|
+
init_internal();
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
// src/dmv2/index.ts
|
|
335
|
+
var init_dmv2 = __esm({
|
|
336
|
+
"src/dmv2/index.ts"() {
|
|
337
|
+
"use strict";
|
|
338
|
+
init_olapTable();
|
|
339
|
+
init_stream();
|
|
340
|
+
init_workflow();
|
|
341
|
+
init_ingestApi();
|
|
342
|
+
init_consumptionApi();
|
|
343
|
+
init_ingestPipeline();
|
|
344
|
+
init_etlPipeline();
|
|
345
|
+
init_materializedView();
|
|
346
|
+
init_sqlResource();
|
|
347
|
+
init_view();
|
|
348
|
+
init_lifeCycle();
|
|
349
|
+
init_webApp();
|
|
350
|
+
init_registry();
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
// src/dataModels/types.ts
|
|
355
|
+
var init_types = __esm({
|
|
356
|
+
"src/dataModels/types.ts"() {
|
|
357
|
+
"use strict";
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
// src/browserCompatible.ts
|
|
362
|
+
var init_browserCompatible = __esm({
|
|
363
|
+
"src/browserCompatible.ts"() {
|
|
364
|
+
"use strict";
|
|
365
|
+
init_dmv2();
|
|
366
|
+
init_types();
|
|
367
|
+
init_sqlHelpers();
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
|
|
29
371
|
// src/commons.ts
|
|
30
372
|
function isTruthy(value) {
|
|
31
373
|
if (!value) return false;
|
|
@@ -155,165 +497,14 @@ var init_commons = __esm({
|
|
|
155
497
|
}
|
|
156
498
|
});
|
|
157
499
|
|
|
158
|
-
// src/
|
|
159
|
-
var
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
var import_process = __toESM(require("process"));
|
|
163
|
-
|
|
164
|
-
// src/sqlHelpers.ts
|
|
165
|
-
var isTable = (value) => typeof value === "object" && value !== null && "kind" in value && value.kind === "OlapTable";
|
|
166
|
-
var isColumn = (value) => typeof value === "object" && "name" in value && "annotations" in value;
|
|
167
|
-
function sql(strings, ...values) {
|
|
168
|
-
return new Sql(strings, values);
|
|
169
|
-
}
|
|
170
|
-
var instanceofSql = (value) => typeof value === "object" && "values" in value && "strings" in value;
|
|
171
|
-
var Sql = class {
|
|
172
|
-
values;
|
|
173
|
-
strings;
|
|
174
|
-
constructor(rawStrings, rawValues) {
|
|
175
|
-
if (rawStrings.length - 1 !== rawValues.length) {
|
|
176
|
-
if (rawStrings.length === 0) {
|
|
177
|
-
throw new TypeError("Expected at least 1 string");
|
|
178
|
-
}
|
|
179
|
-
throw new TypeError(
|
|
180
|
-
`Expected ${rawStrings.length} strings to have ${rawStrings.length - 1} values`
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
const valuesLength = rawValues.reduce(
|
|
184
|
-
(len, value) => len + (instanceofSql(value) ? value.values.length : isColumn(value) || isTable(value) ? 0 : 1),
|
|
185
|
-
0
|
|
186
|
-
);
|
|
187
|
-
this.values = new Array(valuesLength);
|
|
188
|
-
this.strings = new Array(valuesLength + 1);
|
|
189
|
-
this.strings[0] = rawStrings[0];
|
|
190
|
-
let i = 0, pos = 0;
|
|
191
|
-
while (i < rawValues.length) {
|
|
192
|
-
const child = rawValues[i++];
|
|
193
|
-
const rawString = rawStrings[i];
|
|
194
|
-
if (instanceofSql(child)) {
|
|
195
|
-
this.strings[pos] += child.strings[0];
|
|
196
|
-
let childIndex = 0;
|
|
197
|
-
while (childIndex < child.values.length) {
|
|
198
|
-
this.values[pos++] = child.values[childIndex++];
|
|
199
|
-
this.strings[pos] = child.strings[childIndex];
|
|
200
|
-
}
|
|
201
|
-
this.strings[pos] += rawString;
|
|
202
|
-
} else if (isColumn(child)) {
|
|
203
|
-
const aggregationFunction = child.annotations.find(
|
|
204
|
-
([k, _]) => k === "aggregationFunction"
|
|
205
|
-
);
|
|
206
|
-
if (aggregationFunction !== void 0) {
|
|
207
|
-
this.strings[pos] += `${aggregationFunction[1].functionName}Merge(\`${child.name}\`)`;
|
|
208
|
-
} else {
|
|
209
|
-
this.strings[pos] += `\`${child.name}\``;
|
|
210
|
-
}
|
|
211
|
-
this.strings[pos] += rawString;
|
|
212
|
-
} else if (isTable(child)) {
|
|
213
|
-
if (child.config.database) {
|
|
214
|
-
this.strings[pos] += `\`${child.config.database}\`.\`${child.name}\``;
|
|
215
|
-
} else {
|
|
216
|
-
this.strings[pos] += `\`${child.name}\``;
|
|
217
|
-
}
|
|
218
|
-
this.strings[pos] += rawString;
|
|
219
|
-
} else {
|
|
220
|
-
this.values[pos++] = child;
|
|
221
|
-
this.strings[pos] = rawString;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
var toQuery = (sql3) => {
|
|
227
|
-
const parameterizedStubs = sql3.values.map(
|
|
228
|
-
(v, i) => createClickhouseParameter(i, v)
|
|
229
|
-
);
|
|
230
|
-
const query = sql3.strings.map(
|
|
231
|
-
(s, i) => s != "" ? `${s}${emptyIfUndefined(parameterizedStubs[i])}` : ""
|
|
232
|
-
).join("");
|
|
233
|
-
const query_params = sql3.values.reduce(
|
|
234
|
-
(acc, v, i) => ({
|
|
235
|
-
...acc,
|
|
236
|
-
[`p${i}`]: getValueFromParameter(v)
|
|
237
|
-
}),
|
|
238
|
-
{}
|
|
239
|
-
);
|
|
240
|
-
return [query, query_params];
|
|
241
|
-
};
|
|
242
|
-
var toQueryPreview = (sql3) => {
|
|
243
|
-
try {
|
|
244
|
-
const formatValue = (v) => {
|
|
245
|
-
if (Array.isArray(v)) {
|
|
246
|
-
const [type, val] = v;
|
|
247
|
-
if (type === "Identifier") {
|
|
248
|
-
return `\`${String(val)}\``;
|
|
249
|
-
}
|
|
250
|
-
return `[${v.map((x) => formatValue(x)).join(", ")}]`;
|
|
251
|
-
}
|
|
252
|
-
if (v === null || v === void 0) return "NULL";
|
|
253
|
-
if (typeof v === "string") return `'${v.replace(/'/g, "''")}'`;
|
|
254
|
-
if (typeof v === "number") return String(v);
|
|
255
|
-
if (typeof v === "boolean") return v ? "true" : "false";
|
|
256
|
-
if (v instanceof Date)
|
|
257
|
-
return `'${v.toISOString().replace("T", " ").slice(0, 19)}'`;
|
|
258
|
-
try {
|
|
259
|
-
return JSON.stringify(v);
|
|
260
|
-
} catch {
|
|
261
|
-
return String(v);
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
let out = sql3.strings[0] ?? "";
|
|
265
|
-
for (let i = 0; i < sql3.values.length; i++) {
|
|
266
|
-
const val = getValueFromParameter(sql3.values[i]);
|
|
267
|
-
out += formatValue(val);
|
|
268
|
-
out += sql3.strings[i + 1] ?? "";
|
|
269
|
-
}
|
|
270
|
-
return out.replace(/\s+/g, " ").trim();
|
|
271
|
-
} catch (error) {
|
|
272
|
-
console.log(`toQueryPreview error: ${error}`);
|
|
273
|
-
return "/* query preview unavailable */";
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
var getValueFromParameter = (value) => {
|
|
277
|
-
if (Array.isArray(value)) {
|
|
278
|
-
const [type, val] = value;
|
|
279
|
-
if (type === "Identifier") return val;
|
|
280
|
-
}
|
|
281
|
-
return value;
|
|
282
|
-
};
|
|
283
|
-
function createClickhouseParameter(parameterIndex, value) {
|
|
284
|
-
return `{p${parameterIndex}:${mapToClickHouseType(value)}}`;
|
|
285
|
-
}
|
|
286
|
-
var mapToClickHouseType = (value) => {
|
|
287
|
-
if (typeof value === "number") {
|
|
288
|
-
return Number.isInteger(value) ? "Int" : "Float";
|
|
289
|
-
}
|
|
290
|
-
if (typeof value === "boolean") return "Bool";
|
|
291
|
-
if (value instanceof Date) return "DateTime";
|
|
292
|
-
if (Array.isArray(value)) {
|
|
293
|
-
const [type, _] = value;
|
|
294
|
-
return type;
|
|
500
|
+
// src/secrets.ts
|
|
501
|
+
var init_secrets = __esm({
|
|
502
|
+
"src/secrets.ts"() {
|
|
503
|
+
"use strict";
|
|
295
504
|
}
|
|
296
|
-
|
|
297
|
-
};
|
|
298
|
-
function emptyIfUndefined(value) {
|
|
299
|
-
return value === void 0 ? "" : value;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
// src/dmv2/sdk/olapTable.ts
|
|
303
|
-
var import_node_stream = require("stream");
|
|
304
|
-
var import_node_crypto = require("crypto");
|
|
305
|
-
|
|
306
|
-
// src/dmv2/sdk/stream.ts
|
|
307
|
-
var import_node_crypto2 = require("crypto");
|
|
308
|
-
|
|
309
|
-
// src/index.ts
|
|
310
|
-
init_commons();
|
|
505
|
+
});
|
|
311
506
|
|
|
312
507
|
// src/consumption-apis/helpers.ts
|
|
313
|
-
var import_client2 = require("@temporalio/client");
|
|
314
|
-
var import_node_crypto3 = require("crypto");
|
|
315
|
-
var import_perf_hooks = require("perf_hooks");
|
|
316
|
-
var fs = __toESM(require("fs"));
|
|
317
508
|
function formatElapsedTime(ms) {
|
|
318
509
|
if (ms < 1e3) {
|
|
319
510
|
return `${Math.round(ms)} ms`;
|
|
@@ -326,142 +517,6 @@ function formatElapsedTime(ms) {
|
|
|
326
517
|
const remainingSeconds = seconds % 60;
|
|
327
518
|
return `${minutes} minutes and ${remainingSeconds.toFixed(2)} seconds`;
|
|
328
519
|
}
|
|
329
|
-
var MooseClient = class {
|
|
330
|
-
query;
|
|
331
|
-
workflow;
|
|
332
|
-
constructor(queryClient, temporalClient) {
|
|
333
|
-
this.query = queryClient;
|
|
334
|
-
this.workflow = new WorkflowClient(temporalClient);
|
|
335
|
-
}
|
|
336
|
-
};
|
|
337
|
-
var QueryClient = class {
|
|
338
|
-
client;
|
|
339
|
-
query_id_prefix;
|
|
340
|
-
constructor(client, query_id_prefix) {
|
|
341
|
-
this.client = client;
|
|
342
|
-
this.query_id_prefix = query_id_prefix;
|
|
343
|
-
}
|
|
344
|
-
async execute(sql3) {
|
|
345
|
-
const [query, query_params] = toQuery(sql3);
|
|
346
|
-
console.log(`[QueryClient] | Query: ${toQueryPreview(sql3)}`);
|
|
347
|
-
const start = import_perf_hooks.performance.now();
|
|
348
|
-
const result = await this.client.query({
|
|
349
|
-
query,
|
|
350
|
-
query_params,
|
|
351
|
-
format: "JSONEachRow",
|
|
352
|
-
query_id: this.query_id_prefix + (0, import_node_crypto3.randomUUID)()
|
|
353
|
-
// Note: wait_end_of_query deliberately NOT set here as this is used for SELECT queries
|
|
354
|
-
// where response buffering would harm streaming performance and concurrency
|
|
355
|
-
});
|
|
356
|
-
const elapsedMs = import_perf_hooks.performance.now() - start;
|
|
357
|
-
console.log(
|
|
358
|
-
`[QueryClient] | Query completed: ${formatElapsedTime(elapsedMs)}`
|
|
359
|
-
);
|
|
360
|
-
return result;
|
|
361
|
-
}
|
|
362
|
-
async command(sql3) {
|
|
363
|
-
const [query, query_params] = toQuery(sql3);
|
|
364
|
-
console.log(`[QueryClient] | Command: ${toQueryPreview(sql3)}`);
|
|
365
|
-
const start = import_perf_hooks.performance.now();
|
|
366
|
-
const result = await this.client.command({
|
|
367
|
-
query,
|
|
368
|
-
query_params,
|
|
369
|
-
query_id: this.query_id_prefix + (0, import_node_crypto3.randomUUID)()
|
|
370
|
-
});
|
|
371
|
-
const elapsedMs = import_perf_hooks.performance.now() - start;
|
|
372
|
-
console.log(
|
|
373
|
-
`[QueryClient] | Command completed: ${formatElapsedTime(elapsedMs)}`
|
|
374
|
-
);
|
|
375
|
-
return result;
|
|
376
|
-
}
|
|
377
|
-
};
|
|
378
|
-
var WorkflowClient = class {
|
|
379
|
-
client;
|
|
380
|
-
constructor(temporalClient) {
|
|
381
|
-
this.client = temporalClient;
|
|
382
|
-
}
|
|
383
|
-
async execute(name, input_data) {
|
|
384
|
-
try {
|
|
385
|
-
if (!this.client) {
|
|
386
|
-
return {
|
|
387
|
-
status: 404,
|
|
388
|
-
body: `Temporal client not found. Is the feature flag enabled?`
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
const config = await this.getWorkflowConfig(name);
|
|
392
|
-
const [processedInput, workflowId] = this.processInputData(
|
|
393
|
-
name,
|
|
394
|
-
input_data
|
|
395
|
-
);
|
|
396
|
-
console.log(
|
|
397
|
-
`WorkflowClient - starting workflow: ${name} with config ${JSON.stringify(config)} and input_data ${JSON.stringify(processedInput)}`
|
|
398
|
-
);
|
|
399
|
-
const handle = await this.client.workflow.start("ScriptWorkflow", {
|
|
400
|
-
args: [
|
|
401
|
-
{ workflow_name: name, execution_mode: "start" },
|
|
402
|
-
processedInput
|
|
403
|
-
],
|
|
404
|
-
taskQueue: "typescript-script-queue",
|
|
405
|
-
workflowId,
|
|
406
|
-
workflowIdConflictPolicy: "FAIL",
|
|
407
|
-
workflowIdReusePolicy: "ALLOW_DUPLICATE",
|
|
408
|
-
retry: {
|
|
409
|
-
maximumAttempts: config.retries
|
|
410
|
-
},
|
|
411
|
-
workflowRunTimeout: config.timeout
|
|
412
|
-
});
|
|
413
|
-
return {
|
|
414
|
-
status: 200,
|
|
415
|
-
body: `Workflow started: ${name}. View it in the Temporal dashboard: http://localhost:8080/namespaces/default/workflows/${workflowId}/${handle.firstExecutionRunId}/history`
|
|
416
|
-
};
|
|
417
|
-
} catch (error) {
|
|
418
|
-
return {
|
|
419
|
-
status: 400,
|
|
420
|
-
body: `Error starting workflow: ${error}`
|
|
421
|
-
};
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
async terminate(workflowId) {
|
|
425
|
-
try {
|
|
426
|
-
if (!this.client) {
|
|
427
|
-
return {
|
|
428
|
-
status: 404,
|
|
429
|
-
body: `Temporal client not found. Is the feature flag enabled?`
|
|
430
|
-
};
|
|
431
|
-
}
|
|
432
|
-
const handle = this.client.workflow.getHandle(workflowId);
|
|
433
|
-
await handle.terminate();
|
|
434
|
-
return {
|
|
435
|
-
status: 200,
|
|
436
|
-
body: `Workflow terminated: ${workflowId}`
|
|
437
|
-
};
|
|
438
|
-
} catch (error) {
|
|
439
|
-
return {
|
|
440
|
-
status: 400,
|
|
441
|
-
body: `Error terminating workflow: ${error}`
|
|
442
|
-
};
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
async getWorkflowConfig(name) {
|
|
446
|
-
const workflows = await getWorkflows2();
|
|
447
|
-
const dmv2Workflow = workflows.get(name);
|
|
448
|
-
if (dmv2Workflow) {
|
|
449
|
-
return {
|
|
450
|
-
retries: dmv2Workflow.config.retries || 3,
|
|
451
|
-
timeout: dmv2Workflow.config.timeout || "1h"
|
|
452
|
-
};
|
|
453
|
-
}
|
|
454
|
-
throw new Error(`Workflow config not found for ${name}`);
|
|
455
|
-
}
|
|
456
|
-
processInputData(name, input_data) {
|
|
457
|
-
let workflowId = name;
|
|
458
|
-
if (input_data) {
|
|
459
|
-
const hash = (0, import_node_crypto3.createHash)("sha256").update(JSON.stringify(input_data)).digest("hex").slice(0, 16);
|
|
460
|
-
workflowId = `${name}-${hash}`;
|
|
461
|
-
}
|
|
462
|
-
return [input_data, workflowId];
|
|
463
|
-
}
|
|
464
|
-
};
|
|
465
520
|
async function getTemporalClient(temporalUrl, namespace, clientCert, clientKey, apiKey) {
|
|
466
521
|
try {
|
|
467
522
|
console.info(
|
|
@@ -498,538 +553,976 @@ async function getTemporalClient(temporalUrl, namespace, clientCert, clientKey,
|
|
|
498
553
|
return void 0;
|
|
499
554
|
}
|
|
500
555
|
}
|
|
556
|
+
var import_client2, import_node_crypto3, import_perf_hooks, fs, MooseClient, QueryClient, WorkflowClient;
|
|
557
|
+
var init_helpers2 = __esm({
|
|
558
|
+
"src/consumption-apis/helpers.ts"() {
|
|
559
|
+
"use strict";
|
|
560
|
+
import_client2 = require("@temporalio/client");
|
|
561
|
+
import_node_crypto3 = require("crypto");
|
|
562
|
+
import_perf_hooks = require("perf_hooks");
|
|
563
|
+
fs = __toESM(require("fs"));
|
|
564
|
+
init_internal();
|
|
565
|
+
init_sqlHelpers();
|
|
566
|
+
MooseClient = class {
|
|
567
|
+
query;
|
|
568
|
+
workflow;
|
|
569
|
+
constructor(queryClient, temporalClient) {
|
|
570
|
+
this.query = queryClient;
|
|
571
|
+
this.workflow = new WorkflowClient(temporalClient);
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
QueryClient = class {
|
|
575
|
+
client;
|
|
576
|
+
query_id_prefix;
|
|
577
|
+
constructor(client, query_id_prefix) {
|
|
578
|
+
this.client = client;
|
|
579
|
+
this.query_id_prefix = query_id_prefix;
|
|
580
|
+
}
|
|
581
|
+
async execute(sql3) {
|
|
582
|
+
const [query, query_params] = toQuery(sql3);
|
|
583
|
+
console.log(`[QueryClient] | Query: ${toQueryPreview(sql3)}`);
|
|
584
|
+
const start = import_perf_hooks.performance.now();
|
|
585
|
+
const result = await this.client.query({
|
|
586
|
+
query,
|
|
587
|
+
query_params,
|
|
588
|
+
format: "JSONEachRow",
|
|
589
|
+
query_id: this.query_id_prefix + (0, import_node_crypto3.randomUUID)()
|
|
590
|
+
// Note: wait_end_of_query deliberately NOT set here as this is used for SELECT queries
|
|
591
|
+
// where response buffering would harm streaming performance and concurrency
|
|
592
|
+
});
|
|
593
|
+
const elapsedMs = import_perf_hooks.performance.now() - start;
|
|
594
|
+
console.log(
|
|
595
|
+
`[QueryClient] | Query completed: ${formatElapsedTime(elapsedMs)}`
|
|
596
|
+
);
|
|
597
|
+
return result;
|
|
598
|
+
}
|
|
599
|
+
async command(sql3) {
|
|
600
|
+
const [query, query_params] = toQuery(sql3);
|
|
601
|
+
console.log(`[QueryClient] | Command: ${toQueryPreview(sql3)}`);
|
|
602
|
+
const start = import_perf_hooks.performance.now();
|
|
603
|
+
const result = await this.client.command({
|
|
604
|
+
query,
|
|
605
|
+
query_params,
|
|
606
|
+
query_id: this.query_id_prefix + (0, import_node_crypto3.randomUUID)()
|
|
607
|
+
});
|
|
608
|
+
const elapsedMs = import_perf_hooks.performance.now() - start;
|
|
609
|
+
console.log(
|
|
610
|
+
`[QueryClient] | Command completed: ${formatElapsedTime(elapsedMs)}`
|
|
611
|
+
);
|
|
612
|
+
return result;
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
WorkflowClient = class {
|
|
616
|
+
client;
|
|
617
|
+
constructor(temporalClient) {
|
|
618
|
+
this.client = temporalClient;
|
|
619
|
+
}
|
|
620
|
+
async execute(name, input_data) {
|
|
621
|
+
try {
|
|
622
|
+
if (!this.client) {
|
|
623
|
+
return {
|
|
624
|
+
status: 404,
|
|
625
|
+
body: `Temporal client not found. Is the feature flag enabled?`
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
const config = await this.getWorkflowConfig(name);
|
|
629
|
+
const [processedInput, workflowId] = this.processInputData(
|
|
630
|
+
name,
|
|
631
|
+
input_data
|
|
632
|
+
);
|
|
633
|
+
console.log(
|
|
634
|
+
`WorkflowClient - starting workflow: ${name} with config ${JSON.stringify(config)} and input_data ${JSON.stringify(processedInput)}`
|
|
635
|
+
);
|
|
636
|
+
const handle = await this.client.workflow.start("ScriptWorkflow", {
|
|
637
|
+
args: [
|
|
638
|
+
{ workflow_name: name, execution_mode: "start" },
|
|
639
|
+
processedInput
|
|
640
|
+
],
|
|
641
|
+
taskQueue: "typescript-script-queue",
|
|
642
|
+
workflowId,
|
|
643
|
+
workflowIdConflictPolicy: "FAIL",
|
|
644
|
+
workflowIdReusePolicy: "ALLOW_DUPLICATE",
|
|
645
|
+
retry: {
|
|
646
|
+
maximumAttempts: config.retries
|
|
647
|
+
},
|
|
648
|
+
workflowRunTimeout: config.timeout
|
|
649
|
+
});
|
|
650
|
+
return {
|
|
651
|
+
status: 200,
|
|
652
|
+
body: `Workflow started: ${name}. View it in the Temporal dashboard: http://localhost:8080/namespaces/default/workflows/${workflowId}/${handle.firstExecutionRunId}/history`
|
|
653
|
+
};
|
|
654
|
+
} catch (error) {
|
|
655
|
+
return {
|
|
656
|
+
status: 400,
|
|
657
|
+
body: `Error starting workflow: ${error}`
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
async terminate(workflowId) {
|
|
662
|
+
try {
|
|
663
|
+
if (!this.client) {
|
|
664
|
+
return {
|
|
665
|
+
status: 404,
|
|
666
|
+
body: `Temporal client not found. Is the feature flag enabled?`
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
const handle = this.client.workflow.getHandle(workflowId);
|
|
670
|
+
await handle.terminate();
|
|
671
|
+
return {
|
|
672
|
+
status: 200,
|
|
673
|
+
body: `Workflow terminated: ${workflowId}`
|
|
674
|
+
};
|
|
675
|
+
} catch (error) {
|
|
676
|
+
return {
|
|
677
|
+
status: 400,
|
|
678
|
+
body: `Error terminating workflow: ${error}`
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
async getWorkflowConfig(name) {
|
|
683
|
+
const workflows = await getWorkflows2();
|
|
684
|
+
const dmv2Workflow = workflows.get(name);
|
|
685
|
+
if (dmv2Workflow) {
|
|
686
|
+
return {
|
|
687
|
+
retries: dmv2Workflow.config.retries || 3,
|
|
688
|
+
timeout: dmv2Workflow.config.timeout || "1h"
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
throw new Error(`Workflow config not found for ${name}`);
|
|
692
|
+
}
|
|
693
|
+
processInputData(name, input_data) {
|
|
694
|
+
let workflowId = name;
|
|
695
|
+
if (input_data) {
|
|
696
|
+
const hash = (0, import_node_crypto3.createHash)("sha256").update(JSON.stringify(input_data)).digest("hex").slice(0, 16);
|
|
697
|
+
workflowId = `${name}-${hash}`;
|
|
698
|
+
}
|
|
699
|
+
return [input_data, workflowId];
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
});
|
|
501
704
|
|
|
502
|
-
// src/consumption-apis/
|
|
503
|
-
var
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
// src/cluster-utils.ts
|
|
508
|
-
var import_node_cluster = __toESM(require("cluster"));
|
|
509
|
-
var import_node_os = require("os");
|
|
510
|
-
var import_node_process = require("process");
|
|
511
|
-
var DEFAULT_MAX_CPU_USAGE_RATIO = 0.7;
|
|
512
|
-
var RESTART_TIME_MS = 1e4;
|
|
513
|
-
var SIGTERM = "SIGTERM";
|
|
514
|
-
var SIGINT = "SIGINT";
|
|
515
|
-
var SHUTDOWN_WORKERS_INTERVAL = 500;
|
|
516
|
-
var Cluster = class {
|
|
517
|
-
// Tracks if shutdown is currently in progress
|
|
518
|
-
shutdownInProgress = false;
|
|
519
|
-
// Tracks if workers exited cleanly during shutdown
|
|
520
|
-
hasCleanWorkerExit = true;
|
|
521
|
-
// String identifying if this is primary or worker process
|
|
522
|
-
processStr = `${import_node_cluster.default.isPrimary ? "primary" : "worker"} process ${process.pid}`;
|
|
523
|
-
// Functions for starting and stopping workers
|
|
524
|
-
workerStart;
|
|
525
|
-
workerStop;
|
|
526
|
-
// Result from starting worker, needed for cleanup
|
|
527
|
-
startOutput;
|
|
528
|
-
maxCpuUsageRatio;
|
|
529
|
-
usedCpuCount;
|
|
530
|
-
/**
|
|
531
|
-
* Creates a new cluster manager instance.
|
|
532
|
-
*
|
|
533
|
-
* @param options - Configuration options for the cluster
|
|
534
|
-
* @param options.workerStart - Async function to execute when starting a worker
|
|
535
|
-
* @param options.workerStop - Async function to execute when stopping a worker
|
|
536
|
-
* @param options.maxCpuUsageRatio - Maximum ratio of CPU cores to utilize (0-1)
|
|
537
|
-
* @param options.maxWorkerCount - Maximum number of workers to spawn
|
|
538
|
-
* @throws {Error} If maxCpuUsageRatio is not between 0 and 1
|
|
539
|
-
*/
|
|
540
|
-
constructor(options) {
|
|
541
|
-
this.workerStart = options.workerStart;
|
|
542
|
-
this.workerStop = options.workerStop;
|
|
543
|
-
if (options.maxCpuUsageRatio && (options.maxCpuUsageRatio > 1 || options.maxCpuUsageRatio < 0)) {
|
|
544
|
-
throw new Error("maxCpuUsageRatio must be between 0 and 1");
|
|
545
|
-
}
|
|
546
|
-
this.maxCpuUsageRatio = options.maxCpuUsageRatio || DEFAULT_MAX_CPU_USAGE_RATIO;
|
|
547
|
-
this.usedCpuCount = this.computeCPUUsageCount(
|
|
548
|
-
this.maxCpuUsageRatio,
|
|
549
|
-
options.maxWorkerCount
|
|
550
|
-
);
|
|
705
|
+
// src/consumption-apis/webAppHelpers.ts
|
|
706
|
+
var init_webAppHelpers = __esm({
|
|
707
|
+
"src/consumption-apis/webAppHelpers.ts"() {
|
|
708
|
+
"use strict";
|
|
551
709
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
*/
|
|
559
|
-
computeCPUUsageCount(cpuUsageRatio, maxWorkerCount) {
|
|
560
|
-
const cpuCount = (0, import_node_os.availableParallelism)();
|
|
561
|
-
const maxWorkers = maxWorkerCount || cpuCount;
|
|
562
|
-
return Math.min(
|
|
563
|
-
maxWorkers,
|
|
564
|
-
Math.max(1, Math.floor(cpuCount * cpuUsageRatio))
|
|
565
|
-
);
|
|
710
|
+
});
|
|
711
|
+
|
|
712
|
+
// src/scripts/task.ts
|
|
713
|
+
var init_task = __esm({
|
|
714
|
+
"src/scripts/task.ts"() {
|
|
715
|
+
"use strict";
|
|
566
716
|
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
717
|
+
});
|
|
718
|
+
|
|
719
|
+
// src/cluster-utils.ts
|
|
720
|
+
var import_node_cluster, import_node_os, import_node_process, DEFAULT_MAX_CPU_USAGE_RATIO, RESTART_TIME_MS, SIGTERM, SIGINT, SHUTDOWN_WORKERS_INTERVAL, Cluster;
|
|
721
|
+
var init_cluster_utils = __esm({
|
|
722
|
+
"src/cluster-utils.ts"() {
|
|
723
|
+
"use strict";
|
|
724
|
+
import_node_cluster = __toESM(require("cluster"));
|
|
725
|
+
import_node_os = require("os");
|
|
726
|
+
import_node_process = require("process");
|
|
727
|
+
DEFAULT_MAX_CPU_USAGE_RATIO = 0.7;
|
|
728
|
+
RESTART_TIME_MS = 1e4;
|
|
729
|
+
SIGTERM = "SIGTERM";
|
|
730
|
+
SIGINT = "SIGINT";
|
|
731
|
+
SHUTDOWN_WORKERS_INTERVAL = 500;
|
|
732
|
+
Cluster = class {
|
|
733
|
+
// Tracks if shutdown is currently in progress
|
|
734
|
+
shutdownInProgress = false;
|
|
735
|
+
// Tracks if workers exited cleanly during shutdown
|
|
736
|
+
hasCleanWorkerExit = true;
|
|
737
|
+
// String identifying if this is primary or worker process
|
|
738
|
+
processStr = `${import_node_cluster.default.isPrimary ? "primary" : "worker"} process ${process.pid}`;
|
|
739
|
+
// Functions for starting and stopping workers
|
|
740
|
+
workerStart;
|
|
741
|
+
workerStop;
|
|
742
|
+
// Result from starting worker, needed for cleanup
|
|
743
|
+
startOutput;
|
|
744
|
+
maxCpuUsageRatio;
|
|
745
|
+
usedCpuCount;
|
|
746
|
+
/**
|
|
747
|
+
* Creates a new cluster manager instance.
|
|
748
|
+
*
|
|
749
|
+
* @param options - Configuration options for the cluster
|
|
750
|
+
* @param options.workerStart - Async function to execute when starting a worker
|
|
751
|
+
* @param options.workerStop - Async function to execute when stopping a worker
|
|
752
|
+
* @param options.maxCpuUsageRatio - Maximum ratio of CPU cores to utilize (0-1)
|
|
753
|
+
* @param options.maxWorkerCount - Maximum number of workers to spawn
|
|
754
|
+
* @throws {Error} If maxCpuUsageRatio is not between 0 and 1
|
|
755
|
+
*/
|
|
756
|
+
constructor(options) {
|
|
757
|
+
this.workerStart = options.workerStart;
|
|
758
|
+
this.workerStop = options.workerStop;
|
|
759
|
+
if (options.maxCpuUsageRatio && (options.maxCpuUsageRatio > 1 || options.maxCpuUsageRatio < 0)) {
|
|
760
|
+
throw new Error("maxCpuUsageRatio must be between 0 and 1");
|
|
585
761
|
}
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
throw new Error(
|
|
591
|
-
"Worker is not defined, it should be defined in worker process"
|
|
762
|
+
this.maxCpuUsageRatio = options.maxCpuUsageRatio || DEFAULT_MAX_CPU_USAGE_RATIO;
|
|
763
|
+
this.usedCpuCount = this.computeCPUUsageCount(
|
|
764
|
+
this.maxCpuUsageRatio,
|
|
765
|
+
options.maxWorkerCount
|
|
592
766
|
);
|
|
593
767
|
}
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
console.info(`Setting ${numWorkers} workers...`);
|
|
609
|
-
for (let i = 0; i < numWorkers; i++) {
|
|
610
|
-
import_node_cluster.default.fork();
|
|
611
|
-
}
|
|
612
|
-
import_node_cluster.default.on("online", (worker) => {
|
|
613
|
-
console.info(`worker process ${worker.process.pid} is online`);
|
|
614
|
-
});
|
|
615
|
-
import_node_cluster.default.on("exit", (worker, code, signal) => {
|
|
616
|
-
console.info(
|
|
617
|
-
`worker ${worker.process.pid} exited with code ${code} and signal ${signal}`
|
|
618
|
-
);
|
|
619
|
-
if (!this.shutdownInProgress) {
|
|
620
|
-
setTimeout(() => import_node_cluster.default.fork(), RESTART_TIME_MS);
|
|
621
|
-
}
|
|
622
|
-
if (this.shutdownInProgress && code != 0) {
|
|
623
|
-
this.hasCleanWorkerExit = false;
|
|
768
|
+
/**
|
|
769
|
+
* Calculates the number of CPU cores to utilize based on available parallelism and constraints.
|
|
770
|
+
*
|
|
771
|
+
* @param cpuUsageRatio - Ratio of CPU cores to use (0-1)
|
|
772
|
+
* @param maxWorkerCount - Optional maximum number of workers
|
|
773
|
+
* @returns The number of CPU cores to utilize
|
|
774
|
+
*/
|
|
775
|
+
computeCPUUsageCount(cpuUsageRatio, maxWorkerCount) {
|
|
776
|
+
const cpuCount = (0, import_node_os.availableParallelism)();
|
|
777
|
+
const maxWorkers = maxWorkerCount || cpuCount;
|
|
778
|
+
return Math.min(
|
|
779
|
+
maxWorkers,
|
|
780
|
+
Math.max(1, Math.floor(cpuCount * cpuUsageRatio))
|
|
781
|
+
);
|
|
624
782
|
}
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
);
|
|
647
|
-
try {
|
|
648
|
-
if (import_node_cluster.default.isPrimary) {
|
|
649
|
-
await this.shutdownWorkers(signal);
|
|
650
|
-
console.info(`${this.processStr} - worker shutdown successful`);
|
|
651
|
-
(0, import_node_process.exit)(0);
|
|
652
|
-
} else {
|
|
653
|
-
if (this.startOutput) {
|
|
654
|
-
await this.workerStop(this.startOutput);
|
|
783
|
+
/**
|
|
784
|
+
* Initializes the cluster by spawning worker processes and setting up signal handlers.
|
|
785
|
+
* For the primary process, spawns workers and monitors parent process.
|
|
786
|
+
* For worker processes, executes the worker startup function.
|
|
787
|
+
*
|
|
788
|
+
* @throws {Error} If worker is undefined in worker process
|
|
789
|
+
*/
|
|
790
|
+
async start() {
|
|
791
|
+
process.on(SIGTERM, this.gracefulClusterShutdown(SIGTERM));
|
|
792
|
+
process.on(SIGINT, this.gracefulClusterShutdown(SIGINT));
|
|
793
|
+
if (import_node_cluster.default.isPrimary) {
|
|
794
|
+
const parentPid = process.ppid;
|
|
795
|
+
setInterval(() => {
|
|
796
|
+
try {
|
|
797
|
+
process.kill(parentPid, 0);
|
|
798
|
+
} catch (e) {
|
|
799
|
+
console.log("Parent process has exited.");
|
|
800
|
+
this.gracefulClusterShutdown(SIGTERM)();
|
|
801
|
+
}
|
|
802
|
+
}, 1e3);
|
|
803
|
+
await this.bootWorkers(this.usedCpuCount);
|
|
655
804
|
} else {
|
|
656
|
-
|
|
657
|
-
|
|
805
|
+
if (!import_node_cluster.default.worker) {
|
|
806
|
+
throw new Error(
|
|
807
|
+
"Worker is not defined, it should be defined in worker process"
|
|
808
|
+
);
|
|
809
|
+
}
|
|
810
|
+
this.startOutput = await this.workerStart(
|
|
811
|
+
import_node_cluster.default.worker,
|
|
812
|
+
this.usedCpuCount
|
|
658
813
|
);
|
|
659
814
|
}
|
|
660
|
-
console.info(`${this.processStr} shutdown successful`);
|
|
661
|
-
this.hasCleanWorkerExit ? (0, import_node_process.exit)(0) : (0, import_node_process.exit)(1);
|
|
662
815
|
}
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
816
|
+
/**
|
|
817
|
+
* Spawns worker processes and configures their lifecycle event handlers.
|
|
818
|
+
* Handles worker online, exit and disconnect events.
|
|
819
|
+
* Automatically restarts failed workers during normal operation.
|
|
820
|
+
*
|
|
821
|
+
* @param numWorkers - Number of worker processes to spawn
|
|
822
|
+
*/
|
|
823
|
+
bootWorkers = async (numWorkers) => {
|
|
824
|
+
console.info(`Setting ${numWorkers} workers...`);
|
|
825
|
+
for (let i = 0; i < numWorkers; i++) {
|
|
826
|
+
import_node_cluster.default.fork();
|
|
827
|
+
}
|
|
828
|
+
import_node_cluster.default.on("online", (worker) => {
|
|
829
|
+
console.info(`worker process ${worker.process.pid} is online`);
|
|
830
|
+
});
|
|
831
|
+
import_node_cluster.default.on("exit", (worker, code, signal) => {
|
|
832
|
+
console.info(
|
|
833
|
+
`worker ${worker.process.pid} exited with code ${code} and signal ${signal}`
|
|
834
|
+
);
|
|
835
|
+
if (!this.shutdownInProgress) {
|
|
836
|
+
setTimeout(() => import_node_cluster.default.fork(), RESTART_TIME_MS);
|
|
837
|
+
}
|
|
838
|
+
if (this.shutdownInProgress && code != 0) {
|
|
839
|
+
this.hasCleanWorkerExit = false;
|
|
840
|
+
}
|
|
841
|
+
});
|
|
842
|
+
import_node_cluster.default.on("disconnect", (worker) => {
|
|
843
|
+
console.info(`worker process ${worker.process.pid} has disconnected`);
|
|
844
|
+
});
|
|
845
|
+
};
|
|
846
|
+
/**
|
|
847
|
+
* Creates a handler function for graceful shutdown on receipt of a signal.
|
|
848
|
+
* Ensures only one shutdown can occur at a time.
|
|
849
|
+
* Handles shutdown differently for primary and worker processes.
|
|
850
|
+
*
|
|
851
|
+
* @param signal - The signal triggering the shutdown (e.g. SIGTERM)
|
|
852
|
+
* @returns An async function that performs the shutdown
|
|
853
|
+
*/
|
|
854
|
+
gracefulClusterShutdown = (signal) => async () => {
|
|
855
|
+
if (this.shutdownInProgress) {
|
|
856
|
+
return;
|
|
857
|
+
}
|
|
858
|
+
this.shutdownInProgress = true;
|
|
859
|
+
this.hasCleanWorkerExit = true;
|
|
860
|
+
console.info(
|
|
861
|
+
`Got ${signal} on ${this.processStr}. Graceful shutdown start at ${(/* @__PURE__ */ new Date()).toISOString()}`
|
|
862
|
+
);
|
|
863
|
+
try {
|
|
864
|
+
if (import_node_cluster.default.isPrimary) {
|
|
865
|
+
await this.shutdownWorkers(signal);
|
|
866
|
+
console.info(`${this.processStr} - worker shutdown successful`);
|
|
867
|
+
(0, import_node_process.exit)(0);
|
|
868
|
+
} else {
|
|
869
|
+
if (this.startOutput) {
|
|
870
|
+
await this.workerStop(this.startOutput);
|
|
871
|
+
} else {
|
|
872
|
+
console.info(
|
|
873
|
+
`${this.processStr} - shutdown before worker fully started`
|
|
874
|
+
);
|
|
875
|
+
}
|
|
876
|
+
console.info(`${this.processStr} shutdown successful`);
|
|
877
|
+
this.hasCleanWorkerExit ? (0, import_node_process.exit)(0) : (0, import_node_process.exit)(1);
|
|
878
|
+
}
|
|
879
|
+
} catch (e) {
|
|
880
|
+
console.error(`${this.processStr} - shutdown failed`, e);
|
|
881
|
+
(0, import_node_process.exit)(1);
|
|
882
|
+
}
|
|
883
|
+
};
|
|
884
|
+
/**
|
|
885
|
+
* Gracefully terminates all worker processes.
|
|
886
|
+
* Monitors workers until they all exit or timeout occurs.
|
|
887
|
+
* Only relevant for the primary process.
|
|
888
|
+
*
|
|
889
|
+
* @param signal - The signal to send to worker processes
|
|
890
|
+
* @returns A promise that resolves when all workers have terminated
|
|
891
|
+
*/
|
|
892
|
+
shutdownWorkers = (signal) => {
|
|
893
|
+
return new Promise((resolve2, reject) => {
|
|
894
|
+
if (!import_node_cluster.default.isPrimary) {
|
|
895
|
+
return resolve2();
|
|
896
|
+
}
|
|
897
|
+
if (!import_node_cluster.default.workers) {
|
|
898
|
+
return resolve2();
|
|
899
|
+
}
|
|
900
|
+
const workerIds = Object.keys(import_node_cluster.default.workers);
|
|
901
|
+
if (workerIds.length == 0) {
|
|
902
|
+
return resolve2();
|
|
903
|
+
}
|
|
904
|
+
let workersAlive = 0;
|
|
905
|
+
let funcRun = 0;
|
|
906
|
+
const cleanWorkers = () => {
|
|
907
|
+
++funcRun;
|
|
908
|
+
workersAlive = 0;
|
|
909
|
+
Object.values(import_node_cluster.default.workers || {}).filter((worker) => !!worker).forEach((worker) => {
|
|
910
|
+
if (worker && !worker.isDead()) {
|
|
911
|
+
++workersAlive;
|
|
912
|
+
if (funcRun == 1) {
|
|
913
|
+
worker.kill(signal);
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
});
|
|
917
|
+
console.info(workersAlive + " workers alive");
|
|
918
|
+
if (workersAlive == 0) {
|
|
919
|
+
clearInterval(interval);
|
|
920
|
+
return resolve2();
|
|
921
|
+
}
|
|
922
|
+
};
|
|
923
|
+
const interval = setInterval(cleanWorkers, SHUTDOWN_WORKERS_INTERVAL);
|
|
924
|
+
});
|
|
925
|
+
};
|
|
926
|
+
};
|
|
927
|
+
}
|
|
928
|
+
});
|
|
929
|
+
|
|
930
|
+
// src/config/configFile.ts
|
|
931
|
+
async function findConfigFile(startDir = process.cwd()) {
|
|
932
|
+
const fs4 = await import("fs");
|
|
933
|
+
let currentDir = import_node_path.default.resolve(startDir);
|
|
934
|
+
while (true) {
|
|
935
|
+
const configPath = import_node_path.default.join(currentDir, "moose.config.toml");
|
|
936
|
+
if (fs4.existsSync(configPath)) {
|
|
937
|
+
return configPath;
|
|
666
938
|
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
939
|
+
const parentDir = import_node_path.default.dirname(currentDir);
|
|
940
|
+
if (parentDir === currentDir) {
|
|
941
|
+
break;
|
|
942
|
+
}
|
|
943
|
+
currentDir = parentDir;
|
|
944
|
+
}
|
|
945
|
+
return null;
|
|
946
|
+
}
|
|
947
|
+
async function readProjectConfig() {
|
|
948
|
+
const fs4 = await import("fs");
|
|
949
|
+
const configPath = await findConfigFile();
|
|
950
|
+
if (!configPath) {
|
|
951
|
+
throw new ConfigError(
|
|
952
|
+
"moose.config.toml not found in current directory or any parent directory"
|
|
953
|
+
);
|
|
954
|
+
}
|
|
955
|
+
try {
|
|
956
|
+
const configContent = fs4.readFileSync(configPath, "utf-8");
|
|
957
|
+
const config = toml.parse(configContent);
|
|
958
|
+
return config;
|
|
959
|
+
} catch (error) {
|
|
960
|
+
throw new ConfigError(`Failed to parse moose.config.toml: ${error}`);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
var import_node_path, toml, ConfigError;
|
|
964
|
+
var init_configFile = __esm({
|
|
965
|
+
"src/config/configFile.ts"() {
|
|
966
|
+
"use strict";
|
|
967
|
+
import_node_path = __toESM(require("path"));
|
|
968
|
+
toml = __toESM(require("toml"));
|
|
969
|
+
ConfigError = class extends Error {
|
|
970
|
+
constructor(message) {
|
|
971
|
+
super(message);
|
|
972
|
+
this.name = "ConfigError";
|
|
680
973
|
}
|
|
681
|
-
|
|
682
|
-
|
|
974
|
+
};
|
|
975
|
+
}
|
|
976
|
+
});
|
|
977
|
+
|
|
978
|
+
// src/config/runtime.ts
|
|
979
|
+
var runtime_exports = {};
|
|
980
|
+
var ConfigurationRegistry;
|
|
981
|
+
var init_runtime = __esm({
|
|
982
|
+
"src/config/runtime.ts"() {
|
|
983
|
+
"use strict";
|
|
984
|
+
init_configFile();
|
|
985
|
+
ConfigurationRegistry = class _ConfigurationRegistry {
|
|
986
|
+
static instance;
|
|
987
|
+
clickhouseConfig;
|
|
988
|
+
kafkaConfig;
|
|
989
|
+
static getInstance() {
|
|
990
|
+
if (!_ConfigurationRegistry.instance) {
|
|
991
|
+
_ConfigurationRegistry.instance = new _ConfigurationRegistry();
|
|
992
|
+
}
|
|
993
|
+
return _ConfigurationRegistry.instance;
|
|
683
994
|
}
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
return resolve2();
|
|
995
|
+
setClickHouseConfig(config) {
|
|
996
|
+
this.clickhouseConfig = config;
|
|
687
997
|
}
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
998
|
+
setKafkaConfig(config) {
|
|
999
|
+
this.kafkaConfig = config;
|
|
1000
|
+
}
|
|
1001
|
+
_env(name) {
|
|
1002
|
+
const value = process.env[name];
|
|
1003
|
+
if (value === void 0) return void 0;
|
|
1004
|
+
const trimmed = value.trim();
|
|
1005
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
1006
|
+
}
|
|
1007
|
+
_parseBool(value) {
|
|
1008
|
+
if (value === void 0) return void 0;
|
|
1009
|
+
switch (value.trim().toLowerCase()) {
|
|
1010
|
+
case "1":
|
|
1011
|
+
case "true":
|
|
1012
|
+
case "yes":
|
|
1013
|
+
case "on":
|
|
1014
|
+
return true;
|
|
1015
|
+
case "0":
|
|
1016
|
+
case "false":
|
|
1017
|
+
case "no":
|
|
1018
|
+
case "off":
|
|
1019
|
+
return false;
|
|
1020
|
+
default:
|
|
1021
|
+
return void 0;
|
|
705
1022
|
}
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
}
|
|
1023
|
+
}
|
|
1024
|
+
async getClickHouseConfig() {
|
|
1025
|
+
if (this.clickhouseConfig) {
|
|
1026
|
+
return this.clickhouseConfig;
|
|
1027
|
+
}
|
|
1028
|
+
const projectConfig = await readProjectConfig();
|
|
1029
|
+
const envHost = this._env("MOOSE_CLICKHOUSE_CONFIG__HOST");
|
|
1030
|
+
const envPort = this._env("MOOSE_CLICKHOUSE_CONFIG__HOST_PORT");
|
|
1031
|
+
const envUser = this._env("MOOSE_CLICKHOUSE_CONFIG__USER");
|
|
1032
|
+
const envPassword = this._env("MOOSE_CLICKHOUSE_CONFIG__PASSWORD");
|
|
1033
|
+
const envDb = this._env("MOOSE_CLICKHOUSE_CONFIG__DB_NAME");
|
|
1034
|
+
const envUseSSL = this._parseBool(
|
|
1035
|
+
this._env("MOOSE_CLICKHOUSE_CONFIG__USE_SSL")
|
|
1036
|
+
);
|
|
1037
|
+
return {
|
|
1038
|
+
host: envHost ?? projectConfig.clickhouse_config.host,
|
|
1039
|
+
port: envPort ?? projectConfig.clickhouse_config.host_port.toString(),
|
|
1040
|
+
username: envUser ?? projectConfig.clickhouse_config.user,
|
|
1041
|
+
password: envPassword ?? projectConfig.clickhouse_config.password,
|
|
1042
|
+
database: envDb ?? projectConfig.clickhouse_config.db_name,
|
|
1043
|
+
useSSL: envUseSSL !== void 0 ? envUseSSL : projectConfig.clickhouse_config.use_ssl || false
|
|
1044
|
+
};
|
|
1045
|
+
}
|
|
1046
|
+
async getStandaloneClickhouseConfig(overrides) {
|
|
1047
|
+
if (this.clickhouseConfig) {
|
|
1048
|
+
return { ...this.clickhouseConfig, ...overrides };
|
|
1049
|
+
}
|
|
1050
|
+
const envHost = this._env("MOOSE_CLICKHOUSE_CONFIG__HOST");
|
|
1051
|
+
const envPort = this._env("MOOSE_CLICKHOUSE_CONFIG__HOST_PORT");
|
|
1052
|
+
const envUser = this._env("MOOSE_CLICKHOUSE_CONFIG__USER");
|
|
1053
|
+
const envPassword = this._env("MOOSE_CLICKHOUSE_CONFIG__PASSWORD");
|
|
1054
|
+
const envDb = this._env("MOOSE_CLICKHOUSE_CONFIG__DB_NAME");
|
|
1055
|
+
const envUseSSL = this._parseBool(
|
|
1056
|
+
this._env("MOOSE_CLICKHOUSE_CONFIG__USE_SSL")
|
|
1057
|
+
);
|
|
1058
|
+
let projectConfig;
|
|
1059
|
+
try {
|
|
1060
|
+
projectConfig = await readProjectConfig();
|
|
1061
|
+
} catch (error) {
|
|
1062
|
+
projectConfig = null;
|
|
1063
|
+
}
|
|
1064
|
+
const defaults = {
|
|
1065
|
+
host: "localhost",
|
|
1066
|
+
port: "18123",
|
|
1067
|
+
username: "default",
|
|
1068
|
+
password: "",
|
|
1069
|
+
database: "local",
|
|
1070
|
+
useSSL: false
|
|
1071
|
+
};
|
|
1072
|
+
return {
|
|
1073
|
+
host: overrides?.host ?? envHost ?? projectConfig?.clickhouse_config.host ?? defaults.host,
|
|
1074
|
+
port: overrides?.port ?? envPort ?? projectConfig?.clickhouse_config.host_port.toString() ?? defaults.port,
|
|
1075
|
+
username: overrides?.username ?? envUser ?? projectConfig?.clickhouse_config.user ?? defaults.username,
|
|
1076
|
+
password: overrides?.password ?? envPassword ?? projectConfig?.clickhouse_config.password ?? defaults.password,
|
|
1077
|
+
database: overrides?.database ?? envDb ?? projectConfig?.clickhouse_config.db_name ?? defaults.database,
|
|
1078
|
+
useSSL: overrides?.useSSL ?? envUseSSL ?? projectConfig?.clickhouse_config.use_ssl ?? defaults.useSSL
|
|
1079
|
+
};
|
|
1080
|
+
}
|
|
1081
|
+
async getKafkaConfig() {
|
|
1082
|
+
if (this.kafkaConfig) {
|
|
1083
|
+
return this.kafkaConfig;
|
|
1084
|
+
}
|
|
1085
|
+
const projectConfig = await readProjectConfig();
|
|
1086
|
+
const envBroker = this._env("MOOSE_REDPANDA_CONFIG__BROKER") ?? this._env("MOOSE_KAFKA_CONFIG__BROKER");
|
|
1087
|
+
const envMsgTimeout = this._env("MOOSE_REDPANDA_CONFIG__MESSAGE_TIMEOUT_MS") ?? this._env("MOOSE_KAFKA_CONFIG__MESSAGE_TIMEOUT_MS");
|
|
1088
|
+
const envSaslUsername = this._env("MOOSE_REDPANDA_CONFIG__SASL_USERNAME") ?? this._env("MOOSE_KAFKA_CONFIG__SASL_USERNAME");
|
|
1089
|
+
const envSaslPassword = this._env("MOOSE_REDPANDA_CONFIG__SASL_PASSWORD") ?? this._env("MOOSE_KAFKA_CONFIG__SASL_PASSWORD");
|
|
1090
|
+
const envSaslMechanism = this._env("MOOSE_REDPANDA_CONFIG__SASL_MECHANISM") ?? this._env("MOOSE_KAFKA_CONFIG__SASL_MECHANISM");
|
|
1091
|
+
const envSecurityProtocol = this._env("MOOSE_REDPANDA_CONFIG__SECURITY_PROTOCOL") ?? this._env("MOOSE_KAFKA_CONFIG__SECURITY_PROTOCOL");
|
|
1092
|
+
const envNamespace = this._env("MOOSE_REDPANDA_CONFIG__NAMESPACE") ?? this._env("MOOSE_KAFKA_CONFIG__NAMESPACE");
|
|
1093
|
+
const envSchemaRegistryUrl = this._env("MOOSE_REDPANDA_CONFIG__SCHEMA_REGISTRY_URL") ?? this._env("MOOSE_KAFKA_CONFIG__SCHEMA_REGISTRY_URL");
|
|
1094
|
+
const fileKafka = projectConfig.kafka_config ?? projectConfig.redpanda_config;
|
|
1095
|
+
return {
|
|
1096
|
+
broker: envBroker ?? fileKafka?.broker ?? "localhost:19092",
|
|
1097
|
+
messageTimeoutMs: envMsgTimeout ? parseInt(envMsgTimeout, 10) : fileKafka?.message_timeout_ms ?? 1e3,
|
|
1098
|
+
saslUsername: envSaslUsername ?? fileKafka?.sasl_username,
|
|
1099
|
+
saslPassword: envSaslPassword ?? fileKafka?.sasl_password,
|
|
1100
|
+
saslMechanism: envSaslMechanism ?? fileKafka?.sasl_mechanism,
|
|
1101
|
+
securityProtocol: envSecurityProtocol ?? fileKafka?.security_protocol,
|
|
1102
|
+
namespace: envNamespace ?? fileKafka?.namespace,
|
|
1103
|
+
schemaRegistryUrl: envSchemaRegistryUrl ?? fileKafka?.schema_registry_url
|
|
1104
|
+
};
|
|
1105
|
+
}
|
|
1106
|
+
hasRuntimeConfig() {
|
|
1107
|
+
return !!this.clickhouseConfig || !!this.kafkaConfig;
|
|
1108
|
+
}
|
|
1109
|
+
};
|
|
1110
|
+
globalThis._mooseConfigRegistry = ConfigurationRegistry.getInstance();
|
|
1111
|
+
}
|
|
1112
|
+
});
|
|
711
1113
|
|
|
712
|
-
// src/consumption-apis/
|
|
713
|
-
var
|
|
714
|
-
|
|
715
|
-
|
|
1114
|
+
// src/consumption-apis/standalone.ts
|
|
1115
|
+
var standalone_exports = {};
|
|
1116
|
+
__export(standalone_exports, {
|
|
1117
|
+
getMooseClients: () => getMooseClients,
|
|
1118
|
+
getMooseUtils: () => getMooseUtils
|
|
716
1119
|
});
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
1120
|
+
async function getMooseUtils(req) {
|
|
1121
|
+
if (req !== void 0) {
|
|
1122
|
+
console.warn(
|
|
1123
|
+
"[DEPRECATED] getMooseUtils(req) no longer requires a request parameter. Use getMooseUtils() instead."
|
|
1124
|
+
);
|
|
1125
|
+
}
|
|
1126
|
+
const runtimeContext = globalThis._mooseRuntimeContext;
|
|
1127
|
+
if (runtimeContext) {
|
|
1128
|
+
return {
|
|
1129
|
+
client: runtimeContext.client,
|
|
1130
|
+
sql
|
|
1131
|
+
};
|
|
1132
|
+
}
|
|
1133
|
+
if (standaloneUtils) {
|
|
1134
|
+
return standaloneUtils;
|
|
1135
|
+
}
|
|
1136
|
+
await Promise.resolve().then(() => (init_runtime(), runtime_exports));
|
|
1137
|
+
const configRegistry = globalThis._mooseConfigRegistry;
|
|
1138
|
+
if (!configRegistry) {
|
|
1139
|
+
throw new Error(
|
|
1140
|
+
"Moose not initialized. Ensure you're running within a Moose app or have proper configuration set up."
|
|
1141
|
+
);
|
|
1142
|
+
}
|
|
1143
|
+
const clickhouseConfig = await configRegistry.getStandaloneClickhouseConfig();
|
|
1144
|
+
const clickhouseClient = getClickhouseClient(
|
|
1145
|
+
toClientConfig(clickhouseConfig)
|
|
721
1146
|
);
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
1147
|
+
const queryClient = new QueryClient(clickhouseClient, "standalone");
|
|
1148
|
+
const mooseClient = new MooseClient(queryClient);
|
|
1149
|
+
standaloneUtils = {
|
|
1150
|
+
client: mooseClient,
|
|
1151
|
+
sql
|
|
1152
|
+
};
|
|
1153
|
+
return standaloneUtils;
|
|
1154
|
+
}
|
|
1155
|
+
async function getMooseClients(config) {
|
|
1156
|
+
console.warn(
|
|
1157
|
+
"[DEPRECATED] getMooseClients() is deprecated. Use getMooseUtils() instead."
|
|
1158
|
+
);
|
|
1159
|
+
if (config && Object.keys(config).length > 0) {
|
|
1160
|
+
await Promise.resolve().then(() => (init_runtime(), runtime_exports));
|
|
1161
|
+
const configRegistry = globalThis._mooseConfigRegistry;
|
|
1162
|
+
if (!configRegistry) {
|
|
1163
|
+
throw new Error(
|
|
1164
|
+
"Configuration registry not initialized. Ensure the Moose framework is properly set up."
|
|
1165
|
+
);
|
|
1166
|
+
}
|
|
1167
|
+
const clickhouseConfig = await configRegistry.getStandaloneClickhouseConfig(config);
|
|
1168
|
+
const clickhouseClient = getClickhouseClient(
|
|
1169
|
+
toClientConfig(clickhouseConfig)
|
|
1170
|
+
);
|
|
1171
|
+
const queryClient = new QueryClient(clickhouseClient, "standalone");
|
|
1172
|
+
const mooseClient = new MooseClient(queryClient);
|
|
1173
|
+
return { client: mooseClient };
|
|
1174
|
+
}
|
|
1175
|
+
const utils = await getMooseUtils();
|
|
1176
|
+
return { client: utils.client };
|
|
1177
|
+
}
|
|
1178
|
+
var standaloneUtils, toClientConfig;
|
|
1179
|
+
var init_standalone = __esm({
|
|
1180
|
+
"src/consumption-apis/standalone.ts"() {
|
|
1181
|
+
"use strict";
|
|
1182
|
+
init_helpers2();
|
|
1183
|
+
init_commons();
|
|
1184
|
+
init_sqlHelpers();
|
|
1185
|
+
standaloneUtils = null;
|
|
1186
|
+
toClientConfig = (config) => ({
|
|
1187
|
+
...config,
|
|
1188
|
+
useSSL: config.useSSL ? "true" : "false"
|
|
1189
|
+
});
|
|
1190
|
+
}
|
|
1191
|
+
});
|
|
1192
|
+
|
|
1193
|
+
// src/consumption-apis/runner.ts
|
|
1194
|
+
var import_http2, jose, toClientConfig2, createPath, httpLogger, modulesCache, apiHandler, createMainRouter, runApis;
|
|
1195
|
+
var init_runner = __esm({
|
|
1196
|
+
"src/consumption-apis/runner.ts"() {
|
|
1197
|
+
"use strict";
|
|
1198
|
+
import_http2 = __toESM(require("http"));
|
|
1199
|
+
init_commons();
|
|
1200
|
+
init_helpers2();
|
|
1201
|
+
jose = __toESM(require("jose"));
|
|
1202
|
+
init_cluster_utils();
|
|
1203
|
+
init_sqlHelpers();
|
|
1204
|
+
init_internal();
|
|
1205
|
+
toClientConfig2 = (config) => ({
|
|
1206
|
+
...config,
|
|
1207
|
+
useSSL: config.useSSL ? "true" : "false"
|
|
1208
|
+
});
|
|
1209
|
+
createPath = (apisDir, path4) => `${apisDir}${path4}.ts`;
|
|
1210
|
+
httpLogger = (req, res, startMs) => {
|
|
1211
|
+
console.log(
|
|
1212
|
+
`${req.method} ${req.url} ${res.statusCode} ${Date.now() - startMs}ms`
|
|
1213
|
+
);
|
|
1214
|
+
};
|
|
1215
|
+
modulesCache = /* @__PURE__ */ new Map();
|
|
1216
|
+
apiHandler = async (publicKey, clickhouseClient, temporalClient, apisDir, enforceAuth, isDmv2, jwtConfig) => {
|
|
1217
|
+
const apis = isDmv2 ? await getApis2() : /* @__PURE__ */ new Map();
|
|
1218
|
+
return async (req, res) => {
|
|
1219
|
+
const start = Date.now();
|
|
1220
|
+
try {
|
|
1221
|
+
const url = new URL(req.url || "", "http://localhost");
|
|
1222
|
+
const fileName = url.pathname;
|
|
1223
|
+
let jwtPayload;
|
|
1224
|
+
if (publicKey && jwtConfig) {
|
|
1225
|
+
const jwt = req.headers.authorization?.split(" ")[1];
|
|
1226
|
+
if (jwt) {
|
|
1227
|
+
try {
|
|
1228
|
+
const { payload } = await jose.jwtVerify(jwt, publicKey, {
|
|
1229
|
+
issuer: jwtConfig.issuer,
|
|
1230
|
+
audience: jwtConfig.audience
|
|
1231
|
+
});
|
|
1232
|
+
jwtPayload = payload;
|
|
1233
|
+
} catch (error) {
|
|
1234
|
+
console.log("JWT verification failed");
|
|
1235
|
+
if (enforceAuth) {
|
|
1236
|
+
res.writeHead(401, { "Content-Type": "application/json" });
|
|
1237
|
+
res.end(JSON.stringify({ error: "Unauthorized" }));
|
|
1238
|
+
httpLogger(req, res, start);
|
|
1239
|
+
return;
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
} else if (enforceAuth) {
|
|
744
1243
|
res.writeHead(401, { "Content-Type": "application/json" });
|
|
745
1244
|
res.end(JSON.stringify({ error: "Unauthorized" }));
|
|
746
1245
|
httpLogger(req, res, start);
|
|
747
1246
|
return;
|
|
748
1247
|
}
|
|
1248
|
+
} else if (enforceAuth) {
|
|
1249
|
+
res.writeHead(401, { "Content-Type": "application/json" });
|
|
1250
|
+
res.end(JSON.stringify({ error: "Unauthorized" }));
|
|
1251
|
+
httpLogger(req, res, start);
|
|
1252
|
+
return;
|
|
749
1253
|
}
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
if (!userFuncModule) {
|
|
786
|
-
version = url.searchParams.get("version");
|
|
787
|
-
if (!version && apiName.includes("/")) {
|
|
788
|
-
const pathParts = apiName.split("/");
|
|
789
|
-
if (pathParts.length >= 2) {
|
|
790
|
-
userFuncModule = apis.get(apiName);
|
|
1254
|
+
const pathName = createPath(apisDir, fileName);
|
|
1255
|
+
const paramsObject = Array.from(url.searchParams.entries()).reduce(
|
|
1256
|
+
(obj, [key, value]) => {
|
|
1257
|
+
const existingValue = obj[key];
|
|
1258
|
+
if (existingValue) {
|
|
1259
|
+
if (Array.isArray(existingValue)) {
|
|
1260
|
+
existingValue.push(value);
|
|
1261
|
+
} else {
|
|
1262
|
+
obj[key] = [existingValue, value];
|
|
1263
|
+
}
|
|
1264
|
+
} else {
|
|
1265
|
+
obj[key] = value;
|
|
1266
|
+
}
|
|
1267
|
+
return obj;
|
|
1268
|
+
},
|
|
1269
|
+
{}
|
|
1270
|
+
);
|
|
1271
|
+
let userFuncModule = modulesCache.get(pathName);
|
|
1272
|
+
if (userFuncModule === void 0) {
|
|
1273
|
+
if (isDmv2) {
|
|
1274
|
+
let apiName = fileName.replace(/^\/+|\/+$/g, "");
|
|
1275
|
+
let version = null;
|
|
1276
|
+
userFuncModule = apis.get(apiName);
|
|
1277
|
+
if (!userFuncModule) {
|
|
1278
|
+
version = url.searchParams.get("version");
|
|
1279
|
+
if (!version && apiName.includes("/")) {
|
|
1280
|
+
const pathParts = apiName.split("/");
|
|
1281
|
+
if (pathParts.length >= 2) {
|
|
1282
|
+
userFuncModule = apis.get(apiName);
|
|
1283
|
+
if (!userFuncModule) {
|
|
1284
|
+
apiName = pathParts[0];
|
|
1285
|
+
version = pathParts.slice(1).join("/");
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
791
1289
|
if (!userFuncModule) {
|
|
792
|
-
|
|
793
|
-
|
|
1290
|
+
if (version) {
|
|
1291
|
+
const versionedKey = `${apiName}:${version}`;
|
|
1292
|
+
userFuncModule = apis.get(versionedKey);
|
|
1293
|
+
} else {
|
|
1294
|
+
userFuncModule = apis.get(apiName);
|
|
1295
|
+
}
|
|
794
1296
|
}
|
|
795
1297
|
}
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
userFuncModule = apis.get(apiName);
|
|
1298
|
+
if (!userFuncModule) {
|
|
1299
|
+
const availableApis = Array.from(apis.keys()).map(
|
|
1300
|
+
(key) => key.replace(":", "/")
|
|
1301
|
+
);
|
|
1302
|
+
const errorMessage = version ? `API ${apiName} with version ${version} not found. Available APIs: ${availableApis.join(", ")}` : `API ${apiName} not found. Available APIs: ${availableApis.join(", ")}`;
|
|
1303
|
+
throw new Error(errorMessage);
|
|
803
1304
|
}
|
|
1305
|
+
modulesCache.set(pathName, userFuncModule);
|
|
1306
|
+
console.log(`[API] | Executing API: ${apiName}`);
|
|
1307
|
+
} else {
|
|
1308
|
+
userFuncModule = require(pathName);
|
|
1309
|
+
modulesCache.set(pathName, userFuncModule);
|
|
804
1310
|
}
|
|
805
1311
|
}
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
1312
|
+
const queryClient = new QueryClient(clickhouseClient, fileName);
|
|
1313
|
+
let result = isDmv2 ? await userFuncModule(paramsObject, {
|
|
1314
|
+
client: new MooseClient(queryClient, temporalClient),
|
|
1315
|
+
sql,
|
|
1316
|
+
jwt: jwtPayload
|
|
1317
|
+
}) : await userFuncModule.default(paramsObject, {
|
|
1318
|
+
client: new MooseClient(queryClient, temporalClient),
|
|
1319
|
+
sql,
|
|
1320
|
+
jwt: jwtPayload
|
|
1321
|
+
});
|
|
1322
|
+
let body;
|
|
1323
|
+
let status;
|
|
1324
|
+
if (Object.getPrototypeOf(result).constructor.name === "ResultSet") {
|
|
1325
|
+
body = JSON.stringify(await result.json());
|
|
1326
|
+
} else {
|
|
1327
|
+
if ("body" in result && "status" in result) {
|
|
1328
|
+
body = JSON.stringify(result.body);
|
|
1329
|
+
status = result.status;
|
|
1330
|
+
} else {
|
|
1331
|
+
body = JSON.stringify(result);
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
if (status) {
|
|
1335
|
+
res.writeHead(status, { "Content-Type": "application/json" });
|
|
1336
|
+
httpLogger(req, res, start);
|
|
1337
|
+
} else {
|
|
1338
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
1339
|
+
httpLogger(req, res, start);
|
|
1340
|
+
}
|
|
1341
|
+
res.end(body);
|
|
1342
|
+
} catch (error) {
|
|
1343
|
+
console.log("error in path ", req.url, error);
|
|
1344
|
+
if (Object.getPrototypeOf(error).constructor.name === "TypeGuardError") {
|
|
1345
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
1346
|
+
res.end(JSON.stringify({ error: error.message }));
|
|
1347
|
+
httpLogger(req, res, start);
|
|
1348
|
+
}
|
|
1349
|
+
if (error instanceof Error) {
|
|
1350
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
1351
|
+
res.end(JSON.stringify({ error: error.message }));
|
|
1352
|
+
httpLogger(req, res, start);
|
|
1353
|
+
} else {
|
|
1354
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
1355
|
+
res.end();
|
|
1356
|
+
httpLogger(req, res, start);
|
|
812
1357
|
}
|
|
813
|
-
modulesCache.set(pathName, userFuncModule);
|
|
814
|
-
console.log(`[API] | Executing API: ${apiName}`);
|
|
815
|
-
} else {
|
|
816
|
-
userFuncModule = require(pathName);
|
|
817
|
-
modulesCache.set(pathName, userFuncModule);
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
const queryClient = new QueryClient(clickhouseClient, fileName);
|
|
821
|
-
let result = isDmv2 ? await userFuncModule(paramsObject, {
|
|
822
|
-
client: new MooseClient(queryClient, temporalClient),
|
|
823
|
-
sql,
|
|
824
|
-
jwt: jwtPayload
|
|
825
|
-
}) : await userFuncModule.default(paramsObject, {
|
|
826
|
-
client: new MooseClient(queryClient, temporalClient),
|
|
827
|
-
sql,
|
|
828
|
-
jwt: jwtPayload
|
|
829
|
-
});
|
|
830
|
-
let body;
|
|
831
|
-
let status;
|
|
832
|
-
if (Object.getPrototypeOf(result).constructor.name === "ResultSet") {
|
|
833
|
-
body = JSON.stringify(await result.json());
|
|
834
|
-
} else {
|
|
835
|
-
if ("body" in result && "status" in result) {
|
|
836
|
-
body = JSON.stringify(result.body);
|
|
837
|
-
status = result.status;
|
|
838
|
-
} else {
|
|
839
|
-
body = JSON.stringify(result);
|
|
840
1358
|
}
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
if (Object.getPrototypeOf(error).constructor.name === "TypeGuardError") {
|
|
853
|
-
res.writeHead(400, { "Content-Type": "application/json" });
|
|
854
|
-
res.end(JSON.stringify({ error: error.message }));
|
|
855
|
-
httpLogger(req, res, start);
|
|
856
|
-
}
|
|
857
|
-
if (error instanceof Error) {
|
|
858
|
-
res.writeHead(500, { "Content-Type": "application/json" });
|
|
859
|
-
res.end(JSON.stringify({ error: error.message }));
|
|
860
|
-
httpLogger(req, res, start);
|
|
861
|
-
} else {
|
|
862
|
-
res.writeHead(500, { "Content-Type": "application/json" });
|
|
863
|
-
res.end();
|
|
864
|
-
httpLogger(req, res, start);
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
};
|
|
868
|
-
};
|
|
869
|
-
var createMainRouter = async (publicKey, clickhouseClient, temporalClient, apisDir, enforceAuth, isDmv2, jwtConfig) => {
|
|
870
|
-
const apiRequestHandler = await apiHandler(
|
|
871
|
-
publicKey,
|
|
872
|
-
clickhouseClient,
|
|
873
|
-
temporalClient,
|
|
874
|
-
apisDir,
|
|
875
|
-
enforceAuth,
|
|
876
|
-
isDmv2,
|
|
877
|
-
jwtConfig
|
|
878
|
-
);
|
|
879
|
-
const webApps = isDmv2 ? await getWebApps2() : /* @__PURE__ */ new Map();
|
|
880
|
-
const sortedWebApps = Array.from(webApps.values()).sort((a, b) => {
|
|
881
|
-
const pathA = a.config.mountPath || "/";
|
|
882
|
-
const pathB = b.config.mountPath || "/";
|
|
883
|
-
return pathB.length - pathA.length;
|
|
884
|
-
});
|
|
885
|
-
return async (req, res) => {
|
|
886
|
-
const start = Date.now();
|
|
887
|
-
const url = new URL(req.url || "", "http://localhost");
|
|
888
|
-
const pathname = url.pathname;
|
|
889
|
-
if (pathname === "/_moose_internal/health") {
|
|
890
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
891
|
-
res.end(
|
|
892
|
-
JSON.stringify({
|
|
893
|
-
status: "healthy",
|
|
894
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
895
|
-
})
|
|
1359
|
+
};
|
|
1360
|
+
};
|
|
1361
|
+
createMainRouter = async (publicKey, clickhouseClient, temporalClient, apisDir, enforceAuth, isDmv2, jwtConfig) => {
|
|
1362
|
+
const apiRequestHandler = await apiHandler(
|
|
1363
|
+
publicKey,
|
|
1364
|
+
clickhouseClient,
|
|
1365
|
+
temporalClient,
|
|
1366
|
+
apisDir,
|
|
1367
|
+
enforceAuth,
|
|
1368
|
+
isDmv2,
|
|
1369
|
+
jwtConfig
|
|
896
1370
|
);
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
1371
|
+
const webApps = isDmv2 ? await getWebApps2() : /* @__PURE__ */ new Map();
|
|
1372
|
+
const sortedWebApps = Array.from(webApps.values()).sort((a, b) => {
|
|
1373
|
+
const pathA = a.config.mountPath || "/";
|
|
1374
|
+
const pathB = b.config.mountPath || "/";
|
|
1375
|
+
return pathB.length - pathA.length;
|
|
1376
|
+
});
|
|
1377
|
+
return async (req, res) => {
|
|
1378
|
+
const start = Date.now();
|
|
1379
|
+
const url = new URL(req.url || "", "http://localhost");
|
|
1380
|
+
const pathname = url.pathname;
|
|
1381
|
+
if (pathname === "/_moose_internal/health") {
|
|
1382
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
1383
|
+
res.end(
|
|
1384
|
+
JSON.stringify({
|
|
1385
|
+
status: "healthy",
|
|
1386
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
1387
|
+
})
|
|
1388
|
+
);
|
|
1389
|
+
return;
|
|
911
1390
|
}
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
}
|
|
1391
|
+
let jwtPayload;
|
|
1392
|
+
if (publicKey && jwtConfig) {
|
|
1393
|
+
const jwt = req.headers.authorization?.split(" ")[1];
|
|
1394
|
+
if (jwt) {
|
|
1395
|
+
try {
|
|
1396
|
+
const { payload } = await jose.jwtVerify(jwt, publicKey, {
|
|
1397
|
+
issuer: jwtConfig.issuer,
|
|
1398
|
+
audience: jwtConfig.audience
|
|
1399
|
+
});
|
|
1400
|
+
jwtPayload = payload;
|
|
1401
|
+
} catch (error) {
|
|
1402
|
+
console.log("JWT verification failed for WebApp route");
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
for (const webApp of sortedWebApps) {
|
|
1407
|
+
const mountPath = webApp.config.mountPath || "/";
|
|
1408
|
+
const normalizedMount = mountPath.endsWith("/") && mountPath !== "/" ? mountPath.slice(0, -1) : mountPath;
|
|
1409
|
+
const matches = pathname === normalizedMount || pathname.startsWith(normalizedMount + "/");
|
|
1410
|
+
if (matches) {
|
|
1411
|
+
if (webApp.config.injectMooseUtils !== false) {
|
|
1412
|
+
const { getMooseUtils: getMooseUtils2 } = await Promise.resolve().then(() => (init_standalone(), standalone_exports));
|
|
1413
|
+
req.moose = await getMooseUtils2();
|
|
1414
|
+
}
|
|
1415
|
+
let proxiedUrl = req.url;
|
|
1416
|
+
if (normalizedMount !== "/") {
|
|
1417
|
+
const pathWithoutMount = pathname.substring(normalizedMount.length) || "/";
|
|
1418
|
+
proxiedUrl = pathWithoutMount + url.search;
|
|
1419
|
+
}
|
|
1420
|
+
try {
|
|
1421
|
+
const modifiedReq = Object.assign(
|
|
1422
|
+
Object.create(Object.getPrototypeOf(req)),
|
|
1423
|
+
req,
|
|
1424
|
+
{
|
|
1425
|
+
url: proxiedUrl
|
|
1426
|
+
}
|
|
1427
|
+
);
|
|
1428
|
+
await webApp.handler(modifiedReq, res);
|
|
1429
|
+
return;
|
|
1430
|
+
} catch (error) {
|
|
1431
|
+
console.error(`Error in WebApp ${webApp.name}:`, error);
|
|
1432
|
+
if (!res.headersSent) {
|
|
1433
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
1434
|
+
res.end(JSON.stringify({ error: "Internal Server Error" }));
|
|
1435
|
+
}
|
|
1436
|
+
return;
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
926
1439
|
}
|
|
927
|
-
let
|
|
928
|
-
if (
|
|
929
|
-
|
|
930
|
-
|
|
1440
|
+
let apiPath = pathname;
|
|
1441
|
+
if (pathname.startsWith("/api/")) {
|
|
1442
|
+
apiPath = pathname.substring(4);
|
|
1443
|
+
} else if (pathname.startsWith("/consumption/")) {
|
|
1444
|
+
apiPath = pathname.substring(13);
|
|
931
1445
|
}
|
|
932
|
-
|
|
1446
|
+
if (apiPath !== pathname) {
|
|
933
1447
|
const modifiedReq = Object.assign(
|
|
934
1448
|
Object.create(Object.getPrototypeOf(req)),
|
|
935
1449
|
req,
|
|
936
1450
|
{
|
|
937
|
-
url:
|
|
1451
|
+
url: apiPath + url.search
|
|
938
1452
|
}
|
|
939
1453
|
);
|
|
940
|
-
await
|
|
941
|
-
return;
|
|
942
|
-
} catch (error) {
|
|
943
|
-
console.error(`Error in WebApp ${webApp.name}:`, error);
|
|
944
|
-
if (!res.headersSent) {
|
|
945
|
-
res.writeHead(500, { "Content-Type": "application/json" });
|
|
946
|
-
res.end(JSON.stringify({ error: "Internal Server Error" }));
|
|
947
|
-
}
|
|
1454
|
+
await apiRequestHandler(modifiedReq, res);
|
|
948
1455
|
return;
|
|
949
1456
|
}
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
1457
|
+
res.writeHead(404, { "Content-Type": "application/json" });
|
|
1458
|
+
res.end(JSON.stringify({ error: "Not Found" }));
|
|
1459
|
+
httpLogger(req, res, start);
|
|
1460
|
+
};
|
|
1461
|
+
};
|
|
1462
|
+
runApis = async (config) => {
|
|
1463
|
+
const apisCluster = new Cluster({
|
|
1464
|
+
maxWorkerCount: (config.workerCount ?? 0) > 0 ? config.workerCount : void 0,
|
|
1465
|
+
workerStart: async () => {
|
|
1466
|
+
let temporalClient;
|
|
1467
|
+
if (config.temporalConfig) {
|
|
1468
|
+
temporalClient = await getTemporalClient(
|
|
1469
|
+
config.temporalConfig.url,
|
|
1470
|
+
config.temporalConfig.namespace,
|
|
1471
|
+
config.temporalConfig.clientCert,
|
|
1472
|
+
config.temporalConfig.clientKey,
|
|
1473
|
+
config.temporalConfig.apiKey
|
|
1474
|
+
);
|
|
1475
|
+
}
|
|
1476
|
+
const clickhouseClient = getClickhouseClient(
|
|
1477
|
+
toClientConfig2(config.clickhouseConfig)
|
|
1478
|
+
);
|
|
1479
|
+
let publicKey;
|
|
1480
|
+
if (config.jwtConfig?.secret) {
|
|
1481
|
+
console.log("Importing JWT public key...");
|
|
1482
|
+
publicKey = await jose.importSPKI(config.jwtConfig.secret, "RS256");
|
|
1483
|
+
}
|
|
1484
|
+
const runtimeQueryClient = new QueryClient(clickhouseClient, "runtime");
|
|
1485
|
+
globalThis._mooseRuntimeContext = {
|
|
1486
|
+
client: new MooseClient(runtimeQueryClient, temporalClient)
|
|
1487
|
+
};
|
|
1488
|
+
const server = import_http2.default.createServer(
|
|
1489
|
+
await createMainRouter(
|
|
1490
|
+
publicKey,
|
|
1491
|
+
clickhouseClient,
|
|
1492
|
+
temporalClient,
|
|
1493
|
+
config.apisDir,
|
|
1494
|
+
config.enforceAuth,
|
|
1495
|
+
config.isDmv2,
|
|
1496
|
+
config.jwtConfig
|
|
1497
|
+
)
|
|
1498
|
+
);
|
|
1499
|
+
const port = config.proxyPort !== void 0 ? config.proxyPort : 4001;
|
|
1500
|
+
server.listen(port, "localhost", () => {
|
|
1501
|
+
console.log(`Server running on port ${port}`);
|
|
1502
|
+
});
|
|
1503
|
+
return server;
|
|
1504
|
+
},
|
|
1505
|
+
workerStop: async (server) => {
|
|
1506
|
+
return new Promise((resolve2) => {
|
|
1507
|
+
server.close(() => resolve2());
|
|
1508
|
+
});
|
|
964
1509
|
}
|
|
965
|
-
);
|
|
966
|
-
await apiRequestHandler(modifiedReq, res);
|
|
967
|
-
return;
|
|
968
|
-
}
|
|
969
|
-
res.writeHead(404, { "Content-Type": "application/json" });
|
|
970
|
-
res.end(JSON.stringify({ error: "Not Found" }));
|
|
971
|
-
httpLogger(req, res, start);
|
|
972
|
-
};
|
|
973
|
-
};
|
|
974
|
-
var runApis = async (config) => {
|
|
975
|
-
const apisCluster = new Cluster({
|
|
976
|
-
maxWorkerCount: (config.workerCount ?? 0) > 0 ? config.workerCount : void 0,
|
|
977
|
-
workerStart: async () => {
|
|
978
|
-
let temporalClient;
|
|
979
|
-
if (config.temporalConfig) {
|
|
980
|
-
temporalClient = await getTemporalClient(
|
|
981
|
-
config.temporalConfig.url,
|
|
982
|
-
config.temporalConfig.namespace,
|
|
983
|
-
config.temporalConfig.clientCert,
|
|
984
|
-
config.temporalConfig.clientKey,
|
|
985
|
-
config.temporalConfig.apiKey
|
|
986
|
-
);
|
|
987
|
-
}
|
|
988
|
-
const clickhouseClient = getClickhouseClient(
|
|
989
|
-
toClientConfig(config.clickhouseConfig)
|
|
990
|
-
);
|
|
991
|
-
let publicKey;
|
|
992
|
-
if (config.jwtConfig?.secret) {
|
|
993
|
-
console.log("Importing JWT public key...");
|
|
994
|
-
publicKey = await jose.importSPKI(config.jwtConfig.secret, "RS256");
|
|
995
|
-
}
|
|
996
|
-
const server = import_http2.default.createServer(
|
|
997
|
-
await createMainRouter(
|
|
998
|
-
publicKey,
|
|
999
|
-
clickhouseClient,
|
|
1000
|
-
temporalClient,
|
|
1001
|
-
config.apisDir,
|
|
1002
|
-
config.enforceAuth,
|
|
1003
|
-
config.isDmv2,
|
|
1004
|
-
config.jwtConfig
|
|
1005
|
-
)
|
|
1006
|
-
);
|
|
1007
|
-
const port = config.proxyPort !== void 0 ? config.proxyPort : 4001;
|
|
1008
|
-
server.listen(port, "localhost", () => {
|
|
1009
|
-
console.log(`Server running on port ${port}`);
|
|
1010
|
-
});
|
|
1011
|
-
return server;
|
|
1012
|
-
},
|
|
1013
|
-
workerStop: async (server) => {
|
|
1014
|
-
return new Promise((resolve2) => {
|
|
1015
|
-
server.close(() => resolve2());
|
|
1016
1510
|
});
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
};
|
|
1511
|
+
apisCluster.start();
|
|
1512
|
+
};
|
|
1513
|
+
}
|
|
1514
|
+
});
|
|
1021
1515
|
|
|
1022
1516
|
// src/clients/redisClient.ts
|
|
1023
|
-
var import_redis
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1517
|
+
var import_redis;
|
|
1518
|
+
var init_redisClient = __esm({
|
|
1519
|
+
"src/clients/redisClient.ts"() {
|
|
1520
|
+
"use strict";
|
|
1521
|
+
import_redis = require("redis");
|
|
1522
|
+
}
|
|
1523
|
+
});
|
|
1030
1524
|
|
|
1031
1525
|
// src/utilities/json.ts
|
|
1032
|
-
var STRING_DATE_ANNOTATION = "stringDate";
|
|
1033
1526
|
function isNullableType(dt) {
|
|
1034
1527
|
return typeof dt === "object" && dt !== null && "nullable" in dt && typeof dt.nullable !== "undefined";
|
|
1035
1528
|
}
|
|
@@ -1148,36 +1641,77 @@ function mutateParsedJson(data, fieldMutations) {
|
|
|
1148
1641
|
}
|
|
1149
1642
|
applyFieldMutations(data, fieldMutations);
|
|
1150
1643
|
}
|
|
1644
|
+
var STRING_DATE_ANNOTATION;
|
|
1645
|
+
var init_json = __esm({
|
|
1646
|
+
"src/utilities/json.ts"() {
|
|
1647
|
+
"use strict";
|
|
1648
|
+
STRING_DATE_ANNOTATION = "stringDate";
|
|
1649
|
+
}
|
|
1650
|
+
});
|
|
1151
1651
|
|
|
1152
1652
|
// src/utilities/dataParser.ts
|
|
1153
|
-
var CSV_DELIMITERS
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
};
|
|
1653
|
+
var import_csv_parse, CSV_DELIMITERS, DEFAULT_CSV_CONFIG;
|
|
1654
|
+
var init_dataParser = __esm({
|
|
1655
|
+
"src/utilities/dataParser.ts"() {
|
|
1656
|
+
"use strict";
|
|
1657
|
+
import_csv_parse = require("csv-parse");
|
|
1658
|
+
init_json();
|
|
1659
|
+
CSV_DELIMITERS = {
|
|
1660
|
+
COMMA: ",",
|
|
1661
|
+
TAB: " ",
|
|
1662
|
+
SEMICOLON: ";",
|
|
1663
|
+
PIPE: "|"
|
|
1664
|
+
};
|
|
1665
|
+
DEFAULT_CSV_CONFIG = {
|
|
1666
|
+
delimiter: CSV_DELIMITERS.COMMA,
|
|
1667
|
+
columns: true,
|
|
1668
|
+
skipEmptyLines: true,
|
|
1669
|
+
trim: true
|
|
1670
|
+
};
|
|
1671
|
+
}
|
|
1672
|
+
});
|
|
1673
|
+
|
|
1674
|
+
// src/utilities/index.ts
|
|
1675
|
+
var init_utilities = __esm({
|
|
1676
|
+
"src/utilities/index.ts"() {
|
|
1677
|
+
"use strict";
|
|
1678
|
+
init_dataParser();
|
|
1679
|
+
}
|
|
1680
|
+
});
|
|
1681
|
+
|
|
1682
|
+
// src/connectors/dataSource.ts
|
|
1683
|
+
var init_dataSource = __esm({
|
|
1684
|
+
"src/connectors/dataSource.ts"() {
|
|
1685
|
+
"use strict";
|
|
1686
|
+
}
|
|
1687
|
+
});
|
|
1688
|
+
|
|
1689
|
+
// src/index.ts
|
|
1690
|
+
var init_index = __esm({
|
|
1691
|
+
"src/index.ts"() {
|
|
1692
|
+
"use strict";
|
|
1693
|
+
init_browserCompatible();
|
|
1694
|
+
init_helpers();
|
|
1695
|
+
init_commons();
|
|
1696
|
+
init_secrets();
|
|
1697
|
+
init_helpers2();
|
|
1698
|
+
init_webAppHelpers();
|
|
1699
|
+
init_task();
|
|
1700
|
+
init_runner();
|
|
1701
|
+
init_redisClient();
|
|
1702
|
+
init_helpers2();
|
|
1703
|
+
init_standalone();
|
|
1704
|
+
init_sqlHelpers();
|
|
1705
|
+
init_utilities();
|
|
1706
|
+
init_dataSource();
|
|
1707
|
+
init_types();
|
|
1708
|
+
}
|
|
1709
|
+
});
|
|
1165
1710
|
|
|
1166
1711
|
// src/dmv2/internal.ts
|
|
1167
|
-
init_commons();
|
|
1168
1712
|
function getSourceDir() {
|
|
1169
1713
|
return import_process.default.env.MOOSE_SOURCE_DIR || "app";
|
|
1170
1714
|
}
|
|
1171
|
-
var moose_internal = {
|
|
1172
|
-
tables: /* @__PURE__ */ new Map(),
|
|
1173
|
-
streams: /* @__PURE__ */ new Map(),
|
|
1174
|
-
ingestApis: /* @__PURE__ */ new Map(),
|
|
1175
|
-
apis: /* @__PURE__ */ new Map(),
|
|
1176
|
-
sqlResources: /* @__PURE__ */ new Map(),
|
|
1177
|
-
workflows: /* @__PURE__ */ new Map(),
|
|
1178
|
-
webApps: /* @__PURE__ */ new Map()
|
|
1179
|
-
};
|
|
1180
|
-
var defaultRetentionPeriod = 60 * 60 * 24 * 7;
|
|
1181
1715
|
function isS3QueueConfig(config) {
|
|
1182
1716
|
return "engine" in config && config.engine === "S3Queue" /* S3Queue */;
|
|
1183
1717
|
}
|
|
@@ -1414,364 +1948,387 @@ function convertTableConfigToEngineConfig(config) {
|
|
|
1414
1948
|
}
|
|
1415
1949
|
return void 0;
|
|
1416
1950
|
}
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
const id = table.config.version ? `${table.name}_${table.config.version}` : table.name;
|
|
1427
|
-
let metadata = table.metadata;
|
|
1428
|
-
if (!metadata && table.config && table.pipelineParent) {
|
|
1429
|
-
metadata = table.pipelineParent.metadata;
|
|
1430
|
-
}
|
|
1431
|
-
const engineConfig = convertTableConfigToEngineConfig(table.config);
|
|
1432
|
-
let tableSettings = void 0;
|
|
1433
|
-
if (table.config.settings) {
|
|
1434
|
-
tableSettings = Object.entries(table.config.settings).reduce(
|
|
1435
|
-
(acc, [key, value]) => {
|
|
1436
|
-
if (value !== void 0) {
|
|
1437
|
-
acc[key] = String(value);
|
|
1438
|
-
}
|
|
1439
|
-
return acc;
|
|
1440
|
-
},
|
|
1441
|
-
{}
|
|
1442
|
-
);
|
|
1443
|
-
}
|
|
1444
|
-
if (engineConfig?.engine === "S3Queue") {
|
|
1445
|
-
if (!tableSettings) {
|
|
1446
|
-
tableSettings = {};
|
|
1447
|
-
}
|
|
1448
|
-
if (!tableSettings.mode) {
|
|
1449
|
-
tableSettings.mode = "unordered";
|
|
1951
|
+
function findTaskInTree(task, targetName) {
|
|
1952
|
+
if (task.name === targetName) {
|
|
1953
|
+
return task;
|
|
1954
|
+
}
|
|
1955
|
+
if (task.config.onComplete?.length) {
|
|
1956
|
+
for (const childTask of task.config.onComplete) {
|
|
1957
|
+
const found = findTaskInTree(childTask, targetName);
|
|
1958
|
+
if (found) {
|
|
1959
|
+
return found;
|
|
1450
1960
|
}
|
|
1451
1961
|
}
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
lifeCycle: table.config.lifeCycle,
|
|
1471
|
-
// Map 'settings' to 'tableSettings' for internal use
|
|
1472
|
-
tableSettings: tableSettings && Object.keys(tableSettings).length > 0 ? tableSettings : void 0,
|
|
1473
|
-
indexes: table.config.indexes?.map((i) => ({
|
|
1474
|
-
...i,
|
|
1475
|
-
granularity: i.granularity === void 0 ? 1 : i.granularity,
|
|
1476
|
-
arguments: i.arguments === void 0 ? [] : i.arguments
|
|
1477
|
-
})) || [],
|
|
1478
|
-
ttl: table.config.ttl,
|
|
1479
|
-
database: table.config.database,
|
|
1480
|
-
cluster: table.config.cluster
|
|
1962
|
+
}
|
|
1963
|
+
return void 0;
|
|
1964
|
+
}
|
|
1965
|
+
var import_process, moose_internal, defaultRetentionPeriod, toInfraMap, getMooseInternal, dumpMooseInternal, loadIndex, getStreamingFunctions, getApis2, getWorkflows2, getTaskForWorkflow, getWebApps2;
|
|
1966
|
+
var init_internal = __esm({
|
|
1967
|
+
"src/dmv2/internal.ts"() {
|
|
1968
|
+
"use strict";
|
|
1969
|
+
import_process = __toESM(require("process"));
|
|
1970
|
+
init_index();
|
|
1971
|
+
init_commons();
|
|
1972
|
+
moose_internal = {
|
|
1973
|
+
tables: /* @__PURE__ */ new Map(),
|
|
1974
|
+
streams: /* @__PURE__ */ new Map(),
|
|
1975
|
+
ingestApis: /* @__PURE__ */ new Map(),
|
|
1976
|
+
apis: /* @__PURE__ */ new Map(),
|
|
1977
|
+
sqlResources: /* @__PURE__ */ new Map(),
|
|
1978
|
+
workflows: /* @__PURE__ */ new Map(),
|
|
1979
|
+
webApps: /* @__PURE__ */ new Map()
|
|
1481
1980
|
};
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1981
|
+
defaultRetentionPeriod = 60 * 60 * 24 * 7;
|
|
1982
|
+
toInfraMap = (registry) => {
|
|
1983
|
+
const tables = {};
|
|
1984
|
+
const topics = {};
|
|
1985
|
+
const ingestApis = {};
|
|
1986
|
+
const apis = {};
|
|
1987
|
+
const sqlResources = {};
|
|
1988
|
+
const workflows = {};
|
|
1989
|
+
const webApps = {};
|
|
1990
|
+
registry.tables.forEach((table) => {
|
|
1991
|
+
const id = table.config.version ? `${table.name}_${table.config.version}` : table.name;
|
|
1992
|
+
let metadata = table.metadata;
|
|
1993
|
+
if (!metadata && table.config && table.pipelineParent) {
|
|
1994
|
+
metadata = table.pipelineParent.metadata;
|
|
1995
|
+
}
|
|
1996
|
+
const engineConfig = convertTableConfigToEngineConfig(table.config);
|
|
1997
|
+
let tableSettings = void 0;
|
|
1998
|
+
if (table.config.settings) {
|
|
1999
|
+
tableSettings = Object.entries(table.config.settings).reduce(
|
|
2000
|
+
(acc, [key, value]) => {
|
|
2001
|
+
if (value !== void 0) {
|
|
2002
|
+
acc[key] = String(value);
|
|
2003
|
+
}
|
|
2004
|
+
return acc;
|
|
2005
|
+
},
|
|
2006
|
+
{}
|
|
2007
|
+
);
|
|
2008
|
+
}
|
|
2009
|
+
if (engineConfig?.engine === "S3Queue") {
|
|
2010
|
+
if (!tableSettings) {
|
|
2011
|
+
tableSettings = {};
|
|
2012
|
+
}
|
|
2013
|
+
if (!tableSettings.mode) {
|
|
2014
|
+
tableSettings.mode = "unordered";
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
const hasOrderByFields = "orderByFields" in table.config && Array.isArray(table.config.orderByFields) && table.config.orderByFields.length > 0;
|
|
2018
|
+
const hasOrderByExpression = "orderByExpression" in table.config && typeof table.config.orderByExpression === "string" && table.config.orderByExpression.length > 0;
|
|
2019
|
+
if (hasOrderByFields && hasOrderByExpression) {
|
|
2020
|
+
throw new Error(
|
|
2021
|
+
`Table ${table.name}: Provide either orderByFields or orderByExpression, not both.`
|
|
2022
|
+
);
|
|
2023
|
+
}
|
|
2024
|
+
const orderBy = hasOrderByExpression && "orderByExpression" in table.config ? table.config.orderByExpression ?? "" : "orderByFields" in table.config ? table.config.orderByFields ?? [] : [];
|
|
2025
|
+
tables[id] = {
|
|
2026
|
+
name: table.name,
|
|
2027
|
+
columns: table.columnArray,
|
|
2028
|
+
orderBy,
|
|
2029
|
+
partitionBy: "partitionBy" in table.config ? table.config.partitionBy : void 0,
|
|
2030
|
+
sampleByExpression: "sampleByExpression" in table.config ? table.config.sampleByExpression : void 0,
|
|
2031
|
+
primaryKeyExpression: "primaryKeyExpression" in table.config ? table.config.primaryKeyExpression : void 0,
|
|
2032
|
+
engineConfig,
|
|
2033
|
+
version: table.config.version,
|
|
2034
|
+
metadata,
|
|
2035
|
+
lifeCycle: table.config.lifeCycle,
|
|
2036
|
+
// Map 'settings' to 'tableSettings' for internal use
|
|
2037
|
+
tableSettings: tableSettings && Object.keys(tableSettings).length > 0 ? tableSettings : void 0,
|
|
2038
|
+
indexes: table.config.indexes?.map((i) => ({
|
|
2039
|
+
...i,
|
|
2040
|
+
granularity: i.granularity === void 0 ? 1 : i.granularity,
|
|
2041
|
+
arguments: i.arguments === void 0 ? [] : i.arguments
|
|
2042
|
+
})) || [],
|
|
2043
|
+
ttl: table.config.ttl,
|
|
2044
|
+
database: table.config.database,
|
|
2045
|
+
cluster: table.config.cluster
|
|
2046
|
+
};
|
|
2047
|
+
});
|
|
2048
|
+
registry.streams.forEach((stream) => {
|
|
2049
|
+
let metadata = stream.metadata;
|
|
2050
|
+
if (!metadata && stream.config && stream.pipelineParent) {
|
|
2051
|
+
metadata = stream.pipelineParent.metadata;
|
|
2052
|
+
}
|
|
2053
|
+
const transformationTargets = [];
|
|
2054
|
+
const consumers = [];
|
|
2055
|
+
stream._transformations.forEach((transforms, destinationName) => {
|
|
2056
|
+
transforms.forEach(([destination, _, config]) => {
|
|
2057
|
+
transformationTargets.push({
|
|
2058
|
+
kind: "stream",
|
|
2059
|
+
name: destinationName,
|
|
2060
|
+
version: config.version,
|
|
2061
|
+
metadata: config.metadata,
|
|
2062
|
+
sourceFile: config.sourceFile
|
|
2063
|
+
});
|
|
2064
|
+
});
|
|
2065
|
+
});
|
|
2066
|
+
stream._consumers.forEach((consumer) => {
|
|
2067
|
+
consumers.push({
|
|
2068
|
+
version: consumer.config.version,
|
|
2069
|
+
sourceFile: consumer.config.sourceFile
|
|
2070
|
+
});
|
|
1498
2071
|
});
|
|
2072
|
+
topics[stream.name] = {
|
|
2073
|
+
name: stream.name,
|
|
2074
|
+
columns: stream.columnArray,
|
|
2075
|
+
targetTable: stream.config.destination?.name,
|
|
2076
|
+
targetTableVersion: stream.config.destination?.config.version,
|
|
2077
|
+
retentionPeriod: stream.config.retentionPeriod ?? defaultRetentionPeriod,
|
|
2078
|
+
partitionCount: stream.config.parallelism ?? 1,
|
|
2079
|
+
version: stream.config.version,
|
|
2080
|
+
transformationTargets,
|
|
2081
|
+
hasMultiTransform: stream._multipleTransformations === void 0,
|
|
2082
|
+
consumers,
|
|
2083
|
+
metadata,
|
|
2084
|
+
lifeCycle: stream.config.lifeCycle,
|
|
2085
|
+
schemaConfig: stream.config.schemaConfig
|
|
2086
|
+
};
|
|
1499
2087
|
});
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
2088
|
+
registry.ingestApis.forEach((api) => {
|
|
2089
|
+
let metadata = api.metadata;
|
|
2090
|
+
if (!metadata && api.config && api.pipelineParent) {
|
|
2091
|
+
metadata = api.pipelineParent.metadata;
|
|
2092
|
+
}
|
|
2093
|
+
ingestApis[api.name] = {
|
|
2094
|
+
name: api.name,
|
|
2095
|
+
columns: api.columnArray,
|
|
2096
|
+
version: api.config.version,
|
|
2097
|
+
path: api.config.path,
|
|
2098
|
+
writeTo: {
|
|
2099
|
+
kind: "stream",
|
|
2100
|
+
name: api.config.destination.name
|
|
2101
|
+
},
|
|
2102
|
+
deadLetterQueue: api.config.deadLetterQueue?.name,
|
|
2103
|
+
metadata,
|
|
2104
|
+
schema: api.schema,
|
|
2105
|
+
allowExtraFields: api.allowExtraFields
|
|
2106
|
+
};
|
|
1505
2107
|
});
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
2108
|
+
registry.apis.forEach((api, key) => {
|
|
2109
|
+
const rustKey = api.config.version ? `${api.name}:${api.config.version}` : api.name;
|
|
2110
|
+
apis[rustKey] = {
|
|
2111
|
+
name: api.name,
|
|
2112
|
+
queryParams: api.columnArray,
|
|
2113
|
+
responseSchema: api.responseSchema,
|
|
2114
|
+
version: api.config.version,
|
|
2115
|
+
path: api.config.path,
|
|
2116
|
+
metadata: api.metadata
|
|
2117
|
+
};
|
|
2118
|
+
});
|
|
2119
|
+
registry.sqlResources.forEach((sqlResource) => {
|
|
2120
|
+
sqlResources[sqlResource.name] = {
|
|
2121
|
+
name: sqlResource.name,
|
|
2122
|
+
setup: sqlResource.setup,
|
|
2123
|
+
teardown: sqlResource.teardown,
|
|
2124
|
+
sourceFile: sqlResource.sourceFile,
|
|
2125
|
+
sourceLine: sqlResource.sourceLine,
|
|
2126
|
+
sourceColumn: sqlResource.sourceColumn,
|
|
2127
|
+
pullsDataFrom: sqlResource.pullsDataFrom.map((r) => {
|
|
2128
|
+
if (r.kind === "OlapTable") {
|
|
2129
|
+
const table = r;
|
|
2130
|
+
const id = table.config.version ? `${table.name}_${table.config.version}` : table.name;
|
|
2131
|
+
return {
|
|
2132
|
+
id,
|
|
2133
|
+
kind: "Table"
|
|
2134
|
+
};
|
|
2135
|
+
} else if (r.kind === "SqlResource") {
|
|
2136
|
+
const resource = r;
|
|
2137
|
+
return {
|
|
2138
|
+
id: resource.name,
|
|
2139
|
+
kind: "SqlResource"
|
|
2140
|
+
};
|
|
2141
|
+
} else {
|
|
2142
|
+
throw new Error(`Unknown sql resource dependency type: ${r}`);
|
|
2143
|
+
}
|
|
2144
|
+
}),
|
|
2145
|
+
pushesDataTo: sqlResource.pushesDataTo.map((r) => {
|
|
2146
|
+
if (r.kind === "OlapTable") {
|
|
2147
|
+
const table = r;
|
|
2148
|
+
const id = table.config.version ? `${table.name}_${table.config.version}` : table.name;
|
|
2149
|
+
return {
|
|
2150
|
+
id,
|
|
2151
|
+
kind: "Table"
|
|
2152
|
+
};
|
|
2153
|
+
} else if (r.kind === "SqlResource") {
|
|
2154
|
+
const resource = r;
|
|
2155
|
+
return {
|
|
2156
|
+
id: resource.name,
|
|
2157
|
+
kind: "SqlResource"
|
|
2158
|
+
};
|
|
2159
|
+
} else {
|
|
2160
|
+
throw new Error(`Unknown sql resource dependency type: ${r}`);
|
|
2161
|
+
}
|
|
2162
|
+
})
|
|
2163
|
+
};
|
|
2164
|
+
});
|
|
2165
|
+
registry.workflows.forEach((workflow) => {
|
|
2166
|
+
workflows[workflow.name] = {
|
|
2167
|
+
name: workflow.name,
|
|
2168
|
+
retries: workflow.config.retries,
|
|
2169
|
+
timeout: workflow.config.timeout,
|
|
2170
|
+
schedule: workflow.config.schedule
|
|
2171
|
+
};
|
|
2172
|
+
});
|
|
2173
|
+
registry.webApps.forEach((webApp) => {
|
|
2174
|
+
webApps[webApp.name] = {
|
|
2175
|
+
name: webApp.name,
|
|
2176
|
+
mountPath: webApp.config.mountPath || "/",
|
|
2177
|
+
metadata: webApp.config.metadata
|
|
2178
|
+
};
|
|
2179
|
+
});
|
|
2180
|
+
return {
|
|
2181
|
+
topics,
|
|
2182
|
+
tables,
|
|
2183
|
+
ingestApis,
|
|
2184
|
+
apis,
|
|
2185
|
+
sqlResources,
|
|
2186
|
+
workflows,
|
|
2187
|
+
webApps
|
|
2188
|
+
};
|
|
1521
2189
|
};
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
if (!metadata && api.config && api.pipelineParent) {
|
|
1526
|
-
metadata = api.pipelineParent.metadata;
|
|
2190
|
+
getMooseInternal = () => globalThis.moose_internal;
|
|
2191
|
+
if (getMooseInternal() === void 0) {
|
|
2192
|
+
globalThis.moose_internal = moose_internal;
|
|
1527
2193
|
}
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
name: api.config.destination.name
|
|
1536
|
-
},
|
|
1537
|
-
deadLetterQueue: api.config.deadLetterQueue?.name,
|
|
1538
|
-
metadata,
|
|
1539
|
-
schema: api.schema,
|
|
1540
|
-
allowExtraFields: api.allowExtraFields
|
|
1541
|
-
};
|
|
1542
|
-
});
|
|
1543
|
-
registry.apis.forEach((api, key) => {
|
|
1544
|
-
const rustKey = api.config.version ? `${api.name}:${api.config.version}` : api.name;
|
|
1545
|
-
apis[rustKey] = {
|
|
1546
|
-
name: api.name,
|
|
1547
|
-
queryParams: api.columnArray,
|
|
1548
|
-
responseSchema: api.responseSchema,
|
|
1549
|
-
version: api.config.version,
|
|
1550
|
-
path: api.config.path,
|
|
1551
|
-
metadata: api.metadata
|
|
2194
|
+
dumpMooseInternal = async () => {
|
|
2195
|
+
loadIndex();
|
|
2196
|
+
console.log(
|
|
2197
|
+
"___MOOSE_STUFF___start",
|
|
2198
|
+
JSON.stringify(toInfraMap(getMooseInternal())),
|
|
2199
|
+
"end___MOOSE_STUFF___"
|
|
2200
|
+
);
|
|
1552
2201
|
};
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
return {
|
|
1567
|
-
id,
|
|
1568
|
-
kind: "Table"
|
|
1569
|
-
};
|
|
1570
|
-
} else if (r.kind === "SqlResource") {
|
|
1571
|
-
const resource = r;
|
|
1572
|
-
return {
|
|
1573
|
-
id: resource.name,
|
|
1574
|
-
kind: "SqlResource"
|
|
1575
|
-
};
|
|
1576
|
-
} else {
|
|
1577
|
-
throw new Error(`Unknown sql resource dependency type: ${r}`);
|
|
2202
|
+
loadIndex = () => {
|
|
2203
|
+
const registry = getMooseInternal();
|
|
2204
|
+
registry.tables.clear();
|
|
2205
|
+
registry.streams.clear();
|
|
2206
|
+
registry.ingestApis.clear();
|
|
2207
|
+
registry.apis.clear();
|
|
2208
|
+
registry.sqlResources.clear();
|
|
2209
|
+
registry.workflows.clear();
|
|
2210
|
+
registry.webApps.clear();
|
|
2211
|
+
const appDir = `${import_process.default.cwd()}/${getSourceDir()}`;
|
|
2212
|
+
Object.keys(require.cache).forEach((key) => {
|
|
2213
|
+
if (key.startsWith(appDir)) {
|
|
2214
|
+
delete require.cache[key];
|
|
1578
2215
|
}
|
|
1579
|
-
})
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
};
|
|
1588
|
-
} else if (r.kind === "SqlResource") {
|
|
1589
|
-
const resource = r;
|
|
1590
|
-
return {
|
|
1591
|
-
id: resource.name,
|
|
1592
|
-
kind: "SqlResource"
|
|
1593
|
-
};
|
|
1594
|
-
} else {
|
|
1595
|
-
throw new Error(`Unknown sql resource dependency type: ${r}`);
|
|
2216
|
+
});
|
|
2217
|
+
try {
|
|
2218
|
+
require(`${import_process.default.cwd()}/${getSourceDir()}/index.ts`);
|
|
2219
|
+
} catch (error) {
|
|
2220
|
+
let hint;
|
|
2221
|
+
const details = error instanceof Error ? error.message : String(error);
|
|
2222
|
+
if (details.includes("ERR_REQUIRE_ESM") || details.includes("ES Module")) {
|
|
2223
|
+
hint = "The file or its dependencies are ESM-only. Switch to packages that dual-support CJS & ESM, or upgrade to Node 22.12+. If you must use Node 20, you may try Node 20.19\n\n";
|
|
1596
2224
|
}
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
workflows[workflow.name] = {
|
|
1602
|
-
name: workflow.name,
|
|
1603
|
-
retries: workflow.config.retries,
|
|
1604
|
-
timeout: workflow.config.timeout,
|
|
1605
|
-
schedule: workflow.config.schedule
|
|
2225
|
+
const errorMsg = `${hint ?? ""}${details}`;
|
|
2226
|
+
const cause = error instanceof Error ? error : void 0;
|
|
2227
|
+
throw new Error(errorMsg, { cause });
|
|
2228
|
+
}
|
|
1606
2229
|
};
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
2230
|
+
getStreamingFunctions = async () => {
|
|
2231
|
+
loadIndex();
|
|
2232
|
+
const registry = getMooseInternal();
|
|
2233
|
+
const transformFunctions = /* @__PURE__ */ new Map();
|
|
2234
|
+
registry.streams.forEach((stream) => {
|
|
2235
|
+
stream._transformations.forEach((transforms, destinationName) => {
|
|
2236
|
+
transforms.forEach(([_, transform, config]) => {
|
|
2237
|
+
const transformFunctionKey = `${stream.name}_${destinationName}${config.version ? `_${config.version}` : ""}`;
|
|
2238
|
+
compilerLog(`getStreamingFunctions: ${transformFunctionKey}`);
|
|
2239
|
+
transformFunctions.set(transformFunctionKey, [
|
|
2240
|
+
transform,
|
|
2241
|
+
config,
|
|
2242
|
+
stream.columnArray
|
|
2243
|
+
]);
|
|
2244
|
+
});
|
|
2245
|
+
});
|
|
2246
|
+
stream._consumers.forEach((consumer) => {
|
|
2247
|
+
const consumerFunctionKey = `${stream.name}_<no-target>${consumer.config.version ? `_${consumer.config.version}` : ""}`;
|
|
2248
|
+
transformFunctions.set(consumerFunctionKey, [
|
|
2249
|
+
consumer.consumer,
|
|
2250
|
+
consumer.config,
|
|
2251
|
+
stream.columnArray
|
|
2252
|
+
]);
|
|
2253
|
+
});
|
|
2254
|
+
});
|
|
2255
|
+
return transformFunctions;
|
|
1613
2256
|
};
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
}
|
|
1637
|
-
|
|
1638
|
-
const registry = getMooseInternal();
|
|
1639
|
-
registry.tables.clear();
|
|
1640
|
-
registry.streams.clear();
|
|
1641
|
-
registry.ingestApis.clear();
|
|
1642
|
-
registry.apis.clear();
|
|
1643
|
-
registry.sqlResources.clear();
|
|
1644
|
-
registry.workflows.clear();
|
|
1645
|
-
registry.webApps.clear();
|
|
1646
|
-
const appDir = `${import_process.default.cwd()}/${getSourceDir()}`;
|
|
1647
|
-
Object.keys(require.cache).forEach((key) => {
|
|
1648
|
-
if (key.startsWith(appDir)) {
|
|
1649
|
-
delete require.cache[key];
|
|
1650
|
-
}
|
|
1651
|
-
});
|
|
1652
|
-
try {
|
|
1653
|
-
require(`${import_process.default.cwd()}/${getSourceDir()}/index.ts`);
|
|
1654
|
-
} catch (error) {
|
|
1655
|
-
let hint;
|
|
1656
|
-
const details = error instanceof Error ? error.message : String(error);
|
|
1657
|
-
if (details.includes("ERR_REQUIRE_ESM") || details.includes("ES Module")) {
|
|
1658
|
-
hint = "The file or its dependencies are ESM-only. Switch to packages that dual-support CJS & ESM, or upgrade to Node 22.12+. If you must use Node 20, you may try Node 20.19\n\n";
|
|
1659
|
-
}
|
|
1660
|
-
const errorMsg = `${hint ?? ""}${details}`;
|
|
1661
|
-
const cause = error instanceof Error ? error : void 0;
|
|
1662
|
-
throw new Error(errorMsg, { cause });
|
|
1663
|
-
}
|
|
1664
|
-
};
|
|
1665
|
-
var getStreamingFunctions = async () => {
|
|
1666
|
-
loadIndex();
|
|
1667
|
-
const registry = getMooseInternal();
|
|
1668
|
-
const transformFunctions = /* @__PURE__ */ new Map();
|
|
1669
|
-
registry.streams.forEach((stream) => {
|
|
1670
|
-
stream._transformations.forEach((transforms, destinationName) => {
|
|
1671
|
-
transforms.forEach(([_, transform, config]) => {
|
|
1672
|
-
const transformFunctionKey = `${stream.name}_${destinationName}${config.version ? `_${config.version}` : ""}`;
|
|
1673
|
-
compilerLog(`getStreamingFunctions: ${transformFunctionKey}`);
|
|
1674
|
-
transformFunctions.set(transformFunctionKey, [
|
|
1675
|
-
transform,
|
|
1676
|
-
config,
|
|
1677
|
-
stream.columnArray
|
|
1678
|
-
]);
|
|
2257
|
+
getApis2 = async () => {
|
|
2258
|
+
loadIndex();
|
|
2259
|
+
const apiFunctions = /* @__PURE__ */ new Map();
|
|
2260
|
+
const registry = getMooseInternal();
|
|
2261
|
+
const versionCountByName = /* @__PURE__ */ new Map();
|
|
2262
|
+
const nameToSoleVersionHandler = /* @__PURE__ */ new Map();
|
|
2263
|
+
registry.apis.forEach((api, key) => {
|
|
2264
|
+
const handler = api.getHandler();
|
|
2265
|
+
apiFunctions.set(key, handler);
|
|
2266
|
+
if (!api.config.version) {
|
|
2267
|
+
if (!apiFunctions.has(api.name)) {
|
|
2268
|
+
apiFunctions.set(api.name, handler);
|
|
2269
|
+
}
|
|
2270
|
+
nameToSoleVersionHandler.delete(api.name);
|
|
2271
|
+
versionCountByName.delete(api.name);
|
|
2272
|
+
} else if (!apiFunctions.has(api.name)) {
|
|
2273
|
+
const count = (versionCountByName.get(api.name) ?? 0) + 1;
|
|
2274
|
+
versionCountByName.set(api.name, count);
|
|
2275
|
+
if (count === 1) {
|
|
2276
|
+
nameToSoleVersionHandler.set(api.name, handler);
|
|
2277
|
+
} else {
|
|
2278
|
+
nameToSoleVersionHandler.delete(api.name);
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
1679
2281
|
});
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
};
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
const nameToSoleVersionHandler = /* @__PURE__ */ new Map();
|
|
1698
|
-
registry.apis.forEach((api, key) => {
|
|
1699
|
-
const handler = api.getHandler();
|
|
1700
|
-
apiFunctions.set(key, handler);
|
|
1701
|
-
if (!api.config.version) {
|
|
1702
|
-
if (!apiFunctions.has(api.name)) {
|
|
1703
|
-
apiFunctions.set(api.name, handler);
|
|
1704
|
-
}
|
|
1705
|
-
nameToSoleVersionHandler.delete(api.name);
|
|
1706
|
-
versionCountByName.delete(api.name);
|
|
1707
|
-
} else if (!apiFunctions.has(api.name)) {
|
|
1708
|
-
const count = (versionCountByName.get(api.name) ?? 0) + 1;
|
|
1709
|
-
versionCountByName.set(api.name, count);
|
|
1710
|
-
if (count === 1) {
|
|
1711
|
-
nameToSoleVersionHandler.set(api.name, handler);
|
|
1712
|
-
} else {
|
|
1713
|
-
nameToSoleVersionHandler.delete(api.name);
|
|
2282
|
+
nameToSoleVersionHandler.forEach((handler, name) => {
|
|
2283
|
+
if (!apiFunctions.has(name)) {
|
|
2284
|
+
apiFunctions.set(name, handler);
|
|
2285
|
+
}
|
|
2286
|
+
});
|
|
2287
|
+
return apiFunctions;
|
|
2288
|
+
};
|
|
2289
|
+
getWorkflows2 = async () => {
|
|
2290
|
+
loadIndex();
|
|
2291
|
+
const registry = getMooseInternal();
|
|
2292
|
+
return registry.workflows;
|
|
2293
|
+
};
|
|
2294
|
+
getTaskForWorkflow = async (workflowName, taskName) => {
|
|
2295
|
+
const workflows = await getWorkflows2();
|
|
2296
|
+
const workflow = workflows.get(workflowName);
|
|
2297
|
+
if (!workflow) {
|
|
2298
|
+
throw new Error(`Workflow ${workflowName} not found`);
|
|
1714
2299
|
}
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
});
|
|
1722
|
-
return apiFunctions;
|
|
1723
|
-
};
|
|
1724
|
-
var getWorkflows2 = async () => {
|
|
1725
|
-
loadIndex();
|
|
1726
|
-
const registry = getMooseInternal();
|
|
1727
|
-
return registry.workflows;
|
|
1728
|
-
};
|
|
1729
|
-
function findTaskInTree(task, targetName) {
|
|
1730
|
-
if (task.name === targetName) {
|
|
1731
|
-
return task;
|
|
1732
|
-
}
|
|
1733
|
-
if (task.config.onComplete?.length) {
|
|
1734
|
-
for (const childTask of task.config.onComplete) {
|
|
1735
|
-
const found = findTaskInTree(childTask, targetName);
|
|
1736
|
-
if (found) {
|
|
1737
|
-
return found;
|
|
2300
|
+
const task = findTaskInTree(
|
|
2301
|
+
workflow.config.startingTask,
|
|
2302
|
+
taskName
|
|
2303
|
+
);
|
|
2304
|
+
if (!task) {
|
|
2305
|
+
throw new Error(`Task ${taskName} not found in workflow ${workflowName}`);
|
|
1738
2306
|
}
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
const workflow = workflows.get(workflowName);
|
|
1746
|
-
if (!workflow) {
|
|
1747
|
-
throw new Error(`Workflow ${workflowName} not found`);
|
|
1748
|
-
}
|
|
1749
|
-
const task = findTaskInTree(
|
|
1750
|
-
workflow.config.startingTask,
|
|
1751
|
-
taskName
|
|
1752
|
-
);
|
|
1753
|
-
if (!task) {
|
|
1754
|
-
throw new Error(`Task ${taskName} not found in workflow ${workflowName}`);
|
|
2307
|
+
return task;
|
|
2308
|
+
};
|
|
2309
|
+
getWebApps2 = async () => {
|
|
2310
|
+
loadIndex();
|
|
2311
|
+
return getMooseInternal().webApps;
|
|
2312
|
+
};
|
|
1755
2313
|
}
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
};
|
|
2314
|
+
});
|
|
2315
|
+
|
|
2316
|
+
// src/moose-runner.ts
|
|
2317
|
+
var import_ts_node = require("ts-node");
|
|
2318
|
+
init_internal();
|
|
1762
2319
|
|
|
1763
2320
|
// src/blocks/runner.ts
|
|
1764
2321
|
var import_fastq = __toESM(require("fastq"));
|
|
1765
2322
|
init_commons();
|
|
1766
2323
|
var import_node_fs = __toESM(require("fs"));
|
|
1767
|
-
var
|
|
2324
|
+
var import_node_path2 = __toESM(require("path"));
|
|
1768
2325
|
var walkDir = (dir, fileExtension, fileList) => {
|
|
1769
2326
|
const files = import_node_fs.default.readdirSync(dir);
|
|
1770
2327
|
files.forEach((file) => {
|
|
1771
|
-
if (import_node_fs.default.statSync(
|
|
1772
|
-
fileList = walkDir(
|
|
2328
|
+
if (import_node_fs.default.statSync(import_node_path2.default.join(dir, file)).isDirectory()) {
|
|
2329
|
+
fileList = walkDir(import_node_path2.default.join(dir, file), fileExtension, fileList);
|
|
1773
2330
|
} else if (file.endsWith(fileExtension)) {
|
|
1774
|
-
fileList.push(
|
|
2331
|
+
fileList.push(import_node_path2.default.join(dir, file));
|
|
1775
2332
|
}
|
|
1776
2333
|
});
|
|
1777
2334
|
return fileList;
|
|
@@ -1782,7 +2339,7 @@ var DependencyError = class extends Error {
|
|
|
1782
2339
|
this.name = "DependencyError";
|
|
1783
2340
|
}
|
|
1784
2341
|
};
|
|
1785
|
-
var
|
|
2342
|
+
var toClientConfig3 = (config) => ({
|
|
1786
2343
|
...config,
|
|
1787
2344
|
useSSL: config.useSSL ? "true" : "false"
|
|
1788
2345
|
});
|
|
@@ -1834,7 +2391,7 @@ var asyncWorker = async (task) => {
|
|
|
1834
2391
|
await createBlocks(task.chClient, task.blocks);
|
|
1835
2392
|
};
|
|
1836
2393
|
var runBlocks = async (config) => {
|
|
1837
|
-
const chClient = getClickhouseClient(
|
|
2394
|
+
const chClient = getClickhouseClient(toClientConfig3(config.clickhouseConfig));
|
|
1838
2395
|
console.log(`Connected`);
|
|
1839
2396
|
const blocksFiles = walkDir(config.blocksDir, ".ts", []);
|
|
1840
2397
|
const numOfBlockFiles = blocksFiles.length;
|
|
@@ -1847,10 +2404,10 @@ var runBlocks = async (config) => {
|
|
|
1847
2404
|
}
|
|
1848
2405
|
}
|
|
1849
2406
|
});
|
|
1850
|
-
for (const
|
|
1851
|
-
console.log(`Adding to queue: ${
|
|
2407
|
+
for (const path4 of blocksFiles) {
|
|
2408
|
+
console.log(`Adding to queue: ${path4}`);
|
|
1852
2409
|
try {
|
|
1853
|
-
const blocks = require(
|
|
2410
|
+
const blocks = require(path4).default;
|
|
1854
2411
|
queue.push({
|
|
1855
2412
|
chClient,
|
|
1856
2413
|
blocks,
|
|
@@ -1859,7 +2416,7 @@ var runBlocks = async (config) => {
|
|
|
1859
2416
|
} catch (err) {
|
|
1860
2417
|
cliLog({
|
|
1861
2418
|
action: "Blocks",
|
|
1862
|
-
message: `Failed to import blocks from ${
|
|
2419
|
+
message: `Failed to import blocks from ${path4}: ${err}`,
|
|
1863
2420
|
message_type: "Error"
|
|
1864
2421
|
});
|
|
1865
2422
|
}
|
|
@@ -1869,6 +2426,9 @@ var runBlocks = async (config) => {
|
|
|
1869
2426
|
}
|
|
1870
2427
|
};
|
|
1871
2428
|
|
|
2429
|
+
// src/moose-runner.ts
|
|
2430
|
+
init_runner();
|
|
2431
|
+
|
|
1872
2432
|
// src/streaming-functions/runner.ts
|
|
1873
2433
|
var import_node_stream2 = require("stream");
|
|
1874
2434
|
var import_kafka_javascript2 = require("@514labs/kafka-javascript");
|
|
@@ -1876,6 +2436,9 @@ var import_node_buffer = require("buffer");
|
|
|
1876
2436
|
var process3 = __toESM(require("process"));
|
|
1877
2437
|
var http3 = __toESM(require("http"));
|
|
1878
2438
|
init_commons();
|
|
2439
|
+
init_cluster_utils();
|
|
2440
|
+
init_internal();
|
|
2441
|
+
init_json();
|
|
1879
2442
|
var { Kafka: Kafka2 } = import_kafka_javascript2.KafkaJS;
|
|
1880
2443
|
var HOSTNAME = process3.env.HOSTNAME;
|
|
1881
2444
|
var AUTO_COMMIT_INTERVAL_MS = 5e3;
|
|
@@ -2434,12 +2997,15 @@ async function runApiTypeSerializer(targetModel) {
|
|
|
2434
2997
|
|
|
2435
2998
|
// src/scripts/runner.ts
|
|
2436
2999
|
var import_worker2 = require("@temporalio/worker");
|
|
2437
|
-
var
|
|
3000
|
+
var path3 = __toESM(require("path"));
|
|
2438
3001
|
var fs3 = __toESM(require("fs"));
|
|
3002
|
+
init_internal();
|
|
2439
3003
|
|
|
2440
3004
|
// src/scripts/activity.ts
|
|
2441
3005
|
var import_activity = require("@temporalio/activity");
|
|
2442
3006
|
var import_workflow3 = require("@temporalio/workflow");
|
|
3007
|
+
init_internal();
|
|
3008
|
+
init_json();
|
|
2443
3009
|
var activities = {
|
|
2444
3010
|
async hasDmv2Workflow(name) {
|
|
2445
3011
|
try {
|
|
@@ -2724,7 +3290,7 @@ async function registerWorkflows(logger2, config) {
|
|
|
2724
3290
|
}
|
|
2725
3291
|
};
|
|
2726
3292
|
const workflowBundle = await (0, import_worker2.bundleWorkflowCode)({
|
|
2727
|
-
workflowsPath:
|
|
3293
|
+
workflowsPath: path3.resolve(__dirname, "scripts/workflow.js"),
|
|
2728
3294
|
logger: silentLogger
|
|
2729
3295
|
});
|
|
2730
3296
|
const worker = await import_worker2.Worker.create({
|