@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,15 @@
1
+ /**
2
+ * Fetches the given URL, converting the body to JSON, setting the Content-Type header to application/json,
3
+ * and calling .json() on the response.
4
+ */
5
+ export type FetchAsJsonFn = (url: URL, requestInit: Omit<RequestInit, "body"> & {
6
+ body?: object | undefined;
7
+ }) => Promise<any>;
8
+ /**
9
+ * Wraps a fetch function to set the Content-Type header to application/json, to handle JSON.stringify(),
10
+ * and to parse the response as JSON.
11
+ *
12
+ * @param fetchFn The fetch function to wrap
13
+ * @returns
14
+ */
15
+ export declare function createFetchAsJson(fetchFn?: typeof fetch): FetchAsJsonFn;
@@ -0,0 +1,3 @@
1
+ export type NOOP<T> = T extends (...args: any[]) => any ? T : T extends abstract new (...args: any[]) => any ? T : {
2
+ [K in keyof T]: T[K];
3
+ };
@@ -0,0 +1 @@
1
+ export type StringArrayToUnion<T extends string | readonly string[]> = T extends ReadonlyArray<infer U> ? U : T;
@@ -0,0 +1 @@
1
+ export declare function createFetchHeaderMutator(fetchFn: typeof fetch | undefined, mutator: (headers: Headers) => Promise<Headers> | Headers): typeof fetch;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Wraps a fetch plugin so that all errors (including when statusCode is not in the 200s) are converted to either PalantirApiError or UnknownError.
3
+ *
4
+ * If the returned promise does not have an error state, you are free to immediately call `.json()` or equivalent.
5
+ *
6
+ * @param fetchFn
7
+ * @returns
8
+ */
9
+ export declare function createFetchOrThrow(fetchFn?: typeof fetch): (url: RequestInfo | URL, requestInit?: RequestInit) => Promise<Response>;
@@ -0,0 +1,2 @@
1
+ /// <reference types="fetch-retry" />
2
+ export declare function createRetryingFetch(fetch: typeof globalThis.fetch): (input: RequestInfo | URL, init?: import("fetch-retry").RequestInitWithRetry | undefined) => Promise<Response>;
@@ -0,0 +1,9 @@
1
+ export type { ArrayElement } from "./ArrayElement";
2
+ export { createFetchHeaderMutator } from "./createFetchHeaderMutator";
3
+ export { createFetchOrThrow } from "./createFetchOrThrow";
4
+ export { createRetryingFetch } from "./createRetryingFetch";
5
+ export { createFetchAsJson } from "./FetchAsJson";
6
+ export type { FetchAsJsonFn } from "./FetchAsJson";
7
+ export type { NOOP } from "./NOOP";
8
+ export type { StringArrayToUnion } from "./StringArrayToUnion";
9
+ export { stringifyBody } from "./stringifyBody";
@@ -0,0 +1 @@
1
+ export declare function stringifyBody(body: object | undefined): BodyInit | null | undefined;
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@osdk/api",
3
+ "version": "0.0.0-20230929184205",
4
+ "description": "",
5
+ "access": "public",
6
+ "license": "Apache-2.0",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./src/index.ts",
10
+ "import": "./dist/index.mjs",
11
+ "require": "./dist/index.js"
12
+ },
13
+ "./*": {
14
+ "types": "./src/public/*.ts",
15
+ "import": "./dist/public/*.mjs",
16
+ "require": "./dist/public/*.js"
17
+ }
18
+ },
19
+ "dependencies": {
20
+ "fetch-retry": "^5.0.6",
21
+ "tiny-invariant": "^1.3.1"
22
+ },
23
+ "devDependencies": {
24
+ "ts-expect": "^1.3.0",
25
+ "typescript": "^5.2.2"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "imports": {
31
+ "#net": "./src/client/internal/net/index.ts",
32
+ "#util": "./src/util/index.ts",
33
+ "#ontology": "./src/ontology/index.ts",
34
+ "#client/converters": "./src/client/internal/conversions/index.ts",
35
+ "#client/query": "./src/client/query/index.ts"
36
+ },
37
+ "keywords": [],
38
+ "scripts": {
39
+ "build": "tsup",
40
+ "clean": "rm -rf lib dist tsconfig.tsbuildinfo",
41
+ "dev": "tsup --watch",
42
+ "lint": "eslint . && dprint check --config $(find-up dprint.json)",
43
+ "prettier": "prettier .",
44
+ "typecheck": "tsc-absolute"
45
+ }
46
+ }
@@ -0,0 +1,33 @@
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
+ import type { ObjectSet, ObjectSetOptions } from "./objectSet/ObjectSet";
19
+ import type { ObjectSetCreator } from "./ObjectSetCreator";
20
+
21
+ export type ConcreteObjectType<
22
+ O extends OntologyDefinition<any>,
23
+ K extends ObjectTypesFrom<O>,
24
+ > = O["objects"][K];
25
+
26
+ export interface Client<O extends OntologyDefinition<any>> {
27
+ objectSet: <const K extends ObjectTypesFrom<O>>(
28
+ type: K,
29
+ opts?: ObjectSetOptions<O, K>,
30
+ ) => ObjectSet<O, K>;
31
+
32
+ objects: ObjectSetCreator<O>;
33
+ }
@@ -0,0 +1,44 @@
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
+ import type { Client } from "./Client";
19
+ import type { ObjectSet } from "./objectSet/ObjectSet";
20
+
21
+ /**
22
+ * A type that creates an object set for each object in the ontology.
23
+ */
24
+ export type ObjectSetCreator<D extends OntologyDefinition<any>> = {
25
+ [T in ObjectTypesFrom<D>]: ObjectSet<D, T>;
26
+ };
27
+
28
+ /**
29
+ * Create a proxy for the object set creator.
30
+ * @param client The client to use to create the object sets.
31
+ * @returns A proxy for the object set creator.
32
+ */
33
+ export function createObjectSetCreator<T extends Client<any>>(client: T) {
34
+ return new Proxy(
35
+ {},
36
+ {
37
+ get: (target, p, receiver) => {
38
+ if (typeof p === "string") return client.objectSet(p);
39
+
40
+ return undefined;
41
+ },
42
+ },
43
+ );
44
+ }
@@ -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 { OsdkObject } from "#ontology";
18
+
19
+ export interface PageResult<T extends OsdkObject<any>> {
20
+ data: T[];
21
+ nextPageToken: string | undefined;
22
+ }
@@ -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
+ export class PalantirApiError extends Error implements PalantirApiError {
18
+ public message: string;
19
+ public errorName?: string;
20
+ public errorType?: string;
21
+ public statusCode?: number;
22
+ public errorInstanceId?: string;
23
+ public parameters?: any;
24
+
25
+ constructor(
26
+ message: string,
27
+ errorName?: string,
28
+ errorType?: string,
29
+ statusCode?: number,
30
+ errorInstanceId?: string,
31
+ parameters?: any,
32
+ ) {
33
+ super(message);
34
+ this.message = message;
35
+ this.errorName = errorName;
36
+ this.errorType = errorType;
37
+ this.statusCode = statusCode;
38
+ this.errorInstanceId = errorInstanceId;
39
+ this.parameters = parameters;
40
+ }
41
+ }
@@ -0,0 +1,23 @@
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 type ResultOrError<T extends object> =
18
+ | ({ type: "ok"; err?: never } & T)
19
+ | { type: "err"; data?: never; err?: unknown };
20
+
21
+ export function isOk(result: ResultOrError<any>): result is { type: "ok" } {
22
+ return result.type === "ok";
23
+ }
@@ -0,0 +1,31 @@
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 * as ontology from "#ontology";
18
+ import type { FetchAsJsonFn } from "#util";
19
+
20
+ export interface ThinClient<O extends ontology.OntologyDefinition<any>> {
21
+ ontology: O;
22
+ stack: string;
23
+ /**
24
+ * The fetch function to use for all requests.
25
+ *
26
+ * TODO: Document what is needed to get retry logic
27
+ */
28
+ fetch: typeof globalThis.fetch;
29
+
30
+ fetchJson: FetchAsJsonFn;
31
+ }
@@ -0,0 +1,25 @@
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 { PalantirApiError } from "./PalantirApiError";
18
+
19
+ export class UnknownError extends PalantirApiError {
20
+ originalError: Error | undefined;
21
+ constructor(message: string, errorType: string, originalError?: Error) {
22
+ super(message, errorType);
23
+ this.originalError = originalError;
24
+ }
25
+ }
@@ -0,0 +1,49 @@
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 type { Client } from "./Client";
19
+ import { createThinClient } from "./createThinClient";
20
+ import { createObjectSet } from "./objectSet/createObjectSet";
21
+ import type { ObjectSetFactory } from "./objectSet/ObjectSet";
22
+ import { createObjectSetCreator } from "./ObjectSetCreator";
23
+
24
+ export function createClient<O extends OntologyDefinition<any>>(
25
+ ontology: O,
26
+ stack: string,
27
+ tokenProvider: () => string,
28
+ fetchFn: typeof globalThis.fetch = fetch,
29
+ ): Client<O> {
30
+ const thinClient = createThinClient<O>(
31
+ ontology,
32
+ stack,
33
+ tokenProvider,
34
+ fetchFn,
35
+ );
36
+
37
+ const objectSetFactory: ObjectSetFactory<O> = (type, opts) =>
38
+ createObjectSet(type, thinClient, opts);
39
+
40
+ const client: Client<O> = Object.defineProperties(
41
+ {} as Client<O>,
42
+ {
43
+ objectSet: { get: () => objectSetFactory },
44
+ objects: { get: () => createObjectSetCreator(client) },
45
+ } satisfies Record<keyof Client<any>, PropertyDescriptor>,
46
+ );
47
+
48
+ return client;
49
+ }
@@ -0,0 +1,52 @@
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 {
19
+ createFetchAsJson,
20
+ createFetchHeaderMutator,
21
+ createFetchOrThrow,
22
+ createRetryingFetch,
23
+ } from "#util";
24
+ import type { ThinClient } from "./ThinClient";
25
+
26
+ /**
27
+ * The goal of the thin client is to provide a way to tree shake as much as possible.
28
+ */
29
+
30
+ export function createThinClient<T extends OntologyDefinition<any>>(
31
+ ontology: T,
32
+ stack: string,
33
+ tokenProvider: () => string,
34
+ fetchFn: typeof globalThis.fetch = fetch,
35
+ ): ThinClient<T> {
36
+ const retryingFetchWithAuthOrThrow = createFetchHeaderMutator(
37
+ createRetryingFetch(createFetchOrThrow(fetchFn)),
38
+ async (headers) => {
39
+ const token = await tokenProvider();
40
+ headers.set("Authorization", `Bearer ${token}`);
41
+ headers.set("Fetch-User-Agent", ontology.metadata.userAgent);
42
+ return headers;
43
+ },
44
+ );
45
+
46
+ return {
47
+ ontology,
48
+ stack,
49
+ fetch: retryingFetchWithAuthOrThrow,
50
+ fetchJson: createFetchAsJson(retryingFetchWithAuthOrThrow),
51
+ };
52
+ }
@@ -0,0 +1,24 @@
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 type { Client } from "./Client";
18
+ export { createClient } from "./createClient";
19
+ export { createThinClient } from "./createThinClient";
20
+ export type { ObjectSet } from "./objectSet/ObjectSet";
21
+ export type { PageResult } from "./PageResult";
22
+ export { isOk } from "./ResultOrError";
23
+ export type { ResultOrError } from "./ResultOrError";
24
+ export type { ThinClient } from "./ThinClient";
@@ -0,0 +1,20 @@
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 { legacyToModernSingleAggregationResult } from "./legacyToModernSingleAggregationResult";
18
+ export { modernToLegacyAggregationClause } from "./modernToLegacyAggregationClause";
19
+ export { modernToLegacyGroupByClause } from "./modernToLegacyGroupByClause";
20
+ export { modernToLegacyWhereClause } from "./modernToLegacyWhereClause";
@@ -0,0 +1,46 @@
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
+ AggregationResultsWithoutGroups,
20
+ } from "#client/query";
21
+ import type { Wire } from "#net";
22
+ import type { ArrayElement } from "#util";
23
+ import invariant from "tiny-invariant";
24
+
25
+ export function legacyToModernSingleAggregationResult<
26
+ AC extends AggregationClause<any, any>,
27
+ >(
28
+ entry: ArrayElement<Wire.AggregateObjectsResponseV2["data"]>,
29
+ ): AggregationResultsWithoutGroups<any, any, AC> {
30
+ return entry.metrics.reduce(
31
+ (accumulator, curValue) => {
32
+ const parts = curValue.name.split(".");
33
+ invariant(
34
+ parts.length == 2,
35
+ "assumed we were getting a `${key}.${type}`",
36
+ );
37
+ if (!(parts[0] in accumulator)) {
38
+ accumulator[parts[0]] = {};
39
+ }
40
+ accumulator[parts[0]][parts[1]] = curValue.value;
41
+
42
+ return accumulator;
43
+ },
44
+ {} as AggregationResultsWithoutGroups<any, any, any>,
45
+ );
46
+ }
@@ -0,0 +1,45 @@
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 { AggregationClause } from "#client/query";
18
+ import type { Wire } from "#net";
19
+ import type { ObjectTypesFrom, OntologyDefinition } from "#ontology";
20
+
21
+ export function modernToLegacyAggregationClause<
22
+ T extends OntologyDefinition<any>,
23
+ K extends ObjectTypesFrom<T>,
24
+ AC extends AggregationClause<T, K>,
25
+ >(select: AC) {
26
+ return Object.entries(select).flatMap<Wire.AggregationClause>(([k, v]) => {
27
+ if (Array.isArray(v)) {
28
+ return (v as string[]).map((v2) => {
29
+ return {
30
+ type: v2,
31
+ name: `${k}.${v2}`,
32
+ field: k,
33
+ };
34
+ });
35
+ } else {
36
+ return [
37
+ {
38
+ type: v as string,
39
+ name: `${k}.${v}`,
40
+ field: k,
41
+ },
42
+ ];
43
+ }
44
+ });
45
+ }
@@ -0,0 +1,44 @@
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 { AllGroupByValues, GroupByClause } from "#client/query";
18
+ import type { Wire } from "#net";
19
+ import type { ObjectTypesFrom, OntologyDefinition } from "#ontology";
20
+
21
+ export function modernToLegacyGroupByClause<
22
+ O extends OntologyDefinition<any>,
23
+ K extends ObjectTypesFrom<O>,
24
+ >(groupByClause: GroupByClause<O, K> | undefined) {
25
+ if (!groupByClause) return undefined;
26
+
27
+ return Object.entries(
28
+ groupByClause as Record<string, AllGroupByValues>,
29
+ ).flatMap<Wire.GroupByClause>(([field, type]) => {
30
+ if (type === "exact") {
31
+ return [{ type, field }];
32
+ } else if (type.exactWithLimit) {
33
+ return [
34
+ {
35
+ type: "exact",
36
+ field,
37
+ maxGroupCount: type.exactWithLimit,
38
+ },
39
+ ];
40
+ } else {
41
+ return [];
42
+ }
43
+ });
44
+ }