@thisisagile/easy 13.6.10 → 13.6.12

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 (42) hide show
  1. package/dist/data/InMemoryGateway.d.ts +4 -4
  2. package/dist/data/InMemoryGateway.js +2 -2
  3. package/dist/data/InMemoryGateway.js.map +1 -1
  4. package/dist/domain/Repo.js +5 -5
  5. package/dist/domain/Repo.js.map +1 -1
  6. package/dist/domain/Typo.js +6 -6
  7. package/dist/domain/Typo.js.map +1 -1
  8. package/dist/process/Search.d.ts +2 -2
  9. package/dist/process/Search.js +1 -1
  10. package/dist/process/Search.js.map +1 -1
  11. package/dist/services/MappedRouteGateway.d.ts +2 -2
  12. package/dist/services/MappedRouteGateway.js.map +1 -1
  13. package/dist/services/RouteGateway.js.map +1 -1
  14. package/dist/services/ViewRouteGateway.d.ts +2 -2
  15. package/dist/services/ViewRouteGateway.js.map +1 -1
  16. package/dist/sql/TableGateway.d.ts +2 -2
  17. package/dist/sql/TableGateway.js +1 -1
  18. package/dist/sql/TableGateway.js.map +1 -1
  19. package/dist/types/List.d.ts +24 -19
  20. package/dist/types/List.js +71 -30
  21. package/dist/types/List.js.map +1 -1
  22. package/dist/types/PageList.d.ts +44 -5
  23. package/dist/types/PageList.js +106 -9
  24. package/dist/types/PageList.js.map +1 -1
  25. package/dist/utils/If.js +1 -1
  26. package/dist/utils/If.js.map +1 -1
  27. package/dist/utils/View.d.ts +4 -1
  28. package/dist/utils/View.js +8 -6
  29. package/dist/utils/View.js.map +1 -1
  30. package/package.json +2 -2
  31. package/src/data/InMemoryGateway.ts +5 -5
  32. package/src/domain/Repo.ts +6 -22
  33. package/src/domain/Typo.ts +7 -7
  34. package/src/process/Search.ts +3 -3
  35. package/src/services/MappedRouteGateway.ts +23 -23
  36. package/src/services/RouteGateway.ts +45 -45
  37. package/src/services/ViewRouteGateway.ts +31 -31
  38. package/src/sql/TableGateway.ts +8 -3
  39. package/src/types/List.ts +69 -22
  40. package/src/types/PageList.ts +151 -20
  41. package/src/utils/If.ts +5 -3
  42. package/src/utils/View.ts +24 -21
@@ -1,4 +1,4 @@
1
- import { Gateway, Id, isDefined, Json, List, Optional, PageOptions } from '../types';
1
+ import { Gateway, Id, isDefined, Json, Optional, PageList, PageOptions, toPageList } from '../types';
2
2
  import { QueryProvider } from '../data';
3
3
  import { when } from '../validation';
4
4
  import { ifDefined } from '../utils';
