@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.js CHANGED
@@ -177,184 +177,11 @@ var init_dataModelTypes = __esm({
177
177
  }
178
178
  });
179
179
 
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"() {
193
- "use strict";
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
- function dropView(name) {
342
- return `DROP VIEW IF EXISTS ${quoteIdentifier(name)}`.trim();
343
- }
344
- function createMaterializedView(options) {
345
- return `CREATE MATERIALIZED VIEW IF NOT EXISTS ${quoteIdentifier(options.name)}
346
- TO ${quoteIdentifier(options.destinationTable)}
347
- AS ${options.select}`.trim();
348
- }
349
- function populateTable(options) {
350
- return `INSERT INTO ${quoteIdentifier(options.destinationTable)}
351
- ${options.select}`.trim();
352
- }
180
+ // src/dataModels/types.ts
353
181
  var ClickHouseEngines;
354
- var init_helpers = __esm({
355
- "src/blocks/helpers.ts"() {
182
+ var init_types = __esm({
183
+ "src/dataModels/types.ts"() {
356
184
  "use strict";
357
- init_sqlHelpers();
358
185
  ClickHouseEngines = /* @__PURE__ */ ((ClickHouseEngines2) => {
359
186
  ClickHouseEngines2["MergeTree"] = "MergeTree";
360
187
  ClickHouseEngines2["ReplacingMergeTree"] = "ReplacingMergeTree";
@@ -745,6 +572,166 @@ var init_internal = __esm({
745
572
  }
746
573
  });
747
574
 
575
+ // src/sqlHelpers.ts
576
+ function sql(strings, ...values) {
577
+ return new Sql(strings, values);
578
+ }
579
+ function createClickhouseParameter(parameterIndex, value) {
580
+ return `{p${parameterIndex}:${mapToClickHouseType(value)}}`;
581
+ }
582
+ function emptyIfUndefined(value) {
583
+ return value === void 0 ? "" : value;
584
+ }
585
+ var quoteIdentifier, isTable, isView, isColumn, instanceofSql, Sql, toStaticQuery, toQuery, toQueryPreview, getValueFromParameter, mapToClickHouseType;
586
+ var init_sqlHelpers = __esm({
587
+ "src/sqlHelpers.ts"() {
588
+ "use strict";
589
+ quoteIdentifier = (name) => {
590
+ return name.startsWith("`") && name.endsWith("`") ? name : `\`${name}\``;
591
+ };
592
+ isTable = (value) => typeof value === "object" && value !== null && "kind" in value && value.kind === "OlapTable";
593
+ isView = (value) => typeof value === "object" && value !== null && "kind" in value && value.kind === "View";
594
+ isColumn = (value) => typeof value === "object" && value !== null && !("kind" in value) && "name" in value && "annotations" in value;
595
+ instanceofSql = (value) => typeof value === "object" && "values" in value && "strings" in value;
596
+ Sql = class {
597
+ values;
598
+ strings;
599
+ constructor(rawStrings, rawValues) {
600
+ if (rawStrings.length - 1 !== rawValues.length) {
601
+ if (rawStrings.length === 0) {
602
+ throw new TypeError("Expected at least 1 string");
603
+ }
604
+ throw new TypeError(
605
+ `Expected ${rawStrings.length} strings to have ${rawStrings.length - 1} values`
606
+ );
607
+ }
608
+ const valuesLength = rawValues.reduce(
609
+ (len, value) => len + (instanceofSql(value) ? value.values.length : isColumn(value) || isTable(value) || isView(value) ? 0 : 1),
610
+ 0
611
+ );
612
+ this.values = new Array(valuesLength);
613
+ this.strings = new Array(valuesLength + 1);
614
+ this.strings[0] = rawStrings[0];
615
+ let i = 0, pos = 0;
616
+ while (i < rawValues.length) {
617
+ const child = rawValues[i++];
618
+ const rawString = rawStrings[i];
619
+ if (instanceofSql(child)) {
620
+ this.strings[pos] += child.strings[0];
621
+ let childIndex = 0;
622
+ while (childIndex < child.values.length) {
623
+ this.values[pos++] = child.values[childIndex++];
624
+ this.strings[pos] = child.strings[childIndex];
625
+ }
626
+ this.strings[pos] += rawString;
627
+ } else if (isColumn(child)) {
628
+ const aggregationFunction = child.annotations.find(
629
+ ([k, _]) => k === "aggregationFunction"
630
+ );
631
+ if (aggregationFunction !== void 0) {
632
+ this.strings[pos] += `${aggregationFunction[1].functionName}Merge(\`${child.name}\`)`;
633
+ } else {
634
+ this.strings[pos] += `\`${child.name}\``;
635
+ }
636
+ this.strings[pos] += rawString;
637
+ } else if (isTable(child)) {
638
+ if (child.config.database) {
639
+ this.strings[pos] += `\`${child.config.database}\`.\`${child.name}\``;
640
+ } else {
641
+ this.strings[pos] += `\`${child.name}\``;
642
+ }
643
+ this.strings[pos] += rawString;
644
+ } else if (isView(child)) {
645
+ this.strings[pos] += `\`${child.name}\``;
646
+ this.strings[pos] += rawString;
647
+ } else {
648
+ this.values[pos++] = child;
649
+ this.strings[pos] = rawString;
650
+ }
651
+ }
652
+ }
653
+ };
654
+ toStaticQuery = (sql3) => {
655
+ const [query, params] = toQuery(sql3);
656
+ if (Object.keys(params).length !== 0) {
657
+ throw new Error(
658
+ "Dynamic SQL is not allowed in the select statement in view creation."
659
+ );
660
+ }
661
+ return query;
662
+ };
663
+ toQuery = (sql3) => {
664
+ const parameterizedStubs = sql3.values.map(
665
+ (v, i) => createClickhouseParameter(i, v)
666
+ );
667
+ const query = sql3.strings.map(
668
+ (s, i) => s != "" ? `${s}${emptyIfUndefined(parameterizedStubs[i])}` : ""
669
+ ).join("");
670
+ const query_params = sql3.values.reduce(
671
+ (acc, v, i) => ({
672
+ ...acc,
673
+ [`p${i}`]: getValueFromParameter(v)
674
+ }),
675
+ {}
676
+ );
677
+ return [query, query_params];
678
+ };
679
+ toQueryPreview = (sql3) => {
680
+ try {
681
+ const formatValue = (v) => {
682
+ if (Array.isArray(v)) {
683
+ const [type, val] = v;
684
+ if (type === "Identifier") {
685
+ return `\`${String(val)}\``;
686
+ }
687
+ return `[${v.map((x) => formatValue(x)).join(", ")}]`;
688
+ }
689
+ if (v === null || v === void 0) return "NULL";
690
+ if (typeof v === "string") return `'${v.replace(/'/g, "''")}'`;
691
+ if (typeof v === "number") return String(v);
692
+ if (typeof v === "boolean") return v ? "true" : "false";
693
+ if (v instanceof Date)
694
+ return `'${v.toISOString().replace("T", " ").slice(0, 19)}'`;
695
+ try {
696
+ return JSON.stringify(v);
697
+ } catch {
698
+ return String(v);
699
+ }
700
+ };
701
+ let out = sql3.strings[0] ?? "";
702
+ for (let i = 0; i < sql3.values.length; i++) {
703
+ const val = getValueFromParameter(sql3.values[i]);
704
+ out += formatValue(val);
705
+ out += sql3.strings[i + 1] ?? "";
706
+ }
707
+ return out.replace(/\s+/g, " ").trim();
708
+ } catch (error) {
709
+ console.log(`toQueryPreview error: ${error}`);
710
+ return "/* query preview unavailable */";
711
+ }
712
+ };
713
+ getValueFromParameter = (value) => {
714
+ if (Array.isArray(value)) {
715
+ const [type, val] = value;
716
+ if (type === "Identifier") return val;
717
+ }
718
+ return value;
719
+ };
720
+ mapToClickHouseType = (value) => {
721
+ if (typeof value === "number") {
722
+ return Number.isInteger(value) ? "Int" : "Float";
723
+ }
724
+ if (typeof value === "boolean") return "Bool";
725
+ if (value instanceof Date) return "DateTime";
726
+ if (Array.isArray(value)) {
727
+ const [type, _] = value;
728
+ return type;
729
+ }
730
+ return "String";
731
+ };
732
+ }
733
+ });
734
+
748
735
  // src/config/configFile.ts
749
736
  async function findConfigFile(startDir = process.cwd()) {
750
737
  const fs2 = await import("fs");
@@ -936,7 +923,7 @@ var init_olapTable = __esm({
936
923
  "use strict";
937
924
  init_typedBase();
938
925
  init_dataModelTypes();
939
- init_helpers();
926
+ init_types();
940
927
  init_internal();
941
928
  import_node_stream = require("stream");
942
929
  import_node_crypto = require("crypto");
@@ -2231,7 +2218,7 @@ var init_ingestPipeline = __esm({
2231
2218
  init_stream();
2232
2219
  init_olapTable();
2233
2220
  init_ingestApi();
2234
- init_helpers();
2221
+ init_types();
2235
2222
  IngestPipeline = class extends TypedBase {
2236
2223
  /**
2237
2224
  * The OLAP table component of the pipeline, if configured.
@@ -2504,7 +2491,7 @@ var requireTargetTableName, MaterializedView;
2504
2491
  var init_materializedView = __esm({
2505
2492
  "src/dmv2/sdk/materializedView.ts"() {
2506
2493
  "use strict";
2507
- init_helpers();
2494
+ init_types();
2508
2495
  init_sqlHelpers();
2509
2496
  init_olapTable();
2510
2497
  init_internal();
@@ -2923,6 +2910,7 @@ var init_dmv2 = __esm({
2923
2910
  "src/dmv2/index.ts"() {
2924
2911
  "use strict";
2925
2912
  init_olapTable();
2913
+ init_types();
2926
2914
  init_stream();
2927
2915
  init_workflow();
2928
2916
  init_ingestApi();
@@ -2938,13 +2926,6 @@ var init_dmv2 = __esm({
2938
2926
  }
2939
2927
  });
2940
2928
 
2941
- // src/dataModels/types.ts
2942
- var init_types = __esm({
2943
- "src/dataModels/types.ts"() {
2944
- "use strict";
2945
- }
2946
- });
2947
-
2948
2929
  // src/browserCompatible.ts
2949
2930
  var init_browserCompatible = __esm({
2950
2931
  "src/browserCompatible.ts"() {
@@ -3073,7 +3054,7 @@ function joinQueries({
3073
3054
  );
3074
3055
  }
3075
3056
  var import_client2, import_node_crypto3, import_perf_hooks, fs, MooseClient, QueryClient, WorkflowClient, ApiHelpers, ConsumptionHelpers;
3076
- var init_helpers2 = __esm({
3057
+ var init_helpers = __esm({
3077
3058
  "src/consumption-apis/helpers.ts"() {
3078
3059
  "use strict";
3079
3060
  import_client2 = require("@temporalio/client");
@@ -3200,11 +3181,11 @@ var init_helpers2 = __esm({
3200
3181
  }
3201
3182
  async getWorkflowConfig(name) {
3202
3183
  const workflows = await getWorkflows();
3203
- const dmv2Workflow = workflows.get(name);
3204
- if (dmv2Workflow) {
3184
+ const workflow = workflows.get(name);
3185
+ if (workflow) {
3205
3186
  return {
3206
- retries: dmv2Workflow.config.retries || 3,
3207
- timeout: dmv2Workflow.config.timeout || "1h"
3187
+ retries: workflow.config.retries || 3,
3188
+ timeout: workflow.config.timeout || "1h"
3208
3189
  };
3209
3190
  }
3210
3191
  throw new Error(`Workflow config not found for ${name}`);
@@ -3281,7 +3262,7 @@ var init_runner = __esm({
3281
3262
  "src/consumption-apis/runner.ts"() {
3282
3263
  "use strict";
3283
3264
  init_commons();
3284
- init_helpers2();
3265
+ init_helpers();
3285
3266
  jose = __toESM(require("jose"));
3286
3267
  init_cluster_utils();
3287
3268
  init_sqlHelpers();
@@ -3631,7 +3612,7 @@ var standaloneUtils, initPromise2, toClientConfig;
3631
3612
  var init_standalone = __esm({
3632
3613
  "src/consumption-apis/standalone.ts"() {
3633
3614
  "use strict";
3634
- init_helpers2();
3615
+ init_helpers();
3635
3616
  init_commons();
3636
3617
  init_sqlHelpers();
3637
3618
  standaloneUtils = null;
@@ -3786,9 +3767,7 @@ __export(index_exports, {
3786
3767
  createApi: () => createApi,
3787
3768
  createClickhouseParameter: () => createClickhouseParameter,
3788
3769
  createConsumptionApi: () => createConsumptionApi,
3789
- createMaterializedView: () => createMaterializedView,
3790
3770
  createProducerConfig: () => createProducerConfig,
3791
- dropView: () => dropView,
3792
3771
  expressMiddleware: () => expressMiddleware,
3793
3772
  getApi: () => getApi,
3794
3773
  getApis: () => getApis,
@@ -3828,7 +3807,6 @@ __export(index_exports, {
3828
3807
  parseCSV: () => parseCSV,
3829
3808
  parseJSON: () => parseJSON,
3830
3809
  parseJSONWithDates: () => parseJSONWithDates,
3831
- populateTable: () => populateTable,
3832
3810
  quoteIdentifier: () => quoteIdentifier,
3833
3811
  sql: () => sql,
3834
3812
  toQuery: () => toQuery,
@@ -3839,15 +3817,14 @@ module.exports = __toCommonJS(index_exports);
3839
3817
  var init_index = __esm({
3840
3818
  "src/index.ts"() {
3841
3819
  init_browserCompatible();
3842
- init_helpers();
3843
3820
  init_commons();
3844
3821
  init_secrets();
3845
- init_helpers2();
3822
+ init_helpers();
3846
3823
  init_webAppHelpers();
3847
3824
  init_task();
3848
3825
  init_runner();
3849
3826
  init_redisClient();
3850
- init_helpers2();
3827
+ init_helpers();
3851
3828
  init_standalone();
3852
3829
  init_sqlHelpers();
3853
3830
  init_utilities();
@@ -3898,9 +3875,7 @@ init_index();
3898
3875
  createApi,
3899
3876
  createClickhouseParameter,
3900
3877
  createConsumptionApi,
3901
- createMaterializedView,
3902
3878
  createProducerConfig,
3903
- dropView,
3904
3879
  expressMiddleware,
3905
3880
  getApi,
3906
3881
  getApis,
@@ -3940,7 +3915,6 @@ init_index();
3940
3915
  parseCSV,
3941
3916
  parseJSON,
3942
3917
  parseJSONWithDates,
3943
- populateTable,
3944
3918
  quoteIdentifier,
3945
3919
  sql,
3946
3920
  toQuery,