@osdk/api 0.0.0-20230929184205

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 (131) hide show
  1. package/.eslintrc.cjs +4 -0
  2. package/.turbo/turbo-build.log +26 -0
  3. package/.turbo/turbo-lint.log +4 -0
  4. package/CHANGELOG.md +7 -0
  5. package/dist/chunk-TTS63OIX.mjs +7 -0
  6. package/dist/chunk-TTS63OIX.mjs.map +1 -0
  7. package/dist/chunk-ZJRKQTOR.js +16 -0
  8. package/dist/chunk-ZJRKQTOR.js.map +1 -0
  9. package/dist/index.js +20 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/index.mjs +9 -0
  12. package/dist/index.mjs.map +1 -0
  13. package/dist/public/objects.js +16 -0
  14. package/dist/public/objects.js.map +1 -0
  15. package/dist/public/objects.mjs +3 -0
  16. package/dist/public/objects.mjs.map +1 -0
  17. package/lib/client/Client.d.ts +8 -0
  18. package/lib/client/ObjectSetCreator.d.ts +15 -0
  19. package/lib/client/PageResult.d.ts +5 -0
  20. package/lib/client/PalantirApiError.d.ts +9 -0
  21. package/lib/client/ResultOrError.d.ts +11 -0
  22. package/lib/client/ThinClient.d.ts +13 -0
  23. package/lib/client/UnknownError.d.ts +5 -0
  24. package/lib/client/createClient.d.ts +3 -0
  25. package/lib/client/createThinClient.d.ts +6 -0
  26. package/lib/client/index.d.ts +8 -0
  27. package/lib/client/internal/conversions/index.d.ts +4 -0
  28. package/lib/client/internal/conversions/legacyToModernSingleAggregationResult.d.ts +4 -0
  29. package/lib/client/internal/conversions/modernToLegacyAggregationClause.d.ts +4 -0
  30. package/lib/client/internal/conversions/modernToLegacyGroupByClause.d.ts +4 -0
  31. package/lib/client/internal/conversions/modernToLegacyWhereClause.d.ts +4 -0
  32. package/lib/client/internal/net/V2_BASE.d.ts +1 -0
  33. package/lib/client/internal/net/aggregateObjectsV2.d.ts +3 -0
  34. package/lib/client/internal/net/index.d.ts +3 -0
  35. package/lib/client/internal/net/listObjectsFromObjectSetV2.d.ts +3 -0
  36. package/lib/client/internal/net/types.d.ts +357 -0
  37. package/lib/client/object/aggregateOrThrow.d.ts +5 -0
  38. package/lib/client/object/aggregateOrThrow.test.d.ts +2 -0
  39. package/lib/client/object/fetchPageOrThrow.d.ts +10 -0
  40. package/lib/client/object/index.d.ts +2 -0
  41. package/lib/client/objectSet/LinkTypesFrom.d.ts +2 -0
  42. package/lib/client/objectSet/ObjectSet.d.ts +25 -0
  43. package/lib/client/objectSet/createObjectSet.d.ts +5 -0
  44. package/lib/client/query/WhereClause.d.ts +24 -0
  45. package/lib/client/query/aggregations/AggregatableKeys.d.ts +4 -0
  46. package/lib/client/query/aggregations/AggregateOpts.d.ts +7 -0
  47. package/lib/client/query/aggregations/AggregationResultsWithGroups.d.ts +10 -0
  48. package/lib/client/query/aggregations/AggregationResultsWithoutGroups.d.ts +8 -0
  49. package/lib/client/query/aggregations/AggregationsClause.d.ts +8 -0
  50. package/lib/client/query/aggregations/AggregationsClause.test.d.ts +36 -0
  51. package/lib/client/query/aggregations/AggregationsResults.d.ts +5 -0
  52. package/lib/client/query/aggregations/AggregationsResults.test.d.ts +1 -0
  53. package/lib/client/query/aggregations/GroupByClause.d.ts +12 -0
  54. package/lib/client/query/aggregations/GroupByClause.test.d.ts +18 -0
  55. package/lib/client/query/aggregations/GroupByMapper.d.ts +4 -0
  56. package/lib/client/query/index.d.ts +7 -0
  57. package/lib/index.d.ts +6 -0
  58. package/lib/ontology/Definition.d.ts +36 -0
  59. package/lib/ontology/OntologyMetadata.d.ts +5 -0
  60. package/lib/ontology/OsdkObject.d.ts +3 -0
  61. package/lib/ontology/OsdkObjectFrom.d.ts +6 -0
  62. package/lib/ontology/index.d.ts +4 -0
  63. package/lib/public/objects.d.ts +1 -0
  64. package/lib/util/ArrayElement.d.ts +1 -0
  65. package/lib/util/FetchAsJson.d.ts +15 -0
  66. package/lib/util/NOOP.d.ts +3 -0
  67. package/lib/util/StringArrayToUnion.d.ts +1 -0
  68. package/lib/util/createFetchHeaderMutator.d.ts +1 -0
  69. package/lib/util/createFetchOrThrow.d.ts +9 -0
  70. package/lib/util/createRetryingFetch.d.ts +2 -0
  71. package/lib/util/index.d.ts +9 -0
  72. package/lib/util/stringifyBody.d.ts +1 -0
  73. package/package.json +46 -0
  74. package/src/client/Client.ts +33 -0
  75. package/src/client/ObjectSetCreator.ts +44 -0
  76. package/src/client/PageResult.ts +22 -0
  77. package/src/client/PalantirApiError.ts +41 -0
  78. package/src/client/ResultOrError.ts +23 -0
  79. package/src/client/ThinClient.ts +31 -0
  80. package/src/client/UnknownError.ts +25 -0
  81. package/src/client/createClient.ts +49 -0
  82. package/src/client/createThinClient.ts +52 -0
  83. package/src/client/index.ts +24 -0
  84. package/src/client/internal/conversions/index.ts +20 -0
  85. package/src/client/internal/conversions/legacyToModernSingleAggregationResult.ts +46 -0
  86. package/src/client/internal/conversions/modernToLegacyAggregationClause.ts +45 -0
  87. package/src/client/internal/conversions/modernToLegacyGroupByClause.ts +44 -0
  88. package/src/client/internal/conversions/modernToLegacyWhereClause.ts +135 -0
  89. package/src/client/internal/net/V2_BASE.ts +17 -0
  90. package/src/client/internal/net/aggregateObjectsV2.ts +37 -0
  91. package/src/client/internal/net/index.ts +19 -0
  92. package/src/client/internal/net/listObjectsFromObjectSetV2.ts +41 -0
  93. package/src/client/internal/net/types.ts +302 -0
  94. package/src/client/object/aggregateOrThrow.test.ts +137 -0
  95. package/src/client/object/aggregateOrThrow.ts +87 -0
  96. package/src/client/object/fetchPageOrThrow.ts +83 -0
  97. package/src/client/object/index.ts +18 -0
  98. package/src/client/objectSet/LinkTypesFrom.ts +22 -0
  99. package/src/client/objectSet/ObjectSet.ts +92 -0
  100. package/src/client/objectSet/createObjectSet.ts +130 -0
  101. package/src/client/query/WhereClause.ts +68 -0
  102. package/src/client/query/aggregations/AggregatableKeys.ts +37 -0
  103. package/src/client/query/aggregations/AggregateOpts.ts +36 -0
  104. package/src/client/query/aggregations/AggregationResultsWithGroups.ts +40 -0
  105. package/src/client/query/aggregations/AggregationResultsWithoutGroups.ts +37 -0
  106. package/src/client/query/aggregations/AggregationsClause.test.ts +60 -0
  107. package/src/client/query/aggregations/AggregationsClause.ts +44 -0
  108. package/src/client/query/aggregations/AggregationsResults.test.ts +74 -0
  109. package/src/client/query/aggregations/AggregationsResults.ts +30 -0
  110. package/src/client/query/aggregations/GroupByClause.test.ts +38 -0
  111. package/src/client/query/aggregations/GroupByClause.ts +41 -0
  112. package/src/client/query/aggregations/GroupByMapper.ts +21 -0
  113. package/src/client/query/index.ts +32 -0
  114. package/src/index.ts +28 -0
  115. package/src/ontology/Definition.ts +89 -0
  116. package/src/ontology/OntologyMetadata.ts +21 -0
  117. package/src/ontology/OsdkObject.ts +17 -0
  118. package/src/ontology/OsdkObjectFrom.ts +33 -0
  119. package/src/ontology/index.ts +20 -0
  120. package/src/public/objects.ts +17 -0
  121. package/src/util/ArrayElement.ts +18 -0
  122. package/src/util/FetchAsJson.ts +55 -0
  123. package/src/util/NOOP.ts +21 -0
  124. package/src/util/StringArrayToUnion.ts +18 -0
  125. package/src/util/createFetchHeaderMutator.ts +34 -0
  126. package/src/util/createFetchOrThrow.ts +71 -0
  127. package/src/util/createRetryingFetch.ts +55 -0
  128. package/src/util/index.ts +25 -0
  129. package/src/util/stringifyBody.ts +21 -0
  130. package/tsconfig.json +5 -0
  131. package/tsup.config.js +21 -0
