@osdk/client 2.8.0-beta.21 → 2.8.0-beta.22

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 (24) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/build/browser/internal/conversions/legacyToModernSingleAggregationResult.js +30 -15
  3. package/build/browser/internal/conversions/legacyToModernSingleAggregationResult.js.map +1 -1
  4. package/build/browser/internal/conversions/modernToLegacyAggregationClause.js +13 -3
  5. package/build/browser/internal/conversions/modernToLegacyAggregationClause.js.map +1 -1
  6. package/build/browser/object/aggregate.js +2 -2
  7. package/build/browser/object/aggregate.js.map +1 -1
  8. package/build/browser/util/UserAgent.js +2 -2
  9. package/build/cjs/{chunk-3XHX3RLX.cjs → chunk-R7OP6A6S.cjs} +43 -23
  10. package/build/cjs/chunk-R7OP6A6S.cjs.map +1 -0
  11. package/build/cjs/{chunk-CXIHFOWS.cjs → chunk-U7EPNLKB.cjs} +39 -39
  12. package/build/cjs/{chunk-CXIHFOWS.cjs.map → chunk-U7EPNLKB.cjs.map} +1 -1
  13. package/build/cjs/index.cjs +10 -10
  14. package/build/cjs/public/internal.cjs +8 -8
  15. package/build/cjs/public/unstable-do-not-use.cjs +68 -68
  16. package/build/esm/internal/conversions/legacyToModernSingleAggregationResult.js +30 -15
  17. package/build/esm/internal/conversions/legacyToModernSingleAggregationResult.js.map +1 -1
  18. package/build/esm/internal/conversions/modernToLegacyAggregationClause.js +13 -3
  19. package/build/esm/internal/conversions/modernToLegacyAggregationClause.js.map +1 -1
  20. package/build/esm/object/aggregate.js +2 -2
  21. package/build/esm/object/aggregate.js.map +1 -1
  22. package/build/esm/util/UserAgent.js +2 -2
  23. package/package.json +7 -7
  24. package/build/cjs/chunk-3XHX3RLX.cjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @osdk/client
2
2
 
3
+ ## 2.8.0-beta.22
4
+
5
+ ### Minor Changes
6
+
7
+ - cbfa135: Fix aggregation return type for empty object sets
8
+ - f4604c2: fix aggregate endpoint errors crashing instead of surfacing server error
9
+
10
+ ### Patch Changes
11
+
12
+ - @osdk/api@2.8.0-beta.22
13
+ - @osdk/client.unstable@2.8.0-beta.22
14
+ - @osdk/generator-converters@2.8.0-beta.22
15
+
3
16
  ## 2.8.0-beta.21
4
17
 
5
18
  ### Minor Changes
@@ -14,23 +14,38 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import invariant from "tiny-invariant";
17
+ import { splitAggregationKey } from "./modernToLegacyAggregationClause.js";
18
+
18
19
  /** @internal */
