@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.
@@ -312,6 +312,14 @@ var init_sqlHelpers = __esm({
312
312
  });
313
313
 
314
314
  // src/blocks/helpers.ts
315
+ function dropView(name) {
316
+ return `DROP VIEW IF EXISTS ${quoteIdentifier(name)}`.trim();
317
+ }
318
+ function createMaterializedView(options) {
319
+ return `CREATE MATERIALIZED VIEW IF NOT EXISTS ${quoteIdentifier(options.name)}
320
+ TO ${quoteIdentifier(options.destinationTable)}
321
+ AS ${options.select}`.trim();
322
+ }
315
323
  var init_helpers = __esm({
316
324
  "src/blocks/helpers.ts"() {
317
325
  "use strict";
@@ -651,9 +659,7 @@ var init_internal = __esm({
651
659
  apis: /* @__PURE__ */ new Map(),
652
660
  sqlResources: /* @__PURE__ */ new Map(),
653
661
  workflows: /* @__PURE__ */ new Map(),
654
- webApps: /* @__PURE__ */ new Map(),
655
- materializedViews: /* @__PURE__ */ new Map(),
656
- views: /* @__PURE__ */ new Map()
662
+ webApps: /* @__PURE__ */ new Map()
657
663
  };
658
664
  defaultRetentionPeriod = 60 * 60 * 24 * 7;
659
665
  getMooseInternal = () => globalThis.moose_internal;
@@ -2534,93 +2540,6 @@ var init_etlPipeline = __esm({
2534
2540
  }
2535
2541
  });
2536
2542
 
2537
- // src/dmv2/sdk/materializedView.ts
2538
- function formatTableReference(table) {
2539
- const database = table instanceof OlapTable ? table.config.database : void 0;
2540
- if (database) {
2541
- return `\`${database}\`.\`${table.name}\``;
2542
- }
2543
- return `\`${table.name}\``;
2544
- }
2545
- var requireTargetTableName, MaterializedView;
2546
- var init_materializedView = __esm({
2547
- "src/dmv2/sdk/materializedView.ts"() {
2548
- "use strict";
2549
- init_helpers();
2550
- init_sqlHelpers();
2551
- init_olapTable();
2552
- init_internal();
2553
- init_stackTrace();
2554
- requireTargetTableName = (tableName) => {
2555
- if (typeof tableName === "string") {
2556
- return tableName;
2557
- } else {
2558
- throw new Error("Name of targetTable is not specified.");
2559
- }
2560
- };
2561
- MaterializedView = class {
2562
- /** @internal */
2563
- kind = "MaterializedView";
2564
- /** The name of the materialized view */
2565
- name;
2566
- /** The target OlapTable instance where the materialized data is stored. */
2567
- targetTable;
2568
- /** The SELECT SQL statement */
2569
- selectSql;
2570
- /** Names of source tables that the SELECT reads from */
2571
- sourceTables;
2572
- /** Optional metadata for the materialized view */
2573
- metadata;
2574
- constructor(options, targetSchema, targetColumns) {
2575
- let selectStatement = options.selectStatement;
2576
- if (typeof selectStatement !== "string") {
2577
- selectStatement = toStaticQuery(selectStatement);
2578
- }
2579
- if (targetSchema === void 0 || targetColumns === void 0) {
2580
- throw new Error(
2581
- "Supply the type param T so that the schema is inserted by the compiler plugin."
2582
- );
2583
- }
2584
- const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2585
- requireTargetTableName(
2586
- options.targetTable?.name ?? options.tableName
2587
- ),
2588
- {
2589
- orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2590
- engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2591
- },
2592
- targetSchema,
2593
- targetColumns
2594
- );
2595
- if (targetTable.name === options.materializedViewName) {
2596
- throw new Error(
2597
- "Materialized view name cannot be the same as the target table name."
2598
- );
2599
- }
2600
- this.name = options.materializedViewName;
2601
- this.targetTable = targetTable;
2602
- this.selectSql = selectStatement;
2603
- this.sourceTables = options.selectTables.map(
2604
- (t) => formatTableReference(t)
2605
- );
2606
- this.metadata = options.metadata ? { ...options.metadata } : {};
2607
- if (!this.metadata.source) {
2608
- const stack = new Error().stack;
2609
- const sourceInfo = getSourceFileFromStack(stack);
2610
- if (sourceInfo) {
2611
- this.metadata.source = { file: sourceInfo };
2612
- }
2613
- }
2614
- const materializedViews = getMooseInternal().materializedViews;
2615
- if (!isClientOnlyMode() && materializedViews.has(this.name)) {
2616
- throw new Error(`MaterializedView with name ${this.name} already exists`);
2617
- }
2618
- materializedViews.set(this.name, this);
2619
- }
2620
- };
2621
- }
2622
- });
2623
-
2624
2543
  // src/dmv2/sdk/sqlResource.ts
2625
2544
  var SqlResource;
2626
2545
  var init_sqlResource = __esm({
@@ -2684,60 +2603,104 @@ var init_sqlResource = __esm({
2684
2603
  }
2685
2604
  });
2686
2605
 
2687
- // src/dmv2/sdk/view.ts
2688
- function formatTableReference2(table) {
2689
- const database = table instanceof OlapTable ? table.config.database : void 0;
2690
- if (database) {
2691
- return `\`${database}\`.\`${table.name}\``;
2606
+ // src/dmv2/sdk/materializedView.ts
2607
+ var requireTargetTableName, MaterializedView;
2608
+ var init_materializedView = __esm({
2609
+ "src/dmv2/sdk/materializedView.ts"() {
2610
+ "use strict";
2611
+ init_helpers();
2612
+ init_sqlHelpers();
2613
+ init_olapTable();
2614
+ init_sqlResource();
2615
+ requireTargetTableName = (tableName) => {
2616
+ if (typeof tableName === "string") {
2617
+ return tableName;
2618
+ } else {
2619
+ throw new Error("Name of targetTable is not specified.");
2620
+ }
2621
+ };
2622
+ MaterializedView = class extends SqlResource {
2623
+ /** The target OlapTable instance where the materialized data is stored. */
2624
+ targetTable;
2625
+ constructor(options, targetSchema, targetColumns) {
2626
+ let selectStatement = options.selectStatement;
2627
+ if (typeof selectStatement !== "string") {
2628
+ selectStatement = toStaticQuery(selectStatement);
2629
+ }
2630
+ if (targetSchema === void 0 || targetColumns === void 0) {
2631
+ throw new Error(
2632
+ "Supply the type param T so that the schema is inserted by the compiler plugin."
2633
+ );
2634
+ }
2635
+ const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2636
+ requireTargetTableName(
2637
+ options.targetTable?.name ?? options.tableName
2638
+ ),
2639
+ {
2640
+ orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2641
+ engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2642
+ },
2643
+ targetSchema,
2644
+ targetColumns
2645
+ );
2646
+ if (targetTable.name === options.materializedViewName) {
2647
+ throw new Error(
2648
+ "Materialized view name cannot be the same as the target table name."
2649
+ );
2650
+ }
2651
+ super(
2652
+ options.materializedViewName,
2653
+ [
2654
+ createMaterializedView({
2655
+ name: options.materializedViewName,
2656
+ destinationTable: targetTable.name,
2657
+ select: selectStatement
2658
+ })
2659
+ // Population is now handled automatically by Rust infrastructure
2660
+ // based on table engine type and whether this is a new or updated view
2661
+ ],
2662
+ [dropView(options.materializedViewName)],
2663
+ {
2664
+ pullsDataFrom: options.selectTables,
2665
+ pushesDataTo: [targetTable]
2666
+ }
2667
+ );
2668
+ this.targetTable = targetTable;
2669
+ }
2670
+ };
2692
2671
  }
2693
- return `\`${table.name}\``;
2694
- }
2672
+ });
2673
+
2674
+ // src/dmv2/sdk/view.ts
2695
2675
  var View;
2696
2676
  var init_view = __esm({
2697
2677
  "src/dmv2/sdk/view.ts"() {
2698
2678
  "use strict";
2679
+ init_helpers();
2699
2680
  init_sqlHelpers();
2700
- init_olapTable();
2701
- init_internal();
2702
- init_stackTrace();
2703
- View = class {
2704
- /** @internal */
2705
- kind = "View";
2706
- /** The name of the view */
2707
- name;
2708
- /** The SELECT SQL statement that defines the view */
2709
- selectSql;
2710
- /** Names of source tables/views that the SELECT reads from */
2711
- sourceTables;
2712
- /** Optional metadata for the view */
2713
- metadata;
2681
+ init_sqlResource();
2682
+ View = class extends SqlResource {
2714
2683
  /**
2715
2684
  * Creates a new View instance.
2716
2685
  * @param name The name of the view to be created.
2717
2686
  * @param selectStatement The SQL SELECT statement that defines the view's logic.
2718
2687
  * @param baseTables An array of OlapTable or View objects that the `selectStatement` reads from. Used for dependency tracking.
2719
- * @param metadata Optional metadata for the view (e.g., description, source file).
2720
2688
  */
2721
- constructor(name, selectStatement, baseTables, metadata) {
2689
+ constructor(name, selectStatement, baseTables) {
2722
2690
  if (typeof selectStatement !== "string") {
2723
2691
  selectStatement = toStaticQuery(selectStatement);
2724
2692
  }
2725
- this.name = name;
2726
- this.selectSql = selectStatement;
2727
- this.sourceTables = baseTables.map((t) => formatTableReference2(t));
2728
- this.metadata = metadata ? { ...metadata } : {};
2729
- if (!this.metadata.source) {
2730
- const stack = new Error().stack;
2731
- const sourceInfo = getSourceFileFromStack(stack);
2732
- if (sourceInfo) {
2733
- this.metadata.source = { file: sourceInfo };
2693
+ super(
2694
+ name,
2695
+ [
2696
+ `CREATE VIEW IF NOT EXISTS ${name}
2697
+ AS ${selectStatement}`.trim()
2698
+ ],
2699
+ [dropView(name)],
2700
+ {
2701
+ pullsDataFrom: baseTables
2734
2702
  }
2735
- }
2736
- const views = getMooseInternal().views;
2737
- if (!isClientOnlyMode() && views.has(this.name)) {
2738
- throw new Error(`View with name ${this.name} already exists`);
2739
- }
2740
- views.set(this.name, this);
2703
+ );
2741
2704
  }
2742
2705
  };
2743
2706
  }
@@ -2941,18 +2904,6 @@ function getWebApps2() {
2941
2904
  function getWebApp(name) {
2942
2905
  return getMooseInternal().webApps.get(name);
2943
2906
  }
2944
- function getMaterializedViews() {
2945
- return getMooseInternal().materializedViews;
2946
- }
2947
- function getMaterializedView(name) {
2948
- return getMooseInternal().materializedViews.get(name);
2949
- }
2950
- function getViews() {
2951
- return getMooseInternal().views;
2952
- }
2953
- function getView(name) {
2954
- return getMooseInternal().views.get(name);
2955
- }
2956
2907
  var init_registry = __esm({
2957
2908
  "src/dmv2/registry.ts"() {
2958
2909
  "use strict";
@@ -3011,8 +2962,6 @@ export {
3011
2962
  getApis2 as getApis,
3012
2963
  getIngestApi,
3013
2964
  getIngestApis,
3014
- getMaterializedView,
3015
- getMaterializedViews,
3016
2965
  getSqlResource,
3017
2966
  getSqlResources,
3018
2967
  getStream,
@@ -3020,8 +2969,6 @@ export {
3020
2969
  getTable,
3021
2970
  getTables,
3022
2971
  getValueFromParameter,
3023
- getView,
3024
- getViews,
3025
2972
  getWebApp,
3026
2973
  getWebApps2 as getWebApps,
3027
2974
  getWorkflow,