@514labs/moose-lib 0.6.266-ci-8-ge6e86870 → 0.6.267

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.
@@ -636,6 +636,16 @@ function emptyIfUndefined(value) {
636
636
  return value === void 0 ? "" : value;
637
637
  }
638
638
 
639
+ // src/blocks/helpers.ts
640
+ function dropView(name) {
641
+ return `DROP VIEW IF EXISTS ${quoteIdentifier(name)}`.trim();
642
+ }
643
+ function createMaterializedView(options) {
644
+ return `CREATE MATERIALIZED VIEW IF NOT EXISTS ${quoteIdentifier(options.name)}
645
+ TO ${quoteIdentifier(options.destinationTable)}
646
+ AS ${options.select}`.trim();
647
+ }
648
+
639
649
  // src/dmv2/internal.ts
640
650
  import process2 from "process";
641
651
 
@@ -689,9 +699,7 @@ var moose_internal = {
689
699
  apis: /* @__PURE__ */ new Map(),
690
700
  sqlResources: /* @__PURE__ */ new Map(),
691
701
  workflows: /* @__PURE__ */ new Map(),
692
- webApps: /* @__PURE__ */ new Map(),
693
- materializedViews: /* @__PURE__ */ new Map(),
694
- customViews: /* @__PURE__ */ new Map()
702
+ webApps: /* @__PURE__ */ new Map()
695
703
  };
696
704
  var defaultRetentionPeriod = 60 * 60 * 24 * 7;
697
705
  var getMooseInternal = () => globalThis.moose_internal;
@@ -2318,67 +2326,6 @@ var ETLPipeline = class {
2318
2326
  }
2319
2327
  };
2320
2328
 
2321
- // src/dmv2/sdk/materializedView.ts
2322
- var requireTargetTableName = (tableName) => {
2323
- if (typeof tableName === "string") {
2324
- return tableName;
2325
- } else {
2326
- throw new Error("Name of targetTable is not specified.");
2327
- }
2328
- };
2329
- var MaterializedView = class {
2330
- /** @internal */
2331
- kind = "MaterializedView";
2332
- /** The name of the materialized view */
2333
- name;
2334
- /** The target OlapTable instance where the materialized data is stored. */
2335
- targetTable;
2336
- /** The SELECT SQL statement */
2337
- selectSql;
2338
- /** Names of source tables that the SELECT reads from */
2339
- sourceTables;
2340
- /** @internal Source file path where this MV was defined */
2341
- sourceFile;
2342
- constructor(options, targetSchema, targetColumns) {
2343
- let selectStatement = options.selectStatement;
2344
- if (typeof selectStatement !== "string") {
2345
- selectStatement = toStaticQuery(selectStatement);
2346
- }
2347
- if (targetSchema === void 0 || targetColumns === void 0) {
2348
- throw new Error(
2349
- "Supply the type param T so that the schema is inserted by the compiler plugin."
2350
- );
2351
- }
2352
- const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2353
- requireTargetTableName(
2354
- options.targetTable?.name ?? options.tableName
2355
- ),
2356
- {
2357
- orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2358
- engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2359
- },
2360
- targetSchema,
2361
- targetColumns
2362
- );
2363
- if (targetTable.name === options.materializedViewName) {
2364
- throw new Error(
2365
- "Materialized view name cannot be the same as the target table name."
2366
- );
2367
- }
2368
- this.name = options.materializedViewName;
2369
- this.targetTable = targetTable;
2370
- this.selectSql = selectStatement;
2371
- this.sourceTables = options.selectTables.map((t) => t.name);
2372
- const stack = new Error().stack;
2373
- this.sourceFile = getSourceFileFromStack(stack);
2374
- const materializedViews = getMooseInternal().materializedViews;
2375
- if (!isClientOnlyMode() && materializedViews.has(this.name)) {
2376
- throw new Error(`MaterializedView with name ${this.name} already exists`);
2377
- }
2378
- materializedViews.set(this.name, this);
2379
- }
2380
- };
2381
-
2382
2329
  // src/dmv2/sdk/sqlResource.ts
