@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,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 type StringArrayToUnion<T extends string | readonly string[]> = T extends
18
+ ReadonlyArray<infer U> ? U : T;
@@ -0,0 +1,34 @@
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 function createFetchHeaderMutator(
18
+ fetchFn: typeof fetch = fetch,
19
+ mutator: (headers: Headers) => Promise<Headers> | Headers,
20
+ ): typeof fetch {
21
+ return async function headerMutatedFetch(
22
+ url: RequestInfo | URL,
23
+ requestInit?: RequestInit,
24
+ ) {
25
+ if (!requestInit) {
26
+ return fetchFn(url, { headers: await mutator(new Headers()) });
27
+ }
28
+
29
+ return fetchFn(url, {
30
+ ...requestInit,
31
+ headers: await mutator(new Headers(requestInit.headers)),
32
+ });
33
+ };
34
+ }
@@ -0,0 +1,71 @@
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 "../client/PalantirApiError";
18
+ import { UnknownError } from "../client/UnknownError";
19
+
20
+ /**
21
+ * Wraps a fetch plugin so that all errors (including when statusCode is not in the 200s) are converted to either PalantirApiError or UnknownError.
22
+ *
23
+ * If the returned promise does not have an error state, you are free to immediately call `.json()` or equivalent.
24
+ *
25
+ * @param fetchFn
26
+ * @returns
27
+ */
28
+ export function createFetchOrThrow(fetchFn: typeof fetch = fetch) {
29
+ return async function fetchOrThrow(
30
+ url: RequestInfo | URL,
31
+ requestInit?: RequestInit,
32
+ ) {
33
+ let response;
34
+
35
+ try {
36
+ response = await fetchFn(url, requestInit);
37
+ } catch (e) {
38
+ throw convertError(e, "A network error occured");
39
+ }
40
+
41
+ if (!response.ok) {
42
+ let body;
43
+ try {
44
+ body = await response.json();
45
+ } catch (e) {
46
+ throw convertError(e, "A network error occured while reading response");
47
+ }
48
+
49
+ throw new PalantirApiError(
50
+ body?.message
51
+ ?? `Failed to fetch ${response.status} ${response.statusText}`,
52
+ body?.errorName,
53
+ body?.errorCode,
54
+ response.status,
55
+ body?.errorInstanceId,
56
+ body?.parameters,
57
+ );
58
+ }
59
+ return response;
60
+ };
61
+ }
62
+
63
+ function convertError(
64
+ e: any,
65
+ msgIfNotError: string = "An unknown error occurred",
66
+ ) {
67
+ if (e instanceof Error) {
68
+ return new UnknownError(e.message, "UNKNOWN", e);
69
+ }
70
+ return new UnknownError(msgIfNotError, "UNKNOWN");
71
+ }
@@ -0,0 +1,55 @@
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 fetchRetry from "fetch-retry";
18
+ import { PalantirApiError } from "../client/PalantirApiError";
19
+
20
+ const INITIAL_DELAY = 1_000;
21
+ const JITTER_FACTOR = 0.5;
22
+ const MAX_RETRIES = 3;
23
+
24
+ export function createRetryingFetch(fetch: typeof globalThis.fetch) {
25
+ return fetchRetry(fetch, {
26
+ retryDelay(attempt) {
27
+ const delay = INITIAL_DELAY * 2 ** attempt;
28
+ const jitter = delay * JITTER_FACTOR * (Math.random() * 2 - 1);
29
+ return delay + jitter;
30
+ },
31
+ retryOn(attempt, error, response) {
32
+ const status = response?.status ?? 0;
33
+ return (
34
+ !(status >= 200 && status < 300)
35
+ && isRetryable(error)
36
+ && attempt < MAX_RETRIES
37
+ );
38
+ },
39
+ });
40
+ }
41
+
42
+ function isRetryable(e: any): boolean {
43
+ if (e instanceof PalantirApiError) {
44
+ if (
45
+ e.statusCode !== SERVICE_UNAVAILABLE
46
+ && e.statusCode !== TOO_MANY_REQUESTS
47
+ ) {
48
+ return false;
49
+ }
50
+ }
51
+ return true; // I think this logic is flawed?
52
+ }
53
+
54
+ const SERVICE_UNAVAILABLE = 503;
55
+ const TOO_MANY_REQUESTS = 429;
@@ -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
+ export type { ArrayElement } from "./ArrayElement";
18
+ export { createFetchHeaderMutator } from "./createFetchHeaderMutator";
19
+ export { createFetchOrThrow } from "./createFetchOrThrow";
20
+ export { createRetryingFetch } from "./createRetryingFetch";
21
+ export { createFetchAsJson } from "./FetchAsJson";
22
+ export type { FetchAsJsonFn } from "./FetchAsJson";
23
+ export type { NOOP } from "./NOOP";
24
+ export type { StringArrayToUnion } from "./StringArrayToUnion";
25
+ export { stringifyBody } from "./stringifyBody";
@@ -0,0 +1,21 @@
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 function stringifyBody(
18
+ body: object | undefined,
19
+ ): BodyInit | null | undefined {
20
+ return body != null ? JSON.stringify(body) : undefined;
21
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "extends": "tsconfig/base",
3
+ "compilerOptions": { "rootDir": "src", "outDir": "lib" },
4
+ "include": ["./src/**/*", ".eslintrc.cjs"]
5
+ }
package/tsup.config.js ADDED
@@ -0,0 +1,21 @@
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 { defineConfig } from "tsup";
18
+
19
+ export default defineConfig(async (options) =>
20
+ (await import("mytsup")).default(options)
21
+ );