zavadil-ts-common 1.1.40 → 1.1.42
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 +9 -0
- package/dist/cache/HashCacheAsync.d.ts +14 -0
- package/dist/cache/Lazy.d.ts +7 -0
- package/dist/cache/LazyAsync.d.ts +7 -0
- package/dist/cache/index.d.ts +4 -0
- package/dist/client/EntityCachedClient.d.ts +10 -0
- package/dist/client/EntityClient.d.ts +12 -0
- package/dist/client/EntityClientWithStub.d.ts +8 -0
- package/dist/client/LookupClient.d.ts +12 -0
- package/dist/client/RestClient.d.ts +23 -0
- package/dist/client/index.d.ts +5 -0
- package/dist/component/index.d.ts +0 -8
- package/dist/index.d.ts +217 -159
- 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/dist/oauth/OAuthRestClient.d.ts +44 -0
- package/dist/oauth/OAuthSubject.d.ts +7 -0
- package/dist/oauth/OAuthTokenManager.d.ts +21 -0
- package/dist/oauth/RestClientWithOAuth.d.ts +18 -0
- package/dist/oauth/index.d.ts +5 -0
- package/package.json +1 -1
- package/src/cache/index.ts +5 -0
- package/src/client/EntityCachedClient.ts +31 -0
- package/src/client/EntityClient.ts +36 -0
- package/src/client/EntityClientWithStub.ts +26 -0
- package/src/client/LookupClient.ts +46 -0
- package/src/client/index.ts +6 -0
- package/src/component/index.ts +1 -8
- package/src/index.ts +5 -2
- package/src/{component → oauth}/OAuthRestClient.ts +1 -1
- package/src/{component → oauth}/RestClientWithOAuth.ts +1 -1
- package/src/oauth/index.ts +6 -0
- /package/src/{component → cache}/CacheAsync.ts +0 -0
- /package/src/{component → cache}/HashCacheAsync.ts +0 -0
- /package/src/{component → cache}/Lazy.ts +0 -0
- /package/src/{component → cache}/LazyAsync.ts +0 -0
- /package/src/{component → client}/RestClient.ts +0 -0
- /package/src/{component → oauth}/OAuthSubject.ts +0 -0
- /package/src/{component → oauth}/OAuthTokenManager.ts +0 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
import {EntityClient} from "./EntityClient";
|
2
|
+
import {EntityBase} from "../type/Entity";
|
3
|
+
import { LazyAsync } from "../cache";
|
4
|
+
import { RestClient } from "./RestClient";
|
5
|
+
|
6
|
+
export class LookupClient<T extends EntityBase> extends EntityClient<T> {
|
7
|
+
|
8
|
+
private cache: LazyAsync<Array<T>>;
|
9
|
+
|
10
|
+
constructor(client: RestClient, name: string) {
|
11
|
+
super(client, name);
|
12
|
+
this.cache = new LazyAsync<Array<T>>(() => this.loadAllInternal());
|
13
|
+
}
|
14
|
+
|
15
|
+
private loadAllInternal(): Promise<Array<T>> {
|
16
|
+
return this.client.getJson(`${this.name}/all`);
|
17
|
+
}
|
18
|
+
|
19
|
+
loadAll(): Promise<Array<T>> {
|
20
|
+
return this.cache.get();
|
21
|
+
}
|
22
|
+
|
23
|
+
loadSingle(id: number): Promise<T> {
|
24
|
+
// @ts-ignore
|
25
|
+
return this.loadAll().then(
|
26
|
+
(all: Array<T>) => {
|
27
|
+
const d = all.find((l) => l.id === id);
|
28
|
+
if (id === undefined) throw new Error(`${this.name} id ${id} not found!`);
|
29
|
+
return d;
|
30
|
+
}
|
31
|
+
);
|
32
|
+
}
|
33
|
+
|
34
|
+
save(d: T): Promise<T> {
|
35
|
+
return super.save(d)
|
36
|
+
.then((s) => {
|
37
|
+
this.cache.reset();
|
38
|
+
return s;
|
39
|
+
});
|
40
|
+
}
|
41
|
+
|
42
|
+
delete(id: number): Promise<any> {
|
43
|
+
return super.delete(id).then(() => this.cache.reset());
|
44
|
+
}
|
45
|
+
|
46
|
+
}
|
package/src/component/index.ts
CHANGED
@@ -1,11 +1,4 @@
|
|
1
1
|
export * from './EventManager';
|
2
2
|
export * from './UserAlerts';
|
3
|
-
export * from './RestClient';
|
4
|
-
export * from './OAuthRestClient';
|
5
|
-
export * from './OAuthTokenManager';
|
6
|
-
export * from './OAuthSubject';
|
7
3
|
export * from './CancellablePromise';
|
8
|
-
|
9
|
-
export * from './LazyAsync';
|
10
|
-
export * from './CacheAsync';
|
11
|
-
export * from './HashCacheAsync';
|
4
|
+
|
package/src/index.ts
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|