@livequery/rest 2.0.15 → 2.0.18

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.
@@ -2,10 +2,17 @@ import { pipe, mergeMap, BehaviorSubject, tap, of, filter, first } from "rxjs";
2
2
  const requests = new Map();
3
3
  export const Deduplicate = (ms = 1000) => next => {
4
4
  return pipe(mergeMap(async (r) => {
5
+ if (r.options.method == 'GET')
6
+ return of(r);
5
7
  const url = r.url.toString();
6
8
  const cached = requests.get(url);
7
- if (cached && cached.time > Date.now() - ms) {
8
- return cached.response.pipe(filter(Boolean), first());
9
+ if (cached) {
10
+ if (cached.time > Date.now() - ms) {
11
+ return cached.response.pipe(filter(Boolean), first());
12
+ }
13
+ else {
14
+ requests.delete(url);
15
+ }
9
16
  }
10
17
  requests.set(url, {
11
18
  response: new BehaviorSubject(undefined),
@@ -13,7 +20,6 @@ export const Deduplicate = (ms = 1000) => next => {
13
20
  });
14
21
  return of(r).pipe(next(), tap(response => {
15
22
  requests.get(url)?.response.next(response);
16
- requests.delete(url);
17
23
  }));
18
24
  }), mergeMap($ => $));
19
25
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "repository": {
4
4
  "url": "https://github.com/livequery/rest"
5
5
  },
6
- "version": "2.0.15",
6
+ "version": "2.0.18",
7
7
  "type": "module",
8
8
  "description": "",
9
9
  "main": "build/index.js",
@@ -1,2 +0,0 @@
1
- import { ApiRequest } from "./RestTransporter";
2
- export declare const AddHeadersHook: (get_headers: any) => (next: any) => import("rxjs").UnaryFunction<import("rxjs").Observable<ApiRequest>, unknown>;
@@ -1,16 +0,0 @@
1
- import { pipe, mergeMap } from "rxjs";
2
- export const AddHeadersHook = (get_headers) => {
3
- return next => pipe(mergeMap(async (r) => {
4
- const headers = typeof get_headers == 'function' ? await get_headers() : get_headers;
5
- return {
6
- ...r,
7
- options: {
8
- ...r.options || {},
9
- headers: {
10
- ...r.options?.headers || {},
11
- ...headers
12
- }
13
- }
14
- };
15
- }), next());
16
- };
@@ -1,2 +0,0 @@
1
- import { ApiRequest } from "./RestTransporter";
2
- export declare const AddHeadersHook: (headers?: any) => (next: any) => import("rxjs").UnaryFunction<import("rxjs").Observable<ApiRequest>, unknown>;
@@ -1,12 +0,0 @@
1
- import { pipe, mergeMap } from "rxjs";
2
- export const AddHeadersHook = (headers = {}) => {
3
- return next => pipe(mergeMap(async (r) => {
4
- const obj = r.options?.headers;
5
- if (obj) {
6
- for (const [k, v] of Object.entries(headers)) {
7
- headers[k] = v;
8
- }
9
- }
10
- return r;
11
- }), next());
12
- };
File without changes
File without changes