@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.
@@ -20,7 +20,6 @@ __export(commons_exports, {
20
20
  antiCachePath: () => antiCachePath,
21
21
  cliLog: () => cliLog,
22
22
  compilerLog: () => compilerLog,
23
- createProducerConfig: () => createProducerConfig,
24
23
  getClickhouseClient: () => getClickhouseClient,
25
24
  getFileName: () => getFileName,
26
25
  getKafkaClient: () => getKafkaClient,
@@ -46,25 +45,18 @@ function isTruthy(value) {
46
45
  function mapTstoJs(filePath) {
47
46
  return filePath.replace(/\.ts$/, ".js").replace(/\.cts$/, ".cjs").replace(/\.mts$/, ".mjs");
48
47
  }
49
- function createProducerConfig(maxMessageBytes) {
50
- return {
48
+ async function getKafkaProducer(cfg, logger) {
49
+ const kafka = await getKafkaClient(cfg, logger);
50
+ const producer = kafka.producer({
51
51
  kafkaJS: {
52
- idempotent: false,
53
- // Not needed for at-least-once delivery
52
+ idempotent: true,
54
53
  acks: ACKs,
55
54
  retry: {
56
55
  retries: MAX_RETRIES_PRODUCER,
57
56
  maxRetryTime: MAX_RETRY_TIME_MS
58
57
  }
59
- },
60
- "linger.ms": 0,
61
- // This is to make sure at least once delivery with immediate feedback on the send
62
- ...maxMessageBytes && { "message.max.bytes": maxMessageBytes }
63
- };
64
- }
65
- async function getKafkaProducer(cfg, logger, maxMessageBytes) {
66
- const kafka = await getKafkaClient(cfg, logger);
67
- const producer = kafka.producer(createProducerConfig(maxMessageBytes));
58
+ }
59
+ });
68
60
  await producer.connect();
69
61
  return producer;
70
62
  }
@@ -601,16 +593,6 @@ function emptyIfUndefined(value) {
601
593
  return value === void 0 ? "" : value;
602
594
  }
603
595
 
604
- // src/blocks/helpers.ts
605
- function dropView(name) {
606
- return `DROP VIEW IF EXISTS ${quoteIdentifier(name)}`.trim();
607
- }
608
- function createMaterializedView(options) {
609
- return `CREATE MATERIALIZED VIEW IF NOT EXISTS ${quoteIdentifier(options.name)}
610
- TO ${quoteIdentifier(options.destinationTable)}
611
- AS ${options.select}`.trim();
612
- }
613
-
614
596
  // src/dmv2/internal.ts
615
597
  import process2 from "process";
616
598
 
@@ -664,7 +646,9 @@ var moose_internal = {
664
646
  apis: /* @__PURE__ */ new Map(),
665
647
  sqlResources: /* @__PURE__ */ new Map(),
666
648
  workflows: /* @__PURE__ */ new Map(),
667
- webApps: /* @__PURE__ */ new Map()
649
+ webApps: /* @__PURE__ */ new Map(),
650
+ materializedViews: /* @__PURE__ */ new Map(),
651
+ customViews: /* @__PURE__ */ new Map()
668
652
  };
669
653
  var defaultRetentionPeriod = 60 * 60 * 24 * 7;
670
654
  var getMooseInternal = () => globalThis.moose_internal;
@@ -2280,6 +2264,67 @@ var ETLPipeline = class {
2280
2264
  }
2281
2265
  };
2282
2266
 
2267
+ // src/dmv2/sdk/materializedView.ts
2268
+ var requireTargetTableName = (tableName) => {
2269
+ if (typeof tableName === "string") {
2270
+ return tableName;
2271
+ } else {
2272
+ throw new Error("Name of targetTable is not specified.");
2273
+ }
2274
+ };
2275
+ var MaterializedView = class {
2276
+ /** @internal */
2277
+ kind = "MaterializedView";
2278
+ /** The name of the materialized view */
2279
+ name;
2280
+ /** The target OlapTable instance where the materialized data is stored. */
2281
+ targetTable;
2282
+ /** The SELECT SQL statement */
2283
+ selectSql;
2284
+ /** Names of source tables that the SELECT reads from */
2285
+ sourceTables;
2286
+ /** @internal Source file path where this MV was defined */
2287
+ sourceFile;
2288
+ constructor(options, targetSchema, targetColumns) {
2289
+ let selectStatement = options.selectStatement;
2290
+ if (typeof selectStatement !== "string") {
2291
+ selectStatement = toStaticQuery(selectStatement);
2292
+ }
2293
+ if (targetSchema === void 0 || targetColumns === void 0) {
2294
+ throw new Error(
2295
+ "Supply the type param T so that the schema is inserted by the compiler plugin."
2296
+ );
2297
+ }
2298
+ const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2299
+ requireTargetTableName(
2300
+ options.targetTable?.name ?? options.tableName
2301
+ ),
2302
+ {
2303
+ orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2304
+ engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2305
+ },
2306
+ targetSchema,
2307
+ targetColumns
2308
+ );
2309
+ if (targetTable.name === options.materializedViewName) {
2310
+ throw new Error(
2311
+ "Materialized view name cannot be the same as the target table name."
2312
+ );
2313
+ }
2314
+ this.name = options.materializedViewName;
2315
+ this.targetTable = targetTable;
2316
+ this.selectSql = selectStatement;
2317
+ this.sourceTables = options.selectTables.map((t) => t.name);
2318
+ const stack = new Error().stack;
2319
+ this.sourceFile = getSourceFileFromStack(stack);
2320
+ const materializedViews = getMooseInternal().materializedViews;
2321
+ if (!isClientOnlyMode() && materializedViews.has(this.name)) {
2322
+ throw new Error(`MaterializedView with name ${this.name} already exists`);
2323
+ }
2324
+ materializedViews.set(this.name, this);
2325
+ }
2326
+ };
2327
+
2283
2328
  // src/dmv2/sdk/sqlResource.ts
2284
2329
  var SqlResource = class {
2285
2330
  /** @internal */
@@ -2325,66 +2370,18 @@ var SqlResource = class {
2325
2370
  }
2326
2371
  };
2327
2372
 
2328
- // src/dmv2/sdk/materializedView.ts
2329
- var requireTargetTableName = (tableName) => {
2330
- if (typeof tableName === "string") {
2331
- return tableName;
2332
- } else {
2333
- throw new Error("Name of targetTable is not specified.");
2334
- }
2335
- };
2336
- var MaterializedView = class extends SqlResource {
2337
- /** The target OlapTable instance where the materialized data is stored. */
2338
- targetTable;
2339
- constructor(options, targetSchema, targetColumns) {
2340
- let selectStatement = options.selectStatement;
2341
- if (typeof selectStatement !== "string") {
2342
- selectStatement = toStaticQuery(selectStatement);
2343
- }
2344
- if (targetSchema === void 0 || targetColumns === void 0) {
2345
- throw new Error(
2346
- "Supply the type param T so that the schema is inserted by the compiler plugin."
2347
- );
2348
- }
2349
- const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2350
- requireTargetTableName(
2351
- options.targetTable?.name ?? options.tableName
2352
- ),
2353
- {
2354
- orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2355
- engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2356
- },
2357
- targetSchema,
2358
- targetColumns
2359
- );
2360
- if (targetTable.name === options.materializedViewName) {
2361
- throw new Error(
2362
- "Materialized view name cannot be the same as the target table name."
2363
- );
2364
- }
2365
- super(
2366
- options.materializedViewName,
2367
- [
2368
- createMaterializedView({
2369
- name: options.materializedViewName,
2370
- destinationTable: targetTable.name,
2371
- select: selectStatement
2372
- })
2373
- // Population is now handled automatically by Rust infrastructure
2374
- // based on table engine type and whether this is a new or updated view
2375
- ],
2376
- [dropView(options.materializedViewName)],
2377
- {
2378
- pullsDataFrom: options.selectTables,
2379
- pushesDataTo: [targetTable]
2380
- }
2381
- );
2382
- this.targetTable = targetTable;
2383
- }
2384
- };
2385
-
2386
2373
  // src/dmv2/sdk/view.ts
