@holistics/cli-core 2.4.9 → 2.4.11

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.
Files changed (2) hide show
  1. package/dist/commands.js +88 -53
  2. package/package.json +1 -1
package/dist/commands.js CHANGED
@@ -27805,7 +27805,7 @@ var require_dist3 = __commonJS((exports2) => {
27805
27805
  exports2.default = deferred;
27806
27806
  });
27807
27807
  // package.json
27808
- var version = "2.4.9";
27808
+ var version = "2.4.11";
27809
27809
 
27810
27810
  // ../../node_modules/.pnpm/@commander-js+extra-typings@13.1.0_commander@13.1.0/node_modules/@commander-js/extra-typings/esm.mjs
27811
27811
  var import__ = __toESM(require_extra_typings(), 1);
@@ -44816,7 +44816,7 @@ var import_fast_glob = __toESM(require_out4(), 1);
44816
44816
  import fs12 from "fs";
44817
44817
  import path8 from "path";
44818
44818
 
44819
- // ../../node_modules/.pnpm/@holistics+aml@9.2.0/node_modules/@holistics/aml/dist/aml.es.js
44819
+ // ../../node_modules/.pnpm/@holistics+aml@9.4.0/node_modules/@holistics/aml/dist/aml.es.js
44820
44820
  var exports_aml_es = {};
