@514labs/moose-lib 0.6.321-ci-5-ga23d35fe → 0.6.322

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.
@@ -177,33 +177,171 @@ var init_dataModelTypes = __esm({
177
177
  }
178
178
  });
179
179
 
180
- // src/dataModels/types.ts
181
- var ClickHouseEngines;
182
- var init_types = __esm({
183
- "src/dataModels/types.ts"() {
180
+ // src/sqlHelpers.ts
181
+ function sql(strings, ...values) {
182
+ return new Sql(strings, values);
183
+ }
184
+ function createClickhouseParameter(parameterIndex, value) {
185
+ return `{p${parameterIndex}:${mapToClickHouseType(value)}}`;
186
+ }
187
+ function emptyIfUndefined(value) {
188
+ return value === void 0 ? "" : value;
189
+ }
190
+ var quoteIdentifier, isTable, isView, isColumn, instanceofSql, Sql, toStaticQuery, toQuery, toQueryPreview, getValueFromParameter, mapToClickHouseType;
191
+ var init_sqlHelpers = __esm({
192
+ "src/sqlHelpers.ts"() {
184
193
  "use strict";
185
- ClickHouseEngines = /* @__PURE__ */ ((ClickHouseEngines2) => {
186
- ClickHouseEngines2["MergeTree"] = "MergeTree";
187
- ClickHouseEngines2["ReplacingMergeTree"] = "ReplacingMergeTree";
188
- ClickHouseEngines2["SummingMergeTree"] = "SummingMergeTree";
189
- ClickHouseEngines2["AggregatingMergeTree"] = "AggregatingMergeTree";
190
- ClickHouseEngines2["CollapsingMergeTree"] = "CollapsingMergeTree";
191
- ClickHouseEngines2["VersionedCollapsingMergeTree"] = "VersionedCollapsingMergeTree";
192
- ClickHouseEngines2["GraphiteMergeTree"] = "GraphiteMergeTree";
193
- ClickHouseEngines2["S3Queue"] = "S3Queue";
194
- ClickHouseEngines2["S3"] = "S3";
195
- ClickHouseEngines2["Buffer"] = "Buffer";
196
- ClickHouseEngines2["Distributed"] = "Distributed";
197
- ClickHouseEngines2["IcebergS3"] = "IcebergS3";
198
- ClickHouseEngines2["Kafka"] = "Kafka";
199
- ClickHouseEngines2["ReplicatedMergeTree"] = "ReplicatedMergeTree";
200
- ClickHouseEngines2["ReplicatedReplacingMergeTree"] = "ReplicatedReplacingMergeTree";
201
- ClickHouseEngines2["ReplicatedAggregatingMergeTree"] = "ReplicatedAggregatingMergeTree";
202
- ClickHouseEngines2["ReplicatedSummingMergeTree"] = "ReplicatedSummingMergeTree";
203
- ClickHouseEngines2["ReplicatedCollapsingMergeTree"] = "ReplicatedCollapsingMergeTree";
204
- ClickHouseEngines2["ReplicatedVersionedCollapsingMergeTree"] = "ReplicatedVersionedCollapsingMergeTree";
205
- return ClickHouseEngines2;
206
- })(ClickHouseEngines || {});
194
+ quoteIdentifier = (name) => {
195
+ return name.startsWith("`") && name.endsWith("`") ? name : `\`${name}\``;
196
+ };
197
+ isTable = (value) => typeof value === "object" && value !== null && "kind" in value && value.kind === "OlapTable";
198
+ isView = (value) => typeof value === "object" && value !== null && "kind" in value && value.kind === "View";
199
+ isColumn = (value) => typeof value === "object" && value !== null && !("kind" in value) && "name" in value && "annotations" in value;
200
+ instanceofSql = (value) => typeof value === "object" && "values" in value && "strings" in value;
201
+ Sql = class {
202
+ values;
203
+ strings;
204
+ constructor(rawStrings, rawValues) {
205
+ if (rawStrings.length - 1 !== rawValues.length) {
206
+ if (rawStrings.length === 0) {
207
+ throw new TypeError("Expected at least 1 string");
208
+ }
209
+ throw new TypeError(
210
+ `Expected ${rawStrings.length} strings to have ${rawStrings.length - 1} values`
211
+ );
212
+ }
213
+ const valuesLength = rawValues.reduce(
214
+ (len, value) => len + (instanceofSql(value) ? value.values.length : isColumn(value) || isTable(value) || isView(value) ? 0 : 1),
215
+ 0
216
+ );
217
+ this.values = new Array(valuesLength);
218
+ this.strings = new Array(valuesLength + 1);
219
+ this.strings[0] = rawStrings[0];
220
+ let i = 0, pos = 0;
221
+ while (i < rawValues.length) {
222
+ const child = rawValues[i++];
223
+ const rawString = rawStrings[i];
224
+ if (instanceofSql(child)) {
225
+ this.strings[pos] += child.strings[0];
226
+ let childIndex = 0;
227
+ while (childIndex < child.values.length) {
228
+ this.values[pos++] = child.values[childIndex++];
229
+ this.strings[pos] = child.strings[childIndex];
230
+ }
231
+ this.strings[pos] += rawString;
232
+ } else if (isColumn(child)) {
233
+ const aggregationFunction = child.annotations.find(
234
+ ([k, _]) => k === "aggregationFunction"
235
+ );
236
+ if (aggregationFunction !== void 0) {
237
+ this.strings[pos] += `${aggregationFunction[1].functionName}Merge(\`${child.name}\`)`;
238
+ } else {
239
+ this.strings[pos] += `\`${child.name}\``;
240
+ }
241
+ this.strings[pos] += rawString;
242
+ } else if (isTable(child)) {
243
+ if (child.config.database) {
244
+ this.strings[pos] += `\`${child.config.database}\`.\`${child.name}\``;
245
+ } else {
246
+ this.strings[pos] += `\`${child.name}\``;
247
+ }
248
+ this.strings[pos] += rawString;
249
+ } else if (isView(child)) {
250
+ this.strings[pos] += `\`${child.name}\``;
251
+ this.strings[pos] += rawString;
252
+ } else {
253
+ this.values[pos++] = child;
254
+ this.strings[pos] = rawString;
255
+ }
256
+ }
257
+ }
258
+ };
259
+ toStaticQuery = (sql3) => {
260
+ const [query, params] = toQuery(sql3);
261
+ if (Object.keys(params).length !== 0) {
262
+ throw new Error(
263
+ "Dynamic SQL is not allowed in the select statement in view creation."
264
+ );
265
+ }
266
+ return query;
267
+ };
268
+ toQuery = (sql3) => {
269
+ const parameterizedStubs = sql3.values.map(
270
+ (v, i) => createClickhouseParameter(i, v)
271
+ );
272
+ const query = sql3.strings.map(
273
+ (s, i) => s != "" ? `${s}${emptyIfUndefined(parameterizedStubs[i])}` : ""
274
+ ).join("");
275
+ const query_params = sql3.values.reduce(
276
+ (acc, v, i) => ({
277
+ ...acc,
278
+ [`p${i}`]: getValueFromParameter(v)
279
+ }),
280
+ {}
281
+ );
282
+ return [query, query_params];
283
+ };
284
+ toQueryPreview = (sql3) => {
285
+ try {
286
+ const formatValue = (v) => {
287
+ if (Array.isArray(v)) {
288
+ const [type, val] = v;
289
+ if (type === "Identifier") {
290
+ return `\`${String(val)}\``;
291
+ }
292
+ return `[${v.map((x) => formatValue(x)).join(", ")}]`;
293
+ }
294
+ if (v === null || v === void 0) return "NULL";
295
+ if (typeof v === "string") return `'${v.replace(/'/g, "''")}'`;
296
+ if (typeof v === "number") return String(v);
297
+ if (typeof v === "boolean") return v ? "true" : "false";
298
+ if (v instanceof Date)
299
+ return `'${v.toISOString().replace("T", " ").slice(0, 19)}'`;
300
+ try {
301
+ return JSON.stringify(v);
302
+ } catch {
303
+ return String(v);
304
+ }
305
+ };
306
+ let out = sql3.strings[0] ?? "";
307
+ for (let i = 0; i < sql3.values.length; i++) {
308
+ const val = getValueFromParameter(sql3.values[i]);
309
+ out += formatValue(val);
310
+ out += sql3.strings[i + 1] ?? "";
311
+ }
312
+ return out.replace(/\s+/g, " ").trim();
313
+ } catch (error) {
314
+ console.log(`toQueryPreview error: ${error}`);
315
+ return "/* query preview unavailable */";
316
+ }
317
+ };
318
+ getValueFromParameter = (value) => {
319
+ if (Array.isArray(value)) {
320
+ const [type, val] = value;
321
+ if (type === "Identifier") return val;
322
+ }
323
+ return value;
324
+ };
325
+ mapToClickHouseType = (value) => {
326
+ if (typeof value === "number") {
327
+ return Number.isInteger(value) ? "Int" : "Float";
328
+ }
329
+ if (typeof value === "boolean") return "Bool";
330
+ if (value instanceof Date) return "DateTime";
331
+ if (Array.isArray(value)) {
332
+ const [type, _] = value;
333
+ return type;
334
+ }
335
+ return "String";
336
+ };
337
+ }
338
+ });
339
+
340
+ // src/blocks/helpers.ts
341
+ var init_helpers = __esm({
342
+ "src/blocks/helpers.ts"() {
343
+ "use strict";
344
+ init_sqlHelpers();
207
345
  }
208
346
  });
209
347
 
@@ -381,169 +519,9 @@ var init_secrets = __esm({
381
519
  }
382
520
  });
383
521
 
384
- // src/sqlHelpers.ts
385
- function sql(strings, ...values) {
386
- return new Sql(strings, values);
387
- }
388
- function createClickhouseParameter(parameterIndex, value) {
389
- return `{p${parameterIndex}:${mapToClickHouseType(value)}}`;
390
- }
391
- function emptyIfUndefined(value) {
392
- return value === void 0 ? "" : value;
393
- }
394
- var quoteIdentifier, isTable, isView, isColumn, instanceofSql, Sql, toStaticQuery, toQuery, toQueryPreview, getValueFromParameter, mapToClickHouseType;
395
- var init_sqlHelpers = __esm({
396
- "src/sqlHelpers.ts"() {
397
- "use strict";
398
- quoteIdentifier = (name) => {
399
- return name.startsWith("`") && name.endsWith("`") ? name : `\`${name}\``;
400
- };
401
- isTable = (value) => typeof value === "object" && value !== null && "kind" in value && value.kind === "OlapTable";
402
- isView = (value) => typeof value === "object" && value !== null && "kind" in value && value.kind === "View";
403
- isColumn = (value) => typeof value === "object" && value !== null && !("kind" in value) && "name" in value && "annotations" in value;
404
- instanceofSql = (value) => typeof value === "object" && "values" in value && "strings" in value;
405
- Sql = class {
406
- values;
407
- strings;
408
- constructor(rawStrings, rawValues) {
409
- if (rawStrings.length - 1 !== rawValues.length) {
410
- if (rawStrings.length === 0) {
411
- throw new TypeError("Expected at least 1 string");
412
- }
413
- throw new TypeError(
414
- `Expected ${rawStrings.length} strings to have ${rawStrings.length - 1} values`
415
- );
416
- }
417
- const valuesLength = rawValues.reduce(
418
- (len, value) => len + (instanceofSql(value) ? value.values.length : isColumn(value) || isTable(value) || isView(value) ? 0 : 1),
419
- 0
420
- );
421
- this.values = new Array(valuesLength);
422
- this.strings = new Array(valuesLength + 1);
423
- this.strings[0] = rawStrings[0];
424
- let i = 0, pos = 0;
425
- while (i < rawValues.length) {
426
- const child = rawValues[i++];
427
- const rawString = rawStrings[i];
428
- if (instanceofSql(child)) {
429
- this.strings[pos] += child.strings[0];
430
- let childIndex = 0;
431
- while (childIndex < child.values.length) {
432
- this.values[pos++] = child.values[childIndex++];
433
- this.strings[pos] = child.strings[childIndex];
434
- }
435
- this.strings[pos] += rawString;
436
- } else if (isColumn(child)) {
437
- const aggregationFunction = child.annotations.find(
438
- ([k, _]) => k === "aggregationFunction"
439
- );
440
- if (aggregationFunction !== void 0) {
441
- this.strings[pos] += `${aggregationFunction[1].functionName}Merge(\`${child.name}\`)`;
442
- } else {
443
- this.strings[pos] += `\`${child.name}\``;
444
- }
445
- this.strings[pos] += rawString;
446
- } else if (isTable(child)) {
447
- if (child.config.database) {
448
- this.strings[pos] += `\`${child.config.database}\`.\`${child.name}\``;
449
- } else {
450
- this.strings[pos] += `\`${child.name}\``;
451
- }
452
- this.strings[pos] += rawString;
453
- } else if (isView(child)) {
454
- this.strings[pos] += `\`${child.name}\``;
455
- this.strings[pos] += rawString;
456
- } else {
457
- this.values[pos++] = child;
458
- this.strings[pos] = rawString;
459
- }
460
- }
461
- }
462
- };
463
- toStaticQuery = (sql3) => {
464
- const [query, params] = toQuery(sql3);
465
- if (Object.keys(params).length !== 0) {
466
- throw new Error(
467
- "Dynamic SQL is not allowed in the select statement in view creation."
468
- );
469
- }
470
- return query;
471
- };
472
- toQuery = (sql3) => {
473
- const parameterizedStubs = sql3.values.map(
474
- (v, i) => createClickhouseParameter(i, v)
475
- );
476
- const query = sql3.strings.map(
477
- (s, i) => s != "" ? `${s}${emptyIfUndefined(parameterizedStubs[i])}` : ""
478
- ).join("");
479
- const query_params = sql3.values.reduce(
480
- (acc, v, i) => ({
481
- ...acc,
482
- [`p${i}`]: getValueFromParameter(v)
483
- }),
484
- {}
485
- );
486
- return [query, query_params];
487
- };
488
- toQueryPreview = (sql3) => {
489
- try {
490
- const formatValue = (v) => {
491
- if (Array.isArray(v)) {
492
- const [type, val] = v;
493
- if (type === "Identifier") {
494
- return `\`${String(val)}\``;
495
- }
496
- return `[${v.map((x) => formatValue(x)).join(", ")}]`;
497
- }
498
- if (v === null || v === void 0) return "NULL";
499
- if (typeof v === "string") return `'${v.replace(/'/g, "''")}'`;
500
- if (typeof v === "number") return String(v);
501
- if (typeof v === "boolean") return v ? "true" : "false";
502
- if (v instanceof Date)
503
- return `'${v.toISOString().replace("T", " ").slice(0, 19)}'`;
504
- try {
505
- return JSON.stringify(v);
506
- } catch {
507
- return String(v);
508
- }
509
- };
510
- let out = sql3.strings[0] ?? "";
511
- for (let i = 0; i < sql3.values.length; i++) {
512
- const val = getValueFromParameter(sql3.values[i]);
513
- out += formatValue(val);
514
- out += sql3.strings[i + 1] ?? "";
515
- }
516
- return out.replace(/\s+/g, " ").trim();
517
- } catch (error) {
518
- console.log(`toQueryPreview error: ${error}`);
519
- return "/* query preview unavailable */";
520
- }
521
- };
522
- getValueFromParameter = (value) => {
523
- if (Array.isArray(value)) {
524
- const [type, val] = value;
525
- if (type === "Identifier") return val;
526
- }
527
- return value;
528
- };
529
- mapToClickHouseType = (value) => {
530
- if (typeof value === "number") {
531
- return Number.isInteger(value) ? "Int" : "Float";
532
- }
533
- if (typeof value === "boolean") return "Bool";
534
- if (value instanceof Date) return "DateTime";
535
- if (Array.isArray(value)) {
536
- const [type, _] = value;
537
- return type;
538
- }
539
- return "String";
540
- };
541
- }
542
- });
543
-
544
522
  // src/consumption-apis/helpers.ts
545
523
  var import_client2, import_node_crypto;
546
- var init_helpers = __esm({
524
+ var init_helpers2 = __esm({
547
525
  "src/consumption-apis/helpers.ts"() {
548
526
  "use strict";
549
527
  import_client2 = require("@temporalio/client");
@@ -584,7 +562,7 @@ var init_runner = __esm({
584
562
  "src/consumption-apis/runner.ts"() {
585
563
  "use strict";
586
564
  init_commons();
587
- init_helpers();
565
+ init_helpers2();
588
566
  jose = __toESM(require("jose"));
589
567
  init_cluster_utils();
590
568
  init_sqlHelpers();
@@ -605,7 +583,7 @@ var init_redisClient = __esm({
605
583
  var init_standalone = __esm({
606
584
  "src/consumption-apis/standalone.ts"() {
607
585
  "use strict";
608
- init_helpers();
586
+ init_helpers2();
609
587
  init_commons();
610
588
  init_sqlHelpers();
611
589
  }
@@ -655,19 +633,27 @@ var init_dataSource = __esm({
655
633
  }
656
634
  });
657
635
 
636
+ // src/dataModels/types.ts
637
+ var init_types = __esm({
638
+ "src/dataModels/types.ts"() {
639
+ "use strict";
640
+ }
641
+ });
642
+
658
643
  // src/index.ts
659
644
  var init_index = __esm({
660
645
  "src/index.ts"() {
661
646
  "use strict";
662
647
  init_browserCompatible();
648
+ init_helpers();
663
649
  init_commons();
664
650
  init_secrets();
665
- init_helpers();
651
+ init_helpers2();
666
652
  init_webAppHelpers();
667
653
  init_task();
668
654
  init_runner();
669
655
  init_redisClient();
670
- init_helpers();
656
+ init_helpers2();
671
657
  init_standalone();
672
658
  init_sqlHelpers();
673
659
  init_utilities();
@@ -1019,7 +1005,7 @@ var init_olapTable = __esm({
1019
1005
  "use strict";
1020
1006
  init_typedBase();
1021
1007
  init_dataModelTypes();
1022
- init_types();
1008
+ init_helpers();
1023
1009
  init_internal();
1024
1010
  import_node_stream = require("stream");
1025
1011
  import_node_crypto2 = require("crypto");
@@ -2314,7 +2300,7 @@ var init_ingestPipeline = __esm({
2314
2300
  init_stream();
2315
2301
  init_olapTable();
2316
2302
  init_ingestApi();
2317
- init_types();
2303
+ init_helpers();
2318
2304
  IngestPipeline = class extends TypedBase {
2319
2305
  /**
2320
2306
  * The OLAP table component of the pipeline, if configured.
@@ -2587,7 +2573,7 @@ var requireTargetTableName, MaterializedView;
2587
2573
  var init_materializedView = __esm({
2588
2574
  "src/dmv2/sdk/materializedView.ts"() {
2589
2575
  "use strict";
2590
- init_types();
2576
+ init_helpers();
2591
2577
  init_sqlHelpers();
2592
2578
  init_olapTable();
2593
2579
  init_internal();
@@ -3006,7 +2992,6 @@ var init_dmv2 = __esm({
3006
2992
  "src/dmv2/index.ts"() {
3007
2993
  "use strict";
3008
2994
  init_olapTable();
3009
- init_types();
3010
2995
  init_stream();
3011
2996
  init_workflow();
3012
2997
  init_ingestApi();
@@ -3026,7 +3011,6 @@ var init_dmv2 = __esm({
3026
3011
  var browserCompatible_exports = {};
3027
3012
  __export(browserCompatible_exports, {
3028
3013
  Api: () => Api,
3029
- ClickHouseEngines: () => ClickHouseEngines,
3030
3014
  ConsumptionApi: () => ConsumptionApi,
3031
3015
  DeadLetterQueue: () => DeadLetterQueue,
3032
3016
  ETLPipeline: () => ETLPipeline,
@@ -3081,7 +3065,6 @@ init_browserCompatible();
3081
3065
  // Annotate the CommonJS export names for ESM import in node:
3082
3066
  0 && (module.exports = {
3083
3067
  Api,
3084
- ClickHouseEngines,
3085
3068
  ConsumptionApi,
3086
3069
  DeadLetterQueue,
3087
3070
  ETLPipeline,