@514labs/moose-lib 0.6.266-ci-2-g933b2685 → 0.6.266-ci-8-ge6e86870

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.
@@ -541,16 +541,6 @@ function emptyIfUndefined(value) {
541
541
  return value === void 0 ? "" : value;
542
542
  }
543
543
 
544
- // src/blocks/helpers.ts
545
- function dropView(name) {
546
- return `DROP VIEW IF EXISTS ${quoteIdentifier(name)}`.trim();
547
- }
548
- function createMaterializedView(options) {
549
- return `CREATE MATERIALIZED VIEW IF NOT EXISTS ${quoteIdentifier(options.name)}
550
- TO ${quoteIdentifier(options.destinationTable)}
551
- AS ${options.select}`.trim();
552
- }
553
-
554
544
  // src/dmv2/internal.ts
555
545
  import process2 from "process";
556
546
 
@@ -604,7 +594,9 @@ var moose_internal = {
604
594
  apis: /* @__PURE__ */ new Map(),
605
595
  sqlResources: /* @__PURE__ */ new Map(),
606
596
  workflows: /* @__PURE__ */ new Map(),
607
- webApps: /* @__PURE__ */ new Map()
597
+ webApps: /* @__PURE__ */ new Map(),
598
+ materializedViews: /* @__PURE__ */ new Map(),
599
+ customViews: /* @__PURE__ */ new Map()
608
600
  };
609
601
  var defaultRetentionPeriod = 60 * 60 * 24 * 7;
610
602
  var getMooseInternal = () => globalThis.moose_internal;
@@ -2231,6 +2223,67 @@ var ETLPipeline = class {
2231
2223
  }
2232
2224
  };
2233
2225
 
2226
+ // src/dmv2/sdk/materializedView.ts
2227
+ var requireTargetTableName = (tableName) => {
2228
+ if (typeof tableName === "string") {
2229
+ return tableName;
2230
+ } else {
2231
+ throw new Error("Name of targetTable is not specified.");
2232
+ }
2233
+ };
2234
+ var MaterializedView = class {
2235
+ /** @internal */
2236
+ kind = "MaterializedView";
2237
+ /** The name of the materialized view */
2238
+ name;
2239
+ /** The target OlapTable instance where the materialized data is stored. */
2240
+ targetTable;
2241
+ /** The SELECT SQL statement */
2242
+ selectSql;
2243
+ /** Names of source tables that the SELECT reads from */
2244
+ sourceTables;
2245
+ /** @internal Source file path where this MV was defined */
2246
+ sourceFile;
2247
+ constructor(options, targetSchema, targetColumns) {
2248
+ let selectStatement = options.selectStatement;
2249
+ if (typeof selectStatement !== "string") {
2250
+ selectStatement = toStaticQuery(selectStatement);
2251
+ }
2252
+ if (targetSchema === void 0 || targetColumns === void 0) {
2253
+ throw new Error(
2254
+ "Supply the type param T so that the schema is inserted by the compiler plugin."
2255
+ );
2256
+ }
2257
+ const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2258
+ requireTargetTableName(
2259
+ options.targetTable?.name ?? options.tableName
2260
+ ),
2261
+ {
2262
+ orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2263
+ engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2264
+ },
2265
+ targetSchema,
2266
+ targetColumns
2267
+ );
2268
+ if (targetTable.name === options.materializedViewName) {
2269
+ throw new Error(
2270
+ "Materialized view name cannot be the same as the target table name."
2271
+ );
2272
+ }
2273
+ this.name = options.materializedViewName;
2274
+ this.targetTable = targetTable;
2275
+ this.selectSql = selectStatement;
2276
+ this.sourceTables = options.selectTables.map((t) => t.name);
2277
+ const stack = new Error().stack;
2278
+ this.sourceFile = getSourceFileFromStack(stack);
2279
+ const materializedViews = getMooseInternal().materializedViews;
2280
+ if (!isClientOnlyMode() && materializedViews.has(this.name)) {
2281
+ throw new Error(`MaterializedView with name ${this.name} already exists`);
2282
+ }
2283
+ materializedViews.set(this.name, this);
2284
+ }
2285
+ };
2286
+
2234
2287
  // src/dmv2/sdk/sqlResource.ts
