@514labs/moose-lib 0.6.256-ci-4-g0ca62054 → 0.6.256-ci-3-gafce5840

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.mjs CHANGED
@@ -26,7 +26,6 @@ __export(commons_exports, {
26
26
  antiCachePath: () => antiCachePath,
27
27
  cliLog: () => cliLog,
28
28
  compilerLog: () => compilerLog,
29
- createProducerConfig: () => createProducerConfig,
30
29
  getClickhouseClient: () => getClickhouseClient,
31
30
  getFileName: () => getFileName,
32
31
  getKafkaClient: () => getKafkaClient,
@@ -52,25 +51,18 @@ function isTruthy(value) {
52
51
  function mapTstoJs(filePath) {
53
52
  return filePath.replace(/\.ts$/, ".js").replace(/\.cts$/, ".cjs").replace(/\.mts$/, ".mjs");
54
53
  }
55
- function createProducerConfig(maxMessageBytes) {
56
- return {
54
+ async function getKafkaProducer(cfg, logger) {
55
+ const kafka = await getKafkaClient(cfg, logger);
56
+ const producer = kafka.producer({
57
57
  kafkaJS: {
58
- idempotent: false,
59
- // Not needed for at-least-once delivery
58
+ idempotent: true,
60
59
  acks: ACKs,
61
60
  retry: {
62
61
  retries: MAX_RETRIES_PRODUCER,
63
62
  maxRetryTime: MAX_RETRY_TIME_MS
64
63
  }
65
- },
66
- "linger.ms": 0,
67
- // This is to make sure at least once delivery with immediate feedback on the send
68
- ...maxMessageBytes && { "message.max.bytes": maxMessageBytes }
69
- };
70
- }
71
- async function getKafkaProducer(cfg, logger, maxMessageBytes) {
72
- const kafka = await getKafkaClient(cfg, logger);
73
- const producer = kafka.producer(createProducerConfig(maxMessageBytes));
64
+ }
65
+ });
74
66
  await producer.connect();
75
67
  return producer;
76
68
  }
@@ -654,7 +646,9 @@ var moose_internal = {
654
646
  apis: /* @__PURE__ */ new Map(),
655
647
  sqlResources: /* @__PURE__ */ new Map(),
656
648
  workflows: /* @__PURE__ */ new Map(),
657
- webApps: /* @__PURE__ */ new Map()
649
+ webApps: /* @__PURE__ */ new Map(),
650
+ materializedViews: /* @__PURE__ */ new Map(),
651
+ customViews: /* @__PURE__ */ new Map()
658
652
  };
659
653
  var defaultRetentionPeriod = 60 * 60 * 24 * 7;
660
654
  var getMooseInternal = () => globalThis.moose_internal;
@@ -670,6 +664,8 @@ var loadIndex = () => {
670
664
  registry.sqlResources.clear();
671
665
  registry.workflows.clear();
672
666
  registry.webApps.clear();
667
+ registry.materializedViews.clear();
668
+ registry.customViews.clear();
673
669
  const appDir = `${process2.cwd()}/${getSourceDir()}`;
674
670
  Object.keys(__require.cache).forEach((key) => {
675
671
  if (key.startsWith(appDir)) {
@@ -2303,6 +2299,67 @@ var ETLPipeline = class {
2303
2299
  }
2304
2300
  };
2305
2301
 
2302
+ // src/dmv2/sdk/materializedView.ts
2303
+ var requireTargetTableName = (tableName) => {
2304
+ if (typeof tableName === "string") {
2305
+ return tableName;
2306
+ } else {
2307
+ throw new Error("Name of targetTable is not specified.");
2308
+ }
2309
+ };
2310
+ var MaterializedView = class {
2311
+ /** @internal */
2312
+ kind = "MaterializedView";
2313
+ /** The name of the materialized view */
2314
+ name;
2315
+ /** The target OlapTable instance where the materialized data is stored. */
2316
+ targetTable;
2317
+ /** The SELECT SQL statement */
2318
+ selectSql;
2319
+ /** Names of source tables that the SELECT reads from */
2320
+ sourceTables;
2321
+ /** @internal Source file path where this MV was defined */
2322
+ sourceFile;
2323
+ constructor(options, targetSchema, targetColumns) {
2324
+ let selectStatement = options.selectStatement;
2325
+ if (typeof selectStatement !== "string") {
2326
+ selectStatement = toStaticQuery(selectStatement);
2327
+ }
2328
+ if (targetSchema === void 0 || targetColumns === void 0) {
2329
+ throw new Error(
2330
+ "Supply the type param T so that the schema is inserted by the compiler plugin."
2331
+ );
2332
+ }
2333
+ const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2334
+ requireTargetTableName(
2335
+ options.targetTable?.name ?? options.tableName
2336
+ ),
2337
+ {
2338
+ orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2339
+ engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2340
+ },
2341
+ targetSchema,
2342
+ targetColumns
2343
+ );
2344
+ if (targetTable.name === options.materializedViewName) {
2345
+ throw new Error(
2346
+ "Materialized view name cannot be the same as the target table name."
2347
+ );
2348
+ }
2349
+ this.name = options.materializedViewName;
2350
+ this.targetTable = targetTable;
2351
+ this.selectSql = selectStatement;
2352
+ this.sourceTables = options.selectTables.map((t) => t.name);
2353
+ const stack = new Error().stack;
2354
+ this.sourceFile = getSourceFileFromStack(stack);
2355
+ const materializedViews = getMooseInternal().materializedViews;
2356
+ if (!isClientOnlyMode() && materializedViews.has(this.name)) {
2357
+ throw new Error(`MaterializedView with name ${this.name} already exists`);
2358
+ }
2359
+ materializedViews.set(this.name, this);
2360
+ }
2361
+ };
2362
+
2306
2363
  // src/dmv2/sdk/sqlResource.ts
2307
2364
  var SqlResource = class {
2308
2365
  /** @internal */
@@ -2348,66 +2405,18 @@ var SqlResource = class {
2348
2405
  }
2349
2406
  };
2350
2407
 
2351
- // src/dmv2/sdk/materializedView.ts
2352
- var requireTargetTableName = (tableName) => {
2353
- if (typeof tableName === "string") {
2354
- return tableName;
2355
- } else {
2356
- throw new Error("Name of targetTable is not specified.");
2357
- }
2358
- };
2359
- var MaterializedView = class extends SqlResource {
2360
- /** The target OlapTable instance where the materialized data is stored. */
2361
- targetTable;
2362
- constructor(options, targetSchema, targetColumns) {
2363
- let selectStatement = options.selectStatement;
2364
- if (typeof selectStatement !== "string") {
2365
- selectStatement = toStaticQuery(selectStatement);
2366
- }
2367
- if (targetSchema === void 0 || targetColumns === void 0) {
2368
- throw new Error(
2369
- "Supply the type param T so that the schema is inserted by the compiler plugin."
2370
- );
2371
- }
2372
- const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2373
- requireTargetTableName(
2374
- options.targetTable?.name ?? options.tableName
2375
- ),
2376
- {
2377
- orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2378
- engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2379
- },
2380
- targetSchema,
2381
- targetColumns
2382
- );
2383
- if (targetTable.name === options.materializedViewName) {
2384
- throw new Error(
2385
- "Materialized view name cannot be the same as the target table name."
2386
- );
2387
- }
2388
- super(
2389
- options.materializedViewName,
2390
- [
2391
- createMaterializedView({
2392
- name: options.materializedViewName,
2393
- destinationTable: targetTable.name,
2394
- select: selectStatement
2395
- })
2396
- // Population is now handled automatically by Rust infrastructure
2397
- // based on table engine type and whether this is a new or updated view
2398
- ],
2399
- [dropView(options.materializedViewName)],
2400
- {
2401
- pullsDataFrom: options.selectTables,
2402
- pushesDataTo: [targetTable]
2403
- }
2404
- );
2405
- this.targetTable = targetTable;
2406
- }
2407
- };
2408
-
2409
2408
  // src/dmv2/sdk/view.ts
2410
- var View = class extends SqlResource {
2409
+ var View = class {
2410
+ /** @internal */
2411
+ kind = "CustomView";
2412
+ /** The name of the view */
2413
+ name;
2414
+ /** The SELECT SQL statement that defines the view */
2415
+ selectSql;
2416
+ /** Names of source tables/views that the SELECT reads from */
2417
+ sourceTables;
2418
+ /** @internal Source file path where this view was defined */
2419
+ sourceFile;
2411
2420
  /**
2412
2421
  * Creates a new View instance.
2413
2422
  * @param name The name of the view to be created.
@@ -2418,17 +2427,16 @@ var View = class extends SqlResource {
2418
2427
  if (typeof selectStatement !== "string") {
2419
2428
  selectStatement = toStaticQuery(selectStatement);
2420
2429
  }
2421
- super(
2422
- name,
2423
- [
2424
- `CREATE VIEW IF NOT EXISTS ${name}
2425
- AS ${selectStatement}`.trim()
2426
- ],
2427
- [dropView(name)],
2428
- {
2429
- pullsDataFrom: baseTables
2430
- }
2431
- );
2430
+ this.name = name;
2431
+ this.selectSql = selectStatement;
2432
+ this.sourceTables = baseTables.map((t) => t.name);
2433
+ const stack = new Error().stack;
2434
+ this.sourceFile = getSourceFileFromStack(stack);
2435
+ const customViews = getMooseInternal().customViews;
2436
+ if (!isClientOnlyMode() && customViews.has(this.name)) {
2437
+ throw new Error(`View with name ${this.name} already exists`);
2438
+ }
2439
+ customViews.set(this.name, this);
2432
2440
  }
2433
2441
  };
2434
2442
 
@@ -3312,7 +3320,6 @@ export {
3312
3320
  createClickhouseParameter,
3313
3321
  createConsumptionApi,
3314
3322
  createMaterializedView,
3315
- createProducerConfig,
3316
3323
  dropView,
3317
3324
  expressMiddleware,
3318
3325
  getApi,