@osdk/widget.client-react 3.3.0-beta.1 → 3.3.0-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/CHANGELOG.md +89 -0
  2. package/build/browser/ErrorBoundary.js +63 -0
  3. package/build/browser/ErrorBoundary.js.map +1 -0
  4. package/build/browser/client.js +11 -6
  5. package/build/browser/client.js.map +1 -1
  6. package/build/browser/context.js.map +1 -1
  7. package/build/browser/utils/extendParametersWithObjectSets.js +62 -0
  8. package/build/browser/utils/extendParametersWithObjectSets.js.map +1 -0
  9. package/build/browser/utils/extendParametersWithObjectSets.test.js +372 -0
  10. package/build/browser/utils/extendParametersWithObjectSets.test.js.map +1 -0
  11. package/build/browser/utils/initializeParameters.js.map +1 -1
  12. package/build/cjs/index.cjs +111 -11
  13. package/build/cjs/index.cjs.map +1 -1
  14. package/build/cjs/index.d.cts +52 -21
  15. package/build/esm/ErrorBoundary.js +63 -0
  16. package/build/esm/ErrorBoundary.js.map +1 -0
  17. package/build/esm/client.js +11 -6
  18. package/build/esm/client.js.map +1 -1
  19. package/build/esm/context.js.map +1 -1
  20. package/build/esm/utils/extendParametersWithObjectSets.js +62 -0
  21. package/build/esm/utils/extendParametersWithObjectSets.js.map +1 -0
  22. package/build/esm/utils/extendParametersWithObjectSets.test.js +372 -0
  23. package/build/esm/utils/extendParametersWithObjectSets.test.js.map +1 -0
  24. package/build/esm/utils/initializeParameters.js.map +1 -1
  25. package/build/types/ErrorBoundary.d.ts +13 -0
  26. package/build/types/ErrorBoundary.d.ts.map +1 -0
  27. package/build/types/client.d.ts +21 -7
  28. package/build/types/client.d.ts.map +1 -1
  29. package/build/types/context.d.ts +18 -2
  30. package/build/types/context.d.ts.map +1 -1
  31. package/build/types/utils/extendParametersWithObjectSets.d.ts +13 -0
  32. package/build/types/utils/extendParametersWithObjectSets.d.ts.map +1 -0
  33. package/build/types/utils/extendParametersWithObjectSets.test.d.ts +1 -0
  34. package/build/types/utils/extendParametersWithObjectSets.test.d.ts.map +1 -0
  35. package/build/types/utils/initializeParameters.d.ts +3 -2
  36. package/build/types/utils/initializeParameters.d.ts.map +1 -1
  37. package/package.json +6 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,94 @@
1
1
  # @osdk/widget.client-react
2
2
 
3
+ ## 3.3.0-beta.11
4
+
5
+ ### Minor Changes
6
+
7
+ - a8802b3: Add error boundary for custom widgets
8
+ - 8d7b8db: Expand ErrorBoundary to catch all errors
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies [84f0eef]
13
+ - Updated dependencies [486ef7e]
14
+ - Updated dependencies [ea077c6]
15
+ - @osdk/client@2.6.0-beta.13
16
+ - @osdk/widget.client@3.3.0-beta.11
17
+
18
+ ## 3.3.0-beta.10
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies [9961f06]
23
+ - @osdk/client@2.6.0-beta.12
24
+ - @osdk/widget.client@3.3.0-beta.10
25
+
26
+ ## 3.3.0-beta.9
27
+
28
+ ### Patch Changes
29
+
30
+ - Updated dependencies [c5a3815]
31
+ - @osdk/client@2.6.0-beta.11
32
+ - @osdk/widget.client@3.3.0-beta.9
33
+
34
+ ## 3.3.0-beta.8
35
+
36
+ ### Patch Changes
37
+
38
+ - Updated dependencies [3fbb596]
39
+ - @osdk/client@2.6.0-beta.10
40
+ - @osdk/widget.client@3.3.0-beta.8
41
+
42
+ ## 3.3.0-beta.7
43
+
44
+ ### Patch Changes
45
+
46
+ - @osdk/client@2.6.0-beta.9
47
+ - @osdk/widget.client@3.3.0-beta.7
48
+
49
+ ## 3.3.0-beta.6
50
+
51
+ ### Patch Changes
52
+
53
+ - Updated dependencies [a1ffb20]
54
+ - Updated dependencies [e62c692]
55
+ - @osdk/client@2.6.0-beta.8
56
+ - @osdk/widget.client@3.3.0-beta.6
57
+
58
+ ## 3.3.0-beta.5
59
+
60
+ ### Patch Changes
61
+
62
+ - Updated dependencies [507ec7f]
63
+ - @osdk/client@2.6.0-beta.7
64
+ - @osdk/widget.client@3.3.0-beta.5
65
+
66
+ ## 3.3.0-beta.4
67
+
68
+ ### Patch Changes
69
+
70
+ - Updated dependencies [b959085]
71
+ - @osdk/client@2.6.0-beta.6
72
+ - @osdk/widget.client@3.3.0-beta.4
73
+
74
+ ## 3.3.0-beta.3
75
+
76
+ ### Patch Changes
77
+
78
+ - Updated dependencies [b48526f]
79
+ - @osdk/client@2.6.0-beta.5
80
+ - @osdk/widget.client@3.3.0-beta.3
81
+
82
+ ## 3.3.0-beta.2
83
+
84
+ ### Minor Changes
85
+
86
+ - 4d37e98: Improved support for object set parameters in widget.client-react
87
+
88
+ ### Patch Changes
89
+
90
+ - @osdk/widget.client@3.3.0-beta.2
91
+
3
92
  ## 3.2.0-beta.5
4
93
 
5
94
  ### Patch Changes
