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