@514labs/moose-lib 0.6.262-ci-5-gf85ca97c → 0.6.262-ci-2-gfc2fb4ba

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.
@@ -506,6 +506,16 @@ function emptyIfUndefined(value) {
506
506
  return value === void 0 ? "" : value;
507
507
  }
508
508
 
509
+ // src/blocks/helpers.ts
510
+ function dropView(name) {
511
+ return `DROP VIEW IF EXISTS ${quoteIdentifier(name)}`.trim();
512
+ }
513
+ function createMaterializedView(options) {
514
+ return `CREATE MATERIALIZED VIEW IF NOT EXISTS ${quoteIdentifier(options.name)}
515
+ TO ${quoteIdentifier(options.destinationTable)}
516
+ AS ${options.select}`.trim();
517
+ }
518
+
509
519
  // src/dmv2/internal.ts
510
520
  import process2 from "process";
511
521
 
@@ -559,9 +569,7 @@ var moose_internal = {
559
569
  apis: /* @__PURE__ */ new Map(),
560
570
  sqlResources: /* @__PURE__ */ new Map(),
561
571
  workflows: /* @__PURE__ */ new Map(),
562
- webApps: /* @__PURE__ */ new Map(),
563
- materializedViews: /* @__PURE__ */ new Map(),
564
- customViews: /* @__PURE__ */ new Map()
572
+ webApps: /* @__PURE__ */ new Map()
565
573
  };
566
574
  var defaultRetentionPeriod = 60 * 60 * 24 * 7;
567
575
  var getMooseInternal = () => globalThis.moose_internal;
