@osdk/api 0.0.4 → 0.0.6
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/CHANGELOG.md +16 -0
- package/build/js/chunk-4D6JZ4TL.js +7 -0
- package/build/js/chunk-4D6JZ4TL.js.map +1 -0
- package/build/js/chunk-BZ6L26S2.mjs +7 -0
- package/build/js/chunk-BZ6L26S2.mjs.map +1 -0
- package/build/js/chunk-SHYKLQMU.js +15 -0
- package/build/js/chunk-SHYKLQMU.js.map +1 -0
- package/build/js/chunk-SM47N47Q.js +19 -0
- package/build/js/chunk-SM47N47Q.js.map +1 -0
- package/build/js/chunk-TPXDMNRT.mjs +9 -0
- package/build/js/chunk-TPXDMNRT.mjs.map +1 -0
- package/build/js/chunk-XIJ2ZQRX.mjs +5 -0
- package/build/js/chunk-XIJ2ZQRX.mjs.map +1 -0
- package/build/js/index.js +11 -10
- package/build/js/index.js.map +1 -1
- package/build/js/index.mjs +6 -5
- package/build/js/index.mjs.map +1 -1
- package/build/js/public/objects.js +4 -3
- package/build/js/public/objects.mjs +2 -1
- package/build/js/public/utils.js +17 -0
- package/build/js/public/utils.js.map +1 -0
- package/build/js/public/utils.mjs +4 -0
- package/build/js/public/utils.mjs.map +1 -0
- package/build/types/client/Client.d.ts +1 -1
- package/build/types/client/ObjectSetCreator.d.ts +1 -1
- package/build/types/client/PageResult.d.ts +1 -1
- package/build/types/client/ThinClient.d.ts +2 -2
- package/build/types/client/createClient.d.ts +2 -2
- package/build/types/client/createOpenApiRequest.d.ts +2 -0
- package/build/types/client/createThinClient.d.ts +2 -2
- package/build/types/client/internal/conversions/legacyToModernSingleAggregationResult.d.ts +3 -3
- package/build/types/client/internal/conversions/modernToLegacyAggregationClause.d.ts +2 -2
- package/build/types/client/internal/conversions/modernToLegacyGroupByClause.d.ts +2 -2
- package/build/types/client/internal/conversions/modernToLegacyWhereClause.d.ts +3 -3
- package/build/types/client/internal/net/index.d.ts +0 -1
- package/build/types/client/object/aggregateOrThrow.d.ts +3 -3
- package/build/types/client/object/fetchPageOrThrow.d.ts +4 -4
- package/build/types/client/objectSet/LinkTypesFrom.d.ts +2 -2
- package/build/types/client/objectSet/ObjectSet.d.ts +5 -5
- package/build/types/client/objectSet/createObjectSet.d.ts +3 -3
- package/build/types/client/query/WhereClause.d.ts +1 -1
- package/build/types/client/query/aggregations/AggregatableKeys.d.ts +1 -1
- package/build/types/client/query/aggregations/AggregateOpts.d.ts +2 -2
- package/build/types/client/query/aggregations/AggregationResultsWithGroups.d.ts +1 -1
- package/build/types/client/query/aggregations/AggregationResultsWithoutGroups.d.ts +2 -2
- package/build/types/client/query/aggregations/AggregationsClause.d.ts +1 -1
- package/build/types/client/query/aggregations/AggregationsClause.test.d.ts +6 -0
- package/build/types/client/query/aggregations/AggregationsResults.d.ts +1 -1
- package/build/types/client/query/aggregations/GroupByClause.d.ts +1 -1
- package/build/types/client/query/aggregations/GroupByClause.test.d.ts +3 -0
- package/build/types/index.d.ts +6 -3
- package/build/types/ontology/ActionDefinition.d.ts +36 -0
- package/build/types/ontology/Definition.d.ts +36 -8
- package/build/types/ontology/OsdkObjectFrom.d.ts +3 -3
- package/build/types/ontology/QueryDefinition.d.ts +77 -0
- package/build/types/ontology/index.d.ts +2 -0
- package/build/types/public/utils.d.ts +2 -0
- package/package.json +3 -9
- package/build/js/chunk-I3UIWCJ4.js +0 -17
- package/build/js/chunk-I3UIWCJ4.js.map +0 -1
- package/build/js/chunk-II7ELH2S.mjs +0 -8
- package/build/js/chunk-II7ELH2S.mjs.map +0 -1
- package/build/types/client/internal/net/createOpenApiRequest.d.ts +0 -2
- /package/build/types/client/{internal/net/createOpenApiRequest.test.d.ts → createOpenApiRequest.test.d.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @osdk/api
|
|
2
2
|
|
|
3
|
+
## 0.0.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 90cc3ae: Adding Object, Object Set, Attachments, and Actions implementations for OSDK V1.1
|
|
8
|
+
- Updated dependencies [90cc3ae]
|
|
9
|
+
- @osdk/gateway@0.0.2
|
|
10
|
+
|
|
11
|
+
## 0.0.5
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- d2e9964: Removing subpath imports since TS does not resolve them when creating `.d.ts` files
|
|
16
|
+
- Updated dependencies [d2e9964]
|
|
17
|
+
- @osdk/gateway@0.0.1
|
|
18
|
+
|
|
3
19
|
## 0.0.4
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import i from 'fetch-retry';
|
|
2
|
+
|
|
3
|
+
function R(t=fetch,e){return async function(r,s){return s?t(r,{...s,headers:await e(new Headers(s.headers))}):t(r,{headers:await e(new Headers)})}}var a=class extends Error{constructor(e,n,r,s,o,c){super(e),this.message=e,this.errorName=n,this.errorType=r,this.statusCode=s,this.errorInstanceId=o,this.parameters=c;}};var u=1e3,d=.5,h=3;function _(t){return i(t,{retryDelay(e){let n=u*2**e,r=n*d*(Math.random()*2-1);return n+r},retryOn(e,n,r){let s=r?.status??0;return !(s>=200&&s<300)&&f(n)&&e<h}})}function f(t){return !(t instanceof a&&t.statusCode!==E&&t.statusCode!==y)}var E=503,y=429;
|
|
4
|
+
|
|
5
|
+
export { R as a, a as b, _ as c };
|
|
6
|
+
//# sourceMappingURL=out.js.map
|
|
7
|
+
//# sourceMappingURL=chunk-BZ6L26S2.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/createFetchHeaderMutator.ts","../../src/util/createRetryingFetch.ts","../../src/client/PalantirApiError.ts"],"names":["createFetchHeaderMutator","fetchFn","mutator","url","requestInit","fetchRetry","PalantirApiError","message","errorName","errorType","statusCode","errorInstanceId","parameters","INITIAL_DELAY","JITTER_FACTOR","MAX_RETRIES","createRetryingFetch","fetch","attempt","delay","jitter","error","response","status","isRetryable","e","SERVICE_UNAVAILABLE","TOO_MANY_REQUESTS"],"mappings":"AAgBO,SAASA,EAAyBC,EAAU,MAAOC,EAAS,CACjE,OAAO,eAAkCC,EAAKC,EAAa,CACzD,OAAKA,EAKEH,EAAQE,EAAK,CAClB,GAAGC,EACH,QAAS,MAAMF,EAAQ,IAAI,QAAQE,EAAY,OAAO,CAAC,CACzD,CAAC,EAPQH,EAAQE,EAAK,CAClB,QAAS,MAAMD,EAAQ,IAAI,OAAS,CACtC,CAAC,CAML,CACF,CCZA,OAAOG,MAAgB,cCAhB,IAAMC,EAAN,cAA+B,KAAM,CAC1C,YAAYC,EAASC,EAAWC,EAAWC,EAAYC,EAAiBC,EAAY,CAClF,MAAML,CAAO,EACb,KAAK,QAAUA,EACf,KAAK,UAAYC,EACjB,KAAK,UAAYC,EACjB,KAAK,WAAaC,EAClB,KAAK,gBAAkBC,EACvB,KAAK,WAAaC,CACpB,CACF,EDRA,IAAMC,EAAgB,IAChBC,EAAgB,GAChBC,EAAc,EACb,SAASC,EAAoBC,EAAO,CACzC,OAAOZ,EAAWY,EAAO,CACvB,WAAWC,EAAS,CAClB,IAAMC,EAAQN,EAAgB,GAAKK,EAC7BE,EAASD,EAAQL,GAAiB,KAAK,OAAO,EAAI,EAAI,GAC5D,OAAOK,EAAQC,CACjB,EACA,QAAQF,EAASG,EAAOC,EAAU,CAChC,IAAMC,EAASD,GAAU,QAAU,EACnC,MAAO,EAAEC,GAAU,KAAOA,EAAS,MAAQC,EAAYH,CAAK,GAAKH,EAAUH,CAC7E,CACF,CAAC,CACH,CACA,SAASS,EAAYC,EAAG,CACtB,MAAI,EAAAA,aAAanB,GACXmB,EAAE,aAAeC,GAAuBD,EAAE,aAAeE,EAKjE,CAEA,IAAMD,EAAsB,IACtBC,EAAoB","sourcesContent":["/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport function createFetchHeaderMutator(fetchFn = fetch, mutator) {\n return async function headerMutatedFetch(url, requestInit) {\n if (!requestInit) {\n return fetchFn(url, {\n headers: await mutator(new Headers())\n });\n }\n return fetchFn(url, {\n ...requestInit,\n headers: await mutator(new Headers(requestInit.headers))\n });\n };\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport fetchRetry from \"fetch-retry\";\nimport { PalantirApiError } from \"../client/PalantirApiError\";\nconst INITIAL_DELAY = 1_000;\nconst JITTER_FACTOR = 0.5;\nconst MAX_RETRIES = 3;\nexport function createRetryingFetch(fetch) {\n return fetchRetry(fetch, {\n retryDelay(attempt) {\n const delay = INITIAL_DELAY * 2 ** attempt;\n const jitter = delay * JITTER_FACTOR * (Math.random() * 2 - 1);\n return delay + jitter;\n },\n retryOn(attempt, error, response) {\n const status = response?.status ?? 0;\n return !(status >= 200 && status < 300) && isRetryable(error) && attempt < MAX_RETRIES;\n }\n });\n}\nfunction isRetryable(e) {\n if (e instanceof PalantirApiError) {\n if (e.statusCode !== SERVICE_UNAVAILABLE && e.statusCode !== TOO_MANY_REQUESTS) {\n return false;\n }\n }\n return true; // I think this logic is flawed?\n}\n\nconst SERVICE_UNAVAILABLE = 503;\nconst TOO_MANY_REQUESTS = 429;","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport class PalantirApiError extends Error {\n constructor(message, errorName, errorType, statusCode, errorInstanceId, parameters) {\n super(message);\n this.message = message;\n this.errorName = errorName;\n this.errorType = errorType;\n this.statusCode = statusCode;\n this.errorInstanceId = errorInstanceId;\n this.parameters = parameters;\n }\n}"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var i = require('fetch-retry');
|
|
4
|
+
|
|
5
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
6
|
+
|
|
7
|
+
var i__default = /*#__PURE__*/_interopDefault(i);
|
|
8
|
+
|
|
9
|
+
function R(t=fetch,e){return async function(r,s){return s?t(r,{...s,headers:await e(new Headers(s.headers))}):t(r,{headers:await e(new Headers)})}}var a=class extends Error{constructor(e,n,r,s,o,c){super(e),this.message=e,this.errorName=n,this.errorType=r,this.statusCode=s,this.errorInstanceId=o,this.parameters=c;}};var u=1e3,d=.5,h=3;function _(t){return i__default.default(t,{retryDelay(e){let n=u*2**e,r=n*d*(Math.random()*2-1);return n+r},retryOn(e,n,r){let s=r?.status??0;return !(s>=200&&s<300)&&f(n)&&e<h}})}function f(t){return !(t instanceof a&&t.statusCode!==E&&t.statusCode!==y)}var E=503,y=429;
|
|
10
|
+
|
|
11
|
+
exports.a = R;
|
|
12
|
+
exports.b = a;
|
|
13
|
+
exports.c = _;
|
|
14
|
+
//# sourceMappingURL=out.js.map
|
|
15
|
+
//# sourceMappingURL=chunk-SHYKLQMU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/createFetchHeaderMutator.ts","../../src/util/createRetryingFetch.ts","../../src/client/PalantirApiError.ts"],"names":["createFetchHeaderMutator","fetchFn","mutator","url","requestInit","fetchRetry","PalantirApiError","message","errorName","errorType","statusCode","errorInstanceId","parameters","INITIAL_DELAY","JITTER_FACTOR","MAX_RETRIES","createRetryingFetch","fetch","attempt","delay","jitter","error","response","status","isRetryable","e","SERVICE_UNAVAILABLE","TOO_MANY_REQUESTS"],"mappings":"AAgBO,SAASA,EAAyBC,EAAU,MAAOC,EAAS,CACjE,OAAO,eAAkCC,EAAKC,EAAa,CACzD,OAAKA,EAKEH,EAAQE,EAAK,CAClB,GAAGC,EACH,QAAS,MAAMF,EAAQ,IAAI,QAAQE,EAAY,OAAO,CAAC,CACzD,CAAC,EAPQH,EAAQE,EAAK,CAClB,QAAS,MAAMD,EAAQ,IAAI,OAAS,CACtC,CAAC,CAML,CACF,CCZA,OAAOG,MAAgB,cCAhB,IAAMC,EAAN,cAA+B,KAAM,CAC1C,YAAYC,EAASC,EAAWC,EAAWC,EAAYC,EAAiBC,EAAY,CAClF,MAAML,CAAO,EACb,KAAK,QAAUA,EACf,KAAK,UAAYC,EACjB,KAAK,UAAYC,EACjB,KAAK,WAAaC,EAClB,KAAK,gBAAkBC,EACvB,KAAK,WAAaC,CACpB,CACF,EDRA,IAAMC,EAAgB,IAChBC,EAAgB,GAChBC,EAAc,EACb,SAASC,EAAoBC,EAAO,CACzC,OAAOZ,EAAWY,EAAO,CACvB,WAAWC,EAAS,CAClB,IAAMC,EAAQN,EAAgB,GAAKK,EAC7BE,EAASD,EAAQL,GAAiB,KAAK,OAAO,EAAI,EAAI,GAC5D,OAAOK,EAAQC,CACjB,EACA,QAAQF,EAASG,EAAOC,EAAU,CAChC,IAAMC,EAASD,GAAU,QAAU,EACnC,MAAO,EAAEC,GAAU,KAAOA,EAAS,MAAQC,EAAYH,CAAK,GAAKH,EAAUH,CAC7E,CACF,CAAC,CACH,CACA,SAASS,EAAYC,EAAG,CACtB,MAAI,EAAAA,aAAanB,GACXmB,EAAE,aAAeC,GAAuBD,EAAE,aAAeE,EAKjE,CAEA,IAAMD,EAAsB,IACtBC,EAAoB","sourcesContent":["/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport function createFetchHeaderMutator(fetchFn = fetch, mutator) {\n return async function headerMutatedFetch(url, requestInit) {\n if (!requestInit) {\n return fetchFn(url, {\n headers: await mutator(new Headers())\n });\n }\n return fetchFn(url, {\n ...requestInit,\n headers: await mutator(new Headers(requestInit.headers))\n });\n };\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport fetchRetry from \"fetch-retry\";\nimport { PalantirApiError } from \"../client/PalantirApiError\";\nconst INITIAL_DELAY = 1_000;\nconst JITTER_FACTOR = 0.5;\nconst MAX_RETRIES = 3;\nexport function createRetryingFetch(fetch) {\n return fetchRetry(fetch, {\n retryDelay(attempt) {\n const delay = INITIAL_DELAY * 2 ** attempt;\n const jitter = delay * JITTER_FACTOR * (Math.random() * 2 - 1);\n return delay + jitter;\n },\n retryOn(attempt, error, response) {\n const status = response?.status ?? 0;\n return !(status >= 200 && status < 300) && isRetryable(error) && attempt < MAX_RETRIES;\n }\n });\n}\nfunction isRetryable(e) {\n if (e instanceof PalantirApiError) {\n if (e.statusCode !== SERVICE_UNAVAILABLE && e.statusCode !== TOO_MANY_REQUESTS) {\n return false;\n }\n }\n return true; // I think this logic is flawed?\n}\n\nconst SERVICE_UNAVAILABLE = 503;\nconst TOO_MANY_REQUESTS = 429;","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport class PalantirApiError extends Error {\n constructor(message, errorName, errorType, statusCode, errorInstanceId, parameters) {\n super(message);\n this.message = message;\n this.errorName = errorName;\n this.errorType = errorType;\n this.statusCode = statusCode;\n this.errorInstanceId = errorInstanceId;\n this.parameters = parameters;\n }\n}"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk4D6JZ4TL_js = require('./chunk-4D6JZ4TL.js');
|
|
4
|
+
var requests = require('@osdk/gateway/requests');
|
|
5
|
+
var a = require('tiny-invariant');
|
|
6
|
+
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var a__default = /*#__PURE__*/_interopDefault(a);
|
|
10
|
+
|
|
11
|
+
function g(n,o,e="/api",t){return async function(u,s,w,A,E,O,l){let y=new URL(`${e}${s}`,B(n));for(let[f,i]of Object.entries(A||{}))if(Array.isArray(i))for(let j of i)y.searchParams.append(f,j);else y.searchParams.append(f,i);let c=new Headers;O!=null&&c.set("Content-Type",O),l!=null&&c.set("Accept",l),Object.entries(E||{}).forEach(([f,i])=>{i!=null&&c.append(f,i.toString());});let $=L(w),m=await o(y.toString(),{body:$,method:u,headers:c});return l&&l==="*/*"?t?m.body:m.blob():m.json()}}function L(n){return n==null||globalThis.Blob&&n instanceof globalThis.Blob?n:JSON.stringify(n)}function B(n){let o=/^https?:\/\//i,e="https://";return o.test(n)?n.replace(/^http:\/\//i,e):`${e}${n}`}function d(n){return n.metrics.reduce((o,e)=>{let t=e.name.split(".");return t.length!=2&&(process.env.NODE_ENV!=="production"?a__default.default(!1,"assumed we were getting a `${key}.${type}`"):a__default.default(!1)),t[0]in o||(o[t[0]]={}),o[t[0]][t[1]]=e.value,o},{})}function h(n){return Object.entries(n).flatMap(([o,e])=>Array.isArray(e)?e.map(t=>({type:t,name:`${o}.${t}`,field:o})):[{type:e,name:`${o}.${e}`,field:o}])}function v(n){return n?Object.entries(n).flatMap(([o,e])=>e==="exact"?[{type:e,field:o}]:e.exactWithLimit?[{type:"exact",field:o,maxGroupCount:e.exactWithLimit}]:[]):[]}function p(n){if("$and"in n)return {type:"and",value:n.$and.map(p)};if("$or"in n)return {type:"or",value:n.$or.map(p)};if("$not"in n)return {type:"not",value:p(n.$not)};let o=Object.entries(n);if(o.length===1){let[e,t]=o[0];if(t==null&&(process.env.NODE_ENV!=="production"?a__default.default(!1,"Defined key values are only allowed when they are not undefined."):a__default.default(!1)),typeof t=="string"||typeof t=="number")return {type:"eq",field:e,value:t};Object.keys(t).length!==1&&(process.env.NODE_ENV!=="production"?a__default.default(!1,"WhereClause Filter with multiple properties isn't allowed"):a__default.default(!1));let r=Object.keys(t)[0];return t[r]==null&&(process.env.NODE_ENV!=="production"?a__default.default(!1):a__default.default(!1)),r==="ne"?{type:"not",value:{type:"eq",field:e,value:t[r]}}:{type:r,field:e,value:t[r]}}return {type:"and",value:Object.entries(n).map(([e,t])=>{if(t==null&&(process.env.NODE_ENV!=="production"?a__default.default(!1,"Defined key values are only allowed when they are not undefined."):a__default.default(!1)),typeof t=="string"||typeof t=="number")return {type:"eq",field:e,value:t};Object.keys(t).length!==1&&(process.env.NODE_ENV!=="production"?a__default.default(!1,"WhereClause Filter with multiple properties isn't allowed"):a__default.default(!1));let r=Object.keys(t)[0];return t[r]==null&&(process.env.NODE_ENV!=="production"?a__default.default(!1):a__default.default(!1)),r==="ne"?{type:"not",value:{type:"eq",field:e,value:t[r]}}:{type:r,field:e,value:t[r]}})}}async function N(n,o,e){let t={aggregation:h(e.select),groupBy:[],where:void 0};e.groupBy&&(t.groupBy=v(e.groupBy)),e.where&&(t.where=p(e.where));let r=await requests.aggregateObjectsV2(g(n.stack,n.fetch),n.ontology.metadata.ontologyApiName,o,t);return e.groupBy?r.data.map(s=>({group:s.group,values:d(s)})):(r.data.length!==1&&(process.env.NODE_ENV!=="production"?a__default.default(!1,"no group by clause should mean only one data result"):a__default.default(!1)),d(r.data[0]))}async function T(n,o,e,t={type:"base",objectType:o}){let r={objectSet:t,select:e?.select??[]};e?.nextPageToken&&(r.pageToken=e.nextPageToken);let u=await requests.loadObjectSetV2(g(n.stack,n.fetchJson),n.ontology.metadata.ontologyApiName,r);return {data:u.data.map(s=>({...s,__name:o})),nextPageToken:u.nextPageToken}}var P={};chunk4D6JZ4TL_js.a(P,{aggregateOrThrow:()=>N,fetchPageOrThrow:()=>T});
|
|
12
|
+
|
|
13
|
+
exports.a = p;
|
|
14
|
+
exports.b = g;
|
|
15
|
+
exports.c = N;
|
|
16
|
+
exports.d = T;
|
|
17
|
+
exports.e = P;
|
|
18
|
+
//# sourceMappingURL=out.js.map
|
|
19
|
+
//# sourceMappingURL=chunk-SM47N47Q.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/client/createOpenApiRequest.ts","../../src/client/object/aggregateOrThrow.ts","../../src/client/internal/conversions/legacyToModernSingleAggregationResult.ts","../../src/client/internal/conversions/modernToLegacyAggregationClause.ts","../../src/client/internal/conversions/modernToLegacyGroupByClause.ts","../../src/client/internal/conversions/modernToLegacyWhereClause.ts","../../src/client/object/fetchPageOrThrow.ts","../../src/client/object/index.ts"],"names":["createOpenApiRequest","basePath","fetchFn","contextPath","asReadableStream","method","endpointPath","data","queryArguments","headers","requestMediaType","responseMediaType","url","withHttps","key","value","item","headersInit","body","getBody","response","protocolRegex","httpsProtocol","aggregateObjectsV2","invariant","legacyToModernSingleAggregationResult","entry","accumulator","curValue","parts","modernToLegacyAggregationClause","select","k","v","v2","modernToLegacyGroupByClause","groupByClause","field","type","modernToLegacyWhereClause","whereClause","filter","q","aggregateOrThrow","thinClient","objectType","req","result","loadObjectSetV2","fetchPageOrThrow","client","args","objectSet","r","d","object_exports","__export"],"mappings":"wCAgBO,SAASA,EAAqBC,EAAUC,EAASC,EAAc,OAAQC,EAAkB,CAC9F,OAAO,eAA8BC,EAAQC,EAAcC,EAAMC,EAAgBC,EAASC,EAAkBC,EAAmB,CAC7H,IAAMC,EAAM,IAAI,IAAI,GAAGT,CAAW,GAAGG,CAAY,GAAIO,EAAUZ,CAAQ,CAAC,EACxE,OAAW,CAACa,EAAKC,CAAK,IAAK,OAAO,QAAQP,GAAkB,CAAC,CAAC,EAC5D,GAAI,MAAM,QAAQO,CAAK,EACrB,QAAWC,KAAQD,EACjBH,EAAI,aAAa,OAAOE,EAAKE,CAAI,OAGnCJ,EAAI,aAAa,OAAOE,EAAKC,CAAK,EAGtC,IAAME,EAAc,IAAI,QACpBP,GAAoB,MACtBO,EAAY,IAAI,eAAgBP,CAAgB,EAE9CC,GAAqB,MACvBM,EAAY,IAAI,SAAUN,CAAiB,EAE7C,OAAO,QAAQF,GAAW,CAAC,CAAC,EAAE,QAAQ,CAAC,CAACK,EAAKC,CAAK,IAAM,CAClDA,GAAS,MACXE,EAAY,OAAOH,EAAKC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,SAAS,gBAAiBC,EAAY3B,CAAI,EAChK,OAAK4B,EAAI,QAIGC,EAAO,KAAK,IAAIrB,IACnB,CACL,MAAOA,EAAM,MACb,OAAQD,EAAsCC,CAAK,CACrD,EACD,GARGqB,EAAO,KAAK,SAAW,IAAK,QAAQ,IAAI,WAAa,aAAevB,EAAU,GAAO,qDAAqD,EAAIA,EAAU,EAAK,GACxJC,EAAsCsB,EAAO,KAAK,CAAC,CAAC,EAU/D,CKhCA,OAAS,mBAAAC,MAAuB,yBAEhC,eAAsBC,EAAiBC,EAAQL,EAAYM,EAAMC,EAAY,CAC3E,KAAM,OACN,WAAAP,CACF,EAAG,CACD,IAAM3B,EAAO,CACX,UAAAkC,EAEA,OAAQD,GAAM,QAAU,CAAC,CAC3B,EAEIA,GAAM,gBACRjC,EAAK,UAAYiC,EAAK,eAExB,IAAME,EAAI,MAAML,EAAgBhD,EAAqBkD,EAAO,MAAOA,EAAO,SAAS,EAAGA,EAAO,SAAS,SAAS,gBAAiBhC,CAAI,EACpI,MAAO,CACL,KAAMmC,EAAE,KAAK,IAAIC,IAAM,CACrB,GAAGA,EACH,OAAQT,CACV,EAAE,EACF,cAAeQ,EAAE,aACnB,CACF,CCvCA,IAAAE,EAAA,GAAAC,EAAAD,EAAA,sBAAAZ,EAAA,qBAAAM","sourcesContent":["/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport function createOpenApiRequest(basePath, fetchFn, contextPath = \"/api\", asReadableStream) {\n return async function openApiRequest(method, endpointPath, data, queryArguments, headers, requestMediaType, responseMediaType) {\n const url = new URL(`${contextPath}${endpointPath}`, withHttps(basePath));\n for (const [key, value] of Object.entries(queryArguments || {})) {\n if (Array.isArray(value)) {\n for (const item of value) {\n url.searchParams.append(key, item);\n }\n } else {\n url.searchParams.append(key, value);\n }\n }\n const headersInit = new Headers();\n if (requestMediaType != null) {\n headersInit.set(\"Content-Type\", requestMediaType);\n }\n if (responseMediaType != null) {\n headersInit.set(\"Accept\", responseMediaType);\n }\n Object.entries(headers || {}).forEach(([key, value]) => {\n if (value != null) {\n headersInit.append(key, value.toString());\n }\n });\n const body = getBody(data);\n const response = await fetchFn(url.toString(), {\n body,\n method: method,\n headers: headersInit\n });\n if (responseMediaType && responseMediaType === \"*/*\") {\n if (asReadableStream) {\n return response.body;\n }\n return response.blob();\n }\n return response.json();\n };\n}\nfunction getBody(body) {\n if (body == null) {\n return body;\n }\n if (globalThis.Blob && body instanceof globalThis.Blob) {\n return body;\n }\n return JSON.stringify(body);\n}\nfunction withHttps(url) {\n const protocolRegex = /^https?:\\/\\//i;\n const httpsProtocol = \"https://\";\n return protocolRegex.test(url) ? url.replace(/^http:\\/\\//i, httpsProtocol) : `${httpsProtocol}${url}`;\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { aggregateObjectsV2 } from \"@osdk/gateway/requests\";\nimport invariant from \"tiny-invariant\";\nimport { createOpenApiRequest } from \"../createOpenApiRequest\";\nimport { legacyToModernSingleAggregationResult, modernToLegacyAggregationClause, modernToLegacyGroupByClause, modernToLegacyWhereClause } from \"../internal/conversions\";\nexport async function aggregateOrThrow(thinClient, objectType, req) {\n const body = {\n aggregation: modernToLegacyAggregationClause(req.select),\n groupBy: [],\n where: undefined\n };\n if (req.groupBy) {\n body.groupBy = modernToLegacyGroupByClause(req.groupBy);\n }\n if (req.where) {\n body.where = modernToLegacyWhereClause(req.where);\n // TODO: orderBy\n // TODO The token stuff here sucks\n }\n\n const result = await aggregateObjectsV2(createOpenApiRequest(thinClient.stack, thinClient.fetch), thinClient.ontology.metadata.ontologyApiName, objectType, body);\n if (!req.groupBy) {\n !(result.data.length === 1) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"no group by clause should mean only one data result\") : invariant(false) : void 0;\n return legacyToModernSingleAggregationResult(result.data[0]);\n }\n const ret = result.data.map(entry => {\n return {\n group: entry.group,\n values: legacyToModernSingleAggregationResult(entry)\n };\n }); // fixme\n\n return ret; // FIXME\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport invariant from \"tiny-invariant\";\nexport function legacyToModernSingleAggregationResult(entry) {\n return entry.metrics.reduce((accumulator, curValue) => {\n const parts = curValue.name.split(\".\");\n !(parts.length == 2) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"assumed we were getting a `${key}.${type}`\") : invariant(false) : void 0;\n if (!(parts[0] in accumulator)) {\n accumulator[parts[0]] = {};\n }\n accumulator[parts[0]][parts[1]] = curValue.value;\n return accumulator;\n }, {});\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport function modernToLegacyAggregationClause(select) {\n return Object.entries(select).flatMap(([k, v]) => {\n if (Array.isArray(v)) {\n return v.map(v2 => {\n return {\n type: v2,\n name: `${k}.${v2}`,\n field: k\n };\n });\n } else {\n return [{\n type: v,\n // FIXME v has additional possible values\n name: `${k}.${v}`,\n field: k\n }];\n }\n });\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport function modernToLegacyGroupByClause(groupByClause) {\n if (!groupByClause) return [];\n return Object.entries(groupByClause).flatMap(([field, type]) => {\n if (type === \"exact\") {\n return [{\n type,\n field\n }];\n } else if (type.exactWithLimit) {\n return [{\n type: \"exact\",\n field,\n maxGroupCount: type.exactWithLimit\n }];\n } else {\n return [];\n }\n });\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport invariant from \"tiny-invariant\";\nexport function modernToLegacyWhereClause(whereClause) {\n if (\"$and\" in whereClause) {\n return {\n type: \"and\",\n value: whereClause.$and.map(modernToLegacyWhereClause)\n };\n } else if (\"$or\" in whereClause) {\n return {\n type: \"or\",\n value: whereClause.$or.map(modernToLegacyWhereClause)\n };\n } else if (\"$not\" in whereClause) {\n return {\n type: \"not\",\n value: modernToLegacyWhereClause(whereClause.$not)\n };\n }\n const parts = Object.entries(whereClause);\n if (parts.length === 1) {\n const [field, filter] = parts[0];\n !(filter != null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"Defined key values are only allowed when they are not undefined.\") : invariant(false) : void 0;\n if (typeof filter === \"string\" || typeof filter === \"number\") {\n return {\n type: \"eq\",\n field,\n value: filter\n };\n }\n !(Object.keys(filter).length === 1) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"WhereClause Filter with multiple properties isn't allowed\") : invariant(false) : void 0;\n const type = Object.keys(filter)[0];\n !(filter[type] != null) ? process.env.NODE_ENV !== \"production\" ? invariant(false) : invariant(false) : void 0;\n if (type === \"ne\") {\n return {\n type: \"not\",\n value: {\n type: \"eq\",\n field,\n value: filter[type]\n }\n };\n }\n return {\n type,\n field,\n value: filter[type]\n };\n }\n return {\n type: \"and\",\n value: Object.entries(whereClause).map(([field, filter]) => {\n !(filter != null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"Defined key values are only allowed when they are not undefined.\") : invariant(false) : void 0;\n if (typeof filter === \"string\" || typeof filter === \"number\") {\n return {\n type: \"eq\",\n field,\n value: filter\n };\n }\n !(Object.keys(filter).length === 1) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"WhereClause Filter with multiple properties isn't allowed\") : invariant(false) : void 0;\n const q = Object.keys(filter)[0];\n !(filter[q] != null) ? process.env.NODE_ENV !== \"production\" ? invariant(false) : invariant(false) : void 0;\n if (q === \"ne\") {\n return {\n type: \"not\",\n value: {\n type: \"eq\",\n field,\n value: filter[q]\n }\n };\n }\n return {\n type: q,\n field,\n value: filter[q]\n };\n })\n };\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { loadObjectSetV2 } from \"@osdk/gateway/requests\";\nimport { createOpenApiRequest } from \"../createOpenApiRequest\";\nexport async function fetchPageOrThrow(client, objectType, args, objectSet = {\n type: \"base\",\n objectType\n}) {\n const body = {\n objectSet,\n // We have to do the following case because LoadObjectSetRequestV2 isnt readonly\n select: args?.select ?? [] // FIXME?\n };\n\n if (args?.nextPageToken) {\n body.pageToken = args.nextPageToken;\n }\n const r = await loadObjectSetV2(createOpenApiRequest(client.stack, client.fetchJson), client.ontology.metadata.ontologyApiName, body);\n return {\n data: r.data.map(d => ({\n ...d,\n __name: objectType\n })),\n nextPageToken: r.nextPageToken\n };\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { aggregateOrThrow } from \"./aggregateOrThrow\";\nexport { fetchPageOrThrow } from \"./fetchPageOrThrow\";"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { a } from './chunk-XIJ2ZQRX.mjs';
|
|
2
|
+
import { aggregateObjectsV2, loadObjectSetV2 } from '@osdk/gateway/requests';
|
|
3
|
+
import a$1 from 'tiny-invariant';
|
|
4
|
+
|
|
5
|
+
function g(n,o,e="/api",t){return async function(u,s,w,A,E,O,l){let y=new URL(`${e}${s}`,B(n));for(let[f,i]of Object.entries(A||{}))if(Array.isArray(i))for(let j of i)y.searchParams.append(f,j);else y.searchParams.append(f,i);let c=new Headers;O!=null&&c.set("Content-Type",O),l!=null&&c.set("Accept",l),Object.entries(E||{}).forEach(([f,i])=>{i!=null&&c.append(f,i.toString());});let $=L(w),m=await o(y.toString(),{body:$,method:u,headers:c});return l&&l==="*/*"?t?m.body:m.blob():m.json()}}function L(n){return n==null||globalThis.Blob&&n instanceof globalThis.Blob?n:JSON.stringify(n)}function B(n){let o=/^https?:\/\//i,e="https://";return o.test(n)?n.replace(/^http:\/\//i,e):`${e}${n}`}function d(n){return n.metrics.reduce((o,e)=>{let t=e.name.split(".");return t.length!=2&&(process.env.NODE_ENV!=="production"?a$1(!1,"assumed we were getting a `${key}.${type}`"):a$1(!1)),t[0]in o||(o[t[0]]={}),o[t[0]][t[1]]=e.value,o},{})}function h(n){return Object.entries(n).flatMap(([o,e])=>Array.isArray(e)?e.map(t=>({type:t,name:`${o}.${t}`,field:o})):[{type:e,name:`${o}.${e}`,field:o}])}function v(n){return n?Object.entries(n).flatMap(([o,e])=>e==="exact"?[{type:e,field:o}]:e.exactWithLimit?[{type:"exact",field:o,maxGroupCount:e.exactWithLimit}]:[]):[]}function p(n){if("$and"in n)return {type:"and",value:n.$and.map(p)};if("$or"in n)return {type:"or",value:n.$or.map(p)};if("$not"in n)return {type:"not",value:p(n.$not)};let o=Object.entries(n);if(o.length===1){let[e,t]=o[0];if(t==null&&(process.env.NODE_ENV!=="production"?a$1(!1,"Defined key values are only allowed when they are not undefined."):a$1(!1)),typeof t=="string"||typeof t=="number")return {type:"eq",field:e,value:t};Object.keys(t).length!==1&&(process.env.NODE_ENV!=="production"?a$1(!1,"WhereClause Filter with multiple properties isn't allowed"):a$1(!1));let r=Object.keys(t)[0];return t[r]==null&&(process.env.NODE_ENV!=="production"?a$1(!1):a$1(!1)),r==="ne"?{type:"not",value:{type:"eq",field:e,value:t[r]}}:{type:r,field:e,value:t[r]}}return {type:"and",value:Object.entries(n).map(([e,t])=>{if(t==null&&(process.env.NODE_ENV!=="production"?a$1(!1,"Defined key values are only allowed when they are not undefined."):a$1(!1)),typeof t=="string"||typeof t=="number")return {type:"eq",field:e,value:t};Object.keys(t).length!==1&&(process.env.NODE_ENV!=="production"?a$1(!1,"WhereClause Filter with multiple properties isn't allowed"):a$1(!1));let r=Object.keys(t)[0];return t[r]==null&&(process.env.NODE_ENV!=="production"?a$1(!1):a$1(!1)),r==="ne"?{type:"not",value:{type:"eq",field:e,value:t[r]}}:{type:r,field:e,value:t[r]}})}}async function N(n,o,e){let t={aggregation:h(e.select),groupBy:[],where:void 0};e.groupBy&&(t.groupBy=v(e.groupBy)),e.where&&(t.where=p(e.where));let r=await aggregateObjectsV2(g(n.stack,n.fetch),n.ontology.metadata.ontologyApiName,o,t);return e.groupBy?r.data.map(s=>({group:s.group,values:d(s)})):(r.data.length!==1&&(process.env.NODE_ENV!=="production"?a$1(!1,"no group by clause should mean only one data result"):a$1(!1)),d(r.data[0]))}async function T(n,o,e,t={type:"base",objectType:o}){let r={objectSet:t,select:e?.select??[]};e?.nextPageToken&&(r.pageToken=e.nextPageToken);let u=await loadObjectSetV2(g(n.stack,n.fetchJson),n.ontology.metadata.ontologyApiName,r);return {data:u.data.map(s=>({...s,__name:o})),nextPageToken:u.nextPageToken}}var P={};a(P,{aggregateOrThrow:()=>N,fetchPageOrThrow:()=>T});
|
|
6
|
+
|
|
7
|
+
export { p as a, g as b, N as c, T as d, P as e };
|
|
8
|
+
//# sourceMappingURL=out.js.map
|
|
9
|
+
//# sourceMappingURL=chunk-TPXDMNRT.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/client/createOpenApiRequest.ts","../../src/client/object/aggregateOrThrow.ts","../../src/client/internal/conversions/legacyToModernSingleAggregationResult.ts","../../src/client/internal/conversions/modernToLegacyAggregationClause.ts","../../src/client/internal/conversions/modernToLegacyGroupByClause.ts","../../src/client/internal/conversions/modernToLegacyWhereClause.ts","../../src/client/object/fetchPageOrThrow.ts","../../src/client/object/index.ts"],"names":["createOpenApiRequest","basePath","fetchFn","contextPath","asReadableStream","method","endpointPath","data","queryArguments","headers","requestMediaType","responseMediaType","url","withHttps","key","value","item","headersInit","body","getBody","response","protocolRegex","httpsProtocol","aggregateObjectsV2","invariant","legacyToModernSingleAggregationResult","entry","accumulator","curValue","parts","modernToLegacyAggregationClause","select","k","v","v2","modernToLegacyGroupByClause","groupByClause","field","type","modernToLegacyWhereClause","whereClause","filter","q","aggregateOrThrow","thinClient","objectType","req","result","loadObjectSetV2","fetchPageOrThrow","client","args","objectSet","r","d","object_exports","__export"],"mappings":"yCAgBO,SAASA,EAAqBC,EAAUC,EAASC,EAAc,OAAQC,EAAkB,CAC9F,OAAO,eAA8BC,EAAQC,EAAcC,EAAMC,EAAgBC,EAASC,EAAkBC,EAAmB,CAC7H,IAAMC,EAAM,IAAI,IAAI,GAAGT,CAAW,GAAGG,CAAY,GAAIO,EAAUZ,CAAQ,CAAC,EACxE,OAAW,CAACa,EAAKC,CAAK,IAAK,OAAO,QAAQP,GAAkB,CAAC,CAAC,EAC5D,GAAI,MAAM,QAAQO,CAAK,EACrB,QAAWC,KAAQD,EACjBH,EAAI,aAAa,OAAOE,EAAKE,CAAI,OAGnCJ,EAAI,aAAa,OAAOE,EAAKC,CAAK,EAGtC,IAAME,EAAc,IAAI,QACpBP,GAAoB,MACtBO,EAAY,IAAI,eAAgBP,CAAgB,EAE9CC,GAAqB,MACvBM,EAAY,IAAI,SAAUN,CAAiB,EAE7C,OAAO,QAAQF,GAAW,CAAC,CAAC,EAAE,QAAQ,CAAC,CAACK,EAAKC,CAAK,IAAM,CAClDA,GAAS,MACXE,EAAY,OAAOH,EAAKC,EAAM,SAAS,CAAC,CAE5C,CAAC,EACD,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OAAK4B,EAAI,QAIGC,EAAO,KAAK,IAAIrB,IACnB,CACL,MAAOA,EAAM,MACb,OAAQD,EAAsCC,CAAK,CACrD,EACD,GARGqB,EAAO,KAAK,SAAW,IAAK,QAAQ,IAAI,WAAa,aAAevB,EAAU,GAAO,qDAAqD,EAAIA,EAAU,EAAK,GACxJC,EAAsCsB,EAAO,KAAK,CAAC,CAAC,EAU/D,CKhCA,OAAS,mBAAAC,MAAuB,yBAEhC,eAAsBC,EAAiBC,EAAQL,EAAYM,EAAMC,EAAY,CAC3E,KAAM,OACN,WAAAP,CACF,EAAG,CACD,IAAM3B,EAAO,CACX,UAAAkC,EAEA,OAAQD,GAAM,QAAU,CAAC,CAC3B,EAEIA,GAAM,gBACRjC,EAAK,UAAYiC,EAAK,eAExB,IAAME,EAAI,MAAML,EAAgBhD,EAAqBkD,EAAO,MAAOA,EAAO,SAAS,EAAGA,EAAO,SAAS,SAAS,gBAAiBhC,CAAI,EACpI,MAAO,CACL,KAAMmC,EAAE,KAAK,IAAIC,IAAM,CACrB,GAAGA,EACH,OAAQT,CACV,EAAE,EACF,cAAeQ,EAAE,aACnB,CACF,CCvCA,IAAAE,EAAA,GAAAC,EAAAD,EAAA,sBAAAZ,EAAA,qBAAAM","sourcesContent":["/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport function createOpenApiRequest(basePath, fetchFn, contextPath = \"/api\", asReadableStream) {\n return async function openApiRequest(method, endpointPath, data, queryArguments, headers, requestMediaType, responseMediaType) {\n const url = new URL(`${contextPath}${endpointPath}`, withHttps(basePath));\n for (const [key, value] of Object.entries(queryArguments || {})) {\n if (Array.isArray(value)) {\n for (const item of value) {\n url.searchParams.append(key, item);\n }\n } else {\n url.searchParams.append(key, value);\n }\n }\n const headersInit = new Headers();\n if (requestMediaType != null) {\n headersInit.set(\"Content-Type\", requestMediaType);\n }\n if (responseMediaType != null) {\n headersInit.set(\"Accept\", responseMediaType);\n }\n Object.entries(headers || {}).forEach(([key, value]) => {\n if (value != null) {\n headersInit.append(key, value.toString());\n }\n });\n const body = getBody(data);\n const response = await fetchFn(url.toString(), {\n body,\n method: method,\n headers: headersInit\n });\n if (responseMediaType && responseMediaType === \"*/*\") {\n if (asReadableStream) {\n return response.body;\n }\n return response.blob();\n }\n return response.json();\n };\n}\nfunction getBody(body) {\n if (body == null) {\n return body;\n }\n if (globalThis.Blob && body instanceof globalThis.Blob) {\n return body;\n }\n return JSON.stringify(body);\n}\nfunction withHttps(url) {\n const protocolRegex = /^https?:\\/\\//i;\n const httpsProtocol = \"https://\";\n return protocolRegex.test(url) ? url.replace(/^http:\\/\\//i, httpsProtocol) : `${httpsProtocol}${url}`;\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { aggregateObjectsV2 } from \"@osdk/gateway/requests\";\nimport invariant from \"tiny-invariant\";\nimport { createOpenApiRequest } from \"../createOpenApiRequest\";\nimport { legacyToModernSingleAggregationResult, modernToLegacyAggregationClause, modernToLegacyGroupByClause, modernToLegacyWhereClause } from \"../internal/conversions\";\nexport async function aggregateOrThrow(thinClient, objectType, req) {\n const body = {\n aggregation: modernToLegacyAggregationClause(req.select),\n groupBy: [],\n where: undefined\n };\n if (req.groupBy) {\n body.groupBy = modernToLegacyGroupByClause(req.groupBy);\n }\n if (req.where) {\n body.where = modernToLegacyWhereClause(req.where);\n // TODO: orderBy\n // TODO The token stuff here sucks\n }\n\n const result = await aggregateObjectsV2(createOpenApiRequest(thinClient.stack, thinClient.fetch), thinClient.ontology.metadata.ontologyApiName, objectType, body);\n if (!req.groupBy) {\n !(result.data.length === 1) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"no group by clause should mean only one data result\") : invariant(false) : void 0;\n return legacyToModernSingleAggregationResult(result.data[0]);\n }\n const ret = result.data.map(entry => {\n return {\n group: entry.group,\n values: legacyToModernSingleAggregationResult(entry)\n };\n }); // fixme\n\n return ret; // FIXME\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport invariant from \"tiny-invariant\";\nexport function legacyToModernSingleAggregationResult(entry) {\n return entry.metrics.reduce((accumulator, curValue) => {\n const parts = curValue.name.split(\".\");\n !(parts.length == 2) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"assumed we were getting a `${key}.${type}`\") : invariant(false) : void 0;\n if (!(parts[0] in accumulator)) {\n accumulator[parts[0]] = {};\n }\n accumulator[parts[0]][parts[1]] = curValue.value;\n return accumulator;\n }, {});\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport function modernToLegacyAggregationClause(select) {\n return Object.entries(select).flatMap(([k, v]) => {\n if (Array.isArray(v)) {\n return v.map(v2 => {\n return {\n type: v2,\n name: `${k}.${v2}`,\n field: k\n };\n });\n } else {\n return [{\n type: v,\n // FIXME v has additional possible values\n name: `${k}.${v}`,\n field: k\n }];\n }\n });\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport function modernToLegacyGroupByClause(groupByClause) {\n if (!groupByClause) return [];\n return Object.entries(groupByClause).flatMap(([field, type]) => {\n if (type === \"exact\") {\n return [{\n type,\n field\n }];\n } else if (type.exactWithLimit) {\n return [{\n type: \"exact\",\n field,\n maxGroupCount: type.exactWithLimit\n }];\n } else {\n return [];\n }\n });\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport invariant from \"tiny-invariant\";\nexport function modernToLegacyWhereClause(whereClause) {\n if (\"$and\" in whereClause) {\n return {\n type: \"and\",\n value: whereClause.$and.map(modernToLegacyWhereClause)\n };\n } else if (\"$or\" in whereClause) {\n return {\n type: \"or\",\n value: whereClause.$or.map(modernToLegacyWhereClause)\n };\n } else if (\"$not\" in whereClause) {\n return {\n type: \"not\",\n value: modernToLegacyWhereClause(whereClause.$not)\n };\n }\n const parts = Object.entries(whereClause);\n if (parts.length === 1) {\n const [field, filter] = parts[0];\n !(filter != null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"Defined key values are only allowed when they are not undefined.\") : invariant(false) : void 0;\n if (typeof filter === \"string\" || typeof filter === \"number\") {\n return {\n type: \"eq\",\n field,\n value: filter\n };\n }\n !(Object.keys(filter).length === 1) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"WhereClause Filter with multiple properties isn't allowed\") : invariant(false) : void 0;\n const type = Object.keys(filter)[0];\n !(filter[type] != null) ? process.env.NODE_ENV !== \"production\" ? invariant(false) : invariant(false) : void 0;\n if (type === \"ne\") {\n return {\n type: \"not\",\n value: {\n type: \"eq\",\n field,\n value: filter[type]\n }\n };\n }\n return {\n type,\n field,\n value: filter[type]\n };\n }\n return {\n type: \"and\",\n value: Object.entries(whereClause).map(([field, filter]) => {\n !(filter != null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"Defined key values are only allowed when they are not undefined.\") : invariant(false) : void 0;\n if (typeof filter === \"string\" || typeof filter === \"number\") {\n return {\n type: \"eq\",\n field,\n value: filter\n };\n }\n !(Object.keys(filter).length === 1) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"WhereClause Filter with multiple properties isn't allowed\") : invariant(false) : void 0;\n const q = Object.keys(filter)[0];\n !(filter[q] != null) ? process.env.NODE_ENV !== \"production\" ? invariant(false) : invariant(false) : void 0;\n if (q === \"ne\") {\n return {\n type: \"not\",\n value: {\n type: \"eq\",\n field,\n value: filter[q]\n }\n };\n }\n return {\n type: q,\n field,\n value: filter[q]\n };\n })\n };\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { loadObjectSetV2 } from \"@osdk/gateway/requests\";\nimport { createOpenApiRequest } from \"../createOpenApiRequest\";\nexport async function fetchPageOrThrow(client, objectType, args, objectSet = {\n type: \"base\",\n objectType\n}) {\n const body = {\n objectSet,\n // We have to do the following case because LoadObjectSetRequestV2 isnt readonly\n select: args?.select ?? [] // FIXME?\n };\n\n if (args?.nextPageToken) {\n body.pageToken = args.nextPageToken;\n }\n const r = await loadObjectSetV2(createOpenApiRequest(client.stack, client.fetchJson), client.ontology.metadata.ontologyApiName, body);\n return {\n data: r.data.map(d => ({\n ...d,\n __name: objectType\n })),\n nextPageToken: r.nextPageToken\n };\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { aggregateOrThrow } from \"./aggregateOrThrow\";\nexport { fetchPageOrThrow } from \"./fetchPageOrThrow\";"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
package/build/js/index.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkSM47N47Q_js = require('./chunk-SM47N47Q.js');
|
|
4
|
+
var chunkSHYKLQMU_js = require('./chunk-SHYKLQMU.js');
|
|
5
|
+
require('./chunk-4D6JZ4TL.js');
|
|
5
6
|
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
var b__default = /*#__PURE__*/_interopDefault(b);
|
|
9
|
-
|
|
10
|
-
function u(r=fetch,e){return async function(t,o){return o?r(t,{...o,headers:await e(new Headers(o.headers))}):r(t,{headers:await e(new Headers)})}}var i=class extends Error{constructor(e,n,t,o,a,c){super(e),this.message=e,this.errorName=n,this.errorType=t,this.statusCode=o,this.errorInstanceId=a,this.parameters=c;}};var f=class extends i{constructor(e,n,t){super(e,n),this.originalError=t;}};function m(r=fetch){return async function(n,t){let o;try{o=await r(n,t);}catch(a){throw l(a,"A network error occured")}if(!o.ok){let a;try{a=await o.json();}catch(c){throw l(c,"A network error occured while reading response")}throw new i(a?.message??`Failed to fetch ${o.status} ${o.statusText}`,a?.errorName,a?.errorCode,o.status,a?.errorInstanceId,a?.parameters)}return o}}function l(r,e="An unknown error occurred"){return r instanceof Error?new f(r.message,"UNKNOWN",r):new f(e,"UNKNOWN")}var N=1e3,R=.5,I=3;function d(r){return b__default.default(r,{retryDelay(e){let n=N*2**e,t=n*R*(Math.random()*2-1);return n+t},retryOn(e,n,t){let o=t?.status??0;return !(o>=200&&o<300)&&j(n)&&e<I}})}function j(r){return !(r instanceof i&&r.statusCode!==k&&r.statusCode!==P)}var k=503,P=429;function y(r){return r!=null?JSON.stringify(r):void 0}function w(r=fetch){return r=u(r,e=>(e.set("Content-Type","application/json"),e)),async function(n,t){return (await r(n,{...t,body:y(t.body)})).json()}}function h(r,e,n,t=fetch){let o=u(d(m(t)),async a=>{let c=await n();return a.set("Authorization",`Bearer ${c}`),a.set("Fetch-User-Agent",r.metadata.userAgent),a});return {ontology:r,stack:e,fetch:o,fetchJson:w(o)}}var T="searchAround_";function p(r,e,n,t={type:"base",objectType:r}){let o={aggregate:c=>{throw "TODO"},aggregateOrThrow:async c=>chunkI3UIWCJ4_js.b(e,r,c),fetchPage:async c=>{throw "TODO"},fetchPageOrThrow:async c=>chunkI3UIWCJ4_js.c(e,r,c??{},t),asyncIter:()=>{throw ""},where:c=>p(r,e,n,{type:"filter",objectSet:t,where:chunkI3UIWCJ4_js.a(c)}),[Symbol.asyncIterator]:()=>{throw ""},pivotTo:function(c,s){return a(c)().where(s?.$where??{})}};function a(c){return ()=>p(r,e,{},{type:"searchAround",objectSet:t,link:c})}return new Proxy(o,{get(c,s,g){return typeof s=="string"&&s.startsWith(T)?a(s.substring(T.length)):c[s]}})}function F(r){return new Proxy({},{get:(e,n,t)=>{if(typeof n=="string")return r.objectSet(n)}})}function C(r,e,n,t=fetch){let o=h(r,e,n,t),a=(s,g)=>p(s,o,g),c=Object.defineProperties({},{objectSet:{get:()=>a},objects:{get:()=>F(c)}});return c}function E(r){return r.type==="ok"}
|
|
7
|
+
var f=class extends chunkSHYKLQMU_js.b{constructor(t,c,n){super(t,c),this.originalError=n;}};function g(r=fetch){return async function(c,n){let a;try{a=await r(c,n);}catch(o){throw A(o,"A network error occured")}if(!a.ok){let o;try{o=await a.json();}catch(e){throw A(e,"A network error occured while reading response")}throw new chunkSHYKLQMU_js.b(o?.message??`Failed to fetch ${a.status} ${a.statusText}`,o?.errorName,o?.errorCode,a.status,o?.errorInstanceId,o?.parameters)}return a}}function A(r,t="An unknown error occurred"){return r instanceof Error?new f(r.message,"UNKNOWN",r):new f(t,"UNKNOWN")}function w(r){return r!=null?JSON.stringify(r):void 0}function y(r=fetch){return r=chunkSHYKLQMU_js.a(r,t=>(t.set("Content-Type","application/json"),t)),async function(c,n){return (await r(c,{...n,body:w(n.body)})).json()}}function h(r,t,c,n=fetch){let a=chunkSHYKLQMU_js.a(chunkSHYKLQMU_js.c(g(n)),async o=>{let e=await c();return o.set("Authorization",`Bearer ${e}`),o.set("Fetch-User-Agent",r.metadata.userAgent),o});return {ontology:r,stack:t,fetch:a,fetchJson:y(a)}}var T="searchAround_";function p(r,t,c,n={type:"base",objectType:r}){let a={aggregate:e=>{throw "TODO"},aggregateOrThrow:async e=>chunkSM47N47Q_js.c(t,r,e),fetchPage:async e=>{throw "TODO"},fetchPageOrThrow:async e=>chunkSM47N47Q_js.d(t,r,e??{},n),asyncIter:()=>{throw ""},where:e=>p(r,t,c,{type:"filter",objectSet:n,where:chunkSM47N47Q_js.a(e)}),[Symbol.asyncIterator]:()=>{throw ""},pivotTo:function(e,i){return o(e)().where(i?.$where??{})}};function o(e){return ()=>p(r,t,{},{type:"searchAround",objectSet:n,link:e})}return new Proxy(a,{get(e,i,O){return typeof i=="string"&&i.startsWith(T)?o(i.substring(T.length)):e[i]}})}function F(r){return new Proxy({},{get:(t,c,n)=>{if(typeof c=="string")return r.objectSet(c)}})}function b(r,t,c,n=fetch){let a=h(r,t,c,n),o=(i,O)=>p(i,a,O),e=Object.defineProperties({},{objectSet:{get:()=>o},objects:{get:()=>F(e)}});return e}function C(r){return r.type==="ok"}
|
|
11
8
|
|
|
12
9
|
Object.defineProperty(exports, 'Objects', {
|
|
13
10
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
11
|
+
get: function () { return chunkSM47N47Q_js.e; }
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, 'createOpenApiRequest', {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return chunkSM47N47Q_js.b; }
|
|
15
16
|
});
|
|
16
|
-
exports.createClient =
|
|
17
|
+
exports.createClient = b;
|
|
17
18
|
exports.createThinClient = h;
|
|
18
|
-
exports.isOk =
|
|
19
|
+
exports.isOk = C;
|
|
19
20
|
//# sourceMappingURL=out.js.map
|
|
20
21
|
//# sourceMappingURL=index.js.map
|
package/build/js/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/createFetchHeaderMutator.ts","../../src/client/PalantirApiError.ts","../../src/client/UnknownError.ts","../../src/util/createFetchOrThrow.ts","../../src/util/createRetryingFetch.ts","../../src/util/stringifyBody.ts","../../src/util/FetchAsJson.ts","../../src/client/createThinClient.ts","../../src/client/objectSet/createObjectSet.ts","../../src/client/ObjectSetCreator.ts","../../src/client/createClient.ts","../../src/client/ResultOrError.ts"],"names":["createFetchHeaderMutator","fetchFn","mutator","url","requestInit","PalantirApiError","message","errorName","errorType","statusCode","errorInstanceId","parameters","UnknownError","originalError","createFetchOrThrow","response","e","convertError","body","msgIfNotError","fetchRetry","INITIAL_DELAY","JITTER_FACTOR","MAX_RETRIES","createRetryingFetch","fetch","attempt","delay","jitter","error","status","isRetryable","SERVICE_UNAVAILABLE","TOO_MANY_REQUESTS","stringifyBody","createFetchAsJson","headers","createThinClient","ontology","stack","tokenProvider","retryingFetchWithAuthOrThrow","token","searchAroundPrefix","createObjectSet","objectType","thinClient","opts","objectSet","base","req","aggregateOrThrow","args","fetchPageOrThrow","clause","modernToLegacyWhereClause","type","createSearchAround","link","target","p","receiver","createObjectSetCreator","client","createClient","objectSetFactory","isOk","result"],"mappings":"6DAgBO,SAASA,EAAyBC,EAAU,MAAOC,EAAS,CACjE,OAAO,eAAkCC,EAAKC,EAAa,CACzD,OAAKA,EAKEH,EAAQE,EAAK,CAClB,GAAGC,EACH,QAAS,MAAMF,EAAQ,IAAI,QAAQE,EAAY,OAAO,CAAC,CACzD,CAAC,EAPQH,EAAQE,EAAK,CAClB,QAAS,MAAMD,EAAQ,IAAI,OAAS,CACtC,CAAC,CAML,CACF,CCZO,IAAMG,EAAN,cAA+B,KAAM,CAC1C,YAAYC,EAASC,EAAWC,EAAWC,EAAYC,EAAiBC,EAAY,CAClF,MAAML,CAAO,EACb,KAAK,QAAUA,EACf,KAAK,UAAYC,EACjB,KAAK,UAAYC,EACjB,KAAK,WAAaC,EAClB,KAAK,gBAAkBC,EACvB,KAAK,WAAaC,CACpB,CACF,ECTO,IAAMC,EAAN,cAA2BP,CAAiB,CACjD,YAAYC,EAASE,EAAW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,EAA0BD,CAAM,CACzC,CAAC,EAEH,CAAC,OAAO,aAAa,EAAG,IAAM,CAC5B,KAAM,EACR,EACA,QAAS,SAAUE,EAAMT,EAAM,CAC7B,OAAOU,EAAmBD,CAAI,EAAE,EAAE,MAAMT,GAAM,QAAU,CAAC,CAAC,CAC5D,CACF,EACA,SAASU,EAAmBC,EAAM,CAChC,MAAO,IACEd,EAAgBC,EAAYC,EAAY,CAAC,EAAG,CACjD,KAAM,eACN,UAAAE,EACA,KAAAU,CACF,CAAC,CAEL,CACA,OAAO,IAAI,MAAMT,EAAM,CACrB,IAAIU,EAAQC,EAAGC,EAAU,CACvB,OAAI,OAAOD,GAAM,UAAYA,EAAE,WAAWjB,CAAkB,EACnDc,EAAmBG,EAAE,UAAUjB,EAAmB,MAAM,CAAC,EAE3DgB,EAAOC,CAAC,CACjB,CACF,CAAC,CACH,CC7CO,SAASE,EAAuBC,EAAQ,CAC7C,OAAO,IAAI,MAAM,CAAC,EAAG,CACnB,IAAK,CAACJ,EAAQC,EAAGC,IAAa,CAC5B,GAAI,OAAOD,GAAM,SAAU,OAAOG,EAAO,UAAUH,CAAC,CAEtD,CACF,CAAC,CACH,CCbO,SAASI,EAAa1B,EAAUC,EAAOC,EAAevC,EAAU,MAAO,CAC5E,IAAM6C,EAAaT,EAAiBC,EAAUC,EAAOC,EAAevC,CAAO,EACrEgE,EAAmB,CAACT,EAAMT,IAASH,EAAgBY,EAAMV,EAAYC,CAAI,EACzEgB,EAAS,OAAO,iBAAiB,CAAC,EAAG,CACzC,UAAW,CACT,IAAK,IAAME,CACb,EACA,QAAS,CACP,IAAK,IAAMH,EAAuBC,CAAM,CAC1C,CACF,CAAC,EACD,OAAOA,CACT,CCfO,SAASG,EAAKC,EAAQ,CAC3B,OAAOA,EAAO,OAAS,IACzB","sourcesContent":["/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport function createFetchHeaderMutator(fetchFn = fetch, mutator) {\n return async function headerMutatedFetch(url, requestInit) {\n if (!requestInit) {\n return fetchFn(url, {\n headers: await mutator(new Headers())\n });\n }\n return fetchFn(url, {\n ...requestInit,\n headers: await mutator(new Headers(requestInit.headers))\n });\n };\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport class PalantirApiError extends Error {\n constructor(message, errorName, errorType, statusCode, errorInstanceId, parameters) {\n super(message);\n this.message = message;\n this.errorName = errorName;\n this.errorType = errorType;\n this.statusCode = statusCode;\n this.errorInstanceId = errorInstanceId;\n this.parameters = parameters;\n }\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PalantirApiError } from \"./PalantirApiError\";\nexport class UnknownError extends PalantirApiError {\n constructor(message, errorType, originalError) {\n super(message, errorType);\n this.originalError = originalError;\n }\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PalantirApiError } from \"../client/PalantirApiError\";\nimport { UnknownError } from \"../client/UnknownError\";\n\n/**\n * Wraps a fetch plugin so that all errors (including when statusCode is not in the 200s) are converted to either PalantirApiError or UnknownError.\n *\n * If the returned promise does not have an error state, you are free to immediately call `.json()` or equivalent.\n *\n * @param fetchFn\n * @returns\n */\nexport function createFetchOrThrow(fetchFn = fetch) {\n return async function fetchOrThrow(url, requestInit) {\n let response;\n try {\n response = await fetchFn(url, requestInit);\n } catch (e) {\n throw convertError(e, \"A network error occured\");\n }\n if (!response.ok) {\n let body;\n try {\n body = await response.json();\n } catch (e) {\n throw convertError(e, \"A network error occured while reading response\");\n }\n throw new PalantirApiError(body?.message ?? `Failed to fetch ${response.status} ${response.statusText}`, body?.errorName, body?.errorCode, response.status, body?.errorInstanceId, body?.parameters);\n }\n return response;\n };\n}\nfunction convertError(e, msgIfNotError = \"An unknown error occurred\") {\n if (e instanceof Error) {\n return new UnknownError(e.message, \"UNKNOWN\", e);\n }\n return new UnknownError(msgIfNotError, \"UNKNOWN\");\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport fetchRetry from \"fetch-retry\";\nimport { PalantirApiError } from \"../client/PalantirApiError\";\nconst INITIAL_DELAY = 1_000;\nconst JITTER_FACTOR = 0.5;\nconst MAX_RETRIES = 3;\nexport function createRetryingFetch(fetch) {\n return fetchRetry(fetch, {\n retryDelay(attempt) {\n const delay = INITIAL_DELAY * 2 ** attempt;\n const jitter = delay * JITTER_FACTOR * (Math.random() * 2 - 1);\n return delay + jitter;\n },\n retryOn(attempt, error, response) {\n const status = response?.status ?? 0;\n return !(status >= 200 && status < 300) && isRetryable(error) && attempt < MAX_RETRIES;\n }\n });\n}\nfunction isRetryable(e) {\n if (e instanceof PalantirApiError) {\n if (e.statusCode !== SERVICE_UNAVAILABLE && e.statusCode !== TOO_MANY_REQUESTS) {\n return false;\n }\n }\n return true; // I think this logic is flawed?\n}\n\nconst SERVICE_UNAVAILABLE = 503;\nconst TOO_MANY_REQUESTS = 429;","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport function stringifyBody(body) {\n return body != null ? JSON.stringify(body) : undefined;\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createFetchHeaderMutator } from \"./createFetchHeaderMutator\";\nimport { stringifyBody } from \"./stringifyBody\";\n\n/**\n * Fetches the given URL, converting the body to JSON, setting the Content-Type header to application/json,\n * and calling .json() on the response.\n */\n\n/**\n * Wraps a fetch function to set the Content-Type header to application/json, to handle JSON.stringify(),\n * and to parse the response as JSON.\n *\n * @param fetchFn The fetch function to wrap\n * @returns\n */\nexport function createFetchAsJson(fetchFn = fetch) {\n fetchFn = createFetchHeaderMutator(fetchFn, headers => {\n headers.set(\"Content-Type\", \"application/json\");\n return headers;\n });\n return async function fetchAsJson(url, requestInit) {\n return (await fetchFn(url, {\n ...requestInit,\n body: stringifyBody(requestInit.body)\n // TODO fix headers\n })).json();\n };\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createFetchAsJson, createFetchHeaderMutator, createFetchOrThrow, createRetryingFetch } from \"#util\";\n/**\n * The goal of the thin client is to provide a way to tree shake as much as possible.\n */\n\nexport function createThinClient(ontology, stack, tokenProvider, fetchFn = fetch) {\n const retryingFetchWithAuthOrThrow = createFetchHeaderMutator(createRetryingFetch(createFetchOrThrow(fetchFn)), async headers => {\n const token = await tokenProvider();\n headers.set(\"Authorization\", `Bearer ${token}`);\n headers.set(\"Fetch-User-Agent\", ontology.metadata.userAgent);\n return headers;\n });\n return {\n ontology,\n stack,\n fetch: retryingFetchWithAuthOrThrow,\n fetchJson: createFetchAsJson(retryingFetchWithAuthOrThrow)\n };\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { modernToLegacyWhereClause } from \"#client/converters\";\nimport { aggregateOrThrow, fetchPageOrThrow } from \"../object\";\nconst searchAroundPrefix = \"searchAround_\";\nexport function createObjectSet(objectType, thinClient, opts, objectSet = {\n type: \"base\",\n objectType\n}) {\n const base = {\n aggregate: req => {\n throw \"TODO\";\n },\n aggregateOrThrow: async req => {\n return aggregateOrThrow(thinClient, objectType, req);\n },\n fetchPage: async args => {\n throw \"TODO\";\n },\n fetchPageOrThrow: async args => {\n return fetchPageOrThrow(thinClient, objectType, args ?? {}, objectSet);\n },\n asyncIter: () => {\n throw \"\";\n },\n where: clause => {\n return createObjectSet(objectType, thinClient, opts, {\n type: \"filter\",\n objectSet: objectSet,\n where: modernToLegacyWhereClause(clause)\n });\n },\n [Symbol.asyncIterator]: () => {\n throw \"\";\n },\n pivotTo: function (type, opts) {\n return createSearchAround(type)().where(opts?.$where ?? {});\n }\n };\n function createSearchAround(link) {\n return () => {\n return createObjectSet(objectType, thinClient, {}, {\n type: \"searchAround\",\n objectSet,\n link\n });\n };\n }\n return new Proxy(base, {\n get(target, p, receiver) {\n if (typeof p === \"string\" && p.startsWith(searchAroundPrefix)) {\n return createSearchAround(p.substring(searchAroundPrefix.length));\n }\n return target[p];\n }\n });\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * A type that creates an object set for each object in the ontology.\n */\n\n/**\n * Create a proxy for the object set creator.\n * @param client The client to use to create the object sets.\n * @returns A proxy for the object set creator.\n */\nexport function createObjectSetCreator(client) {\n return new Proxy({}, {\n get: (target, p, receiver) => {\n if (typeof p === \"string\") return client.objectSet(p);\n return undefined;\n }\n });\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createThinClient } from \"./createThinClient\";\nimport { createObjectSet } from \"./objectSet/createObjectSet\";\nimport { createObjectSetCreator } from \"./ObjectSetCreator\";\nexport function createClient(ontology, stack, tokenProvider, fetchFn = fetch) {\n const thinClient = createThinClient(ontology, stack, tokenProvider, fetchFn);\n const objectSetFactory = (type, opts) => createObjectSet(type, thinClient, opts);\n const client = Object.defineProperties({}, {\n objectSet: {\n get: () => objectSetFactory\n },\n objects: {\n get: () => createObjectSetCreator(client)\n }\n });\n return client;\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport function isOk(result) {\n return result.type === \"ok\";\n}"]}
|
|
1
|
+
{"version":3,"sources":["../../src/client/UnknownError.ts","../../src/util/createFetchOrThrow.ts","../../src/util/stringifyBody.ts","../../src/util/FetchAsJson.ts","../../src/client/createThinClient.ts","../../src/client/objectSet/createObjectSet.ts","../../src/client/ObjectSetCreator.ts","../../src/client/createClient.ts","../../src/client/ResultOrError.ts"],"names":["UnknownError","PalantirApiError","message","errorType","originalError","createFetchOrThrow","fetchFn","url","requestInit","response","e","convertError","body","msgIfNotError","stringifyBody","createFetchAsJson","createFetchHeaderMutator","headers","createThinClient","ontology","stack","tokenProvider","retryingFetchWithAuthOrThrow","createRetryingFetch","token","searchAroundPrefix","createObjectSet","objectType","thinClient","opts","objectSet","base","req","aggregateOrThrow","args","fetchPageOrThrow","clause","modernToLegacyWhereClause","type","createSearchAround","link","target","p","receiver","createObjectSetCreator","client","createClient","objectSetFactory","isOk","result"],"mappings":"sJAiBO,IAAMA,EAAN,cAA2BC,CAAiB,CACjD,YAAYC,EAASC,EAAWC,EAAe,CAC7C,MAAMF,EAASC,CAAS,EACxB,KAAK,cAAgBC,CACvB,CACF,ECKO,SAASC,EAAmBC,EAAU,MAAO,CAClD,OAAO,eAA4BC,EAAKC,EAAa,CACnD,IAAIC,EACJ,GAAI,CACFA,EAAW,MAAMH,EAAQC,EAAKC,CAAW,CAC3C,OAASE,EAAG,CACV,MAAMC,EAAaD,EAAG,yBAAyB,CACjD,CACA,GAAI,CAACD,EAAS,GAAI,CAChB,IAAIG,EACJ,GAAI,CACFA,EAAO,MAAMH,EAAS,KAAK,CAC7B,OAAS,EAAG,CACV,MAAME,EAAa,EAAG,gDAAgD,CACxE,CACA,MAAM,IAAIV,EAAiBW,GAAM,SAAW,mBAAmBH,EAAS,MAAM,IAAIA,EAAS,UAAU,GAAIG,GAAM,UAAWA,GAAM,UAAWH,EAAS,OAAQG,GAAM,gBAAiBA,GAAM,UAAU,CACrM,CACA,OAA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 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PalantirApiError } from \"./PalantirApiError\";\nexport class UnknownError extends PalantirApiError {\n constructor(message, errorType, originalError) {\n super(message, errorType);\n this.originalError = originalError;\n }\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PalantirApiError } from \"../client/PalantirApiError\";\nimport { UnknownError } from \"../client/UnknownError\";\n\n/**\n * Wraps a fetch plugin so that all errors (including when statusCode is not in the 200s) are converted to either PalantirApiError or UnknownError.\n *\n * If the returned promise does not have an error state, you are free to immediately call `.json()` or equivalent.\n *\n * @param fetchFn\n * @returns\n */\nexport function createFetchOrThrow(fetchFn = fetch) {\n return async function fetchOrThrow(url, requestInit) {\n let response;\n try {\n response = await fetchFn(url, requestInit);\n } catch (e) {\n throw convertError(e, \"A network error occured\");\n }\n if (!response.ok) {\n let body;\n try {\n body = await response.json();\n } catch (e) {\n throw convertError(e, \"A network error occured while reading response\");\n }\n throw new PalantirApiError(body?.message ?? `Failed to fetch ${response.status} ${response.statusText}`, body?.errorName, body?.errorCode, response.status, body?.errorInstanceId, body?.parameters);\n }\n return response;\n };\n}\nfunction convertError(e, msgIfNotError = \"An unknown error occurred\") {\n if (e instanceof Error) {\n return new UnknownError(e.message, \"UNKNOWN\", e);\n }\n return new UnknownError(msgIfNotError, \"UNKNOWN\");\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport function stringifyBody(body) {\n return body != null ? JSON.stringify(body) : undefined;\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createFetchHeaderMutator } from \"./createFetchHeaderMutator\";\nimport { stringifyBody } from \"./stringifyBody\";\n\n/**\n * Fetches the given URL, converting the body to JSON, setting the Content-Type header to application/json,\n * and calling .json() on the response.\n */\n\n/**\n * Wraps a fetch function to set the Content-Type header to application/json, to handle JSON.stringify(),\n * and to parse the response as JSON.\n *\n * @param fetchFn The fetch function to wrap\n * @returns\n */\nexport function createFetchAsJson(fetchFn = fetch) {\n fetchFn = createFetchHeaderMutator(fetchFn, headers => {\n headers.set(\"Content-Type\", \"application/json\");\n return headers;\n });\n return async function fetchAsJson(url, requestInit) {\n return (await fetchFn(url, {\n ...requestInit,\n body: stringifyBody(requestInit.body)\n // TODO fix headers\n })).json();\n };\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createFetchAsJson, createFetchHeaderMutator, createFetchOrThrow, createRetryingFetch } from \"../util\";\n/**\n * The goal of the thin client is to provide a way to tree shake as much as possible.\n */\n\nexport function createThinClient(ontology, stack, tokenProvider, fetchFn = fetch) {\n const retryingFetchWithAuthOrThrow = createFetchHeaderMutator(createRetryingFetch(createFetchOrThrow(fetchFn)), async headers => {\n const token = await tokenProvider();\n headers.set(\"Authorization\", `Bearer ${token}`);\n headers.set(\"Fetch-User-Agent\", ontology.metadata.userAgent);\n return headers;\n });\n return {\n ontology,\n stack,\n fetch: retryingFetchWithAuthOrThrow,\n fetchJson: createFetchAsJson(retryingFetchWithAuthOrThrow)\n };\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { modernToLegacyWhereClause } from \"../internal/conversions\";\nimport { aggregateOrThrow, fetchPageOrThrow } from \"../object\";\nconst searchAroundPrefix = \"searchAround_\";\nexport function createObjectSet(objectType, thinClient, opts, objectSet = {\n type: \"base\",\n objectType\n}) {\n const base = {\n aggregate: req => {\n throw \"TODO\";\n },\n aggregateOrThrow: async req => {\n return aggregateOrThrow(thinClient, objectType, req);\n },\n fetchPage: async args => {\n throw \"TODO\";\n },\n fetchPageOrThrow: async args => {\n return fetchPageOrThrow(thinClient, objectType, args ?? {}, objectSet);\n },\n asyncIter: () => {\n throw \"\";\n },\n where: clause => {\n return createObjectSet(objectType, thinClient, opts, {\n type: \"filter\",\n objectSet: objectSet,\n where: modernToLegacyWhereClause(clause)\n });\n },\n [Symbol.asyncIterator]: () => {\n throw \"\";\n },\n pivotTo: function (type, opts) {\n return createSearchAround(type)().where(opts?.$where ?? {});\n }\n };\n function createSearchAround(link) {\n return () => {\n return createObjectSet(objectType, thinClient, {}, {\n type: \"searchAround\",\n objectSet,\n link\n });\n };\n }\n return new Proxy(base, {\n get(target, p, receiver) {\n if (typeof p === \"string\" && p.startsWith(searchAroundPrefix)) {\n return createSearchAround(p.substring(searchAroundPrefix.length));\n }\n return target[p];\n }\n });\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * A type that creates an object set for each object in the ontology.\n */\n\n/**\n * Create a proxy for the object set creator.\n * @param client The client to use to create the object sets.\n * @returns A proxy for the object set creator.\n */\nexport function createObjectSetCreator(client) {\n return new Proxy({}, {\n get: (target, p, receiver) => {\n if (typeof p === \"string\") return client.objectSet(p);\n return undefined;\n }\n });\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createThinClient } from \"./createThinClient\";\nimport { createObjectSet } from \"./objectSet/createObjectSet\";\nimport { createObjectSetCreator } from \"./ObjectSetCreator\";\nexport function createClient(ontology, stack, tokenProvider, fetchFn = fetch) {\n const thinClient = createThinClient(ontology, stack, tokenProvider, fetchFn);\n const objectSetFactory = (type, opts) => createObjectSet(type, thinClient, opts);\n const client = Object.defineProperties({}, {\n objectSet: {\n get: () => objectSetFactory\n },\n objects: {\n get: () => createObjectSetCreator(client)\n }\n });\n return client;\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport function isOk(result) {\n return result.type === \"ok\";\n}"]}
|
package/build/js/index.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
import b from '
|
|
1
|
+
import { c as c$1, d, a as a$1 } from './chunk-TPXDMNRT.mjs';
|
|
2
|
+
export { e as Objects, b as createOpenApiRequest } from './chunk-TPXDMNRT.mjs';
|
|
3
|
+
import { a, c, b as b$1 } from './chunk-BZ6L26S2.mjs';
|
|
4
|
+
import './chunk-XIJ2ZQRX.mjs';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
var f=class extends b$1{constructor(t,c,n){super(t,c),this.originalError=n;}};function g(r=fetch){return async function(c,n){let a;try{a=await r(c,n);}catch(o){throw A(o,"A network error occured")}if(!a.ok){let o;try{o=await a.json();}catch(e){throw A(e,"A network error occured while reading response")}throw new b$1(o?.message??`Failed to fetch ${a.status} ${a.statusText}`,o?.errorName,o?.errorCode,a.status,o?.errorInstanceId,o?.parameters)}return a}}function A(r,t="An unknown error occurred"){return r instanceof Error?new f(r.message,"UNKNOWN",r):new f(t,"UNKNOWN")}function w(r){return r!=null?JSON.stringify(r):void 0}function y(r=fetch){return r=a(r,t=>(t.set("Content-Type","application/json"),t)),async function(c,n){return (await r(c,{...n,body:w(n.body)})).json()}}function h(r,t,c$1,n=fetch){let a$1=a(c(g(n)),async o=>{let e=await c$1();return o.set("Authorization",`Bearer ${e}`),o.set("Fetch-User-Agent",r.metadata.userAgent),o});return {ontology:r,stack:t,fetch:a$1,fetchJson:y(a$1)}}var T="searchAround_";function p(r,t,c,n={type:"base",objectType:r}){let a={aggregate:e=>{throw "TODO"},aggregateOrThrow:async e=>c$1(t,r,e),fetchPage:async e=>{throw "TODO"},fetchPageOrThrow:async e=>d(t,r,e??{},n),asyncIter:()=>{throw ""},where:e=>p(r,t,c,{type:"filter",objectSet:n,where:a$1(e)}),[Symbol.asyncIterator]:()=>{throw ""},pivotTo:function(e,i){return o(e)().where(i?.$where??{})}};function o(e){return ()=>p(r,t,{},{type:"searchAround",objectSet:n,link:e})}return new Proxy(a,{get(e,i,O){return typeof i=="string"&&i.startsWith(T)?o(i.substring(T.length)):e[i]}})}function F(r){return new Proxy({},{get:(t,c,n)=>{if(typeof c=="string")return r.objectSet(c)}})}function b(r,t,c,n=fetch){let a=h(r,t,c,n),o=(i,O)=>p(i,a,O),e=Object.defineProperties({},{objectSet:{get:()=>o},objects:{get:()=>F(e)}});return e}function C(r){return r.type==="ok"}
|
|
6
7
|
|
|
7
|
-
export {
|
|
8
|
+
export { b as createClient, h as createThinClient, C as isOk };
|
|
8
9
|
//# sourceMappingURL=out.js.map
|
|
9
10
|
//# sourceMappingURL=index.mjs.map
|
package/build/js/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/createFetchHeaderMutator.ts","../../src/client/PalantirApiError.ts","../../src/client/UnknownError.ts","../../src/util/createFetchOrThrow.ts","../../src/util/createRetryingFetch.ts","../../src/util/stringifyBody.ts","../../src/util/FetchAsJson.ts","../../src/client/createThinClient.ts","../../src/client/objectSet/createObjectSet.ts","../../src/client/ObjectSetCreator.ts","../../src/client/createClient.ts","../../src/client/ResultOrError.ts"],"names":["createFetchHeaderMutator","fetchFn","mutator","url","requestInit","PalantirApiError","message","errorName","errorType","statusCode","errorInstanceId","parameters","UnknownError","originalError","createFetchOrThrow","response","e","convertError","body","msgIfNotError","fetchRetry","INITIAL_DELAY","JITTER_FACTOR","MAX_RETRIES","createRetryingFetch","fetch","attempt","delay","jitter","error","status","isRetryable","SERVICE_UNAVAILABLE","TOO_MANY_REQUESTS","stringifyBody","createFetchAsJson","headers","createThinClient","ontology","stack","tokenProvider","retryingFetchWithAuthOrThrow","token","searchAroundPrefix","createObjectSet","objectType","thinClient","opts","objectSet","base","req","aggregateOrThrow","args","fetchPageOrThrow","clause","modernToLegacyWhereClause","type","createSearchAround","link","target","p","receiver","createObjectSetCreator","client","createClient","objectSetFactory","isOk","result"],"mappings":"8DAgBO,SAASA,EAAyBC,EAAU,MAAOC,EAAS,CACjE,OAAO,eAAkCC,EAAKC,EAAa,CACzD,OAAKA,EAKEH,EAAQE,EAAK,CAClB,GAAGC,EACH,QAAS,MAAMF,EAAQ,IAAI,QAAQE,EAAY,OAAO,CAAC,CACzD,CAAC,EAPQH,EAAQE,EAAK,CAClB,QAAS,MAAMD,EAAQ,IAAI,OAAS,CACtC,CAAC,CAML,CACF,CCZO,IAAMG,EAAN,cAA+B,KAAM,CAC1C,YAAYC,EAASC,EAAWC,EAAWC,EAAYC,EAAiBC,EAAY,CAClF,MAAML,CAAO,EACb,KAAK,QAAUA,EACf,KAAK,UAAYC,EACjB,KAAK,UAAYC,EACjB,KAAK,WAAaC,EACl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/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport function createFetchHeaderMutator(fetchFn = fetch, mutator) {\n return async function headerMutatedFetch(url, requestInit) {\n if (!requestInit) {\n return fetchFn(url, {\n headers: await mutator(new Headers())\n });\n }\n return fetchFn(url, {\n ...requestInit,\n headers: await mutator(new Headers(requestInit.headers))\n });\n };\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport class PalantirApiError extends Error {\n constructor(message, errorName, errorType, statusCode, errorInstanceId, parameters) {\n super(message);\n this.message = message;\n this.errorName = errorName;\n this.errorType = errorType;\n this.statusCode = statusCode;\n this.errorInstanceId = errorInstanceId;\n this.parameters = parameters;\n }\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PalantirApiError } from \"./PalantirApiError\";\nexport class UnknownError extends PalantirApiError {\n constructor(message, errorType, originalError) {\n super(message, errorType);\n this.originalError = originalError;\n }\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PalantirApiError } from \"../client/PalantirApiError\";\nimport { UnknownError } from \"../client/UnknownError\";\n\n/**\n * Wraps a fetch plugin so that all errors (including when statusCode is not in the 200s) are converted to either PalantirApiError or UnknownError.\n *\n * If the returned promise does not have an error state, you are free to immediately call `.json()` or equivalent.\n *\n * @param fetchFn\n * @returns\n */\nexport function createFetchOrThrow(fetchFn = fetch) {\n return async function fetchOrThrow(url, requestInit) {\n let response;\n try {\n response = await fetchFn(url, requestInit);\n } catch (e) {\n throw convertError(e, \"A network error occured\");\n }\n if (!response.ok) {\n let body;\n try {\n body = await response.json();\n } catch (e) {\n throw convertError(e, \"A network error occured while reading response\");\n }\n throw new PalantirApiError(body?.message ?? `Failed to fetch ${response.status} ${response.statusText}`, body?.errorName, body?.errorCode, response.status, body?.errorInstanceId, body?.parameters);\n }\n return response;\n };\n}\nfunction convertError(e, msgIfNotError = \"An unknown error occurred\") {\n if (e instanceof Error) {\n return new UnknownError(e.message, \"UNKNOWN\", e);\n }\n return new UnknownError(msgIfNotError, \"UNKNOWN\");\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport fetchRetry from \"fetch-retry\";\nimport { PalantirApiError } from \"../client/PalantirApiError\";\nconst INITIAL_DELAY = 1_000;\nconst JITTER_FACTOR = 0.5;\nconst MAX_RETRIES = 3;\nexport function createRetryingFetch(fetch) {\n return fetchRetry(fetch, {\n retryDelay(attempt) {\n const delay = INITIAL_DELAY * 2 ** attempt;\n const jitter = delay * JITTER_FACTOR * (Math.random() * 2 - 1);\n return delay + jitter;\n },\n retryOn(attempt, error, response) {\n const status = response?.status ?? 0;\n return !(status >= 200 && status < 300) && isRetryable(error) && attempt < MAX_RETRIES;\n }\n });\n}\nfunction isRetryable(e) {\n if (e instanceof PalantirApiError) {\n if (e.statusCode !== SERVICE_UNAVAILABLE && e.statusCode !== TOO_MANY_REQUESTS) {\n return false;\n }\n }\n return true; // I think this logic is flawed?\n}\n\nconst SERVICE_UNAVAILABLE = 503;\nconst TOO_MANY_REQUESTS = 429;","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport function stringifyBody(body) {\n return body != null ? JSON.stringify(body) : undefined;\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createFetchHeaderMutator } from \"./createFetchHeaderMutator\";\nimport { stringifyBody } from \"./stringifyBody\";\n\n/**\n * Fetches the given URL, converting the body to JSON, setting the Content-Type header to application/json,\n * and calling .json() on the response.\n */\n\n/**\n * Wraps a fetch function to set the Content-Type header to application/json, to handle JSON.stringify(),\n * and to parse the response as JSON.\n *\n * @param fetchFn The fetch function to wrap\n * @returns\n */\nexport function createFetchAsJson(fetchFn = fetch) {\n fetchFn = createFetchHeaderMutator(fetchFn, headers => {\n headers.set(\"Content-Type\", \"application/json\");\n return headers;\n });\n return async function fetchAsJson(url, requestInit) {\n return (await fetchFn(url, {\n ...requestInit,\n body: stringifyBody(requestInit.body)\n // TODO fix headers\n })).json();\n };\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createFetchAsJson, createFetchHeaderMutator, createFetchOrThrow, createRetryingFetch } from \"#util\";\n/**\n * The goal of the thin client is to provide a way to tree shake as much as possible.\n */\n\nexport function createThinClient(ontology, stack, tokenProvider, fetchFn = fetch) {\n const retryingFetchWithAuthOrThrow = createFetchHeaderMutator(createRetryingFetch(createFetchOrThrow(fetchFn)), async headers => {\n const token = await tokenProvider();\n headers.set(\"Authorization\", `Bearer ${token}`);\n headers.set(\"Fetch-User-Agent\", ontology.metadata.userAgent);\n return headers;\n });\n return {\n ontology,\n stack,\n fetch: retryingFetchWithAuthOrThrow,\n fetchJson: createFetchAsJson(retryingFetchWithAuthOrThrow)\n };\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { modernToLegacyWhereClause } from \"#client/converters\";\nimport { aggregateOrThrow, fetchPageOrThrow } from \"../object\";\nconst searchAroundPrefix = \"searchAround_\";\nexport function createObjectSet(objectType, thinClient, opts, objectSet = {\n type: \"base\",\n objectType\n}) {\n const base = {\n aggregate: req => {\n throw \"TODO\";\n },\n aggregateOrThrow: async req => {\n return aggregateOrThrow(thinClient, objectType, req);\n },\n fetchPage: async args => {\n throw \"TODO\";\n },\n fetchPageOrThrow: async args => {\n return fetchPageOrThrow(thinClient, objectType, args ?? {}, objectSet);\n },\n asyncIter: () => {\n throw \"\";\n },\n where: clause => {\n return createObjectSet(objectType, thinClient, opts, {\n type: \"filter\",\n objectSet: objectSet,\n where: modernToLegacyWhereClause(clause)\n });\n },\n [Symbol.asyncIterator]: () => {\n throw \"\";\n },\n pivotTo: function (type, opts) {\n return createSearchAround(type)().where(opts?.$where ?? {});\n }\n };\n function createSearchAround(link) {\n return () => {\n return createObjectSet(objectType, thinClient, {}, {\n type: \"searchAround\",\n objectSet,\n link\n });\n };\n }\n return new Proxy(base, {\n get(target, p, receiver) {\n if (typeof p === \"string\" && p.startsWith(searchAroundPrefix)) {\n return createSearchAround(p.substring(searchAroundPrefix.length));\n }\n return target[p];\n }\n });\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * A type that creates an object set for each object in the ontology.\n */\n\n/**\n * Create a proxy for the object set creator.\n * @param client The client to use to create the object sets.\n * @returns A proxy for the object set creator.\n */\nexport function createObjectSetCreator(client) {\n return new Proxy({}, {\n get: (target, p, receiver) => {\n if (typeof p === \"string\") return client.objectSet(p);\n return undefined;\n }\n });\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createThinClient } from \"./createThinClient\";\nimport { createObjectSet } from \"./objectSet/createObjectSet\";\nimport { createObjectSetCreator } from \"./ObjectSetCreator\";\nexport function createClient(ontology, stack, tokenProvider, fetchFn = fetch) {\n const thinClient = createThinClient(ontology, stack, tokenProvider, fetchFn);\n const objectSetFactory = (type, opts) => createObjectSet(type, thinClient, opts);\n const client = Object.defineProperties({}, {\n objectSet: {\n get: () => objectSetFactory\n },\n objects: {\n get: () => createObjectSetCreator(client)\n }\n });\n return client;\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport function isOk(result) {\n return result.type === \"ok\";\n}"]}
|
|
1
|
+
{"version":3,"sources":["../../src/client/UnknownError.ts","../../src/util/createFetchOrThrow.ts","../../src/util/stringifyBody.ts","../../src/util/FetchAsJson.ts","../../src/client/createThinClient.ts","../../src/client/objectSet/createObjectSet.ts","../../src/client/ObjectSetCreator.ts","../../src/client/createClient.ts","../../src/client/ResultOrError.ts"],"names":["UnknownError","PalantirApiError","message","errorType","originalError","createFetchOrThrow","fetchFn","url","requestInit","response","e","convertError","body","msgIfNotError","stringifyBody","createFetchAsJson","createFetchHeaderMutator","headers","createThinClient","ontology","stack","tokenProvider","retryingFetchWithAuthOrThrow","createRetryingFetch","token","searchAroundPrefix","createObjectSet","objectType","thinClient","opts","objectSet","base","req","aggregateOrThrow","args","fetchPageOrThrow","clause","modernToLegacyWhereClause","type","createSearchAround","link","target","p","receiver","createObjectSetCreator","client","createClient","objectSetFactory","isOk","result"],"mappings":"yJAiBO,IAAMA,EAAN,cAA2BC,CAAiB,CACjD,YAAYC,EAASC,EAAWC,EAAe,CAC7C,MAAMF,EAASC,CAAS,EACxB,KAAK,cAAgBC,CACvB,CACF,ECKO,SAASC,EAAmBC,EAAU,MAAO,CAClD,OAAO,eAA4BC,EAAKC,EAAa,CACnD,IAAIC,EACJ,GAAI,CACFA,EAAW,MAAMH,EAAQC,EAAKC,CAAW,CAC3C,OAASE,EAAG,CACV,MAAMC,EAAaD,EAAG,yBAAyB,CACjD,CACA,GAAI,CAACD,EAAS,GAAI,CAChB,IAAIG,EACJ,GAAI,CACFA,EAAO,MAAMH,EAAS,KAAK,CAC7B,OAAS,EAAG,CACV,MAAME,EAAa,EAAG,gDAAgD,CACxE,CACA,MAAM,IAAIV,EAAiBW,GAAM,SAAW,mBAAmBH,EAAS,MAAM,I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,CAAC,EACD,OAAOA,CACT,CCfO,SAASG,EAAKC,EAAQ,CAC3B,OAAOA,EAAO,OAAS,IACzB","sourcesContent":["/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PalantirApiError } from \"./PalantirApiError\";\nexport class UnknownError extends PalantirApiError {\n constructor(message, errorType, originalError) {\n super(message, errorType);\n this.originalError = originalError;\n }\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PalantirApiError } from \"../client/PalantirApiError\";\nimport { UnknownError } from \"../client/UnknownError\";\n\n/**\n * Wraps a fetch plugin so that all errors (including when statusCode is not in the 200s) are converted to either PalantirApiError or UnknownError.\n *\n * If the returned promise does not have an error state, you are free to immediately call `.json()` or equivalent.\n *\n * @param fetchFn\n * @returns\n */\nexport function createFetchOrThrow(fetchFn = fetch) {\n return async function fetchOrThrow(url, requestInit) {\n let response;\n try {\n response = await fetchFn(url, requestInit);\n } catch (e) {\n throw convertError(e, \"A network error occured\");\n }\n if (!response.ok) {\n let body;\n try {\n body = await response.json();\n } catch (e) {\n throw convertError(e, \"A network error occured while reading response\");\n }\n throw new PalantirApiError(body?.message ?? `Failed to fetch ${response.status} ${response.statusText}`, body?.errorName, body?.errorCode, response.status, body?.errorInstanceId, body?.parameters);\n }\n return response;\n };\n}\nfunction convertError(e, msgIfNotError = \"An unknown error occurred\") {\n if (e instanceof Error) {\n return new UnknownError(e.message, \"UNKNOWN\", e);\n }\n return new UnknownError(msgIfNotError, \"UNKNOWN\");\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport function stringifyBody(body) {\n return body != null ? JSON.stringify(body) : undefined;\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createFetchHeaderMutator } from \"./createFetchHeaderMutator\";\nimport { stringifyBody } from \"./stringifyBody\";\n\n/**\n * Fetches the given URL, converting the body to JSON, setting the Content-Type header to application/json,\n * and calling .json() on the response.\n */\n\n/**\n * Wraps a fetch function to set the Content-Type header to application/json, to handle JSON.stringify(),\n * and to parse the response as JSON.\n *\n * @param fetchFn The fetch function to wrap\n * @returns\n */\nexport function createFetchAsJson(fetchFn = fetch) {\n fetchFn = createFetchHeaderMutator(fetchFn, headers => {\n headers.set(\"Content-Type\", \"application/json\");\n return headers;\n });\n return async function fetchAsJson(url, requestInit) {\n return (await fetchFn(url, {\n ...requestInit,\n body: stringifyBody(requestInit.body)\n // TODO fix headers\n })).json();\n };\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createFetchAsJson, createFetchHeaderMutator, createFetchOrThrow, createRetryingFetch } from \"../util\";\n/**\n * The goal of the thin client is to provide a way to tree shake as much as possible.\n */\n\nexport function createThinClient(ontology, stack, tokenProvider, fetchFn = fetch) {\n const retryingFetchWithAuthOrThrow = createFetchHeaderMutator(createRetryingFetch(createFetchOrThrow(fetchFn)), async headers => {\n const token = await tokenProvider();\n headers.set(\"Authorization\", `Bearer ${token}`);\n headers.set(\"Fetch-User-Agent\", ontology.metadata.userAgent);\n return headers;\n });\n return {\n ontology,\n stack,\n fetch: retryingFetchWithAuthOrThrow,\n fetchJson: createFetchAsJson(retryingFetchWithAuthOrThrow)\n };\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { modernToLegacyWhereClause } from \"../internal/conversions\";\nimport { aggregateOrThrow, fetchPageOrThrow } from \"../object\";\nconst searchAroundPrefix = \"searchAround_\";\nexport function createObjectSet(objectType, thinClient, opts, objectSet = {\n type: \"base\",\n objectType\n}) {\n const base = {\n aggregate: req => {\n throw \"TODO\";\n },\n aggregateOrThrow: async req => {\n return aggregateOrThrow(thinClient, objectType, req);\n },\n fetchPage: async args => {\n throw \"TODO\";\n },\n fetchPageOrThrow: async args => {\n return fetchPageOrThrow(thinClient, objectType, args ?? {}, objectSet);\n },\n asyncIter: () => {\n throw \"\";\n },\n where: clause => {\n return createObjectSet(objectType, thinClient, opts, {\n type: \"filter\",\n objectSet: objectSet,\n where: modernToLegacyWhereClause(clause)\n });\n },\n [Symbol.asyncIterator]: () => {\n throw \"\";\n },\n pivotTo: function (type, opts) {\n return createSearchAround(type)().where(opts?.$where ?? {});\n }\n };\n function createSearchAround(link) {\n return () => {\n return createObjectSet(objectType, thinClient, {}, {\n type: \"searchAround\",\n objectSet,\n link\n });\n };\n }\n return new Proxy(base, {\n get(target, p, receiver) {\n if (typeof p === \"string\" && p.startsWith(searchAroundPrefix)) {\n return createSearchAround(p.substring(searchAroundPrefix.length));\n }\n return target[p];\n }\n });\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * A type that creates an object set for each object in the ontology.\n */\n\n/**\n * Create a proxy for the object set creator.\n * @param client The client to use to create the object sets.\n * @returns A proxy for the object set creator.\n */\nexport function createObjectSetCreator(client) {\n return new Proxy({}, {\n get: (target, p, receiver) => {\n if (typeof p === \"string\") return client.objectSet(p);\n return undefined;\n }\n });\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createThinClient } from \"./createThinClient\";\nimport { createObjectSet } from \"./objectSet/createObjectSet\";\nimport { createObjectSetCreator } from \"./ObjectSetCreator\";\nexport function createClient(ontology, stack, tokenProvider, fetchFn = fetch) {\n const thinClient = createThinClient(ontology, stack, tokenProvider, fetchFn);\n const objectSetFactory = (type, opts) => createObjectSet(type, thinClient, opts);\n const client = Object.defineProperties({}, {\n objectSet: {\n get: () => objectSetFactory\n },\n objects: {\n get: () => createObjectSetCreator(client)\n }\n });\n return client;\n}","/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport function isOk(result) {\n return result.type === \"ok\";\n}"]}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkSM47N47Q_js = require('../chunk-SM47N47Q.js');
|
|
4
|
+
require('../chunk-4D6JZ4TL.js');
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
Object.defineProperty(exports, 'aggregateOrThrow', {
|
|
8
9
|
enumerable: true,
|
|
9
|
-
get: function () { return
|
|
10
|
+
get: function () { return chunkSM47N47Q_js.c; }
|
|
10
11
|
});
|
|
11
12
|
Object.defineProperty(exports, 'fetchPageOrThrow', {
|
|
12
13
|
enumerable: true,
|
|
13
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunkSM47N47Q_js.d; }
|
|
14
15
|
});
|
|
15
16
|
//# sourceMappingURL=out.js.map
|
|
16
17
|
//# sourceMappingURL=objects.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { c as aggregateOrThrow, d as fetchPageOrThrow } from '../chunk-TPXDMNRT.mjs';
|
|
2
|
+
import '../chunk-XIJ2ZQRX.mjs';
|
|
2
3
|
//# sourceMappingURL=out.js.map
|
|
3
4
|
//# sourceMappingURL=objects.mjs.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkSHYKLQMU_js = require('../chunk-SHYKLQMU.js');
|
|
4
|
+
require('../chunk-4D6JZ4TL.js');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, 'createFetchHeaderMutator', {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return chunkSHYKLQMU_js.a; }
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, 'createRetryingFetch', {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return chunkSHYKLQMU_js.c; }
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=out.js.map
|
|
17
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ObjectTypesFrom, OntologyDefinition } from "
|
|
1
|
+
import type { ObjectTypesFrom, OntologyDefinition } from "../ontology";
|
|
2
2
|
import type { ObjectSet, ObjectSetOptions } from "./objectSet/ObjectSet";
|
|
3
3
|
import type { ObjectSetCreator } from "./ObjectSetCreator";
|
|
4
4
|
export type ConcreteObjectType<O extends OntologyDefinition<any>, K extends ObjectTypesFrom<O>> = O["objects"][K];
|