@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.
@@ -362,13 +362,10 @@ 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("node:internal") || // Skip Node.js internals (modern format)
366
- line.includes("internal/modules") || // Skip Node.js internals (older format)
365
+ line.includes("internal/modules") || // Skip Node.js internals
367
366
  line.includes("ts-node") || // Skip TypeScript execution
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\\");
367
+ line.includes("/ts-moose-lib/") || // Skip dev/linked moose-lib (Unix)
368
+ line.includes("\\ts-moose-lib\\");
372
369
  }
373
370
  function parseStackLine(line) {
374
371
  const match = line.match(/\((.*):(\d+):(\d+)\)/) || line.match(/at (.*):(\d+):(\d+)/);
@@ -471,12 +468,12 @@ var TypedBase = class {
471
468
  this.validators = validators;
472
469
  this.allowExtraFields = allowExtraFields ?? false;
473
470
  this.metadata = config?.metadata ? { ...config.metadata } : {};
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
- }
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;
480
477
  }
481
478
  }
482
479
  };
@@ -544,16 +541,6 @@ function emptyIfUndefined(value) {
544
541
  return value === void 0 ? "" : value;
545
542
  }
546
543
 
547
- // src/blocks/helpers.ts
548
- function dropView(name) {
549
- return `DROP VIEW IF EXISTS ${quoteIdentifier(name)}`.trim();
550
- }
551
- function createMaterializedView(options) {
552
- return `CREATE MATERIALIZED VIEW IF NOT EXISTS ${quoteIdentifier(options.name)}
553
- TO ${quoteIdentifier(options.destinationTable)}
554
- AS ${options.select}`.trim();
555
- }
556
-
557
544
  // src/dmv2/internal.ts
558
545
  import process2 from "process";
559
546
 
@@ -607,7 +594,9 @@ var moose_internal = {
607
594
  apis: /* @__PURE__ */ new Map(),
608
595
  sqlResources: /* @__PURE__ */ new Map(),
609
596
  workflows: /* @__PURE__ */ new Map(),
610
- webApps: /* @__PURE__ */ new Map()
597
+ webApps: /* @__PURE__ */ new Map(),
598
+ materializedViews: /* @__PURE__ */ new Map(),
599
+ customViews: /* @__PURE__ */ new Map()
611
600
  };
612
601
  var defaultRetentionPeriod = 60 * 60 * 24 * 7;
613
602
  var getMooseInternal = () => globalThis.moose_internal;
@@ -2236,6 +2225,67 @@ var ETLPipeline = class {
2236
2225
  }
2237
2226
  };
2238
2227
 
2228
+ // src/dmv2/sdk/materializedView.ts
2229
+ var requireTargetTableName = (tableName) => {
2230
+ if (typeof tableName === "string") {
2231
+ return tableName;
2232
+ } else {
2233
+ throw new Error("Name of targetTable is not specified.");
2234
+ }
2235
+ };
2236
+ var MaterializedView = class {
2237
+ /** @internal */
2238
+ kind = "MaterializedView";
2239
+ /** The name of the materialized view */
2240
+ name;
2241
+ /** The target OlapTable instance where the materialized data is stored. */
2242
+ targetTable;
2243
+ /** The SELECT SQL statement */
2244
+ selectSql;
2245
+ /** Names of source tables that the SELECT reads from */
2246
+ sourceTables;
2247
+ /** @internal Source file path where this MV was defined */
2248
+ sourceFile;
2249
+ constructor(options, targetSchema, targetColumns) {
2250
+ let selectStatement = options.selectStatement;
2251
+ if (typeof selectStatement !== "string") {
2252
+ selectStatement = toStaticQuery(selectStatement);
2253
+ }
2254
+ if (targetSchema === void 0 || targetColumns === void 0) {
2255
+ throw new Error(
2256
+ "Supply the type param T so that the schema is inserted by the compiler plugin."
2257
+ );
2258
+ }
2259
+ const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2260
+ requireTargetTableName(
2261
+ options.targetTable?.name ?? options.tableName
2262
+ ),
2263
+ {
2264
+ orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2265
+ engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2266
+ },
2267
+ targetSchema,
2268
+ targetColumns
2269
+ );
2270
+ if (targetTable.name === options.materializedViewName) {
2271
+ throw new Error(
2272
+ "Materialized view name cannot be the same as the target table name."
2273
+ );
2274
+ }
2275
+ this.name = options.materializedViewName;
2276
+ this.targetTable = targetTable;
2277
+ this.selectSql = selectStatement;
2278
+ this.sourceTables = options.selectTables.map((t) => t.name);
2279
+ const stack = new Error().stack;
2280
+ this.sourceFile = getSourceFileFromStack(stack);
2281
+ const materializedViews = getMooseInternal().materializedViews;
2282
+ if (!isClientOnlyMode() && materializedViews.has(this.name)) {
2283
+ throw new Error(`MaterializedView with name ${this.name} already exists`);
2284
+ }
2285
+ materializedViews.set(this.name, this);
2286
+ }
2287
+ };
2288
+
2239
2289
  // src/dmv2/sdk/sqlResource.ts
