zavadil-ts-common 1.1.81 → 1.1.83
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/dist/cache/CacheAsync.d.ts +2 -0
- package/dist/cache/HashCacheAsync.d.ts +1 -0
- package/dist/cache/Lazy.d.ts +1 -0
- package/dist/cache/LazyAsync.d.ts +2 -0
- package/dist/client/LookupClient.d.ts +2 -0
- package/dist/client/RestClient.d.ts +4 -4
- package/dist/index.d.ts +11 -4
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/cache/CacheAsync.ts +8 -0
- package/src/cache/HashCacheAsync.ts +4 -0
- package/src/cache/Lazy.ts +4 -1
- package/src/cache/LazyAsync.ts +7 -0
- package/src/client/LookupClient.ts +8 -0
- package/src/client/RestClient.ts +25 -28
package/src/client/RestClient.ts
CHANGED
@@ -16,18 +16,7 @@ export class RestClient {
|
|
16
16
|
return PagingUtil.pagingRequestToQueryParams(pr);
|
17
17
|
}
|
18
18
|
|
19
|
-
|
20
|
-
* Override this to customize http headers.
|
21
|
-
*/
|
22
|
-
getHeaders(url: string): Promise<RestClientHeaders> {
|
23
|
-
return Promise.resolve(
|
24
|
-
{
|
25
|
-
'Content-Type': 'application/json'
|
26
|
-
}
|
27
|
-
);
|
28
|
-
}
|
29
|
-
|
30
|
-
paramsToQueryString(params?: any): string {
|
19
|
+
static paramsToQueryString(params?: any): string {
|
31
20
|
if (!params) return '';
|
32
21
|
const original = new URLSearchParams(params);
|
33
22
|
const cleaned = new URLSearchParams();
|
@@ -39,10 +28,21 @@ export class RestClient {
|
|
39
28
|
return StringUtil.isEmpty(str) ? '' : `?${str}`;
|
40
29
|
}
|
41
30
|
|
31
|
+
/**
|
32
|
+
* Override this to customize http headers.
|
33
|
+
*/
|
34
|
+
getHeaders(url: string): Promise<RestClientHeaders> {
|
35
|
+
return Promise.resolve(
|
36
|
+
{
|
37
|
+
'Content-Type': 'application/json'
|
38
|
+
}
|
39
|
+
);
|
40
|
+
}
|
41
|
+
|
42
42
|
getUrl(endpoint: string, params?: any) {
|
43
43
|
let url = [StringUtil.trimTrailingSlashes(this.baseUrl), StringUtil.trimLeadingSlashes(endpoint)].join('/');
|
44
44
|
if (params) {
|
45
|
-
url = `${url}${
|
45
|
+
url = `${url}${RestClient.paramsToQueryString(params)}`;
|
46
46
|
}
|
47
47
|
return url;
|
48
48
|
}
|
@@ -61,8 +61,8 @@ export class RestClient {
|
|
61
61
|
);
|
62
62
|
}
|
63
63
|
|
64
|
-
processRequest(endpoint: string, requestOptions?: RequestInit): Promise<Response> {
|
65
|
-
return fetch(this.getUrl(endpoint), requestOptions)
|
64
|
+
processRequest(endpoint: string, params?: any, requestOptions?: RequestInit): Promise<Response> {
|
65
|
+
return fetch(this.getUrl(endpoint, params), requestOptions)
|
66
66
|
.then((response) => {
|
67
67
|
if (!response.ok) {
|
68
68
|
const options = {cause: response.status};
|
@@ -106,42 +106,39 @@ export class RestClient {
|
|
106
106
|
});
|
107
107
|
}
|
108
108
|
|
109
|
-
processRequestJson(
|
110
|
-
return this.processRequest(
|
109
|
+
processRequestJson(endpoint: string, params?: any, requestOptions?: object | undefined): Promise<any> {
|
110
|
+
return this.processRequest(endpoint, params, requestOptions)
|
111
111
|
.then((response) => {
|
112
112
|
return response.text().then(JsonUtil.parseWithDates);
|
113
113
|
});
|
114
114
|
}
|
115
115
|
|
116
116
|
getJson(url: string, params?: any): Promise<any> {
|
117
|
-
|
118
|
-
url = `${url}${this.paramsToQueryString(params)}`;
|
119
|
-
}
|
120
|
-
return this.getRequestOptions(url).then(o => this.processRequestJson(url, o));
|
117
|
+
return this.getRequestOptions(url).then(o => this.processRequestJson(url, params, o));
|
121
118
|
}
|
122
119
|
|
123
120
|
postJson(url: string, data: object | null = null): Promise<any> {
|
124
|
-
return this.getRequestOptions(url, 'POST', data).then(o => this.processRequestJson(url, o));
|
121
|
+
return this.getRequestOptions(url, 'POST', data).then(o => this.processRequestJson(url, null, o));
|
125
122
|
}
|
126
123
|
|
127
124
|
putJson(url: string, data: object | null = null): Promise<any> {
|
128
|
-
return this.getRequestOptions(url, 'PUT', data).then(o => this.processRequestJson(url, o));
|
125
|
+
return this.getRequestOptions(url, 'PUT', data).then(o => this.processRequestJson(url, null, o));
|
129
126
|
}
|
130
127
|
|
131
|
-
get(
|
132
|
-
return this.getRequestOptions(
|
128
|
+
get(endpoint: string, params?: any): Promise<Response> {
|
129
|
+
return this.getRequestOptions(endpoint).then(o => this.processRequest(endpoint, params, o));
|
133
130
|
}
|
134
131
|
|
135
132
|
del(url: string): Promise<Response> {
|
136
|
-
return this.getRequestOptions(url, 'DELETE').then(o => this.processRequest(url, o));
|
133
|
+
return this.getRequestOptions(url, 'DELETE').then(o => this.processRequest(url, null, o));
|
137
134
|
}
|
138
135
|
|
139
136
|
post(url: string, data: object | null = null): Promise<Response> {
|
140
|
-
return this.getRequestOptions(url, 'POST', data).then(o => this.processRequest(url, o));
|
137
|
+
return this.getRequestOptions(url, 'POST', data).then(o => this.processRequest(url, null, o));
|
141
138
|
}
|
142
139
|
|
143
140
|
put(url: string, data: object | null = null): Promise<Response> {
|
144
|
-
return this.getRequestOptions(url, 'PUT', data).then(o => this.processRequest(url, o));
|
141
|
+
return this.getRequestOptions(url, 'PUT', data).then(o => this.processRequest(url, null, o));
|
145
142
|
}
|
146
143
|
|
147
144
|
}
|