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

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
@@ -368,13 +368,10 @@ var init_runtime = __esm({
368
368
  // src/dmv2/utils/stackTrace.ts
369
369
  function shouldSkipStackLine(line) {
370
370
  return line.includes("node_modules") || // Skip npm installed packages (prod)
371
- line.includes("node:internal") || // Skip Node.js internals (modern format)
372
- line.includes("internal/modules") || // Skip Node.js internals (older format)
371
+ line.includes("internal/modules") || // Skip Node.js internals
373
372
  line.includes("ts-node") || // Skip TypeScript execution
374
- line.includes("/ts-moose-lib/src/") || // Skip dev/linked moose-lib src (Unix)
375
- line.includes("\\ts-moose-lib\\src\\") || // Skip dev/linked moose-lib src (Windows)
376
- line.includes("/ts-moose-lib/dist/") || // Skip dev/linked moose-lib dist (Unix)
377
- line.includes("\\ts-moose-lib\\dist\\");
373
+ line.includes("/ts-moose-lib/") || // Skip dev/linked moose-lib (Unix)
374
+ line.includes("\\ts-moose-lib\\");
378
375
  }
379
376
  function parseStackLine(line) {
380
377
  const match = line.match(/\((.*):(\d+):(\d+)\)/) || line.match(/at (.*):(\d+):(\d+)/);
@@ -477,12 +474,12 @@ var TypedBase = class {
477
474
  this.validators = validators;
478
475
  this.allowExtraFields = allowExtraFields ?? false;
479
476
  this.metadata = config?.metadata ? { ...config.metadata } : {};
480
- if (!this.metadata.source) {
481
- const stack = new Error().stack;
482
- if (stack) {
483
- const info = getSourceFileInfo(stack);
484
- this.metadata.source = { file: info.file, line: info.line };
485
- }
477
+ const stack = new Error().stack;
478
+ if (stack) {
479
+ const info = getSourceFileInfo(stack);
480
+ this.metadata.source = { file: info.file, line: info.line };
481
+ } else {
482
+ this.metadata.source = void 0;
486
483
  }
487
484
  }
488
485
  };
@@ -695,7 +692,9 @@ var moose_internal = {
695
692
  apis: /* @__PURE__ */ new Map(),
696
693
  sqlResources: /* @__PURE__ */ new Map(),
697
694
  workflows: /* @__PURE__ */ new Map(),
698
- webApps: /* @__PURE__ */ new Map()
695
+ webApps: /* @__PURE__ */ new Map(),
696
+ materializedViews: /* @__PURE__ */ new Map(),
697
+ customViews: /* @__PURE__ */ new Map()
699
698
  };
700
699
  var defaultRetentionPeriod = 60 * 60 * 24 * 7;
701
700
  var getMooseInternal = () => globalThis.moose_internal;
@@ -711,6 +710,8 @@ var loadIndex = () => {
711
710
  registry.sqlResources.clear();
712
711
  registry.workflows.clear();
713
712
  registry.webApps.clear();
713
+ registry.materializedViews.clear();
714
+ registry.customViews.clear();
714
715
  const appDir = `${process2.cwd()}/${getSourceDir()}`;
715
716
  Object.keys(__require.cache).forEach((key) => {
716
717
  if (key.startsWith(appDir)) {
@@ -2357,6 +2358,67 @@ var ETLPipeline = class {
2357
2358
  }
2358
2359
  };
2359
2360
 
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
+
2360
2422
  // src/dmv2/sdk/sqlResource.ts
2361
2423
  var SqlResource = class {
2362
2424
  /** @internal */
@@ -2411,66 +2473,18 @@ var SqlResource = class {
2411
2473
  }
2412
2474
  };
2413
2475
 
2414
- // src/dmv2/sdk/materializedView.ts
2415
- var requireTargetTableName = (tableName) => {
2416
- if (typeof tableName === "string") {
2417
- return tableName;
2418
- } else {
2419
- throw new Error("Name of targetTable is not specified.");
2420
- }
2421
- };
2422
- var MaterializedView = class extends SqlResource {
2423
- /** The target OlapTable instance where the materialized data is stored. */
2424
- targetTable;
2425
- constructor(options, targetSchema, targetColumns) {
2426
- let selectStatement = options.selectStatement;
2427
- if (typeof selectStatement !== "string") {
2428
- selectStatement = toStaticQuery(selectStatement);
2429
- }
2430
- if (targetSchema === void 0 || targetColumns === void 0) {
2431
- throw new Error(
2432
- "Supply the type param T so that the schema is inserted by the compiler plugin."
2433
- );
2434
- }
2435
- const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2436
- requireTargetTableName(
2437
- options.targetTable?.name ?? options.tableName
2438
- ),
2439
- {
2440
- orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2441
- engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2442
- },
2443
- targetSchema,
2444
- targetColumns
2445
- );
2446
- if (targetTable.name === options.materializedViewName) {
2447
- throw new Error(
2448
- "Materialized view name cannot be the same as the target table name."
2449
- );
2450
- }
2451
- super(
2452
- options.materializedViewName,
2453
- [
2454
- createMaterializedView({
2455
- name: options.materializedViewName,
2456
- destinationTable: targetTable.name,
2457
- select: selectStatement
2458
- })
2459
- // Population is now handled automatically by Rust infrastructure
2460
- // based on table engine type and whether this is a new or updated view
2461
- ],
2462
- [dropView(options.materializedViewName)],
2463
- {
2464
- pullsDataFrom: options.selectTables,
2465
- pushesDataTo: [targetTable]
2466
- }
2467
- );
2468
- this.targetTable = targetTable;
2469
- }
2470
- };
2471
-
2472
2476
  // src/dmv2/sdk/view.ts
2473
- var View = class extends SqlResource {
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;
2474
2488
  /**
2475
2489
  * Creates a new View instance.
2476
2490
  * @param name The name of the view to be created.
@@ -2481,17 +2495,16 @@ var View = class extends SqlResource {
2481
2495
  if (typeof selectStatement !== "string") {
2482
2496
  selectStatement = toStaticQuery(selectStatement);
2483
2497
  }
2484
- super(
2485
- name,
2486
- [
2487
- `CREATE VIEW IF NOT EXISTS ${name}
2488
- AS ${selectStatement}`.trim()
2489
- ],
2490
- [dropView(name)],
2491
- {
2492
- pullsDataFrom: baseTables
2493
- }
2494
- );
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);
2495
2508
  }
2496
2509
  };
2497
2510