@@ -1971,6 +1979,7 @@ var IngestPipeline = class extends TypedBase {
1971
1979
  if (config.table) {
1972
1980
  const tableConfig = typeof config.table === "object" ? {
1973
1981
  ...config.table,
1982
+ lifeCycle: config.table.lifeCycle ?? config.lifeCycle,
1974
1983
  ...config.version && { version: config.version }
1975
1984
  } : {
1976
1985
  lifeCycle: config.lifeCycle,
@@ -2001,7 +2010,10 @@ var IngestPipeline = class extends TypedBase {
2001
2010
  const streamConfig = {
2002
2011
  destination: this.table,
2003
2012
  defaultDeadLetterQueue: this.deadLetterQueue,
2004
- ...typeof config.stream === "object" ? config.stream : { lifeCycle: config.lifeCycle },
2013
+ ...typeof config.stream === "object" ? {
2014
+ ...config.stream,
2015
+ lifeCycle: config.stream.lifeCycle ?? config.lifeCycle
2016
+ } : { lifeCycle: config.lifeCycle },
2005
2017
  ...config.version && { version: config.version }
2006
2018
  };
2007
2019
  this.stream = new Stream(
@@ -2177,67 +2189,6 @@ var ETLPipeline = class {
2177
2189
  }
2178
2190
  };
2179
2191
 
2180
- // src/dmv2/sdk/materializedView.ts
2181
- var requireTargetTableName = (tableName) => {
2182
- if (typeof tableName === "string") {
2183
- return tableName;
2184
- } else {
2185
- throw new Error("Name of targetTable is not specified.");
2186
- }
2187
- };
2188
- var MaterializedView = class {
2189
- /** @internal */
2190
- kind = "MaterializedView";
2191
- /** The name of the materialized view */
2192
- name;
2193
- /** The target OlapTable instance where the materialized data is stored. */
2194
- targetTable;
2195
- /** The SELECT SQL statement */
2196
- selectSql;
2197
- /** Names of source tables that the SELECT reads from */
2198
- sourceTables;
2199
- /** @internal Source file path where this MV was defined */
2200
- sourceFile;
2201
- constructor(options, targetSchema, targetColumns) {
2202
- let selectStatement = options.selectStatement;
2203
- if (typeof selectStatement !== "string") {
2204
- selectStatement = toStaticQuery(selectStatement);
2205
- }
2206
- if (targetSchema === void 0 || targetColumns === void 0) {
2207
- throw new Error(
2208
- "Supply the type param T so that the schema is inserted by the compiler plugin."
2209
- );
2210
- }
2211
- const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2212
- requireTargetTableName(
2213
- options.targetTable?.name ?? options.tableName
2214
- ),
2215
- {
2216
- orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2217
- engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2218
- },
2219
- targetSchema,
2220
- targetColumns
2221
- );
2222
- if (targetTable.name === options.materializedViewName) {
2223
- throw new Error(
2224
- "Materialized view name cannot be the same as the target table name."
2225
- );
2226
- }
2227
- this.name = options.materializedViewName;
2228
- this.targetTable = targetTable;
2229
- this.selectSql = selectStatement;
2230
- this.sourceTables = options.selectTables.map((t) => t.name);
2231
- const stack = new Error().stack;
2232
- this.sourceFile = getSourceFileFromStack(stack);
2233
- const materializedViews = getMooseInternal().materializedViews;
2234
- if (!isClientOnlyMode() && materializedViews.has(this.name)) {
2235
- throw new Error(`MaterializedView with name ${this.name} already exists`);
2236
- }
2237
- materializedViews.set(this.name, this);
2238
- }
2239
- };
2240
-
2241
2192
  // src/dmv2/sdk/sqlResource.ts
2242
2193
  var SqlResource = class {
2243
2194
  /** @internal */
@@ -2283,18 +2234,66 @@ var SqlResource = class {
2283
2234
  }
2284
2235
  };
2285
2236
 
2237
+ // src/dmv2/sdk/materializedView.ts
2238
+ var requireTargetTableName = (tableName) => {
2239
+ if (typeof tableName === "string") {
2240
+ return tableName;
2241
+ } else {
2242
+ throw new Error("Name of targetTable is not specified.");
2243
+ }
2244
+ };
2245
+ var MaterializedView = class extends SqlResource {
2246
+ /** The target OlapTable instance where the materialized data is stored. */
2247
+ targetTable;
2248
+ constructor(options, targetSchema, targetColumns) {
2249
+ let selectStatement = options.selectStatement;
2250
+ if (typeof selectStatement !== "string") {
2251
+ selectStatement = toStaticQuery(selectStatement);
2252
+ }
2253
+ if (targetSchema === void 0 || targetColumns === void 0) {
2254
+ throw new Error(
2255
+ "Supply the type param T so that the schema is inserted by the compiler plugin."
2256
+ );
2257
+ }
2258
+ const targetTable = options.targetTable instanceof OlapTable ? options.targetTable : new OlapTable(
2259
+ requireTargetTableName(
2260
+ options.targetTable?.name ?? options.tableName
2261
+ ),
2262
+ {
2263
+ orderByFields: options.targetTable?.orderByFields ?? options.orderByFields,
2264
+ engine: options.targetTable?.engine ?? options.engine ?? "MergeTree" /* MergeTree */
2265
+ },
2266
+ targetSchema,
2267
+ targetColumns
2268
+ );
2269
+ if (targetTable.name === options.materializedViewName) {
2270
+ throw new Error(
2271
+ "Materialized view name cannot be the same as the target table name."
2272
+ );
2273
+ }
2274
+ super(
2275
+ options.materializedViewName,
2276
+ [
2277
+ createMaterializedView({
2278
+ name: options.materializedViewName,
2279
+ destinationTable: targetTable.name,
2280
+ select: selectStatement
2281
+ })
2282
+ // Population is now handled automatically by Rust infrastructure
2283
+ // based on table engine type and whether this is a new or updated view
2284
+ ],
2285
+ [dropView(options.materializedViewName)],
2286
+ {
2287
+ pullsDataFrom: options.selectTables,
2288
+ pushesDataTo: [targetTable]
2289
+ }
2290
+ );
2291
+ this.targetTable = targetTable;
2292
+ }
2293
+ };
2294
+
2286
2295
  // src/dmv2/sdk/view.ts
2287
- var View = class {
2288
- /** @internal */
2289
- kind = "CustomView";
2290
- /** The name of the view */
2291
- name;
2292
- /** The SELECT SQL statement that defines the view */
2293
- selectSql;
2294
- /** Names of source tables/views that the SELECT reads from */
2295
- sourceTables;
2296
- /** @internal Source file path where this view was defined */
2297
- sourceFile;
2296
+ var View = class extends SqlResource {
2298
2297
  /**
2299
2298
  * Creates a new View instance.
2300
2299
  * @param name The name of the view to be created.
@@ -2305,16 +2304,17 @@ var View = class {
2305
2304
  if (typeof selectStatement !== "string") {
2306
2305
  selectStatement = toStaticQuery(selectStatement);
2307
2306
  }
2308
- this.name = name;
2309
- this.selectSql = selectStatement;
2310
- this.sourceTables = baseTables.map((t) => t.name);
2311
- const stack = new Error().stack;
2312
- this.sourceFile = getSourceFileFromStack(stack);
2313
- const customViews = getMooseInternal().customViews;
2314
- if (!isClientOnlyMode() && customViews.has(this.name)) {
2315
- throw new Error(`View with name ${this.name} already exists`);
2316
- }
2317
- customViews.set(this.name, this);
2307
+ super(
2308
+ name,
2309
+ [
2310
+ `CREATE VIEW IF NOT EXISTS ${name}
2311
+ AS ${selectStatement}`.trim()
2312
+ ],
2313
+ [dropView(name)],
2314
+ {
2315
+ pullsDataFrom: baseTables
2316
+ }
2317
+ );
2318
2318
  }
2319
2319
  };
2320
2320