@514labs/moose-lib 0.6.297 → 0.6.298-ci-38-g9d285107

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.
package/dist/index.js CHANGED
@@ -562,7 +562,9 @@ var init_internal = __esm({
562
562
  apis: /* @__PURE__ */ new Map(),
563
563
  sqlResources: /* @__PURE__ */ new Map(),
564
564
  workflows: /* @__PURE__ */ new Map(),
565
- webApps: /* @__PURE__ */ new Map()
565
+ webApps: /* @__PURE__ */ new Map(),
566
+ materializedViews: /* @__PURE__ */ new Map(),
567
+ views: /* @__PURE__ */ new Map()
566
568
  };
567
569
  defaultRetentionPeriod = 60 * 60 * 24 * 7;
568
570
  getMooseInternal = () => globalThis.moose_internal;
@@ -578,6 +580,8 @@ var init_internal = __esm({
578
580
  registry.sqlResources.clear();
579
581
  registry.workflows.clear();
580
582
  registry.webApps.clear();
583
+ registry.materializedViews.clear();
584
+ registry.views.clear();
581
585
  const appDir = `${import_process.default.cwd()}/${getSourceDir()}`;
582
586
  Object.keys(require.cache).forEach((key) => {
583
587
  if (key.startsWith(appDir)) {
@@ -2476,6 +2480,93 @@ var init_etlPipeline = __esm({
2476
2480
  }
2477
2481
  });
2478
2482
 
2483
+ // src/dmv2/sdk/materializedView.ts
2484
+ function formatTableReference(table) {
2485
+ const database = table instanceof OlapTable ? table.config.database : void 0;
2486
+ if (database) {
2487
+ return `\`${database}\`.\`${table.name}\``;
2488
+ }
2489
+ return `\`${table.name}\``;
2490
+ }
2491
+ var requireTargetTableName, MaterializedView;
2492
+ var init_materializedView = __esm({
2493
+ "src/dmv2/sdk/materializedView.ts"() {
2494
+ "use strict";
2495
+ init_helpers();
2496
+ init_sqlHelpers();
2497
+ init_olapTable();
2498
+ init_internal();
2499
+ init_stackTrace();
2500
+ requireTargetTableName = (tableName) => {
2501
+ if (typeof tableName === "string") {
2502
+ return tableName;
2503
+ } else {
2504
+ throw new Error("Name of targetTable is not specified.");
2505
+ }
2506
+ };
2507
+ MaterializedView = class {
2508
+ /** @internal */
2509
+ kind = "MaterializedView";
2510
+ /** The name of the materialized view */
2511
+ name;
2512
+ /** The target OlapTable instance where the materialized data is stored. */
2513
+ targetTable;
2514
+ /** The SELECT SQL statement */
2515
+ selectSql;
2516
+ /** Names of source tables that the SELECT reads from */
2517
+ sourceTables;
2518
+ /** Optional metadata for the materialized view */
2519
+ metadata;
2520
+ constructor(options, targetSchema, targetColumns) {
2521
+ let selectStatement = options.selectStatement;
2522
+ if (typeof selectStatement !== "string") {
2523
+ selectStatement = toStaticQuery(selectStatement);
2524
+ }
2525
+ if (targetSchema === void 0 || targetColumns === void 0) {
2526
+ throw new Error(
2527
+ "Supply the type param T so that the schema is inserted by the compiler plugin."
2528
+ );
2529
+ }
2530
+ const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2531
+ requireTargetTableName(
2532
+ options.targetTable?.name ?? options.tableName
2533
+ ),
2534
+ {
2535
+ orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2536
+ engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2537
+ },
2538
+ targetSchema,
2539
+ targetColumns
2540
+ );
2541
+ if (targetTable.name === options.materializedViewName) {
2542
+ throw new Error(
2543
+ "Materialized view name cannot be the same as the target table name."
2544
+ );
2545
+ }
2546
+ this.name = options.materializedViewName;
2547
+ this.targetTable = targetTable;
2548
+ this.selectSql = selectStatement;
2549
+ this.sourceTables = options.selectTables.map(
2550
+ (t) => formatTableReference(t)
2551
+ );
2552
+ this.metadata = options.metadata ? { ...options.metadata } : {};
2553
+ if (!this.metadata.source) {
2554
+ const stack = new Error().stack;
2555
+ const sourceInfo = getSourceFileFromStack(stack);
2556
+ if (sourceInfo) {
2557
+ this.metadata.source = { file: sourceInfo };
2558
+ }
2559
+ }
2560
+ const materializedViews = getMooseInternal().materializedViews;
2561
+ if (!isClientOnlyMode() && materializedViews.has(this.name)) {
2562
+ throw new Error(`MaterializedView with name ${this.name} already exists`);
2563
+ }
2564
+ materializedViews.set(this.name, this);
2565
+ }
2566
+ };
2567
+ }
2568
+ });
2569
+
2479
2570
  // src/dmv2/sdk/sqlResource.ts
2480
2571
  var SqlResource;
2481
2572
  var init_sqlResource = __esm({
@@ -2539,104 +2630,60 @@ var init_sqlResource = __esm({
2539
2630
  }
2540
2631
  });
2541
2632
 
2542
- // src/dmv2/sdk/materializedView.ts
2543
- var requireTargetTableName, MaterializedView;
2544
- var init_materializedView = __esm({
2545
- "src/dmv2/sdk/materializedView.ts"() {
2546
- "use strict";
2547
- init_helpers();
2548
- init_sqlHelpers();
2549
- init_olapTable();
2550
- init_sqlResource();
2551
- requireTargetTableName = (tableName) => {
2552
- if (typeof tableName === "string") {
2553
- return tableName;
2554
- } else {
2555
- throw new Error("Name of targetTable is not specified.");
2556
- }
2557
- };
2558
- MaterializedView = class extends SqlResource {
2559
- /** The target OlapTable instance where the materialized data is stored. */
2560
- targetTable;
2561
- constructor(options, targetSchema, targetColumns) {
2562
- let selectStatement = options.selectStatement;
2563
- if (typeof selectStatement !== "string") {
2564
- selectStatement = toStaticQuery(selectStatement);
2565
- }
2566
- if (targetSchema === void 0 || targetColumns === void 0) {
2567
- throw new Error(
2568
- "Supply the type param T so that the schema is inserted by the compiler plugin."
2569
- );
2570
- }
2571
- const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2572
- requireTargetTableName(
2573
- options.targetTable?.name ?? options.tableName
2574
- ),
2575
- {
2576
- orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2577
- engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2578
- },
2579
- targetSchema,
2580
- targetColumns
2581
- );
2582
- if (targetTable.name === options.materializedViewName) {
2583
- throw new Error(
2584
- "Materialized view name cannot be the same as the target table name."
2585
- );
2586
- }
2587
- super(
2588
- options.materializedViewName,
2589
- [
2590
- createMaterializedView({
2591
- name: options.materializedViewName,
2592
- destinationTable: targetTable.name,
2593
- select: selectStatement
2594
- })
2595
- // Population is now handled automatically by Rust infrastructure
2596
- // based on table engine type and whether this is a new or updated view
2597
- ],
2598
- [dropView(options.materializedViewName)],
2599
- {
2600
- pullsDataFrom: options.selectTables,
2601
- pushesDataTo: [targetTable]
2602
- }
2603
- );
2604
- this.targetTable = targetTable;
2605
- }
2606
- };
2607
- }
2608
- });
2609
-
2610
2633
  // src/dmv2/sdk/view.ts
2634
+ function formatTableReference2(table) {
2635
+ const database = table instanceof OlapTable ? table.config.database : void 0;
2636
+ if (database) {
2637
+ return `\`${database}\`.\`${table.name}\``;
2638
+ }
2639
+ return `\`${table.name}\``;
2640
+ }
2611
2641
  var View;
2612
2642
  var init_view = __esm({
2613
2643
  "src/dmv2/sdk/view.ts"() {
2614
2644
  "use strict";
2615
- init_helpers();
2616
2645
  init_sqlHelpers();
2617
- init_sqlResource();
2618
- View = class extends SqlResource {
2646
+ init_olapTable();
2647
+ init_internal();
2648
+ init_stackTrace();
2649
+ View = class {
2650
+ /** @internal */
2651
+ kind = "View";
2652
+ /** The name of the view */
2653
+ name;
2654
+ /** The SELECT SQL statement that defines the view */
2655
+ selectSql;
2656
+ /** Names of source tables/views that the SELECT reads from */
2657
+ sourceTables;
2658
+ /** Optional metadata for the view */
2659
+ metadata;
2619
2660
  /**
2620
2661
  * Creates a new View instance.
2621
2662
  * @param name The name of the view to be created.
2622
2663
  * @param selectStatement The SQL SELECT statement that defines the view's logic.
2623
2664
  * @param baseTables An array of OlapTable or View objects that the `selectStatement` reads from. Used for dependency tracking.
2665
+ * @param metadata Optional metadata for the view (e.g., description, source file).
2624
2666
  */
2625
- constructor(name, selectStatement, baseTables) {
2667
+ constructor(name, selectStatement, baseTables, metadata) {
2626
2668
  if (typeof selectStatement !== "string") {
2627
2669
  selectStatement = toStaticQuery(selectStatement);
2628
2670
  }
2629
- super(
2630
- name,
2631
- [
2632
- `CREATE VIEW IF NOT EXISTS ${name}
2633
- AS ${selectStatement}`.trim()
2634
- ],
2635
- [dropView(name)],
2636
- {
2637
- pullsDataFrom: baseTables
2671
+ this.name = name;
2672
+ this.selectSql = selectStatement;
2673
+ this.sourceTables = baseTables.map((t) => formatTableReference2(t));
2674
+ this.metadata = metadata ? { ...metadata } : {};
2675
+ if (!this.metadata.source) {
2676
+ const stack = new Error().stack;
2677
+ const sourceInfo = getSourceFileFromStack(stack);
2678
+ if (sourceInfo) {
2679
+ this.metadata.source = { file: sourceInfo };
2638
2680
  }
2639
- );
2681
+ }
2682
+ const views = getMooseInternal().views;
2683
+ if (!isClientOnlyMode() && views.has(this.name)) {
2684
+ throw new Error(`View with name ${this.name} already exists`);
2685
+ }
2686
+ views.set(this.name, this);
2640
2687
  }
2641
2688
  };
2642
2689
  }
@@ -2840,6 +2887,18 @@ function getWebApps() {
2840
2887
  function getWebApp(name) {
2841
2888
  return getMooseInternal().webApps.get(name);
2842
2889
  }
2890
+ function getMaterializedViews() {
2891
+ return getMooseInternal().materializedViews;
2892
+ }
2893
+ function getMaterializedView(name) {
2894
+ return getMooseInternal().materializedViews.get(name);
2895
+ }
2896
+ function getViews() {
2897
+ return getMooseInternal().views;
2898
+ }
2899
+ function getView(name) {
2900
+ return getMooseInternal().views.get(name);
2901
+ }
2843
2902
  var init_registry = __esm({
2844
2903
  "src/dmv2/registry.ts"() {
2845
2904
  "use strict";
@@ -3728,6 +3787,8 @@ __export(index_exports, {
3728
3787
  getKafkaClient: () => getKafkaClient,
3729
3788
  getKafkaProducer: () => getKafkaProducer,
3730
3789
  getLegacyMooseUtils: () => getLegacyMooseUtils,
3790
+ getMaterializedView: () => getMaterializedView,
3791
+ getMaterializedViews: () => getMaterializedViews,
3731
3792
  getMooseClients: () => getMooseClients,
3732
3793
  getMooseUtils: () => getMooseUtils,
3733
3794
  getMooseUtilsFromRequest: () => getMooseUtilsFromRequest,
@@ -3739,6 +3800,8 @@ __export(index_exports, {
3739
3800
  getTables: () => getTables,
3740
3801
  getTemporalClient: () => getTemporalClient,
3741
3802
  getValueFromParameter: () => getValueFromParameter,
3803
+ getView: () => getView,
3804
+ getViews: () => getViews,
3742
3805
  getWebApp: () => getWebApp,
3743
3806
  getWebApps: () => getWebApps,
3744
3807
  getWorkflow: () => getWorkflow,
@@ -3836,6 +3899,8 @@ init_index();
3836
3899
  getKafkaClient,
3837
3900
  getKafkaProducer,
3838
3901
  getLegacyMooseUtils,
3902
+ getMaterializedView,
3903
+ getMaterializedViews,
3839
3904
  getMooseClients,
3840
3905
  getMooseUtils,
3841
3906
  getMooseUtilsFromRequest,
@@ -3847,6 +3912,8 @@ init_index();
3847
3912
  getTables,
3848
3913
  getTemporalClient,
3849
3914
  getValueFromParameter,
3915
+ getView,
3916
+ getViews,
3850
3917
  getWebApp,
3851
3918
  getWebApps,
3852
3919
  getWorkflow,