ng-http-caching 19.0.1 → 21.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.
@@ -1,13 +1,56 @@
1
- import { InjectionToken } from '@angular/core';
2
- import { HttpRequest, HttpResponse, HttpEvent, HttpContextToken, HttpContext, HttpHeaders } from '@angular/common/http';
3
- import { Observable } from 'rxjs/internal/Observable';
4
- import { NgHttpCachingStorageInterface } from './storage/ng-http-caching-storage.interface';
5
- import * as i0 from "@angular/core";
6
- export type NgHttpCachingContext = Pick<NgHttpCachingConfig, 'getKey' | 'isCacheable' | 'isExpired' | 'isValid'>;
7
- export declare const NG_HTTP_CACHING_CONTEXT: HttpContextToken<NgHttpCachingContext>;
8
- export declare const withNgHttpCachingContext: (value: NgHttpCachingContext, context?: HttpContext) => HttpContext;
9
- export declare const checkCacheHeaders: (headers: HttpHeaders) => boolean;
10
- export interface NgHttpCachingEntry<K = any, T = any> {
1
+ import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent, HttpResponse, HttpContextToken, HttpContext, HttpHeaders } from '@angular/common/http';
2
+ import { Observable } from 'rxjs';
3
+ import * as i0 from '@angular/core';
4
+ import { InjectionToken, ModuleWithProviders } from '@angular/core';
5
+ import { Observable as Observable$1 } from 'rxjs/internal/Observable';
6
+
7
+ declare class NgHttpCachingInterceptorService implements HttpInterceptor {
8
+ private readonly cacheService;
9
+ intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>;
10
+ /**
11
+ * Send http request (next handler)
12
+ */
13
+ sendRequest(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>;
14
+ static ɵfac: i0.ɵɵFactoryDeclaration<NgHttpCachingInterceptorService, never>;
15
+ static ɵprov: i0.ɵɵInjectableDeclaration<NgHttpCachingInterceptorService>;
16
+ }
17
+
18
+ interface NgHttpCachingStorageInterface {
19
+ /**
20
+ * The number of cached entries.
21
+ */
22
+ readonly size: number;
23
+ /**
24
+ * Clear the cache.
25
+ */
26
+ clear(): void;
27
+ /**
28
+ * Delete the cache entry for the provided key.
29
+ */
30
+ delete(key: string): boolean;
31
+ /**
32
+ * The forEach() method executes a provided function once for each cache entry.
33
+ */
34
+ forEach<K = any, T = any>(callbackfn: (value: NgHttpCachingEntry<K, T>, key: string) => void): void;
35
+ /**
36
+ * Return the cache entry for the provided key.
37
+ */
38
+ get<K = any, T = any>(key: string): Readonly<NgHttpCachingEntry<K, T>> | undefined;
39
+ /**
40
+ * Return true if the cache entry exists the provided key.
41
+ */
42
+ has(key: string): boolean;
43
+ /**
44
+ * Set the cache entry for the provided key.
45
+ */
46
+ set<K = any, T = any>(key: string, value: NgHttpCachingEntry<K, T>): void;
47
+ }
48
+
49
+ type NgHttpCachingContext = Pick<NgHttpCachingConfig, 'getKey' | 'isCacheable' | 'isExpired' | 'isValid'>;
50
+ declare const NG_HTTP_CACHING_CONTEXT: HttpContextToken<NgHttpCachingContext>;
51
+ declare const withNgHttpCachingContext: (value: NgHttpCachingContext, context?: HttpContext) => HttpContext;
52
+ declare const checkCacheHeaders: (headers: HttpHeaders) => boolean;
53
+ interface NgHttpCachingEntry<K = any, T = any> {
11
54
  /**
12
55
  * URL
13
56
  */
@@ -29,45 +72,47 @@ export interface NgHttpCachingEntry<K = any, T = any> {
29
72
  */
30
73
  version: string;
31
74
  }
32
- export declare const NG_HTTP_CACHING_CONFIG: InjectionToken<NgHttpCachingContext>;
33
- export declare enum NgHttpCachingStrategy {
75
+ declare const NG_HTTP_CACHING_CONFIG: InjectionToken<NgHttpCachingContext>;
76
+ declare const NgHttpCachingStrategy: {
34
77
  /**
35
78
  * All request are cacheable if HTTP method is into `allowedMethod`
36
79
  */
37
- ALLOW_ALL = "ALLOW_ALL",
80
+ ALLOW_ALL: string;
38
81
  /**
39
82
  * Only the request with `X-NG-HTTP-CACHING-ALLOW-CACHE` header are cacheable if HTTP method is into `allowedMethod`
40
83
  */
41
- DISALLOW_ALL = "DISALLOW_ALL"
42
- }
43
- export declare enum NgHttpCachingHeaders {
84
+ DISALLOW_ALL: string;
85
+ };
86
+ type NgHttpCachingStrategy = typeof NgHttpCachingStrategy[keyof typeof NgHttpCachingStrategy];
87
+ declare const NgHttpCachingHeaders: {
44
88
  /**
45
89
  * Request is cacheable if HTTP method is into `allowedMethod`
46
90
  */
47
- ALLOW_CACHE = "X-NG-HTTP-CACHING-ALLOW-CACHE",
91
+ ALLOW_CACHE: string;
48
92
  /**
49
93
  * Request isn't cacheable
50
94
  */
51
- DISALLOW_CACHE = "X-NG-HTTP-CACHING-DISALLOW-CACHE",
95
+ DISALLOW_CACHE: string;
52
96
  /**
53
97
  * Specific cache lifetime for the request
54
98
  */
55
- LIFETIME = "X-NG-HTTP-CACHING-LIFETIME",
99
+ LIFETIME: string;
56
100
  /**
57
101
  * You can tag multiple request by adding this header with the same tag and
58
102
  * using `NgHttpCachingService.clearCacheByTag(tag: string)` for delete all the tagged request
59
103
  */
60
- TAG = "X-NG-HTTP-CACHING-TAG"
61
- }
62
- export declare const NgHttpCachingHeadersList: NgHttpCachingHeaders[];
63
- export declare const NG_HTTP_CACHING_SECOND_IN_MS = 1000;
64
- export declare const NG_HTTP_CACHING_MINUTE_IN_MS: number;
65
- export declare const NG_HTTP_CACHING_HOUR_IN_MS: number;
66
- export declare const NG_HTTP_CACHING_DAY_IN_MS: number;
67
- export declare const NG_HTTP_CACHING_WEEK_IN_MS: number;
68
- export declare const NG_HTTP_CACHING_MONTH_IN_MS: number;
69
- export declare const NG_HTTP_CACHING_YEAR_IN_MS: number;
70
- export interface NgHttpCachingConfig {
104
+ TAG: string;
105
+ };
106
+ type NgHttpCachingHeaders = typeof NgHttpCachingHeaders[keyof typeof NgHttpCachingHeaders];
107
+ declare const NgHttpCachingHeadersList: string[];
108
+ declare const NG_HTTP_CACHING_SECOND_IN_MS = 1000;
109
+ declare const NG_HTTP_CACHING_MINUTE_IN_MS: number;
110
+ declare const NG_HTTP_CACHING_HOUR_IN_MS: number;
111
+ declare const NG_HTTP_CACHING_DAY_IN_MS: number;
112
+ declare const NG_HTTP_CACHING_WEEK_IN_MS: number;
113
+ declare const NG_HTTP_CACHING_MONTH_IN_MS: number;
114
+ declare const NG_HTTP_CACHING_YEAR_IN_MS: number;
115
+ interface NgHttpCachingConfig {
71
116
  /**
72
117
  * Set the cache store. You can implement your custom store by implement the `NgHttpCachingStorageInterface` interface, eg.:
73
118
  */
@@ -122,7 +167,7 @@ export interface NgHttpCachingConfig {
122
167
  */
123
168
  isValid?: <K, T>(entry: NgHttpCachingEntry<K, T>) => boolean | undefined | void;
124
169
  }
125
- export interface NgHttpCachingDefaultConfig extends NgHttpCachingConfig {
170
+ interface NgHttpCachingDefaultConfig extends NgHttpCachingConfig {
126
171
  store: NgHttpCachingStorageInterface;
127
172
  lifetime: number;
128
173
  allowedMethod: string[];
@@ -130,8 +175,8 @@ export interface NgHttpCachingDefaultConfig extends NgHttpCachingConfig {
130
175
  version: string;
131
176
  checkResponseHeaders: boolean;
132
177
  }
133
- export declare const NgHttpCachingConfigDefault: Readonly<NgHttpCachingDefaultConfig>;
134
- export declare class NgHttpCachingService {
178
+ declare const NgHttpCachingConfigDefault: Readonly<NgHttpCachingDefaultConfig>;
179
+ declare class NgHttpCachingService {
135
180
  private readonly queue;
136
181
  private readonly config;
137
182
  private gcLock;
@@ -144,7 +189,7 @@ export declare class NgHttpCachingService {
144
189
  /**
145
190
  * Return the queue map
146
191
  */
147
- getQueue(): Readonly<Map<string, Observable<HttpEvent<any>>>>;
192
+ getQueue(): Readonly<Map<string, Observable$1<HttpEvent<any>>>>;
148
193
  /**
149
194
  * Return the cache store
150
195
  */
@@ -207,11 +252,11 @@ export declare class NgHttpCachingService {
207
252
  /**
208
253
  * Return observable from cache
209
254
  */
210
- getFromQueue<K, T>(req: HttpRequest<K>): Observable<HttpEvent<T>> | undefined;
255
+ getFromQueue<K, T>(req: HttpRequest<K>): Observable$1<HttpEvent<T>> | undefined;
211
256
  /**
212
257
  * Add observable to cache
213
258
  */
214
- addToQueue<K, T>(req: HttpRequest<K>, obs: Observable<HttpEvent<T>>): void;
259
+ addToQueue<K, T>(req: HttpRequest<K>, obs: Observable$1<HttpEvent<T>>): void;
215
260
  /**
216
261
  * Delete observable from cache
217
262
  */
@@ -225,3 +270,53 @@ export declare class NgHttpCachingService {
225
270
  static ɵfac: i0.ɵɵFactoryDeclaration<NgHttpCachingService, never>;
226
271
  static ɵprov: i0.ɵɵInjectableDeclaration<NgHttpCachingService>;
227
272
  }
273
+
274
+ declare class NgHttpCachingModule {
275
+ static forRoot(ngHttpCachingConfig?: NgHttpCachingConfig): ModuleWithProviders<NgHttpCachingModule>;
276
+ static ɵfac: i0.ɵɵFactoryDeclaration<NgHttpCachingModule, never>;
277
+ static ɵmod: i0.ɵɵNgModuleDeclaration<NgHttpCachingModule, never, never, never>;
278
+ static ɵinj: i0.ɵɵInjectorDeclaration<NgHttpCachingModule>;
279
+ }
280
+
281
+ declare function provideNgHttpCaching(ngHttpCachingConfig?: NgHttpCachingConfig): i0.EnvironmentProviders;
282
+
283
+ declare class NgHttpCachingMemoryStorage extends Map<string, NgHttpCachingEntry<any, any>> implements NgHttpCachingStorageInterface {
284
+ }
285
+
286
+ interface NgHttpCachingStorageEntry {
287
+ url: string;
288
+ response: string;
289
+ request: string;
290
+ addedTime: number;
291
+ version: string;
292
+ }
293
+ declare const serializeRequest: (req: HttpRequest<any>) => string;
294
+ declare const serializeResponse: (res: HttpResponse<any>) => string;
295
+ declare const deserializeRequest: <T = any>(req: string) => HttpRequest<T>;
296
+ declare const deserializeResponse: <T = any>(res: string) => HttpResponse<T>;
297
+ declare class NgHttpCachingBrowserStorage implements NgHttpCachingStorageInterface {
298
+ private storage;
299
+ constructor(storage: Storage);
300
+ get size(): number;
301
+ clear(): void;
302
+ delete(key: string): boolean;
303
+ forEach(callbackfn: (value: NgHttpCachingEntry, key: string) => void): void;
304
+ get(key: string): Readonly<NgHttpCachingEntry> | undefined;
305
+ has(key: string): boolean;
306
+ set(key: string, value: NgHttpCachingEntry): void;
307
+ protected serialize(value: NgHttpCachingEntry): NgHttpCachingStorageEntry;
308
+ protected deserialize(value: NgHttpCachingStorageEntry): NgHttpCachingEntry;
309
+ }
310
+
311
+ declare class NgHttpCachingLocalStorage extends NgHttpCachingBrowserStorage {
312
+ constructor();
313
+ }
314
+ declare const withNgHttpCachingLocalStorage: () => NgHttpCachingLocalStorage;
315
+
316
+ declare class NgHttpCachingSessionStorage extends NgHttpCachingBrowserStorage {
317
+ constructor();
318
+ }
319
+ declare const withNgHttpCachingSessionStorage: () => NgHttpCachingSessionStorage;
320
+
321
+ export { NG_HTTP_CACHING_CONFIG, NG_HTTP_CACHING_CONTEXT, NG_HTTP_CACHING_DAY_IN_MS, NG_HTTP_CACHING_HOUR_IN_MS, NG_HTTP_CACHING_MINUTE_IN_MS, NG_HTTP_CACHING_MONTH_IN_MS, NG_HTTP_CACHING_SECOND_IN_MS, NG_HTTP_CACHING_WEEK_IN_MS, NG_HTTP_CACHING_YEAR_IN_MS, NgHttpCachingBrowserStorage, NgHttpCachingConfigDefault, NgHttpCachingHeaders, NgHttpCachingHeadersList, NgHttpCachingInterceptorService, NgHttpCachingLocalStorage, NgHttpCachingMemoryStorage, NgHttpCachingModule, NgHttpCachingService, NgHttpCachingSessionStorage, NgHttpCachingStrategy, checkCacheHeaders, deserializeRequest, deserializeResponse, provideNgHttpCaching, serializeRequest, serializeResponse, withNgHttpCachingContext, withNgHttpCachingLocalStorage, withNgHttpCachingSessionStorage };
322
+ export type { NgHttpCachingConfig, NgHttpCachingContext, NgHttpCachingDefaultConfig, NgHttpCachingEntry, NgHttpCachingStorageEntry, NgHttpCachingStorageInterface };
package/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * Generated bundle index. Do not edit.
3
- */
4
- /// <amd-module name="ng-http-caching" />
5
- export * from './public-api';
@@ -1,13 +0,0 @@
1
- import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
2
- import { Observable } from 'rxjs';
3
- import * as i0 from "@angular/core";
4
- export declare class NgHttpCachingInterceptorService implements HttpInterceptor {
5
- private readonly cacheService;
6
- intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>;
7
- /**
8
- * Send http request (next handler)
9
- */
10
- sendRequest(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>;
11
- static ɵfac: i0.ɵɵFactoryDeclaration<NgHttpCachingInterceptorService, never>;
12
- static ɵprov: i0.ɵɵInjectableDeclaration<NgHttpCachingInterceptorService>;
13
- }
@@ -1,3 +0,0 @@
1
- import { EnvironmentProviders } from "@angular/core";
2
- import { NgHttpCachingConfig } from "./ng-http-caching.service";
3
- export declare function provideNgHttpCaching(ngHttpCachingConfig?: NgHttpCachingConfig): EnvironmentProviders[];
@@ -1,9 +0,0 @@
1
- import { ModuleWithProviders } from '@angular/core';
2
- import { NgHttpCachingConfig } from './ng-http-caching.service';
3
- import * as i0 from "@angular/core";
4
- export declare class NgHttpCachingModule {
5
- static forRoot(ngHttpCachingConfig?: NgHttpCachingConfig): ModuleWithProviders<NgHttpCachingModule>;
6
- static ɵfac: i0.ɵɵFactoryDeclaration<NgHttpCachingModule, never>;
7
- static ɵmod: i0.ɵɵNgModuleDeclaration<NgHttpCachingModule, never, never, never>;
8
- static ɵinj: i0.ɵɵInjectorDeclaration<NgHttpCachingModule>;
9
- }
@@ -1,27 +0,0 @@
1
- import { NgHttpCachingStorageInterface } from './ng-http-caching-storage.interface';
2
- import { NgHttpCachingEntry } from '../ng-http-caching.service';
3
- import { HttpRequest, HttpResponse } from '@angular/common/http';
4
- export interface NgHttpCachingStorageEntry {
5
- url: string;
6
- response: string;
7
- request: string;
8
- addedTime: number;
9
- version: string;
10
- }
11
- export declare const serializeRequest: (req: HttpRequest<any>) => string;
12
- export declare const serializeResponse: (res: HttpResponse<any>) => string;
13
- export declare const deserializeRequest: <T = any>(req: string) => HttpRequest<T>;
14
- export declare const deserializeResponse: <T = any>(res: string) => HttpResponse<T>;
15
- export declare class NgHttpCachingBrowserStorage implements NgHttpCachingStorageInterface {
16
- private storage;
17
- constructor(storage: Storage);
18
- get size(): number;
19
- clear(): void;
20
- delete(key: string): boolean;
21
- forEach(callbackfn: (value: NgHttpCachingEntry, key: string) => void): void;
22
- get(key: string): Readonly<NgHttpCachingEntry> | undefined;
23
- has(key: string): boolean;
24
- set(key: string, value: NgHttpCachingEntry): void;
25
- protected serialize(value: NgHttpCachingEntry): NgHttpCachingStorageEntry;
26
- protected deserialize(value: NgHttpCachingStorageEntry): NgHttpCachingEntry;
27
- }
@@ -1,5 +0,0 @@
1
- import { NgHttpCachingBrowserStorage } from './ng-http-caching-browser-storage';
2
- export declare class NgHttpCachingLocalStorage extends NgHttpCachingBrowserStorage {
3
- constructor();
4
- }
5
- export declare const withNgHttpCachingLocalStorage: () => NgHttpCachingLocalStorage;
@@ -1,4 +0,0 @@
1
- import { NgHttpCachingStorageInterface } from './ng-http-caching-storage.interface';
2
- import { NgHttpCachingEntry } from '../ng-http-caching.service';
3
- export declare class NgHttpCachingMemoryStorage extends Map<string, NgHttpCachingEntry<any, any>> implements NgHttpCachingStorageInterface {
4
- }
@@ -1,5 +0,0 @@
1
- import { NgHttpCachingBrowserStorage } from './ng-http-caching-browser-storage';
2
- export declare class NgHttpCachingSessionStorage extends NgHttpCachingBrowserStorage {
3
- constructor();
4
- }
5
- export declare const withNgHttpCachingSessionStorage: () => NgHttpCachingSessionStorage;
@@ -1,31 +0,0 @@
1
- import { NgHttpCachingEntry } from '../ng-http-caching.service';
2
- export interface NgHttpCachingStorageInterface {
3
- /**
4
- * The number of cached entries.
5
- */
6
- readonly size: number;
7
- /**
8
- * Clear the cache.
9
- */
10
- clear(): void;
11
- /**
12
- * Delete the cache entry for the provided key.
13
- */
14
- delete(key: string): boolean;
15
- /**
16
- * The forEach() method executes a provided function once for each cache entry.
17
- */
18
- forEach<K = any, T = any>(callbackfn: (value: NgHttpCachingEntry<K, T>, key: string) => void): void;
19
- /**
20
- * Return the cache entry for the provided key.
21
- */
22
- get<K = any, T = any>(key: string): Readonly<NgHttpCachingEntry<K, T>> | undefined;
23
- /**
24
- * Return true if the cache entry exists the provided key.
25
- */
26
- has(key: string): boolean;
27
- /**
28
- * Set the cache entry for the provided key.
29
- */
30
- set<K = any, T = any>(key: string, value: NgHttpCachingEntry<K, T>): void;
31
- }
package/public-api.d.ts DELETED
@@ -1,9 +0,0 @@
1
- export * from './lib/ng-http-caching-interceptor.service';
2
- export * from './lib/ng-http-caching.service';
3
- export * from './lib/ng-http-caching.module';
4
- export * from './lib/ng-http-caching-provider';
5
- export * from './lib/storage/ng-http-caching-storage.interface';
6
- export * from './lib/storage/ng-http-caching-memory-storage';
7
- export * from './lib/storage/ng-http-caching-local-storage';
8
- export * from './lib/storage/ng-http-caching-session-storage';
9
- export * from './lib/storage/ng-http-caching-browser-storage';