@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.
@@ -155,33 +155,171 @@ var init_dataModelTypes = __esm({
155
155
  }
156
156
  });
157
157
 
158
- // src/dataModels/types.ts
159
- var ClickHouseEngines;
160
- var init_types = __esm({
161
- "src/dataModels/types.ts"() {
158
+ // src/sqlHelpers.ts
159
+ function sql(strings, ...values) {
160
+ return new Sql(strings, values);
161
+ }
162
+ function createClickhouseParameter(parameterIndex, value) {
163
+ return `{p${parameterIndex}:${mapToClickHouseType(value)}}`;
164
+ }
165
+ function emptyIfUndefined(value) {
166
+ return value === void 0 ? "" : value;
167
+ }
168
+ var quoteIdentifier, isTable, isView, isColumn, instanceofSql, Sql, toStaticQuery, toQuery, toQueryPreview, getValueFromParameter, mapToClickHouseType;
169
+ var init_sqlHelpers = __esm({
170
+ "src/sqlHelpers.ts"() {
162
171
  "use strict";
163
- ClickHouseEngines = /* @__PURE__ */ ((ClickHouseEngines2) => {
164
- ClickHouseEngines2["MergeTree"] = "MergeTree";
165
- ClickHouseEngines2["ReplacingMergeTree"] = "ReplacingMergeTree";
166
- ClickHouseEngines2["SummingMergeTree"] = "SummingMergeTree";
167
- ClickHouseEngines2["AggregatingMergeTree"] = "AggregatingMergeTree";
168
- ClickHouseEngines2["CollapsingMergeTree"] = "CollapsingMergeTree";
169
- ClickHouseEngines2["VersionedCollapsingMergeTree"] = "VersionedCollapsingMergeTree";
170
- ClickHouseEngines2["GraphiteMergeTree"] = "GraphiteMergeTree";
171
- ClickHouseEngines2["S3Queue"] = "S3Queue";
172
- ClickHouseEngines2["S3"] = "S3";
173
- ClickHouseEngines2["Buffer"] = "Buffer";
174
- ClickHouseEngines2["Distributed"] = "Distributed";
175
- ClickHouseEngines2["IcebergS3"] = "IcebergS3";
176
- ClickHouseEngines2["Kafka"] = "Kafka";
177
- ClickHouseEngines2["ReplicatedMergeTree"] = "ReplicatedMergeTree";
178
- ClickHouseEngines2["ReplicatedReplacingMergeTree"] = "ReplicatedReplacingMergeTree";
179
- ClickHouseEngines2["ReplicatedAggregatingMergeTree"] = "ReplicatedAggregatingMergeTree";
180
- ClickHouseEngines2["ReplicatedSummingMergeTree"] = "ReplicatedSummingMergeTree";
181
- ClickHouseEngines2["ReplicatedCollapsingMergeTree"] = "ReplicatedCollapsingMergeTree";
182
- ClickHouseEngines2["ReplicatedVersionedCollapsingMergeTree"] = "ReplicatedVersionedCollapsingMergeTree";
183
- return ClickHouseEngines2;
184
- })(ClickHouseEngines || {});
172
+ quoteIdentifier = (name) => {
173
+ return name.startsWith("`") && name.endsWith("`") ? name : `\`${name}\``;
174
+ };
175
+ isTable = (value) => typeof value === "object" && value !== null && "kind" in value && value.kind === "OlapTable";
176
+ isView = (value) => typeof value === "object" && value !== null && "kind" in value && value.kind === "View";
177
+ isColumn = (value) => typeof value === "object" && value !== null && !("kind" in value) && "name" in value && "annotations" in value;
178
+ instanceofSql = (value) => typeof value === "object" && "values" in value && "strings" in value;
179
+ Sql = class {
180
+ values;
181
+ strings;
182
+ constructor(rawStrings, rawValues) {
183
+ if (rawStrings.length - 1 !== rawValues.length) {
184
+ if (rawStrings.length === 0) {
185
+ throw new TypeError("Expected at least 1 string");
186
+ }
187
+ throw new TypeError(
188
+ `Expected ${rawStrings.length} strings to have ${rawStrings.length - 1} values`
189
+ );
190
+ }
191
+ const valuesLength = rawValues.reduce(
192
+ (len, value) => len + (instanceofSql(value) ? value.values.length : isColumn(value) || isTable(value) || isView(value) ? 0 : 1),
193
+ 0
194
+ );
195
+ this.values = new Array(valuesLength);
196
+ this.strings = new Array(valuesLength + 1);
197
+ this.strings[0] = rawStrings[0];
198
+ let i = 0, pos = 0;
199
+ while (i < rawValues.length) {
200
+ const child = rawValues[i++];
201
+ const rawString = rawStrings[i];
202
+ if (instanceofSql(child)) {
203
+ this.strings[pos] += child.strings[0];
204
+ let childIndex = 0;
205
+ while (childIndex < child.values.length) {
206
+ this.values[pos++] = child.values[childIndex++];
207
+ this.strings[pos] = child.strings[childIndex];
208
+ }
209
+ this.strings[pos] += rawString;
210
+ } else if (isColumn(child)) {
211
+ const aggregationFunction = child.annotations.find(
212
+ ([k, _]) => k === "aggregationFunction"
213
+ );
214
+ if (aggregationFunction !== void 0) {
215
+ this.strings[pos] += `${aggregationFunction[1].functionName}Merge(\`${child.name}\`)`;
216
+ } else {
217
+ this.strings[pos] += `\`${child.name}\``;
218
+ }
219
+ this.strings[pos] += rawString;
220
+ } else if (isTable(child)) {
221
+ if (child.config.database) {
222
+ this.strings[pos] += `\`${child.config.database}\`.\`${child.name}\``;
223
+ } else {
224
+ this.strings[pos] += `\`${child.name}\``;
225
+ }
226
+ this.strings[pos] += rawString;
227
+ } else if (isView(child)) {
228
+ this.strings[pos] += `\`${child.name}\``;
229
+ this.strings[pos] += rawString;
230
+ } else {
231
+ this.values[pos++] = child;
232
+ this.strings[pos] = rawString;
233
+ }
234
+ }
235
+ }
236
+ };
237
+ toStaticQuery = (sql3) => {
238
+ const [query, params] = toQuery(sql3);
239
+ if (Object.keys(params).length !== 0) {
240
+ throw new Error(
241
+ "Dynamic SQL is not allowed in the select statement in view creation."
242
+ );
243
+ }
244
+ return query;
245
+ };
246
+ toQuery = (sql3) => {
247
+ const parameterizedStubs = sql3.values.map(
248
+ (v, i) => createClickhouseParameter(i, v)
249
+ );
250
+ const query = sql3.strings.map(
251
+ (s, i) => s != "" ? `${s}${emptyIfUndefined(parameterizedStubs[i])}` : ""
252
+ ).join("");
253
+ const query_params = sql3.values.reduce(
254
+ (acc, v, i) => ({
255
+ ...acc,
256
+ [`p${i}`]: getValueFromParameter(v)
257
+ }),
258
+ {}
259
+ );
260
+ return [query, query_params];
261
+ };
262
+ toQueryPreview = (sql3) => {
263
+ try {
264
+ const formatValue = (v) => {
265
+ if (Array.isArray(v)) {
266
+ const [type, val] = v;
267
+ if (type === "Identifier") {
268
+ return `\`${String(val)}\``;
269
+ }
270
+ return `[${v.map((x) => formatValue(x)).join(", ")}]`;
271
+ }
272
+ if (v === null || v === void 0) return "NULL";
273
+ if (typeof v === "string") return `'${v.replace(/'/g, "''")}'`;
274
+ if (typeof v === "number") return String(v);
275
+ if (typeof v === "boolean") return v ? "true" : "false";
276
+ if (v instanceof Date)
277
+ return `'${v.toISOString().replace("T", " ").slice(0, 19)}'`;
278
+ try {
279
+ return JSON.stringify(v);
280
+ } catch {
281
+ return String(v);
282
+ }
283
+ };
284
+ let out = sql3.strings[0] ?? "";
285
+ for (let i = 0; i < sql3.values.length; i++) {
286
+ const val = getValueFromParameter(sql3.values[i]);
287
+ out += formatValue(val);
288
+ out += sql3.strings[i + 1] ?? "";
289
+ }
290
+ return out.replace(/\s+/g, " ").trim();
291
+ } catch (error) {
292
+ console.log(`toQueryPreview error: ${error}`);
293
+ return "/* query preview unavailable */";
294
+ }
295
+ };
296
+ getValueFromParameter = (value) => {
297
+ if (Array.isArray(value)) {
298
+ const [type, val] = value;
299
+ if (type === "Identifier") return val;
300
+ }
301
+ return value;
302
+ };
303
+ mapToClickHouseType = (value) => {
304
+ if (typeof value === "number") {
305
+ return Number.isInteger(value) ? "Int" : "Float";
306
+ }
307
+ if (typeof value === "boolean") return "Bool";
308
+ if (value instanceof Date) return "DateTime";
309
+ if (Array.isArray(value)) {
310
+ const [type, _] = value;
311
+ return type;
312
+ }
313
+ return "String";
314
+ };
315
+ }
316
+ });
317
+
318
+ // src/blocks/helpers.ts
319
+ var init_helpers = __esm({
320
+ "src/blocks/helpers.ts"() {
321
+ "use strict";
322
+ init_sqlHelpers();
185
323
  }
186
324
  });
187
325
 
@@ -359,173 +497,13 @@ var init_secrets = __esm({
359
497
  }
360
498
  });
361
499
 
362
- // src/sqlHelpers.ts
363
- function sql(strings, ...values) {
364
- return new Sql(strings, values);
365
- }
366
- function createClickhouseParameter(parameterIndex, value) {
367
- return `{p${parameterIndex}:${mapToClickHouseType(value)}}`;
368
- }
369
- function emptyIfUndefined(value) {
370
- return value === void 0 ? "" : value;
371
- }
372
- var quoteIdentifier, isTable, isView, isColumn, instanceofSql, Sql, toStaticQuery, toQuery, toQueryPreview, getValueFromParameter, mapToClickHouseType;
373
- var init_sqlHelpers = __esm({
374
- "src/sqlHelpers.ts"() {
375
- "use strict";
376
- quoteIdentifier = (name) => {
377
- return name.startsWith("`") && name.endsWith("`") ? name : `\`${name}\``;
378
- };
379
- isTable = (value) => typeof value === "object" && value !== null && "kind" in value && value.kind === "OlapTable";
380
- isView = (value) => typeof value === "object" && value !== null && "kind" in value && value.kind === "View";
381
- isColumn = (value) => typeof value === "object" && value !== null && !("kind" in value) && "name" in value && "annotations" in value;
382
- instanceofSql = (value) => typeof value === "object" && "values" in value && "strings" in value;
383
- Sql = class {
384
- values;
385
- strings;
386
- constructor(rawStrings, rawValues) {
387
- if (rawStrings.length - 1 !== rawValues.length) {
388
- if (rawStrings.length === 0) {
389
- throw new TypeError("Expected at least 1 string");
390
- }
391
- throw new TypeError(
392
- `Expected ${rawStrings.length} strings to have ${rawStrings.length - 1} values`
393
- );
394
- }
395
- const valuesLength = rawValues.reduce(
396
- (len, value) => len + (instanceofSql(value) ? value.values.length : isColumn(value) || isTable(value) || isView(value) ? 0 : 1),
397
- 0
398
- );
399
- this.values = new Array(valuesLength);
400
- this.strings = new Array(valuesLength + 1);
401
- this.strings[0] = rawStrings[0];
402
- let i = 0, pos = 0;
403
- while (i < rawValues.length) {
404
- const child = rawValues[i++];
405
- const rawString = rawStrings[i];
406
- if (instanceofSql(child)) {
407
- this.strings[pos] += child.strings[0];
408
- let childIndex = 0;
409
- while (childIndex < child.values.length) {
410
- this.values[pos++] = child.values[childIndex++];
411
- this.strings[pos] = child.strings[childIndex];
412
- }
413
- this.strings[pos] += rawString;
414
- } else if (isColumn(child)) {
415
- const aggregationFunction = child.annotations.find(
416
- ([k, _]) => k === "aggregationFunction"
417
- );
418
- if (aggregationFunction !== void 0) {
419
- this.strings[pos] += `${aggregationFunction[1].functionName}Merge(\`${child.name}\`)`;
420
- } else {
421
- this.strings[pos] += `\`${child.name}\``;
422
- }
423
- this.strings[pos] += rawString;
424
- } else if (isTable(child)) {
425
- if (child.config.database) {
426
- this.strings[pos] += `\`${child.config.database}\`.\`${child.name}\``;
427
- } else {
428
- this.strings[pos] += `\`${child.name}\``;
429
- }
430
- this.strings[pos] += rawString;
431
- } else if (isView(child)) {
432
- this.strings[pos] += `\`${child.name}\``;
433
- this.strings[pos] += rawString;
434
- } else {
435
- this.values[pos++] = child;
436
- this.strings[pos] = rawString;
437
- }
438
- }
439
- }
440
- };
441
- toStaticQuery = (sql3) => {
442
- const [query, params] = toQuery(sql3);
443
- if (Object.keys(params).length !== 0) {
444
- throw new Error(
445
- "Dynamic SQL is not allowed in the select statement in view creation."
446
- );
447
- }
448
- return query;
449
- };
450
- toQuery = (sql3) => {
451
- const parameterizedStubs = sql3.values.map(
452
- (v, i) => createClickhouseParameter(i, v)
453
- );
454
- const query = sql3.strings.map(
455
- (s, i) => s != "" ? `${s}${emptyIfUndefined(parameterizedStubs[i])}` : ""
456
- ).join("");
457
- const query_params = sql3.values.reduce(
458
- (acc, v, i) => ({
459
- ...acc,
460
- [`p${i}`]: getValueFromParameter(v)
461
- }),
462
- {}
463
- );
464
- return [query, query_params];
465
- };
466
- toQueryPreview = (sql3) => {
467
- try {
468
- const formatValue = (v) => {
469
- if (Array.isArray(v)) {
470
- const [type, val] = v;
471
- if (type === "Identifier") {
472
- return `\`${String(val)}\``;
473
- }
474
- return `[${v.map((x) => formatValue(x)).join(", ")}]`;
475
- }
476
- if (v === null || v === void 0) return "NULL";
477
- if (typeof v === "string") return `'${v.replace(/'/g, "''")}'`;
478
- if (typeof v === "number") return String(v);
479
- if (typeof v === "boolean") return v ? "true" : "false";
480
- if (v instanceof Date)
481
- return `'${v.toISOString().replace("T", " ").slice(0, 19)}'`;
482
- try {
483
- return JSON.stringify(v);
484
- } catch {
485
- return String(v);
486
- }
487
- };
488
- let out = sql3.strings[0] ?? "";
489
- for (let i = 0; i < sql3.values.length; i++) {
490
- const val = getValueFromParameter(sql3.values[i]);
491
- out += formatValue(val);
492
- out += sql3.strings[i + 1] ?? "";
493
- }
494
- return out.replace(/\s+/g, " ").trim();
495
- } catch (error) {
496
- console.log(`toQueryPreview error: ${error}`);
497
- return "/* query preview unavailable */";
498
- }
499
- };
500
- getValueFromParameter = (value) => {
501
- if (Array.isArray(value)) {
502
- const [type, val] = value;
503
- if (type === "Identifier") return val;
504
- }
505
- return value;
506
- };
507
- mapToClickHouseType = (value) => {
508
- if (typeof value === "number") {
509
- return Number.isInteger(value) ? "Int" : "Float";
510
- }
511
- if (typeof value === "boolean") return "Bool";
512
- if (value instanceof Date) return "DateTime";
513
- if (Array.isArray(value)) {
514
- const [type, _] = value;
515
- return type;
516
- }
517
- return "String";
518
- };
519
- }
520
- });
521
-
522
500
  // src/consumption-apis/helpers.ts
523
501
  import {
524
502
  Client as TemporalClient,
525
503
  Connection
526
504
  } from "@temporalio/client";
527
505
  import { createHash, randomUUID } from "crypto";
528
- var init_helpers = __esm({
506
+ var init_helpers2 = __esm({
529
507
  "src/consumption-apis/helpers.ts"() {
530
508
  "use strict";
531
509
  init_internal();
@@ -563,7 +541,7 @@ var init_runner = __esm({
563
541
  "src/consumption-apis/runner.ts"() {
564
542
  "use strict";
565
543
  init_commons();
566
- init_helpers();
544
+ init_helpers2();
567
545
  init_cluster_utils();
568
546
  init_sqlHelpers();
569
547
  init_internal();
@@ -582,7 +560,7 @@ var init_redisClient = __esm({
582
560
  var init_standalone = __esm({
583
561
  "src/consumption-apis/standalone.ts"() {
584
562
  "use strict";
585
- init_helpers();
563
+ init_helpers2();
586
564
  init_commons();
587
565
  init_sqlHelpers();
588
566
  }
@@ -632,19 +610,27 @@ var init_dataSource = __esm({
632
610
  }
633
611
  });
634
612
 
613
+ // src/dataModels/types.ts
614
+ var init_types = __esm({
615
+ "src/dataModels/types.ts"() {
616
+ "use strict";
617
+ }
618
+ });
619
+
635
620
  // src/index.ts
636
621
  var init_index = __esm({
637
622
  "src/index.ts"() {
638
623
  "use strict";
639
624
  init_browserCompatible();
625
+ init_helpers();
640
626
  init_commons();
641
627
  init_secrets();
642
- init_helpers();
628
+ init_helpers2();
643
629
  init_webAppHelpers();
644
630
  init_task();
645
631
  init_runner();
646
632
  init_redisClient();
647
- init_helpers();
633
+ init_helpers2();
648
634
  init_standalone();
649
635
  init_sqlHelpers();
650
636
  init_utilities();
@@ -998,7 +984,7 @@ var init_olapTable = __esm({
998
984
  "use strict";
999
985
  init_typedBase();
1000
986
  init_dataModelTypes();
1001
- init_types();
987
+ init_helpers();
1002
988
  init_internal();
1003
989
  init_sqlHelpers();
1004
990
  OlapTable = class extends TypedBase {
@@ -2291,7 +2277,7 @@ var init_ingestPipeline = __esm({
2291
2277
  init_stream();
2292
2278
  init_olapTable();
2293
2279
  init_ingestApi();
2294
- init_types();
2280
+ init_helpers();
2295
2281
  IngestPipeline = class extends TypedBase {
2296
2282
  /**
2297
2283
  * The OLAP table component of the pipeline, if configured.
@@ -2564,7 +2550,7 @@ var requireTargetTableName, MaterializedView;
2564
2550
  var init_materializedView = __esm({
2565
2551
  "src/dmv2/sdk/materializedView.ts"() {
2566
2552
  "use strict";
2567
- init_types();
2553
+ init_helpers();
2568
2554
  init_sqlHelpers();
2569
2555
  init_olapTable();
2570
2556
  init_internal();
@@ -2983,7 +2969,6 @@ var init_dmv2 = __esm({
2983
2969
  "src/dmv2/index.ts"() {
2984
2970
  "use strict";
2985
2971
  init_olapTable();
2986
- init_types();
2987
2972
  init_stream();
2988
2973
  init_workflow();
2989
2974
  init_ingestApi();
@@ -3010,7 +2995,6 @@ var init_browserCompatible = __esm({
3010
2995
  init_browserCompatible();
3011
2996
  export {
3012
2997
  Api,
3013
- ClickHouseEngines,
3014
2998
  ConsumptionApi,
3015
2999
  DeadLetterQueue,
3016
3000
  ETLPipeline,