@514labs/moose-lib 0.6.279-ci-2-g69faf7b6 → 0.6.280

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
@@ -692,9 +692,7 @@ var moose_internal = {
692
692
  apis: /* @__PURE__ */ new Map(),
693
693
  sqlResources: /* @__PURE__ */ new Map(),
694
694
  workflows: /* @__PURE__ */ new Map(),
695
- webApps: /* @__PURE__ */ new Map(),
696
- materializedViews: /* @__PURE__ */ new Map(),
697
- customViews: /* @__PURE__ */ new Map()
695
+ webApps: /* @__PURE__ */ new Map()
698
696
  };
699
697
  var defaultRetentionPeriod = 60 * 60 * 24 * 7;
700
698
  var getMooseInternal = () => globalThis.moose_internal;
@@ -710,8 +708,6 @@ var loadIndex = () => {
710
708
  registry.sqlResources.clear();
711
709
  registry.workflows.clear();
712
710
  registry.webApps.clear();
713
- registry.materializedViews.clear();
714
- registry.customViews.clear();
715
711
  const appDir = `${process2.cwd()}/${getSourceDir()}`;
716
712
  Object.keys(__require.cache).forEach((key) => {
717
713
  if (key.startsWith(appDir)) {
@@ -2358,67 +2354,6 @@ var ETLPipeline = class {
2358
2354
  }
2359
2355
  };
2360
2356
 
2361
- // src/dmv2/sdk/materializedView.ts
2362
- var requireTargetTableName = (tableName) => {
2363
- if (typeof tableName === "string") {
2364
- return tableName;
2365
- } else {
2366
- throw new Error("Name of targetTable is not specified.");
2367
- }
2368
- };
2369
- var MaterializedView = class {
2370
- /** @internal */
2371
- kind = "MaterializedView";
2372
- /** The name of the materialized view */
2373
- name;
2374
- /** The target OlapTable instance where the materialized data is stored. */
2375
- targetTable;
2376
- /** The SELECT SQL statement */
2377
- selectSql;
2378
- /** Names of source tables that the SELECT reads from */
2379
- sourceTables;
2380
- /** @internal Source file path where this MV was defined */
2381
- sourceFile;
2382
- constructor(options, targetSchema, targetColumns) {
2383
- let selectStatement = options.selectStatement;
2384
- if (typeof selectStatement !== "string") {
2385
- selectStatement = toStaticQuery(selectStatement);
2386
- }
2387
- if (targetSchema === void 0 || targetColumns === void 0) {
2388
- throw new Error(
2389
- "Supply the type param T so that the schema is inserted by the compiler plugin."
2390
- );
2391
- }
2392
- const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2393
- requireTargetTableName(
2394
- options.targetTable?.name ?? options.tableName
2395
- ),
2396
- {
2397
- orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2398
- engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2399
- },
2400
- targetSchema,
2401
- targetColumns
2402
- );
2403
- if (targetTable.name === options.materializedViewName) {
2404
- throw new Error(
2405
- "Materialized view name cannot be the same as the target table name."
2406
- );
2407
- }
2408
- this.name = options.materializedViewName;
2409
- this.targetTable = targetTable;
2410
- this.selectSql = selectStatement;
2411
- this.sourceTables = options.selectTables.map((t) => t.name);
2412
- const stack = new Error().stack;
2413
- this.sourceFile = getSourceFileFromStack(stack);
2414
- const materializedViews = getMooseInternal().materializedViews;
2415
- if (!isClientOnlyMode() && materializedViews.has(this.name)) {
2416
- throw new Error(`MaterializedView with name ${this.name} already exists`);
2417
- }
2418
- materializedViews.set(this.name, this);
2419
- }
2420
- };
2421
-
2422
2357
  // src/dmv2/sdk/sqlResource.ts
2423
2358
  var SqlResource = class {
2424
2359
  /** @internal */
@@ -2473,18 +2408,66 @@ var SqlResource = class {
2473
2408
  }
2474
2409
  };
2475
2410
 
2411
+ // src/dmv2/sdk/materializedView.ts
2412
+ var requireTargetTableName = (tableName) => {
2413
+ if (typeof tableName === "string") {
2414
+ return tableName;
2415
+ } else {
2416
+ throw new Error("Name of targetTable is not specified.");
2417
+ }
2418
+ };
2419
+ var MaterializedView = class extends SqlResource {
2420
+ /** The target OlapTable instance where the materialized data is stored. */
2421
+ targetTable;
2422
+ constructor(options, targetSchema, targetColumns) {
2423
+ let selectStatement = options.selectStatement;
2424
+ if (typeof selectStatement !== "string") {
2425
+ selectStatement = toStaticQuery(selectStatement);
2426
+ }
2427
+ if (targetSchema === void 0 || targetColumns === void 0) {
2428
+ throw new Error(
2429
+ "Supply the type param T so that the schema is inserted by the compiler plugin."
2430
+ );
2431
+ }
2432
+ const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2433
+ requireTargetTableName(
2434
+ options.targetTable?.name ?? options.tableName
2435
+ ),
2436
+ {
2437
+ orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2438
+ engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2439
+ },
2440
+ targetSchema,
2441
+ targetColumns
2442
+ );
2443
+ if (targetTable.name === options.materializedViewName) {
2444
+ throw new Error(
2445
+ "Materialized view name cannot be the same as the target table name."
2446
+ );
2447
+ }
2448
+ super(
2449
+ options.materializedViewName,
2450
+ [
2451
+ createMaterializedView({
2452
+ name: options.materializedViewName,
2453
+ destinationTable: targetTable.name,
2454
+ select: selectStatement
2455
+ })
2456
+ // Population is now handled automatically by Rust infrastructure
2457
+ // based on table engine type and whether this is a new or updated view
2458
+ ],
2459
+ [dropView(options.materializedViewName)],
2460
+ {
2461
+ pullsDataFrom: options.selectTables,
2462
+ pushesDataTo: [targetTable]
2463
+ }
2464
+ );
2465
+ this.targetTable = targetTable;
2466
+ }
2467
+ };
2468
+
2476
2469
  // src/dmv2/sdk/view.ts
2477
- var View = class {
2478
- /** @internal */
2479
- kind = "CustomView";
2480
- /** The name of the view */
2481
- name;
2482
- /** The SELECT SQL statement that defines the view */
2483
- selectSql;
2484
- /** Names of source tables/views that the SELECT reads from */
2485
- sourceTables;
2486
- /** @internal Source file path where this view was defined */
2487
- sourceFile;
2470
+ var View = class extends SqlResource {
2488
2471
  /**
2489
2472
  * Creates a new View instance.
2490
2473
  * @param name The name of the view to be created.
@@ -2495,16 +2478,17 @@ var View = class {
2495
2478
  if (typeof selectStatement !== "string") {
2496
2479
  selectStatement = toStaticQuery(selectStatement);
2497
2480
  }
2498
- this.name = name;
2499
- this.selectSql = selectStatement;
2500
- this.sourceTables = baseTables.map((t) => t.name);
2501
- const stack = new Error().stack;
2502
- this.sourceFile = getSourceFileFromStack(stack);
2503
- const customViews = getMooseInternal().customViews;
2504
- if (!isClientOnlyMode() && customViews.has(this.name)) {
2505
- throw new Error(`View with name ${this.name} already exists`);
2506
- }
2507
- customViews.set(this.name, this);
2481
+ super(
2482
+ name,
2483
+ [
2484
+ `CREATE VIEW IF NOT EXISTS ${name}
2485
+ AS ${selectStatement}`.trim()
2486
+ ],
2487
+ [dropView(name)],
2488
+ {
2489
+ pullsDataFrom: baseTables
2490
+ }
2491
+ );
2508
2492
  }
2509
2493
  };
2510
2494