@514labs/moose-lib 0.6.320 → 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.
package/dist/index.mjs CHANGED
@@ -161,184 +161,11 @@ var init_dataModelTypes = __esm({
161
161
  }
162
162
  });
163
163
 
164
- // src/sqlHelpers.ts
165
- function sql(strings, ...values) {
166
- return new Sql(strings, values);
167
- }
168
- function createClickhouseParameter(parameterIndex, value) {
169
- return `{p${parameterIndex}:${mapToClickHouseType(value)}}`;
170
- }
171
- function emptyIfUndefined(value) {
172
- return value === void 0 ? "" : value;
173
- }
174
- var quoteIdentifier, isTable, isView, isColumn, instanceofSql, Sql, toStaticQuery, toQuery, toQueryPreview, getValueFromParameter, mapToClickHouseType;
175
- var init_sqlHelpers = __esm({
176
- "src/sqlHelpers.ts"() {
177
- "use strict";
178
- quoteIdentifier = (name) => {
179
- return name.startsWith("`") && name.endsWith("`") ? name : `\`${name}\``;
180
- };
181
- isTable = (value) => typeof value === "object" && value !== null && "kind" in value && value.kind === "OlapTable";
182
- isView = (value) => typeof value === "object" && value !== null && "kind" in value && value.kind === "View";
183
- isColumn = (value) => typeof value === "object" && value !== null && !("kind" in value) && "name" in value && "annotations" in value;
184
- instanceofSql = (value) => typeof value === "object" && "values" in value && "strings" in value;
185
- Sql = class {
186
- values;
187
- strings;
188
- constructor(rawStrings, rawValues) {
189
- if (rawStrings.length - 1 !== rawValues.length) {
190
- if (rawStrings.length === 0) {
191
- throw new TypeError("Expected at least 1 string");
192
- }
193
- throw new TypeError(
194
- `Expected ${rawStrings.length} strings to have ${rawStrings.length - 1} values`
195
- );
196
- }
197
- const valuesLength = rawValues.reduce(
198
- (len, value) => len + (instanceofSql(value) ? value.values.length : isColumn(value) || isTable(value) || isView(value) ? 0 : 1),
199
- 0
200
- );
201
- this.values = new Array(valuesLength);
202
- this.strings = new Array(valuesLength + 1);
203
- this.strings[0] = rawStrings[0];
204
- let i = 0, pos = 0;
205
- while (i < rawValues.length) {
206
- const child = rawValues[i++];
207
- const rawString = rawStrings[i];
208
- if (instanceofSql(child)) {
209
- this.strings[pos] += child.strings[0];
210
- let childIndex = 0;
211
- while (childIndex < child.values.length) {
212
- this.values[pos++] = child.values[childIndex++];
213
- this.strings[pos] = child.strings[childIndex];
214
- }
215
- this.strings[pos] += rawString;
216
- } else if (isColumn(child)) {
217
- const aggregationFunction = child.annotations.find(
218
- ([k, _]) => k === "aggregationFunction"
219
- );
220
- if (aggregationFunction !== void 0) {
221
- this.strings[pos] += `${aggregationFunction[1].functionName}Merge(\`${child.name}\`)`;
222
- } else {
223
- this.strings[pos] += `\`${child.name}\``;
224
- }
225
- this.strings[pos] += rawString;
226
- } else if (isTable(child)) {
227
- if (child.config.database) {
228
- this.strings[pos] += `\`${child.config.database}\`.\`${child.name}\``;
229
- } else {
230
- this.strings[pos] += `\`${child.name}\``;
231
- }
232
- this.strings[pos] += rawString;
233
- } else if (isView(child)) {
234
- this.strings[pos] += `\`${child.name}\``;
235
- this.strings[pos] += rawString;
236
- } else {
237
- this.values[pos++] = child;
238
- this.strings[pos] = rawString;
239
- }
240
- }
241
- }
242
- };
243
- toStaticQuery = (sql3) => {
244
- const [query, params] = toQuery(sql3);
245
- if (Object.keys(params).length !== 0) {
246
- throw new Error(
247
- "Dynamic SQL is not allowed in the select statement in view creation."
248
- );
249
- }
250
- return query;
251
- };
252
- toQuery = (sql3) => {
253
- const parameterizedStubs = sql3.values.map(
254
- (v, i) => createClickhouseParameter(i, v)
255
- );
256
- const query = sql3.strings.map(
257
- (s, i) => s != "" ? `${s}${emptyIfUndefined(parameterizedStubs[i])}` : ""
258
- ).join("");
259
- const query_params = sql3.values.reduce(
260
- (acc, v, i) => ({
261
- ...acc,
262
- [`p${i}`]: getValueFromParameter(v)
263
- }),
264
- {}
265
- );
266
- return [query, query_params];
267
- };
268
- toQueryPreview = (sql3) => {
269
- try {
270
- const formatValue = (v) => {
271
- if (Array.isArray(v)) {
272
- const [type, val] = v;
273
- if (type === "Identifier") {
274
- return `\`${String(val)}\``;
275
- }
276
- return `[${v.map((x) => formatValue(x)).join(", ")}]`;
277
- }
278
- if (v === null || v === void 0) return "NULL";
279
- if (typeof v === "string") return `'${v.replace(/'/g, "''")}'`;
280
- if (typeof v === "number") return String(v);
281
- if (typeof v === "boolean") return v ? "true" : "false";
282
- if (v instanceof Date)
283
- return `'${v.toISOString().replace("T", " ").slice(0, 19)}'`;
284
- try {
285
- return JSON.stringify(v);
286
- } catch {
287
- return String(v);
288
- }
289
- };
290
- let out = sql3.strings[0] ?? "";
291
- for (let i = 0; i < sql3.values.length; i++) {
292
- const val = getValueFromParameter(sql3.values[i]);
293
- out += formatValue(val);
294
- out += sql3.strings[i + 1] ?? "";
295
- }
296
- return out.replace(/\s+/g, " ").trim();
297
- } catch (error) {
298
- console.log(`toQueryPreview error: ${error}`);
299
- return "/* query preview unavailable */";
300
- }
301
- };
302
- getValueFromParameter = (value) => {
303
- if (Array.isArray(value)) {
304
- const [type, val] = value;
305
- if (type === "Identifier") return val;
306
- }
307
- return value;
308
- };
309
- mapToClickHouseType = (value) => {
310
- if (typeof value === "number") {
311
- return Number.isInteger(value) ? "Int" : "Float";
312
- }
313
- if (typeof value === "boolean") return "Bool";
314
- if (value instanceof Date) return "DateTime";
315
- if (Array.isArray(value)) {
316
- const [type, _] = value;
317
- return type;
318
- }
319
- return "String";
320
- };
321
- }
322
- });
323
-
324
- // src/blocks/helpers.ts
325
- function dropView(name) {
326
- return `DROP VIEW IF EXISTS ${quoteIdentifier(name)}`.trim();
327
- }
328
- function createMaterializedView(options) {
329
- return `CREATE MATERIALIZED VIEW IF NOT EXISTS ${quoteIdentifier(options.name)}
330
- TO ${quoteIdentifier(options.destinationTable)}
331
- AS ${options.select}`.trim();
332
- }
333
- function populateTable(options) {
334
- return `INSERT INTO ${quoteIdentifier(options.destinationTable)}
335
- ${options.select}`.trim();
336
- }
164
+ // src/dataModels/types.ts
337
165
  var ClickHouseEngines;
