@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
  };
@@ -541,6 +544,16 @@ function emptyIfUndefined(value) {
541
544
  return value === void 0 ? "" : value;
542
545
  }
543
546
 
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
+
544
557
  // src/dmv2/internal.ts
545
558
  import process2 from "process";
546
559
 
@@ -594,9 +607,7 @@ var moose_internal = {
594
607
  apis: /* @__PURE__ */ new Map(),
595
608
  sqlResources: /* @__PURE__ */ new Map(),
596
609
  workflows: /* @__PURE__ */ new Map(),
597
- webApps: /* @__PURE__ */ new Map(),
598
- materializedViews: /* @__PURE__ */ new Map(),
599
- customViews: /* @__PURE__ */ new Map()
610
+ webApps: /* @__PURE__ */ new Map()
600
611
  };
601
612
  var defaultRetentionPeriod = 60 * 60 * 24 * 7;
602
613
  var getMooseInternal = () => globalThis.moose_internal;
@@ -2225,67 +2236,6 @@ var ETLPipeline = class {
2225
2236
  }
2226
2237
  };
2227
2238
 
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
-
2289
2239
  // src/dmv2/sdk/sqlResource.ts
2290
2240
  var SqlResource = class {
2291
2241
  /** @internal */
@@ -2340,18 +2290,66 @@ var SqlResource = class {
2340
2290
  }
2341
2291
  };
2342
2292
 
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
+
2343
2351
  // src/dmv2/sdk/view.ts
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;
2352
+ var View = class extends SqlResource {
2355
2353
  /**
2356
2354
  * Creates a new View instance.
2357
2355
  * @param name The name of the view to be created.
@@ -2362,16 +2360,17 @@ var View = class {
2362
2360
  if (typeof selectStatement !== "string") {
2363
2361
  selectStatement = toStaticQuery(selectStatement);
2364
2362
  }
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);
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
+ );
2375
2374
  }
2376
2375
  };
2377
2376
 
@@ -2560,18 +2559,6 @@ function getWebApps() {
2560
2559
  function getWebApp(name) {
2561
2560
  return getMooseInternal().webApps.get(name);
2562
2561
  }
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
- }
2575
2562
  export {
2576
2563
  Api,
2577
2564
  ConsumptionApi,
@@ -2590,12 +2577,8 @@ export {
2590
2577
  Workflow,
2591
2578
  getApi,
2592
2579
  getApis,
2593
- getCustomView,
2594
- getCustomViews,
2595
2580
  getIngestApi,
2596
2581
  getIngestApis,
2597
- getMaterializedView,
2598
- getMaterializedViews,
2599
2582
  getSqlResource,
2600
2583
  getSqlResources,
2601
2584
  getStream,