@ethlete/query 5.34.0 → 5.35.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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @ethlete/query
2
2
 
3
+ ## 5.35.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`4f65c4c`](https://github.com/ethlete-io/ethdk/commit/4f65c4ceeb2eec9fe1102c19638c21c42525870d) Thanks [@TomTomB](https://github.com/TomTomB)! - Add subtle namespace to query stack
8
+
9
+ - [`895ab11`](https://github.com/ethlete-io/ethdk/commit/895ab11f64425671558c18254694c12b7232fcbd) Thanks [@TomTomB](https://github.com/TomTomB)! - Add isLastPageLoaded and isFirstPageLoaded to paged query stack
10
+
3
11
  ## 5.34.0
4
12
 
5
13
  ### Minor Changes
@@ -3897,18 +3897,19 @@ const createQueryStack = (options) => {
3897
3897
  dependencies?.();
3898
3898
  untracked(() => clear());
3899
3899
  });
3900
- effect(() => {
3901
- const newArgs = args(dependencies?.());
3902
- if (newArgs === null)
3903
- return;
3904
- const newArgsArray = Array.isArray(newArgs) ? newArgs : [newArgs];
3900
+ effect(() => runWithArgs(args(dependencies?.())));
3901
+ const runWithArgs = (args) => {
3902
+ if (args === null)
3903
+ return null;
3904
+ const newArgsArray = Array.isArray(args) ? args : [args];
3905
3905
  const newQueries = runInInjectionContext(injector, () => newArgsArray.map((newArgsEntry) => queryCreator(withArgs(() => newArgsEntry), ...features)));
3906
- untracked(() => {
3906
+ const result = untracked(() => {
3907
3907
  const oldQueries = queries();
3908
3908
  if (append) {
3909
3909
  const { queries: appendedQueries, lastQuery: lastAppendedQuery } = appendFn(oldQueries, newQueries);
3910
3910
  queries.set(appendedQueries);
3911
3911
  lastQuery.set(lastAppendedQuery);
3912
+ return lastAppendedQuery;
3912
3913
  }
3913
3914
  else {
3914
3915
  for (const oldQuery of oldQueries) {
@@ -3917,10 +3918,13 @@ const createQueryStack = (options) => {
3917
3918
  }
3918
3919
  }
3919
3920
  queries.set(newQueries);
3920
- lastQuery.set(newQueries[newQueries.length - 1] ?? null);
3921
+ const last = newQueries[newQueries.length - 1] ?? null;
3922
+ lastQuery.set(last);
3923
+ return last;
3921
3924
  }
3922
3925
  });
3923
- });
3926
+ return result;
3927
+ };
3924
3928
  const loading = computed(() => queries().some((q) => q.loading()));
3925
3929
  const error = computed(() => queries()
3926
3930
  .map((q) => q.error())
@@ -3950,6 +3954,9 @@ const createQueryStack = (options) => {
3950
3954
  response,
3951
3955
  execute,
3952
3956
  clear,
3957
+ subtle: {
3958
+ runWithArgs,
3959
+ },
3953
3960
  };
3954
3961
  return stack;
3955
3962
  };
@@ -4018,7 +4025,7 @@ const createPagedQueryStack = (options) => {
4018
4025
  const lastResetTimestamp = signal(Date.now());
4019
4026
  const pageDirection = signal('next');
4020
4027
  const stack = createQueryStack({
4021
- args: () => currentPageArgs(),
4028
+ args: () => null,
4022
4029
  queryCreator,
4023
4030
  append: true,
4024
4031
  features,
@@ -4046,6 +4053,7 @@ const createPagedQueryStack = (options) => {
4046
4053
  currentPageArgs.set(args);
4047
4054
  loadedMinPage.set(initialPage());
4048
4055
  loadedMaxPage.set(initialPage());
4056
+ stack.subtle.runWithArgs(args);
4049
4057
  });
4050
4058
  });
4051
4059
  const maxPagination = computed(() => {
@@ -4062,44 +4070,54 @@ const createPagedQueryStack = (options) => {
4062
4070
  return null;
4063
4071
  return responseNormalizer(res, all);
4064
4072
  });
4073
+ const isFirstPageLoaded = computed(() => {
4074
+ const min = minPagination();
4075
+ return min ? loadedMinPage() === min.currentPage : false;
4076
+ });
4077
+ const isLastPageLoaded = computed(() => {
4078
+ const max = maxPagination();
4079
+ return max ? loadedMaxPage() === max.totalPages : false;
4080
+ });
4065
4081
  const fetchPreviousPage = () => {
4066
4082
  const page = loadedMinPage() - 1;
4067
4083
  const allResponses = stack.response();
4068
4084
  if (!canFetchNewPage(page)) {
4069
- return;
4085
+ return null;
4070
4086
  }
4071
4087
  if (page < 1) {
4072
4088
  if (isDevMode()) {
4073
4089
  throw pagedQueryStackPreviousPageCalledButAlreadyAtFirstPage();
4074
4090
  }
4075
- return;
4091
+ return null;
4076
4092
  }
4077
4093
  currentPageArgs.set(options.args(page, allResponses));
4078
4094
  loadedMinPage.set(page);
4079
4095
  pageDirection.set('previous');
4096
+ return stack.subtle.runWithArgs(currentPageArgs());
4080
4097
  };
4081
4098
  const fetchNextPage = () => {
4082
4099
  const page = loadedMaxPage() + 1;
4083
4100
  const currentPagination = maxPagination();
4084
4101
  const allResponses = stack.response();
4085
4102
  if (!canFetchNewPage(page)) {
4086
- return;
4103
+ return null;
4087
4104
  }
4088
4105
  if (!currentPagination) {
4089
4106
  if (isDevMode()) {
4090
4107
  throw pagedQueryStackNextPageCalledWithoutPreviousPage();
4091
4108
  }
4092
- return;
4109
+ return null;
4093
4110
  }
4094
4111
  if (page > currentPagination.totalPages) {
4095
4112
  if (isDevMode()) {
4096
4113
  throw pagedQueryStackPageBiggerThanTotalPages(page, currentPagination.totalPages);
4097
4114
  }
4098
- return;
4115
+ return null;
4099
4116
  }
4100
4117
  currentPageArgs.set(options.args(page, allResponses));
4101
4118
  loadedMaxPage.set(page);
4102
4119
  pageDirection.set('next');
4120
+ return stack.subtle.runWithArgs(currentPageArgs());
4103
4121
  };
4104
4122
  const canFetchNewPage = (pageToLoad) => {
4105
4123
  const currentMaxPagination = maxPagination();
@@ -4200,6 +4218,8 @@ const createPagedQueryStack = (options) => {
4200
4218
  lastQuery: stack.lastQuery,
4201
4219
  isFirstLoad,
4202
4220
  queries: stack.queries,
4221
+ isLastPageLoaded,
4222
+ isFirstPageLoaded,
4203
4223
  reset,
4204
4224
  execute,
4205
4225
  };