@opengeoweb/api 19.3.0 → 19.5.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/dist/index.esm.js CHANGED
@@ -229,23 +229,33 @@ var optimisticUpdate = function optimisticUpdate(updatedQueryKey, queryClient, _
229
229
  return {
230
230
  onMutate: function () {
231
231
  var _onMutate = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(variables) {
232
- var oldData;
232
+ var previousData, matchesVariables;
233
233
  return _regenerator().w(function (_context3) {
234
234
  while (1) switch (_context3.n) {
235
235
  case 0:
236
- void queryClient.cancelQueries({
237
- queryKey: updatedQueryKey
236
+ _context3.n = 1;
237
+ return queryClient.cancelQueries({
238
+ queryKey: updatedQueryKey,
239
+ exact: false
238
240
  });
239
- oldData = queryClient.getQueryData(updatedQueryKey);
240
- if (variables.id) {
241
- queryClient.setQueryData(updatedQueryKey, function (old) {
242
- return old == null ? void 0 : old.map(function (item) {
243
- return item.id === variables.id ? _optimisticUpdate(item, variables) : item;
244
- });
241
+ case 1:
242
+ previousData = queryClient.getQueriesData({
243
+ queryKey: updatedQueryKey,
244
+ exact: false
245
+ });
246
+ matchesVariables = function matchesVariables(item) {
247
+ return !!variables.id && item.id === variables.id || !!variables.eventId && item.eventId === variables.eventId;
248
+ };
249
+ queryClient.setQueriesData({
250
+ queryKey: updatedQueryKey,
251
+ exact: false
252
+ }, function (old) {
253
+ return old == null ? void 0 : old.map(function (item) {
254
+ return matchesVariables(item) ? _optimisticUpdate(item, variables) : item;
245
255
  });
246
- }
256
+ });
247
257
  return _context3.a(2, {
248
- oldData: oldData
258
+ previousData: previousData
249
259
  });
250
260
  }
251
261
  }, _callee3);
@@ -256,9 +266,11 @@ var optimisticUpdate = function optimisticUpdate(updatedQueryKey, queryClient, _
256
266
  return onMutate;
257
267
  }(),
258
268
  onError: function onError(err, _, context) {
259
- if (context != null && context.oldData) {
260
- queryClient.setQueryData(updatedQueryKey, context == null ? void 0 : context.oldData);
261
- }
269
+ context == null || context.previousData.forEach(function (_ref2) {
270
+ var queryKey = _ref2[0],
271
+ data = _ref2[1];
272
+ queryClient.setQueryData(queryKey, data);
273
+ });
262
274
  if (errorCallback) {
263
275
  errorCallback(err);
264
276
  }
@@ -1,4 +1,4 @@
1
- import type { MutationOptions, QueryClient, UseQueryResult } from '@tanstack/react-query';
1
+ import type { MutationOptions, QueryClient, QueryKey, UseQueryResult } from '@tanstack/react-query';
2
2
  import type { Credentials } from '@opengeoweb/authentication';
3
3
  export declare const getHeaders: (auth?: Credentials) => HeadersInit;
4
4
  export declare const withJsonFormat: (url: string) => string;
@@ -6,8 +6,10 @@ export declare const handleResponse: (response: Response) => Promise<any>;
6
6
  export declare const useAuthQuery: <T>(queryKey: string[], queryFn: (auth: Credentials) => Promise<T>, disabled?: boolean, refetchInterval?: number | false) => UseQueryResult<T>;
7
7
  export declare const optimisticUpdate: <U extends {
8
8
  id?: string;
9
+ eventId?: string;
9
10
  }, T extends {
10
11
  id?: string;
12
+ eventId?: string;
11
13
  }>(updatedQueryKey: string[], queryClient: QueryClient, optimisticUpdate: (oldValue: U, variables: T) => U, errorCallback?: (err: Error) => void) => MutationOptions<Headers | null, Error, T, {
12
- oldData: U[] | undefined;
14
+ previousData: [QueryKey, U[] | undefined][];
13
15
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeoweb/api",
3
- "version": "19.3.0",
3
+ "version": "19.5.0",
4
4
  "description": "GeoWeb API library for the opengeoweb project",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {