@opengeoweb/api 10.1.0 → 10.2.1-spike-ol.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/README.md CHANGED
@@ -218,3 +218,7 @@ export const StoryBookExample = (): React.ReactElement => (
218
218
  );
219
219
 
220
220
  ```
221
+
222
+ ### TypeScript Documentation
223
+
224
+ - [TypeScript Docs](https://opengeoweb.gitlab.io/opengeoweb/typescript-docs/api/)
package/index.esm.js CHANGED
@@ -1,24 +1,334 @@
1
1
  import { useAuthenticationContext } from '@opengeoweb/authentication';
2
2
  export * from '@opengeoweb/authentication';
3
- import { useQuery, skipToken } from '@tanstack/react-query';
3
+ import { useQuery } from '@tanstack/react-query';
4
+
5
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
6
+ try {
7
+ var i = n[a](c),
8
+ u = i.value;
9
+ } catch (n) {
10
+ return void e(n);
11
+ }
12
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
13
+ }
14
+ function _asyncToGenerator(n) {
15
+ return function () {
16
+ var t = this,
17
+ e = arguments;
18
+ return new Promise(function (r, o) {
19
+ var a = n.apply(t, e);
20
+ function _next(n) {
21
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
22
+ }
23
+ function _throw(n) {
24
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
25
+ }
26
+ _next(void 0);
27
+ });
28
+ };
29
+ }
30
+ function _regeneratorRuntime() {
31
+ _regeneratorRuntime = function () {
32
+ return e;
33
+ };
34
+ var t,
35
+ e = {},
36
+ r = Object.prototype,
37
+ n = r.hasOwnProperty,
38
+ o = Object.defineProperty || function (t, e, r) {
39
+ t[e] = r.value;
40
+ },
41
+ i = "function" == typeof Symbol ? Symbol : {},
42
+ a = i.iterator || "@@iterator",
43
+ c = i.asyncIterator || "@@asyncIterator",
44
+ u = i.toStringTag || "@@toStringTag";
45
+ function define(t, e, r) {
46
+ return Object.defineProperty(t, e, {
47
+ value: r,
48
+ enumerable: !0,
49
+ configurable: !0,
50
+ writable: !0
51
+ }), t[e];
52
+ }
53
+ try {
54
+ define({}, "");
55
+ } catch (t) {
56
+ define = function (t, e, r) {
57
+ return t[e] = r;
58
+ };
59
+ }
60
+ function wrap(t, e, r, n) {
61
+ var i = e && e.prototype instanceof Generator ? e : Generator,
62
+ a = Object.create(i.prototype),
63
+ c = new Context(n || []);
64
+ return o(a, "_invoke", {
65
+ value: makeInvokeMethod(t, r, c)
66
+ }), a;
67
+ }
68
+ function tryCatch(t, e, r) {
69
+ try {
70
+ return {
71
+ type: "normal",
72
+ arg: t.call(e, r)
73
+ };
74
+ } catch (t) {
75
+ return {
76
+ type: "throw",
77
+ arg: t
78
+ };
79
+ }
80
+ }
81
+ e.wrap = wrap;
82
+ var h = "suspendedStart",
83
+ l = "suspendedYield",
84
+ f = "executing",
85
+ s = "completed",
86
+ y = {};
87
+ function Generator() {}
88
+ function GeneratorFunction() {}
89
+ function GeneratorFunctionPrototype() {}
90
+ var p = {};
91
+ define(p, a, function () {
92
+ return this;
93
+ });
94
+ var d = Object.getPrototypeOf,
95
+ v = d && d(d(values([])));
96
+ v && v !== r && n.call(v, a) && (p = v);
97
+ var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
98
+ function defineIteratorMethods(t) {
99
+ ["next", "throw", "return"].forEach(function (e) {
100
+ define(t, e, function (t) {
101
+ return this._invoke(e, t);
102
+ });
103
+ });
104
+ }
105
+ function AsyncIterator(t, e) {
106
+ function invoke(r, o, i, a) {
107
+ var c = tryCatch(t[r], t, o);
108
+ if ("throw" !== c.type) {
109
+ var u = c.arg,
110
+ h = u.value;
111
+ return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
112
+ invoke("next", t, i, a);
113
+ }, function (t) {
114
+ invoke("throw", t, i, a);
115
+ }) : e.resolve(h).then(function (t) {
116
+ u.value = t, i(u);
117
+ }, function (t) {
118
+ return invoke("throw", t, i, a);
119
+ });
120
+ }
121
+ a(c.arg);
122
+ }
123
+ var r;
124
+ o(this, "_invoke", {
125
+ value: function (t, n) {
126
+ function callInvokeWithMethodAndArg() {
127
+ return new e(function (e, r) {
128
+ invoke(t, n, e, r);
129
+ });
130
+ }
131
+ return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
132
+ }
133
+ });
134
+ }
135
+ function makeInvokeMethod(e, r, n) {
136
+ var o = h;
137
+ return function (i, a) {
138
+ if (o === f) throw Error("Generator is already running");
139
+ if (o === s) {
140
+ if ("throw" === i) throw a;
141
+ return {
142
+ value: t,
143
+ done: !0
144
+ };
145
+ }
146
+ for (n.method = i, n.arg = a;;) {
147
+ var c = n.delegate;
148
+ if (c) {
149
+ var u = maybeInvokeDelegate(c, n);
150
+ if (u) {
151
+ if (u === y) continue;
152
+ return u;
153
+ }
154
+ }
155
+ if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
156
+ if (o === h) throw o = s, n.arg;
157
+ n.dispatchException(n.arg);
158
+ } else "return" === n.method && n.abrupt("return", n.arg);
159
+ o = f;
160
+ var p = tryCatch(e, r, n);
161
+ if ("normal" === p.type) {
162
+ if (o = n.done ? s : l, p.arg === y) continue;
163
+ return {
164
+ value: p.arg,
165
+ done: n.done
166
+ };
167
+ }
168
+ "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
169
+ }
170
+ };
171
+ }
172
+ function maybeInvokeDelegate(e, r) {
173
+ var n = r.method,
174
+ o = e.iterator[n];
175
+ if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
176
+ var i = tryCatch(o, e.iterator, r.arg);
177
+ if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
178
+ var a = i.arg;
179
+ return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
180
+ }
181
+ function pushTryEntry(t) {
182
+ var e = {
183
+ tryLoc: t[0]
184
+ };
185
+ 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
186
+ }
187
+ function resetTryEntry(t) {
188
+ var e = t.completion || {};
189
+ e.type = "normal", delete e.arg, t.completion = e;
190
+ }
191
+ function Context(t) {
192
+ this.tryEntries = [{
193
+ tryLoc: "root"
194
+ }], t.forEach(pushTryEntry, this), this.reset(!0);
195
+ }
196
+ function values(e) {
197
+ if (e || "" === e) {
198
+ var r = e[a];
199
+ if (r) return r.call(e);
200
+ if ("function" == typeof e.next) return e;
201
+ if (!isNaN(e.length)) {
202
+ var o = -1,
203
+ i = function next() {
204
+ for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
205
+ return next.value = t, next.done = !0, next;
206
+ };
207
+ return i.next = i;
208
+ }
209
+ }
210
+ throw new TypeError(typeof e + " is not iterable");
211
+ }
212
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
213
+ value: GeneratorFunctionPrototype,
214
+ configurable: !0
215
+ }), o(GeneratorFunctionPrototype, "constructor", {
216
+ value: GeneratorFunction,
217
+ configurable: !0
218
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
219
+ var e = "function" == typeof t && t.constructor;
220
+ return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
221
+ }, e.mark = function (t) {
222
+ return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
223
+ }, e.awrap = function (t) {
224
+ return {
225
+ __await: t
226
+ };
227
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
228
+ return this;
229
+ }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
230
+ void 0 === i && (i = Promise);
231
+ var a = new AsyncIterator(wrap(t, r, n, o), i);
232
+ return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
233
+ return t.done ? t.value : a.next();
234
+ });
235
+ }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
236
+ return this;
237
+ }), define(g, "toString", function () {
238
+ return "[object Generator]";
239
+ }), e.keys = function (t) {
240
+ var e = Object(t),
241
+ r = [];
242
+ for (var n in e) r.push(n);
243
+ return r.reverse(), function next() {
244
+ for (; r.length;) {
245
+ var t = r.pop();
246
+ if (t in e) return next.value = t, next.done = !1, next;
247
+ }
248
+ return next.done = !0, next;
249
+ };
250
+ }, e.values = values, Context.prototype = {
251
+ constructor: Context,
252
+ reset: function (e) {
253
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
254
+ },
255
+ stop: function () {
256
+ this.done = !0;
257
+ var t = this.tryEntries[0].completion;
258
+ if ("throw" === t.type) throw t.arg;
259
+ return this.rval;
260
+ },
261
+ dispatchException: function (e) {
262
+ if (this.done) throw e;
263
+ var r = this;
264
+ function handle(n, o) {
265
+ return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
266
+ }
267
+ for (var o = this.tryEntries.length - 1; o >= 0; --o) {
268
+ var i = this.tryEntries[o],
269
+ a = i.completion;
270
+ if ("root" === i.tryLoc) return handle("end");
271
+ if (i.tryLoc <= this.prev) {
272
+ var c = n.call(i, "catchLoc"),
273
+ u = n.call(i, "finallyLoc");
274
+ if (c && u) {
275
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
276
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
277
+ } else if (c) {
278
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
279
+ } else {
280
+ if (!u) throw Error("try statement without catch or finally");
281
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
282
+ }
283
+ }
284
+ }
285
+ },
286
+ abrupt: function (t, e) {
287
+ for (var r = this.tryEntries.length - 1; r >= 0; --r) {
288
+ var o = this.tryEntries[r];
289
+ if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
290
+ var i = o;
291
+ break;
292
+ }
293
+ }
294
+ i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
295
+ var a = i ? i.completion : {};
296
+ return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
297
+ },
298
+ complete: function (t, e) {
299
+ if ("throw" === t.type) throw t.arg;
300
+ return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
301
+ },
302
+ finish: function (t) {
303
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
304
+ var r = this.tryEntries[e];
305
+ if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
306
+ }
307
+ },
308
+ catch: function (t) {
309
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
310
+ var r = this.tryEntries[e];
311
+ if (r.tryLoc === t) {
312
+ var n = r.completion;
313
+ if ("throw" === n.type) {
314
+ var o = n.arg;
315
+ resetTryEntry(r);
316
+ }
317
+ return o;
318
+ }
319
+ }
320
+ throw Error("illegal catch attempt");
321
+ },
322
+ delegateYield: function (e, r, n) {
323
+ return this.delegate = {
324
+ iterator: values(e),
325
+ resultName: r,
326
+ nextLoc: n
327
+ }, "next" === this.method && (this.arg = t), y;
328
+ }
329
+ }, e;
330
+ }
4
331
 
5
- /* *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- *
18
- * Copyright 2024 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
19
- * Copyright 2024 - Finnish Meteorological Institute (FMI)
20
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
21
- * */
22
332
  var getHeaders = function getHeaders(auth) {
23
333
  return {
24
334
  'Content-Type': 'application/json',
@@ -26,20 +336,80 @@ var getHeaders = function getHeaders(auth) {
26
336
  Accept: 'application/json'
27
337
  };
28
338
  };
29
- var useAuthQuery = function useAuthQuery(queryKey, queryFn, disabled) {
339
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
340
+ var handleResponse = function handleResponse(response) {
341
+ if (response.status === 200) {
342
+ return response.json();
343
+ }
344
+ return response.json()["catch"](function () {
345
+ // Couldn't parse the JSON
346
+ throw new Error("" + response.status);
347
+ }).then(function (_ref) {
348
+ var message = _ref.message;
349
+ // Got valid JSON with error response, use it
350
+ throw new Error(message || response.status);
351
+ });
352
+ };
353
+ var useAuthQuery = function useAuthQuery(queryKey, _queryFn, disabled, refetchInterval) {
30
354
  if (disabled === void 0) {
31
355
  disabled = false;
32
356
  }
357
+ if (refetchInterval === void 0) {
358
+ refetchInterval = false;
359
+ }
33
360
  var _useAuthenticationCon = useAuthenticationContext(),
34
361
  auth = _useAuthenticationCon.auth;
35
362
  var enabled = !!auth && !disabled;
36
363
  return useQuery({
37
364
  queryKey: queryKey,
38
- queryFn: enabled ? function () {
39
- return queryFn(auth);
40
- } : skipToken
365
+ queryFn: function queryFn() {
366
+ return _queryFn(auth);
367
+ },
368
+ enabled: enabled,
369
+ refetchInterval: refetchInterval
41
370
  });
42
371
  };
372
+ var optimisticUpdate = function optimisticUpdate(updatedQueryKey, queryClient, _optimisticUpdate, errorCallback) {
373
+ return {
374
+ onMutate: function () {
375
+ var _onMutate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(variables) {
376
+ var oldData;
377
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
378
+ while (1) switch (_context.prev = _context.next) {
379
+ case 0:
380
+ void queryClient.cancelQueries({
381
+ queryKey: updatedQueryKey
382
+ });
383
+ oldData = queryClient.getQueryData(updatedQueryKey);
384
+ queryClient.setQueryData(updatedQueryKey, function (old) {
385
+ return old == null ? void 0 : old.map(function (w) {
386
+ return w.id === variables.id ? _optimisticUpdate(w, variables) : w;
387
+ });
388
+ });
389
+ return _context.abrupt("return", {
390
+ oldData: oldData
391
+ });
392
+ case 4:
393
+ case "end":
394
+ return _context.stop();
395
+ }
396
+ }, _callee);
397
+ }));
398
+ function onMutate(_x) {
399
+ return _onMutate.apply(this, arguments);
400
+ }
401
+ return onMutate;
402
+ }(),
403
+ onError: function onError(err, _, context) {
404
+ if (context != null && context.oldData) {
405
+ queryClient.setQueryData(updatedQueryKey, context == null ? void 0 : context.oldData);
406
+ }
407
+ if (errorCallback) {
408
+ errorCallback(err);
409
+ }
410
+ }
411
+ };
412
+ };
43
413
 
44
414
  /* *
45
415
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -68,6 +438,7 @@ var ProductStatus;
68
438
  (function (ProductStatus) {
69
439
  ProductStatus["DRAFT"] = "DRAFT";
70
440
  ProductStatus["PUBLISHED"] = "PUBLISHED";
441
+ ProductStatus["RENEWED"] = "RENEWED";
71
442
  ProductStatus["CANCELLED"] = "CANCELLED";
72
443
  ProductStatus["EXPIRED"] = "EXPIRED";
73
444
  ProductStatus["DISCARDED"] = "DISCARDED";
@@ -204,4 +575,4 @@ var VisibilityCause;
204
575
  var API_NAMESPACE = 'api';
205
576
  // Initialize and create provider if needed
206
577
 
207
- export { API_NAMESPACE, AirmetPhenomena, CloudLevelUnits, Direction, LevelUnits, MovementUnit, ProductStatus, SigmetPhenomena, VisibilityCause, WindUnit, getHeaders, useAuthQuery };
578
+ export { API_NAMESPACE, AirmetPhenomena, CloudLevelUnits, Direction, LevelUnits, MovementUnit, ProductStatus, SigmetPhenomena, VisibilityCause, WindUnit, getHeaders, handleResponse, optimisticUpdate, useAuthQuery };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeoweb/api",
3
- "version": "10.1.0",
3
+ "version": "10.2.1-spike-ol.0",
4
4
  "description": "GeoWeb API library for the opengeoweb project",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -12,6 +12,7 @@ export type ATSRLocation = string;
12
12
  export declare enum ProductStatus {
13
13
  DRAFT = "DRAFT",
14
14
  PUBLISHED = "PUBLISHED",
15
+ RENEWED = "RENEWED",
15
16
  CANCELLED = "CANCELLED",
16
17
  EXPIRED = "EXPIRED",
17
18
  DISCARDED = "DISCARDED"
@@ -27,7 +28,7 @@ export type ProductSequenceId = string;
27
28
  * 'DISCARDED': This product can be thrown away
28
29
  * 'PUBLISHED': product can be PUBLISHED
29
30
  * 'CANCELLED': product can be CANCELLED */
30
- export type ProductCanbe = 'DRAFTED' | 'DISCARDED' | 'PUBLISHED' | 'CANCELLED';
31
+ export type ProductCanbe = 'DRAFTED' | 'DISCARDED' | 'PUBLISHED' | 'RENEWED' | 'CANCELLED';
31
32
  export type ObservationOrForcast = 'OBS' | 'FCST';
32
33
  export declare enum LevelUnits {
33
34
  'FT' = "ft",
package/src/utils.d.ts CHANGED
@@ -1,4 +1,12 @@
1
- import { UseQueryResult } from '@tanstack/react-query';
1
+ import { MutationOptions, QueryClient, UseQueryResult } from '@tanstack/react-query';
2
2
  import { Credentials } from '@opengeoweb/authentication';
3
3
  export declare const getHeaders: (auth: Credentials) => HeadersInit;
4
- export declare const useAuthQuery: <T>(queryKey: string[], queryFn: (auth: Credentials) => Promise<T>, disabled?: boolean) => UseQueryResult<T>;
4
+ export declare const handleResponse: (response: Response) => Promise<any>;
5
+ export declare const useAuthQuery: <T>(queryKey: string[], queryFn: (auth: Credentials) => Promise<T>, disabled?: boolean, refetchInterval?: number | false) => UseQueryResult<T>;
6
+ export declare const optimisticUpdate: <U extends {
7
+ id?: string | undefined;
8
+ }, T extends {
9
+ id: string;
10
+ }>(updatedQueryKey: string[], queryClient: QueryClient, optimisticUpdate: (oldValue: U, variables: T) => U, errorCallback?: (err: Error) => void) => MutationOptions<object, Error, T, {
11
+ oldData: U[] | undefined;
12
+ }>;