2235
2288
  var SqlResource = class {
2236
2289
  /** @internal */
@@ -2285,66 +2338,18 @@ var SqlResource = class {
2285
2338
  }
2286
2339
  };
2287
2340
 
2288
- // src/dmv2/sdk/materializedView.ts
2289
- var requireTargetTableName = (tableName) => {
2290
- if (typeof tableName === "string") {
2291
- return tableName;
2292
- } else {
2293
- throw new Error("Name of targetTable is not specified.");
2294
- }
2295
- };
2296
- var MaterializedView = class extends SqlResource {
2297
- /** The target OlapTable instance where the materialized data is stored. */
2298
- targetTable;
2299
- constructor(options, targetSchema, targetColumns) {
2300
- let selectStatement = options.selectStatement;
2301
- if (typeof selectStatement !== "string") {
2302
- selectStatement = toStaticQuery(selectStatement);
2303
- }
2304
- if (targetSchema === void 0 || targetColumns === void 0) {
2305
- throw new Error(
2306
- "Supply the type param T so that the schema is inserted by the compiler plugin."
2307
- );
2308
- }
2309
- const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2310
- requireTargetTableName(
2311
- options.targetTable?.name ?? options.tableName
2312
- ),
2313
- {
2314
- orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2315
- engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2316
- },
2317
- targetSchema,
2318
- targetColumns
2319
- );
2320
- if (targetTable.name === options.materializedViewName) {
2321
- throw new Error(
2322
- "Materialized view name cannot be the same as the target table name."
2323
- );
2324
- }
2325
- super(
2326
- options.materializedViewName,
2327
- [
2328
- createMaterializedView({
2329
- name: options.materializedViewName,
2330
- destinationTable: targetTable.name,
2331
- select: selectStatement
2332
- })
2333
- // Population is now handled automatically by Rust infrastructure
2334
- // based on table engine type and whether this is a new or updated view
2335
- ],
2336
- [dropView(options.materializedViewName)],
2337
- {
2338
- pullsDataFrom: options.selectTables,
2339
- pushesDataTo: [targetTable]
2340
- }
2341
- );
2342
- this.targetTable = targetTable;
2343
- }
2344
- };
2345
-
2346
2341
  // src/dmv2/sdk/view.ts
2347
- var View = class extends SqlResource {
2342
+ var View = class {
2343
+ /** @internal */
2344
+ kind = "CustomView";
2345
+ /** The name of the view */
2346
+ name;
2347
+ /** The SELECT SQL statement that defines the view */
2348
+ selectSql;
2349
+ /** Names of source tables/views that the SELECT reads from */
2350
+ sourceTables;
2351
+ /** @internal Source file path where this view was defined */
2352
+ sourceFile;
2348
2353
  /**
2349
2354
  * Creates a new View instance.
2350
2355
  * @param name The name of the view to be created.
@@ -2355,17 +2360,16 @@ var View = class extends SqlResource {
2355
2360
  if (typeof selectStatement !== "string") {
2356
2361
  selectStatement = toStaticQuery(selectStatement);
2357
2362
  }
2358
- super(
2359
- name,
2360
- [
2361
- `CREATE VIEW IF NOT EXISTS ${name}
2362
- AS ${selectStatement}`.trim()
2363
- ],
2364
- [dropView(name)],
2365
- {
2366
- pullsDataFrom: baseTables
2367
- }
2368
- );
2363
+ this.name = name;
2364
+ this.selectSql = selectStatement;
2365
+ this.sourceTables = baseTables.map((t) => t.name);
2366
+ const stack = new Error().stack;
2367
+ this.sourceFile = getSourceFileFromStack(stack);
2368
+ const customViews = getMooseInternal().customViews;
2369
+ if (!isClientOnlyMode() && customViews.has(this.name)) {
2370
+ throw new Error(`View with name ${this.name} already exists`);
2371
+ }
2372
+ customViews.set(this.name, this);
2369
2373
  }
2370
2374
  };
2371
2375