@514labs/moose-lib 0.6.297-ci-34-g865e2d1a → 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.
@@ -217,14 +217,6 @@ 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
- }
228
220
  var init_helpers = __esm({
229
221
  "src/blocks/helpers.ts"() {
230
222
  "use strict";
@@ -574,7 +566,9 @@ var init_internal = __esm({
574
566
  apis: /* @__PURE__ */ new Map(),
575
567
  sqlResources: /* @__PURE__ */ new Map(),
576
568
  workflows: /* @__PURE__ */ new Map(),
577
- webApps: /* @__PURE__ */ new Map()
569
+ webApps: /* @__PURE__ */ new Map(),
570
+ materializedViews: /* @__PURE__ */ new Map(),
571
+ customViews: /* @__PURE__ */ new Map()
578
572
  };
579
573
  defaultRetentionPeriod = 60 * 60 * 24 * 7;
580
574
  getMooseInternal = () => globalThis.moose_internal;
@@ -2455,6 +2449,78 @@ var init_etlPipeline = __esm({
2455
2449
  }
2456
2450
  });
2457
2451
 
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
+
2458
2524
  // src/dmv2/sdk/sqlResource.ts
2459
2525
  var SqlResource;
2460
2526
  var init_sqlResource = __esm({
@@ -2518,83 +2584,25 @@ var init_sqlResource = __esm({
2518
2584
  }
2519
2585
  });
2520
2586
 
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
-
2589
2587
  // src/dmv2/sdk/view.ts
2590
2588
  var View;
2591
2589
  var init_view = __esm({
2592
2590
  "src/dmv2/sdk/view.ts"() {
2593
2591
  "use strict";
2594
- init_helpers();
2595
2592
  init_sqlHelpers();
2596
- init_sqlResource();
2597
- View = class extends SqlResource {
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;
2598
2606
  /**
2599
2607
  * Creates a new View instance.
2600
2608
  * @param name The name of the view to be created.
@@ -2605,17 +2613,16 @@ var init_view = __esm({
2605
2613
  if (typeof selectStatement !== "string") {
2606
2614
  selectStatement = toStaticQuery(selectStatement);
2607
2615
  }
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
- );
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);
2619
2626
  }
2620
2627
  };
2621
2628
  }
@@ -2819,6 +2826,18 @@ function getWebApps() {
2819
2826
  function getWebApp(name) {
2820
2827
  return getMooseInternal().webApps.get(name);
2821
2828
  }
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
+ }
2822
2841
  var init_registry = __esm({
2823
2842
  "src/dmv2/registry.ts"() {
2824
2843
  "use strict";
@@ -2863,8 +2882,12 @@ export {
2863
2882
  Workflow,
2864
2883
  getApi,
2865
2884
  getApis,
2885
+ getCustomView,
2886
+ getCustomViews,
2866
2887
  getIngestApi,
2867
2888
  getIngestApis,
2889
+ getMaterializedView,
2890
+ getMaterializedViews,
2868
2891
  getSqlResource,
2869
2892
  getSqlResources,
2870
2893
  getStream,