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

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,171 +155,33 @@ var init_dataModelTypes = __esm({
155
155
  }
156
156
  });
157
157
 
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"() {
171
- "use strict";
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"() {
158
+ // src/dataModels/types.ts
159
+ var ClickHouseEngines;
160
+ var init_types = __esm({
161
+ "src/dataModels/types.ts"() {
321
162
  "use strict";
322
- init_sqlHelpers();
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 || {});
323
185
  }
324
186
  });
325
187
 
@@ -497,13 +359,173 @@ var init_secrets = __esm({
497
359
  }
498
360
  });
499
361
 
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
+
500
522
  // src/consumption-apis/helpers.ts
501
523
  import {
502
524
  Client as TemporalClient,
503
525
  Connection
504
526
  } from "@temporalio/client";
505
527
  import { createHash, randomUUID } from "crypto";
506
- var init_helpers2 = __esm({
528
+ var init_helpers = __esm({
507
529
  "src/consumption-apis/helpers.ts"() {
508
530
  "use strict";
509
531
  init_internal();
@@ -541,7 +563,7 @@ var init_runner = __esm({
541
563
  "src/consumption-apis/runner.ts"() {
542
564
  "use strict";
543
565
  init_commons();
544
- init_helpers2();
566
+ init_helpers();
545
567
  init_cluster_utils();
546
568
  init_sqlHelpers();
547
569
  init_internal();
@@ -560,7 +582,7 @@ var init_redisClient = __esm({
560
582
  var init_standalone = __esm({
561
583
  "src/consumption-apis/standalone.ts"() {
562
584
  "use strict";
563
- init_helpers2();
585
+ init_helpers();
564
586
  init_commons();
565
587
  init_sqlHelpers();
566
588
  }
@@ -610,27 +632,19 @@ var init_dataSource = __esm({
610
632
  }
611
633
  });
612
634
 
613
- // src/dataModels/types.ts
614
- var init_types = __esm({
615
- "src/dataModels/types.ts"() {
616
- "use strict";
617
- }
618
- });
619
-
620
635
  // src/index.ts
621
636
  var init_index = __esm({
622
637
  "src/index.ts"() {
623
638
  "use strict";
624
639
  init_browserCompatible();
625
- init_helpers();
626
640
  init_commons();
627
641
  init_secrets();
628
- init_helpers2();
642
+ init_helpers();
629
643
  init_webAppHelpers();
630
644
  init_task();
631
645
  init_runner();
632
646
  init_redisClient();
633
- init_helpers2();
647
+ init_helpers();
634
648
  init_standalone();
635
649
  init_sqlHelpers();
636
650
  init_utilities();
@@ -984,7 +998,7 @@ var init_olapTable = __esm({
984
998
  "use strict";
985
999
  init_typedBase();
986
1000
  init_dataModelTypes();
987
- init_helpers();
1001
+ init_types();
988
1002
  init_internal();
989
1003
  init_sqlHelpers();
990
1004
  OlapTable = class extends TypedBase {
@@ -2277,7 +2291,7 @@ var init_ingestPipeline = __esm({
2277
2291
  init_stream();
2278
2292
  init_olapTable();
2279
2293
  init_ingestApi();
2280
- init_helpers();
2294
+ init_types();
2281
2295
  IngestPipeline = class extends TypedBase {
2282
2296
  /**
2283
2297
  * The OLAP table component of the pipeline, if configured.
@@ -2550,7 +2564,7 @@ var requireTargetTableName, MaterializedView;
2550
2564
  var init_materializedView = __esm({
2551
2565
  "src/dmv2/sdk/materializedView.ts"() {
2552
2566
  "use strict";
2553
- init_helpers();
2567
+ init_types();
2554
2568
  init_sqlHelpers();
2555
2569
  init_olapTable();
2556
2570
  init_internal();
@@ -2969,6 +2983,7 @@ var init_dmv2 = __esm({
2969
2983
  "src/dmv2/index.ts"() {
2970
2984
  "use strict";
2971
2985
  init_olapTable();
2986
+ init_types();
2972
2987
  init_stream();
2973
2988
  init_workflow();
2974
2989
  init_ingestApi();
@@ -2995,6 +3010,7 @@ var init_browserCompatible = __esm({
2995
3010
  init_browserCompatible();
2996
3011
  export {
2997
3012
  Api,
3013
+ ClickHouseEngines,
2998
3014
  ConsumptionApi,
2999
3015
  DeadLetterQueue,
3000
3016
  ETLPipeline,