ng2-rest 19.0.44 → 19.0.46
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 +136 -136
- package/browser/README.md +24 -24
- package/browser/fesm2022/ng2-rest.mjs.map +1 -1
- package/browser/package.json +1 -1
- package/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.js +1 -1
- package/lib/request-cache.d.ts +18 -0
- package/lib/request-cache.js +118 -0
- package/lib/request-cache.js.map +1 -0
- package/package.json +1 -1
- package/websql/README.md +24 -24
- package/websql/fesm2022/ng2-rest.mjs.map +1 -1
- package/websql/package.json +1 -1
package/browser/package.json
CHANGED
|
@@ -21,6 +21,6 @@ exports.PROJECT_NPM_NAME = 'ng2-rest';
|
|
|
21
21
|
/**
|
|
22
22
|
* Autogenerated by current cli tool. Use *tnp release* to bump version.
|
|
23
23
|
*/
|
|
24
|
-
exports.CURRENT_PACKAGE_VERSION = '19.0.
|
|
24
|
+
exports.CURRENT_PACKAGE_VERSION = '19.0.46';
|
|
25
25
|
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
26
26
|
//# sourceMappingURL=build-info._auto-generated_.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Models } from './models';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated
|
|
4
|
+
* there is Cache API for that
|
|
5
|
+
*/
|
|
6
|
+
export declare class RequestCache {
|
|
7
|
+
response: Models.HttpResponse<any>;
|
|
8
|
+
static readonly LOCAL_STORAGE_KEY = "ng2restrequestcache";
|
|
9
|
+
private static cached;
|
|
10
|
+
private static isRestoredFromLocalStorage;
|
|
11
|
+
private static restoreFromLocalStorage;
|
|
12
|
+
static findBy(sourceRequest: Models.HandleResultSourceRequestOptions): RequestCache;
|
|
13
|
+
constructor(response: Models.HttpResponse<any>);
|
|
14
|
+
get containsCache(): boolean;
|
|
15
|
+
private persistsInLocalStorage;
|
|
16
|
+
store(): this;
|
|
17
|
+
remove(): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequestCache = void 0;
|
|
4
|
+
const lib_1 = require("tnp-core/lib");
|
|
5
|
+
const models_1 = require("./models");
|
|
6
|
+
const lib_2 = require("tnp-core/lib");
|
|
7
|
+
const rest_headers_1 = require("./rest-headers");
|
|
8
|
+
// const log = Log.create('request-cache', Level.__NOTHING);
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated
|
|
11
|
+
* there is Cache API for that
|
|
12
|
+
*/
|
|
13
|
+
class RequestCache {
|
|
14
|
+
response;
|
|
15
|
+
static LOCAL_STORAGE_KEY = 'ng2restrequestcache';
|
|
16
|
+
static cached = [];
|
|
17
|
+
static isRestoredFromLocalStorage = false;
|
|
18
|
+
static restoreFromLocalStorage() {
|
|
19
|
+
if (lib_1.UtilsOs.isSSRMode) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (lib_2.Helpers.isNode) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (!RequestCache.isRestoredFromLocalStorage) {
|
|
26
|
+
RequestCache.isRestoredFromLocalStorage = true;
|
|
27
|
+
const data = localStorage.getItem(RequestCache.LOCAL_STORAGE_KEY);
|
|
28
|
+
let requests = [];
|
|
29
|
+
if (data) {
|
|
30
|
+
try {
|
|
31
|
+
requests = JSON.parse(data);
|
|
32
|
+
}
|
|
33
|
+
catch (error) { }
|
|
34
|
+
const restored = requests.map(r => {
|
|
35
|
+
let { sourceRequest, responseText, body, headers, circular, entity, isArray, cookies, statusCode, } = r.response;
|
|
36
|
+
r.response = new models_1.Models.HttpResponse(sourceRequest, responseText, rest_headers_1.RestHeaders.from(headers), statusCode, entity, circular, -1, // jobid from local storage TODO
|
|
37
|
+
isArray);
|
|
38
|
+
r = new RequestCache(r.response);
|
|
39
|
+
r.response.rq = r;
|
|
40
|
+
return r;
|
|
41
|
+
});
|
|
42
|
+
// log.i('RESTORED FROM LOCAL STORAGE', restored);
|
|
43
|
+
RequestCache.cached = restored;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
static findBy(sourceRequest) {
|
|
48
|
+
if (lib_1.UtilsOs.isSSRMode) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
// log.i('findby', sourceRequest);
|
|
52
|
+
// log.i('RequestCache.cached', RequestCache.cached);
|
|
53
|
+
RequestCache.restoreFromLocalStorage();
|
|
54
|
+
return RequestCache.cached.find(c => {
|
|
55
|
+
const a = c.response.sourceRequest;
|
|
56
|
+
const b = sourceRequest;
|
|
57
|
+
return (a.isArray === b.isArray &&
|
|
58
|
+
a.url === b.url &&
|
|
59
|
+
a.method === b.method &&
|
|
60
|
+
a.body === b.body);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
constructor(response) {
|
|
64
|
+
this.response = response;
|
|
65
|
+
}
|
|
66
|
+
get containsCache() {
|
|
67
|
+
RequestCache.restoreFromLocalStorage();
|
|
68
|
+
return RequestCache.cached.includes(this);
|
|
69
|
+
}
|
|
70
|
+
persistsInLocalStorage() {
|
|
71
|
+
if (lib_1.UtilsOs.isSSRMode) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
localStorage.setItem(RequestCache.LOCAL_STORAGE_KEY, JSON.stringify(RequestCache.cached.map(r => {
|
|
75
|
+
return {
|
|
76
|
+
response: {
|
|
77
|
+
sourceRequest: r.response.sourceRequest,
|
|
78
|
+
responseText: r.response.responseText,
|
|
79
|
+
headers: r.response.headers,
|
|
80
|
+
statusCode: r.response.statusCode,
|
|
81
|
+
entity: r.response.entity,
|
|
82
|
+
circular: r.response.circular,
|
|
83
|
+
isArray: r.response.isArray,
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
})));
|
|
87
|
+
}
|
|
88
|
+
store() {
|
|
89
|
+
if (lib_1.UtilsOs.isSSRMode) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
RequestCache.restoreFromLocalStorage();
|
|
93
|
+
if (!this.containsCache) {
|
|
94
|
+
RequestCache.cached.push(this);
|
|
95
|
+
this.persistsInLocalStorage();
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
console.log('already stored');
|
|
99
|
+
}
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
remove() {
|
|
103
|
+
if (lib_1.UtilsOs.isSSRMode) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
RequestCache.restoreFromLocalStorage();
|
|
107
|
+
const index = RequestCache.cached.indexOf(this);
|
|
108
|
+
if (index !== -1) {
|
|
109
|
+
RequestCache.cached.splice(index, 1);
|
|
110
|
+
this.persistsInLocalStorage();
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
console.log('already removed');
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.RequestCache = RequestCache;
|
|
118
|
+
//# sourceMappingURL=request-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-cache.js","sourceRoot":"","sources":[""],"names":[],"mappings":";;;AAAA,sCAA0C;AAC1C,qCAAkC;AAElC,sCAAuC;AACvC,iDAA6C;AAC7C,4DAA4D;AAE5D;;;GAGG;AACH,MAAa,YAAY;IAyEJ;IAxEnB,MAAM,CAAU,iBAAiB,GAAG,qBAAqB,CAAC;IAElD,MAAM,CAAC,MAAM,GAAmB,EAAE,CAAC;IACnC,MAAM,CAAC,0BAA0B,GAAG,KAAK,CAAC;IAE1C,MAAM,CAAC,uBAAuB;QACpC,IAAI,aAAO,CAAC,SAAS,EAAE,CAAC;YACtB,OAAO;QACT,CAAC;QACD,IAAI,aAAO,CAAC,MAAM,EAAE,CAAC;YACnB,OAAO;QACT,CAAC;QACD,IAAI,CAAC,YAAY,CAAC,0BAA0B,EAAE,CAAC;YAC7C,YAAY,CAAC,0BA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C;IAED,KAAK;QACH,IAAI,aAAO,CAAC,SAAS,EAAE,CAAC;YACtB,OAAO;QACT,CAAC;QACD,YAAY,CAAC,uBAAuB,EAAE,CAAC;QACvC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;YACxB,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC/B,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAChC,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAChC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM;QACJ,IAAI,aAAO,CAAC,SAAS,EAAE,CAAC;YACtB,OAAO;QACT,CAAC;QACD,YAAY,CAAC,uBAAuB,EAAE,CAAC;QACvC,MAAM,KAAK,GAAG,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAChD,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;YACjB,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;YACrC,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAChC,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;;AAlIH,oCAmIC"}
|
package/package.json
CHANGED
package/websql/README.md
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
# MyLib
|
|
2
|
-
|
|
3
|
-
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 13.2.0.
|
|
4
|
-
|
|
5
|
-
## Code scaffolding
|
|
6
|
-
|
|
7
|
-
Run `ng generate component component-name --project my-lib` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project my-lib`.
|
|
8
|
-
> Note: Don't forget to add `--project my-lib` or else it will be added to the default project in your `angular.json` file.
|
|
9
|
-
|
|
10
|
-
## Build
|
|
11
|
-
|
|
12
|
-
Run `ng build my-lib` to build the project. The build artifacts will be stored in the `dist/` directory.
|
|
13
|
-
|
|
14
|
-
## Publishing
|
|
15
|
-
|
|
16
|
-
After building your library with `ng build my-lib`, go to the dist folder `cd dist/my-lib` and run `npm publish`.
|
|
17
|
-
|
|
18
|
-
## Running unit tests
|
|
19
|
-
|
|
20
|
-
Run `ng test my-lib` to execute the unit tests via [Karma](https://karma-runner.github.io).
|
|
21
|
-
|
|
22
|
-
## Further help
|
|
23
|
-
|
|
24
|
-
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
|
|
1
|
+
# MyLib
|
|
2
|
+
|
|
3
|
+
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 13.2.0.
|
|
4
|
+
|
|
5
|
+
## Code scaffolding
|
|
6
|
+
|
|
7
|
+
Run `ng generate component component-name --project my-lib` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project my-lib`.
|
|
8
|
+
> Note: Don't forget to add `--project my-lib` or else it will be added to the default project in your `angular.json` file.
|
|
9
|
+
|
|
10
|
+
## Build
|
|
11
|
+
|
|
12
|
+
Run `ng build my-lib` to build the project. The build artifacts will be stored in the `dist/` directory.
|
|
13
|
+
|
|
14
|
+
## Publishing
|
|
15
|
+
|
|
16
|
+
After building your library with `ng build my-lib`, go to the dist folder `cd dist/my-lib` and run `npm publish`.
|
|
17
|
+
|
|
18
|
+
## Running unit tests
|
|
19
|
+
|
|
20
|
+
Run `ng test my-lib` to execute the unit tests via [Karma](https://karma-runner.github.io).
|
|
21
|
+
|
|
22
|
+
## Further help
|
|
23
|
+
|
|
24
|
+
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
|