@514labs/moose-lib 0.6.262-ci-2-g350aed07 → 0.6.262-ci-5-gf85ca97c

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
@@ -393,35 +393,8 @@ function getSourceFileInfo(stack) {
393
393
  }
394
394
  return {};
395
395
  }
396
- function getSourceLocationFromStack(stack) {
397
- if (!stack) return void 0;
398
- const lines = stack.split("\n");
399
- for (const line of lines.slice(1)) {
400
- if (shouldSkipStackLine(line)) {
401
- continue;
402
- }
403
- const v8Match = line.match(/at\s+(?:.*?\s+\()?(.+):(\d+):(\d+)\)?/);
404
- if (v8Match) {
405
- return {
406
- file: v8Match[1],
407
- line: parseInt(v8Match[2], 10),
408
- column: parseInt(v8Match[3], 10)
409
- };
410
- }
411
- const smMatch = line.match(/(?:.*@)?(.+):(\d+):(\d+)/);
412
- if (smMatch) {
413
- return {
414
- file: smMatch[1],
415
- line: parseInt(smMatch[2], 10),
416
- column: parseInt(smMatch[3], 10)
417
- };
418
- }
419
- }
420
- return void 0;
421
- }
422
396
  function getSourceFileFromStack(stack) {
423
- const location = getSourceLocationFromStack(stack);
424
- return location?.file;
397
+ return getSourceFileInfo(stack).file;
425
398
  }
426
399
 
427
400
  // src/dmv2/typedBase.ts
@@ -682,7 +655,9 @@ var moose_internal = {
682
655
  apis: /* @__PURE__ */ new Map(),
683
656
  sqlResources: /* @__PURE__ */ new Map(),
684
657
  workflows: /* @__PURE__ */ new Map(),
685
- webApps: /* @__PURE__ */ new Map()
658
+ webApps: /* @__PURE__ */ new Map(),
659
+ materializedViews: /* @__PURE__ */ new Map(),
660
+ customViews: /* @__PURE__ */ new Map()
686
661
  };
687
662
  var defaultRetentionPeriod = 60 * 60 * 24 * 7;
688
663
  var getMooseInternal = () => globalThis.moose_internal;
