@osdk/react 0.10.0-beta.13 → 0.10.0-beta.14
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 +14 -0
- package/build/browser/new/OsdkContext2.js +22 -2
- package/build/browser/new/OsdkContext2.js.map +1 -1
- package/build/browser/new/useOsdkAction.js +2 -6
- package/build/browser/new/useOsdkAction.js.map +1 -1
- package/build/browser/new/useOsdkFunctions.js +137 -0
- package/build/browser/new/useOsdkFunctions.js.map +1 -0
- package/build/browser/public/unstable-do-not-use.js +18 -0
- package/build/browser/public/unstable-do-not-use.js.map +1 -0
- package/build/cjs/chunk-2N32USW5.cjs +28 -0
- package/build/cjs/chunk-2N32USW5.cjs.map +1 -0
- package/build/cjs/chunk-R4FZ5MUH.cjs +34 -0
- package/build/cjs/chunk-R4FZ5MUH.cjs.map +1 -0
- package/build/cjs/{chunk-SVVMLSKN.cjs → chunk-ZUNR45SJ.cjs} +15 -4
- package/build/cjs/chunk-ZUNR45SJ.cjs.map +1 -0
- package/build/cjs/index.cjs +7 -6
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/public/experimental/admin.cjs +11 -11
- package/build/cjs/public/experimental.cjs +30 -33
- package/build/cjs/public/experimental.cjs.map +1 -1
- package/build/cjs/public/experimental.d.cts +4 -120
- package/build/cjs/public/unstable-do-not-use.cjs +114 -0
- package/build/cjs/public/unstable-do-not-use.cjs.map +1 -0
- package/build/cjs/public/unstable-do-not-use.d.cts +35 -0
- package/build/cjs/useOsdkFunction-B0s7lqgN.d.cts +121 -0
- package/build/esm/new/OsdkContext2.js +22 -2
- package/build/esm/new/OsdkContext2.js.map +1 -1
- package/build/esm/new/useOsdkAction.js +2 -6
- package/build/esm/new/useOsdkAction.js.map +1 -1
- package/build/esm/new/useOsdkFunctions.js +137 -0
- package/build/esm/new/useOsdkFunctions.js.map +1 -0
- package/build/esm/public/unstable-do-not-use.js +18 -0
- package/build/esm/public/unstable-do-not-use.js.map +1 -0
- package/build/types/new/OsdkContext2.d.ts +1 -0
- package/build/types/new/OsdkContext2.d.ts.map +1 -1
- package/build/types/new/useOsdkFunctions.d.ts +31 -0
- package/build/types/new/useOsdkFunctions.d.ts.map +1 -0
- package/build/types/public/unstable-do-not-use.d.ts +2 -0
- package/build/types/public/unstable-do-not-use.d.ts.map +1 -0
- package/package.json +14 -5
- package/unstable-do-not-use.d.ts +17 -0
- package/build/cjs/chunk-OVBG5VXE.cjs +0 -50
- package/build/cjs/chunk-OVBG5VXE.cjs.map +0 -1
- package/build/cjs/chunk-SVVMLSKN.cjs.map +0 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { QueryDefinition } from "@osdk/api";
|
|
2
|
+
import type { UseOsdkFunctionOptions, UseOsdkFunctionResult } from "./useOsdkFunction.js";
|
|
3
|
+
export interface FunctionQueryParams<Q extends QueryDefinition<unknown>> {
|
|
4
|
+
queryDefinition: Q;
|
|
5
|
+
/**
|
|
6
|
+
* Only allow params and enabled options at the query level,
|
|
7
|
+
* other options are not yet supported in this batch context
|
|
8
|
+
*/
|
|
9
|
+
options?: Pick<UseOsdkFunctionOptions<Q>, "params" | "enabled">;
|
|
10
|
+
}
|
|
11
|
+
export interface UseOsdkFunctionsProps {
|
|
12
|
+
/**
|
|
13
|
+
* Array of query configurations to execute
|
|
14
|
+
*/
|
|
15
|
+
queries: Array<FunctionQueryParams<QueryDefinition<unknown>>>;
|
|
16
|
+
/**
|
|
17
|
+
* Whether to enable all queries. When false, no queries will execute.
|
|
18
|
+
* Individual query enabled states are also respected.
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
enabled?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export type UseOsdkFunctionsResult = Array<Omit<UseOsdkFunctionResult<QueryDefinition<unknown>>, "refetch">>;
|
|
24
|
+
/**
|
|
25
|
+
* React hook for executing multiple OSDK function queries in parallel.
|
|
26
|
+
* Results are returned in the same order as the input queries.
|
|
27
|
+
*
|
|
28
|
+
* @param options - Configuration options containing the queries to execute
|
|
29
|
+
* @returns Array of results in the same order as input queries, each with the same shape as useOsdkFunction
|
|
30
|
+
*/
|
|
31
|
+
export declare function useOsdkFunctions({ queries, enabled }: UseOsdkFunctionsProps): UseOsdkFunctionsResult;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,cAAmC,uBAAuB,WAAY;AAItE,cACE,wBACA,6BACK,sBAAuB;AAE9B,iBAAiB,oBAAoB,UAAU,0BAA0B;CACvE,iBAAiB;;;;;CAKjB,UAAU,KAAK,uBAAuB,IAAI,WAAW;AACtD;AAED,iBAAiB,sBAAsB;;;;CAIrC,SAAS,MAAM,oBAAoB;;;;;;CAOnC;AACD;AAED,YAAY,yBAAyB,MACnC,KAAK,sBAAsB,2BAA2B;;;;;;;;AAUxD,OAAO,iBAAS,iBACd,EAAE,SAAS,SAAuC,EAArB,wBAC5B","names":[],"sources":["../../../src/new/useOsdkFunctions.ts"],"version":3,"file":"useOsdkFunctions.d.ts"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,SAAS,wBAAwB;AACjC,cACE,qBACA,uBACA,8BACK","names":[],"sources":["../../../src/public/unstable-do-not-use.ts"],"version":3,"file":"unstable-do-not-use.d.ts"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@osdk/react",
|
|
3
|
-
"version": "0.10.0-beta.
|
|
3
|
+
"version": "0.10.0-beta.14",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,6 +25,15 @@
|
|
|
25
25
|
"require": "./build/cjs/public/experimental.cjs",
|
|
26
26
|
"default": "./build/browser/public/experimental.js"
|
|
27
27
|
},
|
|
28
|
+
"./unstable-do-not-use": {
|
|
29
|
+
"browser": "./build/browser/public/unstable-do-not-use.js",
|
|
30
|
+
"import": {
|
|
31
|
+
"types": "./build/types/public/unstable-do-not-use.d.ts",
|
|
32
|
+
"default": "./build/esm/public/unstable-do-not-use.js"
|
|
33
|
+
},
|
|
34
|
+
"require": "./build/cjs/public/unstable-do-not-use.cjs",
|
|
35
|
+
"default": "./build/browser/public/unstable-do-not-use.js"
|
|
36
|
+
},
|
|
28
37
|
"./experimental/admin": {
|
|
29
38
|
"browser": "./build/browser/public/experimental/admin.js",
|
|
30
39
|
"import": {
|
|
@@ -76,11 +85,11 @@
|
|
|
76
85
|
"react": "^18.3.1",
|
|
77
86
|
"tiny-invariant": "^1.3.3",
|
|
78
87
|
"typescript": "~5.5.4",
|
|
79
|
-
"@osdk/
|
|
80
|
-
"@osdk/client": "2.8.0-beta.
|
|
81
|
-
"@osdk/client.test.ontology": "2.8.0-beta.
|
|
88
|
+
"@osdk/monorepo.tsconfig": "~0.7.0-beta.1",
|
|
89
|
+
"@osdk/client": "2.8.0-beta.29",
|
|
90
|
+
"@osdk/client.test.ontology": "2.8.0-beta.29",
|
|
82
91
|
"@osdk/monorepo.api-extractor": "~0.7.0-beta.1",
|
|
83
|
-
"@osdk/
|
|
92
|
+
"@osdk/api": "2.8.0-beta.29"
|
|
84
93
|
},
|
|
85
94
|
"publishConfig": {
|
|
86
95
|
"access": "public"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export * from "./build/cjs/public/unstable-do-not-use.cjs";
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var React3 = require('react');
|
|
4
|
-
|
|
5
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
6
|
-
|
|
7
|
-
var React3__default = /*#__PURE__*/_interopDefault(React3);
|
|
8
|
-
|
|
9
|
-
// src/useOsdkClient.ts
|
|
10
|
-
function fakeClientFn(..._args) {
|
|
11
|
-
throw new Error("This is not a real client. Did you forget to <OsdkContext.Provider>?");
|
|
12
|
-
}
|
|
13
|
-
var fakeClient = Object.assign(fakeClientFn, {
|
|
14
|
-
fetchMetadata: fakeClientFn
|
|
15
|
-
});
|
|
16
|
-
var OsdkContext = /* @__PURE__ */ React3__default.default.createContext({
|
|
17
|
-
client: fakeClient
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
// src/useOsdkClient.ts
|
|
21
|
-
function useOsdkClient() {
|
|
22
|
-
return React3__default.default.useContext(OsdkContext).client;
|
|
23
|
-
}
|
|
24
|
-
function useOsdkMetadata(type) {
|
|
25
|
-
const client = useOsdkClient();
|
|
26
|
-
const [metadata, setMetadata] = React3__default.default.useState(void 0);
|
|
27
|
-
const [error, setError] = React3__default.default.useState();
|
|
28
|
-
if (!metadata && !error) {
|
|
29
|
-
client.fetchMetadata(type).then((fetchedMetadata) => {
|
|
30
|
-
setMetadata(fetchedMetadata);
|
|
31
|
-
}).catch((error2) => {
|
|
32
|
-
const errorMessage = error2 instanceof Error ? error2.message : String(error2);
|
|
33
|
-
setError(errorMessage);
|
|
34
|
-
});
|
|
35
|
-
return {
|
|
36
|
-
loading: true
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
loading: false,
|
|
41
|
-
metadata,
|
|
42
|
-
error
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
exports.OsdkContext = OsdkContext;
|
|
47
|
-
exports.useOsdkClient = useOsdkClient;
|
|
48
|
-
exports.useOsdkMetadata = useOsdkMetadata;
|
|
49
|
-
//# sourceMappingURL=chunk-OVBG5VXE.cjs.map
|
|
50
|
-
//# sourceMappingURL=chunk-OVBG5VXE.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/OsdkContext.ts","../../src/useOsdkClient.ts","../../src/useOsdkMetadata.ts"],"names":["React","error"],"mappings":";;;;;;;;;AAiBA,SAAS,gBAAgB,KAAO,EAAA;AAC9B,EAAM,MAAA,IAAI,MAAM,sEAAsE,CAAA;AACxF;AACA,IAAM,UAAA,GAAa,MAAO,CAAA,MAAA,CAAO,YAAc,EAAA;AAAA,EAC7C,aAAe,EAAA;AACjB,CAAC,CAAA;AACY,IAAA,WAAA,2CAAiC,aAAc,CAAA;AAAA,EAC1D,MAAQ,EAAA;AACV,CAAC;;;ACPM,SAAS,aAAgB,GAAA;AAC9B,EAAOA,OAAAA,uBAAAA,CAAM,UAAW,CAAA,WAAW,CAAE,CAAA,MAAA;AACvC;ACFO,SAAS,gBAAgB,IAAM,EAAA;AACpC,EAAA,MAAM,SAAS,aAAc,EAAA;AAC7B,EAAA,MAAM,CAAC,QAAU,EAAA,WAAW,CAAIA,GAAAA,uBAAAA,CAAM,SAAS,MAAS,CAAA;AACxD,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAIA,wBAAM,QAAS,EAAA;AACzC,EAAI,IAAA,CAAC,QAAY,IAAA,CAAC,KAAO,EAAA;AACvB,IAAA,MAAA,CAAO,aAAc,CAAA,IAAI,CAAE,CAAA,IAAA,CAAK,CAAmB,eAAA,KAAA;AACjD,MAAA,WAAA,CAAY,eAAe,CAAA;AAAA,KAC5B,CAAA,CAAE,KAAM,CAAA,CAAAC,MAAS,KAAA;AAChB,MAAA,MAAM,eAAeA,MAAiB,YAAA,KAAA,GAAQA,MAAM,CAAA,OAAA,GAAU,OAAOA,MAAK,CAAA;AAC1E,MAAA,QAAA,CAAS,YAAY,CAAA;AAAA,KACtB,CAAA;AACD,IAAO,OAAA;AAAA,MACL,OAAS,EAAA;AAAA,KACX;AAAA;AAEF,EAAO,OAAA;AAAA,IACL,OAAS,EAAA,KAAA;AAAA,IACT,QAAA;AAAA,IACA;AAAA,GACF;AACF","file":"chunk-OVBG5VXE.cjs","sourcesContent":["/*\n * Copyright 2024 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 React from \"react\";\nfunction fakeClientFn(..._args) {\n throw new Error(\"This is not a real client. Did you forget to <OsdkContext.Provider>?\");\n}\nconst fakeClient = Object.assign(fakeClientFn, {\n fetchMetadata: fakeClientFn\n});\nexport const OsdkContext = /*#__PURE__*/React.createContext({\n client: fakeClient\n});","/*\n * Copyright 2024 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 React from \"react\";\nimport { OsdkContext } from \"./OsdkContext.js\";\nexport function useOsdkClient() {\n return React.useContext(OsdkContext).client;\n}","/*\n * Copyright 2024 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 React from \"react\";\nimport { useOsdkClient } from \"./useOsdkClient.js\";\nexport function useOsdkMetadata(type) {\n const client = useOsdkClient();\n const [metadata, setMetadata] = React.useState(undefined);\n const [error, setError] = React.useState();\n if (!metadata && !error) {\n client.fetchMetadata(type).then(fetchedMetadata => {\n setMetadata(fetchedMetadata);\n }).catch(error => {\n const errorMessage = error instanceof Error ? error.message : String(error);\n setError(errorMessage);\n });\n return {\n loading: true\n };\n }\n return {\n loading: false,\n metadata,\n error\n };\n}"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/new/OsdkContext2.ts","../../src/new/makeExternalStore.ts"],"names":[],"mappings":"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","file":"chunk-SVVMLSKN.cjs","sourcesContent":["/*\n * Copyright 2024 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 React from \"react\";\nfunction fakeClientFn(..._args) {\n throw new Error(\"This is not a real client. Did you forget to <OsdkContext.Provider>?\");\n}\nconst fakeClient = Object.assign(fakeClientFn, {\n fetchMetadata: fakeClientFn\n});\nexport const OsdkContext2 = /*#__PURE__*/React.createContext({\n client: fakeClient,\n observableClient: undefined\n});","/*\n * Copyright 2025 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 makeExternalStore(createObservation, _name, initialValue) {\n let lastResult = initialValue;\n function getSnapShot() {\n return lastResult;\n }\n function subscribe(notifyUpdate) {\n const obs = createObservation({\n next: payload => {\n lastResult = payload;\n notifyUpdate();\n },\n error: error => {\n lastResult = {\n ...(lastResult ?? {}),\n error: error instanceof Error ? error : new Error(String(error))\n };\n notifyUpdate();\n },\n complete: () => {}\n });\n return () => {\n obs.unsubscribe();\n };\n }\n return {\n subscribe,\n getSnapShot\n };\n}\n\n/**\n * Like makeExternalStore but for async subscription creation.\n *\n * Uses an isActive flag to handle race conditions:\n * If cleanup runs before promise resolves, the stale subscription is\n * immediately unsubscribed when it eventually resolves\n */\nexport function makeExternalStoreAsync(createObservation, _name, initialValue) {\n let lastResult = initialValue;\n function getSnapShot() {\n return lastResult;\n }\n function subscribe(notifyUpdate) {\n let isActive = true;\n let currentSubscription;\n const subscriptionPromise = createObservation({\n next: payload => {\n if (isActive) {\n lastResult = payload;\n notifyUpdate();\n }\n },\n error: error => {\n if (isActive) {\n lastResult = {\n ...(lastResult ?? {}),\n error: error instanceof Error ? error : new Error(String(error))\n };\n notifyUpdate();\n }\n },\n complete: () => {}\n });\n subscriptionPromise.then(sub => {\n if (isActive) {\n currentSubscription = sub;\n } else {\n sub.unsubscribe();\n }\n }).catch(error => {\n if (isActive) {\n lastResult = {\n ...(lastResult ?? {}),\n error: error instanceof Error ? error : new Error(String(error))\n };\n notifyUpdate();\n }\n });\n return () => {\n isActive = false;\n if (currentSubscription) {\n currentSubscription.unsubscribe();\n }\n };\n }\n return {\n subscribe,\n getSnapShot\n };\n}"]}
|