@514labs/moose-lib 0.6.284-ci-4-g1a9baa0b → 0.6.284-ci-9-g6ab40892

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;
@@ -2228,67 +2236,6 @@ var ETLPipeline = class {
2228
2236
  }
2229
2237
  };
2230
2238
 
2231
- // src/dmv2/sdk/materializedView.ts
2232
- var requireTargetTableName = (tableName) => {
2233
- if (typeof tableName === "string") {
2234
- return tableName;
2235
- } else {
2236
- throw new Error("Name of targetTable is not specified.");
2237
- }
2238
- };
2239
- var MaterializedView = class {
2240
- /** @internal */
2241
- kind = "MaterializedView";
2242
- /** The name of the materialized view */
2243
- name;
2244
- /** The target OlapTable instance where the materialized data is stored. */
2245
- targetTable;
2246
- /** The SELECT SQL statement */
2247
- selectSql;
2248
- /** Names of source tables that the SELECT reads from */
2249
- sourceTables;
2250
- /** @internal Source file path where this MV was defined */
2251
- sourceFile;
2252
- constructor(options, targetSchema, targetColumns) {
2253
- let selectStatement = options.selectStatement;
2254
- if (typeof selectStatement !== "string") {
2255
- selectStatement = toStaticQuery(selectStatement);
2256
- }
2257
- if (targetSchema === void 0 || targetColumns === void 0) {
2258
- throw new Error(
2259
- "Supply the type param T so that the schema is inserted by the compiler plugin."
2260
- );
2261
- }
2262
- const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2263
- requireTargetTableName(
2264
- options.targetTable?.name ?? options.tableName
2265
- ),
2266
- {
2267
- orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2268
- engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2269
- },
2270
- targetSchema,
2271
- targetColumns
2272
- );
2273
- if (targetTable.name === options.materializedViewName) {
2274
- throw new Error(
2275
- "Materialized view name cannot be the same as the target table name."
2276
- );
2277
- }
2278
- this.name = options.materializedViewName;
2279
- this.targetTable = targetTable;
2280
- this.selectSql = selectStatement;
2281
- this.sourceTables = options.selectTables.map((t) => t.name);
2282
- const stack = new Error().stack;
2283
- this.sourceFile = getSourceFileFromStack(stack);
2284
- const materializedViews = getMooseInternal().materializedViews;
2285
- if (!isClientOnlyMode() && materializedViews.has(this.name)) {
2286
- throw new Error(`MaterializedView with name ${this.name} already exists`);
2287
- }
2288
- materializedViews.set(this.name, this);
2289
- }
2290
- };
2291
-
2292
2239
  // src/dmv2/sdk/sqlResource.ts
2293
2240
  var SqlResource = class {
2294
2241
  /** @internal */
@@ -2343,18 +2290,66 @@ var SqlResource = class {
2343
2290
  }
2344
2291
  };
2345
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
+
2346
2351
  // src/dmv2/sdk/view.ts
2347
- var View = class {
2348
- /** @internal */
2349
- kind = "CustomView";
2350
- /** The name of the view */
2351
- name;
2352
- /** The SELECT SQL statement that defines the view */
2353
- selectSql;
2354
- /** Names of source tables/views that the SELECT reads from */
2355
- sourceTables;
2356
- /** @internal Source file path where this view was defined */
2357
- sourceFile;
2352
+ var View = class extends SqlResource {
2358
2353
  /**
2359
2354
  * Creates a new View instance.
2360
2355
  * @param name The name of the view to be created.
@@ -2365,16 +2360,17 @@ var View = class {
2365
2360
  if (typeof selectStatement !== "string") {
2366
2361
  selectStatement = toStaticQuery(selectStatement);
2367
2362
  }
2368
- this.name = name;
2369
- this.selectSql = selectStatement;
2370
- this.sourceTables = baseTables.map((t) => t.name);
2371
- const stack = new Error().stack;
2372
- this.sourceFile = getSourceFileFromStack(stack);
2373
- const customViews = getMooseInternal().customViews;
2374
- if (!isClientOnlyMode() && customViews.has(this.name)) {
2375
- throw new Error(`View with name ${this.name} already exists`);
2376
- }
2377
- 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
+ );
2378
2374
  }
2379
2375
  };
2380
2376
 
@@ -2563,18 +2559,6 @@ function getWebApps() {
2563
2559
  function getWebApp(name) {
2564
2560
  return getMooseInternal().webApps.get(name);
2565
2561
  }
2566
- function getMaterializedViews() {
2567
- return getMooseInternal().materializedViews;
2568
- }
2569
- function getMaterializedView(name) {
2570
- return getMooseInternal().materializedViews.get(name);
2571
- }
2572
- function getCustomViews() {
2573
- return getMooseInternal().customViews;
2574
- }
2575
- function getCustomView(name) {
2576
- return getMooseInternal().customViews.get(name);
2577
- }
2578
2562
  export {
2579
2563
  Api,
2580
2564
  ConsumptionApi,
@@ -2593,12 +2577,8 @@ export {
2593
2577
  Workflow,
2594
2578
  getApi,
2595
2579
  getApis,
2596
- getCustomView,
2597
- getCustomViews,
2598
2580
  getIngestApi,
2599
2581
  getIngestApis,
2600
- getMaterializedView,
2601
- getMaterializedViews,
2602
2582
  getSqlResource,
2603
2583
  getSqlResources,
2604
2584
  getStream,