ngx-api-cache 20.0.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 ADDED
@@ -0,0 +1,44 @@
1
+ # ngx-api-cache
2
+
3
+ This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 20.3.2.
4
+
5
+ ## Description
6
+
7
+ This is a very lightweight library for vertical scrolling.
8
+
9
+ This library does not require third party dependencies
10
+
11
+ ### USAGE
12
+
13
+ 1. Install
14
+
15
+ ```bash
16
+ npm i ngx-api-cache or
17
+ ```
18
+ OR
19
+
20
+ ```bash
21
+ yarn add ngx-api-cache
22
+ ```
23
+
24
+ 2. Import to your component or module this component:
25
+
26
+ ```bash
27
+ NgxScrollbarUltimateComponent
28
+ ```
29
+
30
+ 3. Add to your code:
31
+
32
+ ```bash
33
+ <ngx-api-cache>
34
+ your content
35
+ </ngx-api-cache>
36
+ ```
37
+ 4. Add visibility 'hover', if you need.
38
+
39
+ ```bash
40
+ <ngx-api-cache visibility = 'hover'>
41
+ your content
42
+ </ngx-api-cache>
43
+ ```
44
+ P.S: the container must have a height in the styles
@@ -0,0 +1,72 @@
1
+ import { HttpClient } from '@angular/common/http';
2
+ import * as i0 from '@angular/core';
3
+ import { inject, signal, Injectable } from '@angular/core';
4
+ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
5
+ import { catchError, throwError } from 'rxjs';
6
+
7
+ class NgxApiCacheService {
8
+ http = inject(HttpClient);
9
+ cache = new Map();
10
+ get(url, destroyRef) {
11
+ if (!this.cache.has(url)) {
12
+ const entry = {
13
+ data: signal(null),
14
+ loading: signal(true),
15
+ error: signal(null)
16
+ };
17
+ this.cache.set(url, entry);
18
+ this.request(url, entry, destroyRef);
19
+ }
20
+ const entry = this.cache.get(url);
21
+ return {
22
+ data: entry.data.asReadonly(),
23
+ loading: entry.loading.asReadonly(),
24
+ error: entry.error.asReadonly(),
25
+ refresh: () => {
26
+ entry.loading.set(true);
27
+ entry.error.set(null);
28
+ this.request(url, entry, destroyRef);
29
+ },
30
+ patch: (updater) => {
31
+ const current = entry.data();
32
+ const newValue = updater(current);
33
+ entry.data.set(newValue);
34
+ }
35
+ };
36
+ }
37
+ request(url, entry, destroyRef) {
38
+ let obs$ = this.http.get(url).pipe(catchError(error => {
39
+ entry.loading.set(false);
40
+ entry.error.set(error);
41
+ entry.data.set(null);
42
+ return throwError(() => error);
43
+ }));
44
+ if (destroyRef) {
45
+ obs$ = obs$.pipe(takeUntilDestroyed(destroyRef));
46
+ }
47
+ obs$.subscribe(resp => {
48
+ entry.loading.set(false);
49
+ entry.error.set(null);
50
+ entry.data.set(resp);
51
+ });
52
+ }
53
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: NgxApiCacheService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
54
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: NgxApiCacheService, providedIn: 'root' });
55
+ }
56
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: NgxApiCacheService, decorators: [{
57
+ type: Injectable,
58
+ args: [{
59
+ providedIn: 'root'
60
+ }]
61
+ }] });
62
+
63
+ /*
64
+ * Public API Surface of my-lib
65
+ */
66
+
67
+ /**
68
+ * Generated bundle index. Do not edit.
69
+ */
70
+
71
+ export { NgxApiCacheService };
72
+ //# sourceMappingURL=ngx-api-cache.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ngx-api-cache.mjs","sources":["../../../projects/ngx-api-cache/src/lib/ngx-api-cache.service.ts","../../../projects/ngx-api-cache/src/public-api.ts","../../../projects/ngx-api-cache/src/ngx-api-cache.ts"],"sourcesContent":["import { HttpClient } from '@angular/common/http';\nimport { Injectable, signal, inject, DestroyRef } from '@angular/core';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\nimport { catchError, throwError } from 'rxjs';\nimport { CacheEntry, CacheResult } from './types';\n\n@Injectable({\n providedIn: 'root'\n})\nexport class NgxApiCacheService {\n private http = inject(HttpClient);\n private cache = new Map<string, CacheEntry<unknown>>();\n\n public get<T>(url: string, destroyRef?: DestroyRef): CacheResult<T> {\n if (!this.cache.has(url)) {\n const entry: CacheEntry<T> = {\n data: signal(null),\n loading: signal(true),\n error: signal(null)\n };\n this.cache.set(url, entry as CacheEntry<unknown>);\n this.request(url, entry, destroyRef);\n }\n\n const entry = this.cache.get(url) as CacheEntry<T>;\n\n return {\n data: entry.data.asReadonly(),\n loading: entry.loading.asReadonly(),\n error: entry.error.asReadonly(),\n refresh: (): void => {\n entry.loading.set(true);\n entry.error.set(null);\n this.request(url, entry, destroyRef);\n },\n patch: (updater: (current: T | null) => T): void => {\n const current = entry.data();\n const newValue = updater(current);\n entry.data.set(newValue);\n }\n };\n }\n\n private request<T>(url: string, entry: CacheEntry<T>, destroyRef?: DestroyRef): void {\n let obs$ = this.http.get<T>(url).pipe(\n catchError(error => {\n entry.loading.set(false);\n entry.error.set(error);\n entry.data.set(null);\n return throwError(() => error);\n })\n );\n\n if (destroyRef) {\n obs$ = obs$.pipe(takeUntilDestroyed(destroyRef));\n }\n\n obs$.subscribe(resp => {\n entry.loading.set(false);\n entry.error.set(null);\n entry.data.set(resp);\n });\n }\n}\n","/*\n * Public API Surface of my-lib\n */\n\nexport * from './lib/ngx-api-cache.service';\nexport * from './lib/types';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;MASa,kBAAkB,CAAA;AACrB,IAAA,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC;AACzB,IAAA,KAAK,GAAG,IAAI,GAAG,EAA+B;IAE/C,GAAG,CAAI,GAAW,EAAE,UAAuB,EAAA;QAChD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;AACxB,YAAA,MAAM,KAAK,GAAkB;AAC3B,g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G,CAAC,KAAK,CAAC;AACxB,YAAA,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC;AACtB,YAAA,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;AACpB,YAAA,OAAO,UAAU,CAAC,MAAM,KAAK,CAAC;QAChC,CAAC,CAAC,CACH;QAED,IAAI,UAAU,EAAE;YACd,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC;QAClD;AAEA,QAAA,IAAI,CAAC,SAAS,CAAC,IAAI,IAAG;AACpB,YAAA,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC;AACxB,YAAA,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;AACrB,YAAA,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;AACtB,QAAA,CAAC,CAAC;IACJ;wGArDW,kBAAkB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAAlB,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,kBAAkB,cAFjB,MAAM,EAAA,CAAA;;4FAEP,kBAAkB,EAAA,UAAA,EAAA,CAAA;kBAH9B,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE;AACb,iBAAA;;;ACRD;;AAEG;;ACFH;;AAEG;;;;"}
package/index.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ import * as i0 from '@angular/core';
2
+ import { Signal, WritableSignal, DestroyRef } from '@angular/core';
3
+
4
+ interface CacheEntry<T> {
5
+ data: WritableSignal<T | null>;
6
+ loading: WritableSignal<boolean>;
7
+ error: WritableSignal<unknown | null>;
8
+ }
9
+ interface CacheResult<T> {
10
+ data: Signal<T | null>;
11
+ loading: Signal<boolean>;
12
+ error: Signal<unknown | null>;
13
+ refresh: () => void;
14
+ patch: (updater: (current: T | null) => T) => void;
15
+ }
16
+
17
+ declare class NgxApiCacheService {
18
+ private http;
19
+ private cache;
20
+ get<T>(url: string, destroyRef?: DestroyRef): CacheResult<T>;
21
+ private request;
22
+ static ɵfac: i0.ɵɵFactoryDeclaration<NgxApiCacheService, never>;
23
+ static ɵprov: i0.ɵɵInjectableDeclaration<NgxApiCacheService>;
24
+ }
25
+
26
+ export { NgxApiCacheService };
27
+ export type { CacheEntry, CacheResult };
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "ngx-api-cache",
3
+ "version": "20.0.0",
4
+ "peerDependencies": {
5
+ "@angular/common": "^20.3.1",
6
+ "@angular/core": "^20.3.1"
7
+ },
8
+ "dependencies": {
9
+ "tslib": "^2.3.0"
10
+ },
11
+ "sideEffects": false,
12
+ "funding": [
13
+ {
14
+ "type": "crypto",
15
+ "url": "https://andrew-dev283.github.io/andrew-dev.github.io/"
16
+ },
17
+ {
18
+ "type": "boosty",
19
+ "url": "https://boosty.to/hq_dev"
20
+ }
21
+ ],
22
+ "homepage": "https://github.com/andrew-dev283/ngx-api-cache",
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "https://github.com/andrew-dev283/ngx-api-cache.git"
26
+ },
27
+ "publishConfig": {
28
+ "registry": "https://registry.npmjs.org/"
29
+ },
30
+ "module": "fesm2022/ngx-api-cache.mjs",
31
+ "typings": "index.d.ts",
32
+ "exports": {
33
+ "./package.json": {
34
+ "default": "./package.json"
35
+ },
36
+ ".": {
37
+ "types": "./index.d.ts",
38
+ "default": "./fesm2022/ngx-api-cache.mjs"
39
+ }
40
+ }
41
+ }