@uipath/oms-commands 1.202.1-preview.220 → 1.202.1-preview.238

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/index.js +224 -7
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -4746,7 +4746,165 @@ class FilterImplicitLimitError extends Error {
4746
4746
  this.instructions = "Pass --limit <n> to choose how many records the filter applies to. " + "To filter over all records, pass the command's maximum accepted --limit (see the option's description in --help).";
4747
4747
  }
4748
4748
  }
4749
- function applyFilter(data, filter) {
4749
+ function countRecords(data) {
4750
+ if (Array.isArray(data))
4751
+ return data.length;
4752
+ return data == null ? 0 : 1;
4753
+ }
4754
+ function availableFields(data) {
4755
+ const records = Array.isArray(data) ? data : [data];
4756
+ const keys = new Set;
4757
+ for (const record of records) {
4758
+ if (record && typeof record === "object" && !Array.isArray(record)) {
4759
+ for (const key of Object.keys(record))
4760
+ keys.add(key);
4761
+ }
4762
+ }
4763
+ return [...keys];
4764
+ }
4765
+ function decodeQuotedIdentifier(whole, inner) {
4766
+ const [error, decoded] = catchError(() => JSON.parse(whole));
4767
+ if (!error && typeof decoded === "string")
4768
+ return decoded;
4769
+ return inner.replace(/\\(.)/g, "$1");
4770
+ }
4771
+ function referencedFields(filter) {
4772
+ const top = new Set;
4773
+ const nested = new Set;
4774
+ const withoutValueLiterals = filter.replace(/'(?:\\.|[^'\\])*'/g, " ").replace(/`(?:\\.|[^`\\])*`/g, " ");
4775
+ const isPathTail = (text, index) => text[index - 1] === "." && /[A-Za-z0-9_"]/.test(text[index - 2] ?? "");
4776
+ const quoted = [];
4777
+ const withoutLiterals = withoutValueLiterals.replace(/"((?:\\.|[^"\\])*)"/g, (whole, name, index) => {
4778
+ const isAlias = /^\s*:/.test(withoutValueLiterals.slice(index + whole.length));
4779
+ if (!isAlias) {
4780
+ quoted.push({
4781
+ name: decodeQuotedIdentifier(whole, name),
4782
+ index,
4783
+ tail: isPathTail(withoutValueLiterals, index)
4784
+ });
4785
+ }
4786
+ return `"${" ".repeat(whole.length - 2)}"`;
4787
+ });
4788
+ const descent = /[A-Za-z0-9_"]\s*[.[]/.exec(withoutLiterals);
4789
+ const rootEnd = descent ? descent.index + 1 : Number.POSITIVE_INFINITY;
4790
+ const place = (name, index, tail) => {
4791
+ if (tail || index >= rootEnd)
4792
+ nested.add(name);
4793
+ else
4794
+ top.add(name);
4795
+ };
4796
+ for (const entry of quoted)
4797
+ place(entry.name, entry.index, entry.tail);
4798
+ const identifiers = withoutLiterals.matchAll(/([A-Za-z_][A-Za-z0-9_]*)(\s*[:(])?/g);
4799
+ const reserved = new Set(["true", "false", "null", "and", "or", "not"]);
4800
+ for (const match of identifiers) {
4801
+ const [, name, trailing] = match;
4802
+ if (trailing || reserved.has(name))
4803
+ continue;
4804
+ place(name, match.index, isPathTail(withoutLiterals, match.index));
4805
+ }
4806
+ return {
4807
+ top: [...top],
4808
+ nested: [...nested].filter((name) => !top.has(name)),
4809
+ hasPredicate: /\[\s*\?/.test(withoutValueLiterals)
4810
+ };
4811
+ }
4812
+ function appearsBelowTopLevel(data, name) {
4813
+ let budget = 2000;
4814
+ const visit = (value, depth) => {
4815
+ if (budget-- <= 0 || depth > 4)
4816
+ return false;
4817
+ if (value === null || typeof value !== "object")
4818
+ return false;
4819
+ if (Array.isArray(value))
4820
+ return value.some((entry) => visit(entry, depth));
4821
+ const record = value;
4822
+ if (depth > 0 && Object.hasOwn(record, name))
4823
+ return true;
4824
+ return Object.values(record).some((entry) => visit(entry, depth + 1));
4825
+ };
4826
+ return visit(data, 0);
4827
+ }
4828
+ function alwaysNullKeys(records) {
4829
+ const objects = records.filter((r) => r != null && typeof r === "object" && !Array.isArray(r));
4830
+ if (objects.length === 0 || objects.length !== records.length)
4831
+ return [];
4832
+ const keys = [...new Set(objects.flatMap((o) => Object.keys(o)))];
4833
+ if (keys.length === 0)
4834
+ return [];
4835
+ const nullKeys = keys.filter((key) => objects.every((record) => record[key] === null));
4836
+ return nullKeys.length === keys.length ? nullKeys : [];
4837
+ }
4838
+ function carriesOnlyNulls(value) {
4839
+ if (value === null)
4840
+ return true;
4841
+ if (Array.isArray(value)) {
4842
+ return value.length > 0 && value.every(carriesOnlyNulls);
4843
+ }
4844
+ if (typeof value === "object" && value !== undefined) {
4845
+ const values = Object.values(value);
4846
+ return values.length > 0 && values.every(carriesOnlyNulls);
4847
+ }
4848
+ return false;
4849
+ }
4850
+ function nameList(names, cap2 = 12) {
4851
+ const shown = names.slice(0, cap2).map((n) => `\`${n}\``);
4852
+ const rest = names.length - shown.length;
4853
+ return shown.join(", ") + (rest > 0 ? `, and ${rest} more` : "");
4854
+ }
4855
+ function buildFilterWarning(filter, data, outcome) {
4856
+ const present = availableFields(data);
4857
+ const refs = referencedFields(filter);
4858
+ const unknown = refs.top.filter((name) => !present.includes(name) && !appearsBelowTopLevel(data, name));
4859
+ const unchecked = refs.nested.filter((name) => !present.includes(name));
4860
+ const count = countRecords(data);
4861
+ const scope = `${count} record(s)`;
4862
+ const isNotAField = (names) => `${nameList(names)} ${names.length === 1 ? "is not a field" : "are not fields"} on the ${scope} it read`;
4863
+ const soundness = unchecked.length > 0 ? `${nameList(unchecked)} ${unchecked.length === 1 ? "reads" : "read"} below the top level, so ${unchecked.length === 1 ? "it was" : "they were"} not checked against the record keys` : refs.top.length > 0 ? "every field it names exists" : "";
4864
+ const withSoundness = (base) => soundness ? `${base}, and ${soundness}` : base;
4865
+ let detail;
4866
+ let lede;
4867
+ if (outcome.kind === "null-elements") {
4868
+ lede = "returned only null values";
4869
+ const projected = `all ${outcome.count} of the elements it projected are null`;
4870
+ if (unknown.length > 0) {
4871
+ detail = `${projected}, because ${isNotAField(unknown)}`;
4872
+ } else if (unchecked.length > 0) {
4873
+ detail = withSoundness(projected);
4874
+ } else {
4875
+ detail = `${projected}, and every field it names exists — a multi-select list ` + `(\`[A, B]\`) reads each entry against \`Data\` itself, so on a list ` + `result use \`[].[A, B]\` or \`[].{a: A, b: B}\` to read the records`;
4876
+ }
4877
+ } else if (outcome.kind === "null-rows") {
4878
+ lede = "returned only null values";
4879
+ const projected = `every value it projected is null on all ${outcome.count} row(s)`;
4880
+ detail = unknown.length > 0 ? `${projected}, because ${isNotAField(unknown)}` : withSoundness(projected);
4881
+ } else if (outcome.kind === "null-values") {
4882
+ lede = "returned only null values";
4883
+ const projected = `every key it projected (${nameList(outcome.keys)}) is null`;
4884
+ const sameSet = unknown.length === outcome.keys.length && outcome.keys.every((k) => unknown.includes(k));
4885
+ if (sameSet) {
4886
+ detail = `${isNotAField(outcome.keys)}, so every key it projected is null`;
4887
+ } else if (unknown.length > 0) {
4888
+ detail = `${projected}, because ${isNotAField(unknown)}`;
4889
+ } else {
4890
+ detail = withSoundness(`${projected} on all ${scope}`);
4891
+ }
4892
+ } else {
4893
+ lede = "returned nothing";
4894
+ if (unknown.length > 0) {
4895
+ detail = isNotAField(unknown);
4896
+ } else {
4897
+ const selection = refs.hasPredicate ? "no record matched" : "the expression resolved to no value";
4898
+ detail = withSoundness(`${selection} — it read ${scope}`);
4899
+ }
4900
+ }
4901
+ const fields = present.length > 0 ? ` Available fields: ${nameList(present)}.` : "";
4902
+ return `--output-filter ${JSON.stringify(filter)} ${lede}: ${detail}.${fields}`;
4903
+ }
4904
+ function appendWarning(existing, note) {
4905
+ return existing ? `${existing} ${note}` : note;
4906
+ }
4907
+ function applyFilter(data, filter, onWarning) {
4750
4908
  const codec = requireJmespath();
4751
4909
  let result;
4752
4910
  try {
@@ -4754,9 +4912,34 @@ function applyFilter(data, filter) {
4754
4912
  } catch (err) {
4755
4913
  throw new FilterEvaluationError(filter, err);
4756
4914
  }
4757
- if (result == null)
4915
+ const inputCount = countRecords(data);
4916
+ const warn = (outcome) => {
4917
+ if (inputCount === 0)
4918
+ return;
4919
+ const note = buildFilterWarning(filter, data, outcome);
4920
+ getOutputSink().writeErr(`[WARN] ${note}
4921
+ `);
4922
+ onWarning?.(note);
4923
+ };
4924
+ const warnIfAllNull = (records) => {
4925
+ const keys = alwaysNullKeys(records);
4926
+ if (keys.length > 0)
4927
+ warn({ kind: "null-values", keys });
4928
+ };
4929
+ if (result == null) {
4930
+ warn({ kind: "empty" });
4758
4931
  return [];
4932
+ }
4759
4933
  if (Array.isArray(result)) {
4934
+ if (result.length === 0) {
4935
+ warn({ kind: "empty" });
4936
+ } else if (result.every((entry) => entry === null)) {
4937
+ warn({ kind: "null-elements", count: result.length });
4938
+ } else if (result.every((entry) => Array.isArray(entry)) && carriesOnlyNulls(result)) {
4939
+ warn({ kind: "null-rows", count: result.length });
4940
+ } else {
4941
+ warnIfAllNull(result);
4942
+ }
4760
4943
  if (result.length > 0 && typeof result[0] !== "object") {
4761
4944
  const fieldMatch = filter.match(/\.(\w+)$/);
4762
4945
  const key = fieldMatch ? fieldMatch[1] : "Value";
@@ -4764,10 +4947,30 @@ function applyFilter(data, filter) {
4764
4947
  }
4765
4948
  return result;
4766
4949
  }
4767
- if (typeof result === "object")
4950
+ if (typeof result === "object") {
4951
+ warnIfAllNull([result]);
4768
4952
  return result;
4953
+ }
4769
4954
  return { Value: result };
4770
4955
  }
4956
+ function filterFailureData(envelope) {
4957
+ const filter = getOutputFilter();
4958
+ const data = envelope.Data;
4959
+ if (!filter || data == null)
4960
+ return;
4961
+ let note;
4962
+ const [filterError, filtered] = catchError(() => applyFilter(data, filter, (n) => {
4963
+ note = n;
4964
+ }));
4965
+ if (filterError) {
4966
+ envelope.Warning = appendWarning(envelope.Warning, `--output-filter was not applied, so Data is shown in full: ${filterError.message}`);
4967
+ return;
4968
+ }
4969
+ envelope.Data = filtered;
4970
+ if (note) {
4971
+ envelope.Warning = appendWarning(envelope.Warning, note);
4972
+ }
4973
+ }
4771
4974
  function defaultErrorCodeForResult(result) {
4772
4975
  switch (result) {
4773
4976
  case RESULTS.AuthenticationError:
@@ -4850,8 +5053,14 @@ var OutputFormatter;
4850
5053
  }
4851
5054
  const filter = getOutputFilter();
4852
5055
  if (filter) {
4853
- const filtered = applyFilter(data.Data, filter);
5056
+ let note;
5057
+ const filtered = applyFilter(data.Data, filter, (n) => {
5058
+ note = n;
5059
+ });
4854
5060
  data.Data = normalize ? normalizeDataKeys(filtered, verbatim, subtrees && { refs: subtrees.refs, mode: "skip" }) : filtered;
5061
+ if (note) {
5062
+ data.Warning = appendWarning(data.Warning, note);
5063
+ }
4855
5064
  }
4856
5065
  logOutput(normalizeOutputKeys(data), getOutputFormat(), options?.tableRowStyle);
4857
5066
  }
@@ -4879,6 +5088,7 @@ var OutputFormatter;
4879
5088
  delete envelope.TelemetryErrorClass;
4880
5089
  delete envelope.TelemetryTerminalOutcome;
4881
5090
  delete envelope.TelemetryTerminalSignal;
5091
+ filterFailureData(envelope);
4882
5092
  if (!suppressTelemetry) {
4883
5093
  telemetry.trackEvent(CommonTelemetryEvents.Error, {
4884
5094
  result: data.Result,
@@ -4927,13 +5137,20 @@ var OutputFormatter;
4927
5137
  OutputFormatter.log = log;
4928
5138
  function formatToString(data) {
4929
5139
  const filter = getOutputFilter();
5140
+ const envelope = data;
4930
5141
  if ("Data" in data && data.Data != null) {
4931
5142
  data.Data = normalizeDataKeys(data.Data);
4932
5143
  if (filter) {
4933
- data.Data = normalizeDataKeys(applyFilter(data.Data, filter));
5144
+ let note;
5145
+ data.Data = normalizeDataKeys(applyFilter(data.Data, filter, (n) => {
5146
+ note = n;
5147
+ }));
5148
+ if (note) {
5149
+ envelope.Warning = appendWarning(envelope.Warning, note);
5150
+ }
4934
5151
  }
4935
5152
  }
4936
- const output = normalizeOutputKeys(data);
5153
+ const output = normalizeOutputKeys(envelope);
4937
5154
  const lines = [];
4938
5155
  const sink = getOutputSink();
4939
5156
  printOutput(output, getOutputFormat(), (msg) => {
@@ -13516,4 +13733,4 @@ export {
13516
13733
  registerCommands
13517
13734
  };
13518
13735
 
13519
- //# debugId=CFE963DDB96F23B364756E2164756E21
13736
+ //# debugId=BAF14296C0282D2564756E2164756E21
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@uipath/oms-commands",
3
3
  "license": "SEE LICENSE IN LICENSE.txt",
4
- "version": "1.202.1-preview.220",
4
+ "version": "1.202.1-preview.238",
5
5
  "description": "Admin CLI commands for the UiPath Organization Management Service. Library composed by admin-tool, not a standalone CLI tool.",
6
6
  "private": false,
7
7
  "repository": {
@@ -25,5 +25,5 @@
25
25
  "files": [
26
26
  "dist"
27
27
  ],
28
- "gitHead": "a09041733b628c3f6b658a1f58349ea0f40bb492"
28
+ "gitHead": "537e43df1d3583633cfd3a0b88634f9ce3ba9d6b"
29
29
  }