autoql-fe-utils 1.0.36 → 1.0.37

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.d.ts CHANGED
@@ -567,6 +567,7 @@ interface Scale {
567
567
  interface ValueLabel {
568
568
  keyword: string;
569
569
  show_message: string;
570
+ format_txt?: string;
570
571
  canonical?: string;
571
572
  column_name?: string;
572
573
  }
@@ -1738,7 +1739,7 @@ declare const REQUEST_CANCELLED_ERROR = "Request cancelled";
1738
1739
 
1739
1740
  declare const isAggSeed: (subject: any) => any;
1740
1741
  declare const getSampleQueryRegex: (suggestionValues: any) => RegExp;
1741
- declare const getSampleQueryText: (query: any, values: any) => any;
1742
+ declare const getSampleQueryText: (query: any, values?: {}) => any;
1742
1743
  declare const fetchTopicsForVL: () => void;
1743
1744
  declare const getQueryRequestParams: (chunk: any, values: any) => {
1744
1745
  query: any;
@@ -1751,16 +1752,14 @@ declare const fetchDataExplorerAutocomplete: ({ suggestion, domain, token, apiKe
1751
1752
  token?: string;
1752
1753
  cancelToken?: any;
1753
1754
  }) => Promise<any[]>;
1754
- declare const fetchDataExplorerSampleQueries: ({ domain, apiKey, token, text, context, selectedVL, userVLSelection, columns, }?: {
1755
+ declare const fetchDataExplorerSampleQueries: ({ domain, apiKey, token, text, context, columns, }?: {
1755
1756
  domain?: string;
1756
1757
  apiKey?: string;
1757
1758
  token?: string;
1758
1759
  text?: string;
1759
1760
  context?: string;
1760
- selectedVL?: ValueLabel;
1761
- userVLSelection?: ValueLabel[];
1762
1761
  columns?: object;
1763
- }) => Promise<unknown>;
1762
+ }) => Promise<axios.AxiosResponse<any, any>>;
1764
1763
  declare const fetchDataExplorerSuggestions: ({ pageSize, pageNumber, domain, apiKey, token, text, context, selectedVL, userVLSelection, skipQueryValidation, }?: {
1765
1764
  pageSize?: number;
1766
1765
  pageNumber?: number;
@@ -27727,9 +27727,12 @@
27727
27727
  const valueRegex = new RegExp(valueRegexArray.join("|"), "gm");
27728
27728
  return valueRegex;
27729
27729
  };
27730
- var getSampleQueryText = (query, values) => {
27730
+ var getSampleQueryText = (query, values = {}) => {
27731
27731
  try {
27732
27732
  const valueArray = Object.keys(values);
27733
+ if (!(valueArray == null ? void 0 : valueArray.length)) {
27734
+ return query;
27735
+ }
27733
27736
  let queryText = query;
27734
27737
  valueArray.forEach((valueKey) => {
27735
27738
  var _a;
@@ -27777,7 +27780,7 @@
27777
27780
  };
27778
27781
  var transformSampleQuerySuggestions = (suggestions) => {
27779
27782
  const newSuggestions = [];
27780
- suggestions.forEach((suggestion) => {
27783
+ suggestions == null ? void 0 : suggestions.forEach((suggestion) => {
27781
27784
  const initialQuery = suggestion.query;
27782
27785
  const initialValues = transformSampleQueryValues(suggestion.value);
27783
27786
  const chunked = getSampleQueryChunk(suggestion.query, initialValues);
@@ -27792,7 +27795,7 @@
27792
27795
  });
27793
27796
  return newSuggestions;
27794
27797
  };
27795
- var transformSampleQueryValues = (originalValues) => {
27798
+ var transformSampleQueryValues = (originalValues = {}) => {
27796
27799
  var _a;
27797
27800
  const newValues = {};
27798
27801
  if ((_a = Object.keys(originalValues)) == null ? void 0 : _a.length) {
@@ -27821,39 +27824,52 @@
27821
27824
  return;
27822
27825
  }
27823
27826
  };
27824
- var getSampleQueryChunk = (query, values) => {
27825
- const valueArray = Object.keys(values);
27826
- const valueRegexArray = valueArray.map((value) => `(${value})`);
27827
- const valueRegex = new RegExp(valueRegexArray.join("|"), "gm");
27828
- let splitStrArray = [query];
27829
- if (valueArray == null ? void 0 : valueArray.length) {
27830
- splitStrArray = query.split(valueRegex);
27831
- }
27832
- const chunkedSuggestion = [];
27833
- splitStrArray.forEach((key) => {
27834
- var _a, _b;
27835
- const replacement = (_a = values[key]) == null ? void 0 : _a.replacement;
27836
- const type = getSampleQueryReplacementType(key, replacement);
27837
- const name = key == null ? void 0 : key.trim();
27838
- if (!type || !name) {
27839
- return;
27840
- }
27841
- let value = (_b = replacement == null ? void 0 : replacement.format_txt) == null ? void 0 : _b.trim();
27842
- if (type == "TEXT" /* SAMPLE_QUERY_TEXT_TYPE */) {
27843
- value = name;
27827
+ var getSampleQueryChunk = (query, values = {}) => {
27828
+ try {
27829
+ const valueArray = Object.keys(values);
27830
+ if (!(valueArray == null ? void 0 : valueArray.length)) {
27831
+ return [
27832
+ {
27833
+ type: "TEXT" /* SAMPLE_QUERY_TEXT_TYPE */,
27834
+ value: query == null ? void 0 : query.trim(),
27835
+ name: query == null ? void 0 : query.trim()
27836
+ }
27837
+ ];
27844
27838
  }
27845
- if (!value) {
27846
- return;
27839
+ const valueRegexArray = valueArray.map((value) => `(${value})`);
27840
+ const valueRegex = new RegExp(valueRegexArray.join("|"), "gm");
27841
+ let splitStrArray = [query];
27842
+ if (valueArray == null ? void 0 : valueArray.length) {
27843
+ splitStrArray = query.split(valueRegex);
27847
27844
  }
27848
- const chunk = {
27849
- type,
27850
- value,
27851
- name,
27852
- replacement
27853
- };
27854
- chunkedSuggestion.push(chunk);
27855
- });
27856
- return chunkedSuggestion;
27845
+ const chunkedSuggestion = [];
27846
+ splitStrArray.forEach((key) => {
27847
+ var _a, _b;
27848
+ const replacement = (_a = values[key]) == null ? void 0 : _a.replacement;
27849
+ const type = getSampleQueryReplacementType(key, replacement);
27850
+ const name = key == null ? void 0 : key.trim();
27851
+ if (!type || !name) {
27852
+ return;
27853
+ }
27854
+ let value = (_b = replacement == null ? void 0 : replacement.format_txt) == null ? void 0 : _b.trim();
27855
+ if (type == "TEXT" /* SAMPLE_QUERY_TEXT_TYPE */) {
27856
+ value = name;
27857
+ }
27858
+ if (!value) {
27859
+ return;
27860
+ }
27861
+ const chunk = {
27862
+ type,
27863
+ value,
27864
+ name,
27865
+ replacement
27866
+ };
27867
+ chunkedSuggestion.push(chunk);
27868
+ });
27869
+ return chunkedSuggestion;
27870
+ } catch (error) {
27871
+ console.error(error);
27872
+ }
27857
27873
  };
27858
27874
  var transformDataExplorerAutocompleteResponse = (response) => {
27859
27875
  var _a, _b, _c, _d, _e, _f, _g, _h;
@@ -27914,20 +27930,10 @@
27914
27930
  apiKey,
27915
27931
  token,
27916
27932
  text = "",
27917
- context,
27918
- selectedVL,
27919
- userVLSelection = [],
27933
+ context = "",
27920
27934
  columns
27921
27935
  } = {}) => {
27922
27936
  const url2 = `${domain}/autoql/api/v1/query/querybuilder?key=${apiKey}`;
27923
- let vlInfo = [];
27924
- if (selectedVL) {
27925
- vlInfo.push(transformVLForDataExplorerSuggestions(selectedVL));
27926
- }
27927
- if (userVLSelection) {
27928
- const transformedVLs = userVLSelection.map((vl) => transformVLForDataExplorerSuggestions(vl));
27929
- vlInfo = [...vlInfo, ...transformedVLs];
27930
- }
27931
27937
  const data = {
27932
27938
  query_to_start: text,
27933
27939
  context,
@@ -27949,68 +27955,6 @@
27949
27955
  var _a;
27950
27956
  return Promise.reject((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data);
27951
27957
  });
27952
- const suggestionsMock = [
27953
- {
27954
- query: "all sales for PUBLIC_0_CUSTOMER_DIMENSION_0_CUSTOMER_NAME_VALUE_LABEL above DUCKLING_AMOUNT",
27955
- values: {
27956
- DUCKLING_AMOUNT: {
27957
- canonical: "DUCKLING_AMOUNT",
27958
- format_txt: "100",
27959
- keyword: "100",
27960
- display_name: "100"
27961
- },
27962
- PUBLIC_0_CUSTOMER_DIMENSION_0_CUSTOMER_NAME_VALUE_LABEL: {
27963
- show_message: "Customer Name",
27964
- keyword: "Jonny Depp",
27965
- format_txt: "Jonny Depp",
27966
- canonical: "CUSTOMER_0_DISPLAYNAME_VALUE_LABEL"
27967
- }
27968
- }
27969
- },
27970
- {
27971
- query: "total sales DUCKLING_TIME",
27972
- values: {
27973
- DUCKLING_TIME: {
27974
- canonical: "DUCKLING_TIME",
27975
- format_txt: "last year",
27976
- keyword: "last year",
27977
- display_name: "last year"
27978
- }
27979
- }
27980
- },
27981
- {
27982
- query: "all sales for PUBLIC_0_CUSTOMER_DIMENSION_0_CUSTOMER_NAME_VALUE_LABEL",
27983
- values: {
27984
- PUBLIC_0_CUSTOMER_DIMENSION_0_CUSTOMER_NAME_VALUE_LABEL: {
27985
- show_message: "Customer Name",
27986
- keyword: "Jonny Depp",
27987
- format_txt: "Jonny Depp",
27988
- canonical: "CUSTOMER_0_DISPLAYNAME_VALUE_LABEL"
27989
- }
27990
- }
27991
- }
27992
- ];
27993
- const promise = new Promise((res, rej) => {
27994
- setTimeout(() => {
27995
- var _a, _b;
27996
- try {
27997
- const testResponse = {
27998
- data: {
27999
- data: {
28000
- suggestions: suggestionsMock
28001
- }
28002
- }
28003
- };
28004
- const suggestions = transformSampleQuerySuggestions((_b = (_a = testResponse == null ? void 0 : testResponse.data) == null ? void 0 : _a.data) == null ? void 0 : _b.suggestions);
28005
- testResponse.data.data.suggestions = suggestions;
28006
- res(testResponse);
28007
- } catch (error) {
28008
- console.error(error);
28009
- rej(error);
28010
- }
28011
- }, 500);
28012
- });
28013
- return promise;
28014
27958
  };
28015
27959
  var fetchDataExplorerSuggestions = async ({
28016
27960
  pageSize,