@514labs/moose-lib 0.6.297-ci-4-g3b2674ae → 0.6.297-ci-22-g1be0de24

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,14 +312,6 @@ 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
- }
323
315
  var init_helpers = __esm({
324
316
  "src/blocks/helpers.ts"() {
325
317
  "use strict";
@@ -659,7 +651,9 @@ var init_internal = __esm({
659
651
  apis: /* @__PURE__ */ new Map(),
660
652
  sqlResources: /* @__PURE__ */ new Map(),
661
653
  workflows: /* @__PURE__ */ new Map(),
662
- webApps: /* @__PURE__ */ new Map()
654
+ webApps: /* @__PURE__ */ new Map(),
655
+ materializedViews: /* @__PURE__ */ new Map(),
656
+ customViews: /* @__PURE__ */ new Map()
663
657
  };
664
658
  defaultRetentionPeriod = 60 * 60 * 24 * 7;
665
659
  getMooseInternal = () => globalThis.moose_internal;
@@ -2540,6 +2534,78 @@ var init_etlPipeline = __esm({
2540
2534
  }
2541
2535
  });
2542
2536
 
2537
+ // src/dmv2/sdk/materializedView.ts
2538
+ var requireTargetTableName, MaterializedView;
2539
+ var init_materializedView = __esm({
2540
+ "src/dmv2/sdk/materializedView.ts"() {
2541
+ "use strict";
2542
+ init_helpers();
2543
+ init_sqlHelpers();
2544
+ init_olapTable();
2545
+ init_internal();
2546
+ init_stackTrace();
2547
+ requireTargetTableName = (tableName) => {
2548
+ if (typeof tableName === "string") {
2549
+ return tableName;
2550
+ } else {
2551
+ throw new Error("Name of targetTable is not specified.");
2552
+ }
2553
+ };
2554
+ MaterializedView = class {
2555
+ /** @internal */
2556
+ kind = "MaterializedView";
2557
+ /** The name of the materialized view */
2558
+ name;
2559
+ /** The target OlapTable instance where the materialized data is stored. */
2560
+ targetTable;
2561
+ /** The SELECT SQL statement */
2562
+ selectSql;
2563
+ /** Names of source tables that the SELECT reads from */
2564
+ sourceTables;
2565
+ /** @internal Source file path where this MV was defined */
2566
+ sourceFile;
2567
+ constructor(options, targetSchema, targetColumns) {
2568
+ let selectStatement = options.selectStatement;
2569
+ if (typeof selectStatement !== "string") {
2570
+ selectStatement = toStaticQuery(selectStatement);
2571
+ }
2572
+ if (targetSchema === void 0 || targetColumns === void 0) {
2573
+ throw new Error(
2574
+ "Supply the type param T so that the schema is inserted by the compiler plugin."
2575
+ );
2576
+ }
2577
+ const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2578
+ requireTargetTableName(
2579
+ options.targetTable?.name ?? options.tableName
2580
+ ),
2581
+ {
2582
+ orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2583
+ engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2584
+ },
2585
+ targetSchema,
2586
+ targetColumns
2587
+ );
2588
+ if (targetTable.name === options.materializedViewName) {
2589
+ throw new Error(
2590
+ "Materialized view name cannot be the same as the target table name."
2591
+ );
2592
+ }
2593
+ this.name = options.materializedViewName;
2594
+ this.targetTable = targetTable;
2595
+ this.selectSql = selectStatement;
2596
+ this.sourceTables = options.selectTables.map((t) => t.name);
2597
+ const stack = new Error().stack;
2598
+ this.sourceFile = getSourceFileFromStack(stack);
2599
+ const materializedViews = getMooseInternal().materializedViews;
2600
+ if (!isClientOnlyMode() && materializedViews.has(this.name)) {
2601
+ throw new Error(`MaterializedView with name ${this.name} already exists`);
2602
+ }
2603
+ materializedViews.set(this.name, this);
2604
+ }
2605
+ };
2606
+ }
2607
+ });
2608
+
2543
2609
  // src/dmv2/sdk/sqlResource.ts
2544
2610
  var SqlResource;
2545
2611
  var init_sqlResource = __esm({
@@ -2603,83 +2669,25 @@ var init_sqlResource = __esm({
2603
2669
  }
2604
2670
  });
2605
2671
 
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
- };
2671
- }
2672
- });
2673
-
2674
2672
  // src/dmv2/sdk/view.ts
2675
2673
  var View;
2676
2674
  var init_view = __esm({
2677
2675
  "src/dmv2/sdk/view.ts"() {
2678
2676
  "use strict";
2679
- init_helpers();
2680
2677
  init_sqlHelpers();
2681
- init_sqlResource();
2682
- View = class extends SqlResource {
2678
+ init_internal();
2679
+ init_stackTrace();
2680
+ View = class {
2681
+ /** @internal */
2682
+ kind = "CustomView";
2683
+ /** The name of the view */
2684
+ name;
2685
+ /** The SELECT SQL statement that defines the view */
2686
+ selectSql;
2687
+ /** Names of source tables/views that the SELECT reads from */
2688
+ sourceTables;
2689
+ /** @internal Source file path where this view was defined */
2690
+ sourceFile;
2683
2691
  /**
2684
2692
  * Creates a new View instance.
2685
2693
  * @param name The name of the view to be created.
@@ -2690,17 +2698,16 @@ var init_view = __esm({
2690
2698
  if (typeof selectStatement !== "string") {
2691
2699
  selectStatement = toStaticQuery(selectStatement);
2692
2700
  }
2693
- super(
2694
- name,
2695
- [
2696
- `CREATE VIEW IF NOT EXISTS ${name}
2697
- AS ${selectStatement}`.trim()
2698
- ],
2699
- [dropView(name)],
2700
- {
2701
- pullsDataFrom: baseTables
2702
- }
2703
- );
2701
+ this.name = name;
2702
+ this.selectSql = selectStatement;
2703
+ this.sourceTables = baseTables.map((t) => t.name);
2704
+ const stack = new Error().stack;
2705
+ this.sourceFile = getSourceFileFromStack(stack);
2706
+ const customViews = getMooseInternal().customViews;
2707
+ if (!isClientOnlyMode() && customViews.has(this.name)) {
2708
+ throw new Error(`View with name ${this.name} already exists`);
2709
+ }
2710
+ customViews.set(this.name, this);
2704
2711
  }
2705
2712
  };
2706
2713
  }
@@ -2904,6 +2911,18 @@ function getWebApps2() {
2904
2911
  function getWebApp(name) {
2905
2912
  return getMooseInternal().webApps.get(name);
2906
2913
  }
2914
+ function getMaterializedViews() {
2915
+ return getMooseInternal().materializedViews;
2916
+ }
2917
+ function getMaterializedView(name) {
2918
+ return getMooseInternal().materializedViews.get(name);
2919
+ }
2920
+ function getCustomViews() {
2921
+ return getMooseInternal().customViews;
2922
+ }
2923
+ function getCustomView(name) {
2924
+ return getMooseInternal().customViews.get(name);
2925
+ }
2907
2926
  var init_registry = __esm({
2908
2927
  "src/dmv2/registry.ts"() {
2909
2928
  "use strict";
@@ -2960,8 +2979,12 @@ export {
2960
2979
  createClickhouseParameter,
2961
2980
  getApi,
2962
2981
  getApis2 as getApis,
2982
+ getCustomView,
2983
+ getCustomViews,
2963
2984
  getIngestApi,
2964
2985
  getIngestApis,
2986
+ getMaterializedView,
2987
+ getMaterializedViews,
2965
2988
  getSqlResource,
2966
2989
  getSqlResources,
2967
2990
  getStream,