@osdk/react 0.10.0-beta.9 → 0.10.0
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 +99 -0
- package/build/browser/new/OsdkContext2.js +22 -2
- package/build/browser/new/OsdkContext2.js.map +1 -1
- package/build/browser/new/platform-apis/admin/useCbacBanner.js +63 -0
- package/build/browser/new/platform-apis/admin/useCbacBanner.js.map +1 -0
- package/build/browser/new/platform-apis/admin/useCbacMarkingRestrictions.js +64 -0
- package/build/browser/new/platform-apis/admin/useCbacMarkingRestrictions.js.map +1 -0
- package/build/browser/new/platform-apis/admin/useMarkingCategories.js +46 -0
- package/build/browser/new/platform-apis/admin/useMarkingCategories.js.map +1 -0
- package/build/browser/new/platform-apis/admin/useMarkings.js +46 -0
- package/build/browser/new/platform-apis/admin/useMarkings.js.map +1 -0
- package/build/browser/new/platform-apis/admin/useUserMarkings.js +50 -0
- package/build/browser/new/platform-apis/admin/useUserMarkings.js.map +1 -0
- package/build/browser/new/useOsdkAction.js +3 -6
- package/build/browser/new/useOsdkAction.js.map +1 -1
- package/build/browser/new/useOsdkFunctions.js +137 -0
- package/build/browser/new/useOsdkFunctions.js.map +1 -0
- package/build/browser/new/useOsdkObject.js +6 -2
- package/build/browser/new/useOsdkObject.js.map +1 -1
- package/build/browser/new/useOsdkObjects.js +6 -2
- package/build/browser/new/useOsdkObjects.js.map +1 -1
- package/build/browser/public/experimental/admin.js +5 -0
- package/build/browser/public/experimental/admin.js.map +1 -1
- package/build/browser/public/unstable-do-not-use.js +18 -0
- package/build/browser/public/unstable-do-not-use.js.map +1 -0
- package/build/cjs/chunk-2N32USW5.cjs +28 -0
- package/build/cjs/chunk-2N32USW5.cjs.map +1 -0
- package/build/cjs/chunk-R4FZ5MUH.cjs +34 -0
- package/build/cjs/chunk-R4FZ5MUH.cjs.map +1 -0
- package/build/cjs/{chunk-SVVMLSKN.cjs → chunk-ZUNR45SJ.cjs} +15 -4
- package/build/cjs/chunk-ZUNR45SJ.cjs.map +1 -0
- package/build/cjs/index.cjs +7 -6
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/public/experimental/admin.cjs +154 -7
- package/build/cjs/public/experimental/admin.cjs.map +1 -1
- package/build/cjs/public/experimental/admin.d.cts +159 -2
- package/build/cjs/public/experimental.cjs +42 -36
- package/build/cjs/public/experimental.cjs.map +1 -1
- package/build/cjs/public/experimental.d.cts +12 -121
- package/build/cjs/public/unstable-do-not-use.cjs +114 -0
- package/build/cjs/public/unstable-do-not-use.cjs.map +1 -0
- package/build/cjs/public/unstable-do-not-use.d.cts +35 -0
- package/build/cjs/useOsdkFunction-B0s7lqgN.d.cts +121 -0
- package/build/esm/new/OsdkContext2.js +22 -2
- package/build/esm/new/OsdkContext2.js.map +1 -1
- package/build/esm/new/platform-apis/admin/useCbacBanner.js +63 -0
- package/build/esm/new/platform-apis/admin/useCbacBanner.js.map +1 -0
- package/build/esm/new/platform-apis/admin/useCbacMarkingRestrictions.js +64 -0
- package/build/esm/new/platform-apis/admin/useCbacMarkingRestrictions.js.map +1 -0
- package/build/esm/new/platform-apis/admin/useMarkingCategories.js +46 -0
- package/build/esm/new/platform-apis/admin/useMarkingCategories.js.map +1 -0
- package/build/esm/new/platform-apis/admin/useMarkings.js +46 -0
- package/build/esm/new/platform-apis/admin/useMarkings.js.map +1 -0
- package/build/esm/new/platform-apis/admin/useUserMarkings.js +50 -0
- package/build/esm/new/platform-apis/admin/useUserMarkings.js.map +1 -0
- package/build/esm/new/useOsdkAction.js +3 -6
- package/build/esm/new/useOsdkAction.js.map +1 -1
- package/build/esm/new/useOsdkFunctions.js +137 -0
- package/build/esm/new/useOsdkFunctions.js.map +1 -0
- package/build/esm/new/useOsdkObject.js +6 -2
- package/build/esm/new/useOsdkObject.js.map +1 -1
- package/build/esm/new/useOsdkObjects.js +6 -2
- package/build/esm/new/useOsdkObjects.js.map +1 -1
- package/build/esm/public/experimental/admin.js +5 -0
- package/build/esm/public/experimental/admin.js.map +1 -1
- package/build/esm/public/unstable-do-not-use.js +18 -0
- package/build/esm/public/unstable-do-not-use.js.map +1 -0
- package/build/types/new/OsdkContext2.d.ts +1 -0
- package/build/types/new/OsdkContext2.d.ts.map +1 -1
- package/build/types/new/platform-apis/admin/useCbacBanner.d.ts +33 -0
- package/build/types/new/platform-apis/admin/useCbacBanner.d.ts.map +1 -0
- package/build/types/new/platform-apis/admin/useCbacMarkingRestrictions.d.ts +34 -0
- package/build/types/new/platform-apis/admin/useCbacMarkingRestrictions.d.ts.map +1 -0
- package/build/types/new/platform-apis/admin/useMarkingCategories.d.ts +27 -0
- package/build/types/new/platform-apis/admin/useMarkingCategories.d.ts.map +1 -0
- package/build/types/new/platform-apis/admin/useMarkings.d.ts +27 -0
- package/build/types/new/platform-apis/admin/useMarkings.d.ts.map +1 -0
- package/build/types/new/platform-apis/admin/useUserMarkings.d.ts +33 -0
- package/build/types/new/platform-apis/admin/useUserMarkings.d.ts.map +1 -0
- package/build/types/new/useOsdkFunctions.d.ts +31 -0
- package/build/types/new/useOsdkFunctions.d.ts.map +1 -0
- package/build/types/new/useOsdkObject.d.ts +2 -1
- package/build/types/new/useOsdkObject.d.ts.map +1 -1
- package/build/types/new/useOsdkObjects.d.ts +6 -0
- package/build/types/new/useOsdkObjects.d.ts.map +1 -1
- package/build/types/public/experimental/admin.d.ts +8 -0
- package/build/types/public/experimental/admin.d.ts.map +1 -1
- package/build/types/public/unstable-do-not-use.d.ts +2 -0
- package/build/types/public/unstable-do-not-use.d.ts.map +1 -0
- package/package.json +19 -10
- package/unstable-do-not-use.d.ts +17 -0
- package/build/cjs/chunk-OVBG5VXE.cjs +0 -50
- package/build/cjs/chunk-OVBG5VXE.cjs.map +0 -1
- package/build/cjs/chunk-SVVMLSKN.cjs.map +0 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Client, Osdk, WhereClause, PropertyKeys, ActionDefinition, ActionEditResponse, ActionValidationError, ActionValidationResponse, ObjectTypeDefinition } from '@osdk/client';
|
|
2
|
-
import { ObservableClient, ActionSignatureFromDef
|
|
2
|
+
import { ObservableClient, ActionSignatureFromDef } from '@osdk/client/unstable-do-not-use';
|
|
3
3
|
import React from 'react';
|
|
4
|
-
import { ObjectOrInterfaceDefinition, LinkNames, LinkedType, SimplePropertyDef, ObjectSet, WhereClause as WhereClause$1, DerivedProperty, PropertyKeys as PropertyKeys$1, Osdk as Osdk$1, AggregateOpts, AggregationsResults,
|
|
4
|
+
import { ObjectOrInterfaceDefinition, LinkNames, LinkedType, SimplePropertyDef, ObjectSet, WhereClause as WhereClause$1, DerivedProperty, PropertyKeys as PropertyKeys$1, Osdk as Osdk$1, AggregateOpts, AggregationsResults, PrimaryKeyType } from '@osdk/api';
|
|
5
|
+
export { U as UseOsdkFunctionOptions, a as UseOsdkFunctionResult, u as useOsdkFunction } from '../useOsdkFunction-B0s7lqgN.cjs';
|
|
5
6
|
export { U as UseOsdkMetadataResult, u as useOsdkClient, a as useOsdkMetadata } from '../useOsdkMetadata-BElt3F5s.cjs';
|
|
6
7
|
|
|
7
8
|
interface OsdkProviderOptions {
|
|
@@ -326,123 +327,6 @@ interface UseOsdkAggregationResult<T extends ObjectOrInterfaceDefinition, A exte
|
|
|
326
327
|
declare function useOsdkAggregation<Q extends ObjectOrInterfaceDefinition, const A extends AggregateOpts<Q>, RDPs extends Record<string, SimplePropertyDef> = {}>(type: Q, options: UseOsdkAggregationOptions<Q, A, RDPs>): UseOsdkAggregationResult<Q, A>;
|
|
327
328
|
declare function useOsdkAggregation<Q extends ObjectTypeDefinition, const A extends AggregateOpts<Q>, RDPs extends Record<string, SimplePropertyDef> = {}>(type: Q, options: UseOsdkAggregationOptionsWithObjectSet<Q, A, RDPs>): UseOsdkAggregationResult<Q, A>;
|
|
328
329
|
|
|
329
|
-
interface UseOsdkFunctionOptions<Q extends QueryDefinition<unknown>> {
|
|
330
|
-
/**
|
|
331
|
-
* Parameters to pass to the function.
|
|
332
|
-
* Must include all required parameters; optional parameters can be omitted.
|
|
333
|
-
*/
|
|
334
|
-
params?: CompileTimeMetadata<Q>["parameters"] extends Record<string, never> ? undefined : QueryParameterType<CompileTimeMetadata<Q>["parameters"]>;
|
|
335
|
-
/**
|
|
336
|
-
* Object types this function depends on.
|
|
337
|
-
* When actions modify objects of these types, the function will automatically refetch.
|
|
338
|
-
*
|
|
339
|
-
* @example
|
|
340
|
-
* ```tsx
|
|
341
|
-
* // Refetch when any Employee object changes
|
|
342
|
-
* { dependsOn: [Employee] }
|
|
343
|
-
* ```
|
|
344
|
-
*/
|
|
345
|
-
dependsOn?: Array<ObjectTypeDefinition$1 | string>;
|
|
346
|
-
/**
|
|
347
|
-
* Specific object instances or ObjectSets this function depends on.
|
|
348
|
-
* When any of these specific objects change, the function will refetch.
|
|
349
|
-
* More fine-grained than dependsOn for precise invalidation control.
|
|
350
|
-
*
|
|
351
|
-
* For ObjectSets, the object type is extracted asynchronously and changes
|
|
352
|
-
* to any object of that type will trigger a refetch.
|
|
353
|
-
*
|
|
354
|
-
* @example
|
|
355
|
-
* ```tsx
|
|
356
|
-
* // Refetch when this specific employee changes
|
|
357
|
-
* { dependsOnObjects: [employee] }
|
|
358
|
-
*
|
|
359
|
-
* // Refetch when any object in the ObjectSet's type changes
|
|
360
|
-
* { dependsOnObjects: [employeeObjectSet] }
|
|
361
|
-
* ```
|
|
362
|
-
*/
|
|
363
|
-
dependsOnObjects?: Array<Osdk$1.Instance<ObjectTypeDefinition$1> | ObjectSet<ObjectTypeDefinition$1>>;
|
|
364
|
-
/**
|
|
365
|
-
* The number of milliseconds to dedupe identical function calls.
|
|
366
|
-
* Two calls with the same function and params will share results
|
|
367
|
-
* if the second call is within this interval of the first.
|
|
368
|
-
* @default 2000
|
|
369
|
-
*/
|
|
370
|
-
dedupeIntervalMs?: number;
|
|
371
|
-
/**
|
|
372
|
-
* Whether to enable the query. When false, the query will not execute.
|
|
373
|
-
* Useful for:
|
|
374
|
-
* - Dependent queries that need to wait for other data
|
|
375
|
-
* - Conditional queries based on component state
|
|
376
|
-
*
|
|
377
|
-
* @default true
|
|
378
|
-
* @example
|
|
379
|
-
* // Dependent query - wait for required data
|
|
380
|
-
* const { data: employee } = useOsdkObject(Employee, employeeId);
|
|
381
|
-
* const { data: report } = useOsdkFunction(getEmployeeReport, {
|
|
382
|
-
* params: { employeeId: employee?.$primaryKey },
|
|
383
|
-
* enabled: !!employee
|
|
384
|
-
* });
|
|
385
|
-
*/
|
|
386
|
-
enabled?: boolean;
|
|
387
|
-
}
|
|
388
|
-
interface UseOsdkFunctionResult<Q extends QueryDefinition<unknown>> {
|
|
389
|
-
/**
|
|
390
|
-
* The function result, or undefined if not yet loaded or on error.
|
|
391
|
-
*/
|
|
392
|
-
data: (CompileTimeMetadata<Q>["signature"] extends (...args: never[]) => infer R ? Awaited<R> : never) | undefined;
|
|
393
|
-
/**
|
|
394
|
-
* True while the function is executing.
|
|
395
|
-
*/
|
|
396
|
-
isLoading: boolean;
|
|
397
|
-
/**
|
|
398
|
-
* Error if the function execution failed.
|
|
399
|
-
*/
|
|
400
|
-
error: Error | undefined;
|
|
401
|
-
/**
|
|
402
|
-
* Timestamp (ms since epoch) of when the result was last fetched.
|
|
403
|
-
*/
|
|
404
|
-
lastUpdated: number;
|
|
405
|
-
/**
|
|
406
|
-
* Manually refetch the function.
|
|
407
|
-
* Useful for "pull to refresh" or retry patterns.
|
|
408
|
-
*/
|
|
409
|
-
refetch: () => void;
|
|
410
|
-
}
|
|
411
|
-
/**
|
|
412
|
-
* React hook for executing and observing OSDK functions.
|
|
413
|
-
*
|
|
414
|
-
* Provides automatic caching, deduplication, and reactive updates for function calls.
|
|
415
|
-
* Functions are automatically re-fetched when dependencies change (configured via options).
|
|
416
|
-
*
|
|
417
|
-
* @param queryDef - The QueryDefinition to execute
|
|
418
|
-
* @param options - Configuration options for the function call
|
|
419
|
-
* @returns Object containing result, loading state, error, and refetch function
|
|
420
|
-
*
|
|
421
|
-
* @example Basic usage
|
|
422
|
-
* ```tsx
|
|
423
|
-
* const { data, isLoading, error } = useOsdkFunction(getEmployeeStats, {
|
|
424
|
-
* params: { departmentId: "engineering" }
|
|
425
|
-
* });
|
|
426
|
-
* ```
|
|
427
|
-
*
|
|
428
|
-
* @example With dependency tracking
|
|
429
|
-
* ```tsx
|
|
430
|
-
* const { data, refetch } = useOsdkFunction(calculateMetrics, {
|
|
431
|
-
* params: { startDate, endDate },
|
|
432
|
-
* dependsOn: [Employee, Project],
|
|
433
|
-
* });
|
|
434
|
-
* ```
|
|
435
|
-
*
|
|
436
|
-
* @example With specific object dependencies
|
|
437
|
-
* ```tsx
|
|
438
|
-
* const { data } = useOsdkFunction(getEmployeeReport, {
|
|
439
|
-
* params: { employeeId: employee.$primaryKey },
|
|
440
|
-
* dependsOnObjects: [employee],
|
|
441
|
-
* });
|
|
442
|
-
* ```
|
|
443
|
-
*/
|
|
444
|
-
declare function useOsdkFunction<Q extends QueryDefinition<unknown>>(queryDef: Q, options?: UseOsdkFunctionOptions<Q>): UseOsdkFunctionResult<Q>;
|
|
445
|
-
|
|
446
330
|
interface UseOsdkObjectResult<Q extends ObjectOrInterfaceDefinition> {
|
|
447
331
|
object: Osdk$1.Instance<Q> | undefined;
|
|
448
332
|
isLoading: boolean;
|
|
@@ -471,11 +355,12 @@ declare function useOsdkObject<Q extends ObjectOrInterfaceDefinition>(type: Q, p
|
|
|
471
355
|
*
|
|
472
356
|
* @param type The object type or interface definition
|
|
473
357
|
* @param primaryKey The primary key of the object
|
|
474
|
-
* @param options Options including $select and
|
|
358
|
+
* @param options Options including $select, enabled, and $loadPropertySecurityMetadata
|
|
475
359
|
*/
|
|
476
360
|
declare function useOsdkObject<Q extends ObjectOrInterfaceDefinition>(type: Q, primaryKey: PrimaryKeyType<Q>, options?: {
|
|
477
361
|
$select?: readonly PropertyKeys$1<Q>[];
|
|
478
362
|
enabled?: boolean;
|
|
363
|
+
$loadPropertySecurityMetadata?: boolean;
|
|
479
364
|
}): UseOsdkObjectResult<Q>;
|
|
480
365
|
|
|
481
366
|
interface UseOsdkObjectsOptions<T extends ObjectOrInterfaceDefinition, RDPs extends Record<string, SimplePropertyDef> = {}> {
|
|
@@ -569,6 +454,12 @@ interface UseOsdkObjectsOptions<T extends ObjectOrInterfaceDefinition, RDPs exte
|
|
|
569
454
|
* useOsdkObjects(Employee, { $select: ["name", "status"] })
|
|
570
455
|
*/
|
|
571
456
|
$select?: readonly PropertyKeys$1<T>[];
|
|
457
|
+
/**
|
|
458
|
+
* When true, loads per-property security metadata (marking requirements)
|
|
459
|
+
* alongside each object. The returned objects will have `$propertySecurities`
|
|
460
|
+
* populated with conjunctive/disjunctive marking requirements per property.
|
|
461
|
+
*/
|
|
462
|
+
$loadPropertySecurityMetadata?: boolean;
|
|
572
463
|
}
|
|
573
464
|
interface UseOsdkListResult<T extends ObjectOrInterfaceDefinition, RDPs extends Record<string, SimplePropertyDef> = {}, EXTRA_OPTIONS extends never | "$rid" = never> {
|
|
574
465
|
/**
|
|
@@ -647,4 +538,4 @@ interface DebouncedCallback<TArgs extends readonly unknown[]> {
|
|
|
647
538
|
*/
|
|
648
539
|
declare function useDebouncedCallback<TArgs extends readonly unknown[]>(callback: (...args: TArgs) => void | Promise<void>, delay: number): DebouncedCallback<TArgs>;
|
|
649
540
|
|
|
650
|
-
export { OsdkProvider2, type UseOsdkAggregationResult, type
|
|
541
|
+
export { OsdkProvider2, type UseOsdkAggregationResult, type UseOsdkListResult, type UseOsdkObjectsOptions, useDebouncedCallback, useLinks, useObjectSet, useOsdkAction, useOsdkAggregation, useOsdkObject, useOsdkObjects };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk2N32USW5_cjs = require('../chunk-2N32USW5.cjs');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
|
|
8
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
9
|
+
|
|
10
|
+
function useOsdkFunctions({
|
|
11
|
+
queries,
|
|
12
|
+
enabled = true
|
|
13
|
+
}) {
|
|
14
|
+
const client = chunk2N32USW5_cjs.useOsdkClient();
|
|
15
|
+
const [results, setResults] = React__default.default.useState(() => queries.map(() => ({
|
|
16
|
+
data: void 0,
|
|
17
|
+
isLoading: false,
|
|
18
|
+
error: void 0,
|
|
19
|
+
lastUpdated: 0
|
|
20
|
+
})));
|
|
21
|
+
const abortControllerRef = React__default.default.useRef(null);
|
|
22
|
+
React__default.default.useEffect(() => {
|
|
23
|
+
if (!enabled || queries.length === 0) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
abortControllerRef.current?.abort();
|
|
27
|
+
const abortController = new AbortController();
|
|
28
|
+
abortControllerRef.current = abortController;
|
|
29
|
+
const executeQueries = async () => {
|
|
30
|
+
setResults((prev) => queries.map((_, index) => ({
|
|
31
|
+
data: prev[index]?.data,
|
|
32
|
+
// Preserving existing data
|
|
33
|
+
isLoading: queries[index].options?.enabled !== false,
|
|
34
|
+
error: void 0,
|
|
35
|
+
lastUpdated: prev[index]?.lastUpdated || 0
|
|
36
|
+
})));
|
|
37
|
+
for await (const queryResult of executeQueriesGenerator(queries, client)) {
|
|
38
|
+
const {
|
|
39
|
+
index,
|
|
40
|
+
result,
|
|
41
|
+
error
|
|
42
|
+
} = queryResult;
|
|
43
|
+
if (abortController.signal.aborted) {
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
setResults((prev) => {
|
|
47
|
+
if (abortController.signal.aborted) {
|
|
48
|
+
return prev;
|
|
49
|
+
}
|
|
50
|
+
const newResults = [...prev];
|
|
51
|
+
newResults[index] = {
|
|
52
|
+
data: result,
|
|
53
|
+
isLoading: false,
|
|
54
|
+
error: error instanceof Error ? error : error ? new Error(typeof error === "string" ? error : JSON.stringify(error)) : void 0,
|
|
55
|
+
lastUpdated: Date.now()
|
|
56
|
+
};
|
|
57
|
+
return newResults;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
void executeQueries();
|
|
62
|
+
return () => {
|
|
63
|
+
abortController.abort();
|
|
64
|
+
};
|
|
65
|
+
}, [enabled, client, queries]);
|
|
66
|
+
return results;
|
|
67
|
+
}
|
|
68
|
+
async function* executeQueriesGenerator(queries, client) {
|
|
69
|
+
const queryPromises = queries.map((query, index) => createQueryPromise(query, index, client));
|
|
70
|
+
const pendingPromises = [...queryPromises];
|
|
71
|
+
while (pendingPromises.length > 0) {
|
|
72
|
+
const raceResult = await Promise.race(pendingPromises.map((promise, idx) => promise.then((result) => ({
|
|
73
|
+
result,
|
|
74
|
+
idx
|
|
75
|
+
}))));
|
|
76
|
+
yield raceResult.result;
|
|
77
|
+
void pendingPromises.splice(raceResult.idx, 1);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
var createQueryPromise = async (query, index, client) => {
|
|
81
|
+
if (query.options?.enabled === false) {
|
|
82
|
+
return {
|
|
83
|
+
index,
|
|
84
|
+
result: void 0,
|
|
85
|
+
error: void 0
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const queryClient = client(query.queryDefinition);
|
|
89
|
+
if ("executeFunction" in queryClient && typeof queryClient.executeFunction === "function") {
|
|
90
|
+
try {
|
|
91
|
+
const result = await queryClient.executeFunction(query.options?.params);
|
|
92
|
+
return {
|
|
93
|
+
index,
|
|
94
|
+
result,
|
|
95
|
+
error: null
|
|
96
|
+
};
|
|
97
|
+
} catch (error) {
|
|
98
|
+
return {
|
|
99
|
+
index,
|
|
100
|
+
result: void 0,
|
|
101
|
+
error
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
index,
|
|
107
|
+
result: void 0,
|
|
108
|
+
error: new Error("Invalid query client: executeFunction method not found")
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
exports.useOsdkFunctions = useOsdkFunctions;
|
|
113
|
+
//# sourceMappingURL=unstable-do-not-use.cjs.map
|
|
114
|
+
//# sourceMappingURL=unstable-do-not-use.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/new/useOsdkFunctions.ts"],"names":["useOsdkClient","React"],"mappings":";;;;;;;;;AAyBO,SAAS,gBAAiB,CAAA;AAAA,EAC/B,OAAA;AAAA,EACA,OAAU,GAAA;AACZ,CAAG,EAAA;AACD,EAAA,MAAM,SAASA,+BAAc,EAAA;AAC7B,EAAM,MAAA,CAAC,SAAS,UAAU,CAAA,GAAIC,uBAAM,QAAS,CAAA,MAAM,OAAQ,CAAA,GAAA,CAAI,OAAO;AAAA,IACpE,IAAM,EAAA,MAAA;AAAA,IACN,SAAW,EAAA,KAAA;AAAA,IACX,KAAO,EAAA,MAAA;AAAA,IACP,WAAa,EAAA;AAAA,IACb,CAAC,CAAA;AACH,EAAM,MAAA,kBAAA,GAAqBA,sBAAM,CAAA,MAAA,CAAO,IAAI,CAAA;AAC5C,EAAAA,sBAAA,CAAM,UAAU,MAAM;AACpB,IAAA,IAAI,CAAC,OAAA,IAAW,OAAQ,CAAA,MAAA,KAAW,CAAG,EAAA;AACpC,MAAA;AAAA;AAIF,IAAA,kBAAA,CAAmB,SAAS,KAAM,EAAA;AAClC,IAAM,MAAA,eAAA,GAAkB,IAAI,eAAgB,EAAA;AAC5C,IAAA,kBAAA,CAAmB,OAAU,GAAA,eAAA;AAC7B,IAAA,MAAM,iBAAiB,YAAY;AAEjC,MAAA,UAAA,CAAW,CAAQ,IAAA,KAAA,OAAA,CAAQ,GAAI,CAAA,CAAC,GAAG,KAAW,MAAA;AAAA,QAC5C,IAAA,EAAM,IAAK,CAAA,KAAK,CAAG,EAAA,IAAA;AAAA;AAAA,QAEnB,SAAW,EAAA,OAAA,CAAQ,KAAK,CAAA,CAAE,SAAS,OAAY,KAAA,KAAA;AAAA,QAC/C,KAAO,EAAA,MAAA;AAAA,QACP,WAAa,EAAA,IAAA,CAAK,KAAK,C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EAAO,IAAI,KAAA,CAAM,wDAAwD;AAAA,GAC3E;AACF,CAAA","file":"unstable-do-not-use.cjs","sourcesContent":["/*\n * Copyright 2026 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from \"react\";\nimport { useOsdkClient } from \"../useOsdkClient.js\";\n/**\n * React hook for executing multiple OSDK function queries in parallel.\n * Results are returned in the same order as the input queries.\n *\n * @param options - Configuration options containing the queries to execute\n * @returns Array of results in the same order as input queries, each with the same shape as useOsdkFunction\n */\nexport function useOsdkFunctions({\n queries,\n enabled = true\n}) {\n const client = useOsdkClient();\n const [results, setResults] = React.useState(() => queries.map(() => ({\n data: undefined,\n isLoading: false,\n error: undefined,\n lastUpdated: 0\n })));\n const abortControllerRef = React.useRef(null);\n React.useEffect(() => {\n if (!enabled || queries.length === 0) {\n return;\n }\n\n // Cancel previous requests\n abortControllerRef.current?.abort();\n const abortController = new AbortController();\n abortControllerRef.current = abortController;\n const executeQueries = async () => {\n // Initialize loading state for all queries\n setResults(prev => queries.map((_, index) => ({\n data: prev[index]?.data,\n // Preserving existing data\n isLoading: queries[index].options?.enabled !== false,\n error: undefined,\n lastUpdated: prev[index]?.lastUpdated || 0\n })));\n for await (const queryResult of executeQueriesGenerator(queries, client)) {\n const {\n index,\n result,\n error\n } = queryResult;\n if (abortController.signal.aborted) {\n break;\n }\n setResults(prev => {\n if (abortController.signal.aborted) {\n return prev;\n }\n const newResults = [...prev];\n newResults[index] = {\n data: result,\n isLoading: false,\n error: error instanceof Error ? error : error ? new Error(typeof error === \"string\" ? error : JSON.stringify(error)) : undefined,\n lastUpdated: Date.now()\n };\n return newResults;\n });\n }\n };\n void executeQueries();\n return () => {\n abortController.abort();\n };\n }, [enabled, client, queries]);\n return results;\n}\n/**\n * Generator function that executes queries and yields results as they complete\n */\nasync function* executeQueriesGenerator(queries, client) {\n const queryPromises = queries.map((query, index) => createQueryPromise(query, index, client));\n const pendingPromises = [...queryPromises];\n\n // Yield results as they complete using Promise.race\n while (pendingPromises.length > 0) {\n const raceResult = await Promise.race(pendingPromises.map((promise, idx) => promise.then(result => ({\n result,\n idx\n }))));\n yield raceResult.result;\n\n // Remove the completed promise from the pending list\n void pendingPromises.splice(raceResult.idx, 1);\n }\n}\nconst createQueryPromise = async (query, index, client) => {\n // Skip disabled queries\n if (query.options?.enabled === false) {\n return {\n index,\n result: undefined,\n error: undefined\n };\n }\n const queryClient = client(query.queryDefinition);\n if (\"executeFunction\" in queryClient && typeof queryClient.executeFunction === \"function\") {\n try {\n const result = await queryClient.executeFunction(query.options?.params);\n return {\n index,\n result,\n error: null\n };\n } catch (error) {\n return {\n index,\n result: undefined,\n error\n };\n }\n }\n return {\n index,\n result: undefined,\n error: new Error(\"Invalid query client: executeFunction method not found\")\n };\n};"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { QueryDefinition } from '@osdk/api';
|
|
2
|
+
import { U as UseOsdkFunctionOptions, a as UseOsdkFunctionResult } from '../useOsdkFunction-B0s7lqgN.cjs';
|
|
3
|
+
import '@osdk/client/unstable-do-not-use';
|
|
4
|
+
|
|
5
|
+
interface FunctionQueryParams<Q extends QueryDefinition<unknown>> {
|
|
6
|
+
queryDefinition: Q;
|
|
7
|
+
/**
|
|
8
|
+
* Only allow params and enabled options at the query level,
|
|
9
|
+
* other options are not yet supported in this batch context
|
|
10
|
+
*/
|
|
11
|
+
options?: Pick<UseOsdkFunctionOptions<Q>, "params" | "enabled">;
|
|
12
|
+
}
|
|
13
|
+
interface UseOsdkFunctionsProps {
|
|
14
|
+
/**
|
|
15
|
+
* Array of query configurations to execute
|
|
16
|
+
*/
|
|
17
|
+
queries: Array<FunctionQueryParams<QueryDefinition<unknown>>>;
|
|
18
|
+
/**
|
|
19
|
+
* Whether to enable all queries. When false, no queries will execute.
|
|
20
|
+
* Individual query enabled states are also respected.
|
|
21
|
+
* @default true
|
|
22
|
+
*/
|
|
23
|
+
enabled?: boolean;
|
|
24
|
+
}
|
|
25
|
+
type UseOsdkFunctionsResult = Array<Omit<UseOsdkFunctionResult<QueryDefinition<unknown>>, "refetch">>;
|
|
26
|
+
/**
|
|
27
|
+
* React hook for executing multiple OSDK function queries in parallel.
|
|
28
|
+
* Results are returned in the same order as the input queries.
|
|
29
|
+
*
|
|
30
|
+
* @param options - Configuration options containing the queries to execute
|
|
31
|
+
* @returns Array of results in the same order as input queries, each with the same shape as useOsdkFunction
|
|
32
|
+
*/
|
|
33
|
+
declare function useOsdkFunctions({ queries, enabled }: UseOsdkFunctionsProps): UseOsdkFunctionsResult;
|
|
34
|
+
|
|
35
|
+
export { type FunctionQueryParams, type UseOsdkFunctionsProps, type UseOsdkFunctionsResult, useOsdkFunctions };
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { QueryDefinition, CompileTimeMetadata, ObjectTypeDefinition, Osdk, ObjectSet } from '@osdk/api';
|
|
2
|
+
import { QueryParameterType } from '@osdk/client/unstable-do-not-use';
|
|
3
|
+
|
|
4
|
+
interface UseOsdkFunctionOptions<Q extends QueryDefinition<unknown>> {
|
|
5
|
+
/**
|
|
6
|
+
* Parameters to pass to the function.
|
|
7
|
+
* Must include all required parameters; optional parameters can be omitted.
|
|
8
|
+
*/
|
|
9
|
+
params?: CompileTimeMetadata<Q>["parameters"] extends Record<string, never> ? undefined : QueryParameterType<CompileTimeMetadata<Q>["parameters"]>;
|
|
10
|
+
/**
|
|
11
|
+
* Object types this function depends on.
|
|
12
|
+
* When actions modify objects of these types, the function will automatically refetch.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* // Refetch when any Employee object changes
|
|
17
|
+
* { dependsOn: [Employee] }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
dependsOn?: Array<ObjectTypeDefinition | string>;
|
|
21
|
+
/**
|
|
22
|
+
* Specific object instances or ObjectSets this function depends on.
|
|
23
|
+
* When any of these specific objects change, the function will refetch.
|
|
24
|
+
* More fine-grained than dependsOn for precise invalidation control.
|
|
25
|
+
*
|
|
26
|
+
* For ObjectSets, the object type is extracted asynchronously and changes
|
|
27
|
+
* to any object of that type will trigger a refetch.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```tsx
|
|
31
|
+
* // Refetch when this specific employee changes
|
|
32
|
+
* { dependsOnObjects: [employee] }
|
|
33
|
+
*
|
|
34
|
+
* // Refetch when any object in the ObjectSet's type changes
|
|
35
|
+
* { dependsOnObjects: [employeeObjectSet] }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
dependsOnObjects?: Array<Osdk.Instance<ObjectTypeDefinition> | ObjectSet<ObjectTypeDefinition>>;
|
|
39
|
+
/**
|
|
40
|
+
* The number of milliseconds to dedupe identical function calls.
|
|
41
|
+
* Two calls with the same function and params will share results
|
|
42
|
+
* if the second call is within this interval of the first.
|
|
43
|
+
* @default 2000
|
|
44
|
+
*/
|
|
45
|
+
dedupeIntervalMs?: number;
|
|
46
|
+
/**
|
|
47
|
+
* Whether to enable the query. When false, the query will not execute.
|
|
48
|
+
* Useful for:
|
|
49
|
+
* - Dependent queries that need to wait for other data
|
|
50
|
+
* - Conditional queries based on component state
|
|
51
|
+
*
|
|
52
|
+
* @default true
|
|
53
|
+
* @example
|
|
54
|
+
* // Dependent query - wait for required data
|
|
55
|
+
* const { data: employee } = useOsdkObject(Employee, employeeId);
|
|
56
|
+
* const { data: report } = useOsdkFunction(getEmployeeReport, {
|
|
57
|
+
* params: { employeeId: employee?.$primaryKey },
|
|
58
|
+
* enabled: !!employee
|
|
59
|
+
* });
|
|
60
|
+
*/
|
|
61
|
+
enabled?: boolean;
|
|
62
|
+
}
|
|
63
|
+
interface UseOsdkFunctionResult<Q extends QueryDefinition<unknown>> {
|
|
64
|
+
/**
|
|
65
|
+
* The function result, or undefined if not yet loaded or on error.
|
|
66
|
+
*/
|
|
67
|
+
data: (CompileTimeMetadata<Q>["signature"] extends (...args: never[]) => infer R ? Awaited<R> : never) | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* True while the function is executing.
|
|
70
|
+
*/
|
|
71
|
+
isLoading: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Error if the function execution failed.
|
|
74
|
+
*/
|
|
75
|
+
error: Error | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Timestamp (ms since epoch) of when the result was last fetched.
|
|
78
|
+
*/
|
|
79
|
+
lastUpdated: number;
|
|
80
|
+
/**
|
|
81
|
+
* Manually refetch the function.
|
|
82
|
+
* Useful for "pull to refresh" or retry patterns.
|
|
83
|
+
*/
|
|
84
|
+
refetch: () => void;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* React hook for executing and observing OSDK functions.
|
|
88
|
+
*
|
|
89
|
+
* Provides automatic caching, deduplication, and reactive updates for function calls.
|
|
90
|
+
* Functions are automatically re-fetched when dependencies change (configured via options).
|
|
91
|
+
*
|
|
92
|
+
* @param queryDef - The QueryDefinition to execute
|
|
93
|
+
* @param options - Configuration options for the function call
|
|
94
|
+
* @returns Object containing result, loading state, error, and refetch function
|
|
95
|
+
*
|
|
96
|
+
* @example Basic usage
|
|
97
|
+
* ```tsx
|
|
98
|
+
* const { data, isLoading, error } = useOsdkFunction(getEmployeeStats, {
|
|
99
|
+
* params: { departmentId: "engineering" }
|
|
100
|
+
* });
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @example With dependency tracking
|
|
104
|
+
* ```tsx
|
|
105
|
+
* const { data, refetch } = useOsdkFunction(calculateMetrics, {
|
|
106
|
+
* params: { startDate, endDate },
|
|
107
|
+
* dependsOn: [Employee, Project],
|
|
108
|
+
* });
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* @example With specific object dependencies
|
|
112
|
+
* ```tsx
|
|
113
|
+
* const { data } = useOsdkFunction(getEmployeeReport, {
|
|
114
|
+
* params: { employeeId: employee.$primaryKey },
|
|
115
|
+
* dependsOnObjects: [employee],
|
|
116
|
+
* });
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
declare function useOsdkFunction<Q extends QueryDefinition<unknown>>(queryDef: Q, options?: UseOsdkFunctionOptions<Q>): UseOsdkFunctionResult<Q>;
|
|
120
|
+
|
|
121
|
+
export { type UseOsdkFunctionOptions as U, type UseOsdkFunctionResult as a, useOsdkFunction as u };
|
|
@@ -15,14 +15,34 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import React from "react";
|
|
18
|
+
export const MISSING_PROVIDER_MESSAGE = "No OsdkProvider2 found. Did you forget to wrap your component tree with <OsdkProvider2>?";
|
|
18
19
|
function fakeClientFn(..._args) {
|
|
19
|
-
throw new Error(
|
|
20
|
+
throw new Error(MISSING_PROVIDER_MESSAGE);
|
|
20
21
|
}
|
|
21
22
|
const fakeClient = Object.assign(fakeClientFn, {
|
|
22
23
|
fetchMetadata: fakeClientFn
|
|
23
24
|
});
|
|
25
|
+
|
|
26
|
+
// Proxy that throws a clear error when any method is called, so hooks like
|
|
27
|
+
// useOsdkObjects get "Did you forget <OsdkProvider2>?" instead of
|
|
28
|
+
// "cannot read canonicalizeWhereClause of undefined".
|
|
29
|
+
// We intercept `get` so every property access returns a throwing function,
|
|
30
|
+
// without needing to enumerate every ObservableClient method.
|
|
31
|
+
// Symbol.toPrimitive and Symbol.toStringTag are accessed by React/devtools
|
|
32
|
+
// during rendering and logging — returning undefined for these avoids
|
|
33
|
+
// spurious throws in contexts unrelated to the user's code.
|
|
34
|
+
const fakeObservableClient = new Proxy({}, {
|
|
35
|
+
get(_target, prop) {
|
|
36
|
+
if (prop === Symbol.toPrimitive || prop === Symbol.toStringTag) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
return (..._args) => {
|
|
40
|
+
throw new Error(MISSING_PROVIDER_MESSAGE);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
});
|
|
24
44
|
export const OsdkContext2 = /*#__PURE__*/React.createContext({
|
|
25
45
|
client: fakeClient,
|
|
26
|
-
observableClient:
|
|
46
|
+
observableClient: fakeObservableClient
|
|
27
47
|
});
|
|
28
48
|
//# sourceMappingURL=OsdkContext2.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OsdkContext2.js","names":["React","fakeClientFn","_args","Error","fakeClient","Object","assign","fetchMetadata","OsdkContext2","createContext","client","observableClient"
|
|
1
|
+
{"version":3,"file":"OsdkContext2.js","names":["React","MISSING_PROVIDER_MESSAGE","fakeClientFn","_args","Error","fakeClient","Object","assign","fetchMetadata","fakeObservableClient","Proxy","get","_target","prop","Symbol","toPrimitive","toStringTag","undefined","OsdkContext2","createContext","client","observableClient"],"sources":["OsdkContext2.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Client } from \"@osdk/client\";\nimport type { ObservableClient } from \"@osdk/client/unstable-do-not-use\";\nimport React from \"react\";\n\nexport const MISSING_PROVIDER_MESSAGE =\n \"No OsdkProvider2 found. Did you forget to wrap your component tree with <OsdkProvider2>?\";\n\nfunction fakeClientFn(..._args: any[]) {\n throw new Error(MISSING_PROVIDER_MESSAGE);\n}\n\nconst fakeClient = Object.assign(fakeClientFn, {\n fetchMetadata: fakeClientFn,\n} as Client);\n\n// Proxy that throws a clear error when any method is called, so hooks like\n// useOsdkObjects get \"Did you forget <OsdkProvider2>?\" instead of\n// \"cannot read canonicalizeWhereClause of undefined\".\n// We intercept `get` so every property access returns a throwing function,\n// without needing to enumerate every ObservableClient method.\n// Symbol.toPrimitive and Symbol.toStringTag are accessed by React/devtools\n// during rendering and logging — returning undefined for these avoids\n// spurious throws in contexts unrelated to the user's code.\nconst fakeObservableClient = new Proxy({} as ObservableClient, {\n get(_target, prop) {\n if (prop === Symbol.toPrimitive || prop === Symbol.toStringTag) {\n return undefined;\n }\n return (..._args: any[]) => {\n throw new Error(MISSING_PROVIDER_MESSAGE);\n };\n },\n});\n\ninterface OsdkContextContents {\n client: Client;\n // keeping the old name for now intentionally\n // in case i need both for a while\n // in the future we can just make\n // this `client: ObservableClient`\n observableClient: ObservableClient;\n}\n\nexport const OsdkContext2: React.Context<OsdkContextContents> = React\n .createContext<OsdkContextContents>({\n client: fakeClient,\n observableClient: fakeObservableClient,\n });\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAOA,KAAK,MAAM,OAAO;AAEzB,OAAO,MAAMC,wBAAwB,GACnC,0FAA0F;AAE5F,SAASC,YAAYA,CAAC,GAAGC,KAAY,EAAE;EACrC,MAAM,IAAIC,KAAK,CAACH,wBAAwB,CAAC;AAC3C;AAEA,MAAMI,UAAU,GAAGC,MAAM,CAACC,MAAM,CAACL,YAAY,EAAE;EAC7CM,aAAa,EAAEN;AACjB,CAAW,CAAC;;AAEZ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMO,oBAAoB,GAAG,IAAIC,KAAK,CAAC,CAAC,CAAC,EAAsB;EAC7DC,GAAGA,CAACC,OAAO,EAAEC,IAAI,EAAE;IACjB,IAAIA,IAAI,KAAKC,MAAM,CAACC,WAAW,IAAIF,IAAI,KAAKC,MAAM,CAACE,WAAW,EAAE;MAC9D,OAAOC,SAAS;IAClB;IACA,OAAO,CAAC,GAAGd,KAAY,KAAK;MAC1B,MAAM,IAAIC,KAAK,CAACH,wBAAwB,CAAC;IAC3C,CAAC;EACH;AACF,CAAC,CAAC;AAWF,OAAO,MAAMiB,YAAgD,gBAAGlB,KAAK,CAClEmB,aAAa,CAAsB;EAClCC,MAAM,EAAEf,UAAU;EAClBgB,gBAAgB,EAAEZ;AACpB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { CbacBanners } from "@osdk/foundry.admin";
|
|
18
|
+
import React from "react";
|
|
19
|
+
import { usePlatformQuery } from "../../../utils/usePlatformQuery.js";
|
|
20
|
+
import { OsdkContext2 } from "../../OsdkContext2.js";
|
|
21
|
+
/**
|
|
22
|
+
* Get the CBAC banner data for the given marking IDs.
|
|
23
|
+
* @param options Options to control the query.
|
|
24
|
+
*/
|
|
25
|
+
export function useCbacBanner({
|
|
26
|
+
markingIds,
|
|
27
|
+
enabled: externalEnabled = true
|
|
28
|
+
}) {
|
|
29
|
+
const {
|
|
30
|
+
client
|
|
31
|
+
} = React.useContext(OsdkContext2);
|
|
32
|
+
const stableMarkingIds = React.useMemo(() => markingIds, [JSON.stringify(markingIds)]);
|
|
33
|
+
const enabled = stableMarkingIds.length > 0 && externalEnabled;
|
|
34
|
+
const handleQuery = React.useCallback(() => {
|
|
35
|
+
return CbacBanners.get(client, {
|
|
36
|
+
markingIds: stableMarkingIds,
|
|
37
|
+
preview: true
|
|
38
|
+
});
|
|
39
|
+
}, [client, stableMarkingIds]);
|
|
40
|
+
const query = usePlatformQuery({
|
|
41
|
+
query: handleQuery,
|
|
42
|
+
enabled,
|
|
43
|
+
queryName: "cbac-banner"
|
|
44
|
+
});
|
|
45
|
+
const banner = React.useMemo(() => {
|
|
46
|
+
if (query.data == null) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
classificationString: query.data.classificationString,
|
|
51
|
+
textColor: query.data.textColor,
|
|
52
|
+
backgroundColors: query.data.backgroundColors,
|
|
53
|
+
markingIds: query.data.markings
|
|
54
|
+
};
|
|
55
|
+
}, [query.data]);
|
|
56
|
+
return {
|
|
57
|
+
banner,
|
|
58
|
+
isLoading: query.isLoading,
|
|
59
|
+
error: query.error,
|
|
60
|
+
refetch: query.refetch
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=useCbacBanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCbacBanner.js","names":["CbacBanners","React","usePlatformQuery","OsdkContext2","useCbacBanner","markingIds","enabled","externalEnabled","client","useContext","stableMarkingIds","useMemo","JSON","stringify","length","handleQuery","useCallback","get","preview","query","queryName","banner","data","undefined","classificationString","textColor","backgroundColors","markings","isLoading","error","refetch"],"sources":["useCbacBanner.ts"],"sourcesContent":["/*\n * Copyright 2026 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 { CbacBanners } from \"@osdk/foundry.admin\";\nimport React from \"react\";\nimport { usePlatformQuery } from \"../../../utils/usePlatformQuery.js\";\nimport { OsdkContext2 } from \"../../OsdkContext2.js\";\n\nexport interface CbacBannerData {\n classificationString: string;\n textColor: string;\n backgroundColors: string[];\n markingIds: string[];\n}\n\nexport interface UseCbacBannerOptions {\n markingIds: string[];\n /**\n * Enable or disable the query.\n *\n * When `false`, the query will not automatically execute.\n *\n * This is useful for:\n * - Lazy/on-demand queries that should wait for user interaction\n * - Dependent queries that need data from another query first\n * - Conditional queries based on component state\n *\n * @default true\n */\n enabled?: boolean;\n}\n\nexport interface UseCbacBannerResult {\n banner: CbacBannerData | undefined;\n isLoading: boolean;\n\n error: Error | undefined;\n\n refetch: () => void;\n}\n\n/**\n * Get the CBAC banner data for the given marking IDs.\n * @param options Options to control the query.\n */\nexport function useCbacBanner(\n { markingIds, enabled: externalEnabled = true }: UseCbacBannerOptions,\n): UseCbacBannerResult {\n const { client } = React.useContext(OsdkContext2);\n\n const stableMarkingIds = React.useMemo(\n () => markingIds,\n [JSON.stringify(markingIds)],\n );\n\n const enabled = stableMarkingIds.length > 0 && externalEnabled;\n\n const handleQuery = React.useCallback(() => {\n return CbacBanners.get(client, {\n markingIds: stableMarkingIds,\n preview: true,\n });\n }, [client, stableMarkingIds]);\n\n const query = usePlatformQuery({\n query: handleQuery,\n enabled,\n queryName: \"cbac-banner\",\n });\n\n const banner = React.useMemo((): CbacBannerData | undefined => {\n if (query.data == null) {\n return undefined;\n }\n return {\n classificationString: query.data.classificationString,\n textColor: query.data.textColor,\n backgroundColors: query.data.backgroundColors,\n markingIds: query.data.markings,\n };\n }, [query.data]);\n\n return {\n banner,\n isLoading: query.isLoading,\n error: query.error,\n refetch: query.refetch,\n };\n}\n"],"mappings":"AA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AEP,KAAK,CAACG,IAAI,CAACI,gBAAgB;MAC7CrB,UAAU,EAAEc,KAAK,CAACG,IAAI,CAACK;IACzB,CAAC;EACH,CAAC,EAAE,CAACR,KAAK,CAACG,IAAI,CAAC,CAAC;EAEhB,OAAO;IACLD,MAAM;IACNO,SAAS,EAAET,KAAK,CAACS,SAAS;IAC1BC,KAAK,EAAEV,KAAK,CAACU,KAAK;IAClBC,OAAO,EAAEX,KAAK,CAACW;EACjB,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { CbacMarkingRestrictionsObjects } from "@osdk/foundry.admin";
|
|
18
|
+
import React from "react";
|
|
19
|
+
import { usePlatformQuery } from "../../../utils/usePlatformQuery.js";
|
|
20
|
+
import { OsdkContext2 } from "../../OsdkContext2.js";
|
|
21
|
+
/**
|
|
22
|
+
* Get CBAC marking restrictions (implied, disallowed, required) for the given marking IDs.
|
|
23
|
+
* @param options Options to control the query.
|
|
24
|
+
*/
|
|
25
|
+
export function useCbacMarkingRestrictions({
|
|
26
|
+
markingIds,
|
|
27
|
+
enabled: externalEnabled = true
|
|
28
|
+
}) {
|
|
29
|
+
const {
|
|
30
|
+
client
|
|
31
|
+
} = React.useContext(OsdkContext2);
|
|
32
|
+
const stableMarkingIds = React.useMemo(() => markingIds, [JSON.stringify(markingIds)]);
|
|
33
|
+
const enabled = stableMarkingIds.length > 0 && externalEnabled;
|
|
34
|
+
const handleQuery = React.useCallback(() => {
|
|
35
|
+
return CbacMarkingRestrictionsObjects.get(client, {
|
|
36
|
+
markingIds: stableMarkingIds,
|
|
37
|
+
preview: true
|
|
38
|
+
});
|
|
39
|
+
}, [client, stableMarkingIds]);
|
|
40
|
+
const query = usePlatformQuery({
|
|
41
|
+
query: handleQuery,
|
|
42
|
+
enabled,
|
|
43
|
+
queryName: "cbac-marking-restrictions"
|
|
44
|
+
});
|
|
45
|
+
const restrictions = React.useMemo(() => {
|
|
46
|
+
if (query.data == null) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
disallowedMarkings: query.data.disallowedMarkings.map(String),
|
|
51
|
+
impliedMarkings: query.data.impliedMarkings.map(String),
|
|
52
|
+
requiredMarkings: query.data.requiredMarkings.map(group => group.map(String)),
|
|
53
|
+
userSatisfiesMarkings: query.data.userSatisfiesMarkings,
|
|
54
|
+
isValid: query.data.isValid
|
|
55
|
+
};
|
|
56
|
+
}, [query.data]);
|
|
57
|
+
return {
|
|
58
|
+
restrictions,
|
|
59
|
+
isLoading: query.isLoading,
|
|
60
|
+
error: query.error,
|
|
61
|
+
refetch: query.refetch
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=useCbacMarkingRestrictions.js.map
|