338
- var init_helpers = __esm({
339
- "src/blocks/helpers.ts"() {
166
+ var init_types = __esm({
167
+ "src/dataModels/types.ts"() {
340
168
  "use strict";
341
- init_sqlHelpers();
342
169
  ClickHouseEngines = /* @__PURE__ */ ((ClickHouseEngines2) => {
343
170
  ClickHouseEngines2["MergeTree"] = "MergeTree";
344
171
  ClickHouseEngines2["ReplacingMergeTree"] = "ReplacingMergeTree";
@@ -729,6 +556,166 @@ var init_internal = __esm({
729
556
  }
730
557
  });
731
558
 
559
+ // src/sqlHelpers.ts
560
+ function sql(strings, ...values) {
561
+ return new Sql(strings, values);
562
+ }
563
+ function createClickhouseParameter(parameterIndex, value) {
564
+ return `{p${parameterIndex}:${mapToClickHouseType(value)}}`;
565
+ }
566
+ function emptyIfUndefined(value) {
567
+ return value === void 0 ? "" : value;
568
+ }
569
+ var quoteIdentifier, isTable, isView, isColumn, instanceofSql, Sql, toStaticQuery, toQuery, toQueryPreview, getValueFromParameter, mapToClickHouseType;
570
+ var init_sqlHelpers = __esm({
571
+ "src/sqlHelpers.ts"() {
572
+ "use strict";
573
+ quoteIdentifier = (name) => {
574
+ return name.startsWith("`") && name.endsWith("`") ? name : `\`${name}\``;
575
+ };
576
+ isTable = (value) => typeof value === "object" && value !== null && "kind" in value && value.kind === "OlapTable";
577
+ isView = (value) => typeof value === "object" && value !== null && "kind" in value && value.kind === "View";
578
+ isColumn = (value) => typeof value === "object" && value !== null && !("kind" in value) && "name" in value && "annotations" in value;
579
+ instanceofSql = (value) => typeof value === "object" && "values" in value && "strings" in value;
580
+ Sql = class {
581
+ values;
582
+ strings;
583
+ constructor(rawStrings, rawValues) {
584
+ if (rawStrings.length - 1 !== rawValues.length) {
585
+ if (rawStrings.length === 0) {
586
+ throw new TypeError("Expected at least 1 string");
587
+ }
588
+ throw new TypeError(
589
+ `Expected ${rawStrings.length} strings to have ${rawStrings.length - 1} values`
590
+ );
591
+ }
592
+ const valuesLength = rawValues.reduce(
593
+ (len, value) => len + (instanceofSql(value) ? value.values.length : isColumn(value) || isTable(value) || isView(value) ? 0 : 1),
594
+ 0
595
+ );
596
+ this.values = new Array(valuesLength);
597
+ this.strings = new Array(valuesLength + 1);
598
+ this.strings[0] = rawStrings[0];
599
+ let i = 0, pos = 0;
600
+ while (i < rawValues.length) {
601
+ const child = rawValues[i++];
602
+ const rawString = rawStrings[i];
603
+ if (instanceofSql(child)) {
604
+ this.strings[pos] += child.strings[0];
605
+ let childIndex = 0;
606
+ while (childIndex < child.values.length) {
607
+ this.values[pos++] = child.values[childIndex++];
608
+ this.strings[pos] = child.strings[childIndex];
609
+ }
610
+ this.strings[pos] += rawString;
611
+ } else if (isColumn(child)) {
612
+ const aggregationFunction = child.annotations.find(
613
+ ([k, _]) => k === "aggregationFunction"
614
+ );
615
+ if (aggregationFunction !== void 0) {
616
+ this.strings[pos] += `${aggregationFunction[1].functionName}Merge(\`${child.name}\`)`;
617
+ } else {
618
+ this.strings[pos] += `\`${child.name}\``;
619
+ }
620
+ this.strings[pos] += rawString;
621
+ } else if (isTable(child)) {
622
+ if (child.config.database) {
623
+ this.strings[pos] += `\`${child.config.database}\`.\`${child.name}\``;
624
+ } else {
625
+ this.strings[pos] += `\`${child.name}\``;
626
+ }
627
+ this.strings[pos] += rawString;
628
+ } else if (isView(child)) {
629
+ this.strings[pos] += `\`${child.name}\``;
630
+ this.strings[pos] += rawString;
631
+ } else {
632
+ this.values[pos++] = child;
633
+ this.strings[pos] = rawString;
634
+ }
635
+ }
636
+ }
637
+ };
638
+ toStaticQuery = (sql3) => {
639
+ const [query, params] = toQuery(sql3);
640
+ if (Object.keys(params).length !== 0) {
641
+ throw new Error(
642
+ "Dynamic SQL is not allowed in the select statement in view creation."
643
+ );
644
+ }
645
+ return query;
646
+ };
647
+ toQuery = (sql3) => {
648
+ const parameterizedStubs = sql3.values.map(
649
+ (v, i) => createClickhouseParameter(i, v)
650
+ );
651
+ const query = sql3.strings.map(
652
+ (s, i) => s != "" ? `${s}${emptyIfUndefined(parameterizedStubs[i])}` : ""
653
+ ).join("");
654
+ const query_params = sql3.values.reduce(
655
+ (acc, v, i) => ({
656
+ ...acc,
657
+ [`p${i}`]: getValueFromParameter(v)
658
+ }),
659
+ {}
660
+ );
661
+ return [query, query_params];
662
+ };
663
+ toQueryPreview = (sql3) => {
664
+ try {
665
+ const formatValue = (v) => {
666
+ if (Array.isArray(v)) {
667
+ const [type, val] = v;
668
+ if (type === "Identifier") {
669
+ return `\`${String(val)}\``;
670
+ }
671
+ return `[${v.map((x) => formatValue(x)).join(", ")}]`;
672
+ }
673
+ if (v === null || v === void 0) return "NULL";
674
+ if (typeof v === "string") return `'${v.replace(/'/g, "''")}'`;
675
+ if (typeof v === "number") return String(v);
676
+ if (typeof v === "boolean") return v ? "true" : "false";
677
+ if (v instanceof Date)
678
+ return `'${v.toISOString().replace("T", " ").slice(0, 19)}'`;
679
+ try {
680
+ return JSON.stringify(v);
681
+ } catch {
682
+ return String(v);
683
+ }
684
+ };
685
+ let out = sql3.strings[0] ?? "";
686
+ for (let i = 0; i < sql3.values.length; i++) {
687
+ const val = getValueFromParameter(sql3.values[i]);
688
+ out += formatValue(val);
689
+ out += sql3.strings[i + 1] ?? "";
690
+ }
691
+ return out.replace(/\s+/g, " ").trim();
692
+ } catch (error) {
693
+ console.log(`toQueryPreview error: ${error}`);
694
+ return "/* query preview unavailable */";
695
+ }
696
+ };
697
+ getValueFromParameter = (value) => {
698
+ if (Array.isArray(value)) {
699
+ const [type, val] = value;
700
+ if (type === "Identifier") return val;
701
+ }
702
+ return value;
703
+ };
704
+ mapToClickHouseType = (value) => {
705
+ if (typeof value === "number") {
706
+ return Number.isInteger(value) ? "Int" : "Float";
707
+ }
708
+ if (typeof value === "boolean") return "Bool";
709
+ if (value instanceof Date) return "DateTime";
710
+ if (Array.isArray(value)) {
711
+ const [type, _] = value;
712
+ return type;
713
+ }
714
+ return "String";
715
+ };
716
+ }
717
+ });
718
+
732
719
  // src/config/configFile.ts
733
720
  import path from "path";
734
721
  import * as toml from "toml";
@@ -922,7 +909,7 @@ var init_olapTable = __esm({
922
909
  "use strict";
923
910
  init_typedBase();
924
911
  init_dataModelTypes();
925
- init_helpers();
912
+ init_types();
926
913
  init_internal();
927
914
  init_sqlHelpers();
928
915
  OlapTable = class extends TypedBase {
@@ -2215,7 +2202,7 @@ var init_ingestPipeline = __esm({
2215
2202
  init_stream();
2216
2203
  init_olapTable();
2217
2204
  init_ingestApi();
2218
- init_helpers();
2205
+ init_types();
2219
2206
  IngestPipeline = class extends TypedBase {
2220
2207
  /**
2221
2208
  * The OLAP table component of the pipeline, if configured.
@@ -2488,7 +2475,7 @@ var requireTargetTableName, MaterializedView;
2488
2475
  var init_materializedView = __esm({
2489
2476
  "src/dmv2/sdk/materializedView.ts"() {
2490
2477
  "use strict";
2491
- init_helpers();
2478
+ init_types();
2492
2479
  init_sqlHelpers();
2493
2480
  init_olapTable();
2494
2481
  init_internal();
@@ -2907,6 +2894,7 @@ var init_dmv2 = __esm({
2907
2894
  "src/dmv2/index.ts"() {
2908
2895
  "use strict";
2909
2896
  init_olapTable();
2897
+ init_types();
2910
2898
  init_stream();
2911
2899
  init_workflow();
2912
2900
  init_ingestApi();
@@ -2922,13 +2910,6 @@ var init_dmv2 = __esm({
2922
2910
  }
2923
2911
  });
2924
2912
 
2925
- // src/dataModels/types.ts
2926
- var init_types = __esm({
2927
- "src/dataModels/types.ts"() {
2928
- "use strict";
2929
- }
2930
- });
2931
-
2932
2913
  // src/browserCompatible.ts
2933
2914
  var init_browserCompatible = __esm({
2934
2915
  "src/browserCompatible.ts"() {
@@ -3064,7 +3045,7 @@ function joinQueries({
3064
3045
  );
3065
3046
  }
3066
3047
  var MooseClient, QueryClient, WorkflowClient, ApiHelpers, ConsumptionHelpers;
3067
- var init_helpers2 = __esm({
3048
+ var init_helpers = __esm({
3068
3049
  "src/consumption-apis/helpers.ts"() {
3069
3050
  "use strict";
3070
3051
  init_internal();
@@ -3187,11 +3168,11 @@ var init_helpers2 = __esm({
3187
3168
  }
3188
3169
  async getWorkflowConfig(name) {
3189
3170
  const workflows = await getWorkflows();
3190
- const dmv2Workflow = workflows.get(name);
3191
- if (dmv2Workflow) {
3171
+ const workflow = workflows.get(name);
3172
+ if (workflow) {
3192
3173
  return {
3193
- retries: dmv2Workflow.config.retries || 3,
3194
- timeout: dmv2Workflow.config.timeout || "1h"
3174
+ retries: workflow.config.retries || 3,
3175
+ timeout: workflow.config.timeout || "1h"
3195
3176
  };
3196
3177
  }
3197
3178
  throw new Error(`Workflow config not found for ${name}`);
@@ -3268,7 +3249,7 @@ var init_runner = __esm({
3268
3249
  "src/consumption-apis/runner.ts"() {
3269
3250
  "use strict";
3270
3251
  init_commons();
3271
- init_helpers2();
3252
+ init_helpers();
3272
3253
  init_cluster_utils();
3273
3254
  init_sqlHelpers();
3274
3255
  init_internal();
@@ -3617,7 +3598,7 @@ var standaloneUtils, initPromise2, toClientConfig;
3617
3598
  var init_standalone = __esm({
3618
3599
  "src/consumption-apis/standalone.ts"() {
3619
3600
  "use strict";
3620
- init_helpers2();
3601
+ init_helpers();
3621
3602
  init_commons();
3622
3603
  init_sqlHelpers();
3623
3604
  standaloneUtils = null;
@@ -3733,15 +3714,14 @@ var init_dataSource = __esm({
3733
3714
  var init_index = __esm({
3734
3715
  "src/index.ts"() {
3735
3716
  init_browserCompatible();
3736
- init_helpers();
3737
3717
  init_commons();
3738
3718
  init_secrets();
3739
- init_helpers2();
3719
+ init_helpers();
3740
3720
  init_webAppHelpers();
3741
3721
  init_task();
3742
3722
  init_runner();
3743
3723
  init_redisClient();
3744
- init_helpers2();
3724
+ init_helpers();
3745
3725
  init_standalone();
3746
3726
  init_sqlHelpers();
3747
3727
  init_utilities();
@@ -3791,9 +3771,7 @@ export {
3791
3771
  createApi,
3792
3772
  createClickhouseParameter,
3793
3773
  createConsumptionApi,
3794
- createMaterializedView,
3795
3774
  createProducerConfig,
3796
- dropView,
3797
3775
  expressMiddleware,
3798
3776
  getApi,
3799
3777
  getApis,
@@ -3833,7 +3811,6 @@ export {
3833
3811
  parseCSV,
3834
3812
  parseJSON,
3835
3813
  parseJSONWithDates,
3836
- populateTable,
3837
3814
  quoteIdentifier,
3838
3815
  sql,
3839
3816
  toQuery,