@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.
package/dist/index.mjs CHANGED
@@ -546,7 +546,9 @@ var init_internal = __esm({
546
546
  apis: /* @__PURE__ */ new Map(),
547
547
  sqlResources: /* @__PURE__ */ new Map(),
548
548
  workflows: /* @__PURE__ */ new Map(),
549
- webApps: /* @__PURE__ */ new Map()
549
+ webApps: /* @__PURE__ */ new Map(),
550
+ materializedViews: /* @__PURE__ */ new Map(),
551
+ customViews: /* @__PURE__ */ new Map()
550
552
  };
551
553
  defaultRetentionPeriod = 60 * 60 * 24 * 7;
552
554
  getMooseInternal = () => globalThis.moose_internal;
@@ -562,6 +564,8 @@ var init_internal = __esm({
562
564
  registry.sqlResources.clear();
563
565
  registry.workflows.clear();
564
566
  registry.webApps.clear();
567
+ registry.materializedViews.clear();
568
+ registry.customViews.clear();
565
569
  const appDir = `${process2.cwd()}/${getSourceDir()}`;
566
570
  Object.keys(__require.cache).forEach((key) => {
567
571
  if (key.startsWith(appDir)) {
@@ -2460,6 +2464,78 @@ var init_etlPipeline = __esm({
2460
2464
  }
2461
2465
  });
2462
2466
 
2467
+ // src/dmv2/sdk/materializedView.ts
2468
+ var requireTargetTableName, MaterializedView;
2469
+ var init_materializedView = __esm({
2470
+ "src/dmv2/sdk/materializedView.ts"() {
2471
+ "use strict";
2472
+ init_helpers();
2473
+ init_sqlHelpers();
2474
+ init_olapTable();
2475
+ init_internal();
2476
+ init_stackTrace();
2477
+ requireTargetTableName = (tableName) => {
2478
+ if (typeof tableName === "string") {
2479
+ return tableName;
2480
+ } else {
2481
+ throw new Error("Name of targetTable is not specified.");
2482
+ }
2483
+ };
2484
+ MaterializedView = class {
2485
+ /** @internal */
2486
+ kind = "MaterializedView";
2487
+ /** The name of the materialized view */
2488
+ name;
2489
+ /** The target OlapTable instance where the materialized data is stored. */
2490
+ targetTable;
2491
+ /** The SELECT SQL statement */
2492
+ selectSql;
2493
+ /** Names of source tables that the SELECT reads from */
2494
+ sourceTables;
2495
+ /** @internal Source file path where this MV was defined */
2496
+ sourceFile;
2497
+ constructor(options, targetSchema, targetColumns) {
2498
+ let selectStatement = options.selectStatement;
2499
+ if (typeof selectStatement !== "string") {
2500
+ selectStatement = toStaticQuery(selectStatement);
2501
+ }
2502
+ if (targetSchema === void 0 || targetColumns === void 0) {
2503
+ throw new Error(
2504
+ "Supply the type param T so that the schema is inserted by the compiler plugin."
2505
+ );
2506
+ }
2507
+ const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2508
+ requireTargetTableName(
2509
+ options.targetTable?.name ?? options.tableName
2510
+ ),
2511
+ {
2512
+ orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2513
+ engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2514
+ },
2515
+ targetSchema,
2516
+ targetColumns
2517
+ );
2518
+ if (targetTable.name === options.materializedViewName) {
2519
+ throw new Error(
2520
+ "Materialized view name cannot be the same as the target table name."
2521
+ );
2522
+ }
2523
+ this.name = options.materializedViewName;
2524
+ this.targetTable = targetTable;
2525
+ this.selectSql = selectStatement;
2526
+ this.sourceTables = options.selectTables.map((t) => t.name);
2527
+ const stack = new Error().stack;
2528
+ this.sourceFile = getSourceFileFromStack(stack);
2529
+ const materializedViews = getMooseInternal().materializedViews;
2530
+ if (!isClientOnlyMode() && materializedViews.has(this.name)) {
2531
+ throw new Error(`MaterializedView with name ${this.name} already exists`);
2532
+ }
2533
+ materializedViews.set(this.name, this);
2534
+ }
2535
+ };
2536
+ }
2537
+ });
2538
+
2463
2539
  // src/dmv2/sdk/sqlResource.ts
2464
2540
  var SqlResource;
2465
2541
  var init_sqlResource = __esm({
@@ -2523,83 +2599,25 @@ var init_sqlResource = __esm({
2523
2599
  }
2524
2600
  });
2525
2601
 
2526
- // src/dmv2/sdk/materializedView.ts
2527
- var requireTargetTableName, MaterializedView;
2528
- var init_materializedView = __esm({
2529
- "src/dmv2/sdk/materializedView.ts"() {
2530
- "use strict";
2531
- init_helpers();
2532
- init_sqlHelpers();
2533
- init_olapTable();
2534
- init_sqlResource();
2535
- requireTargetTableName = (tableName) => {
2536
- if (typeof tableName === "string") {
2537
- return tableName;
2538
- } else {
2539
- throw new Error("Name of targetTable is not specified.");
2540
- }
2541
- };
2542
- MaterializedView = class extends SqlResource {
2543
- /** The target OlapTable instance where the materialized data is stored. */
2544
- targetTable;
2545
- constructor(options, targetSchema, targetColumns) {
2546
- let selectStatement = options.selectStatement;
2547
- if (typeof selectStatement !== "string") {
2548
- selectStatement = toStaticQuery(selectStatement);
2549
- }
2550
- if (targetSchema === void 0 || targetColumns === void 0) {
2551
- throw new Error(
2552
- "Supply the type param T so that the schema is inserted by the compiler plugin."
2553
- );
2554
- }
2555
- const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2556
- requireTargetTableName(
2557
- options.targetTable?.name ?? options.tableName
2558
- ),
2559
- {
2560
- orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2561
- engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2562
- },
2563
- targetSchema,
2564
- targetColumns
2565
- );
2566
- if (targetTable.name === options.materializedViewName) {
2567
- throw new Error(
2568
- "Materialized view name cannot be the same as the target table name."
2569
- );
2570
- }
2571
- super(
2572
- options.materializedViewName,
2573
- [
2574
- createMaterializedView({
2575
- name: options.materializedViewName,
2576
- destinationTable: targetTable.name,
2577
- select: selectStatement
2578
- })
2579
- // Population is now handled automatically by Rust infrastructure
2580
- // based on table engine type and whether this is a new or updated view
2581
- ],
2582
- [dropView(options.materializedViewName)],
2583
- {
2584
- pullsDataFrom: options.selectTables,
2585
- pushesDataTo: [targetTable]
2586
- }
2587
- );
2588
- this.targetTable = targetTable;
2589
- }
2590
- };
2591
- }
2592
- });
2593
-
2594
2602
  // src/dmv2/sdk/view.ts
2595
2603
  var View;
2596
2604
  var init_view = __esm({
2597
2605
  "src/dmv2/sdk/view.ts"() {
2598
2606
  "use strict";
2599
- init_helpers();
2600
2607
  init_sqlHelpers();
2601
- init_sqlResource();
2602
- View = class extends SqlResource {
2608
+ init_internal();
2609
+ init_stackTrace();
2610
+ View = class {
2611
+ /** @internal */
2612
+ kind = "CustomView";
2613
+ /** The name of the view */
2614
+ name;
2615
+ /** The SELECT SQL statement that defines the view */
2616
+ selectSql;
2617
+ /** Names of source tables/views that the SELECT reads from */
2618
+ sourceTables;
2619
+ /** @internal Source file path where this view was defined */
2620
+ sourceFile;
2603
2621
  /**
2604
2622
  * Creates a new View instance.
2605
2623
  * @param name The name of the view to be created.
@@ -2610,17 +2628,16 @@ var init_view = __esm({
2610
2628
  if (typeof selectStatement !== "string") {
2611
2629
  selectStatement = toStaticQuery(selectStatement);
2612
2630
  }
2613
- super(
2614
- name,
2615
- [
2616
- `CREATE VIEW IF NOT EXISTS ${name}
2617
- AS ${selectStatement}`.trim()
2618
- ],
2619
- [dropView(name)],
2620
- {
2621
- pullsDataFrom: baseTables
2622
- }
2623
- );
2631
+ this.name = name;
2632
+ this.selectSql = selectStatement;
2633
+ this.sourceTables = baseTables.map((t) => t.name);
2634
+ const stack = new Error().stack;
2635
+ this.sourceFile = getSourceFileFromStack(stack);
2636
+ const customViews = getMooseInternal().customViews;
2637
+ if (!isClientOnlyMode() && customViews.has(this.name)) {
2638
+ throw new Error(`View with name ${this.name} already exists`);
2639
+ }
2640
+ customViews.set(this.name, this);
2624
2641
  }
2625
2642
  };
2626
2643
  }
@@ -2824,6 +2841,18 @@ function getWebApps() {
2824
2841
  function getWebApp(name) {
2825
2842
  return getMooseInternal().webApps.get(name);
2826
2843
  }
2844
+ function getMaterializedViews() {
2845
+ return getMooseInternal().materializedViews;
2846
+ }
2847
+ function getMaterializedView(name) {
2848
+ return getMooseInternal().materializedViews.get(name);
2849
+ }
2850
+ function getCustomViews() {
2851
+ return getMooseInternal().customViews;
2852
+ }
2853
+ function getCustomView(name) {
2854
+ return getMooseInternal().customViews.get(name);
2855
+ }
2827
2856
  var init_registry = __esm({
2828
2857
  "src/dmv2/registry.ts"() {
2829
2858
  "use strict";
@@ -3727,12 +3756,16 @@ export {
3727
3756
  getApi,
3728
3757
  getApis,
3729
3758
  getClickhouseClient,
3759
+ getCustomView,
3760
+ getCustomViews,
3730
3761
  getFileName,
3731
3762
  getIngestApi,
3732
3763
  getIngestApis,
3733
3764
  getKafkaClient,
3734
3765
  getKafkaProducer,
3735
3766
  getLegacyMooseUtils,
3767
+ getMaterializedView,
3768
+ getMaterializedViews,
3736
3769
  getMooseClients,
3737
3770
  getMooseUtils,
3738
3771
  getMooseUtilsFromRequest,