@514labs/moose-lib 0.6.297-ci-40-g26f564af → 0.6.297

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.
@@ -217,6 +217,14 @@ var init_sqlHelpers = __esm({
217
217
  });
218
218
 
219
219
  // src/blocks/helpers.ts
220
+ function dropView(name) {
221
+ return `DROP VIEW IF EXISTS ${quoteIdentifier(name)}`.trim();
222
+ }
223
+ function createMaterializedView(options) {
224
+ return `CREATE MATERIALIZED VIEW IF NOT EXISTS ${quoteIdentifier(options.name)}
225
+ TO ${quoteIdentifier(options.destinationTable)}
226
+ AS ${options.select}`.trim();
227
+ }
220
228
  var init_helpers = __esm({
221
229
  "src/blocks/helpers.ts"() {
222
230
  "use strict";
@@ -566,9 +574,7 @@ var init_internal = __esm({
566
574
  apis: /* @__PURE__ */ new Map(),
567
575
  sqlResources: /* @__PURE__ */ new Map(),
568
576
  workflows: /* @__PURE__ */ new Map(),
569
- webApps: /* @__PURE__ */ new Map(),
570
- materializedViews: /* @__PURE__ */ new Map(),
571
- views: /* @__PURE__ */ new Map()
577
+ webApps: /* @__PURE__ */ new Map()
572
578
  };
573
579
  defaultRetentionPeriod = 60 * 60 * 24 * 7;
574
580
  getMooseInternal = () => globalThis.moose_internal;
@@ -2449,93 +2455,6 @@ var init_etlPipeline = __esm({
2449
2455
  }
2450
2456
  });
2451
2457
 
2452
- // src/dmv2/sdk/materializedView.ts
2453
- function formatTableReference(table) {
2454
- const database = table instanceof OlapTable ? table.config.database : void 0;
2455
- if (database) {
2456
- return `\`${database}\`.\`${table.name}\``;
2457
- }
2458
- return `\`${table.name}\``;
2459
- }
2460
- var requireTargetTableName, MaterializedView;
2461
- var init_materializedView = __esm({
2462
- "src/dmv2/sdk/materializedView.ts"() {
2463
- "use strict";
2464
- init_helpers();
2465
- init_sqlHelpers();
2466
- init_olapTable();
2467
- init_internal();
2468
- init_stackTrace();
2469
- requireTargetTableName = (tableName) => {
2470
- if (typeof tableName === "string") {
2471
- return tableName;
2472
- } else {
2473
- throw new Error("Name of targetTable is not specified.");
2474
- }
2475
- };
2476
- MaterializedView = class {
2477
- /** @internal */
2478
- kind = "MaterializedView";
2479
- /** The name of the materialized view */
2480
- name;
2481
- /** The target OlapTable instance where the materialized data is stored. */
2482
- targetTable;
2483
- /** The SELECT SQL statement */
2484
- selectSql;
2485
- /** Names of source tables that the SELECT reads from */
2486
- sourceTables;
2487
- /** Optional metadata for the materialized view */
2488
- metadata;
2489
- constructor(options, targetSchema, targetColumns) {
2490
- let selectStatement = options.selectStatement;
2491
- if (typeof selectStatement !== "string") {
2492
- selectStatement = toStaticQuery(selectStatement);
2493
- }
2494
- if (targetSchema === void 0 || targetColumns === void 0) {
2495
- throw new Error(
2496
- "Supply the type param T so that the schema is inserted by the compiler plugin."
2497
- );
2498
- }
2499
- const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2500
- requireTargetTableName(
2501
- options.targetTable?.name ?? options.tableName
2502
- ),
2503
- {
2504
- orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2505
- engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2506
- },
2507
- targetSchema,
2508
- targetColumns
2509
- );
2510
- if (targetTable.name === options.materializedViewName) {
2511
- throw new Error(
2512
- "Materialized view name cannot be the same as the target table name."
2513
- );
2514
- }
2515
- this.name = options.materializedViewName;
2516
- this.targetTable = targetTable;
2517
- this.selectSql = selectStatement;
2518
- this.sourceTables = options.selectTables.map(
2519
- (t) => formatTableReference(t)
2520
- );
2521
- this.metadata = options.metadata ? { ...options.metadata } : {};
2522
- if (!this.metadata.source) {
2523
- const stack = new Error().stack;
2524
- const sourceInfo = getSourceFileFromStack(stack);
2525
- if (sourceInfo) {
2526
- this.metadata.source = { file: sourceInfo };
2527
- }
2528
- }
2529
- const materializedViews = getMooseInternal().materializedViews;
2530
- if (!isClientOnlyMode() && materializedViews.has(this.name)) {
2531
- throw new Error(`MaterializedView with name ${this.name} already exists`);
2532
- }
2533
- materializedViews.set(this.name, this);
2534
- }
2535
- };
2536
- }
2537
- });
2538
-
2539
2458
  // src/dmv2/sdk/sqlResource.ts
2540
2459
  var SqlResource;
2541
2460
  var init_sqlResource = __esm({
@@ -2599,60 +2518,104 @@ var init_sqlResource = __esm({
2599
2518
  }
2600
2519
  });
2601
2520
 
2602
- // src/dmv2/sdk/view.ts
2603
- function formatTableReference2(table) {
2604
- const database = table instanceof OlapTable ? table.config.database : void 0;
2605
- if (database) {
2606
- return `\`${database}\`.\`${table.name}\``;
2521
+ // src/dmv2/sdk/materializedView.ts
2522
+ var requireTargetTableName, MaterializedView;
2523
+ var init_materializedView = __esm({
2524
+ "src/dmv2/sdk/materializedView.ts"() {
2525
+ "use strict";
2526
+ init_helpers();
2527
+ init_sqlHelpers();
2528
+ init_olapTable();
2529
+ init_sqlResource();
2530
+ requireTargetTableName = (tableName) => {
2531
+ if (typeof tableName === "string") {
2532
+ return tableName;
2533
+ } else {
2534
+ throw new Error("Name of targetTable is not specified.");
2535
+ }
2536
+ };
2537
+ MaterializedView = class extends SqlResource {
2538
+ /** The target OlapTable instance where the materialized data is stored. */
2539
+ targetTable;
2540
+ constructor(options, targetSchema, targetColumns) {
2541
+ let selectStatement = options.selectStatement;
2542
+ if (typeof selectStatement !== "string") {
2543
+ selectStatement = toStaticQuery(selectStatement);
2544
+ }
2545
+ if (targetSchema === void 0 || targetColumns === void 0) {
2546
+ throw new Error(
2547
+ "Supply the type param T so that the schema is inserted by the compiler plugin."
2548
+ );
2549
+ }
2550
+ const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2551
+ requireTargetTableName(
2552
+ options.targetTable?.name ?? options.tableName
2553
+ ),
2554
+ {
2555
+ orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2556
+ engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2557
+ },
2558
+ targetSchema,
2559
+ targetColumns
2560
+ );
2561
+ if (targetTable.name === options.materializedViewName) {
2562
+ throw new Error(
2563
+ "Materialized view name cannot be the same as the target table name."
2564
+ );
2565
+ }
2566
+ super(
2567
+ options.materializedViewName,
2568
+ [
2569
+ createMaterializedView({
2570
+ name: options.materializedViewName,
2571
+ destinationTable: targetTable.name,
2572
+ select: selectStatement
2573
+ })
2574
+ // Population is now handled automatically by Rust infrastructure
2575
+ // based on table engine type and whether this is a new or updated view
2576
+ ],
2577
+ [dropView(options.materializedViewName)],
2578
+ {
2579
+ pullsDataFrom: options.selectTables,
2580
+ pushesDataTo: [targetTable]
2581
+ }
2582
+ );
2583
+ this.targetTable = targetTable;
2584
+ }
2585
+ };
2607
2586
  }
2608
- return `\`${table.name}\``;
2609
- }
2587
+ });
2588
+
2589
+ // src/dmv2/sdk/view.ts
2610
2590
  var View;
2611
2591
  var init_view = __esm({
2612
2592
  "src/dmv2/sdk/view.ts"() {
2613
2593
  "use strict";
2594
+ init_helpers();
2614
2595
  init_sqlHelpers();
2615
- init_olapTable();
2616
- init_internal();
2617
- init_stackTrace();
2618
- View = class {
2619
- /** @internal */
2620
- kind = "View";
2621
- /** The name of the view */
2622
- name;
2623
- /** The SELECT SQL statement that defines the view */
2624
- selectSql;
2625
- /** Names of source tables/views that the SELECT reads from */
2626
- sourceTables;
2627
- /** Optional metadata for the view */
2628
- metadata;
2596
+ init_sqlResource();
2597
+ View = class extends SqlResource {
2629
2598
  /**
2630
2599
  * Creates a new View instance.
2631
2600
  * @param name The name of the view to be created.
2632
2601
  * @param selectStatement The SQL SELECT statement that defines the view's logic.
2633
2602
  * @param baseTables An array of OlapTable or View objects that the `selectStatement` reads from. Used for dependency tracking.
2634
- * @param metadata Optional metadata for the view (e.g., description, source file).
2635
2603
  */
2636
- constructor(name, selectStatement, baseTables, metadata) {
2604
+ constructor(name, selectStatement, baseTables) {
2637
2605
  if (typeof selectStatement !== "string") {
2638
2606
  selectStatement = toStaticQuery(selectStatement);
2639
2607
  }
2640
- this.name = name;
2641
- this.selectSql = selectStatement;
2642
- this.sourceTables = baseTables.map((t) => formatTableReference2(t));
2643
- this.metadata = metadata ? { ...metadata } : {};
2644
- if (!this.metadata.source) {
2645
- const stack = new Error().stack;
2646
- const sourceInfo = getSourceFileFromStack(stack);
2647
- if (sourceInfo) {
2648
- this.metadata.source = { file: sourceInfo };
2608
+ super(
2609
+ name,
2610
+ [
2611
+ `CREATE VIEW IF NOT EXISTS ${name}
2612
+ AS ${selectStatement}`.trim()
2613
+ ],
2614
+ [dropView(name)],
2615
+ {
2616
+ pullsDataFrom: baseTables
2649
2617
  }
2650
- }
2651
- const views = getMooseInternal().views;
2652
- if (!isClientOnlyMode() && views.has(this.name)) {
2653
- throw new Error(`View with name ${this.name} already exists`);
2654
- }
2655
- views.set(this.name, this);
2618
+ );
2656
2619
  }
2657
2620
  };
2658
2621
  }
@@ -2856,18 +2819,6 @@ function getWebApps() {
2856
2819
  function getWebApp(name) {
2857
2820
  return getMooseInternal().webApps.get(name);
2858
2821
  }
2859
- function getMaterializedViews() {
2860
- return getMooseInternal().materializedViews;
2861
- }
2862
- function getMaterializedView(name) {
2863
- return getMooseInternal().materializedViews.get(name);
2864
- }
2865
- function getViews() {
2866
- return getMooseInternal().views;
2867
- }
2868
- function getView(name) {
2869
- return getMooseInternal().views.get(name);
2870
- }
2871
2822
  var init_registry = __esm({
2872
2823
  "src/dmv2/registry.ts"() {
2873
2824
  "use strict";
@@ -2914,16 +2865,12 @@ export {
2914
2865
  getApis,
2915
2866
  getIngestApi,
2916
2867
  getIngestApis,
2917
- getMaterializedView,
2918
- getMaterializedViews,
2919
2868
  getSqlResource,
2920
2869
  getSqlResources,
2921
2870
  getStream,
2922
2871
  getStreams,
2923
2872
  getTable,
2924
2873
  getTables,
2925
- getView,
2926
- getViews,
2927
2874
  getWebApp,
2928
2875
  getWebApps,
2929
2876
  getWorkflow,