@@ -0,0 +1,63 @@
1
+ /*
2
+ * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import * as React from "react";
18
+ /**
19
+ * Error boundary to catch and display errors in widget code.
20
+ */
21
+ export class ErrorBoundary extends React.Component {
22
+ state = {
23
+ error: null
24
+ };
25
+ static getDerivedStateFromError(error) {
26
+ return {
27
+ error
28
+ };
29
+ }
30
+ render() {
31
+ if (this.state.error) {
32
+ const errorDetails = this.state.error instanceof Error ? this.state.error.stack : "See browser console for more details.";
33
+ return /*#__PURE__*/React.createElement("section", {
34
+ style: {
35
+ padding: "16px"
36
+ }
37
+ }, /*#__PURE__*/React.createElement("h3", {
38
+ style: {
39
+ margin: "0 0 12px 0",
40
+ color: "#c00"
41
+ }
42
+ }, "An uncaught error occurred"), process.env.NODE_ENV !== "production" && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("p", {
43
+ style: {
44
+ margin: "0 0 8px 0"
45
+ }
46
+ }, "This error was caught by the widget framework's fallback error boundary."), /*#__PURE__*/React.createElement("ul", {
47
+ style: {
48
+ margin: "0 0 16px 0"
49
+ }
50
+ }, /*#__PURE__*/React.createElement("li", null, "Ensure errors are properly handled in your code with try-catch blocks and promise rejection handling."), /*#__PURE__*/React.createElement("li", null, "Add your own error boundary to replace this fallback with a custom error message or recovery options for your users."), /*#__PURE__*/React.createElement("li", null, "See:", " ", /*#__PURE__*/React.createElement("code", null, "https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary")))), /*#__PURE__*/React.createElement("pre", {
51
+ style: {
52
+ backgroundColor: "#f5f5f5",
53
+ padding: "12px",
54
+ overflow: "auto",
55
+ fontSize: "12px",
56
+ margin: 0
57
+ }
58
+ }, errorDetails));
59
+ }
60
+ return this.props.children;
61
+ }
62
+ }
63
+ //# sourceMappingURL=ErrorBoundary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorBoundary.js","names":["React","ErrorBoundary","Component","state","error","getDerivedStateFromError","render","errorDetails","Error","stack","createElement","style","padding","margin","color","process","env","NODE_ENV","Fragment","backgroundColor","overflow","fontSize","props","children"],"sources":["ErrorBoundary.tsx"],"sourcesContent":["/*\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\nimport * as React from \"react\";\n\ninterface State {\n error: unknown;\n}\n\n/**\n * Error boundary to catch and display errors in widget code.\n */\nexport class ErrorBoundary extends React.Component<\n React.PropsWithChildren,\n State\n> {\n state: State = { error: null };\n\n static getDerivedStateFromError(error: unknown): Partial<State> {\n return { error };\n }\n\n render(): React.ReactNode {\n if (this.state.error) {\n const errorDetails = this.state.error instanceof Error\n ? this.state.error.stack\n : \"See browser console for more details.\";\n\n return (\n <section style={{ padding: \"16px\" }}>\n <h3 style={{ margin: \"0 0 12px 0\", color: \"#c00\" }}>\n An uncaught error occurred\n </h3>\n {process.env.NODE_ENV !== \"production\" && (\n <>\n <p style={{ margin: \"0 0 8px 0\" }}>\n This error was caught by the widget framework's fallback error\n boundary.\n </p>\n <ul style={{ margin: \"0 0 16px 0\" }}>\n <li>\n Ensure errors are properly handled in your code with try-catch\n blocks and promise rejection handling.\n </li>\n <li>\n Add your own error boundary to replace this fallback with a\n custom error message or recovery options for your users.\n </li>\n <li>\n See:{\" \"}\n <code>\n https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary\n </code>\n </li>\n </ul>\n </>\n )}\n <pre\n style={{\n backgroundColor: \"#f5f5f5\",\n padding: \"12px\",\n overflow: \"auto\",\n fontSize: \"12px\",\n margin: 0,\n }}\n >\n {errorDetails}\n </pre>\n </section>\n );\n }\n\n return this.props.children;\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAM9B;AACA;AACA;AACA,OAAO,MAAMC,aAAa,SAASD,KAAK,CAACE,SAAS,CAGhD;EACAC,KAAK,GAAU;IAAEC,KAAK,EAAE;EAAK,CAAC;EAE9B,OAAOC,wBAAwBA,CAACD,KAAc,EAAkB;IAC9D,OAAO;MAAEA;IAAM,CAAC;EAClB;EAEAE,MAAMA,CAAA,EAAoB;IACxB,IAAI,IAAI,CAACH,KAAK,CAACC,KAAK,EAAE;MACpB,MAAMG,YAAY,GAAG,IAAI,CAACJ,KAAK,CAACC,KAAK,YAAYI,KAAK,GAClD,IAAI,CAACL,KAAK,CAACC,KAAK,CAACK,KAAK,GACtB,uCAAuC;MAE3C,oBACET,KAAA,CAAAU,aAAA;QAASC,KAAK,EAAE;UAAEC,OAAO,EAAE;QAAO;MAAE,gBAClCZ,KAAA,CAAAU,aAAA;QAAIC,KAAK,EAAE;UAAEE,MAAM,EAAE,YAAY;UAAEC,KAAK,EAAE;QAAO;MAAE,GAAC,4BAEhD,CAAC,EACJC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,iBACpCjB,KAAA,CAAAU,aAAA,CAAAV,KAAA,CAAAkB,QAAA,qBACElB,KAAA,CAAAU,aAAA;QAAGC,KAAK,EAAE;UAAEE,MAAM,EAAE;QAAY;MAAE,GAAC,0EAGhC,CAAC,eACJb,KAAA,CAAAU,aAAA;QAAIC,KAAK,EAAE;UAAEE,MAAM,EAAE;QAAa;MAAE,gBAClCb,KAAA,CAAAU,aAAA,aAAI,uGAGA,CAAC,eACLV,KAAA,CAAAU,aAAA,aAAI,sHAGA,CAAC,eACLV,KAAA,CAAAU,aAAA,aAAI,MACE,EAAC,GAAG,eACRV,KAAA,CAAAU,aAAA,eAAM,8FAEA,CACJ,CACF,CACJ,CACH,eACDV,KAAA,CAAAU,aAAA;QACEC,KAAK,EAAE;UACLQ,eAAe,EAAE,SAAS;UAC1BP,OAAO,EAAE,MAAM;UACfQ,QAAQ,EAAE,MAAM;UAChBC,QAAQ,EAAE,MAAM;UAChBR,MAAM,EAAE;QACV;MAAE,GAEDN,YACE,CACE,CAAC;IAEd;IAEA,OAAO,IAAI,CAACe,KAAK,CAACC,QAAQ;EAC5B;AACF","ignoreList":[]}
@@ -15,8 +15,10 @@
15
15
  */
