api-core-lib 16.12.133 → 16.12.135
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/dist/client.cjs +34 -25
- package/dist/client.js +20 -11
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -352,6 +352,7 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
|
|
|
352
352
|
const lastCallRef = _react.useRef.call(void 0, {});
|
|
353
353
|
const initialFetchRef = _react.useRef.call(void 0, false);
|
|
354
354
|
const stableActionsRef = _react.useRef.call(void 0, {});
|
|
355
|
+
const isSyncingFromUrlRef = _react.useRef.call(void 0, false);
|
|
355
356
|
const savedCallbacks = _react.useRef.call(void 0, { onSuccess, onError });
|
|
356
357
|
_react.useEffect.call(void 0, () => {
|
|
357
358
|
savedCallbacks.current = { onSuccess, onError };
|
|
@@ -378,20 +379,31 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
|
|
|
378
379
|
}
|
|
379
380
|
});
|
|
380
381
|
if (Object.keys(queryFromUrl).length > 0) {
|
|
382
|
+
isSyncingFromUrlRef.current = true;
|
|
381
383
|
setQueryOptions((prev) => {
|
|
382
384
|
const newState = { ...prev };
|
|
385
|
+
let hasChanged = false;
|
|
383
386
|
for (const actionName in queryFromUrl) {
|
|
384
|
-
|
|
387
|
+
const newOpts = { ...newState[actionName], ...queryFromUrl[actionName] };
|
|
388
|
+
if (JSON.stringify(newState[actionName]) !== JSON.stringify(newOpts)) {
|
|
389
|
+
newState[actionName] = newOpts;
|
|
390
|
+
hasChanged = true;
|
|
391
|
+
}
|
|
385
392
|
}
|
|
386
|
-
return newState;
|
|
393
|
+
return hasChanged ? newState : prev;
|
|
387
394
|
});
|
|
388
395
|
}
|
|
389
|
-
}, [urlSync]);
|
|
396
|
+
}, [_optionalChain([urlSync, 'optionalAccess', _6 => _6.searchParams]), _optionalChain([urlSync, 'optionalAccess', _7 => _7.actionsToSync]), _optionalChain([urlSync, 'optionalAccess', _8 => _8.defaultSyncAction])]);
|
|
390
397
|
_react.useEffect.call(void 0, () => {
|
|
391
398
|
if (!urlSync) return;
|
|
399
|
+
if (isSyncingFromUrlRef.current) {
|
|
400
|
+
isSyncingFromUrlRef.current = false;
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
392
403
|
const { searchParams, updateUrl, actionsToSync, defaultSyncAction } = urlSync;
|
|
393
404
|
const currentParams = new URLSearchParams(searchParams);
|
|
394
405
|
let hasChanged = false;
|
|
406
|
+
const newParams = new URLSearchParams();
|
|
395
407
|
for (const actionName in queryOptions) {
|
|
396
408
|
if (actionsToSync.some((a) => a === actionName)) {
|
|
397
409
|
const params = queryOptions[actionName];
|
|
@@ -399,19 +411,16 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
|
|
|
399
411
|
for (const key in params) {
|
|
400
412
|
const fullKey = isDefaultAction ? key : `${actionName}.${key}`;
|
|
401
413
|
const value = params[key];
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
if (stringValue) currentParams.set(fullKey, stringValue);
|
|
405
|
-
else currentParams.delete(fullKey);
|
|
406
|
-
hasChanged = true;
|
|
414
|
+
if (value !== void 0 && value !== null && value !== "") {
|
|
415
|
+
newParams.set(fullKey, String(value));
|
|
407
416
|
}
|
|
408
417
|
}
|
|
409
418
|
}
|
|
410
419
|
}
|
|
411
|
-
if (
|
|
412
|
-
updateUrl(
|
|
420
|
+
if (newParams.toString() !== currentParams.toString()) {
|
|
421
|
+
updateUrl(newParams.toString());
|
|
413
422
|
}
|
|
414
|
-
}, [queryOptions, urlSync]);
|
|
423
|
+
}, [queryOptions, _optionalChain([urlSync, 'optionalAccess', _9 => _9.updateUrl]), _optionalChain([urlSync, 'optionalAccess', _10 => _10.actionsToSync]), _optionalChain([urlSync, 'optionalAccess', _11 => _11.defaultSyncAction])]);
|
|
415
424
|
_react.useMemo.call(void 0, () => {
|
|
416
425
|
for (const actionName in moduleConfig.actions) {
|
|
417
426
|
const actionConfig = moduleConfig.actions[actionName];
|
|
@@ -423,7 +432,7 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
|
|
|
423
432
|
let requestConfig = options2.config || {};
|
|
424
433
|
if (actionConfig.method === "GET") {
|
|
425
434
|
const currentQueryOptions = queryOptions[actionName];
|
|
426
|
-
bodyForCall = { ...actionConfig._input, ...currentQueryOptions, ..._optionalChain([options2, 'access',
|
|
435
|
+
bodyForCall = { ...actionConfig._input, ...currentQueryOptions, ..._optionalChain([options2, 'access', _12 => _12.config, 'optionalAccess', _13 => _13.params]), ...input };
|
|
427
436
|
} else if (actionConfig.upload && input) {
|
|
428
437
|
bodyForCall = new FormData();
|
|
429
438
|
for (const key in input) {
|
|
@@ -460,24 +469,24 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
|
|
|
460
469
|
}));
|
|
461
470
|
}
|
|
462
471
|
if (result.success) {
|
|
463
|
-
_optionalChain([savedCallbacks, 'access',
|
|
464
|
-
_optionalChain([options2, 'access',
|
|
465
|
-
_optionalChain([actionConfig, 'access',
|
|
472
|
+
_optionalChain([savedCallbacks, 'access', _14 => _14.current, 'access', _15 => _15.onSuccess, 'optionalCall', _16 => _16(actionName, result.message || "Action successful", result.data)]);
|
|
473
|
+
_optionalChain([options2, 'access', _17 => _17.onSuccess, 'optionalCall', _18 => _18(result.data, mutationContext)]);
|
|
474
|
+
_optionalChain([actionConfig, 'access', _19 => _19.invalidates, 'optionalAccess', _20 => _20.forEach, 'call', _21 => _21((keyToInvalidate) => {
|
|
466
475
|
const prefix = `${moduleConfig.baseEndpoint}/${keyToInvalidate}::`;
|
|
467
476
|
_chunkJAMEOM7Tcjs.globalStateManager.invalidateByPrefix(prefix);
|
|
468
477
|
})]);
|
|
469
478
|
} else {
|
|
470
|
-
_optionalChain([savedCallbacks, 'access',
|
|
471
|
-
_optionalChain([options2, 'access',
|
|
479
|
+
_optionalChain([savedCallbacks, 'access', _22 => _22.current, 'access', _23 => _23.onError, 'optionalCall', _24 => _24(actionName, result.message || "Action failed", _nullishCoalesce(result.error, () => ( void 0)))]);
|
|
480
|
+
_optionalChain([options2, 'access', _25 => _25.onError, 'optionalCall', _26 => _26(result.error, mutationContext)]);
|
|
472
481
|
}
|
|
473
482
|
return result;
|
|
474
483
|
} catch (error) {
|
|
475
|
-
const apiError = _optionalChain([error, 'access',
|
|
484
|
+
const apiError = _optionalChain([error, 'access', _27 => _27.response, 'optionalAccess', _28 => _28.data]) || { status: 500, message: error.message };
|
|
476
485
|
if (shouldCache) {
|
|
477
486
|
_chunkJAMEOM7Tcjs.globalStateManager.setState(cacheKey, (prev) => ({ ...prev, error: apiError, loading: false, success: false }));
|
|
478
487
|
}
|
|
479
|
-
_optionalChain([savedCallbacks, 'access',
|
|
480
|
-
_optionalChain([options2, 'access',
|
|
488
|
+
_optionalChain([savedCallbacks, 'access', _29 => _29.current, 'access', _30 => _30.onError, 'optionalCall', _31 => _31(actionName, apiError.message, apiError)]);
|
|
489
|
+
_optionalChain([options2, 'access', _32 => _32.onError, 'optionalCall', _33 => _33(apiError, mutationContext)]);
|
|
481
490
|
throw error;
|
|
482
491
|
} finally {
|
|
483
492
|
if (options2.onSettled) {
|
|
@@ -504,11 +513,11 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
|
|
|
504
513
|
actionsToRun.forEach((actionName) => {
|
|
505
514
|
const key = actionName;
|
|
506
515
|
const hydratedData = hydratedState ? JSON.parse(hydratedState) : {};
|
|
507
|
-
if (_optionalChain([hydratedData, 'access',
|
|
516
|
+
if (_optionalChain([hydratedData, 'access', _34 => _34[actionName], 'optionalAccess', _35 => _35.data])) {
|
|
508
517
|
return;
|
|
509
518
|
}
|
|
510
519
|
const actionConfig = moduleConfig.actions[key];
|
|
511
|
-
const executeAction = _optionalChain([actions, 'access',
|
|
520
|
+
const executeAction = _optionalChain([actions, 'access', _36 => _36[key], 'optionalAccess', _37 => _37.execute]);
|
|
512
521
|
if (typeof executeAction === "function") {
|
|
513
522
|
const input = actionConfig.hasQuery ? queryOptions[actionName] : void 0;
|
|
514
523
|
executeAction(input);
|
|
@@ -519,7 +528,7 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
|
|
|
519
528
|
const queries = _react.useMemo.call(void 0, () => {
|
|
520
529
|
return Object.keys(moduleConfig.actions).reduce((acc, actionName) => {
|
|
521
530
|
const actionConfig = moduleConfig.actions[actionName];
|
|
522
|
-
if (_optionalChain([actionConfig, 'optionalAccess',
|
|
531
|
+
if (_optionalChain([actionConfig, 'optionalAccess', _38 => _38.hasQuery])) {
|
|
523
532
|
const setActionQueryOptions = (updater) => {
|
|
524
533
|
const key = actionName;
|
|
525
534
|
setQueryOptions((prev) => ({ ...prev, [key]: typeof updater === "function" ? updater(prev[key] || {}) : updater }));
|
|
@@ -546,7 +555,7 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
|
|
|
546
555
|
}, [actions, queryOptions, moduleConfig.actions]);
|
|
547
556
|
const states = {};
|
|
548
557
|
function isActionWithQuery(key, actions2) {
|
|
549
|
-
return _optionalChain([actions2, 'access',
|
|
558
|
+
return _optionalChain([actions2, 'access', _39 => _39[key], 'optionalAccess', _40 => _40.hasQuery]) === true;
|
|
550
559
|
}
|
|
551
560
|
for (const actionName in moduleConfig.actions) {
|
|
552
561
|
if (Object.prototype.hasOwnProperty.call(moduleConfig.actions, actionName)) {
|
|
@@ -555,7 +564,7 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
|
|
|
555
564
|
if (actionConfig.cacheResponse !== false) {
|
|
556
565
|
let currentQueryOptions;
|
|
557
566
|
if (isActionWithQuery(key, moduleConfig.actions)) {
|
|
558
|
-
currentQueryOptions = _optionalChain([queries, 'access',
|
|
567
|
+
currentQueryOptions = _optionalChain([queries, 'access', _41 => _41[key], 'optionalAccess', _42 => _42.options]);
|
|
559
568
|
}
|
|
560
569
|
const input = currentQueryOptions;
|
|
561
570
|
const pathParams = JSON.parse(pathParamsString);
|
package/dist/client.js
CHANGED
|
@@ -352,6 +352,7 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
|
|
|
352
352
|
const lastCallRef = useRef4({});
|
|
353
353
|
const initialFetchRef = useRef4(false);
|
|
354
354
|
const stableActionsRef = useRef4({});
|
|
355
|
+
const isSyncingFromUrlRef = useRef4(false);
|
|
355
356
|
const savedCallbacks = useRef4({ onSuccess, onError });
|
|
356
357
|
useEffect4(() => {
|
|
357
358
|
savedCallbacks.current = { onSuccess, onError };
|
|
@@ -378,20 +379,31 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
|
|
|
378
379
|
}
|
|
379
380
|
});
|
|
380
381
|
if (Object.keys(queryFromUrl).length > 0) {
|
|
382
|
+
isSyncingFromUrlRef.current = true;
|
|
381
383
|
setQueryOptions((prev) => {
|
|
382
384
|
const newState = { ...prev };
|
|
385
|
+
let hasChanged = false;
|
|
383
386
|
for (const actionName in queryFromUrl) {
|
|
384
|
-
|
|
387
|
+
const newOpts = { ...newState[actionName], ...queryFromUrl[actionName] };
|
|
388
|
+
if (JSON.stringify(newState[actionName]) !== JSON.stringify(newOpts)) {
|
|
389
|
+
newState[actionName] = newOpts;
|
|
390
|
+
hasChanged = true;
|
|
391
|
+
}
|
|
385
392
|
}
|
|
386
|
-
return newState;
|
|
393
|
+
return hasChanged ? newState : prev;
|
|
387
394
|
});
|
|
388
395
|
}
|
|
389
|
-
}, [urlSync]);
|
|
396
|
+
}, [urlSync?.searchParams, urlSync?.actionsToSync, urlSync?.defaultSyncAction]);
|
|
390
397
|
useEffect4(() => {
|
|
391
398
|
if (!urlSync) return;
|
|
399
|
+
if (isSyncingFromUrlRef.current) {
|
|
400
|
+
isSyncingFromUrlRef.current = false;
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
392
403
|
const { searchParams, updateUrl, actionsToSync, defaultSyncAction } = urlSync;
|
|
393
404
|
const currentParams = new URLSearchParams(searchParams);
|
|
394
405
|
let hasChanged = false;
|
|
406
|
+
const newParams = new URLSearchParams();
|
|
395
407
|
for (const actionName in queryOptions) {
|
|
396
408
|
if (actionsToSync.some((a) => a === actionName)) {
|
|
397
409
|
const params = queryOptions[actionName];
|
|
@@ -399,19 +411,16 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
|
|
|
399
411
|
for (const key in params) {
|
|
400
412
|
const fullKey = isDefaultAction ? key : `${actionName}.${key}`;
|
|
401
413
|
const value = params[key];
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
if (stringValue) currentParams.set(fullKey, stringValue);
|
|
405
|
-
else currentParams.delete(fullKey);
|
|
406
|
-
hasChanged = true;
|
|
414
|
+
if (value !== void 0 && value !== null && value !== "") {
|
|
415
|
+
newParams.set(fullKey, String(value));
|
|
407
416
|
}
|
|
408
417
|
}
|
|
409
418
|
}
|
|
410
419
|
}
|
|
411
|
-
if (
|
|
412
|
-
updateUrl(
|
|
420
|
+
if (newParams.toString() !== currentParams.toString()) {
|
|
421
|
+
updateUrl(newParams.toString());
|
|
413
422
|
}
|
|
414
|
-
}, [queryOptions, urlSync]);
|
|
423
|
+
}, [queryOptions, urlSync?.updateUrl, urlSync?.actionsToSync, urlSync?.defaultSyncAction]);
|
|
415
424
|
useMemo3(() => {
|
|
416
425
|
for (const actionName in moduleConfig.actions) {
|
|
417
426
|
const actionConfig = moduleConfig.actions[actionName];
|