@514labs/moose-lib 0.6.279-ci-3-g3edfe2f6 → 0.6.280-ci-6-g9ba15e89

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.
@@ -362,10 +362,13 @@ var init_runtime = __esm({
362
362
  // src/dmv2/utils/stackTrace.ts
363
363
  function shouldSkipStackLine(line) {
364
364
  return line.includes("node_modules") || // Skip npm installed packages (prod)
365
- line.includes("internal/modules") || // Skip Node.js internals
365
+ line.includes("node:internal") || // Skip Node.js internals (modern format)
366
+ line.includes("internal/modules") || // Skip Node.js internals (older format)
366
367
  line.includes("ts-node") || // Skip TypeScript execution
367
- line.includes("/ts-moose-lib/") || // Skip dev/linked moose-lib (Unix)
368
- line.includes("\\ts-moose-lib\\");
368
+ line.includes("/ts-moose-lib/src/") || // Skip dev/linked moose-lib src (Unix)
369
+ line.includes("\\ts-moose-lib\\src\\") || // Skip dev/linked moose-lib src (Windows)
370
+ line.includes("/ts-moose-lib/dist/") || // Skip dev/linked moose-lib dist (Unix)
371
+ line.includes("\\ts-moose-lib\\dist\\");
369
372
  }
370
373
  function parseStackLine(line) {
371
374
  const match = line.match(/\((.*):(\d+):(\d+)\)/) || line.match(/at (.*):(\d+):(\d+)/);
@@ -468,12 +471,12 @@ var TypedBase = class {
468
471
  this.validators = validators;
469
472
  this.allowExtraFields = allowExtraFields ?? false;
470
473
  this.metadata = config?.metadata ? { ...config.metadata } : {};
471
- const stack = new Error().stack;
472
- if (stack) {
473
- const info = getSourceFileInfo(stack);
474
- this.metadata.source = { file: info.file, line: info.line };
475
- } else {
476
- this.metadata.source = void 0;
474
+ if (!this.metadata.source) {
475
+ const stack = new Error().stack;
476
+ if (stack) {
477
+ const info = getSourceFileInfo(stack);
478
+ this.metadata.source = { file: info.file, line: info.line };
479
+ }
477
480
  }
478
481
  }
479
482
  };
@@ -636,6 +639,16 @@ function emptyIfUndefined(value) {
636
639
  return value === void 0 ? "" : value;
637
640
  }
638
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
+
639
652
  // src/dmv2/internal.ts
640
653
  import process2 from "process";
641
654
 
@@ -689,9 +702,7 @@ var moose_internal = {
689
702
  apis: /* @__PURE__ */ new Map(),
690
703
  sqlResources: /* @__PURE__ */ new Map(),
691
704
  workflows: /* @__PURE__ */ new Map(),
692
- webApps: /* @__PURE__ */ new Map(),
693
- materializedViews: /* @__PURE__ */ new Map(),
694
- customViews: /* @__PURE__ */ new Map()
705
+ webApps: /* @__PURE__ */ new Map()
695
706
  };
696
707
  var defaultRetentionPeriod = 60 * 60 * 24 * 7;
697
708
  var getMooseInternal = () => globalThis.moose_internal;
@@ -2320,67 +2331,6 @@ var ETLPipeline = class {
2320
2331
  }
2321
2332
  };
2322
2333
 
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
-
2384
2334
  // src/dmv2/sdk/sqlResource.ts
2385
2335
  var SqlResource = class {
2386
2336
  /** @internal */
@@ -2435,18 +2385,66 @@ var SqlResource = class {
2435
2385
  }
2436
2386
  };
2437
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
+
2438
2446
  // src/dmv2/sdk/view.ts
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;
2447
+ var View = class extends SqlResource {
2450
2448
  /**
2451
2449
  * Creates a new View instance.
2452
2450
  * @param name The name of the view to be created.
@@ -2457,16 +2455,17 @@ var View = class {
2457
2455
  if (typeof selectStatement !== "string") {
2458
2456
  selectStatement = toStaticQuery(selectStatement);
2459
2457
  }
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);
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
+ );
2470
2469
  }
2471
2470
  };
2472
2471