@osdk/react 0.3.0-rc.4 → 0.4.0-beta.2

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 CHANGED
@@ -1,10 +1,16 @@
1
1
  # @osdkkit/react
2
2
 
3
- ## 0.3.0-rc.4
3
+ ## 0.4.0-beta.2
4
+
5
+ ### Minor Changes
6
+
7
+ - fe0cc43: Experimental react changes
4
8
 
5
9
  ### Patch Changes
6
10
 
7
- - 66a8ee4: Adding support for react caching work.
11
+ - Updated dependencies [fe0cc43]
12
+ - @osdk/client@2.2.0-beta.4
13
+ - @osdk/api@2.2.0-beta.4
8
14
 
9
15
  ## 0.3.0-beta.3
10
16
 
@@ -14,22 +14,18 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- export function makeExternalStore(createObservation, name) {
17
+ export function makeExternalStore(createObservation) {
18
18
  let lastResult;
19
19
  function getSnapShot() {
20
20
  return lastResult;
21
21
  }
22
22
  return {
23
23
  subscribe: function subscribe(notifyUpdate) {
24
- // eslint-disable-next-line no-console
25
- console.log("Subscribing", name);
26
24
  const obs = createObservation(payload => {
27
25
  lastResult = payload;
28
26
  notifyUpdate();
29
27
  });
30
28
  return () => {
31
- // eslint-disable-next-line no-console
32
- console.log("Unsubscribing", name);
33
29
  obs.unsubscribe();
34
30
  };
35
31
  },
@@ -1 +1 @@
1
- {"version":3,"file":"makeExternalStore.js","names":["makeExternalStore","createObservation","name","lastResult","getSnapShot","subscribe","notifyUpdate","console","log","obs","payload","unsubscribe"],"sources":["makeExternalStore.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 { Unsubscribable } from \"@osdk/client/unstable-do-not-use\";\n\nexport function makeExternalStore<X>(\n createObservation: (callback: (x: X | undefined) => void) => Unsubscribable,\n name?: string,\n): {\n subscribe: (notifyUpdate: () => void) => () => void;\n getSnapShot: () => X | undefined;\n} {\n let lastResult: X | undefined;\n\n function getSnapShot(): X | undefined {\n return lastResult;\n }\n\n function subscribe(notifyUpdate: () => void) {\n // eslint-disable-next-line no-console\n console.log(\"Subscribing\", name);\n const obs = createObservation((payload) => {\n lastResult = payload;\n notifyUpdate();\n });\n\n return (): void => {\n // eslint-disable-next-line no-console\n console.log(\"Unsubscribing\", name);\n obs.unsubscribe();\n };\n }\n\n return {\n subscribe,\n getSnapShot,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAO,SAASA,iBAAiBA,CAC/BC,iBAA2E,EAC3EC,IAAa,EAIb;EACA,IAAIC,UAAyB;EAE7B,SAASC,WAAWA,CAAA,EAAkB;IACpC,OAAOD,UAAU;EACnB;EAiBA,OAAO;IACLE,SAAS,EAhBX,SAASA,SAASA,CAACC,YAAwB,EAAE;MAC3C;MACAC,OAAO,CAACC,GAAG,CAAC,aAAa,EAAEN,IAAI,CAAC;MAChC,MAAMO,GAAG,GAAGR,iBAAiB,CAAES,OAAO,IAAK;QACzCP,UAAU,GAAGO,OAAO;QACpBJ,YAAY,CAAC,CAAC;MAChB,CAAC,CAAC;MAEF,OAAO,MAAY;QACjB;QACAC,OAAO,CAACC,GAAG,CAAC,eAAe,EAAEN,IAAI,CAAC;QAClCO,GAAG,CAACE,WAAW,CAAC,CAAC;MACnB,CAAC;IACH,CAGW;IACTP;EACF,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"makeExternalStore.js","names":["makeExternalStore","createObservation","lastResult","getSnapShot","subscribe","notifyUpdate","obs","payload","unsubscribe"],"sources":["makeExternalStore.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 { Unsubscribable } from \"@osdk/client/unstable-do-not-use\";\n\nexport function makeExternalStore<X>(\n createObservation: (callback: (x: X | undefined) => void) => Unsubscribable,\n name?: string,\n): {\n subscribe: (notifyUpdate: () => void) => () => void;\n getSnapShot: () => X | undefined;\n} {\n let lastResult: X | undefined;\n\n function getSnapShot(): X | undefined {\n return lastResult;\n }\n\n function subscribe(notifyUpdate: () => void) {\n const obs = createObservation((payload) => {\n lastResult = payload;\n notifyUpdate();\n });\n\n return (): void => {\n obs.unsubscribe();\n };\n }\n\n return {\n subscribe,\n getSnapShot,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAO,SAASA,iBAAiBA,CAC/BC,iBAA2E,EAK3E;EACA,IAAIC,UAAyB;EAE7B,SAASC,WAAWA,CAAA,EAAkB;IACpC,OAAOD,UAAU;EACnB;EAaA,OAAO;IACLE,SAAS,EAZX,SAASA,SAASA,CAACC,YAAwB,EAAE;MAC3C,MAAMC,GAAG,GAAGL,iBAAiB,CAAEM,OAAO,IAAK;QACzCL,UAAU,GAAGK,OAAO;QACpBF,YAAY,CAAC,CAAC;MAChB,CAAC,CAAC;MAEF,OAAO,MAAY;QACjBC,GAAG,CAACE,WAAW,CAAC,CAAC;MACnB,CAAC;IACH,CAGW;IACTL;EACF,CAAC;AACH","ignoreList":[]}
@@ -23,9 +23,18 @@ export function useOsdkAction(actionDef) {
23
23
  } = React.useContext(OsdkContext2);
24
24
  const [error, setError] = React.useState();
25
25
  const [data, setData] = React.useState();
26
- const applyAction = React.useCallback(async function (args, opts) {
26
+ const [isPending, setPending] = React.useState(false);
27
+ const applyAction = React.useCallback(async function (hookArgs) {
28
+ const {
29
+ $optimisticUpdate,
30
+ ...args
31
+ } = hookArgs;
27
32
  try {
28
- const r = await store.applyAction(actionDef, args, opts);
33
+ setPending(true);
34
+ setError(undefined);
35
+ const r = await store.applyAction(actionDef, args, {
36
+ optimisticUpdate: $optimisticUpdate
37
+ });
29
38
  setData(r);
30
39
  return r;
31
40
  } catch (e) {
@@ -38,12 +47,15 @@ export function useOsdkAction(actionDef) {
38
47
  unknown: e
39
48
  });
40
49
  }
50
+ } finally {
51
+ setPending(false);
41
52
  }
42
53
  }, [store, setError]);
43
54
  return {
44
55
  applyAction,
45
56
  error,
46
- data
57
+ data,
58
+ isPending
47
59
  };
48
60
  }
49
61
  //# sourceMappingURL=useOsdkAction.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useOsdkAction.js","names":["ActionValidationError","React","OsdkContext2","useOsdkAction","actionDef","store","useContext","error","setError","useState","data","setData","applyAction","useCallback","args","opts","r","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\nexport interface UseOsdkActionResult<Q extends ActionDefinition<any>> {\n applyAction: (\n args: Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0],\n opts: ObservableClient.ApplyActionOptions,\n ) => Promise<unknown>;\n\n error:\n | undefined\n | Partial<{\n actionValidation: ActionValidationError;\n unknown: unknown;\n }>;\n data: unknown;\n}\n\nexport function useOsdkAction<Q extends ActionDefinition<any>>(\n actionDef: Q,\n): UseOsdkActionResult<Q> {\n const { store } = React.useContext(OsdkContext2);\n const [error, setError] = React.useState<UseOsdkActionResult<Q>[\"error\"]>();\n const [data, setData] = React.useState<unknown>();\n\n const applyAction = React.useCallback(async function applyAction(\n args: Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0],\n opts: ObservableClient.ApplyActionOptions,\n ) {\n try {\n const r = await store.applyAction(actionDef, args, opts);\n setData(r);\n return r;\n } catch (e) {\n if (e instanceof ActionValidationError) {\n setError({\n actionValidation: e,\n });\n } else {\n setError({ unknown: e });\n }\n }\n }, [store, setError]);\n\n return { applyAction, error, data };\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;AAiBhD,OAAO,SAASC,aAAaA,CAC3BC,SAAY,EACY;EACxB,MAAM;IAAEC;EAAM,CAAC,GAAGJ,KAAK,CAACK,UAAU,CAACJ,YAAY,CAAC;EAChD,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;EAEjD,MAAMG,WAAW,GAAGX,KAAK,CAACY,WAAW,CAAC,gBACpCC,IAA6D,EAC7DC,IAAyC,EACzC;IACA,IAAI;MACF,MAAMC,CAAC,GAAG,MAAMX,KAAK,CAACO,WAAW,CAACR,SAAS,EAAEU,IAAI,EAAEC,IAAI,CAAC;MACxDJ,OAAO,CAACK,CAAC,CAAC;MACV,OAAOA,CAAC;IACV,CAAC,CAAC,OAAOC,CAAC,EAAE;MACV,IAAIA,CAAC,YAAYjB,qBAAqB,EAAE;QACtCQ,QAAQ,CAAC;UACPU,gBAAgB,EAAED;QACpB,CAAC,CAAC;MACJ,CAAC,MAAM;QACLT,QAAQ,CAAC;UAAEW,OAAO,EAAEF;QAAE,CAAC,CAAC;MAC1B;IACF;EACF,CAAC,EAAE,CAACZ,KAAK,EAAEG,QAAQ,CAAC,CAAC;EAErB,OAAO;IAAEI,WAAW;IAAEL,KAAK;IAAEG;EAAK,CAAC;AACrC","ignoreList":[]}
1
+ {"version":3,"file":"useOsdkAction.js","names":["ActionValidationError","React","OsdkContext2","useOsdkAction","actionDef","store","useContext","error","setError","useState","data","setData","isPending","setPending","applyAction","useCallback","hookArgs","$optimisticUpdate","args","undefined","r","optimisticUpdate","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>,\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 { store } = 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>,\n ) {\n const { $optimisticUpdate, ...args } = hookArgs;\n try {\n setPending(true);\n setError(undefined);\n const r = await store.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({ unknown: e });\n }\n } finally {\n setPending(false);\n }\n }, [store, 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;EAAM,CAAC,GAAGJ,KAAK,CAACK,UAAU,CAACJ,YAAY,CAAC;EAChD,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,QAA8B,EAC9B;IACA,MAAM;MAAEC,iBAAiB;MAAE,GAAGC;IAAK,CAAC,GAAGF,QAAQ;IAC/C,IAAI;MACFH,UAAU,CAAC,IAAI,CAAC;MAChBL,QAAQ,CAACW,SAAS,CAAC;MACnB,MAAMC,CAAC,GAAG,MAAMf,KAAK,CAACS,WAAW,CAACV,SAAS,EAAEc,IAAI,EAAE;QACjDG,gBAAgB,EAAEJ;MACpB,CAAC,CAAC;MACFN,OAAO,CAACS,CAAC,CAAC;MACV,OAAOA,CAAC;IACV,CAAC,CAAC,OAAOE,CAAC,EAAE;MACV,IAAIA,CAAC,YAAYtB,qBAAqB,EAAE;QACtCQ,QAAQ,CAAC;UACPe,gBAAgB,EAAED;QACpB,CAAC,CAAC;MACJ,CAAC,MAAM;QACLd,QAAQ,CAAC;UAAEgB,OAAO,EAAEF;QAAE,CAAC,CAAC;MAC1B;IACF,CAAC,SAAS;MACRT,UAAU,CAAC,KAAK,CAAC;IACnB;EACF,CAAC,EAAE,CAACR,KAAK,EAAEG,QAAQ,CAAC,CAAC;EAErB,OAAO;IAAEM,WAAW;IAAEP,KAAK;IAAEG,IAAI;IAAEE;EAAU,CAAC;AAChD","ignoreList":[]}
@@ -17,17 +17,33 @@
17
17
  import React from "react";
18
18
  import { makeExternalStore } from "./makeExternalStore.js";
19
19
  import { OsdkContext2 } from "./OsdkContext2.js";
20
- export function useOsdkList(type, opts) {
20
+ export function useOsdkList(objectType, {
21
+ pageSize,
22
+ orderBy,
23
+ dedupeIntervalMs,
24
+ where,
25
+ streamUpdates
26
+ }) {
21
27
  const {
22
28
  store
23
29
  } = React.useContext(OsdkContext2);
24
- const where = store.canonicalizeWhereClause(opts.where);
30
+
31
+ /* We want the canonical where clause so that the use of `React.useMemo`
32
+ is stable. No real added cost as we canonicalize internal to
33
+ the ObservableClient anyway.
34
+ */
35
+ const canonWhere = store.canonicalizeWhereClause(where ?? {});
25
36
  const {
26
37
  subscribe,
27
38
  getSnapShot
28
- } = React.useMemo(() => makeExternalStore(x => store.observeList(type, where, {
29
- dedupeInterval: opts.dedupeIntervalMs ?? 2_000
30
- }, x), `list ${type.apiName} ${JSON.stringify(where)}`), [store, type, where, opts.dedupeIntervalMs]);
39
+ } = React.useMemo(() => makeExternalStore(x => store.observeList({
40
+ objectType,
41
+ where: canonWhere,
42
+ dedupeInterval: dedupeIntervalMs ?? 2_000,
43
+ pageSize,
44
+ orderBy,
45
+ streamUpdates
46
+ }, x), process.env.NODE_ENV !== "production" ? `list ${objectType.apiName} ${JSON.stringify(canonWhere)}` : void 0), [store, objectType, canonWhere, dedupeIntervalMs]);
31
47
  const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);
32
48
  return {
33
49
  fetchMore: listPayload?.fetchMore,
@@ -1 +1 @@
1
- {"version":3,"file":"useOsdkList.js","names":["React","makeExternalStore","OsdkContext2","useOsdkList","type","opts","store","useContext","where","canonicalizeWhereClause","subscribe","getSnapShot","useMemo","x","observeList","dedupeInterval","dedupeIntervalMs","apiName","JSON","stringify","listPayload","useSyncExternalStore","fetchMore","data","resolvedList","isLoading","status","error","undefined","isOptimistic"],"sources":["useOsdkList.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 { ObjectTypeDefinition, Osdk, WhereClause } from \"@osdk/client\";\nimport type { ListPayload } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkListOptions<T extends ObjectTypeDefinition> {\n where: WhereClause<T>;\n\n /**\n * The number of milliseconds to wait after the last observed list change.\n *\n * Two uses of `useOsdkList` with the where clause will only trigger one\n * network request if the second is within `dedupeIntervalMs`.\n */\n dedupeIntervalMs?: number;\n}\nexport interface UseOsdkListResult<T extends ObjectTypeDefinition> {\n fetchMore: (() => Promise<unknown>) | undefined;\n data: Osdk.Instance<T>[];\n isLoading: boolean;\n\n // FIXME populate error!\n error: undefined;\n\n /**\n * Refers to whether the ordered list of objects (only considering the $primaryKey)\n * is optimistic or not.\n *\n * If you need to know if the contents of the list are optimistic you can\n * do that on a per object basis with useOsdkObject\n */\n isOptimistic: boolean;\n}\n\nexport function useOsdkList<T extends ObjectTypeDefinition>(\n type: T,\n opts: UseOsdkListOptions<T>,\n): UseOsdkListResult<T> {\n const { store } = React.useContext(OsdkContext2);\n const where = store.canonicalizeWhereClause(opts.where);\n\n const { subscribe, getSnapShot } = React.useMemo(\n () =>\n makeExternalStore<ListPayload>((x) =>\n store.observeList(\n type,\n where,\n {\n dedupeInterval: opts.dedupeIntervalMs ?? 2_000,\n },\n x,\n ), `list ${type.apiName} ${JSON.stringify(where)}`),\n [store, type, where, opts.dedupeIntervalMs],\n );\n\n const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n return {\n fetchMore: listPayload?.fetchMore,\n data: listPayload?.resolvedList as Osdk.Instance<T>[],\n isLoading: listPayload?.status === \"loading\",\n error: undefined,\n isOptimistic: listPayload?.isOptimistic ?? false,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AA+BhD,OAAO,SAASC,WAAWA,CACzBC,IAAO,EACPC,IAA2B,EACL;EACtB,MAAM;IAAEC;EAAM,CAAC,GAAGN,KAAK,CAACO,UAAU,CAACL,YAAY,CAAC;EAChD,MAAMM,KAAK,GAAGF,KAAK,CAACG,uBAAuB,CAACJ,IAAI,CAACG,KAAK,CAAC;EAEvD,MAAM;IAAEE,SAAS;IAAEC;EAAY,CAAC,GAAGX,KAAK,CAACY,OAAO,CAC9C,MACEX,iBAAiB,CAAeY,CAAC,IAC/BP,KAAK,CAACQ,WAAW,CACfV,IAAI,EACJI,KAAK,EACL;IACEO,cAAc,EAAEV,IAAI,CAACW,gBAAgB,IAAI;EAC3C,CAAC,EACDH,CACF,CAAC,EAAE,QAAQT,IAAI,CAACa,OAAO,IAAIC,IAAI,CAACC,SAAS,CAACX,KAAK,CAAC,EAAE,CAAC,EACvD,CAACF,KAAK,EAAEF,IAAI,EAAEI,KAAK,EAAEH,IAAI,CAACW,gBAAgB,CAC5C,CAAC;EAED,MAAMI,WAAW,GAAGpB,KAAK,CAACqB,oBAAoB,CAACX,SAAS,EAAEC,WAAW,CAAC;EAEtE,OAAO;IACLW,SAAS,EAAEF,WAAW,EAAEE,SAAS;IACjCC,IAAI,EAAEH,WAAW,EAAEI,YAAkC;IACrDC,SAAS,EAAEL,WAAW,EAAEM,MAAM,KAAK,SAAS;IAC5CC,KAAK,EAAEC,SAAS;IAChBC,YAAY,EAAET,WAAW,EAAES,YAAY,IAAI;EAC7C,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"useOsdkList.js","names":["React","makeExternalStore","OsdkContext2","useOsdkList","objectType","pageSize","orderBy","dedupeIntervalMs","where","streamUpdates","store","useContext","canonWhere","canonicalizeWhereClause","subscribe","getSnapShot","useMemo","x","observeList","dedupeInterval","process","env","NODE_ENV","apiName","JSON","stringify","listPayload","useSyncExternalStore","fetchMore","data","resolvedList","isLoading","status","error","undefined","isOptimistic"],"sources":["useOsdkList.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 {\n ObjectTypeDefinition,\n Osdk,\n PropertyKeys,\n WhereClause,\n} from \"@osdk/client\";\nimport type { ListPayload } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkListOptions<T extends ObjectTypeDefinition> {\n /**\n * Standard OSDK Where\n */\n where?: WhereClause<T>;\n\n /**\n * The preferred page size for the list.\n */\n pageSize?: number;\n\n /** */\n orderBy?: {\n [K in PropertyKeys<T>]?: \"asc\" | \"desc\";\n };\n\n /**\n * Causes the list to automatically fetch more as soon as the previous page\n * has been loaded. If a number is provided, it will continue to automatically\n * fetch more until the list is at least that long.\n */\n // autoFetchMore?: boolean | number;\n\n /**\n * Upon a list being revalidated, this option determines how the component\n * will be re-rendered with the data.\n *\n * An example to help understand the options:\n *\n * Suppose pageSize is 10 and we have called `fetchMore()` twice. The list is\n * now 30 items long.\n *\n * Upon revalidation, we get the first 10 items of the list. The options behave\n * as follows:\n *\n * - `\"in-place\"`: The first 10 items of the list are replaced with the new 10\n * items. The list is now 30 items long, but only the first 10 items are valid.\n * - `\"wait\"`: The old list is returned until after the next 20 items are loaded\n * (which will happen automatically). The list is now 30 items long.\n * - `\"reset\"`: The entire list is replaced with the new 10 items. The list is\n * now 10 items long.\n */\n // invalidationMode?: \"in-place\" | \"wait\" | \"reset\";\n\n /**\n * The number of milliseconds to wait after the last observed list change.\n *\n * Two uses of `useOsdkList` with the where clause will only trigger one\n * network request if the second is within `dedupeIntervalMs`.\n */\n dedupeIntervalMs?: number;\n\n /**\n * If provided, the list will be considered this length for the purposes of\n * `invalidationMode` when using the `wait` option. If not provided,\n * the internal expectedLength will be determined by the number of times\n * `fetchMore` has been called.\n */\n // expectedLength?: number | undefined;\n\n streamUpdates?: boolean;\n}\n\nexport interface UseOsdkListResult<T extends ObjectTypeDefinition> {\n fetchMore: (() => Promise<unknown>) | undefined;\n data: Osdk.Instance<T>[];\n isLoading: boolean;\n\n // FIXME populate error!\n error: undefined;\n\n /**\n * Refers to whether the ordered list of objects (only considering the $primaryKey)\n * is optimistic or not.\n *\n * If you need to know if the contents of the list are optimistic you can\n * do that on a per object basis with useOsdkObject\n */\n isOptimistic: boolean;\n}\n\ndeclare const process: {\n env: {\n NODE_ENV: \"development\" | \"production\";\n };\n};\n\nexport function useOsdkList<T extends ObjectTypeDefinition>(\n objectType: T,\n { pageSize, orderBy, dedupeIntervalMs, where, streamUpdates }:\n UseOsdkListOptions<T>,\n): UseOsdkListResult<T> {\n const { store } = 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 = store.canonicalizeWhereClause(where ?? {});\n\n const { subscribe, getSnapShot } = React.useMemo(\n () =>\n makeExternalStore<ListPayload>(\n (x) =>\n store.observeList({\n objectType,\n where: canonWhere,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n pageSize,\n orderBy,\n streamUpdates,\n }, x),\n process.env.NODE_ENV !== \"production\"\n ? `list ${objectType.apiName} ${JSON.stringify(canonWhere)}`\n : void 0,\n ),\n [store, objectType, canonWhere, dedupeIntervalMs],\n );\n\n const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n return {\n fetchMore: listPayload?.fetchMore,\n data: listPayload?.resolvedList as Osdk.Instance<T>[],\n isLoading: listPayload?.status === \"loading\",\n error: undefined,\n isOptimistic: listPayload?.isOptimistic ?? false,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AAyFhD,OAAO,SAASC,WAAWA,CACzBC,UAAa,EACb;EAAEC,QAAQ;EAAEC,OAAO;EAAEC,gBAAgB;EAAEC,KAAK;EAAEC;AACxB,CAAC,EACD;EACtB,MAAM;IAAEC;EAAM,CAAC,GAAGV,KAAK,CAACW,UAAU,CAACT,YAAY,CAAC;;EAEhD;AACF;AACA;AACA;EACE,MAAMU,UAAU,GAAGF,KAAK,CAACG,uBAAuB,CAACL,KAAK,IAAI,CAAC,CAAC,CAAC;EAE7D,MAAM;IAAEM,SAAS;IAAEC;EAAY,CAAC,GAAGf,KAAK,CAACgB,OAAO,CAC9C,MACEf,iBAAiB,CACdgB,CAAC,IACAP,KAAK,CAACQ,WAAW,CAAC;IAChBd,UAAU;IACVI,KAAK,EAAEI,UAAU;IACjBO,cAAc,EAAEZ,gBAAgB,IAAI,KAAK;IACzCF,QAAQ;IACRC,OAAO;IACPG;EACF,CAAC,EAAEQ,CAAC,CAAC,EACPG,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GACjC,QAAQlB,UAAU,CAACmB,OAAO,IAAIC,IAAI,CAACC,SAAS,CAACb,UAAU,CAAC,EAAE,GAC1D,KAAK,CACX,CAAC,EACH,CAACF,KAAK,EAAEN,UAAU,EAAEQ,UAAU,EAAEL,gBAAgB,CAClD,CAAC;EAED,MAAMmB,WAAW,GAAG1B,KAAK,CAAC2B,oBAAoB,CAACb,SAAS,EAAEC,WAAW,CAAC;EAEtE,OAAO;IACLa,SAAS,EAAEF,WAAW,EAAEE,SAAS;IACjCC,IAAI,EAAEH,WAAW,EAAEI,YAAkC;IACrDC,SAAS,EAAEL,WAAW,EAAEM,MAAM,KAAK,SAAS;IAC5CC,KAAK,EAAEC,SAAS;IAChBC,YAAY,EAAET,WAAW,EAAES,YAAY,IAAI;EAC7C,CAAC;AACH","ignoreList":[]}
@@ -38,9 +38,18 @@ function useOsdkAction(actionDef) {
38
38
  } = React3__default.default.useContext(OsdkContext2);
39
39
  const [error, setError] = React3__default.default.useState();
40
40
  const [data, setData] = React3__default.default.useState();
41
- const applyAction = React3__default.default.useCallback(async function applyAction2(args, opts) {
41
+ const [isPending, setPending] = React3__default.default.useState(false);
42
+ const applyAction = React3__default.default.useCallback(async function applyAction2(hookArgs) {
43
+ const {
44
+ $optimisticUpdate,
45
+ ...args
46
+ } = hookArgs;
42
47
  try {
43
- const r = await store.applyAction(actionDef, args, opts);
48
+ setPending(true);
49
+ setError(void 0);
50
+ const r = await store.applyAction(actionDef, args, {
51
+ optimisticUpdate: $optimisticUpdate
52
+ });
44
53
  setData(r);
45
54
  return r;
46
55
  } catch (e) {
@@ -53,12 +62,15 @@ function useOsdkAction(actionDef) {
53
62
  unknown: e
54
63
  });
55
64
  }
65
+ } finally {
66
+ setPending(false);
56
67
  }
57
68
  }, [store, setError]);
58
69
  return {
59
70
  applyAction,
60
71
  error,
61
- data
72
+ data,
73
+ isPending
62
74
  };
63
75
  }
64
76
 
@@ -69,13 +81,11 @@ function makeExternalStore(createObservation, name) {
69
81
  return lastResult;
70
82
  }
71
83
  function subscribe(notifyUpdate) {
72
- console.log("Subscribing", name);
73
84
  const obs = createObservation((payload) => {
74
85
  lastResult = payload;
75
86
  notifyUpdate();
76
87
  });
77
88
  return () => {
78
- console.log("Unsubscribing", name);
79
89
  obs.unsubscribe();
80
90
  };
81
91
  }
@@ -86,17 +96,28 @@ function makeExternalStore(createObservation, name) {
86
96
  }
87
97
 
88
98
  // src/new/useOsdkList.ts
89
- function useOsdkList(type, opts) {
99
+ function useOsdkList(objectType, {
100
+ pageSize,
101
+ orderBy,
102
+ dedupeIntervalMs,
103
+ where,
104
+ streamUpdates
105
+ }) {
90
106
  const {
91
107
  store
92
108
  } = React3__default.default.useContext(OsdkContext2);
93
- const where = store.canonicalizeWhereClause(opts.where);
109
+ const canonWhere = store.canonicalizeWhereClause(where ?? {});
94
110
  const {
95
111
  subscribe,
96
112
  getSnapShot
97
- } = React3__default.default.useMemo(() => makeExternalStore((x) => store.observeList(type, where, {
98
- dedupeInterval: opts.dedupeIntervalMs ?? 2e3
99
- }, x), `list ${type.apiName} ${JSON.stringify(where)}`), [store, type, where, opts.dedupeIntervalMs]);
113
+ } = React3__default.default.useMemo(() => makeExternalStore((x) => store.observeList({
114
+ objectType,
115
+ where: canonWhere,
116
+ dedupeInterval: dedupeIntervalMs ?? 2e3,
117
+ pageSize,
118
+ orderBy,
119
+ streamUpdates
120
+ }, x), process.env.NODE_ENV !== "production" ? `list ${objectType.apiName} ${JSON.stringify(canonWhere)}` : undefined), [store, objectType, canonWhere, dedupeIntervalMs]);
100
121
  const listPayload = React3__default.default.useSyncExternalStore(subscribe, getSnapShot);
101
122
  return {
102
123
  fetchMore: listPayload?.fetchMore,
@@ -118,7 +139,7 @@ function useOsdkObject(...args) {
118
139
  getSnapShot
119
140
  } = React3__default.default.useMemo(() => makeExternalStore((payload2) => store.observeObject(objectType, primaryKey, {
120
141
  mode
121
- }, payload2), `object ${objectType} ${primaryKey}`), [store, objectType, primaryKey, mode]);
142
+ }, payload2)), [store, objectType, primaryKey, mode]);
122
143
  const payload = React3__default.default.useSyncExternalStore(subscribe, getSnapShot);
123
144
  return {
124
145
  object: payload?.object,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/new/OsdkContext2.ts","../../../src/new/OsdkProvider2.tsx","../../../src/new/useOsdkAction.ts","../../../src/new/makeExternalStore.ts","../../../src/new/useOsdkList.ts","../../../src/new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AE,CAAA,CAAA,EAAG,CAAC,KAAA,EAAO,UAAY,EAAA,UAAA,EAAY,IAAI,CAAC,CAAA;AACzF,EAAA,MAAM,OAAUH,GAAAA,uBAAAA,CAAM,oBAAqB,CAAA,SAAA,EAAW,WAAW,CAAA;AACjE,EAAO,OAAA;AAAA,IACL,QAAQ,OAAS,EAAA,MAAA;AAAA,IACjB,SAAA,EAAW,SAAS,MAAW,KAAA,SAAA;AAAA,IAC/B,YAAA,EAAc,SAAS,YAAgB,IAAA,KAAA;AAAA,IACvC,aAAa,MAAM;AACjB,MAAM,MAAA,iBAAA;AAAA;AACR,GACF;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 store: 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 React from \"react\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\nexport function OsdkProvider2({\n children,\n client,\n store\n}) {\n return /*#__PURE__*/React.createElement(OsdkContext2.Provider, {\n value: {\n client,\n store\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 store\n } = React.useContext(OsdkContext2);\n const [error, setError] = React.useState();\n const [data, setData] = React.useState();\n const applyAction = React.useCallback(async function applyAction(args, opts) {\n try {\n const r = await store.applyAction(actionDef, args, opts);\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 }\n }, [store, setError]);\n return {\n applyAction,\n error,\n data\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 // eslint-disable-next-line no-console\n console.log(\"Subscribing\", name);\n const obs = createObservation(payload => {\n lastResult = payload;\n notifyUpdate();\n });\n return () => {\n // eslint-disable-next-line no-console\n console.log(\"Unsubscribing\", name);\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\";\nexport function useOsdkList(type, opts) {\n const {\n store\n } = React.useContext(OsdkContext2);\n const where = store.canonicalizeWhereClause(opts.where);\n const {\n subscribe,\n getSnapShot\n } = React.useMemo(() => makeExternalStore(x => store.observeList(type, where, {\n dedupeInterval: opts.dedupeIntervalMs ?? 2_000\n }, x), `list ${type.apiName} ${JSON.stringify(where)}`), [store, type, where, opts.dedupeIntervalMs]);\n const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);\n return {\n fetchMore: listPayload?.fetchMore,\n data: listPayload?.resolvedList,\n isLoading: listPayload?.status === \"loading\",\n error: undefined,\n isOptimistic: listPayload?.isOptimistic ?? false\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 store\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(payload => store.observeObject(objectType, primaryKey, {\n mode\n }, payload), `object ${objectType} ${primaryKey}`), [store, 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 ?? false,\n forceUpdate: () => {\n throw \"not implemented\";\n }\n };\n}"]}
1
+ {"version":3,"sources":["../../../src/new/OsdkContext2.ts","../../../src/new/OsdkProvider2.tsx","../../../src/new/useOsdkAction.ts","../../../src/new/makeExternalStore.ts","../../../src/new/useOsdkList.ts","../../../src/new/useOsdkObject.ts"],"names":["React","applyAction","ActionValidationError","payload"],"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,KAAO,EAAA;AACT,CAAC,CAAA;;;ACRM,SAAS,aAAc,CAAA;AAAA,EAC5B,QAAA;AAAA,EACA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AC,KAAA,EAAO,UAAY,EAAA,UAAA,EAAY,IAAI,CAAC,CAAA;AACzF,EAAA,MAAM,OAAUH,GAAAA,uBAAAA,CAAM,oBAAqB,CAAA,SAAA,EAAW,WAAW,CAAA;AACjE,EAAO,OAAA;AAAA,IACL,QAAQ,OAAS,EAAA,MAAA;AAAA,IACjB,SAAA,EAAW,SAAS,MAAW,KAAA,SAAA;AAAA,IAC/B,YAAA,EAAc,SAAS,YAAgB,IAAA,KAAA;AAAA,IACvC,aAAa,MAAM;AACjB,MAAM,MAAA,iBAAA;AAAA;AACR,GACF;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 store: 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 React from \"react\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\nexport function OsdkProvider2({\n children,\n client,\n store\n}) {\n return /*#__PURE__*/React.createElement(OsdkContext2.Provider, {\n value: {\n client,\n store\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 store\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 store.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 }, [store, 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(payload => {\n lastResult = payload;\n notifyUpdate();\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\";\nexport function useOsdkList(objectType, {\n pageSize,\n orderBy,\n dedupeIntervalMs,\n where,\n streamUpdates\n}) {\n const {\n store\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 = store.canonicalizeWhereClause(where ?? {});\n const {\n subscribe,\n getSnapShot\n } = React.useMemo(() => makeExternalStore(x => store.observeList({\n objectType,\n where: canonWhere,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n pageSize,\n orderBy,\n streamUpdates\n }, x), process.env.NODE_ENV !== \"production\" ? `list ${objectType.apiName} ${JSON.stringify(canonWhere)}` : void 0), [store, objectType, canonWhere, dedupeIntervalMs]);\n const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);\n return {\n fetchMore: listPayload?.fetchMore,\n data: listPayload?.resolvedList,\n isLoading: listPayload?.status === \"loading\",\n error: undefined,\n isOptimistic: listPayload?.isOptimistic ?? false\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 store\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(payload => store.observeObject(objectType, primaryKey, {\n mode\n }, payload), `object ${objectType} ${primaryKey}`), [store, 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 ?? false,\n forceUpdate: () => {\n throw \"not implemented\";\n }\n };\n}"]}
@@ -1,4 +1,4 @@
1
- import { Client, ActionDefinition, ActionValidationError, ObjectTypeDefinition, WhereClause, Osdk } from '@osdk/client';
1
+ import { Client, ActionDefinition, ActionValidationError, ObjectTypeDefinition, WhereClause, PropertyKeys, Osdk } from '@osdk/client';
2
2
  import { ObservableClient, ActionSignatureFromDef } from '@osdk/client/unstable-do-not-use';
3
3
  import React from 'react';
4
4
  import { ObjectTypeDefinition as ObjectTypeDefinition$1, Osdk as Osdk$1, PrimaryKeyType } from '@osdk/api';
@@ -11,18 +11,57 @@ interface OsdkProviderOptions {
11
11
  }
12
12
  declare function OsdkProvider2({ children, client, store, }: OsdkProviderOptions): React.JSX.Element;
13
13
 
14
+ type ApplyActionParams<Q extends ActionDefinition<any>> = Parameters<ActionSignatureFromDef<Q>["applyAction"]>[0] & {
15
+ [K in keyof ObservableClient.ApplyActionOptions as `$${K}`]: ObservableClient.ApplyActionOptions[K];
16
+ };
14
17
  interface UseOsdkActionResult<Q extends ActionDefinition<any>> {
15
- applyAction: (args: Parameters<ActionSignatureFromDef<Q>["applyAction"]>[0], opts: ObservableClient.ApplyActionOptions) => Promise<unknown>;
18
+ applyAction: (args: ApplyActionParams<Q>) => Promise<unknown>;
16
19
  error: undefined | Partial<{
17
20
  actionValidation: ActionValidationError;
18
21
  unknown: unknown;
19
22
  }>;
20
23
  data: unknown;
24
+ isPending: boolean;
21
25
  }
22
26
  declare function useOsdkAction<Q extends ActionDefinition<any>>(actionDef: Q): UseOsdkActionResult<Q>;
23
27
 
24
28
  interface UseOsdkListOptions<T extends ObjectTypeDefinition> {
25
- where: WhereClause<T>;
29
+ /**
30
+ * Standard OSDK Where
31
+ */
32
+ where?: WhereClause<T>;
33
+ /**
34
+ * The preferred page size for the list.
35
+ */
36
+ pageSize?: number;
37
+ /** */
38
+ orderBy?: {
39
+ [K in PropertyKeys<T>]?: "asc" | "desc";
40
+ };
41
+ /**
42
+ * Causes the list to automatically fetch more as soon as the previous page
43
+ * has been loaded. If a number is provided, it will continue to automatically
44
+ * fetch more until the list is at least that long.
45
+ */
46
+ /**
47
+ * Upon a list being revalidated, this option determines how the component
48
+ * will be re-rendered with the data.
49
+ *
50
+ * An example to help understand the options:
51
+ *
52
+ * Suppose pageSize is 10 and we have called `fetchMore()` twice. The list is
53
+ * now 30 items long.
54
+ *
55
+ * Upon revalidation, we get the first 10 items of the list. The options behave
56
+ * as follows:
57
+ *
58
+ * - `"in-place"`: The first 10 items of the list are replaced with the new 10
59
+ * items. The list is now 30 items long, but only the first 10 items are valid.
60
+ * - `"wait"`: The old list is returned until after the next 20 items are loaded
61
+ * (which will happen automatically). The list is now 30 items long.
62
+ * - `"reset"`: The entire list is replaced with the new 10 items. The list is
63
+ * now 10 items long.
64
+ */
26
65
  /**
27
66
  * The number of milliseconds to wait after the last observed list change.
28
67
  *
@@ -30,6 +69,13 @@ interface UseOsdkListOptions<T extends ObjectTypeDefinition> {
30
69
  * network request if the second is within `dedupeIntervalMs`.
31
70
  */
32
71
  dedupeIntervalMs?: number;
72
+ /**
73
+ * If provided, the list will be considered this length for the purposes of
74
+ * `invalidationMode` when using the `wait` option. If not provided,
75
+ * the internal expectedLength will be determined by the number of times
76
+ * `fetchMore` has been called.
77
+ */
78
+ streamUpdates?: boolean;
33
79
  }
34
80
  interface UseOsdkListResult<T extends ObjectTypeDefinition> {
35
81
  fetchMore: (() => Promise<unknown>) | undefined;
@@ -45,7 +91,7 @@ interface UseOsdkListResult<T extends ObjectTypeDefinition> {
45
91
  */
46
92
  isOptimistic: boolean;
47
93
  }
48
- declare function useOsdkList<T extends ObjectTypeDefinition>(type: T, opts: UseOsdkListOptions<T>): UseOsdkListResult<T>;
94
+ declare function useOsdkList<T extends ObjectTypeDefinition>(objectType: T, { pageSize, orderBy, dedupeIntervalMs, where, streamUpdates }: UseOsdkListOptions<T>): UseOsdkListResult<T>;
49
95
 
50
96
  interface UseOsdkObjectResult<Q extends ObjectTypeDefinition$1> {
51
97
  object: Osdk$1.Instance<Q> | undefined;
@@ -14,22 +14,18 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- export function makeExternalStore(createObservation, name) {
17
+ export function makeExternalStore(createObservation) {
18
18
  let lastResult;
19
19
  function getSnapShot() {
20
20
  return lastResult;
21
21
  }
22
22
  return {
23
23
  subscribe: function subscribe(notifyUpdate) {
24
- // eslint-disable-next-line no-console
25
- console.log("Subscribing", name);
26
24
  const obs = createObservation(payload => {
27
25
  lastResult = payload;
28
26
  notifyUpdate();
29
27
  });
30
28
  return () => {
31
- // eslint-disable-next-line no-console
32
- console.log("Unsubscribing", name);
33
29
  obs.unsubscribe();
34
30
  };
35
31
  },
@@ -1 +1 @@
1
- {"version":3,"file":"makeExternalStore.js","names":["makeExternalStore","createObservation","name","lastResult","getSnapShot","subscribe","notifyUpdate","console","log","obs","payload","unsubscribe"],"sources":["makeExternalStore.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 { Unsubscribable } from \"@osdk/client/unstable-do-not-use\";\n\nexport function makeExternalStore<X>(\n createObservation: (callback: (x: X | undefined) => void) => Unsubscribable,\n name?: string,\n): {\n subscribe: (notifyUpdate: () => void) => () => void;\n getSnapShot: () => X | undefined;\n} {\n let lastResult: X | undefined;\n\n function getSnapShot(): X | undefined {\n return lastResult;\n }\n\n function subscribe(notifyUpdate: () => void) {\n // eslint-disable-next-line no-console\n console.log(\"Subscribing\", name);\n const obs = createObservation((payload) => {\n lastResult = payload;\n notifyUpdate();\n });\n\n return (): void => {\n // eslint-disable-next-line no-console\n console.log(\"Unsubscribing\", name);\n obs.unsubscribe();\n };\n }\n\n return {\n subscribe,\n getSnapShot,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAO,SAASA,iBAAiBA,CAC/BC,iBAA2E,EAC3EC,IAAa,EAIb;EACA,IAAIC,UAAyB;EAE7B,SAASC,WAAWA,CAAA,EAAkB;IACpC,OAAOD,UAAU;EACnB;EAiBA,OAAO;IACLE,SAAS,EAhBX,SAASA,SAASA,CAACC,YAAwB,EAAE;MAC3C;MACAC,OAAO,CAACC,GAAG,CAAC,aAAa,EAAEN,IAAI,CAAC;MAChC,MAAMO,GAAG,GAAGR,iBAAiB,CAAES,OAAO,IAAK;QACzCP,UAAU,GAAGO,OAAO;QACpBJ,YAAY,CAAC,CAAC;MAChB,CAAC,CAAC;MAEF,OAAO,MAAY;QACjB;QACAC,OAAO,CAACC,GAAG,CAAC,eAAe,EAAEN,IAAI,CAAC;QAClCO,GAAG,CAACE,WAAW,CAAC,CAAC;MACnB,CAAC;IACH,CAGW;IACTP;EACF,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"makeExternalStore.js","names":["makeExternalStore","createObservation","lastResult","getSnapShot","subscribe","notifyUpdate","obs","payload","unsubscribe"],"sources":["makeExternalStore.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 { Unsubscribable } from \"@osdk/client/unstable-do-not-use\";\n\nexport function makeExternalStore<X>(\n createObservation: (callback: (x: X | undefined) => void) => Unsubscribable,\n name?: string,\n): {\n subscribe: (notifyUpdate: () => void) => () => void;\n getSnapShot: () => X | undefined;\n} {\n let lastResult: X | undefined;\n\n function getSnapShot(): X | undefined {\n return lastResult;\n }\n\n function subscribe(notifyUpdate: () => void) {\n const obs = createObservation((payload) => {\n lastResult = payload;\n notifyUpdate();\n });\n\n return (): void => {\n obs.unsubscribe();\n };\n }\n\n return {\n subscribe,\n getSnapShot,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAO,SAASA,iBAAiBA,CAC/BC,iBAA2E,EAK3E;EACA,IAAIC,UAAyB;EAE7B,SAASC,WAAWA,CAAA,EAAkB;IACpC,OAAOD,UAAU;EACnB;EAaA,OAAO;IACLE,SAAS,EAZX,SAASA,SAASA,CAACC,YAAwB,EAAE;MAC3C,MAAMC,GAAG,GAAGL,iBAAiB,CAAEM,OAAO,IAAK;QACzCL,UAAU,GAAGK,OAAO;QACpBF,YAAY,CAAC,CAAC;MAChB,CAAC,CAAC;MAEF,OAAO,MAAY;QACjBC,GAAG,CAACE,WAAW,CAAC,CAAC;MACnB,CAAC;IACH,CAGW;IACTL;EACF,CAAC;AACH","ignoreList":[]}
@@ -23,9 +23,18 @@ export function useOsdkAction(actionDef) {
23
23
  } = React.useContext(OsdkContext2);
24
24
  const [error, setError] = React.useState();
25
25
  const [data, setData] = React.useState();
26
- const applyAction = React.useCallback(async function (args, opts) {
26
+ const [isPending, setPending] = React.useState(false);
27
+ const applyAction = React.useCallback(async function (hookArgs) {
28
+ const {
29
+ $optimisticUpdate,
30
+ ...args
31
+ } = hookArgs;
27
32
  try {
28
- const r = await store.applyAction(actionDef, args, opts);
33
+ setPending(true);
34
+ setError(undefined);
35
+ const r = await store.applyAction(actionDef, args, {
36
+ optimisticUpdate: $optimisticUpdate
37
+ });
29
38
  setData(r);
30
39
  return r;
31
40
  } catch (e) {
@@ -38,12 +47,15 @@ export function useOsdkAction(actionDef) {
38
47
  unknown: e
39
48
  });
40
49
  }
50
+ } finally {
51
+ setPending(false);
41
52
  }
42
53
  }, [store, setError]);
43
54
  return {
44
55
  applyAction,
45
56
  error,
46
- data
57
+ data,
58
+ isPending
47
59
  };
48
60
  }
49
61
  //# sourceMappingURL=useOsdkAction.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useOsdkAction.js","names":["ActionValidationError","React","OsdkContext2","useOsdkAction","actionDef","store","useContext","error","setError","useState","data","setData","applyAction","useCallback","args","opts","r","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\nexport interface UseOsdkActionResult<Q extends ActionDefinition<any>> {\n applyAction: (\n args: Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0],\n opts: ObservableClient.ApplyActionOptions,\n ) => Promise<unknown>;\n\n error:\n | undefined\n | Partial<{\n actionValidation: ActionValidationError;\n unknown: unknown;\n }>;\n data: unknown;\n}\n\nexport function useOsdkAction<Q extends ActionDefinition<any>>(\n actionDef: Q,\n): UseOsdkActionResult<Q> {\n const { store } = React.useContext(OsdkContext2);\n const [error, setError] = React.useState<UseOsdkActionResult<Q>[\"error\"]>();\n const [data, setData] = React.useState<unknown>();\n\n const applyAction = React.useCallback(async function applyAction(\n args: Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0],\n opts: ObservableClient.ApplyActionOptions,\n ) {\n try {\n const r = await store.applyAction(actionDef, args, opts);\n setData(r);\n return r;\n } catch (e) {\n if (e instanceof ActionValidationError) {\n setError({\n actionValidation: e,\n });\n } else {\n setError({ unknown: e });\n }\n }\n }, [store, setError]);\n\n return { applyAction, error, data };\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;AAiBhD,OAAO,SAASC,aAAaA,CAC3BC,SAAY,EACY;EACxB,MAAM;IAAEC;EAAM,CAAC,GAAGJ,KAAK,CAACK,UAAU,CAACJ,YAAY,CAAC;EAChD,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;EAEjD,MAAMG,WAAW,GAAGX,KAAK,CAACY,WAAW,CAAC,gBACpCC,IAA6D,EAC7DC,IAAyC,EACzC;IACA,IAAI;MACF,MAAMC,CAAC,GAAG,MAAMX,KAAK,CAACO,WAAW,CAACR,SAAS,EAAEU,IAAI,EAAEC,IAAI,CAAC;MACxDJ,OAAO,CAACK,CAAC,CAAC;MACV,OAAOA,CAAC;IACV,CAAC,CAAC,OAAOC,CAAC,EAAE;MACV,IAAIA,CAAC,YAAYjB,qBAAqB,EAAE;QACtCQ,QAAQ,CAAC;UACPU,gBAAgB,EAAED;QACpB,CAAC,CAAC;MACJ,CAAC,MAAM;QACLT,QAAQ,CAAC;UAAEW,OAAO,EAAEF;QAAE,CAAC,CAAC;MAC1B;IACF;EACF,CAAC,EAAE,CAACZ,KAAK,EAAEG,QAAQ,CAAC,CAAC;EAErB,OAAO;IAAEI,WAAW;IAAEL,KAAK;IAAEG;EAAK,CAAC;AACrC","ignoreList":[]}
1
+ {"version":3,"file":"useOsdkAction.js","names":["ActionValidationError","React","OsdkContext2","useOsdkAction","actionDef","store","useContext","error","setError","useState","data","setData","isPending","setPending","applyAction","useCallback","hookArgs","$optimisticUpdate","args","undefined","r","optimisticUpdate","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>,\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 { store } = 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>,\n ) {\n const { $optimisticUpdate, ...args } = hookArgs;\n try {\n setPending(true);\n setError(undefined);\n const r = await store.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({ unknown: e });\n }\n } finally {\n setPending(false);\n }\n }, [store, 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;EAAM,CAAC,GAAGJ,KAAK,CAACK,UAAU,CAACJ,YAAY,CAAC;EAChD,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,QAA8B,EAC9B;IACA,MAAM;MAAEC,iBAAiB;MAAE,GAAGC;IAAK,CAAC,GAAGF,QAAQ;IAC/C,IAAI;MACFH,UAAU,CAAC,IAAI,CAAC;MAChBL,QAAQ,CAACW,SAAS,CAAC;MACnB,MAAMC,CAAC,GAAG,MAAMf,KAAK,CAACS,WAAW,CAACV,SAAS,EAAEc,IAAI,EAAE;QACjDG,gBAAgB,EAAEJ;MACpB,CAAC,CAAC;MACFN,OAAO,CAACS,CAAC,CAAC;MACV,OAAOA,CAAC;IACV,CAAC,CAAC,OAAOE,CAAC,EAAE;MACV,IAAIA,CAAC,YAAYtB,qBAAqB,EAAE;QACtCQ,QAAQ,CAAC;UACPe,gBAAgB,EAAED;QACpB,CAAC,CAAC;MACJ,CAAC,MAAM;QACLd,QAAQ,CAAC;UAAEgB,OAAO,EAAEF;QAAE,CAAC,CAAC;MAC1B;IACF,CAAC,SAAS;MACRT,UAAU,CAAC,KAAK,CAAC;IACnB;EACF,CAAC,EAAE,CAACR,KAAK,EAAEG,QAAQ,CAAC,CAAC;EAErB,OAAO;IAAEM,WAAW;IAAEP,KAAK;IAAEG,IAAI;IAAEE;EAAU,CAAC;AAChD","ignoreList":[]}
@@ -17,17 +17,33 @@
17
17
  import React from "react";
18
18
  import { makeExternalStore } from "./makeExternalStore.js";
19
19
  import { OsdkContext2 } from "./OsdkContext2.js";
20
- export function useOsdkList(type, opts) {
20
+ export function useOsdkList(objectType, {
21
+ pageSize,
22
+ orderBy,
23
+ dedupeIntervalMs,
24
+ where,
25
+ streamUpdates
26
+ }) {
21
27
  const {
22
28
  store
23
29
  } = React.useContext(OsdkContext2);
24
- const where = store.canonicalizeWhereClause(opts.where);
30
+
31
+ /* We want the canonical where clause so that the use of `React.useMemo`
32
+ is stable. No real added cost as we canonicalize internal to
33
+ the ObservableClient anyway.
34
+ */
35
+ const canonWhere = store.canonicalizeWhereClause(where ?? {});
25
36
  const {
26
37
  subscribe,
27
38
  getSnapShot
28
- } = React.useMemo(() => makeExternalStore(x => store.observeList(type, where, {
29
- dedupeInterval: opts.dedupeIntervalMs ?? 2_000
30
- }, x), `list ${type.apiName} ${JSON.stringify(where)}`), [store, type, where, opts.dedupeIntervalMs]);
39
+ } = React.useMemo(() => makeExternalStore(x => store.observeList({
40
+ objectType,
41
+ where: canonWhere,
42
+ dedupeInterval: dedupeIntervalMs ?? 2_000,
43
+ pageSize,
44
+ orderBy,
45
+ streamUpdates
46
+ }, x), process.env.NODE_ENV !== "production" ? `list ${objectType.apiName} ${JSON.stringify(canonWhere)}` : void 0), [store, objectType, canonWhere, dedupeIntervalMs]);
31
47
  const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);
32
48
  return {
33
49
  fetchMore: listPayload?.fetchMore,
@@ -1 +1 @@
1
- {"version":3,"file":"useOsdkList.js","names":["React","makeExternalStore","OsdkContext2","useOsdkList","type","opts","store","useContext","where","canonicalizeWhereClause","subscribe","getSnapShot","useMemo","x","observeList","dedupeInterval","dedupeIntervalMs","apiName","JSON","stringify","listPayload","useSyncExternalStore","fetchMore","data","resolvedList","isLoading","status","error","undefined","isOptimistic"],"sources":["useOsdkList.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 { ObjectTypeDefinition, Osdk, WhereClause } from \"@osdk/client\";\nimport type { ListPayload } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkListOptions<T extends ObjectTypeDefinition> {\n where: WhereClause<T>;\n\n /**\n * The number of milliseconds to wait after the last observed list change.\n *\n * Two uses of `useOsdkList` with the where clause will only trigger one\n * network request if the second is within `dedupeIntervalMs`.\n */\n dedupeIntervalMs?: number;\n}\nexport interface UseOsdkListResult<T extends ObjectTypeDefinition> {\n fetchMore: (() => Promise<unknown>) | undefined;\n data: Osdk.Instance<T>[];\n isLoading: boolean;\n\n // FIXME populate error!\n error: undefined;\n\n /**\n * Refers to whether the ordered list of objects (only considering the $primaryKey)\n * is optimistic or not.\n *\n * If you need to know if the contents of the list are optimistic you can\n * do that on a per object basis with useOsdkObject\n */\n isOptimistic: boolean;\n}\n\nexport function useOsdkList<T extends ObjectTypeDefinition>(\n type: T,\n opts: UseOsdkListOptions<T>,\n): UseOsdkListResult<T> {\n const { store } = React.useContext(OsdkContext2);\n const where = store.canonicalizeWhereClause(opts.where);\n\n const { subscribe, getSnapShot } = React.useMemo(\n () =>\n makeExternalStore<ListPayload>((x) =>\n store.observeList(\n type,\n where,\n {\n dedupeInterval: opts.dedupeIntervalMs ?? 2_000,\n },\n x,\n ), `list ${type.apiName} ${JSON.stringify(where)}`),\n [store, type, where, opts.dedupeIntervalMs],\n );\n\n const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n return {\n fetchMore: listPayload?.fetchMore,\n data: listPayload?.resolvedList as Osdk.Instance<T>[],\n isLoading: listPayload?.status === \"loading\",\n error: undefined,\n isOptimistic: listPayload?.isOptimistic ?? false,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AA+BhD,OAAO,SAASC,WAAWA,CACzBC,IAAO,EACPC,IAA2B,EACL;EACtB,MAAM;IAAEC;EAAM,CAAC,GAAGN,KAAK,CAACO,UAAU,CAACL,YAAY,CAAC;EAChD,MAAMM,KAAK,GAAGF,KAAK,CAACG,uBAAuB,CAACJ,IAAI,CAACG,KAAK,CAAC;EAEvD,MAAM;IAAEE,SAAS;IAAEC;EAAY,CAAC,GAAGX,KAAK,CAACY,OAAO,CAC9C,MACEX,iBAAiB,CAAeY,CAAC,IAC/BP,KAAK,CAACQ,WAAW,CACfV,IAAI,EACJI,KAAK,EACL;IACEO,cAAc,EAAEV,IAAI,CAACW,gBAAgB,IAAI;EAC3C,CAAC,EACDH,CACF,CAAC,EAAE,QAAQT,IAAI,CAACa,OAAO,IAAIC,IAAI,CAACC,SAAS,CAACX,KAAK,CAAC,EAAE,CAAC,EACvD,CAACF,KAAK,EAAEF,IAAI,EAAEI,KAAK,EAAEH,IAAI,CAACW,gBAAgB,CAC5C,CAAC;EAED,MAAMI,WAAW,GAAGpB,KAAK,CAACqB,oBAAoB,CAACX,SAAS,EAAEC,WAAW,CAAC;EAEtE,OAAO;IACLW,SAAS,EAAEF,WAAW,EAAEE,SAAS;IACjCC,IAAI,EAAEH,WAAW,EAAEI,YAAkC;IACrDC,SAAS,EAAEL,WAAW,EAAEM,MAAM,KAAK,SAAS;IAC5CC,KAAK,EAAEC,SAAS;IAChBC,YAAY,EAAET,WAAW,EAAES,YAAY,IAAI;EAC7C,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"useOsdkList.js","names":["React","makeExternalStore","OsdkContext2","useOsdkList","objectType","pageSize","orderBy","dedupeIntervalMs","where","streamUpdates","store","useContext","canonWhere","canonicalizeWhereClause","subscribe","getSnapShot","useMemo","x","observeList","dedupeInterval","process","env","NODE_ENV","apiName","JSON","stringify","listPayload","useSyncExternalStore","fetchMore","data","resolvedList","isLoading","status","error","undefined","isOptimistic"],"sources":["useOsdkList.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 {\n ObjectTypeDefinition,\n Osdk,\n PropertyKeys,\n WhereClause,\n} from \"@osdk/client\";\nimport type { ListPayload } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\nimport { makeExternalStore } from \"./makeExternalStore.js\";\nimport { OsdkContext2 } from \"./OsdkContext2.js\";\n\nexport interface UseOsdkListOptions<T extends ObjectTypeDefinition> {\n /**\n * Standard OSDK Where\n */\n where?: WhereClause<T>;\n\n /**\n * The preferred page size for the list.\n */\n pageSize?: number;\n\n /** */\n orderBy?: {\n [K in PropertyKeys<T>]?: \"asc\" | \"desc\";\n };\n\n /**\n * Causes the list to automatically fetch more as soon as the previous page\n * has been loaded. If a number is provided, it will continue to automatically\n * fetch more until the list is at least that long.\n */\n // autoFetchMore?: boolean | number;\n\n /**\n * Upon a list being revalidated, this option determines how the component\n * will be re-rendered with the data.\n *\n * An example to help understand the options:\n *\n * Suppose pageSize is 10 and we have called `fetchMore()` twice. The list is\n * now 30 items long.\n *\n * Upon revalidation, we get the first 10 items of the list. The options behave\n * as follows:\n *\n * - `\"in-place\"`: The first 10 items of the list are replaced with the new 10\n * items. The list is now 30 items long, but only the first 10 items are valid.\n * - `\"wait\"`: The old list is returned until after the next 20 items are loaded\n * (which will happen automatically). The list is now 30 items long.\n * - `\"reset\"`: The entire list is replaced with the new 10 items. The list is\n * now 10 items long.\n */\n // invalidationMode?: \"in-place\" | \"wait\" | \"reset\";\n\n /**\n * The number of milliseconds to wait after the last observed list change.\n *\n * Two uses of `useOsdkList` with the where clause will only trigger one\n * network request if the second is within `dedupeIntervalMs`.\n */\n dedupeIntervalMs?: number;\n\n /**\n * If provided, the list will be considered this length for the purposes of\n * `invalidationMode` when using the `wait` option. If not provided,\n * the internal expectedLength will be determined by the number of times\n * `fetchMore` has been called.\n */\n // expectedLength?: number | undefined;\n\n streamUpdates?: boolean;\n}\n\nexport interface UseOsdkListResult<T extends ObjectTypeDefinition> {\n fetchMore: (() => Promise<unknown>) | undefined;\n data: Osdk.Instance<T>[];\n isLoading: boolean;\n\n // FIXME populate error!\n error: undefined;\n\n /**\n * Refers to whether the ordered list of objects (only considering the $primaryKey)\n * is optimistic or not.\n *\n * If you need to know if the contents of the list are optimistic you can\n * do that on a per object basis with useOsdkObject\n */\n isOptimistic: boolean;\n}\n\ndeclare const process: {\n env: {\n NODE_ENV: \"development\" | \"production\";\n };\n};\n\nexport function useOsdkList<T extends ObjectTypeDefinition>(\n objectType: T,\n { pageSize, orderBy, dedupeIntervalMs, where, streamUpdates }:\n UseOsdkListOptions<T>,\n): UseOsdkListResult<T> {\n const { store } = 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 = store.canonicalizeWhereClause(where ?? {});\n\n const { subscribe, getSnapShot } = React.useMemo(\n () =>\n makeExternalStore<ListPayload>(\n (x) =>\n store.observeList({\n objectType,\n where: canonWhere,\n dedupeInterval: dedupeIntervalMs ?? 2_000,\n pageSize,\n orderBy,\n streamUpdates,\n }, x),\n process.env.NODE_ENV !== \"production\"\n ? `list ${objectType.apiName} ${JSON.stringify(canonWhere)}`\n : void 0,\n ),\n [store, objectType, canonWhere, dedupeIntervalMs],\n );\n\n const listPayload = React.useSyncExternalStore(subscribe, getSnapShot);\n\n return {\n fetchMore: listPayload?.fetchMore,\n data: listPayload?.resolvedList as Osdk.Instance<T>[],\n isLoading: listPayload?.status === \"loading\",\n error: undefined,\n isOptimistic: listPayload?.isOptimistic ?? false,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;AAyFhD,OAAO,SAASC,WAAWA,CACzBC,UAAa,EACb;EAAEC,QAAQ;EAAEC,OAAO;EAAEC,gBAAgB;EAAEC,KAAK;EAAEC;AACxB,CAAC,EACD;EACtB,MAAM;IAAEC;EAAM,CAAC,GAAGV,KAAK,CAACW,UAAU,CAACT,YAAY,CAAC;;EAEhD;AACF;AACA;AACA;EACE,MAAMU,UAAU,GAAGF,KAAK,CAACG,uBAAuB,CAACL,KAAK,IAAI,CAAC,CAAC,CAAC;EAE7D,MAAM;IAAEM,SAAS;IAAEC;EAAY,CAAC,GAAGf,KAAK,CAACgB,OAAO,CAC9C,MACEf,iBAAiB,CACdgB,CAAC,IACAP,KAAK,CAACQ,WAAW,CAAC;IAChBd,UAAU;IACVI,KAAK,EAAEI,UAAU;IACjBO,cAAc,EAAEZ,gBAAgB,IAAI,KAAK;IACzCF,QAAQ;IACRC,OAAO;IACPG;EACF,CAAC,EAAEQ,CAAC,CAAC,EACPG,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GACjC,QAAQlB,UAAU,CAACmB,OAAO,IAAIC,IAAI,CAACC,SAAS,CAACb,UAAU,CAAC,EAAE,GAC1D,KAAK,CACX,CAAC,EACH,CAACF,KAAK,EAAEN,UAAU,EAAEQ,UAAU,EAAEL,gBAAgB,CAClD,CAAC;EAED,MAAMmB,WAAW,GAAG1B,KAAK,CAAC2B,oBAAoB,CAACb,SAAS,EAAEC,WAAW,CAAC;EAEtE,OAAO;IACLa,SAAS,EAAEF,WAAW,EAAEE,SAAS;IACjCC,IAAI,EAAEH,WAAW,EAAEI,YAAkC;IACrDC,SAAS,EAAEL,WAAW,EAAEM,MAAM,KAAK,SAAS;IAC5CC,KAAK,EAAEC,SAAS;IAChBC,YAAY,EAAET,WAAW,EAAES,YAAY,IAAI;EAC7C,CAAC;AACH","ignoreList":[]}
@@ -1,12 +1,15 @@
1
1
  import type { ActionDefinition } from "@osdk/client";
2
2
  import { ActionValidationError } from "@osdk/client";
3
3
  import type { ActionSignatureFromDef, ObservableClient } from "@osdk/client/unstable-do-not-use";
4
+ type ApplyActionParams<Q extends ActionDefinition<any>> = Parameters<ActionSignatureFromDef<Q>["applyAction"]>[0] & { [K in keyof ObservableClient.ApplyActionOptions as `$${K}`] : ObservableClient.ApplyActionOptions[K] };
4
5
  export interface UseOsdkActionResult<Q extends ActionDefinition<any>> {
5
- applyAction: (args: Parameters<ActionSignatureFromDef<Q>["applyAction"]>[0], opts: ObservableClient.ApplyActionOptions) => Promise<unknown>;
6
+ applyAction: (args: ApplyActionParams<Q>) => Promise<unknown>;
6
7
  error: undefined | Partial<{
7
8
  actionValidation: ActionValidationError
8
9
  unknown: unknown
9
10
  }>;
10
11
  data: unknown;
12
+ isPending: boolean;
11
13
  }
12
14
  export declare function useOsdkAction<Q extends ActionDefinition<any>>(actionDef: Q): UseOsdkActionResult<Q>;
15
+ export {};
@@ -1 +1 @@
1
- {"mappings":"AAgBA,cAAc,wBAAwB,cAAe;AACrD,SAAS,6BAA6B,cAAe;AACrD,cACE,wBACA,wBACK,kCAAmC;AAI1C,iBAAiB,oBAAoB,UAAU,uBAAuB;CACpE,cACEA,MAAM,WAAW,uBAAuB,GAAG,gBAAgB,IAC3DC,MAAM,iBAAiB,uBACpB;CAEL,mBAEI,QAAQ;EACR,kBAAkB;EAClB;CACD;CACH;AACD;AAED,OAAO,iBAAS,cAAc,UAAU,uBACtCC,WAAW,IACV,oBAAoB","names":["args: Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0]","opts: ObservableClient.ApplyActionOptions","actionDef: Q"],"sources":["../../../src/new/useOsdkAction.ts"],"version":3,"file":"useOsdkAction.d.ts"}
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,OACrB;CAEL,mBAEI,QAAQ;EACR,kBAAkB;EAClB;CACD;CACH;CAEA;AACD;AAED,OAAO,iBAAS,cAAc,UAAU,uBACtCC,WAAW,IACV,oBAAoB","names":["args: ApplyActionParams<Q>","actionDef: Q"],"sources":["../../../src/new/useOsdkAction.ts"],"version":3,"file":"useOsdkAction.d.ts"}
@@ -1,6 +1,39 @@
1
- import type { ObjectTypeDefinition, Osdk, WhereClause } from "@osdk/client";
1
+ import type { ObjectTypeDefinition, Osdk, PropertyKeys, WhereClause } from "@osdk/client";
2
2
  export interface UseOsdkListOptions<T extends ObjectTypeDefinition> {
3
- where: WhereClause<T>;
3
+ /**
4
+ * Standard OSDK Where
5
+ */
6
+ where?: WhereClause<T>;
7
+ /**
8
+ * The preferred page size for the list.
9
+ */
10
+ pageSize?: number;
11
+ /** */
12
+ orderBy?: { [K in PropertyKeys<T>]? : "asc" | "desc" };
13
+ /**
14
+ * Causes the list to automatically fetch more as soon as the previous page
15
+ * has been loaded. If a number is provided, it will continue to automatically
16
+ * fetch more until the list is at least that long.
17
+ */
18
+ /**
19
+ * Upon a list being revalidated, this option determines how the component
20
+ * will be re-rendered with the data.
21
+ *
22
+ * An example to help understand the options:
23
+ *
24
+ * Suppose pageSize is 10 and we have called `fetchMore()` twice. The list is
25
+ * now 30 items long.
26
+ *
27
+ * Upon revalidation, we get the first 10 items of the list. The options behave
28
+ * as follows:
29
+ *
30
+ * - `"in-place"`: The first 10 items of the list are replaced with the new 10
31
+ * items. The list is now 30 items long, but only the first 10 items are valid.
32
+ * - `"wait"`: The old list is returned until after the next 20 items are loaded
33
+ * (which will happen automatically). The list is now 30 items long.
34
+ * - `"reset"`: The entire list is replaced with the new 10 items. The list is
35
+ * now 10 items long.
36
+ */
4
37
  /**
5
38
  * The number of milliseconds to wait after the last observed list change.
6
39
  *
@@ -8,6 +41,13 @@ export interface UseOsdkListOptions<T extends ObjectTypeDefinition> {
8
41
  * network request if the second is within `dedupeIntervalMs`.
9
42
  */
10
43
  dedupeIntervalMs?: number;
44
+ /**
45
+ * If provided, the list will be considered this length for the purposes of
46
+ * `invalidationMode` when using the `wait` option. If not provided,
47
+ * the internal expectedLength will be determined by the number of times
48
+ * `fetchMore` has been called.
49
+ */
50
+ streamUpdates?: boolean;
11
51
  }
12
52
  export interface UseOsdkListResult<T extends ObjectTypeDefinition> {
13
53
  fetchMore: (() => Promise<unknown>) | undefined;
@@ -23,4 +63,4 @@ export interface UseOsdkListResult<T extends ObjectTypeDefinition> {
23
63
  */
24
64
  isOptimistic: boolean;
25
65
  }
26
- export declare function useOsdkList<T extends ObjectTypeDefinition>(type: T, opts: UseOsdkListOptions<T>): UseOsdkListResult<T>;
66
+ export declare function useOsdkList<T extends ObjectTypeDefinition>(objectType: T, { pageSize, orderBy, dedupeIntervalMs, where, streamUpdates }: UseOsdkListOptions<T>): UseOsdkListResult<T>;
@@ -1 +1 @@
1
- {"mappings":"AAgBA,cAAc,sBAAsB,MAAM,mBAAmB,cAAe;AAM5E,iBAAiB,mBAAmB,UAAU,sBAAsB;CAClE,OAAO,YAAY;;;;;;;CAQnB;AACD;AACD,iBAAiB,kBAAkB,UAAU,sBAAsB;CACjE,kBAAkB;CAClB,MAAM,KAAK,SAAS;CACpB;CAGA;;;;;;;;CASA;AACD;AAED,OAAO,iBAAS,YAAY,UAAU,sBACpCA,MAAM,GACNC,MAAM,mBAAmB,KACxB,kBAAkB","names":["type: T","opts: UseOsdkListOptions<T>"],"sources":["../../../src/new/useOsdkList.ts"],"version":3,"file":"useOsdkList.d.ts"}
1
+ {"mappings":"AAgBA,cACE,sBACA,MACA,cACA,mBACK,cAAe;AAMtB,iBAAiB,mBAAmB,UAAU,sBAAsB;;;;CAIlE,QAAQ,YAAY;;;;CAKpB;;CAGA,aACG,KAAK,aAAa,OAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqCnC;;;;;;;CAUA;AACD;AAED,iBAAiB,kBAAkB,UAAU,sBAAsB;CACjE,kBAAkB;CAClB,MAAM,KAAK,SAAS;CACpB;CAGA;;;;;;;;CASA;AACD;AAQD,OAAO,iBAAS,YAAY,UAAU,sBACpCA,YAAY,GACZ,EAAE,UAAU,SAAS,kBAAkB,OAAO,eACvB,EAArB,mBAAmB,KACpB,kBAAkB","names":["objectType: T"],"sources":["../../../src/new/useOsdkList.ts"],"version":3,"file":"useOsdkList.d.ts"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osdk/react",
3
- "version": "0.3.0-rc.4",
3
+ "version": "0.4.0-beta.2",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -49,10 +49,10 @@
49
49
  "p-defer": "^4.0.1",
50
50
  "react": "^18.0.0",
51
51
  "typescript": "~5.5.4",
52
- "@osdk/api": "2.1.0-rc.32",
53
- "@osdk/client": "2.1.0-rc.32",
54
- "@osdk/monorepo.api-extractor": "~0.0.0",
55
- "@osdk/monorepo.tsconfig": "~0.0.0"
52
+ "@osdk/api": "2.2.0-beta.4",
53
+ "@osdk/client": "2.2.0-beta.4",
54
+ "@osdk/monorepo.tsconfig": "~0.1.0-beta.1",
55
+ "@osdk/monorepo.api-extractor": "~0.1.0-beta.1"
56
56
  },
57
57
  "publishConfig": {
58
58
  "access": "public"