2387
- var View = class extends SqlResource {
2374
+ var View = class {
2375
+ /** @internal */
2376
+ kind = "CustomView";
2377
+ /** The name of the view */
2378
+ name;
2379
+ /** The SELECT SQL statement that defines the view */
2380
+ selectSql;
2381
+ /** Names of source tables/views that the SELECT reads from */
2382
+ sourceTables;
2383
+ /** @internal Source file path where this view was defined */
2384
+ sourceFile;
2388
2385
  /**
2389
2386
  * Creates a new View instance.
2390
2387
  * @param name The name of the view to be created.
@@ -2395,17 +2392,16 @@ var View = class extends SqlResource {
2395
2392
  if (typeof selectStatement !== "string") {
2396
2393
  selectStatement = toStaticQuery(selectStatement);
2397
2394
  }
2398
- super(
2399
- name,
2400
- [
2401
- `CREATE VIEW IF NOT EXISTS ${name}
2402
- AS ${selectStatement}`.trim()
2403
- ],
2404
- [dropView(name)],
2405
- {
2406
- pullsDataFrom: baseTables
2407
- }
2408
- );
2395
+ this.name = name;
2396
+ this.selectSql = selectStatement;
2397
+ this.sourceTables = baseTables.map((t) => t.name);
2398
+ const stack = new Error().stack;
2399
+ this.sourceFile = getSourceFileFromStack(stack);
2400
+ const customViews = getMooseInternal().customViews;
2401
+ if (!isClientOnlyMode() && customViews.has(this.name)) {
2402
+ throw new Error(`View with name ${this.name} already exists`);
2403
+ }
2404
+ customViews.set(this.name, this);
2409
2405
  }
2410
2406
  };
2411
2407