@thisisagile/easy 12.7.21 → 12.7.22
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/data/Condition.js.map +1 -1
- package/dist/domain/Typo.js.map +1 -1
- package/dist/domain/enums/Currency.js +3 -1
- package/dist/domain/enums/Currency.js.map +1 -1
- package/dist/http/CacheControl.js +12 -9
- package/dist/http/CacheControl.js.map +1 -1
- package/dist/http/LocalRequestStore.d.ts +7 -0
- package/dist/http/LocalRequestStore.js +15 -0
- package/dist/http/LocalRequestStore.js.map +1 -0
- package/dist/http/NoRequestStore.d.ts +3 -3
- package/dist/http/NoRequestStore.js.map +1 -1
- package/dist/http/RestResult.js.map +1 -1
- package/dist/services/Api.d.ts +5 -3
- package/dist/services/Api.js +12 -10
- package/dist/services/Api.js.map +1 -1
- package/dist/services/RouteGateway.js.map +1 -1
- package/dist/types/Cache.d.ts +3 -3
- package/dist/types/CacheAge.js +1 -1
- package/dist/types/CacheAge.js.map +1 -1
- package/dist/types/Constructor.js.map +1 -1
- package/dist/types/Gateway.d.ts +1 -1
- package/dist/types/Gateway.js.map +1 -1
- package/dist/types/List.js +1 -1
- package/dist/types/List.js.map +1 -1
- package/dist/utils/View.js +1 -1
- package/dist/utils/View.js.map +1 -1
- package/package.json +2 -2
- package/src/data/Condition.ts +3 -5
- package/src/domain/Typo.ts +2 -15
- package/src/domain/enums/Currency.ts +3 -1
- package/src/http/CacheControl.ts +26 -24
- package/src/http/LocalRequestStore.ts +12 -0
- package/src/http/NoRequestStore.ts +6 -6
- package/src/http/RestResult.ts +1 -1
- package/src/services/Api.ts +57 -68
- package/src/services/RouteGateway.ts +88 -78
- package/src/types/Cache.ts +6 -6
- package/src/types/CacheAge.ts +48 -48
- package/src/types/Constructor.ts +3 -3
- package/src/types/Gateway.ts +1 -2
- package/src/types/List.ts +1 -1
- package/src/types/PageList.ts +2 -2
- package/src/types/Types.ts +0 -1
- package/src/utils/View.ts +9 -11
package/src/http/CacheControl.ts
CHANGED
|
@@ -1,45 +1,47 @@
|
|
|
1
|
-
import {cacheAge, CacheAge, isNumber, meta, on} from '../types';
|
|
2
|
-
import {ifDefined} from
|
|
1
|
+
import { cacheAge, CacheAge, isNumber, meta, on } from '../types';
|
|
2
|
+
import { ifDefined } from '../utils';
|
|
3
3
|
|
|
4
4
|
export class CacheControl {
|
|
5
|
-
|
|
5
|
+
name = 'Cache-Control';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
}
|
|
7
|
+
protected constructor(readonly enabled = true, private directives: Record<string, boolean | CacheAge | undefined> = {}) {}
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
static disabled = () => new CacheControl(false);
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
static OneSecond = () => new CacheControl().maxAge(1).staleWhileRevalidate(1);
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
static fiveSeconds = () => new CacheControl().maxAge(5).staleWhileRevalidate(5);
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
static tenSeconds = () => new CacheControl().maxAge(10).staleWhileRevalidate(10);
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
static thirtySeconds = () => new CacheControl().maxAge(30).staleWhileRevalidate(30);
|
|
19
18
|
|
|
20
|
-
|
|
19
|
+
static sixtySeconds = () => new CacheControl().maxAge(60).staleWhileRevalidate(60);
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
static custom = (maxAge?: CacheAge, staleWhileRevalidate?: CacheAge) => new CacheControl().maxAge(maxAge).staleWhileRevalidate(staleWhileRevalidate);
|
|
23
22
|
|
|
24
|
-
|
|
23
|
+
readonly maxAge = (ca?: CacheAge): this => on(this, t => (t.directives['max-age'] = ca));
|
|
25
24
|
|
|
26
|
-
|
|
25
|
+
readonly sharedMaxAge = (ca?: CacheAge): this => on(this, t => (t.directives['s-maxage'] = ca));
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
readonly noCache = (a?: boolean): this => on(this, t => (t.directives['no-cache'] = a));
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
readonly mustRevalidate = (a?: boolean): this => on(this, t => (t.directives['must-revalidate'] = a));
|
|
31
30
|
|
|
32
|
-
|
|
31
|
+
readonly private = (a?: boolean): this => on(this, t => (t.directives['private'] = a));
|
|
33
32
|
|
|
34
|
-
|
|
33
|
+
readonly public = (a?: boolean): this => on(this, t => (t.directives['public'] = a));
|
|
35
34
|
|
|
36
|
-
|
|
35
|
+
readonly immutable = (a?: boolean): this => on(this, t => (t.directives['immutable'] = a));
|
|
37
36
|
|
|
38
|
-
|
|
37
|
+
readonly staleWhileRevalidate = (ca?: CacheAge): this => on(this, t => (t.directives['stale-while-revalidate'] = ca));
|
|
39
38
|
|
|
40
|
-
|
|
39
|
+
value = (): string => this.toString();
|
|
41
40
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
toString(): string {
|
|
42
|
+
return meta(this.directives)
|
|
43
|
+
.entries()
|
|
44
|
+
.mapDefined(([k, v]) => ifDefined(v, isNumber(v) ? `${k}=${cacheAge.toSeconds(v)}` : k))
|
|
45
|
+
.join(',');
|
|
46
|
+
}
|
|
45
47
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ctx, Func, Store } from '../types';
|
|
2
|
+
import { Response } from './Response';
|
|
3
|
+
import { Request } from './Request';
|
|
4
|
+
|
|
5
|
+
export class LocalRequestStore implements Store<Response, Request> {
|
|
6
|
+
key = (req: Request): string => '';
|
|
7
|
+
|
|
8
|
+
execute(req: Request, f: Func<Promise<Response>, Request>): Promise<Response> {
|
|
9
|
+
const key = this.key(req);
|
|
10
|
+
return ctx.request.get(key) ?? ctx.request.set(key, f(req));
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {Func, Store} from
|
|
2
|
-
import {Request} from
|
|
3
|
-
import {Response} from
|
|
1
|
+
import { Func, Store } from '../types';
|
|
2
|
+
import { Request } from './Request';
|
|
3
|
+
import { Response } from './Response';
|
|
4
4
|
|
|
5
5
|
export class NoRequestStore implements Store<Response, Request> {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
execute(req: Request, f: Func<Promise<Response>, Request>): Promise<Response> {
|
|
7
|
+
return f(req);
|
|
8
|
+
}
|
|
9
9
|
}
|
package/src/http/RestResult.ts
CHANGED
|
@@ -8,7 +8,7 @@ export type RestResult = {
|
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
const hasErrors = (a: any): a is { error: { code: number; errors: List<Result> } } => isDefined(a?.error?.errors);
|
|
11
|
-
const hasItems = (a: any): a is { data: { code: number; items: List<Json>; totalItems?: number; meta?: Json
|
|
11
|
+
const hasItems = (a: any): a is { data: { code: number; items: List<Json>; totalItems?: number; meta?: Json } } => isDefined(a?.data.items);
|
|
12
12
|
|
|
13
13
|
export const rest = {
|
|
14
14
|
toData: (status: HttpStatus, items: Json[] = [], totalItems?: number, meta?: Json): RestResult => ({
|
package/src/services/Api.ts
CHANGED
|
@@ -1,81 +1,70 @@
|
|
|
1
|
-
import {FetchOptions, Uri} from '../types';
|
|
2
|
-
import {HttpVerb, RequestOptions, RequestProvider, Response, toPageOptions} from '../http';
|
|
3
|
-
import {AxiosProvider} from './AxiosProvider';
|
|
1
|
+
import { FetchOptions, Store, Uri } from '../types';
|
|
2
|
+
import { HttpVerb, Request, RequestOptions, RequestProvider, Response, toPageOptions } from '../http';
|
|
3
|
+
import { AxiosProvider } from './AxiosProvider';
|
|
4
4
|
|
|
5
5
|
export type RouteOptions = RequestOptions | FetchOptions;
|
|
6
6
|
|
|
7
7
|
export class Api {
|
|
8
|
-
|
|
9
|
-
}
|
|
8
|
+
constructor(readonly provider: RequestProvider = new AxiosProvider(), protected store?: Store<Response, Request>) {}
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
get(uri: Uri, options?: RouteOptions, transform?: (r: any) => any, transformError = (r: any) => r): Promise<Response> {
|
|
11
|
+
return this.execute({
|
|
12
|
+
uri: uri.skip(toPageOptions(options)?.skip).take(toPageOptions(options)?.take),
|
|
13
|
+
verb: HttpVerb.Get,
|
|
14
|
+
transform,
|
|
15
|
+
transformError,
|
|
16
|
+
options: this.options(HttpVerb.Get, options),
|
|
17
|
+
});
|
|
18
|
+
}
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
body,
|
|
32
|
-
transform,
|
|
33
|
-
transformError,
|
|
34
|
-
options: this.options(HttpVerb.Post, options)
|
|
35
|
-
});
|
|
36
|
-
}
|
|
20
|
+
post(uri: Uri, body?: unknown, options: RouteOptions = RequestOptions.Json, transform?: (r: any) => any, transformError = (r: any) => r): Promise<Response> {
|
|
21
|
+
return this.execute({
|
|
22
|
+
uri,
|
|
23
|
+
verb: HttpVerb.Post,
|
|
24
|
+
body,
|
|
25
|
+
transform,
|
|
26
|
+
transformError,
|
|
27
|
+
options: this.options(HttpVerb.Post, options),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
37
30
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
31
|
+
put(uri: Uri, body?: unknown, options: RouteOptions = RequestOptions.Json, transform?: (r: any) => any, transformError = (r: any) => r): Promise<Response> {
|
|
32
|
+
return this.execute({
|
|
33
|
+
uri,
|
|
34
|
+
verb: HttpVerb.Put,
|
|
35
|
+
body,
|
|
36
|
+
transform,
|
|
37
|
+
transformError,
|
|
38
|
+
options: this.options(HttpVerb.Put, options),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
48
41
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
body,
|
|
60
|
-
transform,
|
|
61
|
-
transformError,
|
|
62
|
-
options: this.options(HttpVerb.Patch, options)
|
|
63
|
-
});
|
|
64
|
-
}
|
|
42
|
+
patch(uri: Uri, body?: unknown, options: RouteOptions = RequestOptions.Json, transform?: (r: any) => any, transformError = (r: any) => r): Promise<Response> {
|
|
43
|
+
return this.execute({
|
|
44
|
+
uri,
|
|
45
|
+
verb: HttpVerb.Patch,
|
|
46
|
+
body,
|
|
47
|
+
transform,
|
|
48
|
+
transformError,
|
|
49
|
+
options: this.options(HttpVerb.Patch, options),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
65
52
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
53
|
+
delete(uri: Uri, options: RouteOptions = RequestOptions.Json, transform?: (b: any) => any, transformError = (r: any) => r): Promise<Response> {
|
|
54
|
+
return this.execute({
|
|
55
|
+
uri,
|
|
56
|
+
verb: HttpVerb.Delete,
|
|
57
|
+
transform,
|
|
58
|
+
transformError,
|
|
59
|
+
options: this.options(HttpVerb.Delete, options),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
75
62
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
63
|
+
options(verb: HttpVerb, options?: RouteOptions): RequestOptions {
|
|
64
|
+
return options instanceof RequestOptions ? options : RequestOptions.Json;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
execute = (req: Request): Promise<Response> => (this.store ? this.store.execute(req, () => this.provider.execute(req)) : this.provider.execute(req));
|
|
79
68
|
}
|
|
80
69
|
|
|
81
70
|
export const api: Api = new Api();
|
|
@@ -1,81 +1,91 @@
|
|
|
1
|
-
import {Api, RouteOptions} from './Api';
|
|
2
|
-
import {FetchOptions, Filter, Func, Gateway, Id, Json, JsonValue, PageList, toPageList, Uri} from '../types';
|
|
3
|
-
import {HttpStatus, RequestOptions, toPageOptions} from '../http';
|
|
1
|
+
import { Api, RouteOptions } from './Api';
|
|
2
|
+
import { FetchOptions, Filter, Func, Gateway, Id, Json, JsonValue, PageList, toPageList, Uri } from '../types';
|
|
3
|
+
import { HttpStatus, RequestOptions, toPageOptions } from '../http';
|
|
4
4
|
|
|
5
5
|
export class RouteGateway extends Gateway<RouteOptions> {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
6
|
+
constructor(readonly route: Func<Uri>, readonly routeId: Func<Uri>, readonly api: Api = new Api()) {
|
|
7
|
+
super();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
get(uri: Uri, options?: RouteOptions): Promise<PageList<Json>> {
|
|
11
|
+
return this.api.get(uri, options).then(r =>
|
|
12
|
+
toPageList<Json>(
|
|
13
|
+
r.body.data?.items,
|
|
14
|
+
toPageOptions(options) && {
|
|
15
|
+
total: r.body.data?.totalItems,
|
|
16
|
+
filters: r.body.data?.meta?.filters as Filter[],
|
|
17
|
+
}
|
|
18
|
+
)
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getOne(uri: Uri, options?: RouteOptions): Promise<Json | undefined> {
|
|
23
|
+
return this.get(uri, options).then(r => r.first());
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
all(options?: RouteOptions): Promise<PageList<Json>> {
|
|
27
|
+
return this.get(this.route(), options);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
byId(id: Id, options?: RouteOptions): Promise<Json | undefined> {
|
|
31
|
+
return this.getOne(this.routeId().id(id));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
search(q: JsonValue, options?: RouteOptions): Promise<PageList<Json>> {
|
|
35
|
+
return this.get(this.route().query(q), options);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
exists(id: Id, options?: RouteOptions): Promise<boolean> {
|
|
39
|
+
return this.get(this.routeId().id(id))
|
|
40
|
+
.then(r => r.length === 1)
|
|
41
|
+
.catch(r => (HttpStatus.NotFound.equals(r.status) ? false : Promise.reject(r)));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
add(item: Json, options?: RouteOptions): Promise<Json> {
|
|
45
|
+
return this.post(this.route(), item);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
filter(options?: RouteOptions): Promise<PageList<Json>> {
|
|
49
|
+
return this.postSearch(this.route(), options);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
update(item: Json, options?: RouteOptions): Promise<Json> {
|
|
53
|
+
return this.patch(this.routeId().id(item.id), item);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
upsert(item: Json, options?: RouteOptions): Promise<Json> {
|
|
57
|
+
return this.put(this.routeId().id(item.id), item);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
remove(id: Id, options?: RouteOptions): Promise<boolean> {
|
|
61
|
+
return this.delete(this.routeId().id(id));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
post(uri: Uri, item?: Json): Promise<Json> {
|
|
65
|
+
return this.api.post(uri, item).then(r => r.body.data?.items.first() ?? {});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
postSearch(uri: Uri, options?: RequestOptions | FetchOptions): Promise<PageList<Json>> {
|
|
69
|
+
return this.api.post(uri, options).then(r =>
|
|
70
|
+
toPageList<Json>(
|
|
71
|
+
r.body.data?.items,
|
|
72
|
+
toPageOptions(options) && {
|
|
73
|
+
total: r.body.data?.totalItems,
|
|
74
|
+
filters: r.body.data?.meta?.filters as Filter[],
|
|
75
|
+
}
|
|
76
|
+
)
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
patch(uri: Uri, item: Json): Promise<Json> {
|
|
81
|
+
return this.api.patch(uri, item).then(r => r.body.data?.items.first() ?? {});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
put(uri: Uri, item: Json): Promise<Json> {
|
|
85
|
+
return this.api.put(uri, item).then(r => r.body.data?.items.first() ?? {});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
delete(uri: Uri, options?: RouteOptions): Promise<boolean> {
|
|
89
|
+
return this.api.delete(uri).then(() => true);
|
|
90
|
+
}
|
|
81
91
|
}
|
package/src/types/Cache.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {Func} from
|
|
2
|
-
import {CacheAge} from
|
|
3
|
-
import {Construct} from
|
|
1
|
+
import { Func } from './Func';
|
|
2
|
+
import { CacheAge } from './CacheAge';
|
|
3
|
+
import { Construct } from './Constructor';
|
|
4
4
|
|
|
5
5
|
export interface Store<To = any, From = any> {
|
|
6
|
-
|
|
6
|
+
execute: (fetch: From, f: Func<Promise<To>, From>) => Promise<To>;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export type CacheOptions = {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
expiresIn?: CacheAge;
|
|
11
|
+
store?: Construct<Store>;
|
|
12
12
|
};
|
package/src/types/CacheAge.ts
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import {asNumber, asString, choose} from
|
|
1
|
+
import { asNumber, asString, choose } from './index';
|
|
2
2
|
|
|
3
3
|
export type CacheAge = `${number}${'ms' | 's' | 'm' | 'h' | 'd'}` | number;
|
|
4
4
|
|
|
5
5
|
const ageNumber = (s: string): number => asNumber(s.replace(/[a-z]/g, ''));
|
|
6
6
|
|
|
7
7
|
export const cacheAge = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
8
|
+
toMilliseconds: (ca: CacheAge): number =>
|
|
9
|
+
choose(asString(ca))
|
|
10
|
+
.case(
|
|
11
|
+
c => c.endsWith('ms'),
|
|
12
|
+
c => ageNumber(c)
|
|
13
|
+
)
|
|
14
|
+
.case(
|
|
15
|
+
c => c.endsWith('s'),
|
|
16
|
+
c => ageNumber(c) * 1000
|
|
17
|
+
)
|
|
18
|
+
.case(
|
|
19
|
+
c => c.endsWith('m'),
|
|
20
|
+
c => ageNumber(c) * 60 * 1000
|
|
21
|
+
)
|
|
22
|
+
.case(
|
|
23
|
+
c => c.endsWith('h'),
|
|
24
|
+
c => ageNumber(c) * 3600 * 1000
|
|
25
|
+
)
|
|
26
|
+
.case(
|
|
27
|
+
c => c.endsWith('d'),
|
|
28
|
+
c => ageNumber(c) * 24 * 3600 * 1000
|
|
29
|
+
)
|
|
30
|
+
.else(ca as number),
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
32
|
+
toSeconds: (ca: CacheAge): number =>
|
|
33
|
+
choose(asString(ca))
|
|
34
|
+
.case(
|
|
35
|
+
c => c.endsWith('ms'),
|
|
36
|
+
c => ageNumber(c) / 1000
|
|
37
|
+
)
|
|
38
|
+
.case(
|
|
39
|
+
c => c.endsWith('s'),
|
|
40
|
+
c => ageNumber(c)
|
|
41
|
+
)
|
|
42
|
+
.case(
|
|
43
|
+
c => c.endsWith('m'),
|
|
44
|
+
c => ageNumber(c) * 60
|
|
45
|
+
)
|
|
46
|
+
.case(
|
|
47
|
+
c => c.endsWith('h'),
|
|
48
|
+
c => ageNumber(c) * 3600
|
|
49
|
+
)
|
|
50
|
+
.case(
|
|
51
|
+
c => c.endsWith('d'),
|
|
52
|
+
c => ageNumber(c) * 24 * 3600
|
|
53
|
+
)
|
|
54
|
+
.else(ca as number),
|
|
55
|
+
};
|
package/src/types/Constructor.ts
CHANGED
|
@@ -13,6 +13,6 @@ export const ofConstruct = <T>(c: Construct<T>, ...args: unknown[]): T => (isCon
|
|
|
13
13
|
export const toName = (subject?: unknown, postfix = ''): string => (subject as any)?.constructor?.name?.replace(postfix, '').toLowerCase() ?? '';
|
|
14
14
|
|
|
15
15
|
export const on = <T>(t: T, f: (t: T) => unknown): T => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
16
|
+
f(t);
|
|
17
|
+
return t;
|
|
18
|
+
};
|
package/src/types/Gateway.ts
CHANGED
|
@@ -4,8 +4,7 @@ import { Exception } from './Exception';
|
|
|
4
4
|
import { reject } from '../utils';
|
|
5
5
|
import { PageList, PageOptions } from './PageList';
|
|
6
6
|
import { List } from './List';
|
|
7
|
-
import {CacheOptions} from
|
|
8
|
-
|
|
7
|
+
import { CacheOptions } from './Cache';
|
|
9
8
|
|
|
10
9
|
export type FetchOptions = PageOptions & CacheOptions;
|
|
11
10
|
|
package/src/types/List.ts
CHANGED
package/src/types/PageList.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { isList, List, toList } from './List';
|
|
|
2
2
|
import { Construct, ofConstruct } from './Constructor';
|
|
3
3
|
import { isA } from './IsA';
|
|
4
4
|
|
|
5
|
-
export type Sort =
|
|
5
|
+
export type Sort = { key: string; value: -1 | 1 };
|
|
6
6
|
|
|
7
7
|
export type FilterValue = { label?: string; value: any };
|
|
8
8
|
export type Filter = { label?: string; field: string; values: FilterValue[] };
|
|
@@ -26,5 +26,5 @@ export const toPageList = <T>(items?: T[], options?: Omit<PageOptions, 'sort'> &
|
|
|
26
26
|
export const asPageList = <T, U>(c: Construct<T>, items = toPageList<U>()): PageList<T> =>
|
|
27
27
|
toPageList<T>(
|
|
28
28
|
items.map(i => ofConstruct(c, i)),
|
|
29
|
-
items
|
|
29
|
+
items
|
|
30
30
|
);
|
package/src/types/Types.ts
CHANGED