@panneau/data 4.0.73 → 4.0.74

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +312 -113
  2. package/dist/index.js +508 -382
  3. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -9,6 +9,7 @@ import { useQuery, keepPreviousData, useMutation, QueryClient, QueryClientProvid
9
9
  import isArray from 'lodash-es/isArray';
10
10
  import isObject from 'lodash-es/isObject';
11
11
  import isString from 'lodash-es/isString';
12
+ import { isObject as isObject$1, isString as isString$1 } from 'lodash-es';
12
13
 
13
14
  function useItem(scope, id, loader, t0) {
14
15
  const $ = c(15);
@@ -447,176 +448,50 @@ function useItems(scope, t0) {
447
448
  return t32;
448
449
  }
449
450
 
450
- class AccountApi {
451
- constructor(api, opts) {
452
- this.api = api;
453
- this.options = {
454
- withCredentials: false,
455
- ...opts
456
- };
457
- }
458
- update(data) {
459
- const {
460
- withCredentials
461
- } = this.options;
462
- return this.api.requestPost(this.api.route('account'), data, {
463
- withSession: !withCredentials,
464
- withCredentials
465
- });
466
- }
467
- updatePassword(data) {
468
- const {
469
- withCredentials
470
- } = this.options;
471
- return this.api.requestPost(this.api.route('account.password'), data, {
472
- withSession: !withCredentials,
473
- withCredentials
474
- });
475
- }
476
- updateTaxes(data) {
477
- const {
478
- withCredentials
479
- } = this.options;
480
- return this.api.requestPost(this.api.route('account.taxes'), data, {
481
- withSession: !withCredentials,
482
- withCredentials
483
- });
484
- }
485
- delete(data) {
486
- const {
487
- withCredentials
488
- } = this.options;
489
- return this.api.requestPost(this.api.route('account.delete'), data, {
490
- withSession: !withCredentials,
491
- withCredentials
492
- });
493
- }
494
- }
495
-
496
- class AuthApi {
497
- constructor(api, opts) {
498
- this.api = api;
499
- this.options = {
500
- withCredentials: true,
501
- ...opts
502
- };
503
- }
504
- check() {
505
- const {
506
- withCredentials
507
- } = this.options;
508
- return this.api.requestGet(this.api.route('auth.check'), null, {
509
- withSession: !withCredentials,
510
- withCredentials
511
- });
512
- }
513
- login(email, password) {
514
- const {
515
- withCredentials
516
- } = this.options;
517
- return this.api.requestPost(this.api.route('auth.login'), {
518
- email,
519
- password
520
- }, {
521
- withSession: !withCredentials,
522
- withCredentials
523
- });
524
- }
525
- register(data) {
526
- const {
527
- withCredentials
528
- } = this.options;
529
- return this.api.requestPost(this.api.route('auth.register'), data, {
530
- withSession: !withCredentials,
531
- withCredentials
532
- });
533
- }
534
- logout() {
535
- const url = this.api.getFullUrl(this.api.route('auth.logout'));
536
- return fetch(url, {
537
- method: 'POST',
538
- headers: {
539
- ...getCSRFHeaders()
540
- },
541
- credentials: 'include'
542
- }).catch(err => {
543
- console.log('logout err', err); // eslint-disable-line
544
- throw err;
545
- });
546
- }
547
- requestPassword(email) {
548
- const {
549
- withCredentials
550
- } = this.options;
551
- return this.api.requestPost(this.api.route('auth.password.email'), {
552
- email
553
- }, {
554
- withSession: !withCredentials,
555
- withCredentials
556
- });
557
- }
558
- resetPassword(data) {
559
- const {
560
- withCredentials
561
- } = this.options;
562
- return this.api.requestPost(this.api.route('auth.password.update'), data, {
563
- withSession: !withCredentials,
564
- withCredentials
565
- });
566
- }
567
- }
568
-
569
451
  class Base {
570
- constructor(opts = {}) {
452
+ constructor(opts) {
571
453
  this.options = {
572
454
  routes: {},
573
455
  generateUrl: null,
574
- ...opts,
575
- baseUrl: opts.baseUrl,
576
- onUnauthorized: opts.onUnauthorized || null
456
+ ...opts
577
457
  };
578
458
  }
579
459
  requestGet(path, query = null, opts = null) {
580
- const finalQuery = query !== null ? queryString.stringify(query, {
581
- arrayFormat: 'bracket'
582
- }) : null;
583
- return getJSON(`${this.getFullUrl(path)}${finalQuery !== null && finalQuery.length > 0 ? `?${finalQuery}` : ''}`, {
460
+ return getJSON(this.getFullUrl(path, query), {
584
461
  credentials: 'include',
585
462
  headers: getCSRFHeaders(),
586
463
  ...opts
587
- }).catch(error => this.onError(error));
464
+ }).catch(error => {
465
+ this.onError(error);
466
+ return null;
467
+ });
588
468
  }
589
- requestPost(path, data, opts = null) {
469
+ requestPost(path, data = null, opts = null) {
590
470
  return postJSON(this.getFullUrl(path), data, {
591
471
  credentials: 'include',
592
472
  headers: getCSRFHeaders(),
593
473
  ...opts
594
- }).catch(error => this.onError(error));
474
+ }).catch(error => {
475
+ this.onError(error);
476
+ return null;
477
+ });
595
478
  }
596
479
  requestPut(path, data, opts = null) {
597
- return postJSON(this.getFullUrl(path), {
480
+ return this.requestPost(path, {
598
481
  _method: 'PUT',
599
482
  ...data
600
- }, {
601
- credentials: 'include',
602
- headers: getCSRFHeaders(),
603
- ...opts
604
- }).catch(error => this.onError(error));
483
+ }, opts);
605
484
  }
606
485
  requestPatch(path, data, opts = null) {
607
- return postJSON(this.getFullUrl(path), {
486
+ return this.requestPost(path, {
608
487
  _method: 'PATCH',
609
488
  ...data
610
- }, {
611
- credentials: 'include',
612
- headers: getCSRFHeaders(),
613
- ...opts
614
- }).catch(error => this.onError(error));
489
+ }, opts);
615
490
  }
616
- requestDelete(path) {
617
- return this.requestPost(this.getFullUrl(path), {
491
+ requestDelete(path, opts = null) {
492
+ return this.requestPost(path, {
618
493
  _method: 'DELETE'
619
- }).catch(error => this.onError(error));
494
+ }, opts);
620
495
  }
621
496
  hasRoute(route) {
622
497
  const {
@@ -624,7 +499,7 @@ class Base {
624
499
  } = this.options;
625
500
  return typeof routes[route] !== 'undefined';
626
501
  }
627
- route(route, params) {
502
+ route(route, params = null) {
628
503
  const {
629
504
  routes,
630
505
  generateUrl = null
@@ -632,14 +507,18 @@ class Base {
632
507
  if (generateUrl !== null) {
633
508
  return generateUrl(route, params);
634
509
  }
635
- return generatePath(routes[route] || route, params);
510
+ return generatePath(routes?.[route] || route, params);
636
511
  }
637
- getFullUrl(path) {
512
+ getFullUrl(path, query = null) {
638
513
  const {
639
514
  baseUrl = null
640
515
  } = this.options;
641
516
  const hasProtocol = path.indexOf('://') !== -1;
642
- return baseUrl !== null && !hasProtocol ? `${baseUrl.replace(/\/$/, '')}/${path.replace(/^\//, '')}` : path;
517
+ const url = baseUrl !== null && !hasProtocol ? `${baseUrl.replace(/\/$/, '')}/${path.replace(/^\//, '')}` : path;
518
+ const finalQuery = query !== null ? queryString.stringify(query, {
519
+ arrayFormat: 'bracket'
520
+ }) : null;
521
+ return `${url}${finalQuery !== null && finalQuery.length > 0 ? `${url.indexOf('?') === -1 ? '?' : '&'}${finalQuery}` : ''}`;
643
522
  }
644
523
  onError(err) {
645
524
  const {
@@ -651,16 +530,79 @@ class Base {
651
530
  const statusCode = parseInt(status, 10);
652
531
  // If status is refused and callback exists
653
532
  if ((statusCode === 401 || statusCode === 419) && onUnauthorized !== null) {
654
- return onUnauthorized();
533
+ onUnauthorized();
655
534
  }
656
535
  throw err;
657
536
  }
658
537
  }
659
538
 
539
+ class AccountApi extends Base {
540
+ constructor(opts) {
541
+ super({
542
+ ...opts,
543
+ routes: {
544
+ account: 'account',
545
+ 'account.password': 'account/password',
546
+ 'account.delete': 'account/delete',
547
+ ...(opts?.routes || null)
548
+ }
549
+ });
550
+ }
551
+ update(data) {
552
+ return this.requestPost(this.route('account'), data);
553
+ }
554
+ updatePassword(data) {
555
+ return this.requestPost(this.route('account.password'), data);
556
+ }
557
+ delete(data) {
558
+ return this.requestPost(this.route('account.delete'), data);
559
+ }
560
+ }
561
+
562
+ class AuthApi extends Base {
563
+ constructor(opts) {
564
+ super({
565
+ ...opts,
566
+ routes: {
567
+ 'auth.check': 'auth/check',
568
+ 'auth.login': 'auth/login',
569
+ 'auth.register': 'auth/register',
570
+ 'auth.logout': 'auth/logout',
571
+ 'auth.password.email': 'auth/password/email',
572
+ 'auth.password.update': 'auth/password/update',
573
+ ...(opts?.routes || null)
574
+ }
575
+ });
576
+ }
577
+ check() {
578
+ return this.requestGet(this.route('auth.check'));
579
+ }
580
+ login(email, password) {
581
+ return this.requestPost(this.route('auth.login'), {
582
+ email,
583
+ password
584
+ });
585
+ }
586
+ register(data) {
587
+ return this.requestPost(this.route('auth.register'), data);
588
+ }
589
+ logout() {
590
+ return this.requestPost(this.route('auth.logout'));
591
+ }
592
+ requestPassword(email) {
593
+ return this.requestPost(this.route('auth.password.email'), {
594
+ email
595
+ });
596
+ }
597
+ resetPassword(data) {
598
+ return this.requestPost(this.route('auth.password.update'), data);
599
+ }
600
+ }
601
+
660
602
  class MediasApi extends Base {
661
- constructor(opts = {}) {
603
+ constructor(opts) {
662
604
  super({
663
- baseUrl: opts.baseUrl ? opts.baseUrl : null,
605
+ ...opts,
664
606
  routes: {
665
607
  index: 'medias',
666
608
  trashed: 'medias/trash',
@@ -672,7 +614,7 @@ class MediasApi extends Base {
672
614
  restore: 'medias/restore/:media',
673
615
  destroy: 'medias/:media',
674
616
  replace: 'medias/replace/:media',
675
- ...(opts.routes || null)
617
+ ...(opts?.routes || null)
676
618
  }
677
619
  });
678
620
  }
@@ -738,29 +680,28 @@ class MediasApi extends Base {
738
680
  }
739
681
  }
740
682
 
741
- class ResourcesApi {
742
- constructor(api) {
743
- this.api = api;
744
- }
745
- resourceRoute({
746
- id,
747
- has_routes: hasRoutes = false
748
- }, route, params) {
749
- const hasSpecificRoute = this.api.hasRoute(`resources.${id}.${route}`);
750
- const routeName = hasSpecificRoute ? `resources.${id}.${route}` : `resources.${route}`;
751
- return this.api.route(routeName, hasSpecificRoute ? params : {
752
- resource: id,
753
- ...params
683
+ class ResourcesApi extends Base {
684
+ constructor(opts) {
685
+ super({
686
+ ...opts,
687
+ routes: {
688
+ 'resources.index': '/:resource',
689
+ 'resources.show': '/:resource/:id',
690
+ 'resources.store': '/:resource',
691
+ 'resources.update': '/:resource/:id',
692
+ 'resources.destroy': '/:resource/:id',
693
+ 'resources.clone': '/:resource/:id/clone',
694
+ 'resources.restore': '/:resource/:id/restore',
695
+ ...(opts?.routes || null)
696
+ }
754
697
  });
755
698
  }
756
- find(resource, id) {
757
- return this.api.requestGet(this.resourceRoute(resource, 'show', {
699
+ find(resource, id, opts = null) {
700
+ return this.requestGet(this.resourceRoute(resource, 'show', {
758
701
  id
759
- }), null, {
760
- withCredentials: true
761
- });
702
+ }), null, opts);
762
703
  }
763
- get(resource, query = {}, page = 1, count = 12) {
704
+ get(resource, query, page = 1, count = 12, opts = null) {
764
705
  const finalQuery = {
765
706
  ...query
766
707
  };
@@ -770,56 +711,48 @@ class ResourcesApi {
770
711
  if (count !== null) {
771
712
  finalQuery.count = count;
772
713
  }
773
- return this.api.requestGet(this.resourceRoute(resource, 'index'), finalQuery, {
774
- withCredentials: true
775
- });
714
+ return this.requestGet(this.resourceRoute(resource, 'index'), finalQuery, opts);
776
715
  }
777
- store(resource, data) {
778
- return this.api.requestPost(this.resourceRoute(resource, 'store'), data, {
779
- withCredentials: true
780
- });
716
+ store(resource, data, opts = null) {
717
+ return this.requestPost(this.resourceRoute(resource, 'store'), data, opts);
781
718
  }
782
- update(resource, id, data) {
783
- return this.api.requestPatch(this.resourceRoute(resource, 'update', {
719
+ update(resource, id, data, opts = null) {
720
+ return this.requestPatch(this.resourceRoute(resource, 'update', {
784
721
  id
785
- }), data, {
786
- withCredentials: true
787
- });
722
+ }), data, opts);
788
723
  }
789
- destroy(resource, id) {
790
- return this.api.requestDelete(this.resourceRoute(resource, 'destroy', {
724
+ destroy(resource, id, opts = null) {
725
+ return this.requestDelete(this.resourceRoute(resource, 'destroy', {
791
726
  id
792
- }), null, {
793
- withCredentials: true
794
- });
727
+ }), opts);
795
728
  }
796
- clone(resource, id, data = null) {
797
- return this.api.requestPost(this.resourceRoute(resource, 'clone', {
729
+ clone(resource, id, data = null, opts = null) {
730
+ return this.requestPost(this.resourceRoute(resource, 'clone', {
798
731
  id
799
- }), data, {
800
- withCredentials: true
801
- });
732
+ }), data, opts);
802
733
  }
803
- restore(resource, id, data = null) {
804
- return this.api.requestPost(this.resourceRoute(resource, 'restore', {
734
+ restore(resource, id, data = null, opts = null) {
735
+ return this.requestPost(this.resourceRoute(resource, 'restore', {
805
736
  id
806
- }), data, {
807
- withCredentials: true
737
+ }), data, opts);
738
+ }
739
+ resourceRoute({
740
+ id
741
+ }, route, params = null) {
742
+ return this.route(`resources.${id}.${route}`, params) ?? this.route(`resources.${route}`, {
743
+ resource: id,
744
+ ...params
808
745
  });
809
746
  }
810
747
  }
811
748
 
812
749
  class Api extends Base {
813
- constructor(opts = {}) {
750
+ constructor(opts) {
814
751
  super(opts);
815
- this.auth = new AuthApi(this, {
816
- withCredentials: true
817
- });
818
- this.account = new AccountApi(this, {
819
- withCredentials: true
820
- });
752
+ this.auth = new AuthApi(opts);
753
+ this.account = new AccountApi(opts);
821
754
  this.medias = new MediasApi(opts);
822
- this.resources = new ResourcesApi(this);
755
+ this.resources = new ResourcesApi(opts);
823
756
  }
824
757
  }
825
758
 
@@ -828,51 +761,54 @@ function useApi() {
828
761
  return use(ApiContext);
829
762
  }
830
763
  function ApiProvider(t0) {
831
- const $ = c(10);
764
+ const $ = c(11);
832
765
  const {
833
766
  api: t1,
834
767
  baseUrl: t2,
835
768
  onUnauthorized: t3,
769
+ routes: t4,
836
770
  children
837
771
  } = t0;
838
772
  const initialApi = t1 === undefined ? null : t1;
839
773
  const baseUrl = t2 === undefined ? undefined : t2;
840
774
  const onUnauthorized = t3 === undefined ? null : t3;
775
+ const apiRoutes = t4 === undefined ? undefined : t4;
841
776
  const generateUrl = useUrlGenerator();
842
777
  const previousApi = useApi();
843
- const routes = useRoutes();
844
- let t4;
845
- if ($[0] !== baseUrl || $[1] !== generateUrl || $[2] !== initialApi || $[3] !== onUnauthorized || $[4] !== previousApi || $[5] !== routes) {
846
- t4 = initialApi || previousApi || new Api({
778
+ const contextRoutes = useRoutes();
779
+ let t5;
780
+ if ($[0] !== apiRoutes || $[1] !== baseUrl || $[2] !== contextRoutes || $[3] !== generateUrl || $[4] !== initialApi || $[5] !== onUnauthorized || $[6] !== previousApi) {
781
+ t5 = initialApi || previousApi || new Api({
847
782
  baseUrl,
848
783
  generateUrl,
849
- routes,
784
+ routes: apiRoutes || contextRoutes,
850
785
  onUnauthorized
851
786
  });
852
- $[0] = baseUrl;
853
- $[1] = generateUrl;
854
- $[2] = initialApi;
855
- $[3] = onUnauthorized;
856
- $[4] = previousApi;
857
- $[5] = routes;
858
- $[6] = t4;
787
+ $[0] = apiRoutes;
788
+ $[1] = baseUrl;
789
+ $[2] = contextRoutes;
790
+ $[3] = generateUrl;
791
+ $[4] = initialApi;
792
+ $[5] = onUnauthorized;
793
+ $[6] = previousApi;
794
+ $[7] = t5;
859
795
  } else {
860
- t4 = $[6];
796
+ t5 = $[7];
861
797
  }
862
- const api = t4;
863
- let t5;
864
- if ($[7] !== api || $[8] !== children) {
865
- t5 = /*#__PURE__*/jsx(ApiContext, {
798
+ const api = t5;
799
+ let t6;
800
+ if ($[8] !== api || $[9] !== children) {
801
+ t6 = /*#__PURE__*/jsx(ApiContext, {
866
802
  value: api,
867
803
  children: children
868
804
  });
869
- $[7] = api;
870
- $[8] = children;
871
- $[9] = t5;
805
+ $[8] = api;
806
+ $[9] = children;
807
+ $[10] = t6;
872
808
  } else {
873
- t5 = $[9];
809
+ t6 = $[10];
874
810
  }
875
- return t5;
811
+ return t6;
876
812
  }
877
813
 
878
814
  function useResourceDestroy(t0, t1, t2) {
@@ -895,7 +831,10 @@ function useResourceDestroy(t0, t1, t2) {
895
831
  const api = useApi();
896
832
  let t4;
897
833
  if ($[2] !== api || $[3] !== finalId || $[4] !== finalResource) {
898
- t4 = providedId => api.resources.destroy(finalResource, providedId || finalId);
834
+ t4 = t5 => {
835
+ const providedId = t5 === undefined ? null : t5;
836
+ return api.resources.destroy(finalResource, providedId ?? finalId);
837
+ };
899
838
  $[2] = api;
900
839
  $[3] = finalId;
901
840
  $[4] = finalResource;
@@ -1099,161 +1038,344 @@ function useResourceItems(t0, t1, t2, t3, t4) {
1099
1038
  return useItems(resourceId, t8);
1100
1039
  }
1101
1040
 
1102
- function useResourceCreate(resource) {
1103
- const $ = c(6);
1104
- const [loading, setLoading] = useState(false);
1041
+ function useResourceStore(resource, t0) {
1042
+ const $ = c(18);
1043
+ let t1;
1044
+ if ($[0] !== t0) {
1045
+ t1 = t0 === undefined ? {} : t0;
1046
+ $[0] = t0;
1047
+ $[1] = t1;
1048
+ } else {
1049
+ t1 = $[1];
1050
+ }
1051
+ const options = t1;
1052
+ const providedResource = usePanneauResource(resource);
1053
+ const contextResource = useResource();
1054
+ const finalResource = providedResource || contextResource;
1105
1055
  const api = useApi();
1106
- let t0;
1107
- if ($[0] !== api || $[1] !== resource) {
1108
- t0 = data => {
1109
- setLoading(true);
1110
- return api.resources.store(resource, data).then(response => {
1111
- setLoading(false);
1112
- return response;
1113
- }).catch(e => {
1114
- setLoading(false);
1115
- throw e;
1116
- });
1056
+ let t2;
1057
+ if ($[2] !== api || $[3] !== finalResource) {
1058
+ t2 = data => api.resources.store(finalResource, data);
1059
+ $[2] = api;
1060
+ $[3] = finalResource;
1061
+ $[4] = t2;
1062
+ } else {
1063
+ t2 = $[4];
1064
+ }
1065
+ let t3;
1066
+ if ($[5] !== options || $[6] !== t2) {
1067
+ t3 = {
1068
+ mutationFn: t2,
1069
+ ...options
1117
1070
  };
1118
- $[0] = api;
1119
- $[1] = resource;
1120
- $[2] = t0;
1071
+ $[5] = options;
1072
+ $[6] = t2;
1073
+ $[7] = t3;
1121
1074
  } else {
1122
- t0 = $[2];
1075
+ t3 = $[7];
1123
1076
  }
1124
- const store = t0;
1125
- let t1;
1126
- if ($[3] !== loading || $[4] !== store) {
1127
- t1 = {
1128
- store,
1129
- loading
1077
+ const t4 = useMutation(t3);
1078
+ let isPending;
1079
+ let mutate;
1080
+ let mutateAsync;
1081
+ let other;
1082
+ if ($[8] !== t4) {
1083
+ ({
1084
+ mutate,
1085
+ mutateAsync,
1086
+ isPending,
1087
+ ...other
1088
+ } = t4);
1089
+ $[8] = t4;
1090
+ $[9] = isPending;
1091
+ $[10] = mutate;
1092
+ $[11] = mutateAsync;
1093
+ $[12] = other;
1094
+ } else {
1095
+ isPending = $[9];
1096
+ mutate = $[10];
1097
+ mutateAsync = $[11];
1098
+ other = $[12];
1099
+ }
1100
+ let t5;
1101
+ if ($[13] !== isPending || $[14] !== mutate || $[15] !== mutateAsync || $[16] !== other) {
1102
+ t5 = {
1103
+ store: mutate,
1104
+ storeAsync: mutateAsync,
1105
+ loading: isPending,
1106
+ mutate,
1107
+ mutateAsync,
1108
+ isPending,
1109
+ ...other
1130
1110
  };
1131
- $[3] = loading;
1132
- $[4] = store;
1133
- $[5] = t1;
1111
+ $[13] = isPending;
1112
+ $[14] = mutate;
1113
+ $[15] = mutateAsync;
1114
+ $[16] = other;
1115
+ $[17] = t5;
1134
1116
  } else {
1135
- t1 = $[5];
1117
+ t5 = $[17];
1136
1118
  }
1137
- return t1;
1119
+ return t5;
1138
1120
  }
1139
1121
 
1140
- function useResourceUpdate(resource, id) {
1141
- const $ = c(7);
1142
- const [loading, setLoading] = useState(false);
1122
+ function useResourceUpdate(resource, id, t0) {
1123
+ const $ = c(19);
1124
+ let t1;
1125
+ if ($[0] !== t0) {
1126
+ t1 = t0 === undefined ? {} : t0;
1127
+ $[0] = t0;
1128
+ $[1] = t1;
1129
+ } else {
1130
+ t1 = $[1];
1131
+ }
1132
+ const options = t1;
1133
+ const providedResource = usePanneauResource(isObject$1(resource) || isString$1(id) ? resource : null);
1134
+ const contextResource = useResource();
1135
+ const finalResource = providedResource || contextResource;
1136
+ const finalId = !isObject$1(id) ? id : resource;
1143
1137
  const api = useApi();
1144
- let t0;
1145
- if ($[0] !== api || $[1] !== id || $[2] !== resource) {
1146
- t0 = data => {
1147
- setLoading(true);
1148
- return api.resources.update(resource, id, data).then(response => {
1149
- setLoading(false);
1150
- return response;
1151
- }).catch(e => {
1152
- setLoading(false);
1153
- throw e;
1154
- });
1138
+ let t2;
1139
+ if ($[2] !== api || $[3] !== finalId || $[4] !== finalResource) {
1140
+ t2 = data => api.resources.update(finalResource, finalId, data);
1141
+ $[2] = api;
1142
+ $[3] = finalId;
1143
+ $[4] = finalResource;
1144
+ $[5] = t2;
1145
+ } else {
1146
+ t2 = $[5];
1147
+ }
1148
+ let t3;
1149
+ if ($[6] !== options || $[7] !== t2) {
1150
+ t3 = {
1151
+ mutationFn: t2,
1152
+ ...options
1155
1153
  };
1156
- $[0] = api;
1157
- $[1] = id;
1158
- $[2] = resource;
1159
- $[3] = t0;
1154
+ $[6] = options;
1155
+ $[7] = t2;
1156
+ $[8] = t3;
1160
1157
  } else {
1161
- t0 = $[3];
1158
+ t3 = $[8];
1162
1159
  }
1163
- const update = t0;
1164
- let t1;
1165
- if ($[4] !== loading || $[5] !== update) {
1166
- t1 = {
1167
- update,
1168
- loading
1160
+ const t4 = useMutation(t3);
1161
+ let isPending;
1162
+ let mutate;
1163
+ let mutateAsync;
1164
+ let other;
1165
+ if ($[9] !== t4) {
1166
+ ({
1167
+ mutate,
1168
+ mutateAsync,
1169
+ isPending,
1170
+ ...other
1171
+ } = t4);
1172
+ $[9] = t4;
1173
+ $[10] = isPending;
1174
+ $[11] = mutate;
1175
+ $[12] = mutateAsync;
1176
+ $[13] = other;
1177
+ } else {
1178
+ isPending = $[10];
1179
+ mutate = $[11];
1180
+ mutateAsync = $[12];
1181
+ other = $[13];
1182
+ }
1183
+ let t5;
1184
+ if ($[14] !== isPending || $[15] !== mutate || $[16] !== mutateAsync || $[17] !== other) {
1185
+ t5 = {
1186
+ update: mutate,
1187
+ updateAsync: mutateAsync,
1188
+ loading: isPending,
1189
+ mutate,
1190
+ mutateAsync,
1191
+ isPending,
1192
+ ...other
1169
1193
  };
1170
- $[4] = loading;
1171
- $[5] = update;
1172
- $[6] = t1;
1194
+ $[14] = isPending;
1195
+ $[15] = mutate;
1196
+ $[16] = mutateAsync;
1197
+ $[17] = other;
1198
+ $[18] = t5;
1173
1199
  } else {
1174
- t1 = $[6];
1200
+ t5 = $[18];
1175
1201
  }
1176
- return t1;
1202
+ return t5;
1177
1203
  }
1178
1204
 
1179
- function useResourceClone(resource, t0) {
1180
- const $ = c(7);
1181
- const id = t0 === undefined ? null : t0;
1182
- const [loading, setLoading] = useState(false);
1205
+ function useResourceClone(t0, t1, t2) {
1206
+ const $ = c(19);
1207
+ const resource = t0 === undefined ? null : t0;
1208
+ const id = t1 === undefined ? null : t1;
1209
+ let t3;
1210
+ if ($[0] !== t2) {
1211
+ t3 = t2 === undefined ? {} : t2;
1212
+ $[0] = t2;
1213
+ $[1] = t3;
1214
+ } else {
1215
+ t3 = $[1];
1216
+ }
1217
+ const options = t3;
1218
+ const providedResource = usePanneauResource(id !== null && !isObject(id) ? resource : null);
1219
+ const contextResource = useResource();
1220
+ const finalResource = providedResource || contextResource;
1221
+ const finalId = providedResource !== null ? id : resource;
1183
1222
  const api = useApi();
1184
- let t1;
1185
- if ($[0] !== api || $[1] !== id || $[2] !== resource) {
1186
- t1 = providedId => {
1187
- setLoading(true);
1188
- return api.resources.clone(resource, providedId || id).then(response => {
1189
- setLoading(false);
1190
- return response;
1191
- }).catch(e => {
1192
- setLoading(false);
1193
- throw e;
1194
- });
1223
+ let t4;
1224
+ if ($[2] !== api || $[3] !== finalId || $[4] !== finalResource) {
1225
+ t4 = t5 => {
1226
+ const providedId = t5 === undefined ? null : t5;
1227
+ return api.resources.clone(finalResource, providedId ?? finalId);
1195
1228
  };
1196
- $[0] = api;
1197
- $[1] = id;
1198
- $[2] = resource;
1199
- $[3] = t1;
1229
+ $[2] = api;
1230
+ $[3] = finalId;
1231
+ $[4] = finalResource;
1232
+ $[5] = t4;
1200
1233
  } else {
1201
- t1 = $[3];
1234
+ t4 = $[5];
1202
1235
  }
1203
- const clone = t1;
1204
- let t2;
1205
- if ($[4] !== clone || $[5] !== loading) {
1206
- t2 = {
1207
- clone,
1208
- loading
1236
+ let t5;
1237
+ if ($[6] !== options || $[7] !== t4) {
1238
+ t5 = {
1239
+ mutationFn: t4,
1240
+ ...options
1209
1241
  };
1210
- $[4] = clone;
1211
- $[5] = loading;
1212
- $[6] = t2;
1242
+ $[6] = options;
1243
+ $[7] = t4;
1244
+ $[8] = t5;
1213
1245
  } else {
1214
- t2 = $[6];
1246
+ t5 = $[8];
1215
1247
  }
1216
- return t2;
1248
+ const t6 = useMutation(t5);
1249
+ let isPending;
1250
+ let mutate;
1251
+ let mutateAsync;
1252
+ let other;
1253
+ if ($[9] !== t6) {
1254
+ ({
1255
+ mutate,
1256
+ mutateAsync,
1257
+ isPending,
1258
+ ...other
1259
+ } = t6);
1260
+ $[9] = t6;
1261
+ $[10] = isPending;
1262
+ $[11] = mutate;
1263
+ $[12] = mutateAsync;
1264
+ $[13] = other;
1265
+ } else {
1266
+ isPending = $[10];
1267
+ mutate = $[11];
1268
+ mutateAsync = $[12];
1269
+ other = $[13];
1270
+ }
1271
+ let t7;
1272
+ if ($[14] !== isPending || $[15] !== mutate || $[16] !== mutateAsync || $[17] !== other) {
1273
+ t7 = {
1274
+ clone: mutate,
1275
+ cloneAsync: mutateAsync,
1276
+ loading: isPending,
1277
+ mutate,
1278
+ mutateAsync,
1279
+ isPending,
1280
+ ...other
1281
+ };
1282
+ $[14] = isPending;
1283
+ $[15] = mutate;
1284
+ $[16] = mutateAsync;
1285
+ $[17] = other;
1286
+ $[18] = t7;
1287
+ } else {
1288
+ t7 = $[18];
1289
+ }
1290
+ return t7;
1217
1291
  }
1218
1292
 
1219
- function useResourceRestore(resource, t0) {
1220
- const $ = c(7);
1221
- const id = t0 === undefined ? null : t0;
1222
- const [loading, setLoading] = useState(false);
1293
+ function useResourceRestore(t0, t1, t2) {
1294
+ const $ = c(19);
1295
+ const resource = t0 === undefined ? null : t0;
1296
+ const id = t1 === undefined ? null : t1;
1297
+ let t3;
1298
+ if ($[0] !== t2) {
1299
+ t3 = t2 === undefined ? {} : t2;
1300
+ $[0] = t2;
1301
+ $[1] = t3;
1302
+ } else {
1303
+ t3 = $[1];
1304
+ }
1305
+ const options = t3;
1306
+ const providedResource = usePanneauResource(id !== null && !isObject(id) ? resource : null);
1307
+ const contextResource = useResource();
1308
+ const finalResource = providedResource || contextResource;
1309
+ const finalId = providedResource !== null ? id : resource;
1223
1310
  const api = useApi();
1224
- let t1;
1225
- if ($[0] !== api || $[1] !== id || $[2] !== resource) {
1226
- t1 = providedId => {
1227
- setLoading(true);
1228
- return api.resources.restore(resource, providedId || id).then(response => {
1229
- setLoading(false);
1230
- return response;
1231
- }).catch(e => {
1232
- setLoading(false);
1233
- throw e;
1234
- });
1311
+ let t4;
1312
+ if ($[2] !== api || $[3] !== finalId || $[4] !== finalResource) {
1313
+ t4 = t5 => {
1314
+ const providedId = t5 === undefined ? null : t5;
1315
+ return api.resources.restore(finalResource, providedId ?? finalId);
1235
1316
  };
1236
- $[0] = api;
1237
- $[1] = id;
1238
- $[2] = resource;
1239
- $[3] = t1;
1317
+ $[2] = api;
1318
+ $[3] = finalId;
1319
+ $[4] = finalResource;
1320
+ $[5] = t4;
1240
1321
  } else {
1241
- t1 = $[3];
1322
+ t4 = $[5];
1242
1323
  }
1243
- const restore = t1;
1244
- let t2;
1245
- if ($[4] !== loading || $[5] !== restore) {
1246
- t2 = {
1247
- restore,
1248
- loading
1324
+ let t5;
1325
+ if ($[6] !== options || $[7] !== t4) {
1326
+ t5 = {
1327
+ mutationFn: t4,
1328
+ ...options
1249
1329
  };
1250
- $[4] = loading;
1251
- $[5] = restore;
1252
- $[6] = t2;
1330
+ $[6] = options;
1331
+ $[7] = t4;
1332
+ $[8] = t5;
1253
1333
  } else {
1254
- t2 = $[6];
1334
+ t5 = $[8];
1255
1335
  }
1256
- return t2;
1336
+ const t6 = useMutation(t5);
1337
+ let isPending;
1338
+ let mutate;
1339
+ let mutateAsync;
1340
+ let other;
1341
+ if ($[9] !== t6) {
1342
+ ({
1343
+ mutate,
1344
+ mutateAsync,
1345
+ isPending,
1346
+ ...other
1347
+ } = t6);
1348
+ $[9] = t6;
1349
+ $[10] = isPending;
1350
+ $[11] = mutate;
1351
+ $[12] = mutateAsync;
1352
+ $[13] = other;
1353
+ } else {
1354
+ isPending = $[10];
1355
+ mutate = $[11];
1356
+ mutateAsync = $[12];
1357
+ other = $[13];
1358
+ }
1359
+ let t7;
1360
+ if ($[14] !== isPending || $[15] !== mutate || $[16] !== mutateAsync || $[17] !== other) {
1361
+ t7 = {
1362
+ restore: mutate,
1363
+ restoreAsync: mutateAsync,
1364
+ loading: isPending,
1365
+ mutate,
1366
+ mutateAsync,
1367
+ isPending,
1368
+ ...other
1369
+ };
1370
+ $[14] = isPending;
1371
+ $[15] = mutate;
1372
+ $[16] = mutateAsync;
1373
+ $[17] = other;
1374
+ $[18] = t7;
1375
+ } else {
1376
+ t7 = $[18];
1377
+ }
1378
+ return t7;
1257
1379
  }
1258
1380
 
1259
1381
  const QueryContext = /*#__PURE__*/createContext(null);
@@ -1307,59 +1429,63 @@ function QueryProvider(t0) {
1307
1429
  }
1308
1430
 
1309
1431
  function DataProvider(t0) {
1310
- const $ = c(10);
1432
+ const $ = c(11);
1311
1433
  const {
1312
1434
  api: t1,
1313
1435
  apiBaseUrl: t2,
1314
- baseUrl: t3,
1315
- children: t4,
1316
- queryConfig: t5,
1317
- initialQueryKey: t6,
1318
- initialQueryData: t7,
1319
- onUnauthorized: t8
1436
+ routes: t3,
1437
+ baseUrl: t4,
1438
+ children: t5,
1439
+ queryConfig: t6,
1440
+ initialQueryKey: t7,
1441
+ initialQueryData: t8,
1442
+ onUnauthorized: t9
1320
1443
  } = t0;
1321
1444
  const api = t1 === undefined ? null : t1;
1322
1445
  const apiBaseUrl = t2 === undefined ? undefined : t2;
1323
- const baseUrl = t3 === undefined ? undefined : t3;
1324
- const children = t4 === undefined ? null : t4;
1325
- const queryConfig = t5 === undefined ? null : t5;
1326
- const initialQueryKey = t6 === undefined ? null : t6;
1327
- const initialQueryData = t7 === undefined ? null : t7;
1328
- const onUnauthorized = t8 === undefined ? null : t8;
1329
- const t9 = baseUrl ?? apiBaseUrl;
1330
- let t10;
1331
- if ($[0] !== api || $[1] !== children || $[2] !== onUnauthorized || $[3] !== t9) {
1332
- t10 = /*#__PURE__*/jsx(ApiProvider, {
1446
+ const routes = t3 === undefined ? undefined : t3;
1447
+ const baseUrl = t4 === undefined ? undefined : t4;
1448
+ const children = t5 === undefined ? null : t5;
1449
+ const queryConfig = t6 === undefined ? null : t6;
1450
+ const initialQueryKey = t7 === undefined ? null : t7;
1451
+ const initialQueryData = t8 === undefined ? null : t8;
1452
+ const onUnauthorized = t9 === undefined ? null : t9;
1453
+ const t10 = baseUrl ?? apiBaseUrl;
1454
+ let t11;
1455
+ if ($[0] !== api || $[1] !== children || $[2] !== onUnauthorized || $[3] !== routes || $[4] !== t10) {
1456
+ t11 = /*#__PURE__*/jsx(ApiProvider, {
1333
1457
  api: api,
1334
- baseUrl: t9,
1458
+ baseUrl: t10,
1459
+ routes: routes,
1335
1460
  onUnauthorized: onUnauthorized,
1336
1461
  children: children
1337
1462
  });
1338
1463
  $[0] = api;
1339
1464
  $[1] = children;
1340
1465
  $[2] = onUnauthorized;
1341
- $[3] = t9;
1466
+ $[3] = routes;
1342
1467
  $[4] = t10;
1468
+ $[5] = t11;
1343
1469
  } else {
1344
- t10 = $[4];
1470
+ t11 = $[5];
1345
1471
  }
1346
- let t11;
1347
- if ($[5] !== initialQueryData || $[6] !== initialQueryKey || $[7] !== queryConfig || $[8] !== t10) {
1348
- t11 = /*#__PURE__*/jsx(QueryProvider, {
1472
+ let t12;
1473
+ if ($[6] !== initialQueryData || $[7] !== initialQueryKey || $[8] !== queryConfig || $[9] !== t11) {
1474
+ t12 = /*#__PURE__*/jsx(QueryProvider, {
1349
1475
  config: queryConfig,
1350
1476
  initialKey: initialQueryKey,
1351
1477
  initialData: initialQueryData,
1352
- children: t10
1478
+ children: t11
1353
1479
  });
1354
- $[5] = initialQueryData;
1355
- $[6] = initialQueryKey;
1356
- $[7] = queryConfig;
1357
- $[8] = t10;
1480
+ $[6] = initialQueryData;
1481
+ $[7] = initialQueryKey;
1482
+ $[8] = queryConfig;
1358
1483
  $[9] = t11;
1484
+ $[10] = t12;
1359
1485
  } else {
1360
- t11 = $[9];
1486
+ t12 = $[10];
1361
1487
  }
1362
- return t11;
1488
+ return t12;
1363
1489
  }
1364
1490
 
1365
- export { Api, ApiProvider, Base as BaseApi, DataProvider, QueryProvider, useApi, useItem, useItems, useQueryContext, useResourceClone, useResourceDestroy, useResourceItem, useResourceItems, useResourceRestore, useResourceCreate as useResourceStore, useResourceUpdate };
1491
+ export { Api, ApiProvider, Base as BaseApi, DataProvider, QueryProvider, useApi, useItem, useItems, useQueryContext, useResourceClone, useResourceDestroy, useResourceItem, useResourceItems, useResourceRestore, useResourceStore, useResourceUpdate };