44821
44821
  __export(exports_aml_es, {
44822
44822
  voidType: () => mi,
@@ -45198,7 +45198,7 @@ __export(exports_aml_es, {
45198
45198
  AbstractSyntaxNode: () => de
45199
45199
  });
45200
45200
 
45201
- // ../../node_modules/.pnpm/@holistics+aml@9.2.0/node_modules/@holistics/aml/dist/vfsPath-CxxIp9T7.mjs
45201
+ // ../../node_modules/.pnpm/@holistics+aml@9.4.0/node_modules/@holistics/aml/dist/vfsPath-CxxIp9T7.mjs
45202
45202
  var s = {
45203
45203
  globalModuleName: "::",
45204
45204
  languageExtension: "aml"
@@ -45248,10 +45248,10 @@ class r {
45248
45248
  }
45249
45249
  }
45250
45250
 
45251
- // ../../node_modules/.pnpm/@holistics+aml@9.2.0/node_modules/@holistics/aml/dist/aml.es.js
45251
+ // ../../node_modules/.pnpm/@holistics+aml@9.4.0/node_modules/@holistics/aml/dist/aml.es.js
45252
45252
  import Cn from "fs";
45253
45253
  import Ur from "path";
45254
- var ud = "9.2.0";
45254
+ var ud = "9.4.0";
45255
45255
  var Ql = typeof global == "object" && global && global.Object === Object && global;
45256
45256
  var pd = typeof self == "object" && self && self.Object === Object && self;
45257
45257
  var Zt = Ql || pd || Function("return this")();
@@ -135136,14 +135136,24 @@ var generateGrainControlCode = (e16) => {
135136
135136
  let { keepFilters: r3 } = e16.grainControl, i = n.map((e17) => modelFieldRefToAql(e17)).join(", "), a = r3 ? ", keep_filters: true" : "";
135137
135137
  return t === "keep" ? `keep_grains(${i}${a})` : t === "exclude" ? `exclude_grains(${i}${a})` : "";
135138
135138
  };
135139
+ var generateDateTransformationCode = (e16) => {
135140
+ if (e16.truncationUnit)
135141
+ return `${e16.truncationUnit}()`;
135142
+ if (e16.datePartUnit)
135143
+ return `${e16.datePartUnit}_num()`;
135144
+ };
135139
135145
  var generateBasicAggCode = (e16, t) => {
135140
135146
  if (t.type !== SpecType.BasicAgg)
135141
135147
  throw Error(`Invalid basic aggregation type: ${t.type}`);
135142
135148
  if (!t.source)
135143
135149
  throw Error("Missing field in basic aggregation");
135144
- let n = modelFieldRefToAql(t.source);
135145
- return [
135146
- ...t.source.fieldName ? [`${t.aggregationType}(${n})`] : [n, `${t.aggregationType}(1)`],
135150
+ let n = modelFieldRefToAql(t.source), r3 = !t.source.fieldName, i = generateDateTransformationCode(t.source), a;
135151
+ return a = r3 ? [n, `${t.aggregationType}(1)`] : i ? [
135152
+ n,
135153
+ i,
135154
+ `${t.aggregationType}()`
135155
+ ] : [`${t.aggregationType}(${n})`], [
135156
+ ...a,
135147
135157
  t.conditionGroup ? generateWhereCode(e16, t.conditionGroup) : undefined,
135148
135158
  t.grainControl ? generateGrainControlCode(t.grainControl) : undefined
135149
135159
  ].filter(Boolean).join(" | ");
@@ -135190,7 +135200,8 @@ var formatConcatParam = (e16, t) => {
135190
135200
  throw Error(`Invalid field type: ${n}`);
135191
135201
  if (!isScalarType(r3.type))
135192
135202
  throw Error(`Invalid field data type: ${n}`);
135193
- return r3.type.sqlType === SqlType.TEXT ? n : `cast(${n}, 'text')`;
135203
+ let i = generateDateTransformationCode(t);
135204
+ return i ? `cast(${n} | ${i}, 'text')` : r3.type.sqlType === SqlType.TEXT ? n : `cast(${n}, 'text')`;
135194
135205
  };
135195
135206
  var generateConcatCode = (e16, t) => {
135196
135207
  if (t.type !== SpecType.Concat)
@@ -135360,6 +135371,51 @@ function resolveReference(e16, t) {
135360
135371
  return isFieldType(n) ? createModelFieldReference("", toRefString(t)) : createModelFieldReference(toRefString(t), "");
135361
135372
  throw Error(`Invalid expression for field name extraction: ${t.kind}`);
135362
135373
  }
135374
+ function resolveDateTransformation(e16, t) {
135375
+ let { funcName: n, args: r3 } = getFuncInfo(t);
135376
+ if (n === "date_trunc") {
135377
+ if (r3.length !== 2)
135378
+ throw Error(`Expected exactly 2 arguments for date_trunc, got: ${r3.length}`);
135379
+ let t3 = resolveReference(e16, r3[0]);
135380
+ if (!isTextLiteral(r3[1]))
135381
+ throw Error(`Expected text literal for date_trunc unit, got: ${r3[1].kind}`);
135382
+ let n3 = r3[1].value;
135383
+ if (!isDateUnit(n3))
135384
+ throw Error(`Unknown truncation unit: ${n3}`);
135385
+ return {
135386
+ field: t3,
135387
+ truncationUnit: n3
135388
+ };
135389
+ }
135390
+ if (r3.length !== 1)
135391
+ throw Error(`Expected exactly 1 argument for date transformation function '${n}', got: ${r3.length}`);
135392
+ let i = resolveReference(e16, r3[0]);
135393
+ if (isDateUnit(n))
135394
+ return {
135395
+ field: i,
135396
+ truncationUnit: n
135397
+ };
135398
+ if (n.endsWith("_num")) {
135399
+ let e17 = getDateUnitFromDatePartFuncName(n);
135400
+ if (!datePartUnits.includes(e17))
135401
+ throw Error(`Unknown date part unit: ${e17}`);
135402
+ return {
135403
+ field: i,
135404
+ datePartUnit: e17
135405
+ };
135406
+ }
135407
+ throw Error(`Unknown date transformation function: ${n}`);
135408
+ }
135409
+ function resolveFieldSpec(e16, t) {
135410
+ if (!isFunctionCallLikeExpression(t))
135411
+ return resolveReference(e16, t);
135412
+ let { field: n, truncationUnit: r3, datePartUnit: i } = resolveDateTransformation(e16, t);
135413
+ return {
135414
+ ...n,
135415
+ ...r3 && { truncationUnit: r3 },
135416
+ ...i && { datePartUnit: i }
135417
+ };
135418
+ }
135363
135419
  function resolveMetricReference(e16, t) {
135364
135420
  let n = e16.getTypeFromExpression(t);
135365
135421
  if (n && !(isFieldType(n) && isMetricFieldType(n)))
@@ -135732,6 +135788,13 @@ function resolveAggregationAlias(e16) {
135732
135788
  throw Error(`Invalid aggregation type: ${e16}`);
135733
135789
  return t;
135734
135790
  }
135791
+ var truncationAggregations = [
135792
+ "count",
135793
+ "count_distinct",
135794
+ "approx_count_distinct",
135795
+ "min",
135796
+ "max"
135797
+ ];
135735
135798
  function parseAggregation(e16, t) {
135736
135799
  if (!isFunctionCallLikeExpression(t))
135737
135800
  throw Error("Expected function call for aggregation parsing");
@@ -135744,12 +135807,18 @@ function parseAggregation(e16, t) {
135744
135807
  if (isFieldType(a)) {
135745
135808
  if (r3.length !== 1)
135746
135809
  throw Error(`Expected exactly 1 argument for aggregation function, got: ${r3.length}`);
135747
- } else {
135748
- if (r3.length !== 2)
135749
- throw Error(`Expected exactly 2 arguments for aggregation function, got: ${r3.length}`);
135750
- if (!isNumberLiteral(r3[1]))
135751
- throw Error('Model aggregation function must have argument "1"');
135810
+ let t3 = resolveFieldSpec(e16, r3[0]);
135811
+ if (t3.truncationUnit && !truncationAggregations.includes(i))
135812
+ throw Error(`Aggregation '${i}' is not supported on a truncated date`);
135813
+ return {
135814
+ aggregationType: i,
135815
+ source: t3
135816
+ };
135752
135817
  }
135818
+ if (r3.length !== 2)
135819
+ throw Error(`Expected exactly 2 arguments for aggregation function, got: ${r3.length}`);
135820
+ if (!isNumberLiteral(r3[1]))
135821
+ throw Error('Model aggregation function must have argument "1"');
135753
135822
  return {
135754
135823
  aggregationType: i,
135755
135824
  source: resolveReference(e16, r3[0])
@@ -135837,44 +135906,10 @@ var parseDateAdd = (e16, t) => {
135837
135906
  intervals: r3
135838
135907
  };
135839
135908
  };
135840
- var parseDateTransformation = (e16, t) => {
135841
- let { funcName: n, args: r3 } = getFuncInfo(t);
135842
- if (n === "date_trunc") {
135843
- if (r3.length !== 2)
135844
- throw Error(`Expected exactly 2 arguments for date_trunc, got: ${r3.length}`);
135845
- let t3 = resolveReference(e16, r3[0]);
135846
- if (!isTextLiteral(r3[1]))
135847
- throw Error(`Expected text literal for date_trunc unit, got: ${r3[1].kind}`);
135848
- let n3 = r3[1].value;
135849
- if (!isDateUnit(n3))
135850
- throw Error(`Unknown truncation unit: ${n3}`);
135851
- return {
135852
- type: SpecType.DateTransformation,
135853
- field: t3,
135854
- truncationUnit: n3
135855
- };
135856
- }
135857
- if (r3.length !== 1)
135858
- throw Error(`Expected exactly 1 argument for date transformation function '${n}', got: ${r3.length}`);
135859
- let i = resolveReference(e16, r3[0]);
135860
- if (isDateUnit(n))
135861
- return {
135862
- type: SpecType.DateTransformation,
135863
- field: i,
135864
- truncationUnit: n
135865
- };
135866
- if (n.endsWith("_num")) {
135867
- let e17 = getDateUnitFromDatePartFuncName(n);
135868
- if (!datePartUnits.includes(e17))
135869
- throw Error(`Unknown date part unit: ${e17}`);
135870
- return {
135871
- type: SpecType.DateTransformation,
135872
- field: i,
135873
- datePartUnit: e17
135874
- };
135875
- }
135876
- throw Error(`Unknown date transformation function: ${n}`);
135877
- };
135909
+ var parseDateTransformation = (e16, t) => ({
135910
+ type: SpecType.DateTransformation,
135911
+ ...resolveDateTransformation(e16, t)
135912
+ });
135878
135913
  var parseRunningTotal = (e16, t) => {
135879
135914
  let { funcName: n, args: r3 } = getFuncInfo(t);
135880
135915
  if (n !== "running_total")
@@ -135967,7 +136002,7 @@ var parseList = (e16, t) => {
135967
136002
  };
135968
136003
  var parseConcatParam = (e16, t) => {
135969
136004
  let { funcName: n, args: r3 } = tryGetFuncInfo(t) ?? {};
135970
- return n === "cast" && r3 ? parseConcatParam(e16, r3[0]) : isTextLiteral(t) ? createLiteralValue(t.value, SqlType.TEXT) : resolveReference(e16, t);
136005
+ return n === "cast" && r3 ? parseConcatParam(e16, r3[0]) : isTextLiteral(t) ? createLiteralValue(t.value, SqlType.TEXT) : resolveFieldSpec(e16, t);
135971
136006
  };
135972
136007
  var parseConcat = (e16, t) => {
135973
136008
  let { funcName: n, args: r3 } = getFuncInfo(t);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@holistics/cli-core",
3
3
  "type": "module",
4
- "version": "2.4.9",
4
+ "version": "2.4.11",
5
5
  "bin": {
6
6
  "holistics": "./bin/holistics.js"
7
7
  },