@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.
- package/.eslintrc.cjs +4 -0
- package/.turbo/turbo-build.log +26 -0
- package/.turbo/turbo-lint.log +4 -0
- package/CHANGELOG.md +7 -0
- package/dist/chunk-TTS63OIX.mjs +7 -0
- package/dist/chunk-TTS63OIX.mjs.map +1 -0
- package/dist/chunk-ZJRKQTOR.js +16 -0
- package/dist/chunk-ZJRKQTOR.js.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +9 -0
- package/dist/index.mjs.map +1 -0
- package/dist/public/objects.js +16 -0
- package/dist/public/objects.js.map +1 -0
- package/dist/public/objects.mjs +3 -0
- package/dist/public/objects.mjs.map +1 -0
- package/lib/client/Client.d.ts +8 -0
- package/lib/client/ObjectSetCreator.d.ts +15 -0
- package/lib/client/PageResult.d.ts +5 -0
- package/lib/client/PalantirApiError.d.ts +9 -0
- package/lib/client/ResultOrError.d.ts +11 -0
- package/lib/client/ThinClient.d.ts +13 -0
- package/lib/client/UnknownError.d.ts +5 -0
- package/lib/client/createClient.d.ts +3 -0
- package/lib/client/createThinClient.d.ts +6 -0
- package/lib/client/index.d.ts +8 -0
- package/lib/client/internal/conversions/index.d.ts +4 -0
- package/lib/client/internal/conversions/legacyToModernSingleAggregationResult.d.ts +4 -0
- package/lib/client/internal/conversions/modernToLegacyAggregationClause.d.ts +4 -0
- package/lib/client/internal/conversions/modernToLegacyGroupByClause.d.ts +4 -0
- package/lib/client/internal/conversions/modernToLegacyWhereClause.d.ts +4 -0
- package/lib/client/internal/net/V2_BASE.d.ts +1 -0
- package/lib/client/internal/net/aggregateObjectsV2.d.ts +3 -0
- package/lib/client/internal/net/index.d.ts +3 -0
- package/lib/client/internal/net/listObjectsFromObjectSetV2.d.ts +3 -0
- package/lib/client/internal/net/types.d.ts +357 -0
- package/lib/client/object/aggregateOrThrow.d.ts +5 -0
- package/lib/client/object/aggregateOrThrow.test.d.ts +2 -0
- package/lib/client/object/fetchPageOrThrow.d.ts +10 -0
- package/lib/client/object/index.d.ts +2 -0
- package/lib/client/objectSet/LinkTypesFrom.d.ts +2 -0
- package/lib/client/objectSet/ObjectSet.d.ts +25 -0
- package/lib/client/objectSet/createObjectSet.d.ts +5 -0
- package/lib/client/query/WhereClause.d.ts +24 -0
- package/lib/client/query/aggregations/AggregatableKeys.d.ts +4 -0
- package/lib/client/query/aggregations/AggregateOpts.d.ts +7 -0
- package/lib/client/query/aggregations/AggregationResultsWithGroups.d.ts +10 -0
- package/lib/client/query/aggregations/AggregationResultsWithoutGroups.d.ts +8 -0
- package/lib/client/query/aggregations/AggregationsClause.d.ts +8 -0
- package/lib/client/query/aggregations/AggregationsClause.test.d.ts +36 -0
- package/lib/client/query/aggregations/AggregationsResults.d.ts +5 -0
- package/lib/client/query/aggregations/AggregationsResults.test.d.ts +1 -0
- package/lib/client/query/aggregations/GroupByClause.d.ts +12 -0
- package/lib/client/query/aggregations/GroupByClause.test.d.ts +18 -0
- package/lib/client/query/aggregations/GroupByMapper.d.ts +4 -0
- package/lib/client/query/index.d.ts +7 -0
- package/lib/index.d.ts +6 -0
- package/lib/ontology/Definition.d.ts +36 -0
- package/lib/ontology/OntologyMetadata.d.ts +5 -0
- package/lib/ontology/OsdkObject.d.ts +3 -0
- package/lib/ontology/OsdkObjectFrom.d.ts +6 -0
- package/lib/ontology/index.d.ts +4 -0
- package/lib/public/objects.d.ts +1 -0
- package/lib/util/ArrayElement.d.ts +1 -0
- package/lib/util/FetchAsJson.d.ts +15 -0
- package/lib/util/NOOP.d.ts +3 -0
- package/lib/util/StringArrayToUnion.d.ts +1 -0
- package/lib/util/createFetchHeaderMutator.d.ts +1 -0
- package/lib/util/createFetchOrThrow.d.ts +9 -0
- package/lib/util/createRetryingFetch.d.ts +2 -0
- package/lib/util/index.d.ts +9 -0
- package/lib/util/stringifyBody.d.ts +1 -0
- package/package.json +46 -0
- package/src/client/Client.ts +33 -0
- package/src/client/ObjectSetCreator.ts +44 -0
- package/src/client/PageResult.ts +22 -0
- package/src/client/PalantirApiError.ts +41 -0
- package/src/client/ResultOrError.ts +23 -0
- package/src/client/ThinClient.ts +31 -0
- package/src/client/UnknownError.ts +25 -0
- package/src/client/createClient.ts +49 -0
- package/src/client/createThinClient.ts +52 -0
- package/src/client/index.ts +24 -0
- package/src/client/internal/conversions/index.ts +20 -0
- package/src/client/internal/conversions/legacyToModernSingleAggregationResult.ts +46 -0
- package/src/client/internal/conversions/modernToLegacyAggregationClause.ts +45 -0
- package/src/client/internal/conversions/modernToLegacyGroupByClause.ts +44 -0
- package/src/client/internal/conversions/modernToLegacyWhereClause.ts +135 -0
- package/src/client/internal/net/V2_BASE.ts +17 -0
- package/src/client/internal/net/aggregateObjectsV2.ts +37 -0
- package/src/client/internal/net/index.ts +19 -0
- package/src/client/internal/net/listObjectsFromObjectSetV2.ts +41 -0
- package/src/client/internal/net/types.ts +302 -0
- package/src/client/object/aggregateOrThrow.test.ts +137 -0
- package/src/client/object/aggregateOrThrow.ts +87 -0
- package/src/client/object/fetchPageOrThrow.ts +83 -0
- package/src/client/object/index.ts +18 -0
- package/src/client/objectSet/LinkTypesFrom.ts +22 -0
- package/src/client/objectSet/ObjectSet.ts +92 -0
- package/src/client/objectSet/createObjectSet.ts +130 -0
- package/src/client/query/WhereClause.ts +68 -0
- package/src/client/query/aggregations/AggregatableKeys.ts +37 -0
- package/src/client/query/aggregations/AggregateOpts.ts +36 -0
- package/src/client/query/aggregations/AggregationResultsWithGroups.ts +40 -0
- package/src/client/query/aggregations/AggregationResultsWithoutGroups.ts +37 -0
- package/src/client/query/aggregations/AggregationsClause.test.ts +60 -0
- package/src/client/query/aggregations/AggregationsClause.ts +44 -0
- package/src/client/query/aggregations/AggregationsResults.test.ts +74 -0
- package/src/client/query/aggregations/AggregationsResults.ts +30 -0
- package/src/client/query/aggregations/GroupByClause.test.ts +38 -0
- package/src/client/query/aggregations/GroupByClause.ts +41 -0
- package/src/client/query/aggregations/GroupByMapper.ts +21 -0
- package/src/client/query/index.ts +32 -0
- package/src/index.ts +28 -0
- package/src/ontology/Definition.ts +89 -0
- package/src/ontology/OntologyMetadata.ts +21 -0
- package/src/ontology/OsdkObject.ts +17 -0
- package/src/ontology/OsdkObjectFrom.ts +33 -0
- package/src/ontology/index.ts +20 -0
- package/src/public/objects.ts +17 -0
- package/src/util/ArrayElement.ts +18 -0
- package/src/util/FetchAsJson.ts +55 -0
- package/src/util/NOOP.ts +21 -0
- package/src/util/StringArrayToUnion.ts +18 -0
- package/src/util/createFetchHeaderMutator.ts +34 -0
- package/src/util/createFetchOrThrow.ts +71 -0
- package/src/util/createRetryingFetch.ts +55 -0
- package/src/util/index.ts +25 -0
- package/src/util/stringifyBody.ts +21 -0
- package/tsconfig.json +5 -0
- 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
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
|
+
);
|