@@ -0,0 +1,135 @@
1
+ /*
2
+ * Copyright 2023 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import type {
18
+ AndWhereClause,
19
+ NotWhereClause,
20
+ OrWhereClause,
21
+ PossibleWhereClauseFilters,
22
+ WhereClause,
23
+ } from "#client/query";
24
+ import type { Wire } from "#net";
25
+ import type { ObjectDefinition } from "#ontology";
26
+ import invariant from "tiny-invariant";
27
+
28
+ export function modernToLegacyWhereClause<T extends ObjectDefinition<any, any>>(
29
+ whereClause: WhereClause<T>,
30
+ ): Wire.SearchJsonQueryV2 {
31
+ if ("$and" in whereClause) {
32
+ return {
33
+ type: "and",
34
+ value: (whereClause as AndWhereClause<T>).$and.map(
35
+ modernToLegacyWhereClause,
36
+ ),
37
+ };
38
+ } else if ("$or" in whereClause) {
39
+ return {
40
+ type: "or",
41
+ value: (whereClause as OrWhereClause<T>).$or.map(
42
+ modernToLegacyWhereClause,
43
+ ),
44
+ };
45
+ } else if ("$not" in whereClause) {
46
+ return {
47
+ type: "not",
48
+ value: modernToLegacyWhereClause((whereClause as NotWhereClause<T>).$not),
49
+ };
50
+ }
51
+
52
+ const parts = Object.entries(whereClause);
53
+
54
+ if (parts.length === 1) {
55
+ const [field, filter] = parts[0];
56
+ invariant(
57
+ filter != null,
58
+ "Defined key values are only allowed when they are not undefined.",
59
+ );
60
+ if (typeof filter === "string" || typeof filter === "number") {
61
+ return {
62
+ type: "eq",
63
+ field,
64
+ value: filter,
65
+ };
66
+ }
67
+
68
+ invariant(
69
+ Object.keys(filter).length === 1,
70
+ "WhereClause Filter with multiple properties isn't allowed",
71
+ );
72
+ const type = Object.keys(filter)[0] as PossibleWhereClauseFilters;
73
+ invariant(filter[type] != null);
74
+
75
+ if (type === "ne") {
76
+ return {
77
+ type: "not",
78
+ value: {
79
+ type: "eq",
80
+ field,
81
+ value: filter[type],
82
+ },
83
+ };
84
+ }
85
+
86
+ return {
87
+ type,
88
+ field,
89
+ value: filter[type] as any,
90
+ };
91
+ }
92
+
93
+ return {
94
+ type: "and",
95
+ value: Object.entries(whereClause).map<Wire.SearchJsonQueryV2>(
96
+ ([field, filter]) => {
97
+ invariant(
98
+ filter != null,
99
+ "Defined key values are only allowed when they are not undefined.",
100
+ );
101
+ if (typeof filter === "string" || typeof filter === "number") {
102
+ return {
103
+ type: "eq",
104
+ field,
105
+ value: filter,
106
+ };
107
+ }
108
+
109
+ invariant(
110
+ Object.keys(filter).length === 1,
111
+ "WhereClause Filter with multiple properties isn't allowed",
112
+ );
113
+ const q = Object.keys(filter)[0] as PossibleWhereClauseFilters;
114
+ invariant(filter[q] != null);
115
+
116
+ if (q === "ne") {
117
+ return {
118
+ type: "not",
119
+ value: {
120
+ type: "eq",
121
+ field,
122
+ value: filter[q],
123
+ },
124
+ };
125
+ }
126
+
127
+ return {
128
+ type: q,
129
+ field,
130
+ value: filter[q] as any,
131
+ };
132
+ },
133
+ ),
134
+ };
135
+ }
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright 2023 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ export const V2_BASE = "api/v2/ontologies";
@@ -0,0 +1,37 @@
1
+ /*
2
+ * Copyright 2023 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import type { FetchAsJsonFn } from "#util";
18
+ import type { AggregateObjectsV2Body, AggregationAPIResponse } from "./types";
19
+ import { V2_BASE } from "./V2_BASE";
20
+
21
+ export default async function aggregateObjectsV2(
22
+ fetchAsJson: FetchAsJsonFn,
23
+ foundryHost: string,
24
+ ontologyApiName: string,
25
+ objectApiName: string,
26
+ body: AggregateObjectsV2Body,
27
+ ): Promise<AggregationAPIResponse> {
28
+ const aggregateObjectsUrl = new URL(
29
+ `${V2_BASE}/${ontologyApiName}/objects/${objectApiName}/aggregate`,
30
+ `https://${foundryHost}`,
31
+ );
32
+
33
+ return fetchAsJson(aggregateObjectsUrl, {
34
+ method: "POST",
35
+ body,
36
+ });
37
+ }
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Copyright 2023 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ export { default as aggregateObjectsV2 } from "./aggregateObjectsV2";
18
+ export { default as listObjectsFromObjectSetV2 } from "./listObjectsFromObjectSetV2";
19
+ export * as Wire from "./types";
@@ -0,0 +1,41 @@
1
+ /*
2
+ * Copyright 2023 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import type { FetchAsJsonFn } from "#util";
18
+ import type {
19
+ LoadObjectSetRequestV2,
20
+ OntologyObjectV2,
21
+ PagedResponse,
22
+ } from "./types";
23
+ import { V2_BASE } from "./V2_BASE";
24
+
25
+ export default async function listObjectsFromObjectSetV2(
26
+ fetchAsJson: FetchAsJsonFn,
27
+ foundryHost: string,
28
+ ontologyApiName: string,
29
+ body: LoadObjectSetRequestV2,
30
+ ): Promise<PagedResponse<OntologyObjectV2>> {
31
+ return fetchAsJson(
32
+ new URL(
33
+ `${V2_BASE}/${ontologyApiName}/objectSets/loadObjects`,
34
+ `https://${foundryHost}`,
35
+ ),
36
+ {
37
+ method: "POST",
38
+ body,
39
+ },
40
+ );
41
+ }
@@ -0,0 +1,302 @@
1
+ /*
2
+ * Copyright 2023 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ export interface AggregationClause {
18
+ type: string;
19
+ field?: string;
20
+ name: string;
21
+ }
22
+
23
+ export type AggregationValueType = number | string | boolean;
24
+ export type BaseGroupValue = number | string | boolean;
25
+ export type Bucketing<T> =
26
+ | { startValue?: T; endValue: T }
27
+ | { startValue: T; endValue?: T };
28
+ export type GroupValue = BaseGroupValue | Bucketing<BaseGroupValue>;
29
+
30
+ export interface WhereClauseV2 {
31
+ type: string;
32
+ field?: string;
33
+ value?:
34
+ | string
35
+ | number
36
+ | BoundingBoxFilter
37
+ | PolyGonGeoJson
38
+ | DistanceOf
39
+ | boolean
40
+ | WhereClauseV2
41
+ | WhereClauseV2[];
42
+ }
43
+
44
+ export type BoundingBoxFilter = {
45
+ topLeft: PointGeoJson;
46
+ bottomRight: PointGeoJson;
47
+ };
48
+
49
+ export type PolyGonGeoJson = {
50
+ type: "Polygon";
51
+ coordinates: number[][][];
52
+ };
53
+
54
+ export type DistanceOf = {
55
+ center: PointGeoJson;
56
+ distance: {
57
+ value: number;
58
+ unit: string;
59
+ };
60
+ };
61
+
62
+ export type PointGeoJson = {
63
+ type: "Point";
64
+ coordinates: number[];
65
+ };
66
+
67
+ export interface SearchClauseV2 {
68
+ where?: WhereClauseV2;
69
+ orderBy?: {
70
+ fields: OrderByClause[];
71
+ };
72
+ pageSize?: number;
73
+ pageToken?: string;
74
+ }
75
+ export interface OrderByClause {
76
+ field: string;
77
+ direction: string;
78
+ }
79
+
80
+ export type GroupByClause =
81
+ | GroupByExact
82
+ | GroupByFixedWidth
83
+ | GroupByDuration
84
+ | GroupByRanges;
85
+
86
+ export type GroupByExact = {
87
+ type: "exact";
88
+ field: string;
89
+ maxGroupCount?: number;
90
+ };
91
+
92
+ export type GroupByFixedWidth = {
93
+ type: "fixedWidth";
94
+ field: string;
95
+ fixedWidth: number;
96
+ };
97
+
98
+ export type TimeUnit =
99
+ | "MILLISECONDS"
100
+ | "SECONDS"
101
+ | "MINUTES"
102
+ | "HOURS"
103
+ | "DAYS"
104
+ | "WEEKS"
105
+ | "MONTHS"
106
+ | "YEARS"
107
+ | "QUARTERS";
108
+ export type GroupByDuration = {
109
+ type: "duration";
110
+ field: string;
111
+ unit: TimeUnit;
112
+ value: number;
113
+ };
114
+
115
+ export type GroupByRanges = {
116
+ type: "ranges";
117
+ field: string;
118
+ ranges: Array<
119
+ | { startValue?: string | number; endValue: string | number }
120
+ | { startValue: string | number; endValue?: string | number }
121
+ >;
122
+ };
123
+
124
+ export interface AggregateObjectsV2Body {
125
+ aggregation: AggregationClause[];
126
+ groupBy?: GroupByClause[];
127
+ where?: SearchClauseV2;
128
+ }
129
+
130
+ export type AggregationAPIResponse = {
131
+ excludedItems?: number;
132
+ data: Array<{
133
+ group: { [key: string]: GroupValue };
134
+ metrics: Array<{ name: string; value: AggregationValueType }>;
135
+ }>;
136
+ };
137
+
138
+ export type AggregateObjectsResponseV2 = {
139
+ excludedItems?: number;
140
+ data: Array<AggregateObjectsResponseItemV2>;
141
+ };
142
+ export type AggregateObjectsResponseItemV2 = {
143
+ group: Record<AggregationGroupKeyV2, AggregationGroupValueV2>;
144
+ metrics: Array<AggregationMetricResultV2>;
145
+ };
146
+ export type AggregationGroupKeyV2 = string;
147
+ export type AggregationGroupValueV2 = any;
148
+ export type AggregationMetricResultV2 = { name: string; value?: any };
149
+
150
+ export type LoadObjectSetRequestV2 = {
151
+ objectSet: ObjectSet;
152
+ orderBy?: SearchOrderBy;
153
+ select: Array<SelectedPropertyApiName>;
154
+ pageToken?: PageToken;
155
+ pageSize?: PageSize;
156
+ };
157
+
158
+ export type SearchOrderBy = { fields: Array<SearchOrdering> };
159
+ export type SearchOrdering = { field: string; direction?: string };
160
+ export type SelectedPropertyApiName = string;
161
+ export type PageToken = string;
162
+ export type PageSize = number;
163
+ export type ObjectRid = string;
164
+
165
+ export type ObjectSet =
166
+ | (ObjectSetBaseType & { type: "base" })
167
+ | (ObjectSetStaticType & { type: "static" })
168
+ | (ObjectSetReferenceType & { type: "reference" })
169
+ | (ObjectSetFilterType & { type: "filter" })
170
+ | (ObjectSetUnionType & { type: "union" })
171
+ | (ObjectSetIntersectionType & { type: "intersect" })
172
+ | (ObjectSetSubtractType & { type: "subtract" })
173
+ | (ObjectSetSearchAroundType & { type: "searchAround" });
174
+ export type ObjectSetBaseType = { objectType: string };
175
+ export type ObjectSetStaticType = { objects: Array<ObjectRid> };
176
+ export type ObjectSetReferenceType = { reference: string };
177
+ export type ObjectSetFilterType = {
178
+ objectSet: ObjectSet;
179
+ where: SearchJsonQueryV2;
180
+ };
181
+ export type ObjectSetIntersectionType = { objectSets: Array<ObjectSet> };
182
+ /** */
183
+ export type ObjectSetUnionType = { objectSets: Array<ObjectSet> };
184
+ export type ObjectSetSubtractType = { objectSets: Array<ObjectSet> };
185
+ export type ObjectSetSearchAroundType = {
186
+ objectSet: ObjectSet;
187
+ link: LinkTypeApiName;
188
+ };
189
+ export type LinkTypeApiName = string;
190
+
191
+ export type SearchJsonQueryV2 =
192
+ | (LtQuery & { type: "lt" })
193
+ | (GtQuery & { type: "gt" })
194
+ | (LteQuery & { type: "lte" })
195
+ | (GteQuery & { type: "gte" })
196
+ | (EqualsQuery & { type: "eq" })
197
+ | (IsNullQuery & { type: "isNull" })
198
+ | (ContainsQuery & { type: "contains" })
199
+ | (AndQueryV2 & { type: "and" })
200
+ | (OrQueryV2 & { type: "or" })
201
+ | (NotQueryV2 & { type: "not" })
202
+ | (StartsWithQuery & { type: "startsWith" })
203
+ | (ContainsAllTermsInOrderQuery & { type: "containsAllTermsInOrder" })
204
+ | (ContainsAnyTermQuery & { type: "containsAnyTerm" })
205
+ | (ContainsAllTermsQuery & { type: "containsAllTerms" })
206
+ | (WithinDistanceOfQuery & { type: "withinDistanceOf" })
207
+ | (WithinBoundingBoxQuery & { type: "withinBoundingBox" })
208
+ | (IntersectsBoundingBoxQuery & { type: "intersectsBoundingBox" })
209
+ | (DoesNotIntersectBoundingBoxQuery & { type: "doesNotIntersectBoundingBox" })
210
+ | (WithinPolygonQuery & { type: "withinPolygon" })
211
+ | (IntersectsPolygonQuery & { type: "intersectsPolygon" })
212
+ | (DoesNotIntersectPolygonQuery & { type: "doesNotIntersectPolygon" });
213
+ export type LtQuery = { field: string; value: any };
214
+ export type GtQuery = { field: string; value: any };
215
+ export type LteQuery = { field: string; value: any };
216
+ /** Returns objects where the specified field is greater than or equal to a value. */
217
+ export type GteQuery = { field: string; value: any };
218
+ /** Returns objects where the specified field is equal to a value. */
219
+ export type EqualsQuery = { field: string; value: any };
220
+ /** Returns objects based on the existence of the specified field. */
221
+ export type IsNullQuery = { field: string; value: boolean };
222
+ /** Returns objects where the specified array contains a value. */
223
+ export type ContainsQuery = { field: string; value: any };
224
+ export type AndQueryV2 = { value: Array<SearchJsonQueryV2> };
225
+ export type OrQueryV2 = { value: Array<SearchJsonQueryV2> };
226
+ export type NotQueryV2 = { value: SearchJsonQueryV2 };
227
+ export type StartsWithQuery = { field: string; value: string };
228
+ export type ContainsAllTermsInOrderQuery = { field: string; value: string };
229
+ export type ContainsAnyTermQuery = {
230
+ field: string;
231
+ value: string;
232
+ fuzzy?: Fuzzy;
233
+ };
234
+
235
+ export type ContainsAllTermsQuery = {
236
+ field: string;
237
+ value: string;
238
+ fuzzy?: Fuzzy;
239
+ };
240
+ export type WithinDistanceOfQuery = { field: string; value: CenterPoint };
241
+ export type WithinBoundingBoxQuery = { field: string; value: BoundingBoxValue };
242
+ export type IntersectsBoundingBoxQuery = {
243
+ field: string;
244
+ value: BoundingBoxValue;
245
+ };
246
+ export type DoesNotIntersectBoundingBoxQuery = {
247
+ field: string;
248
+ value: BoundingBoxValue;
249
+ };
250
+ export type WithinPolygonQuery = { field: string; value: PolygonValue };
251
+ export type IntersectsPolygonQuery = { field: string; value: PolygonValue };
252
+ export type DoesNotIntersectPolygonQuery = {
253
+ field: string;
254
+ value: PolygonValue;
255
+ };
256
+ //
257
+ export type CenterPoint = { center: CenterPointTypes; distance: Distance };
258
+ export type CenterPointTypes = GeoPoint & { type: "Point" };
259
+ export type GeoPoint = { coordinates: Position; bbox?: BBox };
260
+ export type Position = Array<Coordinate>;
261
+
262
+ export type Fuzzy = boolean;
263
+ export type Coordinate = number;
264
+ export type BBox = Array<Coordinate>;
265
+ export type Distance = { value: number; unit: DistanceUnit };
266
+ export type DistanceUnit =
267
+ | "MILLIMETERS"
268
+ | "CENTIMETERS"
269
+ | "METERS"
270
+ | "KILOMETERS"
271
+ | "INCHES"
272
+ | "FEET"
273
+ | "YARDS"
274
+ | "MILES"
275
+ | "NAUTICAL_MILES";
276
+ export type BoundingBoxValue = {
277
+ topLeft: WithinBoundingBoxPoint;
278
+ bottomRight: WithinBoundingBoxPoint;
279
+ };
280
+ export type WithinBoundingBoxPoint = GeoPoint & { type: "Point" };
281
+ export type PolygonValue = Polygon & { type: "Polygon" };
282
+ export type Polygon = { coordinates: Array<LinearRing>; bbox?: BBox };
283
+ export type LinearRing = Array<Position>;
284
+
285
+ type ApiValueBaseType = string | number | boolean;
286
+ type ApiValueType = ApiValueBaseType[] | ApiValueBaseType;
287
+ type rid = string;
288
+
289
+ export type OntologyObjectV2 = { [key: string]: ApiValueType } & {
290
+ __rid: rid;
291
+ __primaryKey: ApiValueType;
292
+ };
293
+
294
+ export type PagedResponse<T> = {
295
+ data: T[];
296
+ nextPageToken?: string;
297
+ };
298
+
299
+ export type PageOptions = {
300
+ pageSize?: number;
301
+ pageToken?: string;
302
+ };
@@ -0,0 +1,137 @@
1
+ /*
2
+ * Copyright 2023 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import type { OntologyDefinition } from "#ontology";
18
+ import { expectType } from "ts-expect";
19
+ import { createThinClient } from "../createThinClient";
20
+ import type { AggregateOpts } from "../query/aggregations/AggregateOpts";
21
+ import { aggregateOrThrow } from "./aggregateOrThrow";
22
+
23
+ const mockOntology = {
24
+ metadata: undefined as any,
25
+ objects: {
26
+ Todo: {
27
+ apiName: "Todo",
28
+ links: {},
29
+ properties: {
30
+ text: {
31
+ type: "string",
32
+ },
33
+ id: {
34
+ type: "double",
35
+ },
36
+ priority: {
37
+ type: "double",
38
+ },
39
+ other: {
40
+ type: "string",
41
+ },
42
+ },
43
+ },
44
+ },
45
+ } satisfies OntologyDefinition<"Todo">;
46
+ type mockOntology = typeof mockOntology;
47
+ interface MockOntology extends mockOntology {}
48
+
49
+ // export so its not removed
50
+ export async function test1() {
51
+ const thinClient = createThinClient(
52
+ mockOntology as MockOntology,
53
+ "host.com",
54
+ () => "",
55
+ fetch,
56
+ );
57
+ const notGrouped = await aggregateOrThrow(thinClient, "Todo", {
58
+ select: {
59
+ text: "approximateDistinct",
60
+ priority: "avg",
61
+ id: ["max", "avg"],
62
+ },
63
+ });
64
+
65
+ expectType<number>(notGrouped.text.approximateDistinct);
66
+ expectType<number | undefined>(notGrouped.priority.avg);
67
+ expectType<number | undefined>(notGrouped.id.max);
68
+ expectType<number | undefined>(notGrouped.id.avg);
69
+ expectType<never>(notGrouped.other);
70
+
71
+ const grouped = await aggregateOrThrow(thinClient, "Todo", {
72
+ select: {
73
+ text: "approximateDistinct",
74
+ },
75
+ groupBy: {
76
+ text: "exact",
77
+ },
78
+ });
79
+ expectType<Array<any>>(grouped);
80
+ expectType<string | undefined>(grouped[0].group.text);
81
+ expectType<number>(grouped[0].values.text.approximateDistinct);
82
+ }
83
+
84
+ // export so its not removed
85
+ export async function test2() {
86
+ type f = AggregateOpts<
87
+ {
88
+ metadata: any;
89
+ objects: {
90
+ Todo: {
91
+ apiName: "Todo";
92
+ links: {};
93
+ properties: {
94
+ text: {
95
+ type: "string";
96
+ };
97
+ id: {
98
+ type: "double";
99
+ };
100
+ };
101
+ };
102
+ };
103
+ },
104
+ "Todo",
105
+ {
106
+ locationCity: "approximateDistinct";
107
+ text: "approximateDistinct";
108
+ }
109
+ >;
110
+
111
+ const f: AggregateOpts<
112
+ {
113
+ metadata: any;
114
+ objects: {
115
+ Todo: {
116
+ apiName: "Todo";
117
+ links: {};
118
+ properties: {
119
+ text: {
120
+ type: "string";
121
+ };
122
+ id: {
123
+ type: "double";
124
+ };
125
+ };
126
+ };
127
+ };
128
+ },
129
+ "Todo",
130
+ {
131
+ locationCity: "approximateDistinct";
132
+ text: "approximateDistinct";
133
+ }
134
+ > = undefined as any;
135
+
136
+ expectType<"approximateDistinct">(f.select.locationCity);
137
+ }