2240
2290
  var SqlResource = class {
2241
2291
  /** @internal */
@@ -2290,66 +2340,18 @@ var SqlResource = class {
2290
2340
  }
2291
2341
  };
2292
2342
 
2293
- // src/dmv2/sdk/materializedView.ts
2294
- var requireTargetTableName = (tableName) => {
2295
- if (typeof tableName === "string") {
2296
- return tableName;
2297
- } else {
2298
- throw new Error("Name of targetTable is not specified.");
2299
- }
2300
- };
2301
- var MaterializedView = class extends SqlResource {
2302
- /** The target OlapTable instance where the materialized data is stored. */
2303
- targetTable;
2304
- constructor(options, targetSchema, targetColumns) {
2305
- let selectStatement = options.selectStatement;
2306
- if (typeof selectStatement !== "string") {
2307
- selectStatement = toStaticQuery(selectStatement);
2308
- }
2309
- if (targetSchema === void 0 || targetColumns === void 0) {
2310
- throw new Error(
2311
- "Supply the type param T so that the schema is inserted by the compiler plugin."
2312
- );
2313
- }
2314
- const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2315
- requireTargetTableName(
2316
- options.targetTable?.name ?? options.tableName
2317
- ),
2318
- {
2319
- orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2320
- engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2321
- },
2322
- targetSchema,
2323
- targetColumns
2324
- );
2325
- if (targetTable.name === options.materializedViewName) {
2326
- throw new Error(
2327
- "Materialized view name cannot be the same as the target table name."
2328
- );
2329
- }
2330
- super(
2331
- options.materializedViewName,
2332
- [
2333
- createMaterializedView({
2334
- name: options.materializedViewName,
2335
- destinationTable: targetTable.name,
2336
- select: selectStatement
2337
- })
2338
- // Population is now handled automatically by Rust infrastructure
2339
- // based on table engine type and whether this is a new or updated view
2340
- ],
2341
- [dropView(options.materializedViewName)],
2342
- {
2343
- pullsDataFrom: options.selectTables,
2344
- pushesDataTo: [targetTable]
2345
- }
2346
- );
2347
- this.targetTable = targetTable;
2348
- }
2349
- };
2350
-
2351
2343
  // src/dmv2/sdk/view.ts
2352
- var View = class extends SqlResource {
2344
+ var View = class {
2345
+ /** @internal */
2346
+ kind = "CustomView";
2347
+ /** The name of the view */
2348
+ name;
2349
+ /** The SELECT SQL statement that defines the view */
2350
+ selectSql;
2351
+ /** Names of source tables/views that the SELECT reads from */
2352
+ sourceTables;
2353
+ /** @internal Source file path where this view was defined */
2354
+ sourceFile;
2353
2355
  /**
2354
2356
  * Creates a new View instance.
2355
2357
  * @param name The name of the view to be created.
@@ -2360,17 +2362,16 @@ var View = class extends SqlResource {
2360
2362
  if (typeof selectStatement !== "string") {
2361
2363
  selectStatement = toStaticQuery(selectStatement);
2362
2364
  }
2363
- super(
2364
- name,
2365
- [
2366
- `CREATE VIEW IF NOT EXISTS ${name}
2367
- AS ${selectStatement}`.trim()
2368
- ],
2369
- [dropView(name)],
2370
- {
2371
- pullsDataFrom: baseTables
2372
- }
2373
- );
2365
+ this.name = name;
2366
+ this.selectSql = selectStatement;
2367
+ this.sourceTables = baseTables.map((t) => t.name);
2368
+ const stack = new Error().stack;
2369
+ this.sourceFile = getSourceFileFromStack(stack);
2370
+ const customViews = getMooseInternal().customViews;
2371
+ if (!isClientOnlyMode() && customViews.has(this.name)) {
2372
+ throw new Error(`View with name ${this.name} already exists`);
2373
+ }
2374
+ customViews.set(this.name, this);
2374
2375
  }
2375
2376
  };
2376
2377
 
@@ -2559,6 +2560,18 @@ function getWebApps() {
2559
2560
  function getWebApp(name) {
2560
2561
  return getMooseInternal().webApps.get(name);
2561
2562
  }
2563
+ function getMaterializedViews() {
2564
+ return getMooseInternal().materializedViews;
2565
+ }
2566
+ function getMaterializedView(name) {
2567
+ return getMooseInternal().materializedViews.get(name);
2568
+ }
2569
+ function getCustomViews() {
2570
+ return getMooseInternal().customViews;
2571
+ }
2572
+ function getCustomView(name) {
2573
+ return getMooseInternal().customViews.get(name);
2574
+ }
2562
2575
  export {
2563
2576
  Api,
2564
2577
  ConsumptionApi,
@@ -2577,8 +2590,12 @@ export {
2577
2590
  Workflow,
2578
2591
  getApi,
2579
2592
  getApis,
2593
+ getCustomView,
2594
+ getCustomViews,
2580
2595
  getIngestApi,
2581
2596
  getIngestApis,
2597
+ getMaterializedView,
2598
+ getMaterializedViews,
2582
2599
  getSqlResource,
2583
2600
  getSqlResources,
2584
2601
  getStream,