@thisisagile/easy 13.6.11 → 14.0.0

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 (56) hide show
  1. package/README.md +1 -1
  2. package/dist/data/InMemoryGateway.d.ts +4 -4
  3. package/dist/data/InMemoryGateway.js +2 -2
  4. package/dist/data/InMemoryGateway.js.map +1 -1
  5. package/dist/domain/Repo.js +5 -5
  6. package/dist/domain/Repo.js.map +1 -1
  7. package/dist/domain/Typo.js +6 -6
  8. package/dist/domain/Typo.js.map +1 -1
  9. package/dist/domain/enums/Country.d.ts +2 -1
  10. package/dist/domain/enums/Country.js +3 -0
  11. package/dist/domain/enums/Country.js.map +1 -1
  12. package/dist/domain/enums/Locale.d.ts +2 -1
  13. package/dist/domain/enums/Locale.js +3 -0
  14. package/dist/domain/enums/Locale.js.map +1 -1
  15. package/dist/domain/enums/UnitOfMeasurement.js +1 -1
  16. package/dist/domain/enums/UnitOfMeasurement.js.map +1 -1
  17. package/dist/process/Search.d.ts +2 -2
  18. package/dist/process/Search.js +1 -1
  19. package/dist/process/Search.js.map +1 -1
  20. package/dist/services/MappedRouteGateway.d.ts +2 -2
  21. package/dist/services/MappedRouteGateway.js.map +1 -1
  22. package/dist/services/RouteGateway.js.map +1 -1
  23. package/dist/services/ViewRouteGateway.d.ts +2 -2
  24. package/dist/services/ViewRouteGateway.js.map +1 -1
  25. package/dist/sql/TableGateway.d.ts +2 -2
  26. package/dist/sql/TableGateway.js +1 -1
  27. package/dist/sql/TableGateway.js.map +1 -1
  28. package/dist/types/Enum.d.ts +1 -0
  29. package/dist/types/Enum.js +8 -6
  30. package/dist/types/Enum.js.map +1 -1
  31. package/dist/types/List.d.ts +24 -19
  32. package/dist/types/List.js +71 -30
  33. package/dist/types/List.js.map +1 -1
  34. package/dist/types/PageList.d.ts +43 -4
  35. package/dist/types/PageList.js +106 -9
  36. package/dist/types/PageList.js.map +1 -1
  37. package/dist/utils/If.js +1 -1
  38. package/dist/utils/If.js.map +1 -1
  39. package/dist/utils/View.js.map +1 -1
  40. package/package.json +2 -2
  41. package/src/data/InMemoryGateway.ts +5 -5
  42. package/src/domain/Repo.ts +6 -22
  43. package/src/domain/Typo.ts +7 -7
  44. package/src/domain/enums/Country.ts +5 -1
  45. package/src/domain/enums/Locale.ts +5 -1
  46. package/src/domain/enums/UnitOfMeasurement.ts +1 -1
  47. package/src/process/Search.ts +3 -3
  48. package/src/services/MappedRouteGateway.ts +23 -23
  49. package/src/services/RouteGateway.ts +45 -45
  50. package/src/services/ViewRouteGateway.ts +31 -31
  51. package/src/sql/TableGateway.ts +8 -3
  52. package/src/types/Enum.ts +9 -7
  53. package/src/types/List.ts +69 -22
  54. package/src/types/PageList.ts +148 -17
  55. package/src/utils/If.ts +5 -3
  56. package/src/utils/View.ts +5 -1
@@ -1,7 +1,12 @@
1
- import { isList, List, toList } from './List';
2
- import { Construct, ofConstruct, on } from './Constructor';
1
+ import { isList, List } from './List';
2
+ import { Construct, ofConstruct } from './Constructor';
3
3
  import { isA } from './IsA';
4
4
  import { PlainSort, Sort } from './Sort';
5
+ import { GetProperty } from './Get';
6
+ import { ArrayLike } from './Array';
7
+ import { Optional } from './Types';
8
+ import { isNumber } from './Is';
9
+ import { choose } from './Case';
5
10
 
6
11
  export type FilterValue = { label?: string; value: any };
7
12
  export type Filter = { label?: string; field: string; shortField?: string; values: FilterValue[] };
@@ -14,21 +19,147 @@ export const toShortFilter = (field: string, shortField: string, value: any): Fi
14
19
  });
15
20
 
16
21
  export type PageOptions = { take?: number; skip?: number; sort?: Sort[]; sorts?: PlainSort; filters?: Filter[] };
