@osdk/react 0.5.0-beta.2 → 0.5.0-beta.3
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 +15 -0
- package/build/browser/new/useOsdkAction.js +32 -9
- package/build/browser/new/useOsdkAction.js.map +1 -1
- package/build/cjs/public/experimental.cjs +32 -9
- package/build/cjs/public/experimental.cjs.map +1 -1
- package/build/cjs/public/experimental.d.cts +1 -1
- package/build/esm/new/useOsdkAction.js +32 -9
- package/build/esm/new/useOsdkAction.js.map +1 -1
- package/build/types/new/useOsdkAction.d.ts +1 -1
- package/build/types/new/useOsdkAction.d.ts.map +1 -1
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @osdkkit/react
|
|
2
2
|
|
|
3
|
+
## 0.5.0-beta.3
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- cd911a6: applyAction can now take a batch
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [9839eab]
|
|
12
|
+
- Updated dependencies [cd911a6]
|
|
13
|
+
- Updated dependencies [2c800e5]
|
|
14
|
+
- Updated dependencies [cd911a6]
|
|
15
|
+
- @osdk/client@2.3.0-beta.6
|
|
16
|
+
- @osdk/api@2.3.0-beta.6
|
|
17
|
+
|
|
3
18
|
## 0.5.0-beta.2
|
|
4
19
|
|
|
5
20
|
### Minor Changes
|
|
@@ -25,18 +25,41 @@ export function useOsdkAction(actionDef) {
|
|
|
25
25
|
const [data, setData] = React.useState();
|
|
26
26
|
const [isPending, setPending] = React.useState(false);
|
|
27
27
|
const applyAction = React.useCallback(async function (hookArgs) {
|
|
28
|
-
const {
|
|
29
|
-
$optimisticUpdate,
|
|
30
|
-
...args
|
|
31
|
-
} = hookArgs;
|
|
32
28
|
try {
|
|
33
29
|
setPending(true);
|
|
34
30
|
setError(undefined);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
if (Array.isArray(hookArgs)) {
|
|
32
|
+
const updates = [];
|
|
33
|
+
const args = hookArgs.map(a => {
|
|
34
|
+
const {
|
|
35
|
+
$optimisticUpdate,
|
|
36
|
+
...args
|
|
37
|
+
} = a;
|
|
38
|
+
if ($optimisticUpdate) {
|
|
39
|
+
updates.push($optimisticUpdate);
|
|
40
|
+
}
|
|
41
|
+
return args;
|
|
42
|
+
});
|
|
43
|
+
const r = await observableClient.applyAction(actionDef, args, {
|
|
44
|
+
optimisticUpdate: ctx => {
|
|
45
|
+
for (const update of updates) {
|
|
46
|
+
update?.(ctx);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
setData(r);
|
|
51
|
+
return r;
|
|
52
|
+
} else {
|
|
53
|
+
const {
|
|
54
|
+
$optimisticUpdate,
|
|
55
|
+
...args
|
|
56
|
+
} = hookArgs;
|
|
57
|
+
const r = await observableClient.applyAction(actionDef, args, {
|
|
58
|
+
optimisticUpdate: $optimisticUpdate
|
|
59
|
+
});
|
|
60
|
+
setData(r);
|
|
61
|
+
return r;
|
|
62
|
+
}
|
|
40
63
|
} catch (e) {
|
|
41
64
|
if (e instanceof ActionValidationError) {
|
|
42
65
|
setError({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOsdkAction.js","names":["ActionValidationError","React","OsdkContext2","useOsdkAction","actionDef","observableClient","useContext","error","setError","useState","data","setData","isPending","setPending","applyAction","useCallback","hookArgs","
|
|
1
|
+
{"version":3,"file":"useOsdkAction.js","names":["ActionValidationError","React","OsdkContext2","useOsdkAction","actionDef","observableClient","useContext","error","setError","useState","data","setData","isPending","setPending","applyAction","useCallback","hookArgs","undefined","Array","isArray","updates","args","map","a","$optimisticUpdate","push","r","optimisticUpdate","ctx","update","e","actionValidation","unknown"],"sources":["useOsdkAction.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 { ActionDefinition } from \"@osdk/client\";\nimport { ActionValidationError } from \"@osdk/client\";\nimport type {\n ActionSignatureFromDef,\n ObservableClient,\n} from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\ntype ApplyActionParams<Q extends ActionDefinition<any>> =\n & Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0]\n & {\n [K in keyof ObservableClient.ApplyActionOptions as `$${K}`]:\n ObservableClient.ApplyActionOptions[K];\n };\n\nexport interface UseOsdkActionResult<Q extends ActionDefinition<any>> {\n applyAction: (\n args: ApplyActionParams<Q> | Array<ApplyActionParams<Q>>,\n ) => Promise<unknown>;\n\n error:\n | undefined\n | Partial<{\n actionValidation: ActionValidationError;\n unknown: unknown;\n }>;\n data: unknown;\n\n isPending: boolean;\n}\n\nexport function useOsdkAction<Q extends ActionDefinition<any>>(\n actionDef: Q,\n): UseOsdkActionResult<Q> {\n const { observableClient } = React.useContext(OsdkContext2);\n const [error, setError] = React.useState<UseOsdkActionResult<Q>[\"error\"]>();\n const [data, setData] = React.useState<unknown>();\n const [isPending, setPending] = React.useState(false);\n\n const applyAction = React.useCallback(async function applyAction(\n hookArgs: ApplyActionParams<Q> | Array<ApplyActionParams<Q>>,\n ) {\n try {\n setPending(true);\n setError(undefined);\n\n if (Array.isArray(hookArgs)) {\n const updates: Array<\n ObservableClient.ApplyActionOptions[\"optimisticUpdate\"]\n > = [];\n const args = hookArgs.map(a => {\n const { $optimisticUpdate, ...args } = a;\n if ($optimisticUpdate) {\n updates.push($optimisticUpdate);\n }\n return args;\n });\n\n const r = await observableClient.applyAction(actionDef, args, {\n optimisticUpdate: (ctx) => {\n for (const update of updates) {\n update?.(ctx);\n }\n },\n });\n setData(r);\n return r;\n } else {\n const { $optimisticUpdate, ...args } = hookArgs;\n\n const r = await observableClient.applyAction(actionDef, args, {\n optimisticUpdate: $optimisticUpdate,\n });\n setData(r);\n return r;\n }\n } catch (e) {\n if (e instanceof ActionValidationError) {\n setError({\n actionValidation: e,\n });\n } else {\n setError({ unknown: e });\n }\n } finally {\n setPending(false);\n }\n }, [observableClient, setError]);\n\n return { applyAction, error, data, isPending };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,qBAAqB,QAAQ,cAAc;AAKpD,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,YAAY,QAAQ,mBAAmB;AAyBhD,OAAO,SAASC,aAAaA,CAC3BC,SAAY,EACY;EACxB,MAAM;IAAEC;EAAiB,CAAC,GAAGJ,KAAK,CAACK,UAAU,CAACJ,YAAY,CAAC;EAC3D,MAAM,CAACK,KAAK,EAAEC,QAAQ,CAAC,GAAGP,KAAK,CAACQ,QAAQ,CAAkC,CAAC;EAC3E,MAAM,CAACC,IAAI,EAAEC,OAAO,CAAC,GAAGV,KAAK,CAACQ,QAAQ,CAAU,CAAC;EACjD,MAAM,CAACG,SAAS,EAAEC,UAAU,CAAC,GAAGZ,KAAK,CAACQ,QAAQ,CAAC,KAAK,CAAC;EAErD,MAAMK,WAAW,GAAGb,KAAK,CAACc,WAAW,CAAC,gBACpCC,QAA4D,EAC5D;IACA,IAAI;MACFH,UAAU,CAAC,IAAI,CAAC;MAChBL,QAAQ,CAACS,SAAS,CAAC;MAEnB,IAAIC,KAAK,CAACC,OAAO,CAACH,QAAQ,CAAC,EAAE;QAC3B,MAAMI,OAEL,GAAG,EAAE;QACN,MA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useOsdkAction(actionDef) {
|
|
|
42
42
|
const [data, setData] = React3__default.default.useState();
|
|
43
43
|
const [isPending, setPending] = React3__default.default.useState(false);
|
|
44
44
|
const applyAction = React3__default.default.useCallback(async function applyAction2(hookArgs) {
|
|
45
|
-
const {
|
|
46
|
-
$optimisticUpdate,
|
|
47
|
-
...args
|
|
48
|
-
} = hookArgs;
|
|
49
45
|
try {
|
|
50
46
|
setPending(true);
|
|
51
47
|
setError(void 0);
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
48
|
+
if (Array.isArray(hookArgs)) {
|
|
49
|
+
const updates = [];
|
|
50
|
+
const args = hookArgs.map((a) => {
|
|
51
|
+
const {
|
|
52
|
+
$optimisticUpdate,
|
|
53
|
+
...args2
|
|
54
|
+
} = a;
|
|
55
|
+
if ($optimisticUpdate) {
|
|
56
|
+
updates.push($optimisticUpdate);
|
|
57
|
+
}
|
|
58
|
+
return args2;
|
|
59
|
+
});
|
|
60
|
+
const r = await observableClient.applyAction(actionDef, args, {
|
|
61
|
+
optimisticUpdate: (ctx) => {
|
|
62
|
+
for (const update of updates) {
|
|
63
|
+
update?.(ctx);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
setData(r);
|
|
68
|
+
return r;
|
|
69
|
+
} else {
|
|
70
|
+
const {
|
|
71
|
+
$optimisticUpdate,
|
|
72
|
+
...args
|
|
73
|
+
} = hookArgs;
|
|
74
|
+
const r = await observableClient.applyAction(actionDef, args, {
|
|
75
|
+
optimisticUpdate: $optimisticUpdate
|
|
76
|
+
});
|
|
77
|
+
setData(r);
|
|
78
|
+
return r;
|
|
79
|
+
}
|
|
57
80
|
} catch (e) {
|
|
58
81
|
if (e instanceof client.ActionValidationError) {
|
|
59
82
|
setError({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/new/OsdkContext2.ts","../../../src/new/OsdkProvider2.tsx","../../../src/new/useOsdkAction.ts","../../../src/new/makeExternalStore.ts","../../../src/new/useOsdkObject.ts","../../../src/new/useOsdkObjects.ts"],"names":["useMemo","createObservableClient","React","applyAction","ActionValidationError"],"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;AACM,IAAM,YAAA,2CAAkC,aAAc,CAAA;AAAA,EAC3D,MAAQ,EAAA,UAAA;AAAA,EACR,gBAAkB,EAAA;AACpB,CAAC,CAAA;;;ACPM,SAAS,aAAc,CAAA;AAAA,EAC5B,QAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAG,EAAA;AACD,EAAmB,gBAAA,GAAAA,cAAA,CAAQ,MAAM,gBAAoB,IAAAC,uCAAA,CAAuB,MAAM,CAAG,EAAA,CAAC,MAAQ,EAAA,gBAAgB,CAAC,CAAA;AAC/G,EAAA,uBAAoBC,uBAAAA,CAAM,aAAc,CAAA,YAAA,CAAa,QAAU,EAAA;AAAA,IAC7D,KAAO,EAAA;AAAA,MACL,MAAA;AAAA,MACA;AAAA;AACF,KACC,QAAQ,CAAA;AACb;ACZO,SAAS,cAAc,SAAW,EAAA;AACvC,EAAM,MAAA;AAAA,IACJ;AAAA,GACF,GAAIA,uBAAM,CAAA,UAAA,CAAW,YAAY,CAAA;AACjC,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAIA,wBAAM,QAAS,EAAA;AACzC,EAAA,MAAM,CAAC,IAAA,EAAM,OAAO,CAAA,GAAIA,wBAAM,QAAS,EAAA;AACvC,EAAA,MAAM,CAAC,SAAW,EAAA,UAAU,CAAIA,GAAAA,uBAAAA,CAAM,SAAS,KAAK,CAAA;AACpD,EAAA,MAAM,WAAcA,GAAAA,uBAAAA,CAAM,WAAY,CAAA,eAAe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KAAO,EAAA,WAAA,IAAe,OAAW,IAAA,WAAA,GAAc,aAAa,KAAQ,GAAA,MAAA;AAAA,IACpE,MAAM,WAAa,EAAA,YAAA;AAAA,IACnB,SAAA,EAAW,aAAa,MAAW,KAAA,SAAA;AAAA,IACnC,YAAA,EAAc,aAAa,YAAgB,IAAA;AAAA,GAC7C;AACF","file":"experimental.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 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 { createObservableClient } from \"@osdk/client/unstable-do-not-use\";\nimport React, { useMemo } from \"react\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\nexport function OsdkProvider2({\n children,\n client,\n observableClient\n}) {\n observableClient = useMemo(() => observableClient ?? createObservableClient(client), [client, observableClient]);\n return /*#__PURE__*/React.createElement(OsdkContext2.Provider, {\n value: {\n client,\n observableClient\n }\n }, children);\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\nimport { ActionValidationError } from \"@osdk/client\";\nimport React from \"react\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\nexport function useOsdkAction(actionDef) {\n const {\n observableClient\n } = React.useContext(OsdkContext2);\n const [error, setError] = React.useState();\n const [data, setData] = React.useState();\n const [isPending, setPending] = React.useState(false);\n const applyAction = React.useCallback(async function applyAction(hookArgs) {\n const {\n $optimisticUpdate,\n ...args\n } = hookArgs;\n try {\n setPending(true);\n setError(undefined);\n const r = await observableClient.applyAction(actionDef, args, {\n optimisticUpdate: $optimisticUpdate\n });\n setData(r);\n return r;\n } catch (e) {\n if (e instanceof ActionValidationError) {\n setError({\n actionValidation: e\n });\n } else {\n setError({\n unknown: e\n });\n }\n } finally {\n setPending(false);\n }\n }, [observableClient, setError]);\n return {\n applyAction,\n error,\n data,\n isPending\n };\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) {\n let lastResult;\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 * 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 React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\n/**\n * @param obj an existing `Osdk.Instance` object to get metadata for.\n */\n\n/**\n * Loads an object by type and primary key.\n *\n * @param type\n * @param primaryKey\n */\n\n/*\n Implementation of useOsdkObject\n */\nexport function useOsdkObject(...args) {\n const {\n observableClient\n } = React.useContext(OsdkContext2);\n\n // TODO: Figure out what the correct default behavior is for the various scenarios\n const mode = args.length === 1 ? \"offline\" : undefined;\n const objectType = args.length === 1 ? args[0].$objectType : args[0].apiName;\n const primaryKey = args.length === 1 ? args[0].$primaryKey : args[1];\n const {\n subscribe,\n getSnapShot\n } = React.useMemo(() => makeExternalStore(observer => observableClient.observeObject(objectType, primaryKey, {\n mode\n }, observer), `object ${objectType} ${primaryKey}`), [observableClient, objectType, primaryKey, mode]);\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n return {\n object: payload?.object,\n isLoading: payload?.status === \"loading\",\n isOptimistic: !!payload?.isOptimistic,\n error: payload && \"error\" in payload ? payload.error : undefined,\n forceUpdate: () => {\n throw \"not implemented\";\n }\n };\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\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\nexport function useOsdkObjects(type, {\n pageSize,\n orderBy,\n dedupeIntervalMs,\n where = {},\n streamUpdates\n} = {}) {\n const {\n observableClient\n } = React.useContext(OsdkContext2);\n\n /* We want the canonical where clause so that the use of `React.useMemo`\n is stable. No real added cost as we canonicalize internal to\n the ObservableClient anyway.\n */\n const canonWhere = observableClient.canonicalizeWhereClause(where ?? {});\n const {\n subscribe,\n getSnapShot\n } = React.useMemo(() => makeExternalStore(observer => observableClient.observeList({\n type,\n where: canonWhere,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n pageSize,\n orderBy,\n streamUpdates\n }, observer), process.env.NODE_ENV !== \"production\" ? `list ${type.apiName} ${JSON.stringify(canonWhere)}` : void 0), [observableClient, type, canonWhere, dedupeIntervalMs]);\n const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);\n // TODO: we need to expose the error in the result\n return {\n fetchMore: listPayload?.fetchMore,\n error: listPayload && \"error\" in listPayload ? listPayload?.error : undefined,\n data: listPayload?.resolvedList,\n isLoading: listPayload?.status === \"loading\",\n isOptimistic: listPayload?.isOptimistic ?? false\n };\n}"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/new/OsdkContext2.ts","../../../src/new/OsdkProvider2.tsx","../../../src/new/useOsdkAction.ts","../../../src/new/makeExternalStore.ts","../../../src/new/useOsdkObject.ts","../../../src/new/useOsdkObjects.ts"],"names":["useMemo","createObservableClient","React","applyAction","args","ActionValidationError"],"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;AACM,IAAM,YAAA,2CAAkC,aAAc,CAAA;AAAA,EAC3D,MAAQ,EAAA,UAAA;AAAA,EACR,gBAAkB,EAAA;AACpB,CAAC,CAAA;;;ACPM,SAAS,aAAc,CAAA;AAAA,EAC5B,QAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAAG,EAAA;AACD,EAAmB,gBAAA,GAAAA,cAAA,CAAQ,MAAM,gBAAoB,IAAAC,uCAAA,CAAuB,MAAM,CAAG,EAAA,CAAC,MAAQ,EAAA,gBAAgB,CAAC,CAAA;AAC/G,EAAA,uBAAoBC,uBAAAA,CAAM,aAAc,CAAA,YAAA,CAAa,QAAU,EAAA;AAAA,IAC7D,KAAO,EAAA;AAAA,MACL,MAAA;AAAA,MACA;AAAA;AACF,KACC,QAAQ,CAAA;AACb;ACZO,SAAS,cAAc,SAAW,EAAA;AACvC,EAAM,MAAA;AAAA,IACJ;AAAA,GACF,GAAIA,uBAAM,CAAA,UAAA,CAAW,YAAY,CAAA;AACjC,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAIA,wBAAM,QAAS,EAAA;AACzC,EAAA,MAAM,CAAC,IAAA,EAAM,OAAO,CAAA,GAAIA,wBAAM,QAAS,EAAA;AACvC,EAAA,MAAM,CAAC,SAAW,EAAA,UAAU,CAAIA,GAAAA,uBAAAA,CAAM,SAAS,KAAK,CAAA;AACpD,EAAA,MAAM,WAAcA,GAAAA,uBAAAA,CAAM,WAAY,CAAA,eAAeC,aAAY,QAAU,EAAA;AACzE,IAAI,IAAA;A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EA,uBAAM,CAAA,OAAA,CAAQ,MAAM,iBAAkB,CAAA,CAAA,QAAA,KAAY,iBAAiB,WAAY,CAAA;AAAA,IACjF,IAAA;AAAA,IACA,KAAO,EAAA,UAAA;AAAA,IACP,gBAAgB,gBAAoB,IAAA,GAAA;AAAA,IACpC,QAAA;AAAA,IACA,OAAA;AAAA,IACA;AAAA,GACF,EAAG,QAAQ,CAAG,EAAA,OAAA,CAAQ,IAAI,QAAa,KAAA,YAAA,GAAe,CAAQ,KAAA,EAAA,IAAA,CAAK,OAAO,CAAA,CAAA,EAAI,KAAK,SAAU,CAAA,UAAU,CAAC,CAAA,CAAA,GAAK,MAAM,CAAA,EAAG,CAAC,gBAAkB,EAAA,IAAA,EAAM,UAAY,EAAA,gBAAgB,CAAC,CAAA;AAC5K,EAAA,MAAM,WAAcA,GAAAA,uBAAAA,CAAM,oBAAqB,CAAA,SAAA,EAAW,WAAW,CAAA;AAErE,EAAO,OAAA;AAAA,IACL,WAAW,WAAa,EAAA,SAAA;AAAA,IACxB,KAAO,EAAA,WAAA,IAAe,OAAW,IAAA,WAAA,GAAc,aAAa,KAAQ,GAAA,MAAA;AAAA,IACpE,MAAM,WAAa,EAAA,YAAA;AAAA,IACnB,SAAA,EAAW,aAAa,MAAW,KAAA,SAAA;AAAA,IACnC,YAAA,EAAc,aAAa,YAAgB,IAAA;AAAA,GAC7C;AACF","file":"experimental.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 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 { createObservableClient } from \"@osdk/client/unstable-do-not-use\";\nimport React, { useMemo } from \"react\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\nexport function OsdkProvider2({\n children,\n client,\n observableClient\n}) {\n observableClient = useMemo(() => observableClient ?? createObservableClient(client), [client, observableClient]);\n return /*#__PURE__*/React.createElement(OsdkContext2.Provider, {\n value: {\n client,\n observableClient\n }\n }, children);\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\nimport { ActionValidationError } from \"@osdk/client\";\nimport React from \"react\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\nexport function useOsdkAction(actionDef) {\n const {\n observableClient\n } = React.useContext(OsdkContext2);\n const [error, setError] = React.useState();\n const [data, setData] = React.useState();\n const [isPending, setPending] = React.useState(false);\n const applyAction = React.useCallback(async function applyAction(hookArgs) {\n try {\n setPending(true);\n setError(undefined);\n if (Array.isArray(hookArgs)) {\n const updates = [];\n const args = hookArgs.map(a => {\n const {\n $optimisticUpdate,\n ...args\n } = a;\n if ($optimisticUpdate) {\n updates.push($optimisticUpdate);\n }\n return args;\n });\n const r = await observableClient.applyAction(actionDef, args, {\n optimisticUpdate: ctx => {\n for (const update of updates) {\n update?.(ctx);\n }\n }\n });\n setData(r);\n return r;\n } else {\n const {\n $optimisticUpdate,\n ...args\n } = hookArgs;\n const r = await observableClient.applyAction(actionDef, args, {\n optimisticUpdate: $optimisticUpdate\n });\n setData(r);\n return r;\n }\n } catch (e) {\n if (e instanceof ActionValidationError) {\n setError({\n actionValidation: e\n });\n } else {\n setError({\n unknown: e\n });\n }\n } finally {\n setPending(false);\n }\n }, [observableClient, setError]);\n return {\n applyAction,\n error,\n data,\n isPending\n };\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) {\n let lastResult;\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 * 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 React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\n/**\n * @param obj an existing `Osdk.Instance` object to get metadata for.\n */\n\n/**\n * Loads an object by type and primary key.\n *\n * @param type\n * @param primaryKey\n */\n\n/*\n Implementation of useOsdkObject\n */\nexport function useOsdkObject(...args) {\n const {\n observableClient\n } = React.useContext(OsdkContext2);\n\n // TODO: Figure out what the correct default behavior is for the various scenarios\n const mode = args.length === 1 ? \"offline\" : undefined;\n const objectType = args.length === 1 ? args[0].$objectType : args[0].apiName;\n const primaryKey = args.length === 1 ? args[0].$primaryKey : args[1];\n const {\n subscribe,\n getSnapShot\n } = React.useMemo(() => makeExternalStore(observer => observableClient.observeObject(objectType, primaryKey, {\n mode\n }, observer), `object ${objectType} ${primaryKey}`), [observableClient, objectType, primaryKey, mode]);\n const payload = React.useSyncExternalStore(subscribe, getSnapShot);\n return {\n object: payload?.object,\n isLoading: payload?.status === \"loading\",\n isOptimistic: !!payload?.isOptimistic,\n error: payload && \"error\" in payload ? payload.error : undefined,\n forceUpdate: () => {\n throw \"not implemented\";\n }\n };\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\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\nexport function useOsdkObjects(type, {\n pageSize,\n orderBy,\n dedupeIntervalMs,\n where = {},\n streamUpdates\n} = {}) {\n const {\n observableClient\n } = React.useContext(OsdkContext2);\n\n /* We want the canonical where clause so that the use of `React.useMemo`\n is stable. No real added cost as we canonicalize internal to\n the ObservableClient anyway.\n */\n const canonWhere = observableClient.canonicalizeWhereClause(where ?? {});\n const {\n subscribe,\n getSnapShot\n } = React.useMemo(() => makeExternalStore(observer => observableClient.observeList({\n type,\n where: canonWhere,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n pageSize,\n orderBy,\n streamUpdates\n }, observer), process.env.NODE_ENV !== \"production\" ? `list ${type.apiName} ${JSON.stringify(canonWhere)}` : void 0), [observableClient, type, canonWhere, dedupeIntervalMs]);\n const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);\n // TODO: we need to expose the error in the result\n return {\n fetchMore: listPayload?.fetchMore,\n error: listPayload && \"error\" in listPayload ? listPayload?.error : undefined,\n data: listPayload?.resolvedList,\n isLoading: listPayload?.status === \"loading\",\n isOptimistic: listPayload?.isOptimistic ?? false\n };\n}"]}
|
|
@@ -15,7 +15,7 @@ type ApplyActionParams<Q extends ActionDefinition<any>> = Parameters<ActionSigna
|
|
|
15
15
|
[K in keyof ObservableClient.ApplyActionOptions as `$${K}`]: ObservableClient.ApplyActionOptions[K];
|
|
16
16
|
};
|
|
17
17
|
interface UseOsdkActionResult<Q extends ActionDefinition<any>> {
|
|
18
|
-
applyAction: (args: ApplyActionParams<Q>) => Promise<unknown>;
|
|
18
|
+
applyAction: (args: ApplyActionParams<Q> | Array<ApplyActionParams<Q>>) => Promise<unknown>;
|
|
19
19
|
error: undefined | Partial<{
|
|
20
20
|
actionValidation: ActionValidationError;
|
|
21
21
|
unknown: unknown;
|
|
@@ -25,18 +25,41 @@ export function useOsdkAction(actionDef) {
|
|
|
25
25
|
const [data, setData] = React.useState();
|
|
26
26
|
const [isPending, setPending] = React.useState(false);
|
|
27
27
|
const applyAction = React.useCallback(async function (hookArgs) {
|
|
28
|
-
const {
|
|
29
|
-
$optimisticUpdate,
|
|
30
|
-
...args
|
|
31
|
-
} = hookArgs;
|
|
32
28
|
try {
|
|
33
29
|
setPending(true);
|
|
34
30
|
setError(undefined);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
if (Array.isArray(hookArgs)) {
|
|
32
|
+
const updates = [];
|
|
33
|
+
const args = hookArgs.map(a => {
|
|
34
|
+
const {
|
|
35
|
+
$optimisticUpdate,
|
|
36
|
+
...args
|
|
37
|
+
} = a;
|
|
38
|
+
if ($optimisticUpdate) {
|
|
39
|
+
updates.push($optimisticUpdate);
|
|
40
|
+
}
|
|
41
|
+
return args;
|
|
42
|
+
});
|
|
43
|
+
const r = await observableClient.applyAction(actionDef, args, {
|
|
44
|
+
optimisticUpdate: ctx => {
|
|
45
|
+
for (const update of updates) {
|
|
46
|
+
update?.(ctx);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
setData(r);
|
|
51
|
+
return r;
|
|
52
|
+
} else {
|
|
53
|
+
const {
|
|
54
|
+
$optimisticUpdate,
|
|
55
|
+
...args
|
|
56
|
+
} = hookArgs;
|
|
57
|
+
const r = await observableClient.applyAction(actionDef, args, {
|
|
58
|
+
optimisticUpdate: $optimisticUpdate
|
|
59
|
+
});
|
|
60
|
+
setData(r);
|
|
61
|
+
return r;
|
|
62
|
+
}
|
|
40
63
|
} catch (e) {
|
|
41
64
|
if (e instanceof ActionValidationError) {
|
|
42
65
|
setError({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOsdkAction.js","names":["ActionValidationError","React","OsdkContext2","useOsdkAction","actionDef","observableClient","useContext","error","setError","useState","data","setData","isPending","setPending","applyAction","useCallback","hookArgs","
|
|
1
|
+
{"version":3,"file":"useOsdkAction.js","names":["ActionValidationError","React","OsdkContext2","useOsdkAction","actionDef","observableClient","useContext","error","setError","useState","data","setData","isPending","setPending","applyAction","useCallback","hookArgs","undefined","Array","isArray","updates","args","map","a","$optimisticUpdate","push","r","optimisticUpdate","ctx","update","e","actionValidation","unknown"],"sources":["useOsdkAction.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 { ActionDefinition } from \"@osdk/client\";\nimport { ActionValidationError } from \"@osdk/client\";\nimport type {\n ActionSignatureFromDef,\n ObservableClient,\n} from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\ntype ApplyActionParams<Q extends ActionDefinition<any>> =\n & Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0]\n & {\n [K in keyof ObservableClient.ApplyActionOptions as `$${K}`]:\n ObservableClient.ApplyActionOptions[K];\n };\n\nexport interface UseOsdkActionResult<Q extends ActionDefinition<any>> {\n applyAction: (\n args: ApplyActionParams<Q> | Array<ApplyActionParams<Q>>,\n ) => Promise<unknown>;\n\n error:\n | undefined\n | Partial<{\n actionValidation: ActionValidationError;\n unknown: unknown;\n }>;\n data: unknown;\n\n isPending: boolean;\n}\n\nexport function useOsdkAction<Q extends ActionDefinition<any>>(\n actionDef: Q,\n): UseOsdkActionResult<Q> {\n const { observableClient } = React.useContext(OsdkContext2);\n const [error, setError] = React.useState<UseOsdkActionResult<Q>[\"error\"]>();\n const [data, setData] = React.useState<unknown>();\n const [isPending, setPending] = React.useState(false);\n\n const applyAction = React.useCallback(async function applyAction(\n hookArgs: ApplyActionParams<Q> | Array<ApplyActionParams<Q>>,\n ) {\n try {\n setPending(true);\n setError(undefined);\n\n if (Array.isArray(hookArgs)) {\n const updates: Array<\n ObservableClient.ApplyActionOptions[\"optimisticUpdate\"]\n > = [];\n const args = hookArgs.map(a => {\n const { $optimisticUpdate, ...args } = a;\n if ($optimisticUpdate) {\n updates.push($optimisticUpdate);\n }\n return args;\n });\n\n const r = await observableClient.applyAction(actionDef, args, {\n optimisticUpdate: (ctx) => {\n for (const update of updates) {\n update?.(ctx);\n }\n },\n });\n setData(r);\n return r;\n } else {\n const { $optimisticUpdate, ...args } = hookArgs;\n\n const r = await observableClient.applyAction(actionDef, args, {\n optimisticUpdate: $optimisticUpdate,\n });\n setData(r);\n return r;\n }\n } catch (e) {\n if (e instanceof ActionValidationError) {\n setError({\n actionValidation: e,\n });\n } else {\n setError({ unknown: e });\n }\n } finally {\n setPending(false);\n }\n }, [observableClient, setError]);\n\n return { applyAction, error, data, isPending };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,qBAAqB,QAAQ,cAAc;AAKpD,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,YAAY,QAAQ,mBAAmB;AAyBhD,OAAO,SAASC,aAAaA,CAC3BC,SAAY,EACY;EACxB,MAAM;IAAEC;EAAiB,CAAC,GAAGJ,KAAK,CAACK,UAAU,CAACJ,YAAY,CAAC;EAC3D,MAAM,CAACK,KAAK,EAAEC,QAAQ,CAAC,GAAGP,KAAK,CAACQ,QAAQ,CAAkC,CAAC;EAC3E,MAAM,CAACC,IAAI,EAAEC,OAAO,CAAC,GAAGV,KAAK,CAACQ,QAAQ,CAAU,CAAC;EACjD,MAAM,CAACG,SAAS,EAAEC,UAAU,CAAC,GAAGZ,KAAK,CAACQ,QAAQ,CAAC,KAAK,CAAC;EAErD,MAAMK,WAAW,GAAGb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C,SAAS;MACRjB,UAAU,CAAC,KAAK,CAAC;IACnB;EACF,CAAC,EAAE,CAACR,gBAAgB,EAAEG,QAAQ,CAAC,CAAC;EAEhC,OAAO;IAAEM,WAAW;IAAEP,KAAK;IAAEG,IAAI;IAAEE;EAAU,CAAC;AAChD","ignoreList":[]}
|
|
@@ -3,7 +3,7 @@ import { ActionValidationError } from "@osdk/client";
|
|
|
3
3
|
import type { ActionSignatureFromDef, ObservableClient } from "@osdk/client/unstable-do-not-use";
|
|
4
4
|
type ApplyActionParams<Q extends ActionDefinition<any>> = Parameters<ActionSignatureFromDef<Q>["applyAction"]>[0] & { [K in keyof ObservableClient.ApplyActionOptions as `$${K}`] : ObservableClient.ApplyActionOptions[K] };
|
|
5
5
|
export interface UseOsdkActionResult<Q extends ActionDefinition<any>> {
|
|
6
|
-
applyAction: (args: ApplyActionParams<Q>) => Promise<unknown>;
|
|
6
|
+
applyAction: (args: ApplyActionParams<Q> | Array<ApplyActionParams<Q>>) => Promise<unknown>;
|
|
7
7
|
error: undefined | Partial<{
|
|
8
8
|
actionValidation: ActionValidationError
|
|
9
9
|
unknown: unknown
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAgBA,cAAc,wBAAwB,cAAe;AACrD,SAAS,6BAA6B,cAAe;AACrD,cACE,wBACA,wBACK,kCAAmC;KAIrC,kBAAkB,UAAU,yBAC7B,WAAW,uBAAuB,GAAG,gBAAgB,QAEpD,WAAW,iBAAiB,0BAA0B,OACrD,iBAAiB,mBAAmB;AAG1C,iBAAiB,oBAAoB,UAAU,uBAAuB;CACpE,cACEA,MAAM,kBAAkB,
|
|
1
|
+
{"mappings":"AAgBA,cAAc,wBAAwB,cAAe;AACrD,SAAS,6BAA6B,cAAe;AACrD,cACE,wBACA,wBACK,kCAAmC;KAIrC,kBAAkB,UAAU,yBAC7B,WAAW,uBAAuB,GAAG,gBAAgB,QAEpD,WAAW,iBAAiB,0BAA0B,OACrD,iBAAiB,mBAAmB;AAG1C,iBAAiB,oBAAoB,UAAU,uBAAuB;CACpE,cACEA,MAAM,kBAAkB,KAAK,MAAM,kBAAkB,QAClD;CAEL,mBAEI,QAAQ;EACR,kBAAkB;EAClB;CACD;CACH;CAEA;AACD;AAED,OAAO,iBAAS,cAAc,UAAU,uBACtCC,WAAW,IACV,oBAAoB","names":["args: ApplyActionParams<Q> | Array<ApplyActionParams<Q>>","actionDef: Q"],"sources":["../../../src/new/useOsdkAction.ts"],"version":3,"file":"useOsdkAction.d.ts"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@osdk/react",
|
|
3
|
-
"version": "0.5.0-beta.
|
|
3
|
+
"version": "0.5.0-beta.3",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -48,11 +48,12 @@
|
|
|
48
48
|
"happy-dom": "^16.8.1",
|
|
49
49
|
"p-defer": "^4.0.1",
|
|
50
50
|
"react": "^18.0.0",
|
|
51
|
+
"tiny-invariant": "^1.3.3",
|
|
51
52
|
"typescript": "~5.5.4",
|
|
52
|
-
"@osdk/
|
|
53
|
+
"@osdk/client": "2.3.0-beta.6",
|
|
53
54
|
"@osdk/monorepo.api-extractor": "~0.2.0-beta.1",
|
|
54
55
|
"@osdk/monorepo.tsconfig": "~0.2.0-beta.1",
|
|
55
|
-
"@osdk/
|
|
56
|
+
"@osdk/api": "2.3.0-beta.6"
|
|
56
57
|
},
|
|
57
58
|
"publishConfig": {
|
|
58
59
|
"access": "public"
|