@osdk/react 0.10.0-beta.4 → 0.10.0-beta.6
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 +29 -0
- package/build/browser/intellisense.test.helpers/useOsdkObjectsWithRids.js +37 -0
- package/build/browser/intellisense.test.helpers/useOsdkObjectsWithRids.js.map +1 -0
- package/build/browser/intellisense.test.js +24 -0
- package/build/browser/intellisense.test.js.map +1 -1
- package/build/browser/new/makeExternalStore.js +61 -0
- package/build/browser/new/makeExternalStore.js.map +1 -1
- package/build/browser/new/useLinks.js +2 -2
- package/build/browser/new/useLinks.js.map +1 -1
- package/build/browser/new/useObjectSet.js +4 -3
- package/build/browser/new/useObjectSet.js.map +1 -1
- package/build/browser/new/useOsdkAction.js +2 -2
- package/build/browser/new/useOsdkAction.js.map +1 -1
- package/build/browser/new/useOsdkAggregation.js +63 -27
- package/build/browser/new/useOsdkAggregation.js.map +1 -1
- package/build/browser/new/useOsdkFunction.js +10 -8
- package/build/browser/new/useOsdkFunction.js.map +1 -1
- package/build/browser/new/useOsdkObject.js +26 -24
- package/build/browser/new/useOsdkObject.js.map +1 -1
- package/build/browser/new/useOsdkObjects.js +16 -14
- package/build/browser/new/useOsdkObjects.js.map +1 -1
- package/build/cjs/public/experimental.cjs +161 -72
- package/build/cjs/public/experimental.cjs.map +1 -1
- package/build/cjs/public/experimental.d.cts +43 -11
- package/build/esm/intellisense.test.helpers/useOsdkObjectsWithRids.js +37 -0
- package/build/esm/intellisense.test.helpers/useOsdkObjectsWithRids.js.map +1 -0
- package/build/esm/intellisense.test.js +24 -0
- package/build/esm/intellisense.test.js.map +1 -1
- package/build/esm/new/makeExternalStore.js +61 -0
- package/build/esm/new/makeExternalStore.js.map +1 -1
- package/build/esm/new/useLinks.js +2 -2
- package/build/esm/new/useLinks.js.map +1 -1
- package/build/esm/new/useObjectSet.js +4 -3
- package/build/esm/new/useObjectSet.js.map +1 -1
- package/build/esm/new/useOsdkAction.js +2 -2
- package/build/esm/new/useOsdkAction.js.map +1 -1
- package/build/esm/new/useOsdkAggregation.js +63 -27
- package/build/esm/new/useOsdkAggregation.js.map +1 -1
- package/build/esm/new/useOsdkFunction.js +10 -8
- package/build/esm/new/useOsdkFunction.js.map +1 -1
- package/build/esm/new/useOsdkObject.js +26 -24
- package/build/esm/new/useOsdkObject.js.map +1 -1
- package/build/esm/new/useOsdkObjects.js +16 -14
- package/build/esm/new/useOsdkObjects.js.map +1 -1
- package/build/types/intellisense.test.helpers/useOsdkObjectsWithRids.d.ts +1 -0
- package/build/types/intellisense.test.helpers/useOsdkObjectsWithRids.d.ts.map +1 -0
- package/build/types/new/makeExternalStore.d.ts +11 -0
- package/build/types/new/makeExternalStore.d.ts.map +1 -1
- package/build/types/new/useObjectSet.d.ts.map +1 -1
- package/build/types/new/useOsdkAggregation.d.ts +41 -3
- package/build/types/new/useOsdkAggregation.d.ts.map +1 -1
- package/build/types/new/useOsdkObject.d.ts +7 -7
- package/build/types/new/useOsdkObject.d.ts.map +1 -1
- package/build/types/new/useOsdkObjects.d.ts +16 -2
- package/build/types/new/useOsdkObjects.d.ts.map +1 -1
- package/package.json +7 -7
|
@@ -71,6 +71,60 @@ function makeExternalStore(createObservation, _name, initialValue) {
|
|
|
71
71
|
getSnapShot
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
|
+
function makeExternalStoreAsync(createObservation, _name, initialValue) {
|
|
75
|
+
let lastResult = initialValue;
|
|
76
|
+
function getSnapShot() {
|
|
77
|
+
return lastResult;
|
|
78
|
+
}
|
|
79
|
+
function subscribe(notifyUpdate) {
|
|
80
|
+
let isActive = true;
|
|
81
|
+
let currentSubscription;
|
|
82
|
+
const subscriptionPromise = createObservation({
|
|
83
|
+
next: (payload) => {
|
|
84
|
+
if (isActive) {
|
|
85
|
+
lastResult = payload;
|
|
86
|
+
notifyUpdate();
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
error: (error) => {
|
|
90
|
+
if (isActive) {
|
|
91
|
+
lastResult = {
|
|
92
|
+
...lastResult ?? {},
|
|
93
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
94
|
+
};
|
|
95
|
+
notifyUpdate();
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
complete: () => {
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
subscriptionPromise.then((sub) => {
|
|
102
|
+
if (isActive) {
|
|
103
|
+
currentSubscription = sub;
|
|
104
|
+
} else {
|
|
105
|
+
sub.unsubscribe();
|
|
106
|
+
}
|
|
107
|
+
}).catch((error) => {
|
|
108
|
+
if (isActive) {
|
|
109
|
+
lastResult = {
|
|
110
|
+
...lastResult ?? {},
|
|
111
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
112
|
+
};
|
|
113
|
+
notifyUpdate();
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
return () => {
|
|
117
|
+
isActive = false;
|
|
118
|
+
if (currentSubscription) {
|
|
119
|
+
currentSubscription.unsubscribe();
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
subscribe,
|
|
125
|
+
getSnapShot
|
|
126
|
+
};
|
|
127
|
+
}
|
|
74
128
|
|
|
75
129
|
// src/utils/usePlatformQuery.ts
|
|
76
130
|
function usePlatformQuery({
|
|
@@ -242,15 +296,16 @@ function useLinks(objects, linkName, options = {}) {
|
|
|
242
296
|
}, observer));
|
|
243
297
|
}, [enabled, observableClient, objectsArray, objectsKey, linkName, stableWhere, otherOptions.pageSize, stableOrderBy, otherOptions.mode, otherOptions.dedupeIntervalMs]);
|
|
244
298
|
const payload = React9__default.default.useSyncExternalStore(subscribe, getSnapShot);
|
|
245
|
-
return {
|
|
299
|
+
return React9__default.default.useMemo(() => ({
|
|
246
300
|
links: payload?.resolvedList,
|
|
247
301
|
isLoading: enabled ? payload?.status === "loading" || payload?.status === "init" || !payload : false,
|
|
248
302
|
isOptimistic: payload?.isOptimistic ?? false,
|
|
249
303
|
error: payload?.error,
|
|
250
304
|
fetchMore: payload?.hasMore ? payload?.fetchMore : void 0,
|
|
251
305
|
hasMore: payload?.hasMore ?? false
|
|
252
|
-
};
|
|
306
|
+
}), [payload, enabled]);
|
|
253
307
|
}
|
|
308
|
+
var OBJECT_TYPE_PLACEHOLDER = "$__OBJECT__TYPE__PLACEHOLDER";
|
|
254
309
|
function useObjectSet(baseObjectSet, options = {}) {
|
|
255
310
|
const {
|
|
256
311
|
observableClient
|
|
@@ -260,7 +315,7 @@ function useObjectSet(baseObjectSet, options = {}) {
|
|
|
260
315
|
streamUpdates,
|
|
261
316
|
...otherOptions
|
|
262
317
|
} = options;
|
|
263
|
-
const objectTypeKey = baseObjectSet.$objectSetInternals.def.apiName;
|
|
318
|
+
const objectTypeKey = enabled ? baseObjectSet.$objectSetInternals.def.apiName : OBJECT_TYPE_PLACEHOLDER;
|
|
264
319
|
const previousObjectTypeRef = React9__default.default.useRef(objectTypeKey);
|
|
265
320
|
const previousPayloadRef = React9__default.default.useRef();
|
|
266
321
|
const objectTypeChanged = previousObjectTypeRef.current !== objectTypeKey;
|
|
@@ -311,14 +366,14 @@ function useObjectSet(baseObjectSet, options = {}) {
|
|
|
311
366
|
previousPayloadRef.current = payload;
|
|
312
367
|
}
|
|
313
368
|
}, [payload]);
|
|
314
|
-
return {
|
|
369
|
+
return React9__default.default.useMemo(() => ({
|
|
315
370
|
data: payload?.resolvedList,
|
|
316
371
|
isLoading: payload?.status === "loading" || !payload && true || false,
|
|
317
372
|
error: payload && "error" in payload ? payload.error : void 0,
|
|
318
373
|
fetchMore: payload?.hasMore ? payload.fetchMore : void 0,
|
|
319
374
|
objectSet: payload?.objectSet || baseObjectSet,
|
|
320
375
|
totalCount: payload?.totalCount
|
|
321
|
-
};
|
|
376
|
+
}), [payload, baseObjectSet]);
|
|
322
377
|
}
|
|
323
378
|
function useOsdkAction(actionDef) {
|
|
324
379
|
const {
|
|
@@ -427,7 +482,7 @@ function useOsdkAction(actionDef) {
|
|
|
427
482
|
}
|
|
428
483
|
};
|
|
429
484
|
}, []);
|
|
430
|
-
return {
|
|
485
|
+
return React9__default.default.useMemo(() => ({
|
|
431
486
|
applyAction,
|
|
432
487
|
validateAction,
|
|
433
488
|
error,
|
|
@@ -435,48 +490,74 @@ function useOsdkAction(actionDef) {
|
|
|
435
490
|
isPending,
|
|
436
491
|
isValidating,
|
|
437
492
|
validationResult
|
|
438
|
-
};
|
|
493
|
+
}), [applyAction, validateAction, error, data, isPending, isValidating, validationResult]);
|
|
439
494
|
}
|
|
440
495
|
var EMPTY_WHERE = {};
|
|
441
|
-
function useOsdkAggregation(type, {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
496
|
+
function useOsdkAggregation(type, options) {
|
|
497
|
+
const {
|
|
498
|
+
where = EMPTY_WHERE,
|
|
499
|
+
withProperties,
|
|
500
|
+
intersectWith,
|
|
501
|
+
aggregate,
|
|
502
|
+
dedupeIntervalMs
|
|
503
|
+
} = options;
|
|
504
|
+
const objectSet = "objectSet" in options ? options.objectSet : void 0;
|
|
447
505
|
const {
|
|
448
506
|
observableClient
|
|
449
507
|
} = React9__default.default.useContext(OsdkContext2);
|
|
450
|
-
const canonWhere = observableClient.canonicalizeWhereClause(where
|
|
508
|
+
const canonWhere = observableClient.canonicalizeWhereClause(where);
|
|
451
509
|
const stableCanonWhere = React9__default.default.useMemo(() => canonWhere, [JSON.stringify(canonWhere)]);
|
|
510
|
+
const objectSetRef = React9__default.default.useRef(objectSet);
|
|
511
|
+
objectSetRef.current = objectSet;
|
|
512
|
+
const objectSetKeyString = objectSet ? unstableDoNotUse.computeObjectSetCacheKey(objectSet) : void 0;
|
|
452
513
|
const stableWithProperties = React9__default.default.useMemo(() => withProperties, [JSON.stringify(withProperties)]);
|
|
453
514
|
const stableAggregate = React9__default.default.useMemo(() => aggregate, [JSON.stringify(aggregate)]);
|
|
515
|
+
const stableIntersectWith = React9__default.default.useMemo(() => intersectWith, [JSON.stringify(intersectWith)]);
|
|
454
516
|
const {
|
|
455
517
|
subscribe,
|
|
456
518
|
getSnapShot
|
|
457
|
-
} = React9__default.default.useMemo(() =>
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
519
|
+
} = React9__default.default.useMemo(() => {
|
|
520
|
+
if (objectSetKeyString && objectSetRef.current) {
|
|
521
|
+
return makeExternalStoreAsync((observer) => observableClient.observeAggregation({
|
|
522
|
+
type,
|
|
523
|
+
objectSet: objectSetRef.current,
|
|
524
|
+
where: stableCanonWhere,
|
|
525
|
+
withProperties: stableWithProperties,
|
|
526
|
+
intersectWith: stableIntersectWith,
|
|
527
|
+
aggregate: stableAggregate,
|
|
528
|
+
dedupeInterval: dedupeIntervalMs ?? 2e3
|
|
529
|
+
}, observer), process.env.NODE_ENV !== "production" ? `aggregation ${type.apiName} ${objectSetKeyString} ${JSON.stringify(stableCanonWhere)}` : void 0);
|
|
530
|
+
}
|
|
531
|
+
return makeExternalStore((observer) => (
|
|
532
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
533
|
+
observableClient.observeAggregation({
|
|
534
|
+
type,
|
|
535
|
+
where: stableCanonWhere,
|
|
536
|
+
withProperties: stableWithProperties,
|
|
537
|
+
intersectWith: stableIntersectWith,
|
|
538
|
+
aggregate: stableAggregate,
|
|
539
|
+
dedupeInterval: dedupeIntervalMs ?? 2e3
|
|
540
|
+
}, observer)
|
|
541
|
+
), process.env.NODE_ENV !== "production" ? `aggregation ${type.apiName} ${JSON.stringify(stableCanonWhere)}` : void 0);
|
|
542
|
+
}, [observableClient, type.apiName, type.type, objectSetKeyString, stableCanonWhere, stableWithProperties, stableIntersectWith, stableAggregate, dedupeIntervalMs]);
|
|
464
543
|
const payload = React9__default.default.useSyncExternalStore(subscribe, getSnapShot);
|
|
465
|
-
let error;
|
|
466
|
-
if (payload && "error" in payload && payload.error) {
|
|
467
|
-
error = payload.error;
|
|
468
|
-
} else if (payload?.status === "error") {
|
|
469
|
-
error = new Error("Failed to execute aggregation");
|
|
470
|
-
}
|
|
471
544
|
const refetch = React9__default.default.useCallback(async () => {
|
|
472
545
|
await observableClient.invalidateObjectType(type.apiName);
|
|
473
546
|
}, [observableClient, type.apiName]);
|
|
474
|
-
return {
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
547
|
+
return React9__default.default.useMemo(() => {
|
|
548
|
+
let error;
|
|
549
|
+
if (payload && "error" in payload && payload.error) {
|
|
550
|
+
error = payload.error;
|
|
551
|
+
} else if (payload?.status === "error") {
|
|
552
|
+
error = new Error("Failed to execute aggregation");
|
|
553
|
+
}
|
|
554
|
+
return {
|
|
555
|
+
data: payload?.result,
|
|
556
|
+
isLoading: payload?.status === "loading" || payload?.status === "init" || !payload,
|
|
557
|
+
error,
|
|
558
|
+
refetch
|
|
559
|
+
};
|
|
560
|
+
}, [payload, refetch]);
|
|
480
561
|
}
|
|
481
562
|
function useOsdkFunction(queryDef, options = {}) {
|
|
482
563
|
const {
|
|
@@ -515,17 +596,19 @@ function useOsdkFunction(queryDef, options = {}) {
|
|
|
515
596
|
}, observer), process.env.NODE_ENV !== "production" ? `function ${queryDef.apiName} ${JSON.stringify(stableParams)}` : void 0);
|
|
516
597
|
}, [observableClient, queryDef.apiName, queryDef.version, paramsForApi, stableDependsOn, stableDependsOnObjects, dedupeIntervalMs, enabled]);
|
|
517
598
|
const payload = React9__default.default.useSyncExternalStore(subscribe, getSnapShot);
|
|
518
|
-
const error = payload?.error ?? (payload?.status === "error" ? new Error("Failed to execute function") : void 0);
|
|
519
599
|
const refetch = React9__default.default.useCallback(() => {
|
|
520
600
|
void observableClient.invalidateFunction(queryDef, paramsForApi);
|
|
521
601
|
}, [observableClient, queryDef, paramsForApi]);
|
|
522
|
-
return {
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
602
|
+
return React9__default.default.useMemo(() => {
|
|
603
|
+
const error = payload?.error ?? (payload?.status === "error" ? new Error("Failed to execute function") : void 0);
|
|
604
|
+
return {
|
|
605
|
+
data: payload?.result,
|
|
606
|
+
isLoading: payload?.status === "loading",
|
|
607
|
+
error,
|
|
608
|
+
lastUpdated: payload?.lastUpdated ?? 0,
|
|
609
|
+
refetch
|
|
610
|
+
};
|
|
611
|
+
}, [payload, refetch]);
|
|
529
612
|
}
|
|
530
613
|
function useOsdkObject(...args) {
|
|
531
614
|
const {
|
|
@@ -534,8 +617,9 @@ function useOsdkObject(...args) {
|
|
|
534
617
|
const isInstanceSignature = "$objectType" in args[0];
|
|
535
618
|
const enabled = isInstanceSignature ? typeof args[1] === "boolean" ? args[1] : true : typeof args[2] === "boolean" ? args[2] : true;
|
|
536
619
|
const mode = isInstanceSignature ? "offline" : void 0;
|
|
537
|
-
const
|
|
620
|
+
const typeOrApiName = isInstanceSignature ? args[0].$objectType : args[0];
|
|
538
621
|
const primaryKey = isInstanceSignature ? args[0].$primaryKey : args[1];
|
|
622
|
+
const apiNameString = typeof typeOrApiName === "string" ? typeOrApiName : typeOrApiName.apiName;
|
|
539
623
|
const {
|
|
540
624
|
subscribe,
|
|
541
625
|
getSnapShot
|
|
@@ -546,26 +630,29 @@ function useOsdkObject(...args) {
|
|
|
546
630
|
}
|
|
547
631
|
}));
|
|
548
632
|
}
|
|
549
|
-
return makeExternalStore((observer) => observableClient.observeObject(
|
|
633
|
+
return makeExternalStore((observer) => observableClient.observeObject(typeOrApiName, primaryKey, {
|
|
550
634
|
mode
|
|
551
635
|
}, observer));
|
|
552
|
-
}, [enabled, observableClient,
|
|
636
|
+
}, [enabled, observableClient, typeOrApiName, apiNameString, primaryKey, mode]);
|
|
553
637
|
const payload = React9__default.default.useSyncExternalStore(subscribe, getSnapShot);
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
error
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
isOptimistic: !!payload?.isOptimistic,
|
|
564
|
-
error,
|
|
565
|
-
forceUpdate: () => {
|
|
566
|
-
throw new Error("not implemented");
|
|
638
|
+
const forceUpdate = React9__default.default.useCallback(() => {
|
|
639
|
+
throw new Error("not implemented");
|
|
640
|
+
}, []);
|
|
641
|
+
return React9__default.default.useMemo(() => {
|
|
642
|
+
let error;
|
|
643
|
+
if (payload && "error" in payload && payload.error) {
|
|
644
|
+
error = payload.error;
|
|
645
|
+
} else if (payload?.status === "error") {
|
|
646
|
+
error = new Error("Failed to load object");
|
|
567
647
|
}
|
|
568
|
-
|
|
648
|
+
return {
|
|
649
|
+
object: payload?.object,
|
|
650
|
+
isLoading: enabled ? payload?.status === "loading" || payload?.status === "init" || !payload : false,
|
|
651
|
+
isOptimistic: !!payload?.isOptimistic,
|
|
652
|
+
error,
|
|
653
|
+
forceUpdate
|
|
654
|
+
};
|
|
655
|
+
}, [payload, enabled, forceUpdate]);
|
|
569
656
|
}
|
|
570
657
|
var EMPTY_WHERE2 = {};
|
|
571
658
|
function useOsdkObjects(type, options) {
|
|
@@ -620,20 +707,22 @@ function useOsdkObjects(type, options) {
|
|
|
620
707
|
}, observer), process.env.NODE_ENV !== "production" ? `list ${type.apiName} ${stableRids ? `[${stableRids.length} rids]` : ""} ${JSON.stringify(stableCanonWhere)}` : void 0);
|
|
621
708
|
}, [enabled, observableClient, type.apiName, type.type, stableRids, stableCanonWhere, dedupeIntervalMs, pageSize, stableOrderBy, streamUpdates, stableWithProperties, autoFetchMore, stableIntersectWith, pivotTo]);
|
|
622
709
|
const listPayload = React9__default.default.useSyncExternalStore(subscribe, getSnapShot);
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
error
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
710
|
+
return React9__default.default.useMemo(() => {
|
|
711
|
+
let error;
|
|
712
|
+
if (listPayload && "error" in listPayload && listPayload.error) {
|
|
713
|
+
error = listPayload.error;
|
|
714
|
+
} else if (listPayload?.status === "error") {
|
|
715
|
+
error = new Error("Failed to load objects");
|
|
716
|
+
}
|
|
717
|
+
return {
|
|
718
|
+
fetchMore: listPayload?.hasMore ? listPayload.fetchMore : void 0,
|
|
719
|
+
error,
|
|
720
|
+
data: listPayload?.resolvedList,
|
|
721
|
+
isLoading: enabled ? listPayload?.status === "loading" || listPayload?.status === "init" || !listPayload : false,
|
|
722
|
+
isOptimistic: listPayload?.isOptimistic ?? false,
|
|
723
|
+
totalCount: listPayload?.totalCount
|
|
724
|
+
};
|
|
725
|
+
}, [listPayload, enabled]);
|
|
637
726
|
}
|
|
638
727
|
function useDebouncedCallback(callback, delay) {
|
|
639
728
|
const timeoutRef = React9__default.default.useRef();
|