17
- export type PageList<T> = List<T> & Omit<PageOptions, 'sort'> & { total?: number };
22
+
23
+ export class PageList<T> extends List<T> {
24
+ private _take = 250;
25
+ private _skip = 0;
26
+ private _total?: number;
27
+ private _sorts?: PlainSort;
28
+ private _filters?: Filter[];
29
+
30
+ setPageOptions(options?: PageOptions & { total?: number }): this {
31
+ this._take = options?.take ?? 250;
32
+ this._skip = options?.skip ?? 0;
33
+ this._total = options?.total;
34
+ this._sorts = options?.sorts;
35
+ this._filters = options?.filters;
36
+ return this;
37
+ }
38
+
39
+ get take(): number {
40
+ return this._take;
41
+ }
42
+
43
+ get skip(): number {
44
+ return this._skip;
45
+ }
46
+
47
+ get total(): Optional<number> {
48
+ return this._total;
49
+ }
50
+
51
+ get sorts(): Optional<PlainSort> {
52
+ return this._sorts;
53
+ }
54
+
55
+ get filters(): Optional<Filter[]> {
56
+ return this._filters;
57
+ }
58
+
59
+ asc(p: GetProperty<T, any>): PageList<T> {
60
+ return toPageList(super.asc(p), this);
61
+ }
62
+
63
+ desc(p: GetProperty<T, any>): PageList<T> {
64
+ return toPageList(super.desc(p), this);
65
+ }
66
+
67
+ diff(others: ArrayLike<T>): PageList<T> {
68
+ return toPageList(super.diff(others), this);
69
+ }
70
+
71
+ diffByKey(others: ArrayLike<T>, key: keyof T): PageList<T> {
72
+ return toPageList(super.diffByKey(others, key), this);
73
+ }
74
+
75
+ intersect(others: ArrayLike<T>): PageList<T> {
76
+ return toPageList(super.intersect(others), this);
77
+ }
78
+
79
+ intersectByKey(others: ArrayLike<T>, key: keyof T): PageList<T> {
80
+ return toPageList(super.intersectByKey(others, key), this);
81
+ }
82
+
83
+ map<U>(f: (value: T, index: number, array: T[]) => U, params?: unknown): PageList<U> {
84
+ const items = super.map(f, params);
85
+ return toPageList(items, this);
86
+ }
87
+
88
+ flatMap<U, This = unknown>(f: (this: This, value: T, index: number, array: T[]) => ReadonlyArray<U> | U, params?: This): PageList<U> {
89
+ return toPageList(super.flatMap(f, params), this);
90
+ }
91
+
92
+ mapDefined<U>(f: (value: T, index: number, array: T[]) => U, params?: unknown): PageList<NonNullable<U>> {
93
+ return toPageList(super.mapDefined(f, params), this);
94
+ }
95
+
96
+ mapAsync(f: (i: T) => Promise<T>): Promise<PageList<T>> {
97
+ return super.mapAsync(f).then(r => toPageList(r, this));
98
+ }
99
+
100
+ distinct(): PageList<T> {
101
+ return toPageList(super.distinct(), this);
102
+ }
103
+
104
+ distinctByKey(key: keyof T): PageList<T> {
105
+ return toPageList(super.distinctByKey(key), this);
106
+ }
107
+
108
+ filter(p: (value: T, index: number, array: T[]) => unknown, params?: unknown): PageList<T> {
109
+ return toPageList(super.filter(p, params), this);
110
+ }
111
+
112
+ concat(...items: ConcatArray<T>[]): PageList<T>;
113
+ concat(...items: (T | ConcatArray<T>)[]): PageList<T>;
114
+ concat(...items: (T | ConcatArray<T>)[]): PageList<T> {
115
+ return toPageList(super.concat(...items), this);
116
+ }
117
+
118
+ reverse(): PageList<T> {
119
+ return toPageList(super.reverse(), this);
120
+ }
121
+
122
+ splice(start: number, deleteCount?: number): PageList<T>;
123
+ splice(start: number, deleteCount: number, ...items: T[]): PageList<T>;
124
+ splice(start: number, deleteCount: number, ...items: T[]): PageList<T> {
125
+ return toPageList(super.splice(start, deleteCount, ...items), this);
126
+ }
127
+
128
+ remove(item: T): PageList<T> {
129
+ return toPageList(super.remove(item), this);
130
+ }
131
+
132
+ replace(key: keyof T, item: T): PageList<T> {
133
+ return toPageList(super.replace(key, item), this);
134
+ }
135
+
136
+ switch(item: T): PageList<T> {
137
+ return toPageList(super.switch(item), this);
138
+ }
139
+
140
+ defined(): PageList<NonNullable<T>> {
141
+ return toPageList(super.defined(), this);
142
+ }
143
+
144
+ orElse(...alt: ArrayLike<T>): Optional<PageList<T>> {
145
+ return toPageList(super.orElse(...alt), this);
146
+ }
147
+
148
+ slice(start?: number, end?: number): PageList<T> {
149
+ return toPageList(super.slice(start, end), this);
150
+ }
151
+ }
18
152
 
