@514labs/moose-lib 0.6.279-ci-9-gaf2329aa → 0.6.279-ci-13-g512ec2c0

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