@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,87 @@
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 {
18
+ legacyToModernSingleAggregationResult,
19
+ modernToLegacyAggregationClause,
20
+ modernToLegacyGroupByClause,
21
+ modernToLegacyWhereClause,
22
+ } from "#client/converters";
23
+ import type {
24
+ AggregationResultsWithGroups,
25
+ AggregationsResults,
26
+ } from "#client/query";
27
+ import type { Wire } from "#net";
28
+ import { aggregateObjectsV2 } from "#net";
29
+ import type { ObjectTypesFrom, OntologyDefinition } from "#ontology";
30
+ import invariant from "tiny-invariant";
31
+ import type { AggregateOpts } from "../query/aggregations/AggregateOpts";
32
+ import type { ThinClient } from "../ThinClient";
33
+
34
+ export async function aggregateOrThrow<
35
+ T extends OntologyDefinition<any>,
36
+ K extends ObjectTypesFrom<T>,
37
+ const AO extends AggregateOpts<T, K, any>,
38
+ >(
39
+ thinClient: ThinClient<T>,
40
+ objectType: K,
41
+ req: AO,
42
+ ): Promise<AggregationsResults<T, K, AO>> {
43
+ const body: Wire.AggregateObjectsV2Body = {
44
+ aggregation: modernToLegacyAggregationClause<T, K, AO["select"]>(
45
+ req.select,
46
+ ),
47
+ };
48
+
49
+ if (req.groupBy) {
50
+ body.groupBy = modernToLegacyGroupByClause(req.groupBy);
51
+ }
52
+ if (req.where) {
53
+ body.where = {
54
+ where: modernToLegacyWhereClause(req.where),
55
+ // TODO: orderBy
56
+ // TODO The token stuff here sucks
57
+ };
58
+ }
59
+ const result = await aggregateObjectsV2(
60
+ thinClient.fetchJson,
61
+ thinClient.stack,
62
+ thinClient.ontology.metadata.ontologyApiName,
63
+ objectType,
64
+ body,
65
+ );
66
+
67
+ if (!req.groupBy) {
68
+ invariant(
69
+ result.data.length === 1,
70
+ "no group by clause should mean only one data result",
71
+ );
72
+
73
+ return legacyToModernSingleAggregationResult<AO["select"]>(
74
+ result.data[0],
75
+ ) as any;
76
+ }
77
+
78
+ const ret: AggregationResultsWithGroups<T, K, AO["select"], any> = result.data
79
+ .map((entry) => {
80
+ return {
81
+ group: entry.group as any,
82
+ values: legacyToModernSingleAggregationResult(entry),
83
+ };
84
+ }) as any; // fixme
85
+
86
+ return ret as any; // FIXME
87
+ }
@@ -0,0 +1,83 @@
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 { listObjectsFromObjectSetV2 } from "#net";
18
+ import type { Wire } from "#net";
19
+ import type {
20
+ ObjectTypesFrom,
21
+ OntologyDefinition,
22
+ OsdkObjectFrom,
23
+ PropertyKeysFrom,
24
+ } from "#ontology";
25
+ import type { NOOP } from "#util";
26
+ import type { PageResult } from "../PageResult";
27
+ import type { ThinClient } from "../ThinClient";
28
+
29
+ export interface FetchPageOrThrowArgs<
30
+ O extends OntologyDefinition<any>,
31
+ K extends ObjectTypesFrom<O>,
32
+ L extends PropertyKeysFrom<O, K>,
33
+ > {
34
+ select?: readonly L[];
35
+ nextPageToken?: string;
36
+ }
37
+
38
+ export async function fetchPageOrThrow<
39
+ O extends OntologyDefinition<any>,
40
+ T extends ObjectTypesFrom<O>,
41
+ const A extends FetchPageOrThrowArgs<O, T, PropertyKeysFrom<O, T>>,
42
+ >(
43
+ client: ThinClient<O>,
44
+ objectType: T,
45
+ args: A,
46
+ objectSet: Wire.ObjectSet = {
47
+ type: "base",
48
+ objectType,
49
+ },
50
+ ): Promise<
51
+ PageResult<
52
+ NOOP<
53
+ OsdkObjectFrom<
54
+ T,
55
+ O,
56
+ A["select"] extends readonly string[] ? A["select"][number]
57
+ : PropertyKeysFrom<O, T>
58
+ >
59
+ >
60
+ >
61
+ > {
62
+ const body: Wire.LoadObjectSetRequestV2 = {
63
+ objectSet,
64
+ // We have to do the following case because LoadObjectSetRequestV2 isnt readonly
65
+ select: (args?.select ?? []) as unknown as string[], // FIXME?
66
+ };
67
+
68
+ if (args?.nextPageToken) {
69
+ body.pageToken = args.nextPageToken;
70
+ }
71
+
72
+ const r = await listObjectsFromObjectSetV2(
73
+ client.fetchJson,
74
+ client.stack,
75
+ client.ontology.metadata.ontologyApiName,
76
+ body,
77
+ );
78
+
79
+ return {
80
+ data: r.data.map((d) => ({ ...d, __name: objectType })),
81
+ nextPageToken: r.nextPageToken,
82
+ } as any;
83
+ }
@@ -0,0 +1,18 @@
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 { aggregateOrThrow } from "./aggregateOrThrow";
18
+ export { fetchPageOrThrow } from "./fetchPageOrThrow";
@@ -0,0 +1,22 @@
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 { ObjectTypesFrom, OntologyDefinition } from "#ontology";
18
+
19
+ export type LinkTypesFrom<
20
+ O extends OntologyDefinition<string>,
21
+ K extends ObjectTypesFrom<O>,
22
+ > = keyof O["objects"][K]["links"] & string;
@@ -0,0 +1,92 @@
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 { AggregationsResults, WhereClause } from "#client/query";
18
+ import type {
19
+ ObjectInfoFrom,
20
+ ObjectTypesFrom,
21
+ OntologyDefinition,
22
+ OsdkObjectFrom,
23
+ PropertyKeysFrom,
24
+ } from "#ontology";
25
+ import type { FetchPageOrThrowArgs } from "../object/fetchPageOrThrow";
26
+ import type { PageResult } from "../PageResult";
27
+ import type { AggregateOpts } from "../query/aggregations/AggregateOpts";
28
+ import type { ResultOrError } from "../ResultOrError";
29
+ import type { LinkTypesFrom } from "./LinkTypesFrom";
30
+
31
+ export type ObjectSet<
32
+ O extends OntologyDefinition<string>,
33
+ K extends ObjectTypesFrom<O>,
34
+ > = BaseObjectSet<O, K>; // & SearchAround<O, K>;
35
+
36
+ // GOTTA DO THIS STILL
37
+ export type SearchAround<
38
+ O extends OntologyDefinition<string>,
39
+ K extends ObjectTypesFrom<O>,
40
+ > = {
41
+ [L in LinkTypesFrom<O, K> as `searchAround_${L}`]: () => ObjectSet<O, L>; // TODO accept args?
42
+ };
43
+
44
+ export interface BaseObjectSet<
45
+ O extends OntologyDefinition<any>,
46
+ K extends ObjectTypesFrom<O>,
47
+ > {
48
+ fetchPageOrThrow: <L extends PropertyKeysFrom<O, K>>(
49
+ args?: FetchPageOrThrowArgs<O, K, L>,
50
+ ) => Promise<PageResult<OsdkObjectFrom<K, O, L>>>;
51
+ fetchPage: <L extends PropertyKeysFrom<O, K>>(
52
+ args?: FetchPageOrThrowArgs<O, K, L>,
53
+ ) => Promise<ResultOrError<PageResult<OsdkObjectFrom<K, O, L>>>>;
54
+
55
+ asyncIter: () => AsyncIterableIterator<
56
+ OsdkObjectFrom<K, O, PropertyKeysFrom<O, K>>
57
+ >;
58
+ [Symbol.asyncIterator](): AsyncIterableIterator<
59
+ OsdkObjectFrom<K, O, PropertyKeysFrom<O, K>>
60
+ >;
61
+
62
+ aggregateOrThrow: <const AO extends AggregateOpts<O, K, any>>(
63
+ req: AO,
64
+ ) => Promise<AggregationsResults<O, K, AO>>;
65
+
66
+ aggregate: <const AO extends AggregateOpts<O, K, any>>(
67
+ req: AO,
68
+ ) => Promise<ResultOrError<AggregationsResults<O, K, typeof req>>>;
69
+
70
+ where: (clause: WhereClause<ObjectInfoFrom<O, K>>) => ObjectSet<O, K>;
71
+
72
+ pivotTo: <T extends LinkTypesFrom<O, K>>(
73
+ type: T,
74
+ opts?: ObjectSetOptions<O, O["objects"][K]["links"][T]["targetType"]>,
75
+ ) => ObjectSet<O, O["objects"][K]["links"][T]["targetType"]>;
76
+ }
77
+
78
+ // type Q<T extends
79
+
80
+ export interface ObjectSetOptions<
81
+ O extends OntologyDefinition<any>,
82
+ K extends ObjectTypesFrom<O>,
83
+ > {
84
+ $where?: WhereClause<ObjectInfoFrom<O, K>>;
85
+ }
86
+
87
+ export type ObjectSetFactory<O extends OntologyDefinition<any>> = <
88
+ K extends ObjectTypesFrom<O>,
89
+ >(
90
+ type: K,
91
+ opts?: ObjectSetOptions<O, K>,
92
+ ) => ObjectSet<O, K>; // FIXME
@@ -0,0 +1,130 @@
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 { modernToLegacyWhereClause } from "#client/converters";
18
+ import type {
19
+ AggregationClause,
20
+ AggregationsResults,
21
+ GroupByClause,
22
+ WhereClause,
23
+ } from "#client/query";
24
+ import type { Wire } from "#net";
25
+ import type {
26
+ ObjectInfoFrom,
27
+ ObjectTypesFrom,
28
+ OntologyDefinition,
29
+ PropertyKeysFrom,
30
+ } from "#ontology";
31
+ import { aggregateOrThrow, fetchPageOrThrow } from "../object";
32
+ import type { FetchPageOrThrowArgs } from "../object/fetchPageOrThrow";
33
+ import type { AggregateOpts } from "../query/aggregations/AggregateOpts";
34
+ import type { ThinClient } from "../ThinClient";
35
+ import type { LinkTypesFrom } from "./LinkTypesFrom";
36
+ import type { BaseObjectSet, ObjectSet, ObjectSetOptions } from "./ObjectSet";
37
+
38
+ const searchAroundPrefix = "searchAround_";
39
+ export function createObjectSet<
40
+ O extends OntologyDefinition<any>,
41
+ K extends ObjectTypesFrom<O>,
42
+ >(
43
+ objectType: K,
44
+ thinClient: ThinClient<O>,
45
+ opts: ObjectSetOptions<O, K> | undefined,
46
+ objectSet: Wire.ObjectSet = {
47
+ type: "base",
48
+ objectType,
49
+ },
50
+ ): ObjectSet<O, K> {
51
+ const base: BaseObjectSet<O, K> = {
52
+ aggregate: <
53
+ AC extends AggregationClause<O, K>,
54
+ GBC extends GroupByClause<O, K> | undefined = undefined,
55
+ >(req: {
56
+ select: AC;
57
+ where?: WhereClause<ObjectInfoFrom<O, K>>;
58
+ groupBy?: GBC;
59
+ }) => {
60
+ throw "TODO";
61
+ },
62
+ aggregateOrThrow: async <
63
+ AC extends AggregationClause<O, K>,
64
+ // GBC extends GroupByClause<O, K>,
65
+ AO extends AggregateOpts<O, K, AC>,
66
+ >(
67
+ req: AO,
68
+ ): Promise<AggregationsResults<O, K, AO>> => {
69
+ return aggregateOrThrow(thinClient, objectType, req);
70
+ },
71
+ fetchPage: async (args?: { nextPageToken?: string }) => {
72
+ throw "TODO";
73
+ },
74
+ fetchPageOrThrow: async <L extends PropertyKeysFrom<O, K>>(
75
+ args?: FetchPageOrThrowArgs<O, K, L>,
76
+ ) => {
77
+ return fetchPageOrThrow(
78
+ thinClient,
79
+ objectType,
80
+ args ?? {},
81
+ objectSet,
82
+ ) as any;
83
+ },
84
+
85
+ asyncIter: () => {
86
+ throw "";
87
+ },
88
+ where: (clause) => {
89
+ return createObjectSet(objectType, thinClient, opts, {
90
+ type: "filter",
91
+ objectSet: objectSet,
92
+ where: modernToLegacyWhereClause(clause),
93
+ });
94
+ },
95
+ [Symbol.asyncIterator]: () => {
96
+ throw "";
97
+ },
98
+
99
+ pivotTo: function<T extends LinkTypesFrom<O, K>>(
100
+ type: T,
101
+ opts?: ObjectSetOptions<O, O["objects"][K]["links"][T]["targetType"]>,
102
+ ): ObjectSet<O, O["objects"][K]["links"][T]["targetType"]> {
103
+ return createSearchAround(type)().where(opts?.$where ?? {});
104
+ },
105
+ };
106
+
107
+ function createSearchAround<S extends LinkTypesFrom<O, K>>(link: S) {
108
+ return () => {
109
+ return createObjectSet(
110
+ objectType,
111
+ thinClient,
112
+ {},
113
+ {
114
+ type: "searchAround",
115
+ objectSet,
116
+ link,
117
+ },
118
+ );
119
+ };
120
+ }
121
+
122
+ return new Proxy(base as ObjectSet<O, K>, {
123
+ get(target, p, receiver) {
124
+ if (typeof p === "string" && p.startsWith(searchAroundPrefix)) {
125
+ return createSearchAround(p.substring(searchAroundPrefix.length));
126
+ }
127
+ return (target as any)[p as any] as any;
128
+ },
129
+ });
130
+ }
@@ -0,0 +1,68 @@
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 { ObjectDefinition, PropertyDefinition } from "#ontology";
18
+
19
+ export type PossibleWhereClauseFilters =
20
+ | "gt"
21
+ | "eq"
22
+ | "ne"
23
+ | "isNull"
24
+ | "gte"
25
+ | "lt"
26
+ | "lte";
27
+
28
+ // We need to conditional here to force the union to be distributed
29
+ type MakeFilter<K extends PossibleWhereClauseFilters, V> = K extends string ?
30
+ & Omit<{ [k in PossibleWhereClauseFilters]?: undefined }, K>
31
+ & {
32
+ [k in K]: V;
33
+ }
34
+ : never;
35
+
36
+ type BaseFilter<T> =
37
+ | T
38
+ | MakeFilter<"eq" | "ne", T>
39
+ | MakeFilter<"isNull", boolean>;
40
+
41
+ type StringFilter = BaseFilter<string>;
42
+ type NumberFilter =
43
+ | BaseFilter<number>
44
+ | MakeFilter<"gt" | "gte" | "lt" | "lte", number>;
45
+
46
+ type FilterFor<PD extends PropertyDefinition> = PD["type"] extends "string"
47
+ ? StringFilter
48
+ : NumberFilter; // FIXME we need to represent all types
49
+
50
+ export interface AndWhereClause<T extends ObjectDefinition<any, any>> {
51
+ $and: WhereClause<T>[];
52
+ }
53
+
54
+ export interface OrWhereClause<T extends ObjectDefinition<any, any>> {
55
+ $or: WhereClause<T>[];
56
+ }
57
+
58
+ export interface NotWhereClause<T extends ObjectDefinition<any, any>> {
59
+ $not: WhereClause<T>;
60
+ }
61
+
62
+ export type WhereClause<T extends ObjectDefinition<any, any>> =
63
+ | OrWhereClause<T>
64
+ | AndWhereClause<T>
65
+ | NotWhereClause<T>
66
+ | {
67
+ [P in keyof T["properties"]]?: FilterFor<T["properties"][P]>;
68
+ };
@@ -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 {
18
+ ObjectInfoFrom,
19
+ ObjectTypesFrom,
20
+ OntologyDefinition,
21
+ PropertyKeysFrom,
22
+ } from "#ontology";
23
+
24
+ type Q<
25
+ O extends OntologyDefinition<any>,
26
+ K extends ObjectTypesFrom<O>,
27
+ P extends PropertyKeysFrom<O, K>,
28
+ > = ObjectInfoFrom<O, K>["properties"][P]["type"] extends "string" ? K
29
+ : ObjectInfoFrom<O, K>["properties"][P]["type"] extends "double" ? K
30
+ : never;
31
+
32
+ export type AggregatableKeys<
33
+ O extends OntologyDefinition<any>,
34
+ K extends ObjectTypesFrom<O>,
35
+ > = keyof {
36
+ [P in PropertyKeysFrom<O, K>]: any;
37
+ };
@@ -0,0 +1,36 @@
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
+ AggregationClause,
19
+ GroupByClause,
20
+ WhereClause,
21
+ } from "#client/query";
22
+ import type {
23
+ ObjectInfoFrom,
24
+ ObjectTypesFrom,
25
+ OntologyDefinition,
26
+ } from "#ontology";
27
+
28
+ export type AggregateOpts<
29
+ T extends OntologyDefinition<any>,
30
+ K extends ObjectTypesFrom<T>,
31
+ AC extends AggregationClause<T, K>,
32
+ > = {
33
+ select: AC;
34
+ where?: WhereClause<ObjectInfoFrom<T, K>>;
35
+ groupBy?: GroupByClause<T, K>;
36
+ };
@@ -0,0 +1,40 @@
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
+ ObjectTypesFrom,
19
+ OntologyDefinition,
20
+ OsdkObjectPropertyType,
21
+ PropertyDefinitionFrom,
22
+ PropertyKeysFrom,
23
+ } from "#ontology";
24
+ import type { AggregationResultsWithoutGroups } from "./AggregationResultsWithoutGroups";
25
+ import type { AggregationClause } from "./AggregationsClause";
26
+ import type { GroupByClause } from "./GroupByClause";
27
+
28
+ export type AggregationResultsWithGroups<
29
+ O extends OntologyDefinition<any>,
30
+ K extends ObjectTypesFrom<O>,
31
+ A extends AggregationClause<O, K>,
32
+ G extends GroupByClause<O, K> | undefined,
33
+ > = {
34
+ group: {
35
+ [P in keyof G & PropertyKeysFrom<O, K>]: OsdkObjectPropertyType<
36
+ PropertyDefinitionFrom<O, K, P>
37
+ >;
38
+ };
39
+ values: AggregationResultsWithoutGroups<O, K, A>;
40
+ }[];
@@ -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 {
18
+ ObjectTypesFrom,
19
+ OntologyDefinition,
20
+ OsdkObjectPropertyType,
21
+ PropertyDefinitionFrom,
22
+ PropertyKeysFrom,
23
+ } from "#ontology";
24
+ import type { StringArrayToUnion } from "#util";
25
+ import type { AggregationClause } from "./AggregationsClause";
26
+
27
+ export type AggregationResultsWithoutGroups<
28
+ O extends OntologyDefinition<any>,
29
+ K extends ObjectTypesFrom<O>,
30
+ AC extends AggregationClause<O, K>,
31
+ > = {
32
+ [P in PropertyKeysFrom<O, K>]: AC[P] extends readonly string[] | string ? {
33
+ [Z in StringArrayToUnion<AC[P]>]: Z extends "approximateDistinct" ? number
34
+ : OsdkObjectPropertyType<PropertyDefinitionFrom<O, K, P>>;
35
+ }
36
+ : never;
37
+ };