@@ -13,10 +13,15 @@ export class TableGateway<T extends Table> extends Gateway<PageOptions> {
13
13
 
14
14
  protected provide = ({ provider }: TableOptions = {}): QueryProvider => provider ?? this.provider;
15
15
 
16
- all(options?: TableOptions): Promise<List<Json>> {
16
+ all(options?: TableOptions): Promise<PageList<Json>> {
17
17
  return this.provide(options)
18
18
  .query(this.table.select())
19
- .then(js => js.map(j => this.table.in(j)));
19
+ .then(js =>
20
+ toPageList(
21
+ js.map(j => this.table.in(j)),
22
+ options
23
+ )
24
+ );
20
25
  }
21
26
 
22
27
  byId(id: Id, options?: TableOptions): Promise<Optional<Json>> {
package/src/types/List.ts CHANGED
@@ -11,9 +11,13 @@ import { meta } from './Meta';
11
11
  import { Optional } from './Types';
12
12
 
13
13
  export class List<T = unknown> extends Array<T> {
14
- asc = (p: GetProperty<T, any>): List<T> => this.sort((e1, e2) => (ofProperty(e1, p) > ofProperty(e2, p) ? 1 : -1));
14
+ asc(p: GetProperty<T, any>): List<T> {
15
+ return this.sort((e1, e2) => (ofProperty(e1, p) > ofProperty(e2, p) ? 1 : -1));
16
+ }
15
17
 
16
- desc = (p: GetProperty<T, any>): List<T> => this.sort((e1, e2) => (ofProperty(e1, p) < ofProperty(e2, p) ? 1 : -1));
18
+ desc(p: GetProperty<T, any>): List<T> {
19
+ return this.sort((e1, e2) => (ofProperty(e1, p) < ofProperty(e2, p) ? 1 : -1));
20
+ }
17
21
 
18
22
  first = (p?: (value: T, index: number, array: T[]) => unknown, params?: unknown): T => (p ? this.find(p, params) : this[0]) as T;
19
23
 
@@ -31,13 +35,21 @@ export class List<T = unknown> extends Array<T> {
31
35
 
32
36
  overlaps = (...items: ArrayLike<T>): boolean => toList<T>(...items).some(i => this.some(t => i === t));
33
37
 
34
- diff = (others: ArrayLike<T>): List<T> => this.filter(i => !others.includes(i));
38
+ diff(others: ArrayLike<T>): List<T> {
39
+ return this.filter(i => !others.includes(i));
40
+ }
35
41
 
36
- diffByKey = (others: ArrayLike<T>, key: keyof T): List<T> => this.filter((i: any) => !others.some((o: any) => o[key] === i[key]));
42
+ diffByKey(others: ArrayLike<T>, key: keyof T): List<T> {
43
+ return this.filter((i: any) => !others.some((o: any) => o[key] === i[key]));
44
+ }
37
45
 
38
- intersect = (others: ArrayLike<T>): List<T> => this.filter(i => others.includes(i));
46
+ intersect(others: ArrayLike<T>): List<T> {
47
+ return this.filter(i => others.includes(i));
48
+ }
39
49
 
40
- intersectByKey = (others: ArrayLike<T>, key: keyof T): List<T> => this.filter((i: any) => others.some((o: any) => o[key] === i[key]));
50
+ intersectByKey(others: ArrayLike<T>, key: keyof T): List<T> {
51
+ return this.filter((i: any) => others.some((o: any) => o[key] === i[key]));
52
+ }
41
53
 
42
54
  toJSON = (): Json[] =>
43
55
  this.reduce((a, i) => {
@@ -45,49 +57,82 @@ export class List<T = unknown> extends Array<T> {
45
57
  return a;
46
58
  }, new Array<Json>());
47
59
 
48
- map = <U>(f: (value: T, index: number, array: T[]) => U, params?: unknown): List<U> => toList<U>(super.map(f, params));
60
+ map<U>(f: (value: T, index: number, array: T[]) => U, params?: unknown): List<U> {
61
+ return toList<U>(super.map(f, params));
62
+ }
49
63
 
50
- flatMap = <U, This = unknown>(f: (this: This, value: T, index: number, array: T[]) => ReadonlyArray<U> | U, params?: This): List<U> =>
51
- toList<U>(super.flatMap(f, params));
64
+ flatMap<U, This = unknown>(f: (this: This, value: T, index: number, array: T[]) => ReadonlyArray<U> | U, params?: This): List<U> {
65
+ return toList<U>(super.flatMap(f, params));
66
+ }
52
67
 
53
- mapDefined = <U>(f: (value: T, index: number, array: T[]) => U, params?: unknown): List<NonNullable<U>> => this.map(f, params).defined();
68
+ mapDefined<U>(f: (value: T, index: number, array: T[]) => U, params?: unknown): List<NonNullable<U>> {
69
+ return this.map(f, params).defined();
70
+ }
54
71
 
55
- mapAsync = (f: (i: T) => Promise<T>): Promise<List<T>> => Promise.all(super.map(e => f(e))).then(a => toList<T>(a));
72
+ mapAsync(f: (i: T) => Promise<T>): Promise<List<T>> {
73
+ return Promise.all(super.map(e => f(e))).then(a => toList<T>(a));
74
+ }
56
75
 
57
- distinct = (): List<T> => this.filter((i, index) => this.indexOf(i) === index);
76
+ distinct(): List<T> {
77
+ return this.filter((i, index) => this.indexOf(i) === index);
78
+ }
58
79
 
59
- distinctByKey = (key: keyof T): List<T> => meta(this.toObject(key)).values();
80
+ distinctByKey(key: keyof T): List<T> {
81
+ return meta(this.toObject(key)).values();
82
+ }
60
83
 
61
- filter = (p: (value: T, index: number, array: T[]) => unknown, params?: unknown): List<T> => toList<T>(super.filter(p, params));
84
+ filter(p: (value: T, index: number, array: T[]) => unknown, params?: unknown): List<T> {
85
+ return toList<T>(super.filter(p, params));
86
+ }
62
87
 
63
88
  sum = (p: (t: T) => number): number => this.reduce((sum: number, i) => sum + p(i), 0);
64
89
 
65
90
  byId = (id: Id): T => this.first(i => asString((i as any).id) === asString(id));
66
91
 
67
- add = (...items: (T | T[])[]): this => {
92
+ add = (...items: ArrayLike<T>): this => {
68
93
  super.push(...toArray(...items));
69
94
  return this;
70
95
  };
71
96
 
72
- remove = (item: T): List<T> => {
97
+ concat(...items: ConcatArray<T>[]): List<T>;
98
+ concat(...items: (T | ConcatArray<T>)[]): List<T>;
99
+ concat(...items: (T | ConcatArray<T>)[]): List<T> {
100
+ return toList<T>(super.concat(...items));
101
+ }
102
+
103
+ reverse(): List<T> {
104
+ return toList<T>(super.reverse());
105
+ }
106
+
107
+ splice(start: number, deleteCount?: number): List<T>;
108
+ splice(start: number, deleteCount: number, ...items: T[]): List<T>;
109
+ splice(start: number, deleteCount: number, ...items: T[]): List<T> {
110
+ return toList<T>(super.splice(start, deleteCount, ...items));
111
+ }
112
+
113
+ remove(item: T): List<T> {
73
114
  const index = this.indexOf(item);
74
115
  if (index > -1) {
75
116
  this.splice(index, 1);
76
117
  }
77
118
  return this;
78
- };
119
+ }
79
120
 
80
- replace = (key: keyof T, item: T): List<T> => {
121
+ replace(key: keyof T, item: T): List<T> {
81
122
  tryTo(() => item[key])
82
123
  .map(k => this.findIndex(i => i[key] === k))
83
124
  .filter(i => i > -1)
84
125
  .map(i => (this[i] = item));
85
126
  return this;
86
- };
127
+ }
87
128
 
88
- switch = (item: T): List<T> => (this.includes(item) ? this.remove(item) : this.add(item));
129
+ switch(item: T): List<T> {
130
+ return this.includes(item) ? this.remove(item) : this.add(item);
131
+ }
89
132
 
90
- defined = (): List<NonNullable<T>> => this.reduce((l, v) => (isDefined(v) ? l.add(v) : l), toList<NonNullable<T>>());
133
+ defined(): List<NonNullable<T>> {
134
+ return this.reduce((l, v) => (isDefined(v) ? l.add(v) : l), toList<NonNullable<T>>());
135
+ }
91
136
 
92
137
  toObject = (key: keyof T, options: { deleteKey?: boolean } = {}): Record<string | number | symbol, T> =>
93
138
  this.reduce((o: any, i) => {
@@ -104,7 +149,9 @@ export class List<T = unknown> extends Array<T> {
104
149
  return a;
105
150
  }, {} as Record<string | number | symbol, List<T>>);
106
151
 
107
- orElse = (...alt: ArrayLike<T>): Optional<List<T>> => (!isEmpty(this) ? this : !isEmpty(...alt) ? toList<T>(...alt) : undefined);
152
+ orElse(...alt: ArrayLike<T>): Optional<List<T>> {
153
+ return !isEmpty(this) ? this : !isEmpty(...alt) ? toList<T>(...alt) : undefined;
154
+ }
108
155
 
109
156
  weave = (insertFrom: T[], interval: number): this => {
110
157
  for (let i = interval, n = 0; i <= this.length && n < insertFrom.length; i += interval + 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 };
18
-
19
- export const isPageList = <T>(l?: T[]): l is PageList<T> => isList<T>(l) && isA(l, 'total');
20
-
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
- );
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
+ }
152
+
153
+ export const isPageList = <T>(l?: unknown): l is PageList<T> => isList<T>(l) && isA(l, 'total');
154
+
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
@@ -29,13 +29,13 @@ export type InOut = { in?: Func | View; col?: string };
29
29
  const isColOnly = (v: unknown): v is InOut => isObject(v) && isDefined(v.col) && !isDefined(v.in);
30
30
  const isInOnly = (v: unknown): v is InOut => isObject(v) && !isDefined(v.col) && isFunction(v.in);
31
31
  const isColAndFunction = (
32
- v: unknown,
32
+ v: unknown
33
33
  ): v is {
34
34
  col: string;
35
35
  in: Func;
36
36
  } => isObject(v) && isDefined(v.col) && isFunction(v.in);
37
37
  const isColAndView = (
38
- v: unknown,
38
+ v: unknown
39
39
  ): v is {
40
40
  col: string;
41
41
  in: View;
@@ -50,9 +50,9 @@ const toFunc = (a: any, col: string, f: Func = a => a): Func =>
50
50
  const toViewer = (key: string, value: unknown): Viewer =>
51
51
  choose(value)
52
52
  .is.not.defined(
53
- v => v,
54
- () => toViewer(key, () => undefined),
55
- )
53
+ v => v,
54
+ () => toViewer(key, () => undefined)
55
+ )
56
56
  .type(isBoolean, b => toViewer(key, () => b))
57
57
  .type(isNumber, n => toViewer(key, () => n))
58
58
  .type(isString, s => toViewer(key, (a: any) => toFunc(a, s)(a)))
@@ -60,7 +60,7 @@ const toViewer = (key: string, value: unknown): Viewer =>
60
60
  .type(isFunction, f => toViewer(key, { in: { key, f } }))
61
61
  .type(isInOnly, io => toViewer(key, { in: { key, f: io.in } }))
62
62
  .type(isColAndFunction, io => toViewer(key, { in: { key, f: (a: any) => toFunc(a, io.col, io.in)(a) } }))
63
- .type(isColAndView, io => toViewer(key, { in: { key, f: (a: any) => toFunc(a, io.col, io.in.from)(a) } }))
63
+ .type(isColAndView, io => toViewer(key, { in: { key, f: (a: any) => io.in.from(traverse(a, io.col)) } }))
64
64
  .else(v => v as Viewer);
65
65
 
66
66
  const toViewers = (views: Views): Viewer[] =>
@@ -69,22 +69,25 @@ const toViewers = (views: Views): Viewer[] =>
69
69
  .map(([k, v]) => toViewer(k, v));
70
70
 
71
71
  export class View<V = Json> {
72
- constructor(private views: Views<V> = {} as Views<V>, readonly startsFrom: 'scratch' | 'source' = 'scratch', readonly viewers: Viewer[] = toViewers(views)) {
73
- }
72
+ constructor(private views: Views<V> = {} as Views<V>, readonly startsFrom: 'scratch' | 'source' = 'scratch', readonly viewers: Viewer[] = toViewers(views)) {}
74
73
 
75
74
  get fromSource(): View<V> {
76
75
  return new View(this.views, 'source', this.viewers);
77
76
  }
78
77
 
79
- from = <T = unknown>(source: T): T extends PageList<infer V> ? PageList<V> : T extends List<infer V> ? List<V> : T extends Array<infer V> ? V[] : V =>
80
- isArray(source)
81
- ? isPageList(source)
82
- ? toPageList(
83
- source.map(s => this.reduce(asJson(s))),
84
- source,
85
- )
86
- : source.map(s => this.reduce(asJson(s)))
87
- : this.reduce(asJson(source));
78
+ from<T = unknown>(source: PageList<T>): PageList<V>;
79
+ from<T = unknown>(source: List<T>): List<V>;
80
+ from<T = unknown>(source: T[]): V[];
81
+ from<T = unknown>(source: T): V;
82
+ from<T = unknown>(source: PageList<T> | List<T> | T[] | T): PageList<V> | List<V> | V[] | V {
83
+ if (isPageList(source))
84
+ return toPageList(
85
+ source.map(s => this.reduce(asJson(s))),
86
+ source
87
+ );
88
+ if (isArray(source)) return source.map(s => this.reduce(asJson(s)));
89
+ return this.reduce(asJson(source));
90
+ }
88
91
 
89
92
  same = (one?: unknown, another?: unknown): boolean => isEqual(this.from(one), this.from(another));
90
93
 
@@ -101,11 +104,11 @@ export const views = {
101
104
  keepOr: (alt?: unknown) => (a: unknown, key?: string) => traverse(a, key) ?? alt,
102
105
  or:
103
106
  (key: string, alt = '') =>
104
- (a: unknown) =>
105
- traverse(a, key) ?? alt,
107
+ (a: unknown) =>
108
+ traverse(a, key) ?? alt,
106
109
  value: (value: unknown) => () => value,
107
110
  to:
108
111
  <T>(ctor: Constructor<T>) =>
109
- (a: unknown, key?: string) =>
110
- new ctor(traverse(a, key)),
112
+ (a: unknown, key?: string) =>
113
+ new ctor(traverse(a, key)),
111
114
  };