16
16
 
17
17
  import { createFoundryWidgetClient } from "@osdk/widget.client";
18
- import React, { useEffect, useMemo } from "react";
18
+ import React, { useEffect, useMemo, useRef } from "react";
19
19
  import { FoundryWidgetContext } from "./context.js";
20
+ import { ErrorBoundary } from "./ErrorBoundary.js";
21
+ import { extendParametersWithObjectSets } from "./utils/extendParametersWithObjectSets.js";
20
22
  import { initializeParameters } from "./utils/initializeParameters.js";
21
23
  /**
22
24
  * Handles subscribing to messages from the host Foundry UI and updating the widget's parameter values accordingly via React context
@@ -24,26 +26,29 @@ import { initializeParameters } from "./utils/initializeParameters.js";
24
26
  export const FoundryWidget = ({
25
27
  children,
26
28
  config,
27
- initialValues
29
+ initialValues,
30
+ client: osdkClient
28
31
  }) => {
29
32
  const client = useMemo(() => createFoundryWidgetClient(), []);
30
33
  const [asyncParameterValues, setAsyncParameterValues] = React.useState(initialValues ?? initializeParameters(config, "not-started"));
31
34
  const [allParameterValues, setAllParameterValues] = React.useState({
32
35
  type: "not-started"
33
36
  });
37
+ const objectSetCache = useRef(new Map());
34
38
  useEffect(() => {
35
39
  client.subscribe();
36
40
  client.hostEventTarget.addEventListener("host.update-parameters", payload => {
41
+ const processedParameters = extendParametersWithObjectSets(osdkClient, config, payload.detail.parameters, objectSetCache.current);
37
42
  setAsyncParameterValues(currentParameters => ({
38
43
  ...currentParameters,
39
- ...payload.detail.parameters
44
+ ...processedParameters
40
45
  }));
41
46
  setAllParameterValues(currentParameters => {
42
47
  let aggregatedLoadedState = "loaded";
43
48
  let firstError;
44
49
  const newParameterValues = {};
45
- for (const key in payload.detail.parameters) {
46
- const value = payload.detail.parameters[key].value;
50
+ for (const key in processedParameters) {
51
+ const value = processedParameters[key].value;
47
52
  // If any fails, consider the whole thing failed
48
53
  if (value.type === "failed") {
49
54
  aggregatedLoadedState = "failed";
@@ -106,6 +111,6 @@ export const FoundryWidget = ({
106
111
  }
107
112
  // Unfortunately the context is statically defined so we can't use the generic type, hence the cast
108
113
  }
109
- }, children);
114
+ }, /*#__PURE__*/React.createElement(ErrorBoundary, null, children));
110
115
  };
