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

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;
@@ -2326,6 +2318,67 @@ var ETLPipeline = class {
2326
2318
  }
2327
2319
  };
2328
2320
 
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
+
2329
2382
  // src/dmv2/sdk/sqlResource.ts
2330
2383
  var SqlResource = class {
2331
2384
  /** @internal */
@@ -2380,66 +2433,18 @@ var SqlResource = class {
2380
2433
  }
2381
2434
  };
2382
2435
 
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
-
2441
2436
  // src/dmv2/sdk/view.ts
2442
- var View = class extends SqlResource {
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;
2443
2448
  /**
2444
2449
  * Creates a new View instance.
2445
2450
  * @param name The name of the view to be created.
@@ -2450,17 +2455,16 @@ var View = class extends SqlResource {
2450
2455
  if (typeof selectStatement !== "string") {
2451
2456
  selectStatement = toStaticQuery(selectStatement);
2452
2457
  }
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
- );
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);
2464
2468
  }
2465
2469
  };
2466
2470