@514labs/moose-lib 0.6.295-ci-20-gbe187727 → 0.6.295

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.
@@ -544,6 +544,16 @@ function emptyIfUndefined(value) {
544
544
  return value === void 0 ? "" : value;
545
545
  }
546
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
+
547
557
  // src/dmv2/internal.ts
548
558
  import process2 from "process";
549
559
 
@@ -597,9 +607,7 @@ var moose_internal = {
597
607
  apis: /* @__PURE__ */ new Map(),
598
608
  sqlResources: /* @__PURE__ */ new Map(),
599
609
  workflows: /* @__PURE__ */ new Map(),
600
- webApps: /* @__PURE__ */ new Map(),
601
- materializedViews: /* @__PURE__ */ new Map(),
602
- customViews: /* @__PURE__ */ new Map()
610
+ webApps: /* @__PURE__ */ new Map()
603
611
  };
604
612
  var defaultRetentionPeriod = 60 * 60 * 24 * 7;
605
613
  var getMooseInternal = () => globalThis.moose_internal;
@@ -2233,67 +2241,6 @@ var ETLPipeline = class {
2233
2241
  }
2234
2242
  };
2235
2243
 
2236
- // src/dmv2/sdk/materializedView.ts
2237
- var requireTargetTableName = (tableName) => {
2238
- if (typeof tableName === "string") {
2239
- return tableName;
2240
- } else {
2241
- throw new Error("Name of targetTable is not specified.");
2242
- }
2243
- };
2244
- var MaterializedView = class {
2245
- /** @internal */
2246
- kind = "MaterializedView";
2247
- /** The name of the materialized view */
2248
- name;
2249
- /** The target OlapTable instance where the materialized data is stored. */
2250
- targetTable;
2251
- /** The SELECT SQL statement */
2252
- selectSql;
2253
- /** Names of source tables that the SELECT reads from */
2254
- sourceTables;
2255
- /** @internal Source file path where this MV was defined */
2256
- sourceFile;
2257
- constructor(options, targetSchema, targetColumns) {
2258
- let selectStatement = options.selectStatement;
2259
- if (typeof selectStatement !== "string") {
2260
- selectStatement = toStaticQuery(selectStatement);
2261
- }
2262
- if (targetSchema === void 0 || targetColumns === void 0) {
2263
- throw new Error(
2264
- "Supply the type param T so that the schema is inserted by the compiler plugin."
2265
- );
2266
- }
2267
- const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2268
- requireTargetTableName(
2269
- options.targetTable?.name ?? options.tableName
2270
- ),
2271
- {
2272
- orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2273
- engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2274
- },
2275
- targetSchema,
2276
- targetColumns
2277
- );
2278
- if (targetTable.name === options.materializedViewName) {
2279
- throw new Error(
2280
- "Materialized view name cannot be the same as the target table name."
2281
- );
2282
- }
2283
- this.name = options.materializedViewName;
2284
- this.targetTable = targetTable;
2285
- this.selectSql = selectStatement;
2286
- this.sourceTables = options.selectTables.map((t) => t.name);
2287
- const stack = new Error().stack;
2288
- this.sourceFile = getSourceFileFromStack(stack);
2289
- const materializedViews = getMooseInternal().materializedViews;
2290
- if (!isClientOnlyMode() && materializedViews.has(this.name)) {
2291
- throw new Error(`MaterializedView with name ${this.name} already exists`);
2292
- }
2293
- materializedViews.set(this.name, this);
2294
- }
2295
- };
2296
-
2297
2244
  // src/dmv2/sdk/sqlResource.ts
2298
2245
  var SqlResource = class {
2299
2246
  /** @internal */
@@ -2348,18 +2295,66 @@ var SqlResource = class {
2348
2295
  }
2349
2296
  };
2350
2297
 
