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.
Files changed (41) hide show
  1. package/dist/cache/CacheAsync.d.ts +9 -0
  2. package/dist/cache/HashCacheAsync.d.ts +14 -0
  3. package/dist/cache/Lazy.d.ts +7 -0
  4. package/dist/cache/LazyAsync.d.ts +7 -0
  5. package/dist/cache/index.d.ts +4 -0
  6. package/dist/client/EntityCachedClient.d.ts +10 -0
  7. package/dist/client/EntityClient.d.ts +12 -0
  8. package/dist/client/EntityClientWithStub.d.ts +8 -0
  9. package/dist/client/LookupClient.d.ts +12 -0
  10. package/dist/client/RestClient.d.ts +23 -0
  11. package/dist/client/index.d.ts +5 -0
  12. package/dist/component/index.d.ts +0 -8
  13. package/dist/index.d.ts +217 -159
  14. package/dist/index.esm.js +1 -1
  15. package/dist/index.esm.js.map +1 -1
  16. package/dist/index.js +1 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/oauth/OAuthRestClient.d.ts +44 -0
  19. package/dist/oauth/OAuthSubject.d.ts +7 -0
  20. package/dist/oauth/OAuthTokenManager.d.ts +21 -0
  21. package/dist/oauth/RestClientWithOAuth.d.ts +18 -0
  22. package/dist/oauth/index.d.ts +5 -0
  23. package/package.json +1 -1
  24. package/src/cache/index.ts +5 -0
  25. package/src/client/EntityCachedClient.ts +31 -0
  26. package/src/client/EntityClient.ts +36 -0
  27. package/src/client/EntityClientWithStub.ts +26 -0
  28. package/src/client/LookupClient.ts +46 -0
  29. package/src/client/index.ts +6 -0
  30. package/src/component/index.ts +1 -8
  31. package/src/index.ts +5 -2
  32. package/src/{component → oauth}/OAuthRestClient.ts +1 -1
  33. package/src/{component → oauth}/RestClientWithOAuth.ts +1 -1
  34. package/src/oauth/index.ts +6 -0
  35. /package/src/{component → cache}/CacheAsync.ts +0 -0
  36. /package/src/{component → cache}/HashCacheAsync.ts +0 -0
  37. /package/src/{component → cache}/Lazy.ts +0 -0
  38. /package/src/{component → cache}/LazyAsync.ts +0 -0
  39. /package/src/{component → client}/RestClient.ts +0 -0
  40. /package/src/{component → oauth}/OAuthSubject.ts +0 -0
  41. /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
+ }
@@ -0,0 +1,6 @@
1
+ export * from './EntityClient';
2
+ export * from './EntityCachedClient';
3
+ export * from './EntityClientWithStub';
4
+ export * from './LookupClient';
5
+ export * from './RestClient';
6
+
@@ -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
- export * from './Lazy';
9
- export * from './LazyAsync';
10
- export * from './CacheAsync';
11
- export * from './HashCacheAsync';
4
+
package/src/index.ts CHANGED
@@ -1,4 +1,7 @@
1
- export * from './vector';
1
+ export * from './cache';
2
+ export * from './client';
3
+ export * from './component';
4
+ export * from './oauth';
2
5
  export * from './type';
3
6
  export * from './util';
4
- export * from './component';
7
+ export * from './vector';
@@ -1,4 +1,4 @@
1
- import {RestClient} from "./RestClient";
1
+ import {RestClient} from "../client/RestClient";
2
2
  import {StringUtil} from "../util";
3
3
 
4
4
  export type TokenRequestPayloadBase = {
@@ -1,5 +1,5 @@
1
1
  import {OAuthTokenManager} from "./OAuthTokenManager";
2
- import { RestClient, RestClientHeaders } from "./RestClient";
2
+ import { RestClient, RestClientHeaders } from "../client";
3
3
 
4
4
  export type ServerOAuthInfoPayload = {
5
5
  debugMode?: boolean;
@@ -0,0 +1,6 @@
1
+ export * from './OAuthRestClient';
2
+ export * from './OAuthTokenManager';
3
+ export * from './OAuthSubject';
4
+ export * from './OAuthTokenManager';
5
+ export * from './RestClientWithOAuth';
6
+
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes