@514labs/moose-lib 0.6.297-ci-35-g4e0a867f → 0.6.297-ci-24-g9a20c7e5

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,84 @@ 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
+ /** Optional metadata for the materialized view */
2566
+ metadata;
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
+ this.metadata = options.metadata ? { ...options.metadata } : {};
2598
+ if (!this.metadata.source) {
2599
+ const stack = new Error().stack;
2600
+ const sourceInfo = getSourceFileFromStack(stack);
2601
+ if (sourceInfo) {
2602
+ this.metadata.source = { file: sourceInfo };
2603
+ }
2604
+ }
2605
+ const materializedViews = getMooseInternal().materializedViews;
2606
+ if (!isClientOnlyMode() && materializedViews.has(this.name)) {
2607
+ throw new Error(`MaterializedView with name ${this.name} already exists`);
2608
+ }
2609
+ materializedViews.set(this.name, this);
2610
+ }
2611
+ };
2612
+ }
2613
+ });
2614
+
2543
2615
  // src/dmv2/sdk/sqlResource.ts
2544
2616
  var SqlResource;
2545
2617
  var init_sqlResource = __esm({
@@ -2603,104 +2675,52 @@ var init_sqlResource = __esm({
2603
2675
  }
2604
2676
  });
2605
2677
 
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
2678
  // src/dmv2/sdk/view.ts
2675
2679
  var View;
2676
2680
  var init_view = __esm({
2677
2681
  "src/dmv2/sdk/view.ts"() {
2678
2682
  "use strict";
2679
- init_helpers();
2680
2683
  init_sqlHelpers();
2681
- init_sqlResource();
2682
- View = class extends SqlResource {
2684
+ init_internal();
2685
+ init_stackTrace();
2686
+ View = class {
2687
+ /** @internal */
2688
+ kind = "CustomView";
2689
+ /** The name of the view */
2690
+ name;
2691
+ /** The SELECT SQL statement that defines the view */
2692
+ selectSql;
2693
+ /** Names of source tables/views that the SELECT reads from */
2694
+ sourceTables;
2695
+ /** Optional metadata for the view */
2696
+ metadata;
2683
2697
  /**
2684
2698
  * Creates a new View instance.
2685
2699
  * @param name The name of the view to be created.
2686
2700
  * @param selectStatement The SQL SELECT statement that defines the view's logic.
2687
2701
  * @param baseTables An array of OlapTable or View objects that the `selectStatement` reads from. Used for dependency tracking.
2702
+ * @param metadata Optional metadata for the view (e.g., description, source file).
2688
2703
  */
2689
- constructor(name, selectStatement, baseTables) {
2704
+ constructor(name, selectStatement, baseTables, metadata) {
2690
2705
  if (typeof selectStatement !== "string") {
2691
2706
  selectStatement = toStaticQuery(selectStatement);
2692
2707
  }
2693
- super(
2694
- name,
2695
- [
2696
- `CREATE VIEW IF NOT EXISTS ${name}
2697
- AS ${selectStatement}`.trim()
2698
- ],
2699
- [dropView(name)],
2700
- {
2701
- pullsDataFrom: baseTables
2708
+ this.name = name;
2709
+ this.selectSql = selectStatement;
2710
+ this.sourceTables = baseTables.map((t) => t.name);
2711
+ this.metadata = metadata ? { ...metadata } : {};
2712
+ if (!this.metadata.source) {
2713
+ const stack = new Error().stack;
2714
+ const sourceInfo = getSourceFileFromStack(stack);
2715
+ if (sourceInfo) {
2716
+ this.metadata.source = { file: sourceInfo };
2702
2717
  }
2703
- );
2718
+ }
2719
+ const customViews = getMooseInternal().customViews;
2720
+ if (!isClientOnlyMode() && customViews.has(this.name)) {
2721
+ throw new Error(`View with name ${this.name} already exists`);
2722
+ }
2723
+ customViews.set(this.name, this);
2704
2724
  }
2705
2725
  };
2706
2726
  }
@@ -2904,6 +2924,18 @@ function getWebApps2() {
2904
2924
  function getWebApp(name) {
2905
2925
  return getMooseInternal().webApps.get(name);
2906
2926
  }
2927
+ function getMaterializedViews() {
2928
+ return getMooseInternal().materializedViews;
2929
+ }
2930
+ function getMaterializedView(name) {
2931
+ return getMooseInternal().materializedViews.get(name);
2932
+ }
2933
+ function getCustomViews() {
2934
+ return getMooseInternal().customViews;
2935
+ }
2936
+ function getCustomView(name) {
2937
+ return getMooseInternal().customViews.get(name);
2938
+ }
2907
2939
  var init_registry = __esm({
2908
2940
  "src/dmv2/registry.ts"() {
2909
2941
  "use strict";
@@ -2960,8 +2992,12 @@ export {
2960
2992
  createClickhouseParameter,
2961
2993
  getApi,
2962
2994
  getApis2 as getApis,
2995
+ getCustomView,
2996
+ getCustomViews,
2963
2997
  getIngestApi,
2964
2998
  getIngestApis,
2999
+ getMaterializedView,
3000
+ getMaterializedViews,
2965
3001
  getSqlResource,
2966
3002
  getSqlResources,
2967
3003
  getStream,