19
- export function legacyToModernSingleAggregationResult(entry) {
20
- return entry.metrics.reduce((accumulator, curValue) => {
21
- const parts = curValue.name.split(".");
22
- if (parts[0] === "count") {
23
- return accumulator;
20
+ export function legacyToModernSingleAggregationResult(entry, select) {
21
+ const result = {};
22
+
23
+ // Seed the result with undefined for every selected metric so that
24
+ // properties are always present, even when the server returns no metrics
25
+ // (e.g. aggregating over 0 objects).
26
+ for (const selectKey of Object.keys(select)) {
27
+ if (selectKey === "$count") {
28
+ continue;
24
29
  }
25
- !(parts.length === 2) ? process.env.NODE_ENV !== "production" ? invariant(false, "assumed we were getting a `${key}.${type}`") : invariant(false) : void 0;
26
- const property = parts[0];
27
- const metricType = parts[1];
28
- if (!(property in accumulator)) {
29
- accumulator[property] = {}; // fixme?
30
+ const {
31
+ property,
32
+ metric
33
+ } = splitAggregationKey(selectKey);
34
+ (result[property] ??= {})[metric] = undefined;
35
+ }
36
+ for (const {
37
+ name,
38
+ value
39
+ } of entry.metrics) {
40
+ if (name === "count") {
41
+ continue;
30
42
  }
31
- accumulator[property][metricType] = curValue.value; // fixme?
32
-
33
- return accumulator;
34
- }, {});
43
+ const [property, metricType] = name.split(".");
44
+ if (result[property]) {
45
+ // guard against an unknown metric name
46
+ result[property][metricType] = value;
47
+ }
48
+ }
49
+ return result;
35
50
  }
36
51
  //# sourceMappingURL=legacyToModernSingleAggregationResult.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"legacyToModernSingleAggregationResult.js","names":["invariant","legacyToModernSingleAggregationResult","entry","metrics","reduce","accumulator","curValue","parts","name","split","length","process","env","NODE_ENV","property","metricType","value"],"sources":["legacyToModernSingleAggregationResult.ts"],"sourcesContent":["/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n AggregationClause,\n AggregationResultsWithoutGroups,\n ObjectOrInterfaceDefinition,\n} from \"@osdk/api\";\nimport type { AggregateObjectsResponseV2 } from \"@osdk/foundry.ontologies\";\nimport invariant from \"tiny-invariant\";\nimport type { ArrayElement } from \"../../util/ArrayElement.js\";\n\n/** @internal */\nexport function legacyToModernSingleAggregationResult<\n Q extends ObjectOrInterfaceDefinition,\n AC extends AggregationClause<Q>,\n>(\n entry: ArrayElement<AggregateObjectsResponseV2[\"data\"]>,\n): AggregationResultsWithoutGroups<Q, AC> {\n return entry.metrics.reduce(\n (accumulator: AggregationResultsWithoutGroups<Q, AC>, curValue) => {\n const parts = curValue.name.split(\".\");\n if (parts[0] === \"count\") {\n return accumulator;\n }\n invariant(\n parts.length === 2,\n \"assumed we were getting a `${key}.${type}`\",\n );\n const property = parts[0] as keyof AggregationResultsWithoutGroups<Q, AC>;\n const metricType = parts[1];\n if (!(property in accumulator)) {\n accumulator[property] = {} as any; // fixme?\n }\n (accumulator[property] as any)[metricType] = curValue.value; // fixme?\n\n return accumulator;\n },\n {} as AggregationResultsWithoutGroups<Q, AC>,\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA,OAAOA,SAAS,MAAM,gBAAgB;AAGtC;AACA,OAAO,SAASC,qCAAqCA,CAInDC,KAAuD,EACf;EACxC,OAAOA,KAAK,CAACC,OAAO,CAACC,MAAM,CACzB,CAACC,WAAmD,EAAEC,QAAQ,KAAK;IACjE,MAAMC,KAAK,GAAGD,QAAQ,CAACE,IAAI,CAACC,KAAK,CAAC,GAAG,CAAC;IACtC,IAAIF,KAAK,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE;MACxB,OAAOF,WAAW;IACpB;IACA,EACEE,KAAK,CAACG,MAAM,KAAK,CAAC,IAAAC,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBADpBb,SAAS,QAEP,4CAA4C,IAF9CA,SAAS;IAIT,MAAMc,QAAQ,GAAGP,KAAK,CAAC,CAAC,CAAiD;IACzE,MAAMQ,UAAU,GAAGR,KAAK,CAAC,CAAC,CAAC;IAC3B,IAAI,EAAEO,QAAQ,IAAIT,WAAW,CAAC,EAAE;MAC9BA,WAAW,CAACS,QAAQ,CAAC,GAAG,CAAC,CAAQ,CAAC,CAAC;IACrC;IACCT,WAAW,CAACS,QAAQ,CAAC,CAASC,UAAU,CAAC,GAAGT,QAAQ,CAACU,KAAK,CAAC,CAAC;;IAE7D,OAAOX,WAAW;EACpB,CAAC,EACD,CAAC,CACH,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"legacyToModernSingleAggregationResult.js","names":["splitAggregationKey","legacyToModernSingleAggregationResult","entry","select","result","selectKey","Object","keys","property","metric","undefined","name","value","metrics","metricType","split"],"sources":["legacyToModernSingleAggregationResult.ts"],"sourcesContent":["/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n AggregationClause,\n AggregationResultsWithoutGroups,\n ObjectOrInterfaceDefinition,\n} from \"@osdk/api\";\nimport type { AggregateObjectsResponseV2 } from \"@osdk/foundry.ontologies\";\nimport type { ArrayElement } from \"../../util/ArrayElement.js\";\nimport { splitAggregationKey } from \"./modernToLegacyAggregationClause.js\";\n\n/** @internal */\nexport function legacyToModernSingleAggregationResult<\n Q extends ObjectOrInterfaceDefinition,\n AC extends AggregationClause<Q>,\n>(\n entry: ArrayElement<AggregateObjectsResponseV2[\"data\"]>,\n select: AC,\n): AggregationResultsWithoutGroups<Q, AC> {\n const result: Record<string, Record<string, any>> = {};\n\n // Seed the result with undefined for every selected metric so that\n // properties are always present, even when the server returns no metrics\n // (e.g. aggregating over 0 objects).\n for (const selectKey of Object.keys(select)) {\n if (selectKey === \"$count\") {\n continue;\n }\n const { property, metric } = splitAggregationKey(selectKey);\n (result[property] ??= {})[metric] = undefined;\n }\n\n for (const { name, value } of entry.metrics) {\n if (name === \"count\") {\n continue;\n }\n const [property, metricType] = name.split(\".\");\n if (result[property]) { // guard against an unknown metric name\n result[property][metricType] = value;\n }\n }\n\n return result as AggregationResultsWithoutGroups<Q, AC>;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,SAASA,mBAAmB,QAAQ,sCAAsC;;AAE1E;AACA,OAAO,SAASC,qCAAqCA,CAInDC,KAAuD,EACvDC,MAAU,EAC8B;EACxC,MAAMC,MAA2C,GAAG,CAAC,CAAC;;EAEtD;EACA;EACA;EACA,KAAK,MAAMC,SAAS,IAAIC,MAAM,CAACC,IAAI,CAACJ,MAAM,CAAC,EAAE;IAC3C,IAAIE,SAAS,KAAK,QAAQ,EAAE;MAC1B;IACF;IACA,MAAM;MAAEG,QAAQ;MAAEC;IAAO,CAAC,GAAGT,mBAAmB,CAACK,SAAS,CAAC;IAC3D,CAACD,MAAM,CAACI,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAEC,MAAM,CAAC,GAAGC,SAAS;EAC/C;EAEA,KAAK,MAAM;IAAEC,IAAI;IAAEC;EAAM,CAAC,IAAIV,KAAK,CAACW,OAAO,EAAE;IAC3C,IAAIF,IAAI,KAAK,OAAO,EAAE;MACpB;IACF;IACA,MAAM,CAACH,QAAQ,EAAEM,UAAU,CAAC,GAAGH,IAAI,CAACI,KAAK,CAAC,GAAG,CAAC;IAC9C,IAAIX,MAAM,CAACI,QAAQ,CAAC,EAAE;MAAE;MACtBJ,MAAM,CAACI,QAAQ,CAAC,CAACM,UAAU,CAAC,GAAGF,KAAK;IACtC;EACF;EAEA,OAAOR,MAAM;AACf","ignoreList":[]}
@@ -16,6 +16,15 @@
16
16
 
17
17
  const directionFieldMap = dir => dir === "asc" ? "ASC" : dir === "desc" ? "DESC" : undefined;
18
18
 
19
+ /** @internal */
20
+ export function splitAggregationKey(key) {
21
+ const colonPos = key.lastIndexOf(":");
22
+ return {
23
+ property: key.slice(0, colonPos),
24
+ metric: key.slice(colonPos + 1)
25
+ };
26
+ }
27
+
19
28
  /** @internal */
20
29
  export function modernToLegacyAggregationClause(select) {
21
30
  return Object.entries(select).flatMap(([propAndMetric, aggregationType]) => {
@@ -26,9 +35,10 @@ export function modernToLegacyAggregationClause(select) {
26
35
  direction: directionFieldMap(aggregationType)
27
36
  };
28
37
  }
29
- const colonPos = propAndMetric.lastIndexOf(":");
30
- const property = propAndMetric.slice(0, colonPos);
31
- const metric = propAndMetric.slice(colonPos + 1);
38
+ const {
39
+ property,
40
+ metric
41
+ } = splitAggregationKey(propAndMetric);
32
42
  return [{
33
43
  type: metric,
34
44
  name: `${property}.${metric}`,
@@ -1 +1 @@
1
- {"version":3,"file":"modernToLegacyAggregationClause.js","names":["directionFieldMap","dir","undefined","modernToLegacyAggregationClause","select","Object","entries","flatMap","propAndMetric","aggregationType","type","name","direction","colonPos","lastIndexOf","property","slice","metric","field"],"sources":["modernToLegacyAggregationClause.ts"],"sourcesContent":["/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { AggregationClause } from \"@osdk/api\";\nimport type { AggregationV2 } from \"@osdk/foundry.ontologies\";\n\nconst directionFieldMap = (dir?: \"asc\" | \"desc\" | \"unordered\") =>\n dir === \"asc\" ? \"ASC\" : dir === \"desc\" ? \"DESC\" : undefined;\n\n/** @internal */\nexport function modernToLegacyAggregationClause<\n AC extends AggregationClause<any>,\n>(select: AC) {\n return Object.entries(select).flatMap<AggregationV2>(\n ([propAndMetric, aggregationType]) => {\n if (propAndMetric === \"$count\") {\n return {\n type: \"count\",\n name: \"count\",\n direction: directionFieldMap(aggregationType),\n };\n }\n\n const colonPos = propAndMetric.lastIndexOf(\":\");\n const property = propAndMetric.slice(0, colonPos);\n const metric = propAndMetric.slice(colonPos + 1);\n\n return [\n {\n type: metric as\n | \"approximateDistinct\"\n | \"exactDistinct\"\n | \"min\"\n | \"max\"\n | \"sum\"\n | \"avg\"\n | \"approximateDistinct\"\n | \"exactDistinct\",\n name: `${property}.${metric}`,\n direction: directionFieldMap(aggregationType),\n field: property,\n },\n ];\n },\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA,MAAMA,iBAAiB,GAAIC,GAAkC,IAC3DA,GAAG,KAAK,KAAK,GAAG,KAAK,GAAGA,GAAG,KAAK,MAAM,GAAG,MAAM,GAAGC,SAAS;;AAE7D;AACA,OAAO,SAASC,+BAA+BA,CAE7CC,MAAU,EAAE;EACZ,OAAOC,MAAM,CAACC,OAAO,CAACF,MAAM,CAAC,CAACG,OAAO,CACnC,CAAC,CAACC,aAAa,EAAEC,eAAe,CAAC,KAAK;IACpC,IAAID,aAAa,KAAK,QAAQ,EAAE;MAC9B,OAAO;QACLE,IAAI,EAAE,OAAO;QACbC,IAAI,EAAE,OAAO;QACbC,SAAS,EAAEZ,iBAAiB,CAACS,eAAe;MAC9C,CAAC;IACH;IAEA,MAAMI,QAAQ,GAAGL,aAAa,CAACM,WAAW,CAAC,GAAG,CAAC;IAC/C,MAAMC,QAAQ,GAAGP,aAAa,CAACQ,KAAK,CAAC,CAAC,EAAEH,QAAQ,CAAC;IACjD,MAAMI,MAAM,GAAGT,aAAa,CAACQ,KAAK,CAACH,QAAQ,GAAG,CAAC,CAAC;IAEhD,OAAO,CACL;MACEH,IAAI,EAAEO,MAQa;MACnBN,IAAI,EAAE,GAAGI,QAAQ,IAAIE,MAAM,EAAE;MAC7BL,SAAS,EAAEZ,iBAAiB,CAACS,eAAe,CAAC;MAC7CS,KAAK,EAAEH;IACT,CAAC,CACF;EACH,CACF,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"modernToLegacyAggregationClause.js","names":["directionFieldMap","dir","undefined","splitAggregationKey","key","colonPos","lastIndexOf","property","slice","metric","modernToLegacyAggregationClause","select","Object","entries","flatMap","propAndMetric","aggregationType","type","name","direction","field"],"sources":["modernToLegacyAggregationClause.ts"],"sourcesContent":["/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { AggregationClause } from \"@osdk/api\";\nimport type { AggregationV2 } from \"@osdk/foundry.ontologies\";\n\nconst directionFieldMap = (dir?: \"asc\" | \"desc\" | \"unordered\") =>\n dir === \"asc\" ? \"ASC\" : dir === \"desc\" ? \"DESC\" : undefined;\n\n/** @internal */\nexport function splitAggregationKey(key: string): {\n property: string;\n metric: string;\n} {\n const colonPos = key.lastIndexOf(\":\");\n return { property: key.slice(0, colonPos), metric: key.slice(colonPos + 1) };\n}\n\n/** @internal */\nexport function modernToLegacyAggregationClause<\n AC extends AggregationClause<any>,\n>(select: AC) {\n return Object.entries(select).flatMap<AggregationV2>(\n ([propAndMetric, aggregationType]) => {\n if (propAndMetric === \"$count\") {\n return {\n type: \"count\",\n name: \"count\",\n direction: directionFieldMap(aggregationType),\n };\n }\n\n const { property, metric } = splitAggregationKey(propAndMetric);\n\n return [\n {\n type: metric as\n | \"approximateDistinct\"\n | \"exactDistinct\"\n | \"min\"\n | \"max\"\n | \"sum\"\n | \"avg\"\n | \"approximateDistinct\"\n | \"exactDistinct\",\n name: `${property}.${metric}`,\n direction: directionFieldMap(aggregationType),\n field: property,\n },\n ];\n },\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA,MAAMA,iBAAiB,GAAIC,GAAkC,IAC3DA,GAAG,KAAK,KAAK,GAAG,KAAK,GAAGA,GAAG,KAAK,MAAM,GAAG,MAAM,GAAGC,SAAS;;AAE7D;AACA,OAAO,SAASC,mBAAmBA,CAACC,GAAW,EAG7C;EACA,MAAMC,QAAQ,GAAGD,GAAG,CAACE,WAAW,CAAC,GAAG,CAAC;EACrC,OAAO;IAAEC,QAAQ,EAAEH,GAAG,CAACI,KAAK,CAAC,CAAC,EAAEH,QAAQ,CAAC;IAAEI,MAAM,EAAEL,GAAG,CAACI,KAAK,CAACH,QAAQ,GAAG,CAAC;EAAE,CAAC;AAC9E;;AAEA;AACA,OAAO,SAASK,+BAA+BA,CAE7CC,MAAU,EAAE;EACZ,OAAOC,MAAM,CAACC,OAAO,CAACF,MAAM,CAAC,CAACG,OAAO,CACnC,CAAC,CAACC,aAAa,EAAEC,eAAe,CAAC,KAAK;IACpC,IAAID,aAAa,KAAK,QAAQ,EAAE;MAC9B,OAAO;QACLE,IAAI,EAAE,OAAO;QACbC,IAAI,EAAE,OAAO;QACbC,SAAS,EAAEnB,iBAAiB,CAACgB,eAAe;MAC9C,CAAC;IACH;IAEA,MAAM;MAAET,QAAQ;MAAEE;IAAO,CAAC,GAAGN,mBAAmB,CAACY,aAAa,CAAC;IAE/D,OAAO,CACL;MACEE,IAAI,EAAER,MAQa;MACnBS,IAAI,EAAE,GAAGX,QAAQ,IAAIE,MAAM,EAAE;MAC7BU,SAAS,EAAEnB,iBAAiB,CAACgB,eAAe,CAAC;MAC7CI,KAAK,EAAEb;IACT,CAAC,CACF;EACH,CACF,CAAC;AACH","ignoreList":[]}
@@ -51,14 +51,14 @@ export async function aggregate(clientCtx, objectType, objectSet = resolveBaseOb
51
51
  !(result.data.length === 1) ? process.env.NODE_ENV !== "production" ? invariant(false, "no group by clause should mean only one data result") : invariant(false) : void 0;
52
52
  return {
53
53
  ...aggregationToCountResult(result.data[0]),
54
- ...legacyToModernSingleAggregationResult(result.data[0])
54
+ ...legacyToModernSingleAggregationResult(result.data[0], req.$select)
55
55
  };
56
56
  }
57
57
  const ret = result.data.map(entry => {
58
58
  return {
59
59
  $group: entry.group,
60
60
  ...aggregationToCountResult(entry),
61
- ...legacyToModernSingleAggregationResult(entry)
61
+ ...legacyToModernSingleAggregationResult(entry, req.$select)
62
62
  };
63
63
  }); // fixme
64
64
 
@@ -1 +1 @@
1
- {"version":3,"file":"aggregate.js","names":["OntologyObjectSets","invariant","legacyToModernSingleAggregationResult","modernToLegacyAggregationClause","modernToLegacyGroupByClause","addUserAgentAndRequestContextHeaders","resolveBaseObjectSetType","aggregate","clientCtx","objectType","objectSet","req","body","aggregation","$select","groupBy","where","undefined","$groupBy","flushEdits","result","ontologyRid","branch","transactionId","data","Array","isArray","Error","JSON","stringify","length","process","env","NODE_ENV","aggregationToCountResult","ret","map","entry","$group","group","aggregateResult","metrics","name","$count","value"],"sources":["aggregate.ts"],"sourcesContent":["/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n AggregateOpts,\n AggregateOptsThatErrorsAndDisallowsOrderingWithMultipleGroupBy,\n AggregationResultsWithGroups,\n AggregationsResults,\n ObjectOrInterfaceDefinition,\n} from \"@osdk/api\";\nimport type {\n AggregateObjectsRequestV2,\n AggregateObjectsResponseV2,\n ObjectSet,\n} from \"@osdk/foundry.ontologies\";\nimport * as OntologyObjectSets from \"@osdk/foundry.ontologies/OntologyObjectSet\";\nimport invariant from \"tiny-invariant\";\nimport { legacyToModernSingleAggregationResult } from \"../internal/conversions/legacyToModernSingleAggregationResult.js\";\nimport { modernToLegacyAggregationClause } from \"../internal/conversions/modernToLegacyAggregationClause.js\";\nimport { modernToLegacyGroupByClause } from \"../internal/conversions/modernToLegacyGroupByClause.js\";\nimport type { MinimalClient } from \"../MinimalClientContext.js\";\nimport { addUserAgentAndRequestContextHeaders } from \"../util/addUserAgentAndRequestContextHeaders.js\";\nimport type { ArrayElement } from \"../util/ArrayElement.js\";\nimport { resolveBaseObjectSetType } from \"../util/objectSetUtils.js\";\n\n/** @internal */\nexport async function aggregate<\n Q extends ObjectOrInterfaceDefinition,\n AO extends AggregateOpts<Q>,\n>(\n clientCtx: MinimalClient,\n objectType: Q,\n objectSet: ObjectSet = resolveBaseObjectSetType(objectType),\n req: AggregateOptsThatErrorsAndDisallowsOrderingWithMultipleGroupBy<Q, AO>,\n): Promise<AggregationsResults<Q, AO>> {\n const resolvedObjectSet = resolveBaseObjectSetType(objectType);\n const body: AggregateObjectsRequestV2 = {\n aggregation: modernToLegacyAggregationClause<AO[\"$select\"]>(\n req.$select,\n ),\n groupBy: [],\n where: undefined,\n };\n\n if (req.$groupBy) {\n body.groupBy = modernToLegacyGroupByClause(req.$groupBy);\n }\n\n if (clientCtx.flushEdits != null) {\n await clientCtx.flushEdits();\n }\n\n const result = await OntologyObjectSets.aggregate(\n addUserAgentAndRequestContextHeaders(clientCtx, objectType),\n await clientCtx.ontologyRid,\n {\n objectSet,\n groupBy: body.groupBy,\n aggregation: body.aggregation,\n },\n { branch: clientCtx.branch, transactionId: clientCtx.transactionId },\n );\n\n if (!result.data || !Array.isArray(result.data)) {\n throw new Error(\n `Aggregation request failed: ${JSON.stringify(result)}`,\n );\n }\n\n if (!req.$groupBy) {\n invariant(\n result.data.length === 1,\n \"no group by clause should mean only one data result\",\n );\n\n return {\n ...aggregationToCountResult(result.data[0]),\n ...legacyToModernSingleAggregationResult(\n result.data[0],\n ),\n } as any;\n }\n\n const ret: AggregationResultsWithGroups<Q, AO[\"$select\"], any> = result.data\n .map((entry) => {\n return {\n $group: entry.group as any,\n ...aggregationToCountResult(entry),\n ...legacyToModernSingleAggregationResult(entry),\n };\n }) as any; // fixme\n\n return ret as any; // FIXME\n}\n\nfunction aggregationToCountResult(\n entry: ArrayElement<AggregateObjectsResponseV2[\"data\"]>,\n): { $count: number } | undefined {\n for (const aggregateResult of entry.metrics) {\n if (aggregateResult.name === \"count\") {\n return { $count: aggregateResult.value };\n }\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAcA,OAAO,KAA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+BC,IAAI,CAACC,SAAS,CAACT,MAAM,CAAC,EACvD,CAAC;EACH;EAEA,IAAI,CAACT,GAAG,CAACO,QAAQ,EAAE;IACjB,EACEE,MAAM,CAACI,IAAI,CAACM,MAAM,KAAK,CAAC,IAAAC,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAD1BhC,SAAS,QAEP,qDAAqD,IAFvDA,SAAS;IAKT,OAAO;MACL,GAAGiC,wBAAwB,CAACd,MAAM,CAACI,IAAI,CAAC,CAAC,CAAC,CAAC;MAC3C,GAAGtB,qCAAqC,CACtCkB,MAAM,CAACI,IAAI,CAAC,CAAC,CACf;IACF,CAAC;EACH;EAEA,MAAMW,GAAwD,GAAGf,MAAM,CAACI,IAAI,CACzEY,GAAG,CAAEC,KAAK,IAAK;IACd,OAAO;MACLC,MAAM,EAAED,KAAK,CAACE,KAAY;MAC1B,GAAGL,wBAAwB,CAACG,KAAK,CAAC;MAClC,GAAGnC,qCAAqC,CAACmC,KAAK;IAChD,CAAC;EACH,CAAC,CAAQ,CAAC,CAAC;;EAEb,OAAOF,GAAG,CAAQ,CAAC;AACrB;AAEA,SAASD,wBAAwBA,CAC/BG,KAAuD,EACvB;EAChC,KAAK,MAAMG,eAAe,IAAIH,KAAK,CAACI,OAAO,EAAE;IAC3C,IAAID,eAAe,CAACE,IAAI,KAAK,OAAO,EAAE;MACpC,OAAO;QAAEC,MAAM,EAAEH,eAAe,CAACI;MAAM,CAAC;IAC1C;EACF;AACF","ignoreList":[]}
1
+ {"version":3,"file":"aggregate.js","names":["OntologyObjectSets","invariant","legacyToModernSingleAggregationResult","modernToLegacyAggregationClause","modernToLegacyGroupByClause","addUserAgentAndRequestContextHeaders","resolveBaseObjectSetType","aggregate","clientCtx","objectType","objectSet","req","body","aggregation","$select","groupBy","where","undefined","$groupBy","flushEdits","result","ontologyRid","branch","transactionId","data","Array","isArray","Error","JSON","stringify","length","process","env","NODE_ENV","aggregationToCountResult","ret","map","entry","$group","group","aggregateResult","metrics","name","$count","value"],"sources":["aggregate.ts"],"sourcesContent":["/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n AggregateOpts,\n AggregateOptsThatErrorsAndDisallowsOrderingWithMultipleGroupBy,\n AggregationResultsWithGroups,\n AggregationsResults,\n ObjectOrInterfaceDefinition,\n} from \"@osdk/api\";\nimport type {\n AggregateObjectsRequestV2,\n AggregateObjectsResponseV2,\n ObjectSet,\n} from \"@osdk/foundry.ontologies\";\nimport * as OntologyObjectSets from \"@osdk/foundry.ontologies/OntologyObjectSet\";\nimport invariant from \"tiny-invariant\";\nimport { legacyToModernSingleAggregationResult } from \"../internal/conversions/legacyToModernSingleAggregationResult.js\";\nimport { modernToLegacyAggregationClause } from \"../internal/conversions/modernToLegacyAggregationClause.js\";\nimport { modernToLegacyGroupByClause } from \"../internal/conversions/modernToLegacyGroupByClause.js\";\nimport type { MinimalClient } from \"../MinimalClientContext.js\";\nimport { addUserAgentAndRequestContextHeaders } from \"../util/addUserAgentAndRequestContextHeaders.js\";\nimport type { ArrayElement } from \"../util/ArrayElement.js\";\nimport { resolveBaseObjectSetType } from \"../util/objectSetUtils.js\";\n\n/** @internal */\nexport async function aggregate<\n Q extends ObjectOrInterfaceDefinition,\n AO extends AggregateOpts<Q>,\n>(\n clientCtx: MinimalClient,\n objectType: Q,\n objectSet: ObjectSet = resolveBaseObjectSetType(objectType),\n req: AggregateOptsThatErrorsAndDisallowsOrderingWithMultipleGroupBy<Q, AO>,\n): Promise<AggregationsResults<Q, AO>> {\n const resolvedObjectSet = resolveBaseObjectSetType(objectType);\n const body: AggregateObjectsRequestV2 = {\n aggregation: modernToLegacyAggregationClause<AO[\"$select\"]>(\n req.$select,\n ),\n groupBy: [],\n where: undefined,\n };\n\n if (req.$groupBy) {\n body.groupBy = modernToLegacyGroupByClause(req.$groupBy);\n }\n\n if (clientCtx.flushEdits != null) {\n await clientCtx.flushEdits();\n }\n\n const result = await OntologyObjectSets.aggregate(\n addUserAgentAndRequestContextHeaders(clientCtx, objectType),\n await clientCtx.ontologyRid,\n {\n objectSet,\n groupBy: body.groupBy,\n aggregation: body.aggregation,\n },\n { branch: clientCtx.branch, transactionId: clientCtx.transactionId },\n );\n\n if (!result.data || !Array.isArray(result.data)) {\n throw new Error(\n `Aggregation request failed: ${JSON.stringify(result)}`,\n );\n }\n\n if (!req.$groupBy) {\n invariant(\n result.data.length === 1,\n \"no group by clause should mean only one data result\",\n );\n\n return {\n ...aggregationToCountResult(result.data[0]),\n ...legacyToModernSingleAggregationResult(\n result.data[0],\n req.$select,\n ),\n } as any;\n }\n\n const ret: AggregationResultsWithGroups<Q, AO[\"$select\"], any> = result.data\n .map((entry) => {\n return {\n $group: entry.group as any,\n ...aggregationToCountResult(entry),\n ...legacyToModernSingleAggregationResult(entry, req.$select),\n };\n }) as any; // fixme\n\n return ret as any; // FIXME\n}\n\nfunction aggregationToCountResult(\n entry: ArrayElement<AggregateObjectsResponseV2[\"data\"]>,\n): { $count: number } | undefined {\n for (const aggregateResult of entry.metrics) {\n if (aggregateResult.name === \"count\") {\n return { $count: aggregateResult.value };\n }\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAcA,OAAO,KAAKA,kBAAkB,MAAM,4CAA4C;AAChF,OAAOC,SAAS,MAAM,gBAAgB;AACtC,SAASC,qCAAqC,QAAQ,kEAAkE;AACxH,SAASC,+BAA+B,QAAQ,4DAA4D;AAC5G,SAASC,2BAA2B,QAAQ,wDAAwD;AAEpG,SAASC,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AAAC,QAAA,oBAD1BhC,SAAS,QAEP,qDAAqD,IAFvDA,SAAS;IAKT,OAAO;MACL,GAAGiC,wBAAwB,CAACd,MAAM,CAACI,IAAI,CAAC,CAAC,CAAC,CAAC;MAC3C,GAAGtB,qCAAqC,CACtCkB,MAAM,CAACI,IAAI,CAAC,CAAC,CAAC,EACdb,GAAG,CAACG,OACN;IACF,CAAC;EACH;EAEA,MAAMqB,GAAwD,GAAGf,MAAM,CAACI,IAAI,CACzEY,GAAG,CAAEC,KAAK,IAAK;IACd,OAAO;MACLC,MAAM,EAAED,KAAK,CAACE,KAAY;MAC1B,GAAGL,wBAAwB,CAACG,KAAK,CAAC;MAClC,GAAGnC,qCAAqC,CAACmC,KAAK,EAAE1B,GAAG,CAACG,OAAO;IAC7D,CAAC;EACH,CAAC,CAAQ,CAAC,CAAC;;EAEb,OAAOqB,GAAG,CAAQ,CAAC;AACrB;AAEA,SAASD,wBAAwBA,CAC/BG,KAAuD,EACvB;EAChC,KAAK,MAAMG,eAAe,IAAIH,KAAK,CAACI,OAAO,EAAE;IAC3C,IAAID,eAAe,CAACE,IAAI,KAAK,OAAO,EAAE;MACpC,OAAO;QAAEC,MAAM,EAAEH,eAAe,CAACI;MAAM,CAAC;IAC1C;EACF;AACF","ignoreList":[]}
@@ -14,6 +14,6 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- export const USER_AGENT = `osdk-client/${"2.8.0-beta.21"}`;
18
- export const OBSERVABLE_USER_AGENT = `osdk-observable-client/${"2.8.0-beta.21"}`;
17
+ export const USER_AGENT = `osdk-client/${"2.8.0-beta.22"}`;
18
+ export const OBSERVABLE_USER_AGENT = `osdk-observable-client/${"2.8.0-beta.22"}`;
19
19
  //# sourceMappingURL=UserAgent.js.map
@@ -921,25 +921,16 @@ function createWithPropertiesObjectSet(objectType, objectSet, definitionMap, fro
921
921
  }
922
922
  };
923
923
  }
924
- function legacyToModernSingleAggregationResult(entry) {
925
- return entry.metrics.reduce((accumulator, curValue) => {
926
- const parts = curValue.name.split(".");
927
- if (parts[0] === "count") {
928
- return accumulator;
929
- }
930
- !(parts.length === 2) ? process.env.NODE_ENV !== "production" ? invariant4__default.default(false, "assumed we were getting a `${key}.${type}`") : invariant4__default.default(false) : void 0;
931
- const property = parts[0];
932
- const metricType = parts[1];
933
- if (!(property in accumulator)) {
934
- accumulator[property] = {};
935
- }
936
- accumulator[property][metricType] = curValue.value;
937
- return accumulator;
938
- }, {});
939
- }
940
924
 
941
925
  // src/internal/conversions/modernToLegacyAggregationClause.ts
942
926
  var directionFieldMap = (dir) => dir === "asc" ? "ASC" : dir === "desc" ? "DESC" : void 0;
927
+ function splitAggregationKey(key) {
928
+ const colonPos = key.lastIndexOf(":");
929
+ return {
930
+ property: key.slice(0, colonPos),
931
+ metric: key.slice(colonPos + 1)
932
+ };
933
+ }
943
934
  function modernToLegacyAggregationClause(select) {
944
935
  return Object.entries(select).flatMap(([propAndMetric, aggregationType]) => {
945
936
  if (propAndMetric === "$count") {
@@ -949,9 +940,10 @@ function modernToLegacyAggregationClause(select) {
949
940
  direction: directionFieldMap(aggregationType)
950
941
  };
951
942
  }
952
- const colonPos = propAndMetric.lastIndexOf(":");
953
- const property = propAndMetric.slice(0, colonPos);
954
- const metric = propAndMetric.slice(colonPos + 1);
943
+ const {
944
+ property,
945
+ metric
946
+ } = splitAggregationKey(propAndMetric);
955
947
  return [{
956
948
  type: metric,
957
949
  name: `${property}.${metric}`,
@@ -960,6 +952,34 @@ function modernToLegacyAggregationClause(select) {
960
952
  }];
961
953
  });
962
954
  }
955
+
956
+ // src/internal/conversions/legacyToModernSingleAggregationResult.ts
957
+ function legacyToModernSingleAggregationResult(entry, select) {
958
+ const result = {};
959
+ for (const selectKey of Object.keys(select)) {
960
+ if (selectKey === "$count") {
961
+ continue;
962
+ }
963
+ const {
964
+ property,
965
+ metric
966
+ } = splitAggregationKey(selectKey);
967
+ (result[property] ??= {})[metric] = void 0;
968
+ }
969
+ for (const {
970
+ name,
971
+ value
972
+ } of entry.metrics) {
973
+ if (name === "count") {
974
+ continue;
975
+ }
976
+ const [property, metricType] = name.split(".");
977
+ if (result[property]) {
978
+ result[property][metricType] = value;
979
+ }
980
+ }
981
+ return result;
982
+ }
963
983
  function modernToLegacyGroupByClause(groupByClause) {
964
984
  if (!groupByClause) return [];
965
985
  return Object.entries(groupByClause).flatMap(([field, type]) => {
@@ -1040,14 +1060,14 @@ async function aggregate2(clientCtx, objectType, objectSet = resolveBaseObjectSe
1040
1060
  !(result.data.length === 1) ? process.env.NODE_ENV !== "production" ? invariant4__default.default(false, "no group by clause should mean only one data result") : invariant4__default.default(false) : void 0;
1041
1061
  return {
1042
1062
  ...aggregationToCountResult(result.data[0]),
1043
- ...legacyToModernSingleAggregationResult(result.data[0])
1063
+ ...legacyToModernSingleAggregationResult(result.data[0], req.$select)
1044
1064
  };
1045
1065
  }
1046
1066
  const ret = result.data.map((entry) => {
1047
1067
  return {
1048
1068
  $group: entry.group,
1049
1069
  ...aggregationToCountResult(entry),
1050
- ...legacyToModernSingleAggregationResult(entry)
1070
+ ...legacyToModernSingleAggregationResult(entry, req.$select)
1051
1071
  };
1052
1072
  });
1053
1073
  return ret;
@@ -1449,5 +1469,5 @@ exports.hydrateAttachmentFromRidInternal = hydrateAttachmentFromRidInternal;
1449
1469
  exports.isObjectSet = isObjectSet;
1450
1470
  exports.isWireObjectSet = isWireObjectSet;
1451
1471
  exports.upload = upload;
1452
- //# sourceMappingURL=chunk-3XHX3RLX.cjs.map
1453
- //# sourceMappingURL=chunk-3XHX3RLX.cjs.map
1472
+ //# sourceMappingURL=chunk-R7OP6A6S.cjs.map
1473
+ //# sourceMappingURL=chunk-R7OP6A6S.cjs.map