2298
+ // src/dmv2/sdk/materializedView.ts
2299
+ var requireTargetTableName = (tableName) => {
2300
+ if (typeof tableName === "string") {
2301
+ return tableName;
2302
+ } else {
2303
+ throw new Error("Name of targetTable is not specified.");
2304
+ }
2305
+ };
2306
+ var MaterializedView = class extends SqlResource {
2307
+ /** The target OlapTable instance where the materialized data is stored. */
2308
+ targetTable;
2309
+ constructor(options, targetSchema, targetColumns) {
2310
+ let selectStatement = options.selectStatement;
2311
+ if (typeof selectStatement !== "string") {
2312
+ selectStatement = toStaticQuery(selectStatement);
2313
+ }
2314
+ if (targetSchema === void 0 || targetColumns === void 0) {
2315
+ throw new Error(
2316
+ "Supply the type param T so that the schema is inserted by the compiler plugin."
2317
+ );
2318
+ }
2319
+ const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2320
+ requireTargetTableName(
2321
+ options.targetTable?.name ?? options.tableName
2322
+ ),
2323
+ {
2324
+ orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2325
+ engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2326
+ },
2327
+ targetSchema,
2328
+ targetColumns
2329
+ );
2330
+ if (targetTable.name === options.materializedViewName) {
2331
+ throw new Error(
2332
+ "Materialized view name cannot be the same as the target table name."
2333
+ );
2334
+ }
2335
+ super(
2336
+ options.materializedViewName,
2337
+ [
2338
+ createMaterializedView({
2339
+ name: options.materializedViewName,
2340
+ destinationTable: targetTable.name,
2341
+ select: selectStatement
2342
+ })
2343
+ // Population is now handled automatically by Rust infrastructure
2344
+ // based on table engine type and whether this is a new or updated view
2345
+ ],
2346
+ [dropView(options.materializedViewName)],
2347
+ {
2348
+ pullsDataFrom: options.selectTables,
2349
+ pushesDataTo: [targetTable]
2350
+ }
2351
+ );
2352
+ this.targetTable = targetTable;
2353
+ }
2354
+ };
2355
+
2351
2356
  // src/dmv2/sdk/view.ts
2352
- var View = class {
2353
- /** @internal */
2354
- kind = "CustomView";
2355
- /** The name of the view */
2356
- name;
2357
- /** The SELECT SQL statement that defines the view */
2358
- selectSql;
2359
- /** Names of source tables/views that the SELECT reads from */
2360
- sourceTables;
2361
- /** @internal Source file path where this view was defined */
2362
- sourceFile;
2357
+ var View = class extends SqlResource {
2363
2358
  /**
2364
2359
  * Creates a new View instance.
2365
2360
  * @param name The name of the view to be created.
@@ -2370,16 +2365,17 @@ var View = class {
2370
2365
  if (typeof selectStatement !== "string") {
2371
2366
  selectStatement = toStaticQuery(selectStatement);
2372
2367
  }
2373
- this.name = name;
2374
- this.selectSql = selectStatement;
2375
- this.sourceTables = baseTables.map((t) => t.name);
2376
- const stack = new Error().stack;
2377
- this.sourceFile = getSourceFileFromStack(stack);
2378
- const customViews = getMooseInternal().customViews;
2379
- if (!isClientOnlyMode() && customViews.has(this.name)) {
2380
- throw new Error(`View with name ${this.name} already exists`);
2381
- }
2382
- customViews.set(this.name, this);
2368
+ super(
2369
+ name,
2370
+ [
2371
+ `CREATE VIEW IF NOT EXISTS ${name}
2372
+ AS ${selectStatement}`.trim()
2373
+ ],
2374
+ [dropView(name)],
2375
+ {
2376
+ pullsDataFrom: baseTables
2377
+ }
2378
+ );
2383
2379
  }
2384
2380
  };
2385
2381
 
@@ -2568,18 +2564,6 @@ function getWebApps() {
2568
2564
  function getWebApp(name) {
2569
2565
  return getMooseInternal().webApps.get(name);
2570
2566
  }
2571
- function getMaterializedViews() {
2572
- return getMooseInternal().materializedViews;
2573
- }
2574
- function getMaterializedView(name) {
2575
- return getMooseInternal().materializedViews.get(name);
2576
- }
2577
- function getCustomViews() {
2578
- return getMooseInternal().customViews;
2579
- }
2580
- function getCustomView(name) {
2581
- return getMooseInternal().customViews.get(name);
2582
- }
2583
2567
  export {
2584
2568
  Api,
2585
2569
  ConsumptionApi,
@@ -2598,12 +2582,8 @@ export {
2598
2582
  Workflow,
2599
2583
  getApi,
2600
2584
  getApis,
2601
- getCustomView,
2602
- getCustomViews,
2603
2585
  getIngestApi,
2604
2586
  getIngestApis,
2605
- getMaterializedView,
2606
- getMaterializedViews,
2607
2587
  getSqlResource,
2608
2588
  getSqlResources,
2609
2589
  getStream,