111
116
  //# sourceMappingURL=client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","names":["createFoundryWidgetClient","React","useEffect","useMemo","FoundryWidgetContext","initializeParameters","FoundryWidget","children","config","initialValues","client","asyncParameterValues","setAsyncParameterValues","useState","allParameterValues","setAllParameterValues","type","subscribe","hostEventTarget","addEventListener","payload","currentParameters","detail","parameters","aggregatedLoadedState","firstError","newParameterValues","key","value","error","currentParameterValue","updatedValue","Error","ready","unsubscribe","createElement","Provider","emitEvent","values","state"],"sources":["client.tsx"],"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 type {\n AsyncParameterValueMap,\n AsyncValue,\n ParameterConfig,\n ParameterValueMap,\n WidgetConfig,\n} from \"@osdk/widget.client\";\nimport { createFoundryWidgetClient } from \"@osdk/widget.client\";\nimport React, { useEffect, useMemo } from \"react\";\nimport type { FoundryWidgetClientContext } from \"./context.js\";\nimport { FoundryWidgetContext } from \"./context.js\";\nimport { initializeParameters } from \"./utils/initializeParameters.js\";\n\ninterface FoundryWidgetProps<C extends WidgetConfig<C[\"parameters\"]>> {\n children: React.ReactNode;\n\n /**\n * Parameter configuration for the widget\n */\n config: C;\n\n /**\n * Customize what the initial value of each parameter should be\n *\n * @default Sets all parameters to the \"not-started\" loading state\n */\n initialValues?: AsyncParameterValueMap<C>;\n}\n\n/**\n * Handles subscribing to messages from the host Foundry UI and updating the widget's parameter values accordingly via React context\n */\nexport const FoundryWidget = <C extends WidgetConfig<C[\"parameters\"]>>({\n children,\n config,\n initialValues,\n}: FoundryWidgetProps<C>): React.ReactElement<FoundryWidgetProps<C>> => {\n const client = useMemo(() => createFoundryWidgetClient<C>(), []);\n const [asyncParameterValues, setAsyncParameterValues] = React.useState<\n AsyncParameterValueMap<C>\n >(initialValues ?? initializeParameters(config, \"not-started\"));\n const [allParameterValues, setAllParameterValues] = React.useState<\n AsyncValue<ParameterValueMap<C>>\n >({\n type: \"not-started\",\n });\n\n useEffect(() => {\n client.subscribe();\n client.hostEventTarget.addEventListener(\n \"host.update-parameters\",\n (payload) => {\n setAsyncParameterValues((currentParameters) => ({\n ...currentParameters,\n ...payload.detail.parameters,\n }));\n setAllParameterValues((currentParameters) => {\n let aggregatedLoadedState: AsyncValue<any>[\"type\"] = \"loaded\";\n let firstError: Error | undefined;\n const newParameterValues: ParameterValueMap<\n WidgetConfig<ParameterConfig>\n > = {};\n for (const key in payload.detail.parameters) {\n const value = payload.detail.parameters[key].value;\n // If any fails, consider the whole thing failed\n if (value.type === \"failed\") {\n aggregatedLoadedState = \"failed\";\n firstError = firstError ?? value.error;\n newParameterValues[key as any] = value.value as any;\n continue;\n }\n // If any is loading, consider all of it loading unless we have failed somewhere\n if (\n value.type === \"loading\"\n && aggregatedLoadedState !== \"failed\"\n ) {\n aggregatedLoadedState = \"loading\";\n continue;\n }\n // If any is reloading, consider it loading unless something is failed or loading for the first time\n if (\n value.type === \"reloading\"\n && aggregatedLoadedState !== \"failed\"\n && aggregatedLoadedState !== \"loading\"\n ) {\n aggregatedLoadedState = \"reloading\";\n newParameterValues[key as any] = value.value as any;\n continue;\n }\n if (\n value.type === \"not-started\"\n && aggregatedLoadedState !== \"failed\"\n && aggregatedLoadedState !== \"loading\"\n && aggregatedLoadedState !== \"reloading\"\n ) {\n aggregatedLoadedState = \"not-started\";\n }\n\n if (value.type === \"loaded\") {\n newParameterValues[key as any] = value.value as any;\n }\n }\n const currentParameterValue = currentParameters.type !== \"not-started\"\n && currentParameters.type !== \"loading\"\n ? currentParameters.value\n : {};\n if (\n aggregatedLoadedState !== \"not-started\"\n && aggregatedLoadedState !== \"loading\"\n ) {\n const updatedValue = {\n ...currentParameterValue,\n ...newParameterValues,\n } as ParameterValueMap<C>;\n return aggregatedLoadedState === \"failed\"\n ? {\n type: aggregatedLoadedState,\n value: updatedValue,\n error: firstError ?? new Error(\"Failed to load parameters\"),\n }\n : {\n type: aggregatedLoadedState,\n value: updatedValue,\n };\n } else {\n return { type: aggregatedLoadedState };\n }\n });\n },\n );\n client.ready();\n return () => {\n client.unsubscribe();\n };\n }, []);\n\n return (\n <FoundryWidgetContext.Provider\n value={{\n emitEvent: client.emitEvent,\n hostEventTarget: client.hostEventTarget,\n asyncParameterValues,\n parameters: {\n values: allParameterValues.value ?? {},\n state: allParameterValues.type,\n },\n // Unfortunately the context is statically defined so we can't use the generic type, hence the cast\n } as FoundryWidgetClientContext<WidgetConfig<ParameterConfig>>}\n >\n {children}\n </FoundryWidgetContext.Provider>\n );\n};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,SAASA,yBAAyB,QAAQ,qBAAqB;AAC/D,OAAOC,KAAK,IAAIC,SAAS,EAAEC,OAAO,QAAQ,OAAO;AAEjD,SAASC,oBAAoB,QAAQ,cAAc;AACnD,SAASC,oBAAoB,QAAQ,iCAAiC;AAkBtE;AACA;AACA;AACA,OAAO,MAAMC,aAAa,GAAGA,CAA0C;EACrEC,QAAQ;EACRC,MAAM;EACNC;AACqB,CAAC,KAAgD;EACtE,MAAMC,MAAM,GAAGP,OAAO,CAAC,MAAMH,yBAAyB,CAAI,CAAC,EAAE,EAAE,CAAC;EAChE,MAAM,CAACW,oBAAoB,EAAEC,uBAAuB,CAAC,GAAGX,KAAK,CAACY,QAAQ,CAEpEJ,aAAa,IAAIJ,oBAAoB,CAACG,MAAM,EAAE,aAAa,CAAC,CAAC;EAC/D,MAAM,CAACM,kBAAkB,EAAEC,qBAAqB,CAAC,GAAGd,KAAK,CAACY,QAAQ,CAEhE;IACAG,IAAI,EAAE;EACR,CAAC,CAAC;EAE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CAAC;AAEpC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"client.js","names":["createFoundryWidgetClient","React","useEffect","useMemo","useRef","FoundryWidgetContext","ErrorBoundary","extendParametersWithObjectSets","initializeParameters","FoundryWidget","children","config","initialValues","client","osdkClient","asyncParameterValues","setAsyncParameterValues","useState","allParameterValues","setAllParameterValues","type","objectSetCache","Map","subscribe","hostEventTarget","addEventListener","payload","processedParameters","detail","parameters","current","currentParameters","aggregatedLoadedState","firstError","newParameterValues","key","value","error","currentParameterValue","updatedValue","Error","ready","unsubscribe","createElement","Provider","emitEvent","values","state"],"sources":["client.tsx"],"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 type { Client, ObjectSet } from \"@osdk/client\";\nimport type { ObjectType } from \"@osdk/widget.api\";\nimport type {\n AsyncValue,\n ParameterConfig,\n WidgetConfig,\n} from \"@osdk/widget.client\";\nimport { createFoundryWidgetClient } from \"@osdk/widget.client\";\nimport React, { useEffect, useMemo, useRef } from \"react\";\nimport type {\n ExtendedAsyncParameterValueMap,\n ExtendedParameterValueMap,\n FoundryWidgetClientContext,\n} from \"./context.js\";\nimport { FoundryWidgetContext } from \"./context.js\";\nimport { ErrorBoundary } from \"./ErrorBoundary.js\";\nimport { extendParametersWithObjectSets } from \"./utils/extendParametersWithObjectSets.js\";\nimport { initializeParameters } from \"./utils/initializeParameters.js\";\n\ntype ExtractObjectTypes<C extends WidgetConfig<C[\"parameters\"]>> =\n C[\"parameters\"][keyof C[\"parameters\"]] extends infer Param\n ? Param extends { type: \"objectSet\"; objectType: infer OT }\n ? OT extends ObjectType ? OT : never\n : never\n : never;\n\ntype HasObjectSetParameters<C extends WidgetConfig<C[\"parameters\"]>> =\n ExtractObjectTypes<C> extends never ? false : true;\n\ntype ObjectSetProps<C extends WidgetConfig<C[\"parameters\"]>> = {\n /**\n * Used to hydrate object sets from their RIDs for object set parameters\n */\n client: Client;\n};\n\ntype FoundryWidgetProps<C extends WidgetConfig<C[\"parameters\"]>> =\n & {\n children: React.ReactNode;\n\n /**\n * Parameter configuration for the widget\n */\n config: C;\n\n /**\n * Customize what the initial value of each parameter should be\n *\n * @default Sets all parameters to the \"not-started\" loading state\n */\n initialValues?: ExtendedAsyncParameterValueMap<C>;\n }\n & Partial<ObjectSetProps<C>>\n & (HasObjectSetParameters<C> extends true ? ObjectSetProps<C> : {});\n\n/**\n * Handles subscribing to messages from the host Foundry UI and updating the widget's parameter values accordingly via React context\n */\nexport const FoundryWidget = <C extends WidgetConfig<C[\"parameters\"]>>({\n children,\n config,\n initialValues,\n client: osdkClient,\n}: FoundryWidgetProps<C>): React.ReactElement<FoundryWidgetProps<C>> => {\n const client = useMemo(() => createFoundryWidgetClient<C>(), []);\n const [asyncParameterValues, setAsyncParameterValues] = React.useState<\n ExtendedAsyncParameterValueMap<C>\n >(initialValues ?? initializeParameters(config, \"not-started\"));\n const [allParameterValues, setAllParameterValues] = React.useState<\n AsyncValue<ExtendedParameterValueMap<C>>\n >({\n type: \"not-started\",\n });\n\n const objectSetCache = useRef<\n Map<string, { objectSetRid: string; objectSet: ObjectSet }>\n >(new Map());\n\n useEffect(() => {\n client.subscribe();\n client.hostEventTarget.addEventListener(\n \"host.update-parameters\",\n (payload) => {\n const processedParameters = extendParametersWithObjectSets(\n osdkClient,\n config,\n payload.detail.parameters,\n objectSetCache.current,\n );\n setAsyncParameterValues((currentParameters) => ({\n ...currentParameters,\n ...processedParameters,\n }));\n setAllParameterValues((currentParameters) => {\n let aggregatedLoadedState: AsyncValue<any>[\"type\"] = \"loaded\";\n let firstError: Error | undefined;\n const newParameterValues: ExtendedParameterValueMap<\n WidgetConfig<ParameterConfig>\n > = {};\n for (const key in processedParameters) {\n const value = processedParameters[key].value;\n // If any fails, consider the whole thing failed\n if (value.type === \"failed\") {\n aggregatedLoadedState = \"failed\";\n firstError = firstError ?? value.error;\n newParameterValues[key as any] = value.value as any;\n continue;\n }\n // If any is loading, consider all of it loading unless we have failed somewhere\n if (\n value.type === \"loading\"\n && aggregatedLoadedState !== \"failed\"\n ) {\n aggregatedLoadedState = \"loading\";\n continue;\n }\n // If any is reloading, consider it loading unless something is failed or loading for the first time\n if (\n value.type === \"reloading\"\n && aggregatedLoadedState !== \"failed\"\n && aggregatedLoadedState !== \"loading\"\n ) {\n aggregatedLoadedState = \"reloading\";\n newParameterValues[key as any] = value.value as any;\n continue;\n }\n if (\n value.type === \"not-started\"\n && aggregatedLoadedState !== \"failed\"\n && aggregatedLoadedState !== \"loading\"\n && aggregatedLoadedState !== \"reloading\"\n ) {\n aggregatedLoadedState = \"not-started\";\n }\n\n if (value.type === \"loaded\") {\n newParameterValues[key as any] = value.value as any;\n }\n }\n const currentParameterValue = currentParameters.type !== \"not-started\"\n && currentParameters.type !== \"loading\"\n ? currentParameters.value\n : {};\n if (\n aggregatedLoadedState !== \"not-started\"\n && aggregatedLoadedState !== \"loading\"\n ) {\n const updatedValue = {\n ...currentParameterValue,\n ...newParameterValues,\n } as ExtendedParameterValueMap<C>;\n return aggregatedLoadedState === \"failed\"\n ? {\n type: aggregatedLoadedState,\n value: updatedValue,\n error: firstError ?? new Error(\"Failed to load parameters\"),\n }\n : {\n type: aggregatedLoadedState,\n value: updatedValue,\n };\n } else {\n return { type: aggregatedLoadedState };\n }\n });\n },\n );\n client.ready();\n return () => {\n client.unsubscribe();\n };\n }, []);\n\n return (\n <FoundryWidgetContext.Provider\n value={{\n emitEvent: client.emitEvent,\n hostEventTarget: client.hostEventTarget,\n asyncParameterValues,\n parameters: {\n values: allParameterValues.value ?? {},\n state: allParameterValues.type,\n },\n // Unfortunately the context is statically defined so we can't use the generic type, hence the cast\n } as FoundryWidgetClientContext<WidgetConfig<ParameterConfig>>}\n >\n <ErrorBoundary>\n {children}\n </ErrorBoundary>\n </FoundryWidgetContext.Provider>\n );\n};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,SAASA,yBAAyB,QAAQ,qBAAqB;AAC/D,OAAOC,KAAK,IAAIC,SAAS,EAAEC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AAMzD,SAASC,oBAAoB,QAAQ,cAAc;AACnD,SAASC,aAAa,QAAQ,oBAAoB;AAClD,SAASC,8BAA8B,QAAQ,2CAA2C;AAC1F,SAASC,oBAAoB,QAAQ,iCAAiC;AAsCtE;AACA;AACA;AACA,OAAO,MAAMC,aAAa,GAAGA,CAA0C;EACrEC,QAAQ;EACRC,MAAM;EACNC,aAAa;EACbC,MAAM,EAAEC;AACa,CAAC,KAAgD;EACtE,MAAMD,MAAM,GAAGV,OAAO,CAAC,MAAMH,yBAAyB,CAAI,CAAC,EAAE,EAAE,CAAC;EAChE,MAAM,CAACe,oBAAoB,EAAEC,uBAAuB,CAAC,GAAGf,KAAK,CAACgB,QAAQ,CAEpEL,aAAa,IAAIJ,oBAAoB,CAACG,MAAM,EAAE,aAAa,CAAC,CAAC;EAC/D,MAAM,CAACO,kBAAkB,EAAEC,qBAAqB,CAAC,GAAGlB,KAAK,CAACgB,QAAQ,CAEhE;IACAG,IAAI,EAAE;EACR,CAAC,CAAC;EAEF,MAAMC,cAAc,GAAGjB,MAAM,CAE3B,IAAIkB,GAAG,CAAC,CAAC,CAAC;EAEZpB,SAAS,CAAC,MAAM;IACdW,MAAM,CAACU,SAAS,CAAC,CAAC;IAClBV,MAAM,CAACW,eAAe,CAACC,gBAAgB,CACrC,wBAAwB,EACvBC,OAAO,IAAK;MACX,MAAMC,mBAAmB,GAAGpB,8BAA8B,CACxDO,UAAU,E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ventTarget","React","useContext","FoundryWidgetContext","createContext","emitEvent","hostEventTarget","asyncParameterValues","parameters","state","values","useFoundryWidgetContext","_useFoundryWidgetContext","withTypes"],"sources":["context.ts"],"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 {\n type AsyncParameterValueMap,\n type AsyncValue,\n FoundryHostEventTarget,\n type FoundryWidgetClient,\n type ParameterConfig,\n type ParameterValueMap,\n type WidgetConfig,\n} from \"@osdk/widget.client\";\nimport React, { useContext } from \"react\";\n\nexport interface FoundryWidgetClientContext<\n C extends WidgetConfig<C[\"parameters\"]>,\n> {\n emitEvent: FoundryWidgetClient<C>[\"emitEvent\"];\n hostEventTarget: FoundryHostEventTarget<C>;\n\n /**\n * Object where the individual parameters have their async state represented\n */\n asyncParameterValues: AsyncParameterValueMap<C>;\n\n /**\n * Convenience object that aggregates the value of all parameters, accounting for their loading states\n */\n parameters: {\n values: Partial<ParameterValueMap<C>>;\n state: AsyncValue<ParameterValueMap<C>>[\"type\"];\n };\n}\n\nexport const FoundryWidgetContext: React.Context<\n FoundryWidgetClientContext<WidgetConfig<ParameterConfig>>\n> = React.createContext<\n FoundryWidgetClientContext<WidgetConfig<ParameterConfig>>\n>({\n emitEvent: () => {},\n hostEventTarget: new FoundryHostEventTarget<WidgetConfig<ParameterConfig>>(),\n asyncParameterValues: {},\n parameters: {\n state: \"not-started\",\n values: {},\n },\n});\n\n/**\n * @returns The current FoundryWidgetClientContext, in the context of your specific parameter configuration\n */\nexport function useFoundryWidgetContext<\n C extends WidgetConfig<C[\"parameters\"]>,\n>() {\n return useContext(FoundryWidgetContext) as FoundryWidgetClientContext<C>;\n}\n\nexport namespace useFoundryWidgetContext {\n export function withTypes<\n C extends WidgetConfig<C[\"parameters\"]>,\n >(): () => FoundryWidgetClientContext<C> {\n return () => {\n return useFoundryWidgetContext<C>();\n };\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAGEA,sBAAsB,QAKjB,qBAAqB;AAC5B,OAAOC,KAAK,IAAIC,UAAU,QAAQ,OAAO;AAsBzC,OAAO,MAAMC,oBAEZ,gBAAGF,KAAK,CAACG,aAAa,CAErB;EACAC,SAAS,EAAEA,CAAA,KAAM,CAAC,CAAC;EACnBC,eAAe,EAAE,IAAIN,sBAAsB,CAAgC,CAAC;EAC5EO,oBAAoB,EAAE,CAAC,CAAC;EACxBC,UAAU,EAAE;IACVC,KAAK,EAAE,aAAa;IACpBC,MAAM,EAAE,CAAC;EACX;AACF,CAAC,CAAC;;AAEF;AACA;AACA;AACA,OAAO,SAASC,uBAAuBA,CAAA,EAEnC;EACF,OAAOT,UAAU,CAACC,oBAAoB,CAAC;AACzC;AAAC,WAAAS,wBAAA;EAAAA,wBAAA,CAAAC,SAAA,GAGQ,YAEkC;IACvC,OAAO,MAAM;MACX,OAAOF,uBAAuB,CAAI,CAAC;IACrC,CAAC;EACH,CAAC;AAAA,GAPcA,uBAAuB,KAAvBA,uBAAuB","ignoreList":[]}