2383
2330
  var SqlResource = class {
2384
2331
  /** @internal */
@@ -2433,18 +2380,66 @@ var SqlResource = class {
2433
2380
  }
2434
2381
  };
2435
2382
 
2383
+ // src/dmv2/sdk/materializedView.ts
2384
+ var requireTargetTableName = (tableName) => {
2385
+ if (typeof tableName === "string") {
2386
+ return tableName;
2387
+ } else {
2388
+ throw new Error("Name of targetTable is not specified.");
2389
+ }
2390
+ };
2391
+ var MaterializedView = class extends SqlResource {
2392
+ /** The target OlapTable instance where the materialized data is stored. */
2393
+ targetTable;
2394
+ constructor(options, targetSchema, targetColumns) {
2395
+ let selectStatement = options.selectStatement;
2396
+ if (typeof selectStatement !== "string") {
2397
+ selectStatement = toStaticQuery(selectStatement);
2398
+ }
2399
+ if (targetSchema === void 0 || targetColumns === void 0) {
2400
+ throw new Error(
2401
+ "Supply the type param T so that the schema is inserted by the compiler plugin."
2402
+ );
2403
+ }
2404
+ const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2405
+ requireTargetTableName(
2406
+ options.targetTable?.name ?? options.tableName
2407
+ ),
2408
+ {
2409
+ orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2410
+ engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2411
+ },
2412
+ targetSchema,
2413
+ targetColumns
2414
+ );
2415
+ if (targetTable.name === options.materializedViewName) {
2416
+ throw new Error(
2417
+ "Materialized view name cannot be the same as the target table name."
2418
+ );
2419
+ }
2420
+ super(
2421
+ options.materializedViewName,
2422
+ [
2423
+ createMaterializedView({
2424
+ name: options.materializedViewName,
2425
+ destinationTable: targetTable.name,
2426
+ select: selectStatement
2427
+ })
2428
+ // Population is now handled automatically by Rust infrastructure
2429
+ // based on table engine type and whether this is a new or updated view
2430
+ ],
2431
+ [dropView(options.materializedViewName)],
2432
+ {
2433
+ pullsDataFrom: options.selectTables,
2434
+ pushesDataTo: [targetTable]
2435
+ }
2436
+ );
2437
+ this.targetTable = targetTable;
2438
+ }
2439
+ };
2440
+
2436
2441
  // src/dmv2/sdk/view.ts
2437
- var View = class {
2438
- /** @internal */
2439
- kind = "CustomView";
2440
- /** The name of the view */
2441
- name;
2442
- /** The SELECT SQL statement that defines the view */
2443
- selectSql;
2444
- /** Names of source tables/views that the SELECT reads from */
2445
- sourceTables;
2446
- /** @internal Source file path where this view was defined */
2447
- sourceFile;
2442
+ var View = class extends SqlResource {
2448
2443
  /**
2449
2444
  * Creates a new View instance.
2450
2445
  * @param name The name of the view to be created.
@@ -2455,16 +2450,17 @@ var View = class {
2455
2450
  if (typeof selectStatement !== "string") {
2456
2451
  selectStatement = toStaticQuery(selectStatement);
2457
2452
  }
2458
- this.name = name;
2459
- this.selectSql = selectStatement;
2460
- this.sourceTables = baseTables.map((t) => t.name);
2461
- const stack = new Error().stack;
2462
- this.sourceFile = getSourceFileFromStack(stack);
2463
- const customViews = getMooseInternal().customViews;
2464
- if (!isClientOnlyMode() && customViews.has(this.name)) {
2465
- throw new Error(`View with name ${this.name} already exists`);
2466
- }
2467
- customViews.set(this.name, this);
2453
+ super(
2454
+ name,
2455
+ [
2456
+ `CREATE VIEW IF NOT EXISTS ${name}
2457
+ AS ${selectStatement}`.trim()
2458
+ ],
2459
+ [dropView(name)],
2460
+ {
2461
+ pullsDataFrom: baseTables
2462
+ }
2463
+ );
2468
2464
  }
2469
2465
  };
2470
2466