@@ -698,6 +673,8 @@ var loadIndex = () => {
698
673
  registry.sqlResources.clear();
699
674
  registry.workflows.clear();
700
675
  registry.webApps.clear();
676
+ registry.materializedViews.clear();
677
+ registry.customViews.clear();
701
678
  const appDir = `${process2.cwd()}/${getSourceDir()}`;
702
679
  Object.keys(__require.cache).forEach((key) => {
703
680
  if (key.startsWith(appDir)) {
@@ -2331,6 +2308,67 @@ var ETLPipeline = class {
2331
2308
  }
2332
2309
  };
2333
2310
 
2311
+ // src/dmv2/sdk/materializedView.ts
2312
+ var requireTargetTableName = (tableName) => {
2313
+ if (typeof tableName === "string") {
2314
+ return tableName;
2315
+ } else {
2316
+ throw new Error("Name of targetTable is not specified.");
2317
+ }
2318
+ };
2319
+ var MaterializedView = class {
2320
+ /** @internal */
2321
+ kind = "MaterializedView";
2322
+ /** The name of the materialized view */
2323
+ name;
2324
+ /** The target OlapTable instance where the materialized data is stored. */
2325
+ targetTable;
2326
+ /** The SELECT SQL statement */
2327
+ selectSql;
2328
+ /** Names of source tables that the SELECT reads from */
2329
+ sourceTables;
2330
+ /** @internal Source file path where this MV was defined */
2331
+ sourceFile;
2332
+ constructor(options, targetSchema, targetColumns) {
2333
+ let selectStatement = options.selectStatement;
2334
+ if (typeof selectStatement !== "string") {
2335
+ selectStatement = toStaticQuery(selectStatement);
2336
+ }
2337
+ if (targetSchema === void 0 || targetColumns === void 0) {
2338
+ throw new Error(
2339
+ "Supply the type param T so that the schema is inserted by the compiler plugin."
2340
+ );
2341
+ }
2342
+ const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2343
+ requireTargetTableName(
2344
+ options.targetTable?.name ?? options.tableName
2345
+ ),
2346
+ {
2347
+ orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2348
+ engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2349
+ },
2350
+ targetSchema,
2351
+ targetColumns
2352
+ );
2353
+ if (targetTable.name === options.materializedViewName) {
2354
+ throw new Error(
2355
+ "Materialized view name cannot be the same as the target table name."
2356
+ );
2357
+ }
2358
+ this.name = options.materializedViewName;
2359
+ this.targetTable = targetTable;
2360
+ this.selectSql = selectStatement;
2361
+ this.sourceTables = options.selectTables.map((t) => t.name);
2362
+ const stack = new Error().stack;
2363
+ this.sourceFile = getSourceFileFromStack(stack);
2364
+ const materializedViews = getMooseInternal().materializedViews;
2365
+ if (!isClientOnlyMode() && materializedViews.has(this.name)) {
2366
+ throw new Error(`MaterializedView with name ${this.name} already exists`);
2367
+ }
2368
+ materializedViews.set(this.name, this);
2369
+ }
2370
+ };
2371
+
2334
2372
  // src/dmv2/sdk/sqlResource.ts
2335
2373
  var SqlResource = class {
2336
2374
  /** @internal */
@@ -2347,10 +2385,6 @@ var SqlResource = class {
2347
2385
  pushesDataTo;
2348
2386
  /** @internal Source file path where this resource was defined */
2349
2387
  sourceFile;
2350
- /** @internal Source line number where this resource was defined */
2351
- sourceLine;
2352
- /** @internal Source column number where this resource was defined */
2353
- sourceColumn;
2354
2388
  /**
2355
2389
  * Creates a new SqlResource instance.
2356
2390
  * @param name The name of the resource.
@@ -2376,75 +2410,22 @@ var SqlResource = class {
2376
2410
  this.pullsDataFrom = options?.pullsDataFrom ?? [];
2377
2411
  this.pushesDataTo = options?.pushesDataTo ?? [];
2378
2412
  const stack = new Error().stack;
2379
- const location = getSourceLocationFromStack(stack);
2380
- if (location) {
2381
- this.sourceFile = location.file;
2382
- this.sourceLine = location.line;
2383
- this.sourceColumn = location.column;
2384
- }
2385
- }
2386
- };
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;
2413
+ this.sourceFile = getSourceFileFromStack(stack);
2443
2414
  }
2444
2415
  };
2445
2416
 
2446
2417
  // src/dmv2/sdk/view.ts
2447
- var View = class extends SqlResource {
2418
+ var View = class {
2419
+ /** @internal */
2420
+ kind = "CustomView";
2421
+ /** The name of the view */
2422
+ name;
2423
+ /** The SELECT SQL statement that defines the view */
2424
+ selectSql;
2425
+ /** Names of source tables/views that the SELECT reads from */
2426
+ sourceTables;
2427
+ /** @internal Source file path where this view was defined */
2428
+ sourceFile;
2448
2429
  /**
2449
2430
  * Creates a new View instance.
2450
2431
  * @param name The name of the view to be created.
@@ -2455,17 +2436,16 @@ var View = class extends SqlResource {
2455
2436
  if (typeof selectStatement !== "string") {
2456
2437
  selectStatement = toStaticQuery(selectStatement);
2457
2438
  }
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
- );
2439
+ this.name = name;
2440
+ this.selectSql = selectStatement;
2441
+ this.sourceTables = baseTables.map((t) => t.name);
2442
+ const stack = new Error().stack;
2443
+ this.sourceFile = getSourceFileFromStack(stack);
2444
+ const customViews = getMooseInternal().customViews;
2445
+ if (!isClientOnlyMode() && customViews.has(this.name)) {
2446
+ throw new Error(`View with name ${this.name} already exists`);
2447
+ }
2448
+ customViews.set(this.name, this);
2469
2449
  }
2470
2450
  };
2471
2451