1
+ {"version":3,"file":"context.js","names":["FoundryHostEventTarget","React","useContext","FoundryWidgetContext","createContext","emitEvent","hostEventTarget","asyncParameterValues","parameters","state","values","useFoundryWidgetContext","_useFoundryWidgetContext","withTypes"],"sources":["context.ts"],"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 type { ObjectSet } from \"@osdk/client\";\nimport type { ObjectType } from \"@osdk/widget.api\";\nimport {\n type AsyncParameterValueMap,\n type AsyncValue,\n FoundryHostEventTarget,\n type FoundryWidgetClient,\n type ParameterConfig,\n type ParameterValueMap,\n type WidgetConfig,\n} from \"@osdk/widget.client\";\nimport React, { useContext } from \"react\";\n\nexport interface FoundryWidgetClientContext<\n C extends WidgetConfig<C[\"parameters\"]>,\n> {\n emitEvent: FoundryWidgetClient<C>[\"emitEvent\"];\n hostEventTarget: FoundryHostEventTarget<C>;\n\n /**\n * Object where the individual parameters have their async state represented\n */\n asyncParameterValues: ExtendedAsyncParameterValueMap<C>;\n\n /**\n * Convenience object that aggregates the value of all parameters, accounting for their loading states\n */\n parameters: {\n values: Partial<ExtendedParameterValueMap<C>>;\n state: AsyncValue<ParameterValueMap<C>>[\"type\"];\n };\n}\n\nexport type ExtendedParameterValueMap<C extends WidgetConfig<C[\"parameters\"]>> =\n {\n [K in keyof C[\"parameters\"]]: K extends keyof ParameterValueMap<C>\n ? C[\"parameters\"][K] extends { type: \"objectSet\"; objectType: infer T }\n ? T extends ObjectType\n ? ParameterValueMap<C>[K] & { objectSet: ObjectSet<T> }\n : ParameterValueMap<C>[K]\n : ParameterValueMap<C>[K]\n : never;\n };\n\nexport type ExtendedAsyncParameterValueMap<\n C extends WidgetConfig<C[\"parameters\"]>,\n> = {\n [K in keyof C[\"parameters\"]]: K extends keyof AsyncParameterValueMap<C>\n ? C[\"parameters\"][K] extends { type: \"objectSet\"; objectType: infer T }\n ? T extends ObjectType ? AsyncParameterValueMap<C>[K] & {\n value: AsyncValue<\n ParameterValueMap<C>[K] & { objectSet: ObjectSet<T> }\n >;\n }\n : AsyncParameterValueMap<C>[K]\n : AsyncParameterValueMap<C>[K]\n : never;\n};\n\nexport const FoundryWidgetContext: React.Context<\n FoundryWidgetClientContext<WidgetConfig<ParameterConfig>>\n> = React.createContext<\n FoundryWidgetClientContext<WidgetConfig<ParameterConfig>>\n>({\n emitEvent: () => {},\n hostEventTarget: new FoundryHostEventTarget<WidgetConfig<ParameterConfig>>(),\n asyncParameterValues: {},\n parameters: {\n state: \"not-started\",\n values: {},\n },\n});\n\n/**\n * @returns The current FoundryWidgetClientContext, in the context of your specific parameter configuration\n */\nexport function useFoundryWidgetContext<\n C extends WidgetConfig<C[\"parameters\"]>,\n>() {\n return useContext(FoundryWidgetContext) as FoundryWidgetClientContext<C>;\n}\n\nexport namespace useFoundryWidgetContext {\n export function withTypes<\n C extends WidgetConfig<C[\"parameters\"]>,\n >(): () => FoundryWidgetClientContext<C> {\n return () => {\n return useFoundryWidgetContext<C>();\n };\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,SAGEA,sBAAsB,QAKjB,qBAAqB;AAC5B,OAAOC,KAAK,IAAIC,UAAU,QAAQ,OAAO;AAgDzC,OAAO,MAAMC,oBAEZ,gBAAGF,KAAK,CAACG,aAAa,CAErB;EACAC,SAAS,EAAEA,CAAA,KAAM,CAAC,CAAC;EACnBC,eAAe,EAAE,IAAIN,sBAAsB,CAAgC,CAAC;EAC5EO,oBAAoB,EAAE,CAAC,CAAC;EACxBC,UAAU,EAAE;IACVC,KAAK,EAAE,aAAa;IACpBC,MAAM,EAAE,CAAC;EACX;AACF,CAAC,CAAC;;AAEF;AACA;AACA;AACA,OAAO,SAASC,uBAAuBA,CAAA,EAEnC;EACF,OAAOT,UAAU,CAACC,oBAAoB,CAAC;AACzC;AAAC,WAAAS,wBAAA;EAAAA,wBAAA,CAAAC,SAAA,GAGQ,YAEkC;IACvC,OAAO,MAAM;MACX,OAAOF,uBAAuB,CAAI,CAAC;IACrC,CAAC;EACH,CAAC;AAAA,GAPcA,uBAAuB,KAAvBA,uBAAuB","ignoreList":[]}
@@ -0,0 +1,62 @@
1
+ /*
2
+ * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { hydrateObjectSetFromRid } from "@osdk/client/internal";
18
+ /**
19
+ * Patches parameter values with hydrated object sets for object set parameters.
20
+ *
21
+ * The cache is used to avoid redundant hydration of the same object set RID, which
22
+ * can cause unnecessary re-renders in React components consuming the parameters.
23
+ */
24
+ export function extendParametersWithObjectSets(osdkClient, config, parameters, cache) {
25
+ const extendedParameters = {
26
+ ...parameters
27
+ };
28
+ for (const parameterId of Object.keys(extendedParameters)) {
29
+ const param = config.parameters[parameterId];
30
+ if (param.type === "objectSet" && extendedParameters[parameterId].type === "objectSet") {
31
+ const parameterValue = extendedParameters[parameterId].value.value;
32
+ if (parameterValue != null) {
33
+ if (typeof parameterValue === "object" && "objectSetRid" in parameterValue && typeof parameterValue.objectSetRid === "string") {
34
+ const objectSetRid = parameterValue.objectSetRid;
35
+ const objectSet = getOrHydrateObjectSet(osdkClient, cache, parameterId, objectSetRid, param.objectType);
36
+ parameterValue.objectSet = objectSet;
37
+ } else {
38
+ throw new Error(`Invalid object set parameter value for parameter "${parameterId}"`);
39
+ }
40
+ } else {
41
+ cache.delete(parameterId);
42
+ }
43
+ }
44
+ }
45
+ return extendedParameters;
46
+ }
47
+ function getOrHydrateObjectSet(osdkClient, cache, paramKey, objectSetRid, definition) {
48
+ if (osdkClient == null) {
49
+ throw new Error("Not provided an OSDK client");
50
+ }
51
+ const cached = cache.get(paramKey);
52
+ if (cached?.objectSetRid === objectSetRid) {
53
+ return cached.objectSet;
54
+ }
55
+ const objectSet = hydrateObjectSetFromRid(osdkClient, definition, objectSetRid);
56
+ cache.set(paramKey, {
57
+ objectSetRid,
58
+ objectSet
59
+ });
60
+ return objectSet;
61
+ }
62
+ //# sourceMappingURL=extendParametersWithObjectSets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extendParametersWithObjectSets.js","names":["hydrateObjectSetFromRid","extendParametersWithObjectSets","osdkClient","config","parameters","cache","extendedParameters","parameterId","Object","keys","param","type","parameterValue","value","objectSetRid","objectSet","getOrHydrateObjectSet","objectType","Error","delete","paramKey","definition","cached","get","set"],"sources":["extendParametersWithObjectSets.ts"],"sourcesContent":["/*\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\nimport type { Client, ObjectSet, ObjectTypeDefinition } from \"@osdk/client\";\nimport { hydrateObjectSetFromRid } from \"@osdk/client/internal\";\nimport type { AsyncParameterValueMap, WidgetConfig } from \"@osdk/widget.api\";\nimport type { ExtendedAsyncParameterValueMap } from \"../context.js\";\n\n/**\n * Patches parameter values with hydrated object sets for object set parameters.\n *\n * The cache is used to avoid redundant hydration of the same object set RID, which\n * can cause unnecessary re-renders in React components consuming the parameters.\n */\nexport function extendParametersWithObjectSets<\n C extends WidgetConfig<C[\"parameters\"]>,\n>(\n osdkClient: Client | undefined,\n config: C,\n parameters: AsyncParameterValueMap<C>,\n cache: Map<string, { objectSetRid: string; objectSet: ObjectSet }>,\n): ExtendedAsyncParameterValueMap<C> {\n const extendedParameters = {\n ...parameters,\n } as ExtendedAsyncParameterValueMap<C>;\n\n for (const parameterId of Object.keys(extendedParameters)) {\n const param = config.parameters[parameterId];\n if (\n param.type === \"objectSet\"\n && extendedParameters[parameterId].type === \"objectSet\"\n ) {\n const parameterValue = extendedParameters[parameterId].value.value;\n if (parameterValue != null) {\n if (\n typeof parameterValue === \"object\"\n && \"objectSetRid\" in parameterValue\n && typeof parameterValue.objectSetRid === \"string\"\n ) {\n const objectSetRid = parameterValue.objectSetRid;\n const objectSet = getOrHydrateObjectSet(\n osdkClient,\n cache,\n parameterId,\n objectSetRid,\n param.objectType as ObjectTypeDefinition,\n );\n (parameterValue as any).objectSet = objectSet;\n } else {\n throw new Error(\n `Invalid object set parameter value for parameter \"${parameterId}\"`,\n );\n }\n } else {\n cache.delete(parameterId);\n }\n }\n }\n\n return extendedParameters;\n}\n\nfunction getOrHydrateObjectSet<T extends ObjectTypeDefinition>(\n osdkClient: Client | undefined,\n cache: Map<string, { objectSetRid: string; objectSet: ObjectSet<T> }>,\n paramKey: string,\n objectSetRid: string,\n definition: T,\n) {\n if (osdkClient == null) {\n throw new Error(\"Not provided an OSDK client\");\n }\n const cached = cache.get(paramKey);\n if (cached?.objectSetRid === objectSetRid) {\n return cached.objectSet;\n }\n const objectSet = hydrateObjectSetFromRid(\n osdkClient,\n definition,\n objectSetRid,\n );\n cache.set(paramKey, { objectSetRid, objectSet });\n return objectSet;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,uBAAuB,QAAQ,uBAAuB;AAI/D;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,8BAA8BA,CAG5CC,UAA8B,EAC9BC,MAAS,EACTC,UAAqC,EACrCC,KAAkE,EAC/B;EACnC,MAAMC,kBAAkB,GAAG;IACzB,GAAGF;EACL,CAAs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