19
153
  export const isPageList = <T>(l?: unknown): l is PageList<T> => isList<T>(l) && isA(l, 'total');
20
154
 
21
- export const toPageList = <T>(items?: T[], options?: Omit<PageOptions, 'sort'> & { total?: number }): PageList<T> =>
22
- on(toList<T>(...(items ?? [])) as PageList<T>, l => {
23
- l.take = options?.take ?? 250;
24
- l.skip = options?.skip ?? 0;
25
- l.total = options?.total;
26
- l.sorts = options?.sorts;
27
- l.filters = options?.filters;
28
- });
29
-
30
- export const asPageList = <T, U>(c: Construct<T>, items = toPageList<U>()): PageList<T> =>
31
- toPageList<T>(
32
- items.map(i => ofConstruct(c, i)),
33
- items
34
- );
155
+ export const toPageList = <T>(items: T[] = [], options?: Omit<PageOptions, 'sort'> & { total?: number }): PageList<T> =>
156
+ choose(items)
157
+ .case(
158
+ i => i.length === 1 && isNumber(i[0]),
159
+ i => new PageList<T>().add(...i)
160
+ )
161
+ .else(i => new PageList<T>(...i))
162
+ .setPageOptions(options);
163
+
164
+ /* @deprecated No longer needed as the PageList is now a class that extends from List, use the map function */
165
+ export const asPageList = <T, U>(c: Construct<T>, items = toPageList<U>()): PageList<T> => items.map(i => ofConstruct(c, i));
package/src/utils/If.ts CHANGED
@@ -1,6 +1,8 @@
1
- import {Construct, isDefined, isNotEmpty, isTrue, ofConstruct, Optional} from '../types';
1
+ import { Construct, isDefined, isNotEmpty, isTrue, ofConstruct, Optional } from '../types';
2
2
 
3
3
  export const ifTrue = <T>(o: unknown, f: Construct<T>, alt?: Construct<T>): Optional<T> => (isTrue(o) ? ofConstruct(f, o) : ofConstruct(alt, o));
4
4
  export const ifFalse = <T>(o: unknown, f: Construct<T>, alt?: Construct<T>): Optional<T> => (!isTrue(o) ? ofConstruct(f, o) : ofConstruct(alt, o));
5
- export const ifDefined = <Out, In = unknown>(o: Optional<In>, f: Construct<Out, NonNullable<In>>, alt?: Construct<Out>): Optional<Out> => (isDefined(o) ? ofConstruct(f, o) : ofConstruct(alt));
6
- export const ifNotEmpty = <T>(o: unknown, f: Construct<T> = o => o, alt?: Construct<T>): Optional<T> => isNotEmpty(o) ? ofConstruct(f, o) : ofConstruct(alt, o);
5
+ export const ifDefined = <Out, In = unknown>(o: Optional<In>, f: Construct<Out, NonNullable<In>>, alt?: Construct<Out>): Optional<Out> =>
6
+ isDefined(o) ? ofConstruct(f, o) : ofConstruct(alt);
7
+ export const ifNotEmpty = <T>(o: unknown, f: Construct<T> = o => o, alt?: Construct<T>): Optional<T> =>
8
+ isNotEmpty(o) ? ofConstruct(f, o) : ofConstruct(alt, o);
package/src/utils/View.ts CHANGED
@@ -80,7 +80,11 @@ export class View<V = Json> {
80
80
  from<T = unknown>(source: T[]): V[];
81
81
  from<T = unknown>(source: T): V;
82
82
  from<T = unknown>(source: PageList<T> | List<T> | T[] | T): PageList<V> | List<V> | V[] | V {
83
- if (isPageList(source)) return toPageList(source.map(s => this.reduce(asJson(s))), source);
83
+ if (isPageList(source))
84
+ return toPageList(
85
+ source.map(s => this.reduce(asJson(s))),
86
+ source
87
+ );
84
88
  if (isArray(source)) return source.map(s => this.reduce(asJson(s)));
85
89
  return this.reduce(asJson(source));
86
90
  }