@thisisagile/easy 14.2.2 → 14.2.4

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