@bayoudhi/moose-lib-serverless 0.2.0 → 0.2.1
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/index.d.mts +128 -141
- package/dist/index.d.ts +128 -141
- package/dist/index.js +673 -536
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +673 -536
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -34,7 +34,116 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
34
34
|
var require_kafka_javascript = __commonJS({
|
|
35
35
|
"stub-native:@514labs/kafka-javascript"(exports2, module2) {
|
|
36
36
|
"use strict";
|
|
37
|
-
|
|
37
|
+
function createDeepProxy() {
|
|
38
|
+
var handler = {
|
|
39
|
+
get: function(_, prop) {
|
|
40
|
+
if (prop === "__esModule") return true;
|
|
41
|
+
if (prop === "default") return proxy;
|
|
42
|
+
if (typeof prop === "symbol") return void 0;
|
|
43
|
+
return proxy;
|
|
44
|
+
},
|
|
45
|
+
apply: function() {
|
|
46
|
+
return proxy;
|
|
47
|
+
},
|
|
48
|
+
construct: function() {
|
|
49
|
+
return proxy;
|
|
50
|
+
},
|
|
51
|
+
ownKeys: function() {
|
|
52
|
+
return ["length", "name", "prototype"];
|
|
53
|
+
},
|
|
54
|
+
getOwnPropertyDescriptor: function(target, prop) {
|
|
55
|
+
if (prop === "length" || prop === "name" || prop === "prototype") {
|
|
56
|
+
return Object.getOwnPropertyDescriptor(target, prop);
|
|
57
|
+
}
|
|
58
|
+
return void 0;
|
|
59
|
+
},
|
|
60
|
+
getPrototypeOf: function() {
|
|
61
|
+
return proxy;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var proxy = new Proxy(function() {
|
|
65
|
+
}, handler);
|
|
66
|
+
return proxy;
|
|
67
|
+
}
|
|
68
|
+
module2.exports = createDeepProxy();
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// stub-native:@temporalio/client
|
|
73
|
+
var require_client = __commonJS({
|
|
74
|
+
"stub-native:@temporalio/client"(exports2, module2) {
|
|
75
|
+
"use strict";
|
|
76
|
+
function createDeepProxy() {
|
|
77
|
+
var handler = {
|
|
78
|
+
get: function(_, prop) {
|
|
79
|
+
if (prop === "__esModule") return true;
|
|
80
|
+
if (prop === "default") return proxy;
|
|
81
|
+
if (typeof prop === "symbol") return void 0;
|
|
82
|
+
return proxy;
|
|
83
|
+
},
|
|
84
|
+
apply: function() {
|
|
85
|
+
return proxy;
|
|
86
|
+
},
|
|
87
|
+
construct: function() {
|
|
88
|
+
return proxy;
|
|
89
|
+
},
|
|
90
|
+
ownKeys: function() {
|
|
91
|
+
return ["length", "name", "prototype"];
|
|
92
|
+
},
|
|
93
|
+
getOwnPropertyDescriptor: function(target, prop) {
|
|
94
|
+
if (prop === "length" || prop === "name" || prop === "prototype") {
|
|
95
|
+
return Object.getOwnPropertyDescriptor(target, prop);
|
|
96
|
+
}
|
|
97
|
+
return void 0;
|
|
98
|
+
},
|
|
99
|
+
getPrototypeOf: function() {
|
|
100
|
+
return proxy;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
var proxy = new Proxy(function() {
|
|
104
|
+
}, handler);
|
|
105
|
+
return proxy;
|
|
106
|
+
}
|
|
107
|
+
module2.exports = createDeepProxy();
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// stub-native:redis
|
|
112
|
+
var require_redis = __commonJS({
|
|
113
|
+
"stub-native:redis"(exports2, module2) {
|
|
114
|
+
"use strict";
|
|
115
|
+
function createDeepProxy() {
|
|
116
|
+
var handler = {
|
|
117
|
+
get: function(_, prop) {
|
|
118
|
+
if (prop === "__esModule") return true;
|
|
119
|
+
if (prop === "default") return proxy;
|
|
120
|
+
if (typeof prop === "symbol") return void 0;
|
|
121
|
+
return proxy;
|
|
122
|
+
},
|
|
123
|
+
apply: function() {
|
|
124
|
+
return proxy;
|
|
125
|
+
},
|
|
126
|
+
construct: function() {
|
|
127
|
+
return proxy;
|
|
128
|
+
},
|
|
129
|
+
ownKeys: function() {
|
|
130
|
+
return ["length", "name", "prototype"];
|
|
131
|
+
},
|
|
132
|
+
getOwnPropertyDescriptor: function(target, prop) {
|
|
133
|
+
if (prop === "length" || prop === "name" || prop === "prototype") {
|
|
134
|
+
return Object.getOwnPropertyDescriptor(target, prop);
|
|
135
|
+
}
|
|
136
|
+
return void 0;
|
|
137
|
+
},
|
|
138
|
+
getPrototypeOf: function() {
|
|
139
|
+
return proxy;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
var proxy = new Proxy(function() {
|
|
143
|
+
}, handler);
|
|
144
|
+
return proxy;
|
|
145
|
+
}
|
|
146
|
+
module2.exports = createDeepProxy();
|
|
38
147
|
}
|
|
39
148
|
});
|
|
40
149
|
|
|
@@ -42,7 +151,38 @@ var require_kafka_javascript = __commonJS({
|
|
|
42
151
|
var require_confluent_schema_registry = __commonJS({
|
|
43
152
|
"stub-native:@kafkajs/confluent-schema-registry"(exports2, module2) {
|
|
44
153
|
"use strict";
|
|
45
|
-
|
|
154
|
+
function createDeepProxy() {
|
|
155
|
+
var handler = {
|
|
156
|
+
get: function(_, prop) {
|
|
157
|
+
if (prop === "__esModule") return true;
|
|
158
|
+
if (prop === "default") return proxy;
|
|
159
|
+
if (typeof prop === "symbol") return void 0;
|
|
160
|
+
return proxy;
|
|
161
|
+
},
|
|
162
|
+
apply: function() {
|
|
163
|
+
return proxy;
|
|
164
|
+
},
|
|
165
|
+
construct: function() {
|
|
166
|
+
return proxy;
|
|
167
|
+
},
|
|
168
|
+
ownKeys: function() {
|
|
169
|
+
return ["length", "name", "prototype"];
|
|
170
|
+
},
|
|
171
|
+
getOwnPropertyDescriptor: function(target, prop) {
|
|
172
|
+
if (prop === "length" || prop === "name" || prop === "prototype") {
|
|
173
|
+
return Object.getOwnPropertyDescriptor(target, prop);
|
|
174
|
+
}
|
|
175
|
+
return void 0;
|
|
176
|
+
},
|
|
177
|
+
getPrototypeOf: function() {
|
|
178
|
+
return proxy;
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
var proxy = new Proxy(function() {
|
|
182
|
+
}, handler);
|
|
183
|
+
return proxy;
|
|
184
|
+
}
|
|
185
|
+
module2.exports = createDeepProxy();
|
|
46
186
|
}
|
|
47
187
|
});
|
|
48
188
|
|
|
@@ -100,7 +240,7 @@ __export(index_exports, {
|
|
|
100
240
|
getWebApp: () => getWebApp,
|
|
101
241
|
getWebApps: () => getWebApps,
|
|
102
242
|
getWorkflow: () => getWorkflow,
|
|
103
|
-
getWorkflows: () =>
|
|
243
|
+
getWorkflows: () => getWorkflows2,
|
|
104
244
|
isValidCSVDelimiter: () => isValidCSVDelimiter,
|
|
105
245
|
logError: () => logError,
|
|
106
246
|
mapToClickHouseType: () => mapToClickHouseType,
|
|
@@ -119,17 +259,19 @@ __export(index_exports, {
|
|
|
119
259
|
module.exports = __toCommonJS(index_exports);
|
|
120
260
|
|
|
121
261
|
// ../ts-moose-lib/dist/serverless.mjs
|
|
262
|
+
var import_fs = require("fs");
|
|
122
263
|
var import_path = __toESM(require("path"), 1);
|
|
123
|
-
var toml = __toESM(require("toml"), 1);
|
|
124
|
-
var import_kafka_javascript = __toESM(require_kafka_javascript(), 1);
|
|
125
264
|
var import_client = require("@clickhouse/client");
|
|
126
|
-
var
|
|
265
|
+
var import_kafka_javascript = __toESM(require_kafka_javascript(), 1);
|
|
127
266
|
var import_path2 = __toESM(require("path"), 1);
|
|
267
|
+
var toml = __toESM(require("toml"), 1);
|
|
128
268
|
var import_process = __toESM(require("process"), 1);
|
|
269
|
+
var import_client2 = __toESM(require_client(), 1);
|
|
270
|
+
var import_redis = __toESM(require_redis(), 1);
|
|
271
|
+
var import_csv_parse = require("csv-parse");
|
|
129
272
|
var import_stream = require("stream");
|
|
130
273
|
var import_crypto = require("crypto");
|
|
131
274
|
var import_crypto2 = require("crypto");
|
|
132
|
-
var import_csv_parse = require("csv-parse");
|
|
133
275
|
var __defProp2 = Object.defineProperty;
|
|
134
276
|
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
135
277
|
var __esm = (fn, res) => function __init() {
|
|
@@ -139,6 +281,26 @@ var __export2 = (target, all) => {
|
|
|
139
281
|
for (var name in all)
|
|
140
282
|
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
141
283
|
};
|
|
284
|
+
var commons_exports = {};
|
|
285
|
+
__export2(commons_exports, {
|
|
286
|
+
ACKs: () => ACKs,
|
|
287
|
+
MAX_RETRIES: () => MAX_RETRIES,
|
|
288
|
+
MAX_RETRIES_PRODUCER: () => MAX_RETRIES_PRODUCER,
|
|
289
|
+
MAX_RETRY_TIME_MS: () => MAX_RETRY_TIME_MS,
|
|
290
|
+
RETRY_FACTOR_PRODUCER: () => RETRY_FACTOR_PRODUCER,
|
|
291
|
+
RETRY_INITIAL_TIME_MS: () => RETRY_INITIAL_TIME_MS,
|
|
292
|
+
antiCachePath: () => antiCachePath,
|
|
293
|
+
cliLog: () => cliLog,
|
|
294
|
+
compilerLog: () => compilerLog,
|
|
295
|
+
createProducerConfig: () => createProducerConfig,
|
|
296
|
+
getClickhouseClient: () => getClickhouseClient,
|
|
297
|
+
getFileName: () => getFileName,
|
|
298
|
+
getKafkaClient: () => getKafkaClient,
|
|
299
|
+
getKafkaProducer: () => getKafkaProducer,
|
|
300
|
+
logError: () => logError,
|
|
301
|
+
mapTstoJs: () => mapTstoJs,
|
|
302
|
+
rewriteImportExtensions: () => rewriteImportExtensions
|
|
303
|
+
});
|
|
142
304
|
function isTruthy(value) {
|
|
143
305
|
if (!value) return false;
|
|
144
306
|
switch (value.trim().toLowerCase()) {
|
|
@@ -154,9 +316,121 @@ function isTruthy(value) {
|
|
|
154
316
|
function mapTstoJs(filePath) {
|
|
155
317
|
return filePath.replace(/\.ts$/, ".js").replace(/\.cts$/, ".cjs").replace(/\.mts$/, ".mjs");
|
|
156
318
|
}
|
|
319
|
+
function walkDirectory(dir, extensions) {
|
|
320
|
+
const results = [];
|
|
321
|
+
if (!(0, import_fs.existsSync)(dir)) {
|
|
322
|
+
return results;
|
|
323
|
+
}
|
|
324
|
+
try {
|
|
325
|
+
const entries = (0, import_fs.readdirSync)(dir, { withFileTypes: true });
|
|
326
|
+
for (const entry of entries) {
|
|
327
|
+
const fullPath = import_path.default.join(dir, entry.name);
|
|
328
|
+
if (entry.isDirectory()) {
|
|
329
|
+
if (entry.name !== "node_modules") {
|
|
330
|
+
results.push(...walkDirectory(fullPath, extensions));
|
|
331
|
+
}
|
|
332
|
+
} else if (entry.isFile()) {
|
|
333
|
+
const ext = import_path.default.extname(entry.name);
|
|
334
|
+
if (extensions.includes(ext)) {
|
|
335
|
+
results.push(fullPath);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
} catch (e) {
|
|
340
|
+
console.debug(`[moose] Failed to read directory ${dir}:`, e);
|
|
341
|
+
}
|
|
342
|
+
return results;
|
|
343
|
+
}
|
|
344
|
+
function addJsExtensionToImports(content, fileDir) {
|
|
345
|
+
const fromPattern = /(from\s+['"])(\.\.?\/[^'"]*?)(['"])/g;
|
|
346
|
+
const bareImportPattern = /(import\s+['"])(\.\.?\/[^'"]*?)(['"])/g;
|
|
347
|
+
const dynamicPattern = /(import\s*\(\s*['"])(\.\.?\/[^'"]*?)(['"])/g;
|
|
348
|
+
let result = content;
|
|
349
|
+
result = result.replace(fromPattern, (match, prefix, importPath, quote) => {
|
|
350
|
+
return rewriteImportPath(match, prefix, importPath, quote, fileDir);
|
|
351
|
+
});
|
|
352
|
+
result = result.replace(
|
|
353
|
+
bareImportPattern,
|
|
354
|
+
(match, prefix, importPath, quote) => {
|
|
355
|
+
return rewriteImportPath(match, prefix, importPath, quote, fileDir);
|
|
356
|
+
}
|
|
357
|
+
);
|
|
358
|
+
result = result.replace(
|
|
359
|
+
dynamicPattern,
|
|
360
|
+
(match, prefix, importPath, quote) => {
|
|
361
|
+
return rewriteImportPath(match, prefix, importPath, quote, fileDir);
|
|
362
|
+
}
|
|
363
|
+
);
|
|
364
|
+
return result;
|
|
365
|
+
}
|
|
366
|
+
function rewriteImportPath(match, prefix, importPath, quote, fileDir) {
|
|
367
|
+
if (/\.[cm]?js$/.test(importPath)) {
|
|
368
|
+
return match;
|
|
369
|
+
}
|
|
370
|
+
if (/\.json$/.test(importPath)) {
|
|
371
|
+
return match;
|
|
372
|
+
}
|
|
373
|
+
if (fileDir) {
|
|
374
|
+
const resolvedPath = import_path.default.resolve(fileDir, importPath);
|
|
375
|
+
if ((0, import_fs.existsSync)(`${resolvedPath}.js`)) {
|
|
376
|
+
return `${prefix}${importPath}.js${quote}`;
|
|
377
|
+
}
|
|
378
|
+
if ((0, import_fs.existsSync)(import_path.default.join(resolvedPath, "index.js"))) {
|
|
379
|
+
return `${prefix}${importPath}/index.js${quote}`;
|
|
380
|
+
}
|
|
381
|
+
if ((0, import_fs.existsSync)(`${resolvedPath}.mjs`)) {
|
|
382
|
+
return `${prefix}${importPath}.mjs${quote}`;
|
|
383
|
+
}
|
|
384
|
+
if ((0, import_fs.existsSync)(import_path.default.join(resolvedPath, "index.mjs"))) {
|
|
385
|
+
return `${prefix}${importPath}/index.mjs${quote}`;
|
|
386
|
+
}
|
|
387
|
+
if ((0, import_fs.existsSync)(`${resolvedPath}.cjs`)) {
|
|
388
|
+
return `${prefix}${importPath}.cjs${quote}`;
|
|
389
|
+
}
|
|
390
|
+
if ((0, import_fs.existsSync)(import_path.default.join(resolvedPath, "index.cjs"))) {
|
|
391
|
+
return `${prefix}${importPath}/index.cjs${quote}`;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
return `${prefix}${importPath}.js${quote}`;
|
|
395
|
+
}
|
|
396
|
+
function rewriteImportExtensions(outDir) {
|
|
397
|
+
const files = walkDirectory(outDir, [".js", ".mjs"]);
|
|
398
|
+
for (const filePath of files) {
|
|
399
|
+
const content = (0, import_fs.readFileSync)(filePath, "utf-8");
|
|
400
|
+
const fileDir = import_path.default.dirname(filePath);
|
|
401
|
+
const rewritten = addJsExtensionToImports(content, fileDir);
|
|
402
|
+
if (content !== rewritten) {
|
|
403
|
+
(0, import_fs.writeFileSync)(filePath, rewritten, "utf-8");
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
function createProducerConfig(maxMessageBytes) {
|
|
408
|
+
return {
|
|
409
|
+
kafkaJS: {
|
|
410
|
+
idempotent: false,
|
|
411
|
+
// Not needed for at-least-once delivery
|
|
412
|
+
acks: ACKs,
|
|
413
|
+
retry: {
|
|
414
|
+
retries: MAX_RETRIES_PRODUCER,
|
|
415
|
+
maxRetryTime: MAX_RETRY_TIME_MS
|
|
416
|
+
}
|
|
417
|
+
},
|
|
418
|
+
"linger.ms": 0,
|
|
419
|
+
// This is to make sure at least once delivery with immediate feedback on the send
|
|
420
|
+
...maxMessageBytes && { "message.max.bytes": maxMessageBytes }
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
async function getKafkaProducer(cfg, logger, maxMessageBytes) {
|
|
424
|
+
const kafka = await getKafkaClient(cfg, logger);
|
|
425
|
+
const producer = kafka.producer(createProducerConfig(maxMessageBytes));
|
|
426
|
+
await producer.connect();
|
|
427
|
+
return producer;
|
|
428
|
+
}
|
|
429
|
+
var Kafka;
|
|
157
430
|
var compilerLog;
|
|
158
431
|
var antiCachePath;
|
|
159
432
|
var getFileName;
|
|
433
|
+
var getClickhouseClient;
|
|
160
434
|
var cliLog;
|
|
161
435
|
var MAX_RETRIES;
|
|
162
436
|
var MAX_RETRY_TIME_MS;
|
|
@@ -164,10 +438,14 @@ var RETRY_INITIAL_TIME_MS;
|
|
|
164
438
|
var MAX_RETRIES_PRODUCER;
|
|
165
439
|
var RETRY_FACTOR_PRODUCER;
|
|
166
440
|
var ACKs;
|
|
441
|
+
var parseBrokerString;
|
|
167
442
|
var logError;
|
|
168
|
-
var
|
|
169
|
-
|
|
443
|
+
var buildSaslConfig;
|
|
444
|
+
var getKafkaClient;
|
|
445
|
+
var init_commons = __esm({
|
|
446
|
+
"src/commons.ts"() {
|
|
170
447
|
"use strict";
|
|
448
|
+
({ Kafka } = import_kafka_javascript.KafkaJS);
|
|
171
449
|
compilerLog = (message) => {
|
|
172
450
|
if (!isTruthy(process.env.MOOSE_DISABLE_COMPILER_LOGS)) {
|
|
173
451
|
console.log(message);
|
|
@@ -175,13 +453,33 @@ var init_commons_types = __esm({
|
|
|
175
453
|
};
|
|
176
454
|
antiCachePath = (path2) => `${path2}?num=${Math.random().toString()}&time=${Date.now()}`;
|
|
177
455
|
getFileName = (filePath) => {
|
|
178
|
-
const regex = /\/([
|
|
456
|
+
const regex = /\/([^\/]+)\.ts/;
|
|
179
457
|
const matches = filePath.match(regex);
|
|
180
458
|
if (matches && matches.length > 1) {
|
|
181
459
|
return matches[1];
|
|
182
460
|
}
|
|
183
461
|
return "";
|
|
184
462
|
};
|
|
463
|
+
getClickhouseClient = ({
|
|
464
|
+
username,
|
|
465
|
+
password,
|
|
466
|
+
database,
|
|
467
|
+
useSSL,
|
|
468
|
+
host,
|
|
469
|
+
port
|
|
470
|
+
}) => {
|
|
471
|
+
const protocol = useSSL === "1" || useSSL.toLowerCase() === "true" ? "https" : "http";
|
|
472
|
+
console.log(`Connecting to Clickhouse at ${protocol}://${host}:${port}`);
|
|
473
|
+
return (0, import_client.createClient)({
|
|
474
|
+
url: `${protocol}://${host}:${port}`,
|
|
475
|
+
username,
|
|
476
|
+
password,
|
|
477
|
+
database,
|
|
478
|
+
application: "moose"
|
|
479
|
+
// Note: wait_end_of_query is configured per operation type, not globally
|
|
480
|
+
// to preserve SELECT query performance while ensuring INSERT/DDL reliability
|
|
481
|
+
});
|
|
482
|
+
};
|
|
185
483
|
cliLog = (log) => {
|
|
186
484
|
const level = log.message_type === "Error" ? "error" : log.message_type === "Warning" ? "warn" : "info";
|
|
187
485
|
const structuredLog = {
|
|
@@ -201,6 +499,7 @@ var init_commons_types = __esm({
|
|
|
201
499
|
MAX_RETRIES_PRODUCER = 150;
|
|
202
500
|
RETRY_FACTOR_PRODUCER = 0.2;
|
|
203
501
|
ACKs = -1;
|
|
502
|
+
parseBrokerString = (brokerString) => brokerString.split(",").map((b) => b.trim()).filter((b) => b.length > 0);
|
|
204
503
|
logError = (logger, e) => {
|
|
205
504
|
logger.error(e.message);
|
|
206
505
|
const stack = e.stack;
|
|
@@ -208,17 +507,56 @@ var init_commons_types = __esm({
|
|
|
208
507
|
logger.error(stack);
|
|
209
508
|
}
|
|
210
509
|
};
|
|
510
|
+
buildSaslConfig = (logger, args) => {
|
|
511
|
+
const mechanism = args.saslMechanism ? args.saslMechanism.toLowerCase() : "";
|
|
512
|
+
switch (mechanism) {
|
|
513
|
+
case "plain":
|
|
514
|
+
case "scram-sha-256":
|
|
515
|
+
case "scram-sha-512":
|
|
516
|
+
return {
|
|
517
|
+
mechanism,
|
|
518
|
+
username: args.saslUsername || "",
|
|
519
|
+
password: args.saslPassword || ""
|
|
520
|
+
};
|
|
521
|
+
default:
|
|
522
|
+
logger.warn(`Unsupported SASL mechanism: ${args.saslMechanism}`);
|
|
523
|
+
return void 0;
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
getKafkaClient = async (cfg, logger) => {
|
|
527
|
+
const brokers = parseBrokerString(cfg.broker || "");
|
|
528
|
+
if (brokers.length === 0) {
|
|
529
|
+
throw new Error(`No valid broker addresses found in: "${cfg.broker}"`);
|
|
530
|
+
}
|
|
531
|
+
logger.log(`Creating Kafka client with brokers: ${brokers.join(", ")}`);
|
|
532
|
+
logger.log(`Security protocol: ${cfg.securityProtocol || "plaintext"}`);
|
|
533
|
+
logger.log(`Client ID: ${cfg.clientId}`);
|
|
534
|
+
const saslConfig = buildSaslConfig(logger, cfg);
|
|
535
|
+
return new Kafka({
|
|
536
|
+
kafkaJS: {
|
|
537
|
+
clientId: cfg.clientId,
|
|
538
|
+
brokers,
|
|
539
|
+
ssl: cfg.securityProtocol === "SASL_SSL",
|
|
540
|
+
...saslConfig && { sasl: saslConfig },
|
|
541
|
+
retry: {
|
|
542
|
+
initialRetryTime: RETRY_INITIAL_TIME_MS,
|
|
543
|
+
maxRetryTime: MAX_RETRY_TIME_MS,
|
|
544
|
+
retries: MAX_RETRIES
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
});
|
|
548
|
+
};
|
|
211
549
|
}
|
|
212
550
|
});
|
|
213
551
|
async function findConfigFile(startDir = process.cwd()) {
|
|
214
552
|
const fs = await import("fs");
|
|
215
|
-
let currentDir =
|
|
553
|
+
let currentDir = import_path2.default.resolve(startDir);
|
|
216
554
|
while (true) {
|
|
217
|
-
const configPath =
|
|
555
|
+
const configPath = import_path2.default.join(currentDir, "moose.config.toml");
|
|
218
556
|
if (fs.existsSync(configPath)) {
|
|
219
557
|
return configPath;
|
|
220
558
|
}
|
|
221
|
-
const parentDir =
|
|
559
|
+
const parentDir = import_path2.default.dirname(currentDir);
|
|
222
560
|
if (parentDir === currentDir) {
|
|
223
561
|
break;
|
|
224
562
|
}
|
|
@@ -388,231 +726,6 @@ var init_runtime = __esm({
|
|
|
388
726
|
globalThis._mooseConfigRegistry = ConfigurationRegistry.getInstance();
|
|
389
727
|
}
|
|
390
728
|
});
|
|
391
|
-
var commons_exports = {};
|
|
392
|
-
__export2(commons_exports, {
|
|
393
|
-
ACKs: () => ACKs,
|
|
394
|
-
MAX_RETRIES: () => MAX_RETRIES,
|
|
395
|
-
MAX_RETRIES_PRODUCER: () => MAX_RETRIES_PRODUCER,
|
|
396
|
-
MAX_RETRY_TIME_MS: () => MAX_RETRY_TIME_MS,
|
|
397
|
-
RETRY_FACTOR_PRODUCER: () => RETRY_FACTOR_PRODUCER,
|
|
398
|
-
RETRY_INITIAL_TIME_MS: () => RETRY_INITIAL_TIME_MS,
|
|
399
|
-
antiCachePath: () => antiCachePath,
|
|
400
|
-
cliLog: () => cliLog,
|
|
401
|
-
compilerLog: () => compilerLog,
|
|
402
|
-
createProducerConfig: () => createProducerConfig,
|
|
403
|
-
getClickhouseClient: () => getClickhouseClient,
|
|
404
|
-
getFileName: () => getFileName,
|
|
405
|
-
getKafkaClient: () => getKafkaClient,
|
|
406
|
-
getKafkaProducer: () => getKafkaProducer,
|
|
407
|
-
logError: () => logError,
|
|
408
|
-
mapTstoJs: () => mapTstoJs,
|
|
409
|
-
rewriteImportExtensions: () => rewriteImportExtensions
|
|
410
|
-
});
|
|
411
|
-
function walkDirectory(dir, extensions) {
|
|
412
|
-
const results = [];
|
|
413
|
-
if (!(0, import_fs.existsSync)(dir)) {
|
|
414
|
-
return results;
|
|
415
|
-
}
|
|
416
|
-
try {
|
|
417
|
-
const entries = (0, import_fs.readdirSync)(dir, { withFileTypes: true });
|
|
418
|
-
for (const entry of entries) {
|
|
419
|
-
const fullPath = import_path2.default.join(dir, entry.name);
|
|
420
|
-
if (entry.isDirectory()) {
|
|
421
|
-
if (entry.name !== "node_modules") {
|
|
422
|
-
results.push(...walkDirectory(fullPath, extensions));
|
|
423
|
-
}
|
|
424
|
-
} else if (entry.isFile()) {
|
|
425
|
-
const ext = import_path2.default.extname(entry.name);
|
|
426
|
-
if (extensions.includes(ext)) {
|
|
427
|
-
results.push(fullPath);
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
} catch (e) {
|
|
432
|
-
console.debug(`[moose] Failed to read directory ${dir}:`, e);
|
|
433
|
-
}
|
|
434
|
-
return results;
|
|
435
|
-
}
|
|
436
|
-
function addJsExtensionToImports(content, fileDir) {
|
|
437
|
-
const fromPattern = /(from\s+['"])(\.\.?\/[^'"]*?)(['"])/g;
|
|
438
|
-
const bareImportPattern = /(import\s+['"])(\.\.?\/[^'"]*?)(['"])/g;
|
|
439
|
-
const dynamicPattern = /(import\s*\(\s*['"])(\.\.?\/[^'"]*?)(['"])/g;
|
|
440
|
-
let result = content;
|
|
441
|
-
result = result.replace(fromPattern, (match, prefix, importPath, quote) => {
|
|
442
|
-
return rewriteImportPath(match, prefix, importPath, quote, fileDir);
|
|
443
|
-
});
|
|
444
|
-
result = result.replace(
|
|
445
|
-
bareImportPattern,
|
|
446
|
-
(match, prefix, importPath, quote) => {
|
|
447
|
-
return rewriteImportPath(match, prefix, importPath, quote, fileDir);
|
|
448
|
-
}
|
|
449
|
-
);
|
|
450
|
-
result = result.replace(
|
|
451
|
-
dynamicPattern,
|
|
452
|
-
(match, prefix, importPath, quote) => {
|
|
453
|
-
return rewriteImportPath(match, prefix, importPath, quote, fileDir);
|
|
454
|
-
}
|
|
455
|
-
);
|
|
456
|
-
return result;
|
|
457
|
-
}
|
|
458
|
-
function rewriteImportPath(match, prefix, importPath, quote, fileDir) {
|
|
459
|
-
if (/\.[cm]?js$/.test(importPath)) {
|
|
460
|
-
return match;
|
|
461
|
-
}
|
|
462
|
-
if (/\.json$/.test(importPath)) {
|
|
463
|
-
return match;
|
|
464
|
-
}
|
|
465
|
-
if (fileDir) {
|
|
466
|
-
const resolvedPath = import_path2.default.resolve(fileDir, importPath);
|
|
467
|
-
if ((0, import_fs.existsSync)(`${resolvedPath}.js`)) {
|
|
468
|
-
return `${prefix}${importPath}.js${quote}`;
|
|
469
|
-
}
|
|
470
|
-
if ((0, import_fs.existsSync)(import_path2.default.join(resolvedPath, "index.js"))) {
|
|
471
|
-
return `${prefix}${importPath}/index.js${quote}`;
|
|
472
|
-
}
|
|
473
|
-
if ((0, import_fs.existsSync)(`${resolvedPath}.mjs`)) {
|
|
474
|
-
return `${prefix}${importPath}.mjs${quote}`;
|
|
475
|
-
}
|
|
476
|
-
if ((0, import_fs.existsSync)(import_path2.default.join(resolvedPath, "index.mjs"))) {
|
|
477
|
-
return `${prefix}${importPath}/index.mjs${quote}`;
|
|
478
|
-
}
|
|
479
|
-
if ((0, import_fs.existsSync)(`${resolvedPath}.cjs`)) {
|
|
480
|
-
return `${prefix}${importPath}.cjs${quote}`;
|
|
481
|
-
}
|
|
482
|
-
if ((0, import_fs.existsSync)(import_path2.default.join(resolvedPath, "index.cjs"))) {
|
|
483
|
-
return `${prefix}${importPath}/index.cjs${quote}`;
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
return `${prefix}${importPath}.js${quote}`;
|
|
487
|
-
}
|
|
488
|
-
function rewriteImportExtensions(outDir) {
|
|
489
|
-
const files = walkDirectory(outDir, [".js", ".mjs"]);
|
|
490
|
-
for (const filePath of files) {
|
|
491
|
-
const content = (0, import_fs.readFileSync)(filePath, "utf-8");
|
|
492
|
-
const fileDir = import_path2.default.dirname(filePath);
|
|
493
|
-
const rewritten = addJsExtensionToImports(content, fileDir);
|
|
494
|
-
if (content !== rewritten) {
|
|
495
|
-
(0, import_fs.writeFileSync)(filePath, rewritten, "utf-8");
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
function createProducerConfig(maxMessageBytes) {
|
|
500
|
-
return {
|
|
501
|
-
kafkaJS: {
|
|
502
|
-
idempotent: false,
|
|
503
|
-
// Not needed for at-least-once delivery
|
|
504
|
-
acks: ACKs,
|
|
505
|
-
retry: {
|
|
506
|
-
retries: MAX_RETRIES_PRODUCER,
|
|
507
|
-
maxRetryTime: MAX_RETRY_TIME_MS
|
|
508
|
-
}
|
|
509
|
-
},
|
|
510
|
-
"linger.ms": 0,
|
|
511
|
-
// This is to make sure at least once delivery with immediate feedback on the send
|
|
512
|
-
...maxMessageBytes && { "message.max.bytes": maxMessageBytes }
|
|
513
|
-
};
|
|
514
|
-
}
|
|
515
|
-
async function getKafkaProducer(cfg, logger, maxMessageBytes) {
|
|
516
|
-
const kafka = await getKafkaClient(cfg, logger);
|
|
517
|
-
const producer = kafka.producer(createProducerConfig(maxMessageBytes));
|
|
518
|
-
await producer.connect();
|
|
519
|
-
return producer;
|
|
520
|
-
}
|
|
521
|
-
var Kafka;
|
|
522
|
-
var getClickhouseClient;
|
|
523
|
-
var parseBrokerString;
|
|
524
|
-
var buildSaslConfig;
|
|
525
|
-
var getKafkaClient;
|
|
526
|
-
var init_commons = __esm({
|
|
527
|
-
"src/commons.ts"() {
|
|
528
|
-
"use strict";
|
|
529
|
-
init_commons_types();
|
|
530
|
-
init_commons_types();
|
|
531
|
-
({ Kafka } = import_kafka_javascript.KafkaJS);
|
|
532
|
-
getClickhouseClient = ({
|
|
533
|
-
username,
|
|
534
|
-
password,
|
|
535
|
-
database,
|
|
536
|
-
useSSL,
|
|
537
|
-
host,
|
|
538
|
-
port
|
|
539
|
-
}) => {
|
|
540
|
-
const protocol = useSSL === "1" || useSSL.toLowerCase() === "true" ? "https" : "http";
|
|
541
|
-
console.log(`Connecting to Clickhouse at ${protocol}://${host}:${port}`);
|
|
542
|
-
return (0, import_client.createClient)({
|
|
543
|
-
url: `${protocol}://${host}:${port}`,
|
|
544
|
-
username,
|
|
545
|
-
password,
|
|
546
|
-
database,
|
|
547
|
-
application: "moose"
|
|
548
|
-
// Note: wait_end_of_query is configured per operation type, not globally
|
|
549
|
-
// to preserve SELECT query performance while ensuring INSERT/DDL reliability
|
|
550
|
-
});
|
|
551
|
-
};
|
|
552
|
-
parseBrokerString = (brokerString) => brokerString.split(",").map((b) => b.trim()).filter((b) => b.length > 0);
|
|
553
|
-
buildSaslConfig = (logger, args) => {
|
|
554
|
-
const mechanism = args.saslMechanism ? args.saslMechanism.toLowerCase() : "";
|
|
555
|
-
switch (mechanism) {
|
|
556
|
-
case "plain":
|
|
557
|
-
case "scram-sha-256":
|
|
558
|
-
case "scram-sha-512":
|
|
559
|
-
return {
|
|
560
|
-
mechanism,
|
|
561
|
-
username: args.saslUsername || "",
|
|
562
|
-
password: args.saslPassword || ""
|
|
563
|
-
};
|
|
564
|
-
default:
|
|
565
|
-
logger.warn(`Unsupported SASL mechanism: ${args.saslMechanism}`);
|
|
566
|
-
return void 0;
|
|
567
|
-
}
|
|
568
|
-
};
|
|
569
|
-
getKafkaClient = async (cfg, logger) => {
|
|
570
|
-
const brokers = parseBrokerString(cfg.broker || "");
|
|
571
|
-
if (brokers.length === 0) {
|
|
572
|
-
throw new Error(`No valid broker addresses found in: "${cfg.broker}"`);
|
|
573
|
-
}
|
|
574
|
-
logger.log(`Creating Kafka client with brokers: ${brokers.join(", ")}`);
|
|
575
|
-
logger.log(`Security protocol: ${cfg.securityProtocol || "plaintext"}`);
|
|
576
|
-
logger.log(`Client ID: ${cfg.clientId}`);
|
|
577
|
-
const saslConfig = buildSaslConfig(logger, cfg);
|
|
578
|
-
return new Kafka({
|
|
579
|
-
kafkaJS: {
|
|
580
|
-
clientId: cfg.clientId,
|
|
581
|
-
brokers,
|
|
582
|
-
ssl: cfg.securityProtocol === "SASL_SSL",
|
|
583
|
-
...saslConfig && { sasl: saslConfig },
|
|
584
|
-
retry: {
|
|
585
|
-
initialRetryTime: RETRY_INITIAL_TIME_MS,
|
|
586
|
-
maxRetryTime: MAX_RETRY_TIME_MS,
|
|
587
|
-
retries: MAX_RETRIES
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
});
|
|
591
|
-
};
|
|
592
|
-
}
|
|
593
|
-
});
|
|
594
|
-
var ClickHouseEngines = /* @__PURE__ */ ((ClickHouseEngines2) => {
|
|
595
|
-
ClickHouseEngines2["MergeTree"] = "MergeTree";
|
|
596
|
-
ClickHouseEngines2["ReplacingMergeTree"] = "ReplacingMergeTree";
|
|
597
|
-
ClickHouseEngines2["SummingMergeTree"] = "SummingMergeTree";
|
|
598
|
-
ClickHouseEngines2["AggregatingMergeTree"] = "AggregatingMergeTree";
|
|
599
|
-
ClickHouseEngines2["CollapsingMergeTree"] = "CollapsingMergeTree";
|
|
600
|
-
ClickHouseEngines2["VersionedCollapsingMergeTree"] = "VersionedCollapsingMergeTree";
|
|
601
|
-
ClickHouseEngines2["GraphiteMergeTree"] = "GraphiteMergeTree";
|
|
602
|
-
ClickHouseEngines2["S3Queue"] = "S3Queue";
|
|
603
|
-
ClickHouseEngines2["S3"] = "S3";
|
|
604
|
-
ClickHouseEngines2["Buffer"] = "Buffer";
|
|
605
|
-
ClickHouseEngines2["Distributed"] = "Distributed";
|
|
606
|
-
ClickHouseEngines2["IcebergS3"] = "IcebergS3";
|
|
607
|
-
ClickHouseEngines2["Kafka"] = "Kafka";
|
|
608
|
-
ClickHouseEngines2["ReplicatedMergeTree"] = "ReplicatedMergeTree";
|
|
609
|
-
ClickHouseEngines2["ReplicatedReplacingMergeTree"] = "ReplicatedReplacingMergeTree";
|
|
610
|
-
ClickHouseEngines2["ReplicatedAggregatingMergeTree"] = "ReplicatedAggregatingMergeTree";
|
|
611
|
-
ClickHouseEngines2["ReplicatedSummingMergeTree"] = "ReplicatedSummingMergeTree";
|
|
612
|
-
ClickHouseEngines2["ReplicatedCollapsingMergeTree"] = "ReplicatedCollapsingMergeTree";
|
|
613
|
-
ClickHouseEngines2["ReplicatedVersionedCollapsingMergeTree"] = "ReplicatedVersionedCollapsingMergeTree";
|
|
614
|
-
return ClickHouseEngines2;
|
|
615
|
-
})(ClickHouseEngines || {});
|
|
616
729
|
function shouldSkipStackLine(line) {
|
|
617
730
|
return line.includes("node_modules") || // Skip npm installed packages (prod)
|
|
618
731
|
line.includes("node:internal") || // Skip Node.js internals (modern format)
|
|
@@ -737,148 +850,73 @@ function isArrayNestedType(dt) {
|
|
|
737
850
|
function isNestedType(dt) {
|
|
738
851
|
return typeof dt === "object" && dt !== null && Array.isArray(dt.columns);
|
|
739
852
|
}
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
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
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
},
|
|
792
|
-
required: [
|
|
793
|
-
"originalRecord",
|
|
794
|
-
"errorMessage",
|
|
795
|
-
"errorType",
|
|
796
|
-
"failedAt",
|
|
797
|
-
"source"
|
|
798
|
-
]
|
|
799
|
-
},
|
|
800
|
-
Recordstringany: {
|
|
801
|
-
type: "object",
|
|
802
|
-
properties: {},
|
|
803
|
-
required: [],
|
|
804
|
-
description: "Construct a type with a set of properties K of type T",
|
|
805
|
-
additionalProperties: {}
|
|
806
|
-
}
|
|
853
|
+
var ClickHouseEngines = /* @__PURE__ */ ((ClickHouseEngines2) => {
|
|
854
|
+
ClickHouseEngines2["MergeTree"] = "MergeTree";
|
|
855
|
+
ClickHouseEngines2["ReplacingMergeTree"] = "ReplacingMergeTree";
|
|
856
|
+
ClickHouseEngines2["SummingMergeTree"] = "SummingMergeTree";
|
|
857
|
+
ClickHouseEngines2["AggregatingMergeTree"] = "AggregatingMergeTree";
|
|
858
|
+
ClickHouseEngines2["CollapsingMergeTree"] = "CollapsingMergeTree";
|
|
859
|
+
ClickHouseEngines2["VersionedCollapsingMergeTree"] = "VersionedCollapsingMergeTree";
|
|
860
|
+
ClickHouseEngines2["GraphiteMergeTree"] = "GraphiteMergeTree";
|
|
861
|
+
ClickHouseEngines2["S3Queue"] = "S3Queue";
|
|
862
|
+
ClickHouseEngines2["S3"] = "S3";
|
|
863
|
+
ClickHouseEngines2["Buffer"] = "Buffer";
|
|
864
|
+
ClickHouseEngines2["Distributed"] = "Distributed";
|
|
865
|
+
ClickHouseEngines2["IcebergS3"] = "IcebergS3";
|
|
866
|
+
ClickHouseEngines2["Kafka"] = "Kafka";
|
|
867
|
+
ClickHouseEngines2["ReplicatedMergeTree"] = "ReplicatedMergeTree";
|
|
868
|
+
ClickHouseEngines2["ReplicatedReplacingMergeTree"] = "ReplicatedReplacingMergeTree";
|
|
869
|
+
ClickHouseEngines2["ReplicatedAggregatingMergeTree"] = "ReplicatedAggregatingMergeTree";
|
|
870
|
+
ClickHouseEngines2["ReplicatedSummingMergeTree"] = "ReplicatedSummingMergeTree";
|
|
871
|
+
ClickHouseEngines2["ReplicatedCollapsingMergeTree"] = "ReplicatedCollapsingMergeTree";
|
|
872
|
+
ClickHouseEngines2["ReplicatedVersionedCollapsingMergeTree"] = "ReplicatedVersionedCollapsingMergeTree";
|
|
873
|
+
return ClickHouseEngines2;
|
|
874
|
+
})(ClickHouseEngines || {});
|
|
875
|
+
init_commons();
|
|
876
|
+
var MOOSE_RUNTIME_ENV_PREFIX = "__MOOSE_RUNTIME_ENV__:";
|
|
877
|
+
var mooseRuntimeEnv = {
|
|
878
|
+
/**
|
|
879
|
+
* Gets a value from an environment variable, with behavior depending on context.
|
|
880
|
+
*
|
|
881
|
+
* When IS_LOADING_INFRA_MAP=true (infrastructure loading):
|
|
882
|
+
* Returns a marker string that Moose CLI will resolve later
|
|
883
|
+
*
|
|
884
|
+
* When IS_LOADING_INFRA_MAP is unset (function/workflow runtime):
|
|
885
|
+
* Returns the actual value from the environment variable
|
|
886
|
+
*
|
|
887
|
+
* @param envVarName - Name of the environment variable to resolve
|
|
888
|
+
* @returns Either a marker string or the actual environment variable value
|
|
889
|
+
* @throws {Error} If the environment variable name is empty
|
|
890
|
+
* @throws {Error} If the environment variable is not set (runtime mode only)
|
|
891
|
+
*
|
|
892
|
+
* @example
|
|
893
|
+
* ```typescript
|
|
894
|
+
* // Instead of this (evaluated at build time):
|
|
895
|
+
* awsAccessKeyId: process.env.AWS_ACCESS_KEY_ID
|
|
896
|
+
*
|
|
897
|
+
* // Use this (evaluated at runtime):
|
|
898
|
+
* awsAccessKeyId: mooseRuntimeEnv.get("AWS_ACCESS_KEY_ID")
|
|
899
|
+
* ```
|
|
900
|
+
*/
|
|
901
|
+
get(envVarName) {
|
|
902
|
+
if (!envVarName || envVarName.trim() === "") {
|
|
903
|
+
throw new Error("Environment variable name cannot be empty");
|
|
807
904
|
}
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
905
|
+
const isLoadingInfraMap = process.env.IS_LOADING_INFRA_MAP === "true";
|
|
906
|
+
if (isLoadingInfraMap) {
|
|
907
|
+
return `${MOOSE_RUNTIME_ENV_PREFIX}${envVarName}`;
|
|
908
|
+
} else {
|
|
909
|
+
const value = process.env[envVarName];
|
|
910
|
+
if (value === void 0) {
|
|
911
|
+
throw new Error(
|
|
912
|
+
`Environment variable '${envVarName}' is not set. This is required for runtime execution of functions/workflows.`
|
|
913
|
+
);
|
|
914
|
+
}
|
|
915
|
+
return value;
|
|
812
916
|
}
|
|
813
|
-
]
|
|
814
|
-
};
|
|
815
|
-
var dlqColumns = [
|
|
816
|
-
{
|
|
817
|
-
name: "originalRecord",
|
|
818
|
-
data_type: "Json",
|
|
819
|
-
primary_key: false,
|
|
820
|
-
required: true,
|
|
821
|
-
unique: false,
|
|
822
|
-
default: null,
|
|
823
|
-
annotations: [],
|
|
824
|
-
ttl: null,
|
|
825
|
-
codec: null,
|
|
826
|
-
materialized: null,
|
|
827
|
-
comment: null
|
|
828
|
-
},
|
|
829
|
-
{
|
|
830
|
-
name: "errorMessage",
|
|
831
|
-
data_type: "String",
|
|
832
|
-
primary_key: false,
|
|
833
|
-
required: true,
|
|
834
|
-
unique: false,
|
|
835
|
-
default: null,
|
|
836
|
-
annotations: [],
|
|
837
|
-
ttl: null,
|
|
838
|
-
codec: null,
|
|
839
|
-
materialized: null,
|
|
840
|
-
comment: null
|
|
841
|
-
},
|
|
842
|
-
{
|
|
843
|
-
name: "errorType",
|
|
844
|
-
data_type: "String",
|
|
845
|
-
primary_key: false,
|
|
846
|
-
required: true,
|
|
847
|
-
unique: false,
|
|
848
|
-
default: null,
|
|
849
|
-
annotations: [],
|
|
850
|
-
ttl: null,
|
|
851
|
-
codec: null,
|
|
852
|
-
materialized: null,
|
|
853
|
-
comment: null
|
|
854
|
-
},
|
|
855
|
-
{
|
|
856
|
-
name: "failedAt",
|
|
857
|
-
data_type: "DateTime",
|
|
858
|
-
primary_key: false,
|
|
859
|
-
required: true,
|
|
860
|
-
unique: false,
|
|
861
|
-
default: null,
|
|
862
|
-
annotations: [],
|
|
863
|
-
ttl: null,
|
|
864
|
-
codec: null,
|
|
865
|
-
materialized: null,
|
|
866
|
-
comment: null
|
|
867
|
-
},
|
|
868
|
-
{
|
|
869
|
-
name: "source",
|
|
870
|
-
data_type: "String",
|
|
871
|
-
primary_key: false,
|
|
872
|
-
required: true,
|
|
873
|
-
unique: false,
|
|
874
|
-
default: null,
|
|
875
|
-
annotations: [],
|
|
876
|
-
ttl: null,
|
|
877
|
-
codec: null,
|
|
878
|
-
materialized: null,
|
|
879
|
-
comment: null
|
|
880
917
|
}
|
|
881
|
-
|
|
918
|
+
};
|
|
919
|
+
var mooseEnvSecrets = mooseRuntimeEnv;
|
|
882
920
|
var quoteIdentifier = (name) => {
|
|
883
921
|
return name.startsWith("`") && name.endsWith("`") ? name : `\`${name}\``;
|
|
884
922
|
};
|
|
@@ -965,8 +1003,8 @@ sql.join = function(fragments, separator) {
|
|
|
965
1003
|
sql.raw = function(text) {
|
|
966
1004
|
return new Sql([text], []);
|
|
967
1005
|
};
|
|
968
|
-
var toStaticQuery = (
|
|
969
|
-
const [query, params] = toQuery(
|
|
1006
|
+
var toStaticQuery = (sql3) => {
|
|
1007
|
+
const [query, params] = toQuery(sql3);
|
|
970
1008
|
if (Object.keys(params).length !== 0) {
|
|
971
1009
|
throw new Error(
|
|
972
1010
|
"Dynamic SQL is not allowed in the select statement in view creation."
|
|
@@ -974,14 +1012,14 @@ var toStaticQuery = (sql2) => {
|
|
|
974
1012
|
}
|
|
975
1013
|
return query;
|
|
976
1014
|
};
|
|
977
|
-
var toQuery = (
|
|
978
|
-
const parameterizedStubs =
|
|
1015
|
+
var toQuery = (sql3) => {
|
|
1016
|
+
const parameterizedStubs = sql3.values.map(
|
|
979
1017
|
(v, i) => createClickhouseParameter(i, v)
|
|
980
1018
|
);
|
|
981
|
-
const query =
|
|
1019
|
+
const query = sql3.strings.map(
|
|
982
1020
|
(s, i) => s != "" ? `${s}${emptyIfUndefined(parameterizedStubs[i])}` : ""
|
|
983
1021
|
).join("");
|
|
984
|
-
const query_params =
|
|
1022
|
+
const query_params = sql3.values.reduce(
|
|
985
1023
|
(acc, v, i) => ({
|
|
986
1024
|
...acc,
|
|
987
1025
|
[`p${i}`]: getValueFromParameter(v)
|
|
@@ -990,7 +1028,7 @@ var toQuery = (sql2) => {
|
|
|
990
1028
|
);
|
|
991
1029
|
return [query, query_params];
|
|
992
1030
|
};
|
|
993
|
-
var toQueryPreview = (
|
|
1031
|
+
var toQueryPreview = (sql3) => {
|
|
994
1032
|
try {
|
|
995
1033
|
const formatValue = (v) => {
|
|
996
1034
|
if (Array.isArray(v)) {
|
|
@@ -1011,44 +1049,254 @@ var toQueryPreview = (sql2) => {
|
|
|
1011
1049
|
} catch {
|
|
1012
1050
|
return String(v);
|
|
1013
1051
|
}
|
|
1014
|
-
};
|
|
1015
|
-
let out =
|
|
1016
|
-
for (let i = 0; i <
|
|
1017
|
-
const val = getValueFromParameter(
|
|
1018
|
-
out += formatValue(val);
|
|
1019
|
-
out +=
|
|
1052
|
+
};
|
|
1053
|
+
let out = sql3.strings[0] ?? "";
|
|
1054
|
+
for (let i = 0; i < sql3.values.length; i++) {
|
|
1055
|
+
const val = getValueFromParameter(sql3.values[i]);
|
|
1056
|
+
out += formatValue(val);
|
|
1057
|
+
out += sql3.strings[i + 1] ?? "";
|
|
1058
|
+
}
|
|
1059
|
+
return out.replace(/\s+/g, " ").trim();
|
|
1060
|
+
} catch (error) {
|
|
1061
|
+
console.log(`toQueryPreview error: ${error}`);
|
|
1062
|
+
return "/* query preview unavailable */";
|
|
1063
|
+
}
|
|
1064
|
+
};
|
|
1065
|
+
var getValueFromParameter = (value) => {
|
|
1066
|
+
if (Array.isArray(value)) {
|
|
1067
|
+
const [type, val] = value;
|
|
1068
|
+
if (type === "Identifier") return val;
|
|
1069
|
+
}
|
|
1070
|
+
return value;
|
|
1071
|
+
};
|
|
1072
|
+
function createClickhouseParameter(parameterIndex, value) {
|
|
1073
|
+
return `{p${parameterIndex}:${mapToClickHouseType(value)}}`;
|
|
1074
|
+
}
|
|
1075
|
+
var mapToClickHouseType = (value) => {
|
|
1076
|
+
if (typeof value === "number") {
|
|
1077
|
+
return Number.isInteger(value) ? "Int" : "Float";
|
|
1078
|
+
}
|
|
1079
|
+
if (typeof value === "boolean") return "Bool";
|
|
1080
|
+
if (value instanceof Date) return "DateTime";
|
|
1081
|
+
if (Array.isArray(value)) {
|
|
1082
|
+
const [type, _] = value;
|
|
1083
|
+
return type;
|
|
1084
|
+
}
|
|
1085
|
+
return "String";
|
|
1086
|
+
};
|
|
1087
|
+
function emptyIfUndefined(value) {
|
|
1088
|
+
return value === void 0 ? "" : value;
|
|
1089
|
+
}
|
|
1090
|
+
init_commons();
|
|
1091
|
+
function jsonDateReviver(key, value) {
|
|
1092
|
+
const iso8601Format = /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)$/;
|
|
1093
|
+
if (typeof value === "string" && iso8601Format.test(value)) {
|
|
1094
|
+
return new Date(value);
|
|
1095
|
+
}
|
|
1096
|
+
return value;
|
|
1097
|
+
}
|
|
1098
|
+
function parseCSV(content, config) {
|
|
1099
|
+
return new Promise((resolve, reject) => {
|
|
1100
|
+
const results = [];
|
|
1101
|
+
(0, import_csv_parse.parse)(content, {
|
|
1102
|
+
delimiter: config.delimiter,
|
|
1103
|
+
columns: config.columns ?? true,
|
|
1104
|
+
skip_empty_lines: config.skipEmptyLines ?? true,
|
|
1105
|
+
trim: config.trim ?? true
|
|
1106
|
+
}).on("data", (row) => {
|
|
1107
|
+
results.push(row);
|
|
1108
|
+
}).on("end", () => {
|
|
1109
|
+
resolve(results);
|
|
1110
|
+
}).on("error", (error) => {
|
|
1111
|
+
reject(error);
|
|
1112
|
+
});
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
function parseJSON(content, config = {}) {
|
|
1116
|
+
try {
|
|
1117
|
+
const parsed = JSON.parse(content, config.reviver);
|
|
1118
|
+
if (Array.isArray(parsed)) {
|
|
1119
|
+
return parsed;
|
|
1120
|
+
} else {
|
|
1121
|
+
return [parsed];
|
|
1122
|
+
}
|
|
1123
|
+
} catch (error) {
|
|
1124
|
+
throw new Error(
|
|
1125
|
+
`Failed to parse JSON: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
1126
|
+
);
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
function parseJSONWithDates(content) {
|
|
1130
|
+
return parseJSON(content, { reviver: jsonDateReviver });
|
|
1131
|
+
}
|
|
1132
|
+
function isValidCSVDelimiter(delimiter) {
|
|
1133
|
+
return delimiter.length === 1 && !/\s/.test(delimiter);
|
|
1134
|
+
}
|
|
1135
|
+
var CSV_DELIMITERS = {
|
|
1136
|
+
COMMA: ",",
|
|
1137
|
+
TAB: " ",
|
|
1138
|
+
SEMICOLON: ";",
|
|
1139
|
+
PIPE: "|"
|
|
1140
|
+
};
|
|
1141
|
+
var DEFAULT_CSV_CONFIG = {
|
|
1142
|
+
delimiter: CSV_DELIMITERS.COMMA,
|
|
1143
|
+
columns: true,
|
|
1144
|
+
skipEmptyLines: true,
|
|
1145
|
+
trim: true
|
|
1146
|
+
};
|
|
1147
|
+
var DEFAULT_JSON_CONFIG = {
|
|
1148
|
+
reviver: jsonDateReviver
|
|
1149
|
+
};
|
|
1150
|
+
var DataSource = class {
|
|
1151
|
+
name;
|
|
1152
|
+
supportsIncremental;
|
|
1153
|
+
constructor(config) {
|
|
1154
|
+
this.name = config.name;
|
|
1155
|
+
this.supportsIncremental = config.supportsIncremental ?? false;
|
|
1156
|
+
}
|
|
1157
|
+
};
|
|
1158
|
+
init_commons();
|
|
1159
|
+
var isClientOnlyMode = () => import_process.default.env.MOOSE_CLIENT_ONLY === "true";
|
|
1160
|
+
var moose_internal = {
|
|
1161
|
+
tables: /* @__PURE__ */ new Map(),
|
|
1162
|
+
streams: /* @__PURE__ */ new Map(),
|
|
1163
|
+
ingestApis: /* @__PURE__ */ new Map(),
|
|
1164
|
+
apis: /* @__PURE__ */ new Map(),
|
|
1165
|
+
sqlResources: /* @__PURE__ */ new Map(),
|
|
1166
|
+
workflows: /* @__PURE__ */ new Map(),
|
|
1167
|
+
webApps: /* @__PURE__ */ new Map(),
|
|
1168
|
+
materializedViews: /* @__PURE__ */ new Map(),
|
|
1169
|
+
views: /* @__PURE__ */ new Map()
|
|
1170
|
+
};
|
|
1171
|
+
var defaultRetentionPeriod = 60 * 60 * 24 * 7;
|
|
1172
|
+
var getMooseInternal = () => globalThis.moose_internal;
|
|
1173
|
+
if (getMooseInternal() === void 0) {
|
|
1174
|
+
globalThis.moose_internal = moose_internal;
|
|
1175
|
+
}
|
|
1176
|
+
var dlqSchema = {
|
|
1177
|
+
version: "3.1",
|
|
1178
|
+
components: {
|
|
1179
|
+
schemas: {
|
|
1180
|
+
DeadLetterModel: {
|
|
1181
|
+
type: "object",
|
|
1182
|
+
properties: {
|
|
1183
|
+
originalRecord: {
|
|
1184
|
+
$ref: "#/components/schemas/Recordstringany"
|
|
1185
|
+
},
|
|
1186
|
+
errorMessage: {
|
|
1187
|
+
type: "string"
|
|
1188
|
+
},
|
|
1189
|
+
errorType: {
|
|
1190
|
+
type: "string"
|
|
1191
|
+
},
|
|
1192
|
+
failedAt: {
|
|
1193
|
+
type: "string",
|
|
1194
|
+
format: "date-time"
|
|
1195
|
+
},
|
|
1196
|
+
source: {
|
|
1197
|
+
oneOf: [
|
|
1198
|
+
{
|
|
1199
|
+
const: "api"
|
|
1200
|
+
},
|
|
1201
|
+
{
|
|
1202
|
+
const: "transform"
|
|
1203
|
+
},
|
|
1204
|
+
{
|
|
1205
|
+
const: "table"
|
|
1206
|
+
}
|
|
1207
|
+
]
|
|
1208
|
+
}
|
|
1209
|
+
},
|
|
1210
|
+
required: [
|
|
1211
|
+
"originalRecord",
|
|
1212
|
+
"errorMessage",
|
|
1213
|
+
"errorType",
|
|
1214
|
+
"failedAt",
|
|
1215
|
+
"source"
|
|
1216
|
+
]
|
|
1217
|
+
},
|
|
1218
|
+
Recordstringany: {
|
|
1219
|
+
type: "object",
|
|
1220
|
+
properties: {},
|
|
1221
|
+
required: [],
|
|
1222
|
+
description: "Construct a type with a set of properties K of type T",
|
|
1223
|
+
additionalProperties: {}
|
|
1224
|
+
}
|
|
1020
1225
|
}
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
var getValueFromParameter = (value) => {
|
|
1028
|
-
if (Array.isArray(value)) {
|
|
1029
|
-
const [type, val] = value;
|
|
1030
|
-
if (type === "Identifier") return val;
|
|
1031
|
-
}
|
|
1032
|
-
return value;
|
|
1226
|
+
},
|
|
1227
|
+
schemas: [
|
|
1228
|
+
{
|
|
1229
|
+
$ref: "#/components/schemas/DeadLetterModel"
|
|
1230
|
+
}
|
|
1231
|
+
]
|
|
1033
1232
|
};
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1233
|
+
var dlqColumns = [
|
|
1234
|
+
{
|
|
1235
|
+
name: "originalRecord",
|
|
1236
|
+
data_type: "Json",
|
|
1237
|
+
primary_key: false,
|
|
1238
|
+
required: true,
|
|
1239
|
+
unique: false,
|
|
1240
|
+
default: null,
|
|
1241
|
+
annotations: [],
|
|
1242
|
+
ttl: null,
|
|
1243
|
+
codec: null,
|
|
1244
|
+
materialized: null,
|
|
1245
|
+
comment: null
|
|
1246
|
+
},
|
|
1247
|
+
{
|
|
1248
|
+
name: "errorMessage",
|
|
1249
|
+
data_type: "String",
|
|
1250
|
+
primary_key: false,
|
|
1251
|
+
required: true,
|
|
1252
|
+
unique: false,
|
|
1253
|
+
default: null,
|
|
1254
|
+
annotations: [],
|
|
1255
|
+
ttl: null,
|
|
1256
|
+
codec: null,
|
|
1257
|
+
materialized: null,
|
|
1258
|
+
comment: null
|
|
1259
|
+
},
|
|
1260
|
+
{
|
|
1261
|
+
name: "errorType",
|
|
1262
|
+
data_type: "String",
|
|
1263
|
+
primary_key: false,
|
|
1264
|
+
required: true,
|
|
1265
|
+
unique: false,
|
|
1266
|
+
default: null,
|
|
1267
|
+
annotations: [],
|
|
1268
|
+
ttl: null,
|
|
1269
|
+
codec: null,
|
|
1270
|
+
materialized: null,
|
|
1271
|
+
comment: null
|
|
1272
|
+
},
|
|
1273
|
+
{
|
|
1274
|
+
name: "failedAt",
|
|
1275
|
+
data_type: "DateTime",
|
|
1276
|
+
primary_key: false,
|
|
1277
|
+
required: true,
|
|
1278
|
+
unique: false,
|
|
1279
|
+
default: null,
|
|
1280
|
+
annotations: [],
|
|
1281
|
+
ttl: null,
|
|
1282
|
+
codec: null,
|
|
1283
|
+
materialized: null,
|
|
1284
|
+
comment: null
|
|
1285
|
+
},
|
|
1286
|
+
{
|
|
1287
|
+
name: "source",
|
|
1288
|
+
data_type: "String",
|
|
1289
|
+
primary_key: false,
|
|
1290
|
+
required: true,
|
|
1291
|
+
unique: false,
|
|
1292
|
+
default: null,
|
|
1293
|
+
annotations: [],
|
|
1294
|
+
ttl: null,
|
|
1295
|
+
codec: null,
|
|
1296
|
+
materialized: null,
|
|
1297
|
+
comment: null
|
|
1046
1298
|
}
|
|
1047
|
-
|
|
1048
|
-
};
|
|
1049
|
-
function emptyIfUndefined(value) {
|
|
1050
|
-
return value === void 0 ? "" : value;
|
|
1051
|
-
}
|
|
1299
|
+
];
|
|
1052
1300
|
var OlapTable = class extends TypedBase {
|
|
1053
1301
|
name;
|
|
1054
1302
|
/** @internal */
|
|
@@ -1787,7 +2035,7 @@ var Stream = class extends TypedBase {
|
|
|
1787
2035
|
*
|
|
1788
2036
|
* @internal
|
|
1789
2037
|
*/
|
|
1790
|
-
_consumers =
|
|
2038
|
+
_consumers = new Array();
|
|
1791
2039
|
/**
|
|
1792
2040
|
* Builds the full Kafka topic name including optional namespace and version suffix.
|
|
1793
2041
|
* Version suffix is appended as _x_y_z where dots in version are replaced with underscores.
|
|
@@ -1892,7 +2140,7 @@ var Stream = class extends TypedBase {
|
|
|
1892
2140
|
default: { SchemaRegistry }
|
|
1893
2141
|
} = await Promise.resolve().then(() => __toESM(require_confluent_schema_registry(), 1));
|
|
1894
2142
|
const registry = new SchemaRegistry({ host: schemaRegistryUrl });
|
|
1895
|
-
let schemaId;
|
|
2143
|
+
let schemaId = void 0;
|
|
1896
2144
|
if ("id" in sr.reference) {
|
|
1897
2145
|
schemaId = sr.reference.id;
|
|
1898
2146
|
} else if ("subjectLatest" in sr.reference) {
|
|
@@ -2652,10 +2900,10 @@ var SqlResource = class {
|
|
|
2652
2900
|
sqlResources.set(name, this);
|
|
2653
2901
|
this.name = name;
|
|
2654
2902
|
this.setup = setup.map(
|
|
2655
|
-
(
|
|
2903
|
+
(sql3) => typeof sql3 === "string" ? sql3 : toStaticQuery(sql3)
|
|
2656
2904
|
);
|
|
2657
2905
|
this.teardown = teardown.map(
|
|
2658
|
-
(
|
|
2906
|
+
(sql3) => typeof sql3 === "string" ? sql3 : toStaticQuery(sql3)
|
|
2659
2907
|
);
|
|
2660
2908
|
this.pullsDataFrom = options?.pullsDataFrom ?? [];
|
|
2661
2909
|
this.pushesDataTo = options?.pushesDataTo ?? [];
|
|
@@ -2884,7 +3132,7 @@ function getSqlResources() {
|
|
|
2884
3132
|
function getSqlResource(name) {
|
|
2885
3133
|
return getMooseInternal().sqlResources.get(name);
|
|
2886
3134
|
}
|
|
2887
|
-
function
|
|
3135
|
+
function getWorkflows2() {
|
|
2888
3136
|
return getMooseInternal().workflows;
|
|
2889
3137
|
}
|
|
2890
3138
|
function getWorkflow(name) {
|
|
@@ -2908,118 +3156,7 @@ function getViews() {
|
|
|
2908
3156
|
function getView(name) {
|
|
2909
3157
|
return getMooseInternal().views.get(name);
|
|
2910
3158
|
}
|
|
2911
|
-
|
|
2912
|
-
var DataSource = class {
|
|
2913
|
-
name;
|
|
2914
|
-
supportsIncremental;
|
|
2915
|
-
constructor(config) {
|
|
2916
|
-
this.name = config.name;
|
|
2917
|
-
this.supportsIncremental = config.supportsIncremental ?? false;
|
|
2918
|
-
}
|
|
2919
|
-
};
|
|
2920
|
-
var MOOSE_RUNTIME_ENV_PREFIX = "__MOOSE_RUNTIME_ENV__:";
|
|
2921
|
-
var mooseRuntimeEnv = {
|
|
2922
|
-
/**
|
|
2923
|
-
* Gets a value from an environment variable, with behavior depending on context.
|
|
2924
|
-
*
|
|
2925
|
-
* When IS_LOADING_INFRA_MAP=true (infrastructure loading):
|
|
2926
|
-
* Returns a marker string that Moose CLI will resolve later
|
|
2927
|
-
*
|
|
2928
|
-
* When IS_LOADING_INFRA_MAP is unset (function/workflow runtime):
|
|
2929
|
-
* Returns the actual value from the environment variable
|
|
2930
|
-
*
|
|
2931
|
-
* @param envVarName - Name of the environment variable to resolve
|
|
2932
|
-
* @returns Either a marker string or the actual environment variable value
|
|
2933
|
-
* @throws {Error} If the environment variable name is empty
|
|
2934
|
-
* @throws {Error} If the environment variable is not set (runtime mode only)
|
|
2935
|
-
*
|
|
2936
|
-
* @example
|
|
2937
|
-
* ```typescript
|
|
2938
|
-
* // Instead of this (evaluated at build time):
|
|
2939
|
-
* awsAccessKeyId: process.env.AWS_ACCESS_KEY_ID
|
|
2940
|
-
*
|
|
2941
|
-
* // Use this (evaluated at runtime):
|
|
2942
|
-
* awsAccessKeyId: mooseRuntimeEnv.get("AWS_ACCESS_KEY_ID")
|
|
2943
|
-
* ```
|
|
2944
|
-
*/
|
|
2945
|
-
get(envVarName) {
|
|
2946
|
-
if (!envVarName || envVarName.trim() === "") {
|
|
2947
|
-
throw new Error("Environment variable name cannot be empty");
|
|
2948
|
-
}
|
|
2949
|
-
const isLoadingInfraMap = process.env.IS_LOADING_INFRA_MAP === "true";
|
|
2950
|
-
if (isLoadingInfraMap) {
|
|
2951
|
-
return `${MOOSE_RUNTIME_ENV_PREFIX}${envVarName}`;
|
|
2952
|
-
} else {
|
|
2953
|
-
const value = process.env[envVarName];
|
|
2954
|
-
if (value === void 0) {
|
|
2955
|
-
throw new Error(
|
|
2956
|
-
`Environment variable '${envVarName}' is not set. This is required for runtime execution of functions/workflows.`
|
|
2957
|
-
);
|
|
2958
|
-
}
|
|
2959
|
-
return value;
|
|
2960
|
-
}
|
|
2961
|
-
}
|
|
2962
|
-
};
|
|
2963
|
-
var mooseEnvSecrets = mooseRuntimeEnv;
|
|
2964
|
-
function jsonDateReviver(key, value) {
|
|
2965
|
-
const iso8601Format = /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)$/;
|
|
2966
|
-
if (typeof value === "string" && iso8601Format.test(value)) {
|
|
2967
|
-
return new Date(value);
|
|
2968
|
-
}
|
|
2969
|
-
return value;
|
|
2970
|
-
}
|
|
2971
|
-
function parseCSV(content, config) {
|
|
2972
|
-
return new Promise((resolve, reject) => {
|
|
2973
|
-
const results = [];
|
|
2974
|
-
(0, import_csv_parse.parse)(content, {
|
|
2975
|
-
delimiter: config.delimiter,
|
|
2976
|
-
columns: config.columns ?? true,
|
|
2977
|
-
skip_empty_lines: config.skipEmptyLines ?? true,
|
|
2978
|
-
trim: config.trim ?? true
|
|
2979
|
-
}).on("data", (row) => {
|
|
2980
|
-
results.push(row);
|
|
2981
|
-
}).on("end", () => {
|
|
2982
|
-
resolve(results);
|
|
2983
|
-
}).on("error", (error) => {
|
|
2984
|
-
reject(error);
|
|
2985
|
-
});
|
|
2986
|
-
});
|
|
2987
|
-
}
|
|
2988
|
-
function parseJSON(content, config = {}) {
|
|
2989
|
-
try {
|
|
2990
|
-
const parsed = JSON.parse(content, config.reviver);
|
|
2991
|
-
if (Array.isArray(parsed)) {
|
|
2992
|
-
return parsed;
|
|
2993
|
-
} else {
|
|
2994
|
-
return [parsed];
|
|
2995
|
-
}
|
|
2996
|
-
} catch (error) {
|
|
2997
|
-
throw new Error(
|
|
2998
|
-
`Failed to parse JSON: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
2999
|
-
);
|
|
3000
|
-
}
|
|
3001
|
-
}
|
|
3002
|
-
function parseJSONWithDates(content) {
|
|
3003
|
-
return parseJSON(content, { reviver: jsonDateReviver });
|
|
3004
|
-
}
|
|
3005
|
-
function isValidCSVDelimiter(delimiter) {
|
|
3006
|
-
return delimiter.length === 1 && !/\s/.test(delimiter);
|
|
3007
|
-
}
|
|
3008
|
-
var CSV_DELIMITERS = {
|
|
3009
|
-
COMMA: ",",
|
|
3010
|
-
TAB: " ",
|
|
3011
|
-
SEMICOLON: ";",
|
|
3012
|
-
PIPE: "|"
|
|
3013
|
-
};
|
|
3014
|
-
var DEFAULT_CSV_CONFIG = {
|
|
3015
|
-
delimiter: CSV_DELIMITERS.COMMA,
|
|
3016
|
-
columns: true,
|
|
3017
|
-
skipEmptyLines: true,
|
|
3018
|
-
trim: true
|
|
3019
|
-
};
|
|
3020
|
-
var DEFAULT_JSON_CONFIG = {
|
|
3021
|
-
reviver: jsonDateReviver
|
|
3022
|
-
};
|
|
3159
|
+
init_commons();
|
|
3023
3160
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3024
3161
|
0 && (module.exports = {
|
|
3025
3162
|
ACKs,
|