@opengeoweb/api 20.0.0-nightly-20261001 → 20.0.1
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 +72 -41
- package/dist/src/utils.d.ts +7 -0
- package/package.json +3 -3
package/dist/index.esm.js
CHANGED
|
@@ -153,46 +153,77 @@ var withJsonFormat = function withJsonFormat(url) {
|
|
|
153
153
|
urlObj.searchParams.set('f', 'json');
|
|
154
154
|
return urlObj.toString();
|
|
155
155
|
};
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
156
|
+
/**
|
|
157
|
+
* Extracts the error message from a non-ok response and throws it, so the
|
|
158
|
+
* backend message can be shown to the user. Uses `message` from the JSON body
|
|
159
|
+
* when present, else the stringified body, else the status code. The response
|
|
160
|
+
* status is set as the error `cause`.
|
|
161
|
+
*/
|
|
162
|
+
var throwResponseError = /*#__PURE__*/function () {
|
|
159
163
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(response) {
|
|
164
|
+
var json, message;
|
|
160
165
|
return _regenerator().w(function (_context) {
|
|
161
166
|
while (1) switch (_context.n) {
|
|
167
|
+
case 0:
|
|
168
|
+
_context.n = 1;
|
|
169
|
+
return response.json()["catch"](function () {
|
|
170
|
+
return null;
|
|
171
|
+
});
|
|
172
|
+
case 1:
|
|
173
|
+
json = _context.v;
|
|
174
|
+
if (!json) {
|
|
175
|
+
_context.n = 3;
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
message = json.message;
|
|
179
|
+
if (!message) {
|
|
180
|
+
_context.n = 2;
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
throw new Error(message, {
|
|
184
|
+
cause: response.status
|
|
185
|
+
});
|
|
186
|
+
case 2:
|
|
187
|
+
throw new Error(JSON.stringify(json), {
|
|
188
|
+
cause: response.status
|
|
189
|
+
});
|
|
190
|
+
case 3:
|
|
191
|
+
throw new Error("" + response.status, {
|
|
192
|
+
cause: response.status
|
|
193
|
+
});
|
|
194
|
+
case 4:
|
|
195
|
+
return _context.a(2);
|
|
196
|
+
}
|
|
197
|
+
}, _callee);
|
|
198
|
+
}));
|
|
199
|
+
return function throwResponseError(_x) {
|
|
200
|
+
return _ref.apply(this, arguments);
|
|
201
|
+
};
|
|
202
|
+
}();
|
|
203
|
+
// This function has a copy in libs/webmap-react/src/lib/edr-layer-api/api.ts. This cannot be used there due to circular dependency
|
|
204
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
205
|
+
var handleResponse = /*#__PURE__*/function () {
|
|
206
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(response) {
|
|
207
|
+
return _regenerator().w(function (_context2) {
|
|
208
|
+
while (1) switch (_context2.n) {
|
|
162
209
|
case 0:
|
|
163
210
|
if (!response.ok) {
|
|
164
|
-
|
|
211
|
+
_context2.n = 1;
|
|
165
212
|
break;
|
|
166
213
|
}
|
|
167
|
-
return
|
|
214
|
+
return _context2.a(2, response.json().then(function (json) {
|
|
168
215
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
169
216
|
return json != null ? json : response.headers;
|
|
170
217
|
})["catch"](function () {
|
|
171
218
|
// No JSON response
|
|
172
219
|
}));
|
|
173
220
|
case 1:
|
|
174
|
-
return
|
|
175
|
-
// Couldn't parse the JSON
|
|
176
|
-
throw new Error("" + response.status);
|
|
177
|
-
}).then(function (json) {
|
|
178
|
-
// Got valid JSON with error response, use it
|
|
179
|
-
if (json) {
|
|
180
|
-
var message = json.message;
|
|
181
|
-
if (message) {
|
|
182
|
-
throw new Error(message, {
|
|
183
|
-
cause: response.status
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
var result = JSON.stringify(json);
|
|
187
|
-
throw new Error(result);
|
|
188
|
-
}
|
|
189
|
-
throw new Error("" + response.status);
|
|
190
|
-
}));
|
|
221
|
+
return _context2.a(2, throwResponseError(response));
|
|
191
222
|
}
|
|
192
|
-
},
|
|
223
|
+
}, _callee2);
|
|
193
224
|
}));
|
|
194
|
-
return function handleResponse(
|
|
195
|
-
return
|
|
225
|
+
return function handleResponse(_x2) {
|
|
226
|
+
return _ref2.apply(this, arguments);
|
|
196
227
|
};
|
|
197
228
|
}();
|
|
198
229
|
var useAuthQuery = function useAuthQuery(queryKey, _queryFn, disabled, refetchInterval) {
|
|
@@ -208,13 +239,13 @@ var useAuthQuery = function useAuthQuery(queryKey, _queryFn, disabled, refetchIn
|
|
|
208
239
|
return useQuery({
|
|
209
240
|
queryKey: queryKey,
|
|
210
241
|
queryFn: function () {
|
|
211
|
-
var _queryFn2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
212
|
-
return _regenerator().w(function (
|
|
213
|
-
while (1) switch (
|
|
242
|
+
var _queryFn2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
|
|
243
|
+
return _regenerator().w(function (_context3) {
|
|
244
|
+
while (1) switch (_context3.n) {
|
|
214
245
|
case 0:
|
|
215
|
-
return
|
|
246
|
+
return _context3.a(2, _queryFn(auth));
|
|
216
247
|
}
|
|
217
|
-
},
|
|
248
|
+
}, _callee3);
|
|
218
249
|
}));
|
|
219
250
|
function queryFn() {
|
|
220
251
|
return _queryFn2.apply(this, arguments);
|
|
@@ -228,12 +259,12 @@ var useAuthQuery = function useAuthQuery(queryKey, _queryFn, disabled, refetchIn
|
|
|
228
259
|
var optimisticUpdate = function optimisticUpdate(updatedQueryKey, queryClient, _optimisticUpdate, errorCallback) {
|
|
229
260
|
return {
|
|
230
261
|
onMutate: function () {
|
|
231
|
-
var _onMutate = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
262
|
+
var _onMutate = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(variables) {
|
|
232
263
|
var previousData, matchesVariables;
|
|
233
|
-
return _regenerator().w(function (
|
|
234
|
-
while (1) switch (
|
|
264
|
+
return _regenerator().w(function (_context4) {
|
|
265
|
+
while (1) switch (_context4.n) {
|
|
235
266
|
case 0:
|
|
236
|
-
|
|
267
|
+
_context4.n = 1;
|
|
237
268
|
return queryClient.cancelQueries({
|
|
238
269
|
queryKey: updatedQueryKey,
|
|
239
270
|
exact: false
|
|
@@ -254,21 +285,21 @@ var optimisticUpdate = function optimisticUpdate(updatedQueryKey, queryClient, _
|
|
|
254
285
|
return matchesVariables(item) ? _optimisticUpdate(item, variables) : item;
|
|
255
286
|
});
|
|
256
287
|
});
|
|
257
|
-
return
|
|
288
|
+
return _context4.a(2, {
|
|
258
289
|
previousData: previousData
|
|
259
290
|
});
|
|
260
291
|
}
|
|
261
|
-
},
|
|
292
|
+
}, _callee4);
|
|
262
293
|
}));
|
|
263
|
-
function onMutate(
|
|
294
|
+
function onMutate(_x3) {
|
|
264
295
|
return _onMutate.apply(this, arguments);
|
|
265
296
|
}
|
|
266
297
|
return onMutate;
|
|
267
298
|
}(),
|
|
268
299
|
onError: function onError(err, _, context) {
|
|
269
|
-
context == null || context.previousData.forEach(function (
|
|
270
|
-
var queryKey =
|
|
271
|
-
data =
|
|
300
|
+
context == null || context.previousData.forEach(function (_ref3) {
|
|
301
|
+
var queryKey = _ref3[0],
|
|
302
|
+
data = _ref3[1];
|
|
272
303
|
queryClient.setQueryData(queryKey, data);
|
|
273
304
|
});
|
|
274
305
|
if (errorCallback) {
|
|
@@ -597,4 +628,4 @@ var QueryClientProviderWrapper = function QueryClientProviderWrapper(_ref) {
|
|
|
597
628
|
var API_NAMESPACE = 'api';
|
|
598
629
|
// Initialize and create provider if needed
|
|
599
630
|
|
|
600
|
-
export { API_NAMESPACE, AirmetPhenomena, CloudLevelUnits, Direction, LevelUnits, MovementUnit, ProductStatus, QueryClientProviderWrapper, SigmetPhenomena, VisibilityCause, WindUnit, configureLibraryDefaults, createTestQueryClient, getHeaders, getQueryClient, handleResponse, makeMockApiCall, optimisticUpdate, resetQueryClient, setQueryClient, useAuthQuery, withJsonFormat };
|
|
631
|
+
export { API_NAMESPACE, AirmetPhenomena, CloudLevelUnits, Direction, LevelUnits, MovementUnit, ProductStatus, QueryClientProviderWrapper, SigmetPhenomena, VisibilityCause, WindUnit, configureLibraryDefaults, createTestQueryClient, getHeaders, getQueryClient, handleResponse, makeMockApiCall, optimisticUpdate, resetQueryClient, setQueryClient, throwResponseError, useAuthQuery, withJsonFormat };
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -11,6 +11,13 @@ import type { Credentials } from '@opengeoweb/authentication';
|
|
|
11
11
|
export type UseMutationReturnType<TData = unknown, TVariables = void, TContext = unknown> = UseMutationResult<TData, Error, TVariables, TContext>;
|
|
12
12
|
export declare const getHeaders: (auth?: Credentials) => HeadersInit;
|
|
13
13
|
export declare const withJsonFormat: (url: string) => string;
|
|
14
|
+
/**
|
|
15
|
+
* Extracts the error message from a non-ok response and throws it, so the
|
|
16
|
+
* backend message can be shown to the user. Uses `message` from the JSON body
|
|
17
|
+
* when present, else the stringified body, else the status code. The response
|
|
18
|
+
* status is set as the error `cause`.
|
|
19
|
+
*/
|
|
20
|
+
export declare const throwResponseError: (response: Response) => Promise<never>;
|
|
14
21
|
export declare const handleResponse: (response: Response) => Promise<any>;
|
|
15
22
|
export declare const useAuthQuery: <T>(queryKey: string[], queryFn: (auth: Credentials) => Promise<T>, disabled?: boolean, refetchInterval?: number | false) => UseQueryResult<T>;
|
|
16
23
|
export declare const optimisticUpdate: <U extends {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengeoweb/api",
|
|
3
|
-
"version": "20.0.
|
|
3
|
+
"version": "20.0.1",
|
|
4
4
|
"description": "GeoWeb API library for the opengeoweb project",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@opengeoweb/authentication": "20.0.
|
|
24
|
-
"@opengeoweb/store": "20.0.
|
|
23
|
+
"@opengeoweb/authentication": "20.0.1",
|
|
24
|
+
"@opengeoweb/store": "20.0.1",
|
|
25
25
|
"lodash": "^4.18.1",
|
|
26
26
|
"@tanstack/react-query": "^5.85.5",
|
|
27
27
|
"@tanstack/query-core": "^5.79.0",
|