@514labs/moose-lib 0.6.321-ci-5-ga23d35fe → 0.6.322-ci-1-gb296906d

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.
@@ -52,13 +52,6 @@ var init_dataModelTypes = __esm({
52
52
  }
53
53
  });
54
54
 
55
- // src/dataModels/types.ts
56
- var init_types = __esm({
57
- "src/dataModels/types.ts"() {
58
- "use strict";
59
- }
60
- });
61
-
62
55
  // src/sqlHelpers.ts
63
56
  function sql(strings, ...values) {
64
57
  return new Sql(strings, values);
@@ -207,6 +200,14 @@ var init_sqlHelpers = __esm({
207
200
  }
208
201
  });
209
202
 
203
+ // src/blocks/helpers.ts
204
+ var init_helpers = __esm({
205
+ "src/blocks/helpers.ts"() {
206
+ "use strict";
207
+ init_sqlHelpers();
208
+ }
209
+ });
210
+
210
211
  // src/dmv2/sdk/olapTable.ts
211
212
  var import_node_stream, import_node_crypto;
212
213
  var init_olapTable = __esm({
@@ -214,7 +215,7 @@ var init_olapTable = __esm({
214
215
  "use strict";
215
216
  init_typedBase();
216
217
  init_dataModelTypes();
217
- init_types();
218
+ init_helpers();
218
219
  init_internal();
219
220
  import_node_stream = require("stream");
220
221
  import_node_crypto = require("crypto");
@@ -268,7 +269,7 @@ var init_ingestPipeline = __esm({
268
269
  init_stream();
269
270
  init_olapTable();
270
271
  init_ingestApi();
271
- init_types();
272
+ init_helpers();
272
273
  }
273
274
  });
274
275
 
@@ -284,7 +285,7 @@ var init_etlPipeline = __esm({
284
285
  var init_materializedView = __esm({
285
286
  "src/dmv2/sdk/materializedView.ts"() {
286
287
  "use strict";
287
- init_types();
288
+ init_helpers();
288
289
  init_sqlHelpers();
289
290
  init_olapTable();
290
291
  init_internal();
@@ -341,7 +342,6 @@ var init_dmv2 = __esm({
341
342
  "src/dmv2/index.ts"() {
342
343
  "use strict";
343
344
  init_olapTable();
344
- init_types();
345
345
  init_stream();
346
346
  init_workflow();
347
347
  init_ingestApi();
@@ -357,6 +357,13 @@ var init_dmv2 = __esm({
357
357
  }
358
358
  });
359
359
 
360
+ // src/dataModels/types.ts
361
+ var init_types = __esm({
362
+ "src/dataModels/types.ts"() {
363
+ "use strict";
364
+ }
365
+ });
366
+
360
367
  // src/browserCompatible.ts
361
368
  var init_browserCompatible = __esm({
362
369
  "src/browserCompatible.ts"() {
@@ -553,7 +560,7 @@ async function getTemporalClient(temporalUrl, namespace, clientCert, clientKey,
553
560
  }
554
561
  }
555
562
  var import_client2, import_node_crypto3, import_perf_hooks, fs, MooseClient, QueryClient, WorkflowClient;
556
- var init_helpers = __esm({
563
+ var init_helpers2 = __esm({
557
564
  "src/consumption-apis/helpers.ts"() {
558
565
  "use strict";
559
566
  import_client2 = require("@temporalio/client");
@@ -680,11 +687,11 @@ var init_helpers = __esm({
680
687
  }
681
688
  async getWorkflowConfig(name) {
682
689
  const workflows = await getWorkflows2();
683
- const workflow = workflows.get(name);
684
- if (workflow) {
690
+ const dmv2Workflow = workflows.get(name);
691
+ if (dmv2Workflow) {
685
692
  return {
686
- retries: workflow.config.retries || 3,
687
- timeout: workflow.config.timeout || "1h"
693
+ retries: dmv2Workflow.config.retries || 3,
694
+ timeout: dmv2Workflow.config.timeout || "1h"
688
695
  };
689
696
  }
690
697
  throw new Error(`Workflow config not found for ${name}`);
@@ -928,11 +935,11 @@ var init_cluster_utils = __esm({
928
935
 
929
936
  // src/config/configFile.ts
930
937
  async function findConfigFile(startDir = process.cwd()) {
931
- const fs4 = await import("fs");
938
+ const fs5 = await import("fs");
932
939
  let currentDir = import_node_path.default.resolve(startDir);
933
940
  while (true) {
934
941
  const configPath = import_node_path.default.join(currentDir, "moose.config.toml");
935
- if (fs4.existsSync(configPath)) {
942
+ if (fs5.existsSync(configPath)) {
936
943
  return configPath;
937
944
  }
938
945
  const parentDir = import_node_path.default.dirname(currentDir);
@@ -944,7 +951,7 @@ async function findConfigFile(startDir = process.cwd()) {
944
951
  return null;
945
952
  }
946
953
  async function readProjectConfig() {
947
- const fs4 = await import("fs");
954
+ const fs5 = await import("fs");
948
955
  const configPath = await findConfigFile();
949
956
  if (!configPath) {
950
957
  throw new ConfigError(
@@ -952,7 +959,7 @@ async function readProjectConfig() {
952
959
  );
953
960
  }
954
961
  try {
955
- const configContent = fs4.readFileSync(configPath, "utf-8");
962
+ const configContent = fs5.readFileSync(configPath, "utf-8");
956
963
  const config = toml.parse(configContent);
957
964
  return config;
958
965
  } catch (error) {
@@ -1190,7 +1197,7 @@ var standaloneUtils, initPromise, toClientConfig;
1190
1197
  var init_standalone = __esm({
1191
1198
  "src/consumption-apis/standalone.ts"() {
1192
1199
  "use strict";
1193
- init_helpers();
1200
+ init_helpers2();
1194
1201
  init_commons();
1195
1202
  init_sqlHelpers();
1196
1203
  standaloneUtils = null;
@@ -1203,13 +1210,13 @@ var init_standalone = __esm({
1203
1210
  });
1204
1211
 
1205
1212
  // src/consumption-apis/runner.ts
1206
- var import_http2, jose, toClientConfig2, httpLogger, modulesCache, apiHandler, createMainRouter, runApis;
1213
+ var import_http2, jose, toClientConfig2, createPath, httpLogger, modulesCache, apiHandler, createMainRouter, runApis;
1207
1214
  var init_runner = __esm({
1208
1215
  "src/consumption-apis/runner.ts"() {
1209
1216
  "use strict";
1210
1217
  import_http2 = __toESM(require("http"));
1211
1218
  init_commons();
1212
- init_helpers();
1219
+ init_helpers2();
1213
1220
  jose = __toESM(require("jose"));
1214
1221
  init_cluster_utils();
1215
1222
  init_sqlHelpers();
@@ -1218,14 +1225,15 @@ var init_runner = __esm({
1218
1225
  ...config,
1219
1226
  useSSL: config.useSSL ? "true" : "false"
1220
1227
  });
1228
+ createPath = (apisDir, path5) => `${apisDir}${path5}.ts`;
1221
1229
  httpLogger = (req, res, startMs) => {
1222
1230
  console.log(
1223
1231
  `${req.method} ${req.url} ${res.statusCode} ${Date.now() - startMs}ms`
1224
1232
  );
1225
1233
  };
1226
1234
  modulesCache = /* @__PURE__ */ new Map();
1227
- apiHandler = async (publicKey, clickhouseClient, temporalClient, enforceAuth, jwtConfig) => {
1228
- const apis = await getApis2();
1235
+ apiHandler = async (publicKey, clickhouseClient, temporalClient, apisDir, enforceAuth, isDmv2, jwtConfig) => {
1236
+ const apis = isDmv2 ? await getApis2() : /* @__PURE__ */ new Map();
1229
1237
  return async (req, res) => {
1230
1238
  const start = Date.now();
1231
1239
  try {
@@ -1262,6 +1270,7 @@ var init_runner = __esm({
1262
1270
  httpLogger(req, res, start);
1263
1271
  return;
1264
1272
  }
1273
+ const pathName = createPath(apisDir, fileName);
1265
1274
  const paramsObject = Array.from(url.searchParams.entries()).reduce(
1266
1275
  (obj, [key, value]) => {
1267
1276
  const existingValue = obj[key];
@@ -1278,44 +1287,53 @@ var init_runner = __esm({
1278
1287
  },
1279
1288
  {}
1280
1289
  );
1281
- let userFuncModule = modulesCache.get(fileName);
1290
+ let userFuncModule = modulesCache.get(pathName);
1282
1291
  if (userFuncModule === void 0) {
1283
- let apiName = fileName.replace(/^\/+|\/+$/g, "");
1284
- let version = null;
1285
- userFuncModule = apis.get(apiName);
1286
- if (!userFuncModule) {
1287
- version = url.searchParams.get("version");
1288
- if (!version && apiName.includes("/")) {
1289
- const pathParts = apiName.split("/");
1290
- if (pathParts.length >= 2) {
1291
- userFuncModule = apis.get(apiName);
1292
- if (!userFuncModule) {
1293
- apiName = pathParts[0];
1294
- version = pathParts.slice(1).join("/");
1292
+ if (isDmv2) {
1293
+ let apiName = fileName.replace(/^\/+|\/+$/g, "");
1294
+ let version = null;
1295
+ userFuncModule = apis.get(apiName);
1296
+ if (!userFuncModule) {
1297
+ version = url.searchParams.get("version");
1298
+ if (!version && apiName.includes("/")) {
1299
+ const pathParts = apiName.split("/");
1300
+ if (pathParts.length >= 2) {
1301
+ userFuncModule = apis.get(apiName);
1302
+ if (!userFuncModule) {
1303
+ apiName = pathParts[0];
1304
+ version = pathParts.slice(1).join("/");
1305
+ }
1306
+ }
1307
+ }
1308
+ if (!userFuncModule) {
1309
+ if (version) {
1310
+ const versionedKey = `${apiName}:${version}`;
1311
+ userFuncModule = apis.get(versionedKey);
1312
+ } else {
1313
+ userFuncModule = apis.get(apiName);
1295
1314
  }
1296
1315
  }
1297
1316
  }
1298
1317
  if (!userFuncModule) {
1299
- if (version) {
1300
- const versionedKey = `${apiName}:${version}`;
1301
- userFuncModule = apis.get(versionedKey);
1302
- } else {
1303
- userFuncModule = apis.get(apiName);
1304
- }
1318
+ const availableApis = Array.from(apis.keys()).map(
1319
+ (key) => key.replace(":", "/")
1320
+ );
1321
+ const errorMessage = version ? `API ${apiName} with version ${version} not found. Available APIs: ${availableApis.join(", ")}` : `API ${apiName} not found. Available APIs: ${availableApis.join(", ")}`;
1322
+ throw new Error(errorMessage);
1305
1323
  }
1324
+ modulesCache.set(pathName, userFuncModule);
1325
+ console.log(`[API] | Executing API: ${apiName}`);
1326
+ } else {
1327
+ userFuncModule = require(pathName);
1328
+ modulesCache.set(pathName, userFuncModule);
1306
1329
  }
1307
- if (!userFuncModule) {
1308
- const availableApis = Array.from(apis.keys()).map(
1309
- (key) => key.replace(":", "/")
1310
- );
1311
- const errorMessage = version ? `API ${apiName} with version ${version} not found. Available APIs: ${availableApis.join(", ")}` : `API ${apiName} not found. Available APIs: ${availableApis.join(", ")}`;
1312
- throw new Error(errorMessage);
1313
- }
1314
- modulesCache.set(fileName, userFuncModule);
1315
- console.log(`[API] | Executing API: ${apiName}`);
1316
1330
  }
1317
1331
  const queryClient = new QueryClient(clickhouseClient, fileName);
1318
- let result = await userFuncModule(paramsObject, {
1332
+ let result = isDmv2 ? await userFuncModule(paramsObject, {
1333
+ client: new MooseClient(queryClient, temporalClient),
1334
+ sql,
1335
+ jwt: jwtPayload
1336
+ }) : await userFuncModule.default(paramsObject, {
1319
1337
  client: new MooseClient(queryClient, temporalClient),
1320
1338
  sql,
1321
1339
  jwt: jwtPayload
@@ -1359,15 +1377,17 @@ var init_runner = __esm({
1359
1377
  }
1360
1378
  };
1361
1379
  };
1362
- createMainRouter = async (publicKey, clickhouseClient, temporalClient, enforceAuth, jwtConfig) => {
1380
+ createMainRouter = async (publicKey, clickhouseClient, temporalClient, apisDir, enforceAuth, isDmv2, jwtConfig) => {
1363
1381
  const apiRequestHandler = await apiHandler(
1364
1382
  publicKey,
1365
1383
  clickhouseClient,
1366
1384
  temporalClient,
1385
+ apisDir,
1367
1386
  enforceAuth,
1387
+ isDmv2,
1368
1388
  jwtConfig
1369
1389
  );
1370
- const webApps = await getWebApps2();
1390
+ const webApps = isDmv2 ? await getWebApps2() : /* @__PURE__ */ new Map();
1371
1391
  const sortedWebApps = Array.from(webApps.values()).sort((a, b) => {
1372
1392
  const pathA = a.config.mountPath || "/";
1373
1393
  const pathB = b.config.mountPath || "/";
@@ -1489,7 +1509,9 @@ var init_runner = __esm({
1489
1509
  publicKey,
1490
1510
  clickhouseClient,
1491
1511
  temporalClient,
1512
+ config.apisDir,
1492
1513
  config.enforceAuth,
1514
+ config.isDmv2,
1493
1515
  config.jwtConfig
1494
1516
  )
1495
1517
  );
@@ -1688,14 +1710,15 @@ var init_index = __esm({
1688
1710
  "src/index.ts"() {
1689
1711
  "use strict";
1690
1712
  init_browserCompatible();
1713
+ init_helpers();
1691
1714
  init_commons();
1692
1715
  init_secrets();
1693
- init_helpers();
1716
+ init_helpers2();
1694
1717
  init_webAppHelpers();
1695
1718
  init_task();
1696
1719
  init_runner();
1697
1720
  init_redisClient();
1698
- init_helpers();
1721
+ init_helpers2();
1699
1722
  init_standalone();
1700
1723
  init_sqlHelpers();
1701
1724
  init_utilities();
@@ -2411,6 +2434,117 @@ var init_internal = __esm({
2411
2434
  // src/moose-runner.ts
2412
2435
  var import_ts_node = require("ts-node");
2413
2436
  init_internal();
2437
+
2438
+ // src/blocks/runner.ts
2439
+ var import_fastq = __toESM(require("fastq"));
2440
+ init_commons();
2441
+ var import_node_fs = __toESM(require("fs"));
2442
+ var import_node_path2 = __toESM(require("path"));
2443
+ var walkDir = (dir, fileExtension, fileList) => {
2444
+ const files = import_node_fs.default.readdirSync(dir);
2445
+ files.forEach((file) => {
2446
+ if (import_node_fs.default.statSync(import_node_path2.default.join(dir, file)).isDirectory()) {
2447
+ fileList = walkDir(import_node_path2.default.join(dir, file), fileExtension, fileList);
2448
+ } else if (file.endsWith(fileExtension)) {
2449
+ fileList.push(import_node_path2.default.join(dir, file));
2450
+ }
2451
+ });
2452
+ return fileList;
2453
+ };
2454
+ var DependencyError = class extends Error {
2455
+ constructor(message) {
2456
+ super(message);
2457
+ this.name = "DependencyError";
2458
+ }
2459
+ };
2460
+ var toClientConfig3 = (config) => ({
2461
+ ...config,
2462
+ useSSL: config.useSSL ? "true" : "false"
2463
+ });
2464
+ var createBlocks = async (chClient, blocks) => {
2465
+ for (const query of blocks.setup) {
2466
+ try {
2467
+ console.log(`Creating block using query ${query}`);
2468
+ await chClient.command({
2469
+ query,
2470
+ clickhouse_settings: {
2471
+ wait_end_of_query: 1
2472
+ // Ensure at least once delivery and DDL acknowledgment
2473
+ }
2474
+ });
2475
+ } catch (err) {
2476
+ cliLog({
2477
+ action: "Blocks",
2478
+ message: `Failed to create blocks: ${err}`,
2479
+ message_type: "Error"
2480
+ });
2481
+ if (err && JSON.stringify(err).includes(`UNKNOWN_TABLE`)) {
2482
+ throw new DependencyError(err.toString());
2483
+ }
2484
+ }
2485
+ }
2486
+ };
2487
+ var deleteBlocks = async (chClient, blocks) => {
2488
+ for (const query of blocks.teardown) {
2489
+ try {
2490
+ console.log(`Deleting block using query ${query}`);
2491
+ await chClient.command({
2492
+ query,
2493
+ clickhouse_settings: {
2494
+ wait_end_of_query: 1
2495
+ // Ensure at least once delivery and DDL acknowledgment
2496
+ }
2497
+ });
2498
+ } catch (err) {
2499
+ cliLog({
2500
+ action: "Blocks",
2501
+ message: `Failed to delete blocks: ${err}`,
2502
+ message_type: "Error"
2503
+ });
2504
+ }
2505
+ }
2506
+ };
2507
+ var asyncWorker = async (task) => {
2508
+ await deleteBlocks(task.chClient, task.blocks);
2509
+ await createBlocks(task.chClient, task.blocks);
2510
+ };
2511
+ var runBlocks = async (config) => {
2512
+ const chClient = getClickhouseClient(toClientConfig3(config.clickhouseConfig));
2513
+ console.log(`Connected`);
2514
+ const blocksFiles = walkDir(config.blocksDir, ".ts", []);
2515
+ const numOfBlockFiles = blocksFiles.length;
2516
+ console.log(`Found ${numOfBlockFiles} blocks files`);
2517
+ const queue = import_fastq.default.promise(asyncWorker, 1);
2518
+ queue.error((err, task) => {
2519
+ if (err && task.retries > 0) {
2520
+ if (err instanceof DependencyError) {
2521
+ queue.push({ ...task, retries: task.retries - 1 });
2522
+ }
2523
+ }
2524
+ });
2525
+ for (const path5 of blocksFiles) {
2526
+ console.log(`Adding to queue: ${path5}`);
2527
+ try {
2528
+ const blocks = require(path5).default;
2529
+ queue.push({
2530
+ chClient,
2531
+ blocks,
2532
+ retries: numOfBlockFiles
2533
+ });
2534
+ } catch (err) {
2535
+ cliLog({
2536
+ action: "Blocks",
2537
+ message: `Failed to import blocks from ${path5}: ${err}`,
2538
+ message_type: "Error"
2539
+ });
2540
+ }
2541
+ }
2542
+ while (!queue.idle()) {
2543
+ await new Promise((resolve3) => setTimeout(resolve3, 1e3));
2544
+ }
2545
+ };
2546
+
2547
+ // src/moose-runner.ts
2414
2548
  init_runner();
2415
2549
 
2416
2550
  // src/streaming-functions/runner.ts
@@ -2695,7 +2829,17 @@ var sendMessageMetrics = (logger2, metrics) => {
2695
2829
  metrics.count_out = 0;
2696
2830
  setTimeout(() => sendMessageMetrics(logger2, metrics), 1e3);
2697
2831
  };
2698
- async function loadStreamingFunction(sourceTopic, targetTopic) {
2832
+ function loadStreamingFunction(functionFilePath) {
2833
+ let streamingFunctionImport;
2834
+ try {
2835
+ streamingFunctionImport = require(functionFilePath.substring(0, functionFilePath.length - 3));
2836
+ } catch (e) {
2837
+ cliLog({ action: "Function", message: `${e}`, message_type: "Error" });
2838
+ throw e;
2839
+ }
2840
+ return streamingFunctionImport.default;
2841
+ }
2842
+ async function loadStreamingFunctionV2(sourceTopic, targetTopic) {
2699
2843
  const transformFunctions = await getStreamingFunctions();
2700
2844
  const transformFunctionKey = `${topicNameToStreamName(sourceTopic)}_${targetTopic ? topicNameToStreamName(targetTopic) : "<no-target>"}`;
2701
2845
  const matchingEntries = Array.from(transformFunctions.entries()).filter(
@@ -2740,12 +2884,17 @@ var startConsumer = async (args, logger2, metrics, _parallelism, consumer, produ
2740
2884
  );
2741
2885
  let streamingFunctions;
2742
2886
  let fieldMutations;
2743
- const result = await loadStreamingFunction(
2744
- args.sourceTopic,
2745
- args.targetTopic
2746
- );
2747
- streamingFunctions = result.functions;
2748
- fieldMutations = result.fieldMutations;
2887
+ if (args.isDmv2) {
2888
+ const result = await loadStreamingFunctionV2(
2889
+ args.sourceTopic,
2890
+ args.targetTopic
2891
+ );
2892
+ streamingFunctions = result.functions;
2893
+ fieldMutations = result.fieldMutations;
2894
+ } else {
2895
+ streamingFunctions = [[loadStreamingFunction(args.functionFilePath), {}]];
2896
+ fieldMutations = void 0;
2897
+ }
2749
2898
  await consumer.subscribe({
2750
2899
  topics: [args.sourceTopic.name]
2751
2900
  // Use full topic name for Kafka operations
@@ -2979,8 +3128,8 @@ async function runApiTypeSerializer(targetModel) {
2979
3128
 
2980
3129
  // src/scripts/runner.ts
2981
3130
  var import_worker2 = require("@temporalio/worker");
2982
- var path3 = __toESM(require("path"));
2983
- var fs3 = __toESM(require("fs"));
3131
+ var path4 = __toESM(require("path"));
3132
+ var fs4 = __toESM(require("fs"));
2984
3133
  init_internal();
2985
3134
 
2986
3135
  // src/scripts/activity.ts
@@ -2989,7 +3138,7 @@ var import_workflow3 = require("@temporalio/workflow");
2989
3138
  init_internal();
2990
3139
  init_json();
2991
3140
  var activities = {
2992
- async hasWorkflow(name) {
3141
+ async hasDmv2Workflow(name) {
2993
3142
  try {
2994
3143
  const workflows = await getWorkflows2();
2995
3144
  const hasWorkflow = workflows.has(name);
@@ -3000,7 +3149,7 @@ var activities = {
3000
3149
  return false;
3001
3150
  }
3002
3151
  },
3003
- async getWorkflowByName(name) {
3152
+ async getDmv2Workflow(name) {
3004
3153
  try {
3005
3154
  import_activity.log.info(`Getting workflow ${name}`);
3006
3155
  const workflows = await getWorkflows2();
@@ -3045,7 +3194,7 @@ var activities = {
3045
3194
  throw new Error(errorMsg);
3046
3195
  }
3047
3196
  },
3048
- async executeTask(workflow, task, inputData) {
3197
+ async executeDmv2Task(workflow, task, inputData) {
3049
3198
  const context = import_activity.Context.current();
3050
3199
  const taskState = {};
3051
3200
  let heartbeatInterval = null;
@@ -3106,7 +3255,7 @@ var activities = {
3106
3255
  };
3107
3256
  function createActivityForScript(scriptName) {
3108
3257
  return {
3109
- [scriptName]: activities.executeTask
3258
+ [scriptName]: activities.executeDmv2Task
3110
3259
  };
3111
3260
  }
3112
3261
 
@@ -3144,12 +3293,12 @@ var initializeLogger = LoggerSingleton.initializeLogger;
3144
3293
 
3145
3294
  // src/scripts/runner.ts
3146
3295
  var ALREADY_REGISTERED = /* @__PURE__ */ new Set();
3147
- function collectActivities(logger2, workflows) {
3148
- logger2.info(`<WF> Collecting tasks from workflows`);
3296
+ function collectActivitiesDmv2(logger2, workflows) {
3297
+ logger2.info(`<DMV2WF> Collecting tasks from dmv2 workflows`);
3149
3298
  const scriptNames = [];
3150
3299
  for (const [name, workflow] of workflows.entries()) {
3151
3300
  logger2.info(
3152
- `<WF> Registering workflow: ${name} with starting task: ${workflow.config.startingTask.name}`
3301
+ `<DMV2WF> Registering dmv2 workflow: ${name} with starting task: ${workflow.config.startingTask.name}`
3153
3302
  );
3154
3303
  scriptNames.push(`${name}/${workflow.config.startingTask.name}`);
3155
3304
  }
@@ -3164,8 +3313,8 @@ async function createTemporalConnection(logger2, temporalConfig) {
3164
3313
  };
3165
3314
  if (temporalConfig.clientCert && temporalConfig.clientKey) {
3166
3315
  logger2.info("Using TLS for secure Temporal");
3167
- const cert = await fs3.readFileSync(temporalConfig.clientCert);
3168
- const key = await fs3.readFileSync(temporalConfig.clientKey);
3316
+ const cert = await fs4.readFileSync(temporalConfig.clientCert);
3317
+ const key = await fs4.readFileSync(temporalConfig.clientKey);
3169
3318
  connectionOptions.tls = {
3170
3319
  clientCertPair: {
3171
3320
  crt: cert,
@@ -3212,27 +3361,29 @@ async function registerWorkflows(logger2, config) {
3212
3361
  try {
3213
3362
  const workflows = await getWorkflows2();
3214
3363
  if (workflows.size > 0) {
3215
- logger2.info(`<WF> Found ${workflows.size} workflows`);
3216
- allScriptPaths.push(...collectActivities(logger2, workflows));
3364
+ logger2.info(`<DMV2WF> Found ${workflows.size} dmv2 workflows`);
3365
+ allScriptPaths.push(...collectActivitiesDmv2(logger2, workflows));
3217
3366
  if (allScriptPaths.length === 0) {
3218
- logger2.info(`<WF> No tasks found in workflows`);
3367
+ logger2.info(`<DMV2WF> No tasks found in dmv2 workflows`);
3219
3368
  return null;
3220
3369
  }
3221
- logger2.info(`<WF> Found ${allScriptPaths.length} tasks in workflows`);
3370
+ logger2.info(
3371
+ `<DMV2WF> Found ${allScriptPaths.length} tasks in dmv2 workflows`
3372
+ );
3222
3373
  for (const activityName of allScriptPaths) {
3223
3374
  if (!ALREADY_REGISTERED.has(activityName)) {
3224
3375
  const activity = await createActivityForScript(activityName);
3225
3376
  dynamicActivities.push(activity);
3226
3377
  ALREADY_REGISTERED.add(activityName);
3227
- logger2.info(`<WF> Registered task ${activityName}`);
3378
+ logger2.info(`<DMV2WF> Registered task ${activityName}`);
3228
3379
  }
3229
3380
  }
3230
3381
  if (dynamicActivities.length === 0) {
3231
- logger2.info(`<WF> No dynamic activities found in workflows`);
3382
+ logger2.info(`<DMV2WF> No dynamic activities found in dmv2 workflows`);
3232
3383
  return null;
3233
3384
  }
3234
3385
  logger2.info(
3235
- `<WF> Found ${dynamicActivities.length} dynamic activities in workflows`
3386
+ `<DMV2WF> Found ${dynamicActivities.length} dynamic activities in dmv2 workflows`
3236
3387
  );
3237
3388
  }
3238
3389
  if (allScriptPaths.length === 0) {
@@ -3270,7 +3421,7 @@ async function registerWorkflows(logger2, config) {
3270
3421
  }
3271
3422
  };
3272
3423
  const workflowBundle = await (0, import_worker2.bundleWorkflowCode)({
3273
- workflowsPath: path3.resolve(__dirname, "scripts/workflow.js"),
3424
+ workflowsPath: path4.resolve(__dirname, "scripts/workflow.js"),
3274
3425
  logger: silentLogger
3275
3426
  });
3276
3427
  const worker = await import_worker2.Worker.create({
@@ -3385,17 +3536,33 @@ program.command("dmv2-serializer").description("Load DMv2 index").action(() => {
3385
3536
  program.command("export-serializer").description("Run export serializer").argument("<target-model>", "Target model to serialize").action((targetModel) => {
3386
3537
  runExportSerializer(targetModel);
3387
3538
  });
3388
- program.command("consumption-apis").description("Run consumption APIs").argument("<clickhouse-db>", "Clickhouse database name").argument("<clickhouse-host>", "Clickhouse host").argument("<clickhouse-port>", "Clickhouse port").argument("<clickhouse-username>", "Clickhouse username").argument("<clickhouse-password>", "Clickhouse password").option("--clickhouse-use-ssl", "Use SSL for Clickhouse connection", false).option("--jwt-secret <secret>", "JWT public key for verification").option("--jwt-issuer <issuer>", "Expected JWT issuer").option("--jwt-audience <audience>", "Expected JWT audience").option(
3539
+ program.command("blocks").description("Run blocks").argument("<blocks-dir>", "Directory containing blocks").argument("<clickhouse-db>", "Clickhouse database name").argument("<clickhouse-host>", "Clickhouse host").argument("<clickhouse-port>", "Clickhouse port").argument("<clickhouse-username>", "Clickhouse username").argument("<clickhouse-password>", "Clickhouse password").option("--clickhouse-use-ssl", "Use SSL for Clickhouse connection", false).action(
3540
+ (blocksDir, clickhouseDb, clickhouseHost, clickhousePort, clickhouseUsername, clickhousePassword, options) => {
3541
+ runBlocks({
3542
+ blocksDir,
3543
+ clickhouseConfig: {
3544
+ database: clickhouseDb,
3545
+ host: clickhouseHost,
3546
+ port: clickhousePort,
3547
+ username: clickhouseUsername,
3548
+ password: clickhousePassword,
3549
+ useSSL: options.clickhouseUseSsl
3550
+ }
3551
+ });
3552
+ }
3553
+ );
3554
+ program.command("consumption-apis").description("Run consumption APIs").argument("<consumption-dir>", "Directory containing consumption APIs").argument("<clickhouse-db>", "Clickhouse database name").argument("<clickhouse-host>", "Clickhouse host").argument("<clickhouse-port>", "Clickhouse port").argument("<clickhouse-username>", "Clickhouse username").argument("<clickhouse-password>", "Clickhouse password").option("--clickhouse-use-ssl", "Use SSL for Clickhouse connection", false).option("--jwt-secret <secret>", "JWT public key for verification").option("--jwt-issuer <issuer>", "Expected JWT issuer").option("--jwt-audience <audience>", "Expected JWT audience").option(
3389
3555
  "--enforce-auth",
3390
3556
  "Enforce authentication on all consumption APIs",
3391
3557
  false
3392
- ).option("--temporal-url <url>", "Temporal server URL").option("--temporal-namespace <namespace>", "Temporal namespace").option("--client-cert <path>", "Path to client certificate").option("--client-key <path>", "Path to client key").option("--api-key <key>", "API key for authentication").option("--proxy-port <port>", "Port to run the proxy server on", parseInt).option(
3558
+ ).option("--temporal-url <url>", "Temporal server URL").option("--temporal-namespace <namespace>", "Temporal namespace").option("--client-cert <path>", "Path to client certificate").option("--client-key <path>", "Path to client key").option("--api-key <key>", "API key for authentication").option("--is-dmv2", "Whether this is a DMv2 consumption", false).option("--proxy-port <port>", "Port to run the proxy server on", parseInt).option(
3393
3559
  "--worker-count <count>",
3394
3560
  "Number of worker processes for the consumption API cluster",
3395
3561
  parseInt
3396
3562
  ).action(
3397
- (clickhouseDb, clickhouseHost, clickhousePort, clickhouseUsername, clickhousePassword, options) => {
3563
+ (apisDir, clickhouseDb, clickhouseHost, clickhousePort, clickhouseUsername, clickhousePassword, options) => {
3398
3564
  runApis({
3565
+ apisDir,
3399
3566
  clickhouseConfig: {
3400
3567
  database: clickhouseDb,
3401
3568
  host: clickhouseHost,
@@ -3417,6 +3584,7 @@ program.command("consumption-apis").description("Run consumption APIs").argument
3417
3584
  apiKey: options.apiKey
3418
3585
  },
3419
3586
  enforceAuth: options.enforceAuth,
3587
+ isDmv2: options.isDmv2,
3420
3588
  proxyPort: options.proxyPort,
3421
3589
  workerCount: options.workerCount
3422
3590
  });
@@ -3425,7 +3593,7 @@ program.command("consumption-apis").description("Run consumption APIs").argument
3425
3593
  program.command("streaming-functions").description("Run streaming functions").argument("<source-topic>", "Source topic configuration as JSON").argument("<function-file-path>", "Path to the function file").argument(
3426
3594
  "<broker>",
3427
3595
  "Kafka broker address(es) - comma-separated for multiple brokers (e.g., 'broker1:9092, broker2:9092'). Whitespace around commas is automatically trimmed."
3428
- ).argument("<max-subscriber-count>", "Maximum number of subscribers").option("--target-topic <target-topic>", "Target topic configuration as JSON").option("--sasl-username <username>", "SASL username").option("--sasl-password <password>", "SASL password").option("--sasl-mechanism <mechanism>", "SASL mechanism").option("--security-protocol <protocol>", "Security protocol").option("--log-payloads", "Log payloads for debugging", false).action(
3596
+ ).argument("<max-subscriber-count>", "Maximum number of subscribers").option("--target-topic <target-topic>", "Target topic configuration as JSON").option("--sasl-username <username>", "SASL username").option("--sasl-password <password>", "SASL password").option("--sasl-mechanism <mechanism>", "SASL mechanism").option("--security-protocol <protocol>", "Security protocol").option("--is-dmv2", "Whether this is a DMv2 function", false).option("--log-payloads", "Log payloads for debugging", false).action(
3429
3597
  (sourceTopic, functionFilePath, broker, maxSubscriberCount, options) => {
3430
3598
  const config = {
3431
3599
  sourceTopic: JSON.parse(sourceTopic),
@@ -3433,6 +3601,7 @@ program.command("streaming-functions").description("Run streaming functions").ar
3433
3601
  functionFilePath,
3434
3602
  broker,
3435
3603
  maxSubscriberCount: parseInt(maxSubscriberCount),
3604
+ isDmv2: options.isDmv2,
3436
3605
  logPayloads: options.logPayloads,
3437
3606
  saslUsername: options.saslUsername,
3438
3607
  saslPassword: options.saslPassword,