@thisisagile/easy 14.2.2 → 14.2.3
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/domain/Child.d.ts +1 -1
- package/dist/domain/Child.js +3 -1
- package/dist/domain/Child.js.map +1 -1
- package/dist/domain/Entity.d.ts +1 -1
- package/dist/domain/Entity.js +3 -1
- package/dist/domain/Entity.js.map +1 -1
- package/dist/domain/Struct.d.ts +3 -3
- package/dist/domain/Struct.js +9 -3
- package/dist/domain/Struct.js.map +1 -1
- package/dist/domain/structs/Box.d.ts +2 -2
- package/dist/domain/structs/Box.js +8 -6
- package/dist/domain/structs/Box.js.map +1 -1
- package/dist/domain/structs/Dimension.d.ts +3 -2
- package/dist/domain/structs/Dimension.js +9 -2
- package/dist/domain/structs/Dimension.js.map +1 -1
- package/dist/domain/structs/Money.d.ts +3 -3
- package/dist/domain/structs/Money.js +9 -3
- package/dist/domain/structs/Money.js.map +1 -1
- package/dist/domain/structs/Weight.d.ts +6 -5
- package/dist/domain/structs/Weight.js +18 -5
- package/dist/domain/structs/Weight.js.map +1 -1
- package/dist/resources/Req.js.map +1 -1
- package/dist/types/Enum.js +3 -1
- package/dist/types/Enum.js.map +1 -1
- package/dist/types/List.d.ts +16 -16
- package/dist/types/List.js +62 -39
- package/dist/types/List.js.map +1 -1
- package/dist/types/PageList.js +1 -2
- package/dist/types/PageList.js.map +1 -1
- package/dist/types/Uri.d.ts +2 -2
- package/dist/types/Uri.js +5 -3
- package/dist/types/Uri.js.map +1 -1
- package/dist/utils/View.js.map +1 -1
- package/package.json +2 -2
- package/src/domain/Child.ts +3 -1
- package/src/domain/Entity.ts +3 -2
- package/src/domain/Struct.ts +9 -3
- package/src/domain/structs/Box.ts +6 -4
- package/src/domain/structs/Dimension.ts +13 -2
- package/src/domain/structs/Money.ts +9 -3
- package/src/domain/structs/Weight.ts +23 -5
- package/src/resources/Req.ts +2 -8
- package/src/types/Enum.ts +3 -1
- package/src/types/List.ts +43 -20
- package/src/types/PageList.ts +11 -10
- package/src/types/Uri.ts +99 -94
- package/src/utils/View.ts +11 -12
package/src/types/Uri.ts
CHANGED
|
@@ -1,115 +1,120 @@
|
|
|
1
|
-
import {isBoolean, isDefined, isNotEmpty, isTrue} from './Is';
|
|
2
|
-
import {asString, Text} from './Text';
|
|
3
|
-
import {toName} from './Constructor';
|
|
4
|
-
import {ctx} from './Context';
|
|
5
|
-
import {List, toList} from './List';
|
|
6
|
-
import {meta} from './Meta';
|
|
7
|
-
import {tryTo} from './Try';
|
|
8
|
-
import {Optional} from './Types';
|
|
9
|
-
import {OneOrMore, toArray} from
|
|
1
|
+
import { isBoolean, isDefined, isNotEmpty, isTrue } from './Is';
|
|
2
|
+
import { asString, Text } from './Text';
|
|
3
|
+
import { toName } from './Constructor';
|
|
4
|
+
import { ctx } from './Context';
|
|
5
|
+
import { List, toList } from './List';
|
|
6
|
+
import { meta } from './Meta';
|
|
7
|
+
import { tryTo } from './Try';
|
|
8
|
+
import { Optional } from './Types';
|
|
9
|
+
import { OneOrMore, toArray } from './Array';
|
|
10
10
|
|
|
11
11
|
export type Segment = Text & { key?: string; segment?: string; query?: (value: unknown) => string };
|
|
12
12
|
|
|
13
|
-
export const toSegment = (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} = {}): Segment => ({
|
|
17
|
-
key: key as string,
|
|
13
|
+
export const toSegment = (
|
|
14
|
+
key?: Text,
|
|
15
|
+
{
|
|
18
16
|
segment,
|
|
19
17
|
query,
|
|
20
|
-
|
|
18
|
+
}: {
|
|
19
|
+
segment?: string;
|
|
20
|
+
query?: (value: unknown) => string;
|
|
21
|
+
} = {}
|
|
22
|
+
): Segment => ({
|
|
23
|
+
key: key as string,
|
|
24
|
+
segment,
|
|
25
|
+
query,
|
|
26
|
+
toString: () => asString(key),
|
|
21
27
|
});
|
|
22
28
|
|
|
23
29
|
export const uri = {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
host: (key?: string): Segment => toSegment(key, { segment: key ?? ctx.env.host ?? '$host' }),
|
|
31
|
+
resource: (resource: Uri): Segment => toSegment(toName(resource, 'Uri'), { segment: toName(resource, 'Uri') }),
|
|
32
|
+
segment: (key?: Text): Segment => toSegment(key, { segment: key as string }),
|
|
33
|
+
path: (key: Text): Segment => toSegment(key, { segment: `:${key}` }),
|
|
34
|
+
query: (key: Text): Segment => toSegment(key, { query: (value: unknown): string => (isDefined(value) ? `${key}=${value}` : '') }),
|
|
35
|
+
boolean: (key: Text): Segment => toSegment(key, { query: (value: unknown): string => (isTrue(value) ? `${key}` : '') }),
|
|
30
36
|
};
|
|
31
37
|
|
|
32
38
|
type Prop = { segment: Segment; value: any };
|
|
33
39
|
|
|
34
40
|
const toRoute = (...segments: Segment[]): string =>
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
41
|
+
toList(segments)
|
|
42
|
+
.mapDefined(s => s.segment)
|
|
43
|
+
.join('/');
|
|
38
44
|
|
|
39
45
|
export type Uri = {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
id: (id?: unknown) => Uri;
|
|
47
|
+
query: (q?: unknown) => Uri;
|
|
48
|
+
skip: (n?: number) => Uri;
|
|
49
|
+
take: (n?: number) => Uri;
|
|
50
|
+
path: string;
|
|
51
|
+
route: (resource: string) => string;
|
|
52
|
+
isInternal: boolean;
|
|
53
|
+
toString: () => string;
|
|
48
54
|
};
|
|
49
55
|
|
|
50
56
|
export type UriExpandProps = { q: string };
|
|
51
57
|
|
|
52
58
|
export class EasyUri<Props = UriExpandProps> implements Uri {
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
59
|
+
static readonly id = uri.path('id');
|
|
60
|
+
static readonly ids = uri.query('ids');
|
|
61
|
+
static readonly query = uri.query('q');
|
|
62
|
+
static readonly skip = uri.query('skip');
|
|
63
|
+
static readonly take = uri.query('take');
|
|
64
|
+
|
|
65
|
+
readonly host = uri.host();
|
|
66
|
+
readonly resource = uri.resource(this);
|
|
67
|
+
|
|
68
|
+
protected state: any = {};
|
|
69
|
+
|
|
70
|
+
constructor(readonly segments: Segment[] = []) {}
|
|
71
|
+
|
|
72
|
+
get path(): string {
|
|
73
|
+
return toRoute(uri.segment(''), this.resource, ...this.segments);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
get complete(): string {
|
|
77
|
+
return toRoute(this.host, this.resource, ...this.segments);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
get isInternal(): boolean {
|
|
81
|
+
return toRoute(this.host) === (ctx.env.host ?? '$host');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
protected get props(): List<Prop> {
|
|
85
|
+
return meta(this.state).values<Prop>();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
route = (resource: Optional<string> = this.resource.key): string => toRoute(uri.segment(''), uri.segment(resource?.toLowerCase()), ...this.segments);
|
|
89
|
+
|
|
90
|
+
set = (segment: Segment, value?: unknown): this => {
|
|
91
|
+
tryTo(value)
|
|
92
|
+
.is.defined()
|
|
93
|
+
.accept(value => (this.state[segment.key ?? ''] = { segment, value }));
|
|
94
|
+
return this;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
toString(): string {
|
|
98
|
+
return tryTo(() => this.props)
|
|
99
|
+
.map(ps => ps.filter(p => p.segment?.segment))
|
|
100
|
+
.map(ps => ps.reduce((r: string, p: Prop) => r.replace(asString(p.segment.segment), asString(p.value)), this.complete))
|
|
101
|
+
.map(route => ({
|
|
102
|
+
route,
|
|
103
|
+
query: this.props.mapDefined(p => (p.segment?.query ? p.segment?.query(p.value) : undefined))?.join('&'),
|
|
104
|
+
}))
|
|
105
|
+
.map(({ route, query }) => (isNotEmpty(query) ? `${route}?${query}` : route)).value;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
id = (id?: unknown): this => this.set(EasyUri.id, id);
|
|
109
|
+
ids = (ids: OneOrMore<unknown>): this => this.set(EasyUri.ids, toArray(ids).join(','));
|
|
110
|
+
query = (q?: unknown): this => this.set(EasyUri.query, q);
|
|
111
|
+
|
|
112
|
+
skip = (index?: number): this => this.set(EasyUri.skip, index);
|
|
113
|
+
take = (items?: number): this => this.set(EasyUri.take, items);
|
|
114
|
+
|
|
115
|
+
expand(props: Partial<Props>): this {
|
|
116
|
+
return meta(props)
|
|
117
|
+
.entries()
|
|
118
|
+
.reduce((u, [k, v]) => (isBoolean(v) ? u.set(uri.boolean(k), v) : u.set(uri.query(k), toArray(v).join(','))), this);
|
|
119
|
+
}
|
|
115
120
|
}
|
package/src/utils/View.ts
CHANGED
|
@@ -29,13 +29,13 @@ export type InOut = { in?: Func | View<any>; 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
|
-
|
|
54
|
-
|
|
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)))
|
|
@@ -69,8 +69,7 @@ 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);
|
|
@@ -84,7 +83,7 @@ export class View<V = Json> {
|
|
|
84
83
|
if (isPageList(source))
|
|
85
84
|
return toPageList(
|
|
86
85
|
source.map(s => this.reduce(asJson(s))),
|
|
87
|
-
source
|
|
86
|
+
source
|
|
88
87
|
);
|
|
89
88
|
if (isArray(source)) return source.map(s => this.reduce(asJson(s)));
|
|
90
89
|
return this.reduce(asJson(source));
|
|
@@ -105,11 +104,11 @@ export const views = {
|
|
|
105
104
|
keepOr: (alt?: unknown) => (a: unknown, key?: string) => traverse(a, key) ?? alt,
|
|
106
105
|
or:
|
|
107
106
|
(key: string, alt = '') =>
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
(a: unknown) =>
|
|
108
|
+
traverse(a, key) ?? alt,
|
|
110
109
|
value: (value: unknown) => () => value,
|
|
111
110
|
to:
|
|
112
111
|
<T>(ctor: Constructor<T>) =>
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
(a: unknown, key?: string) =>
|
|
113
|
+
new ctor(traverse(a, key)),
|
|
115
114
|
};
|