@514labs/moose-lib 0.6.284-ci-4-g1a9baa0b → 0.6.284-ci-1-gd8150d90

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