@514labs/moose-lib 0.6.297-ci-22-g1be0de24 → 0.6.297-ci-35-g4e0a867f

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
- customViews: /* @__PURE__ */ new Map()
577
+ webApps: /* @__PURE__ */ new Map()
572
578
  };
573
579
  defaultRetentionPeriod = 60 * 60 * 24 * 7;
574
580
  getMooseInternal = () => globalThis.moose_internal;
@@ -2449,78 +2455,6 @@ var init_etlPipeline = __esm({
2449
2455
  }
2450
2456
  });
2451
2457
 
2452
- // src/dmv2/sdk/materializedView.ts
2453
- var requireTargetTableName, MaterializedView;
2454
- var init_materializedView = __esm({
2455
- "src/dmv2/sdk/materializedView.ts"() {
2456
- "use strict";
2457
- init_helpers();
2458
- init_sqlHelpers();
2459
- init_olapTable();
2460
- init_internal();
2461
- init_stackTrace();
2462
- requireTargetTableName = (tableName) => {
2463
- if (typeof tableName === "string") {
2464
- return tableName;
2465
- } else {
2466
- throw new Error("Name of targetTable is not specified.");
2467
- }
2468
- };
2469
- MaterializedView = class {
2470
- /** @internal */
2471
- kind = "MaterializedView";
2472
- /** The name of the materialized view */
2473
- name;
2474
- /** The target OlapTable instance where the materialized data is stored. */
2475
- targetTable;
2476
- /** The SELECT SQL statement */
2477
- selectSql;
2478
- /** Names of source tables that the SELECT reads from */
2479
- sourceTables;
2480
- /** @internal Source file path where this MV was defined */
2481
- sourceFile;
2482
- constructor(options, targetSchema, targetColumns) {
2483
- let selectStatement = options.selectStatement;
2484
- if (typeof selectStatement !== "string") {
2485
- selectStatement = toStaticQuery(selectStatement);
2486
- }
2487
- if (targetSchema === void 0 || targetColumns === void 0) {
2488
- throw new Error(
2489
- "Supply the type param T so that the schema is inserted by the compiler plugin."
2490
- );
2491
- }
2492
- const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2493
- requireTargetTableName(
2494
- options.targetTable?.name ?? options.tableName
2495
- ),
2496
- {
2497
- orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2498
- engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2499
- },
2500
- targetSchema,
2501
- targetColumns
2502
- );
2503
- if (targetTable.name === options.materializedViewName) {
2504
- throw new Error(
2505
- "Materialized view name cannot be the same as the target table name."
2506
- );
2507
- }
2508
- this.name = options.materializedViewName;
2509
- this.targetTable = targetTable;
2510
- this.selectSql = selectStatement;
2511
- this.sourceTables = options.selectTables.map((t) => t.name);
2512
- const stack = new Error().stack;
2513
- this.sourceFile = getSourceFileFromStack(stack);
2514
- const materializedViews = getMooseInternal().materializedViews;
2515
- if (!isClientOnlyMode() && materializedViews.has(this.name)) {
2516
- throw new Error(`MaterializedView with name ${this.name} already exists`);
2517
- }
2518
- materializedViews.set(this.name, this);
2519
- }
2520
- };
2521
- }
2522
- });
2523
-
2524
2458
  // src/dmv2/sdk/sqlResource.ts
2525
2459
  var SqlResource;
2526
2460
  var init_sqlResource = __esm({
@@ -2584,25 +2518,83 @@ var init_sqlResource = __esm({
2584
2518
  }
2585
2519
  });
2586
2520
 
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
+ };
2586
+ }
2587
+ });
2588
+
2587
2589
  // src/dmv2/sdk/view.ts
2588
2590
  var View;
2589
2591
  var init_view = __esm({
2590
2592
  "src/dmv2/sdk/view.ts"() {
2591
2593
  "use strict";
2594
+ init_helpers();
2592
2595
  init_sqlHelpers();
2593
- init_internal();
2594
- init_stackTrace();
2595
- View = class {
2596
- /** @internal */
2597
- kind = "CustomView";
2598
- /** The name of the view */
2599
- name;
2600
- /** The SELECT SQL statement that defines the view */
2601
- selectSql;
2602
- /** Names of source tables/views that the SELECT reads from */
2603
- sourceTables;
2604
- /** @internal Source file path where this view was defined */
2605
- sourceFile;
2596
+ init_sqlResource();
2597
+ View = class extends SqlResource {
2606
2598
  /**
2607
2599
  * Creates a new View instance.
2608
2600
  * @param name The name of the view to be created.
@@ -2613,16 +2605,17 @@ var init_view = __esm({
2613
2605
  if (typeof selectStatement !== "string") {
2614
2606
  selectStatement = toStaticQuery(selectStatement);
2615
2607
  }
2616
- this.name = name;
2617
- this.selectSql = selectStatement;
2618
- this.sourceTables = baseTables.map((t) => t.name);
2619
- const stack = new Error().stack;
2620
- this.sourceFile = getSourceFileFromStack(stack);
2621
- const customViews = getMooseInternal().customViews;
2622
- if (!isClientOnlyMode() && customViews.has(this.name)) {
2623
- throw new Error(`View with name ${this.name} already exists`);
2624
- }
2625
- customViews.set(this.name, this);
2608
+ super(
2609
+ name,
2610
+ [
2611
+ `CREATE VIEW IF NOT EXISTS ${name}
2612
+ AS ${selectStatement}`.trim()
2613
+ ],
2614
+ [dropView(name)],
2615
+ {
2616
+ pullsDataFrom: baseTables
2617
+ }
2618
+ );
2626
2619
  }
2627
2620
  };
2628
2621
  }
@@ -2826,18 +2819,6 @@ function getWebApps() {
2826
2819
  function getWebApp(name) {
2827
2820
  return getMooseInternal().webApps.get(name);
2828
2821
  }
2829
- function getMaterializedViews() {
2830
- return getMooseInternal().materializedViews;
2831
- }
2832
- function getMaterializedView(name) {
2833
- return getMooseInternal().materializedViews.get(name);
2834
- }
2835
- function getCustomViews() {
2836
- return getMooseInternal().customViews;
2837
- }
2838
- function getCustomView(name) {
2839
- return getMooseInternal().customViews.get(name);
2840
- }
2841
2822
  var init_registry = __esm({
2842
2823
  "src/dmv2/registry.ts"() {
2843
2824
  "use strict";
@@ -2882,12 +2863,8 @@ export {
2882
2863
  Workflow,
2883
2864
  getApi,
2884
2865
  getApis,
2885
- getCustomView,
2886
- getCustomViews,
2887
2866
  getIngestApi,
2888
2867
  getIngestApis,
2889
- getMaterializedView,
2890
- getMaterializedViews,
2891
2868
  getSqlResource,
2892
2869
  getSqlResources,
2893
2870
  getStream,