@thisisagile/easy 15.12.13 → 15.13.1

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 (54) hide show
  1. package/dist/domain/enums/Country.d.ts +1 -1
  2. package/dist/domain/enums/Country.js.map +1 -1
  3. package/dist/domain/enums/Country.mjs.map +1 -1
  4. package/dist/domain/values/DateTime.d.ts +3 -3
  5. package/dist/domain/values/DateTime.js +1 -1
  6. package/dist/domain/values/DateTime.js.map +1 -1
  7. package/dist/domain/values/DateTime.mjs +2 -5
  8. package/dist/domain/values/DateTime.mjs.map +1 -1
  9. package/dist/http/CacheControl.d.ts +1 -1
  10. package/dist/http/CacheControl.js.map +1 -1
  11. package/dist/http/CacheControl.mjs.map +1 -1
  12. package/dist/services/ApiGateway.d.ts +3 -3
  13. package/dist/services/ApiGateway.js.map +1 -1
  14. package/dist/services/ApiGateway.mjs.map +1 -1
  15. package/dist/services/RouteGateway.d.ts +3 -3
  16. package/dist/services/RouteGateway.js.map +1 -1
  17. package/dist/services/RouteGateway.mjs.map +1 -1
  18. package/dist/types/Array.js.map +1 -1
  19. package/dist/types/Array.mjs.map +1 -1
  20. package/dist/types/Falsy.d.ts +1 -1
  21. package/dist/types/Falsy.js.map +1 -1
  22. package/dist/types/Falsy.mjs.map +1 -1
  23. package/dist/types/List.d.ts +6 -6
  24. package/dist/types/List.js.map +1 -1
  25. package/dist/types/List.mjs.map +1 -1
  26. package/dist/types/Meta.js.map +1 -1
  27. package/dist/types/Meta.mjs.map +1 -1
  28. package/dist/utils/Base64.d.ts +1 -1
  29. package/dist/utils/Base64.js.map +1 -1
  30. package/dist/utils/Base64.mjs.map +1 -1
  31. package/dist/utils/Log.js.map +1 -1
  32. package/dist/utils/Log.mjs.map +1 -1
  33. package/dist/utils/Sentence.d.ts +4 -4
  34. package/dist/utils/Sentence.js.map +1 -1
  35. package/dist/utils/Sentence.mjs.map +1 -1
  36. package/dist/validation/Contraints.d.ts +1 -0
  37. package/dist/validation/Contraints.js +3 -0
  38. package/dist/validation/Contraints.js.map +1 -1
  39. package/dist/validation/Contraints.mjs +2 -0
  40. package/dist/validation/Contraints.mjs.map +1 -1
  41. package/package.json +2 -2
  42. package/src/domain/enums/Country.ts +250 -250
  43. package/src/domain/values/DateTime.ts +17 -22
  44. package/src/http/CacheControl.ts +13 -14
  45. package/src/services/ApiGateway.ts +3 -3
  46. package/src/services/RouteGateway.ts +4 -4
  47. package/src/types/Array.ts +11 -10
  48. package/src/types/Falsy.ts +1 -1
  49. package/src/types/List.ts +13 -14
  50. package/src/types/Meta.ts +0 -1
  51. package/src/utils/Base64.ts +4 -4
  52. package/src/utils/Log.ts +1 -2
  53. package/src/utils/Sentence.ts +4 -4
  54. package/src/validation/Contraints.ts +3 -0
@@ -1,20 +1,15 @@
1
- import { choose, isA, isDate, isDefined, isNumber, isString, JsonValue, Optional, Value } from "../../types";
2
- import {
3
- DateTime as LuxonDateTime,
4
- DateTimeUnit as LuxonDateTimeUnit,
5
- DurationUnit as LuxonDurationUnit,
6
- Settings
7
- } from "luxon";
8
- import { ifDefined } from "../../utils";
1
+ import { choose, isA, isDate, isDefined, isNumber, isString, JsonValue, Optional, Value } from '../../types';
2
+ import { DateTime as LuxonDateTime, DateTimeUnit as LuxonDateTimeUnit, DurationUnit as LuxonDurationUnit, Settings } from 'luxon';
3
+ import { ifDefined } from '../../utils';
9
4
 
10
- Settings.defaultZone = "utc";
5
+ Settings.defaultZone = 'utc';
11
6
 
12
7
  export type DateTimeUnit = LuxonDateTimeUnit;
13
8
  export type DurationUnit = LuxonDurationUnit;
14
9
  export type Duration = Partial<Record<DurationUnit, number>>;
15
10
 
16
11
  export type DiffOptions = {
17
- rounding: "floor" | "ceil" | "round";
12
+ rounding: 'floor' | 'ceil' | 'round';
18
13
  };
19
14
 
20
15
  export class DateTime extends Value<Optional<string>> {
@@ -44,7 +39,7 @@ export class DateTime extends Value<Optional<string>> {
44
39
  }
45
40
 
46
41
  protected get utc(): LuxonDateTime {
47
- return this.luxon.setZone("utc");
42
+ return this.luxon.setZone('utc');
48
43
  }
49
44
 
50
45
  protected get luxon(): LuxonDateTime {
@@ -59,7 +54,7 @@ export class DateTime extends Value<Optional<string>> {
59
54
 
60
55
  from(param?: string | DateTime, other?: string): string {
61
56
  const date: Optional<DateTime> = isA<DateTime>(param) ? param : undefined;
62
- const locale: string = isString(param) ? param : undefined ?? other ?? "en";
57
+ const locale: string = (isString(param) ? param : undefined) ?? other ?? 'en';
63
58
  return ifDefined(
64
59
  date,
65
60
  d => this.utc.setLocale(locale).toRelative({ base: d.utc }),
@@ -76,32 +71,32 @@ export class DateTime extends Value<Optional<string>> {
76
71
  }
77
72
 
78
73
  equals(dt: DateTime): boolean {
79
- return this.utc.hasSame(dt.utc, "millisecond");
74
+ return this.utc.hasSame(dt.utc, 'millisecond');
80
75
  }
81
76
 
82
77
  add(n: number): DateTime;
83
78
  add(n: number, unit: DurationUnit): DateTime;
84
79
  add(duration: Duration): DateTime;
85
80
  add(n: number | Duration, unit?: DurationUnit): DateTime {
86
- return new DateTime(this.luxon.plus(isNumber(n) ? { [unit ?? 'day' as string]: n } : n).toISO());
81
+ return new DateTime(this.luxon.plus(isNumber(n) ? { [unit ?? ('day' as string)]: n } : n).toISO());
87
82
  }
88
83
 
89
84
  subtract(n: number): DateTime;
90
85
  subtract(n: number, unit: DurationUnit): DateTime;
91
86
  subtract(duration: Duration): DateTime;
92
87
  subtract(n: number | Duration, unit?: DurationUnit): DateTime {
93
- return new DateTime(this.luxon.minus(isNumber(n) ? { [unit ?? 'day' as string]: n } : n).toISO());
88
+ return new DateTime(this.luxon.minus(isNumber(n) ? { [unit ?? ('day' as string)]: n } : n).toISO());
94
89
  }
95
90
 
96
- diff(other: DateTime, unit: DateTimeUnit = "day", opts?: DiffOptions): number {
97
- return Math[opts?.rounding ?? "floor"](this.utc.diff(other.utc).as(unit));
91
+ diff(other: DateTime, unit: DateTimeUnit = 'day', opts?: DiffOptions): number {
92
+ return Math[opts?.rounding ?? 'floor'](this.utc.diff(other.utc).as(unit));
98
93
  }
99
94
 
100
- startOf(unit: DateTimeUnit = "day"): DateTime {
95
+ startOf(unit: DateTimeUnit = 'day'): DateTime {
101
96
  return new DateTime(this.luxon.startOf(unit).toISO());
102
97
  }
103
98
 
104
- endOf(unit: DateTimeUnit = "day"): DateTime {
99
+ endOf(unit: DateTimeUnit = 'day'): DateTime {
105
100
  return new DateTime(this.luxon.endOf(unit).toISO());
106
101
  }
107
102
 
@@ -110,7 +105,7 @@ export class DateTime extends Value<Optional<string>> {
110
105
  }
111
106
 
112
107
  toString(): string {
113
- return this.value ?? "";
108
+ return this.value ?? '';
114
109
  }
115
110
 
116
111
  toJSON(): JsonValue {
@@ -121,12 +116,12 @@ export class DateTime extends Value<Optional<string>> {
121
116
  return this.luxon.toFormat(format);
122
117
  }
123
118
 
124
- toLocale(locale = "nl-NL", format = "D"): string {
119
+ toLocale(locale = 'nl-NL', format = 'D'): string {
125
120
  return this.luxon.setLocale(locale).toFormat(format);
126
121
  }
127
122
 
128
123
  toFull(locale?: string): string {
129
- return this.toLocale(locale, "DDD");
124
+ return this.toLocale(locale, 'DDD');
130
125
  }
131
126
 
132
127
  toDate(): Optional<Date> {
@@ -1,11 +1,10 @@
1
- import { cacheAge, CacheAge, entries, isNumber, on } from "../types";
2
- import { ifDefined } from "../utils";
1
+ import { cacheAge, CacheAge, entries, isNumber, 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
9
  static disabled = () => new CacheControl(false);
11
10
 
@@ -21,27 +20,27 @@ export class CacheControl {
21
20
 
22
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
39
  value = (): string => this.toString();
41
40
 
42
41
  toString(): string {
43
42
  return entries(this.directives)
44
43
  .mapDefined(([k, v]) => ifDefined(v, isNumber(v) ? `${k}=${cacheAge.toSeconds(v)}` : k))
45
- .join(",");
44
+ .join(',');
46
45
  }
47
46
  }
@@ -1,6 +1,6 @@
1
- import { Api, RouteOptions } from "./Api";
2
- import { FetchOptions, Gateway, Json, Optional, PageList, toPageList, Uri, use } from "../types";
3
- import { RequestOptions } from "../http";
1
+ import { Api, RouteOptions } from './Api';
2
+ import { FetchOptions, Gateway, Json, Optional, PageList, toPageList, Uri, use } from '../types';
3
+ import { RequestOptions } from '../http';
4
4
 
5
5
  export class ApiGateway extends Gateway<RouteOptions> {
6
6
  constructor(readonly api: Api = new Api()) {
@@ -1,7 +1,7 @@
1
- import { Api, RouteOptions } from "./Api";
2
- import { Func, Id, Json, JsonValue, List, Optional, PageList, toArray, Uri } from "../types";
3
- import { HttpStatus } from "../http";
4
- import { ApiGateway } from "./ApiGateway";
1
+ import { Api, RouteOptions } from './Api';
2
+ import { Func, Id, Json, JsonValue, List, Optional, PageList, toArray, Uri } from '../types';
3
+ import { HttpStatus } from '../http';
4
+ import { ApiGateway } from './ApiGateway';
5
5
 
6
6
  export class RouteGateway extends ApiGateway {
7
7
  constructor(readonly route: Func<Uri>, readonly routeId: Func<Uri>, readonly api: Api = new Api()) {
@@ -1,5 +1,5 @@
1
- import { isArray, isDefined } from "./Is";
2
- import { on, use } from "./Constructor";
1
+ import { isArray, isDefined } from './Is';
2
+ import { on, use } from './Constructor';
3
3
 
4
4
  export type OneOrMore<T> = T | Array<T>;
5
5
  export type ArrayLike<T> = OneOrMore<T>[];
@@ -14,18 +14,19 @@ export const toObject = <T>(key: keyof T, ...items: ArrayLike<T>): Record<string
14
14
  }, {});
15
15
 
16
16
  export const array = {
17
- merge: (first: any[] = [], second: any[] = [], firstKey = "id", secondKey = "id"): any[] =>
17
+ merge: (first: any[] = [], second: any[] = [], firstKey = 'id', secondKey = 'id'): any[] =>
18
18
  first.map(f => ({
19
19
  ...f,
20
- ...second.find(s => isDefined(s[secondKey]) && isDefined(f[firstKey]) && s[secondKey] === f[firstKey])
20
+ ...second.find(s => isDefined(s[secondKey]) && isDefined(f[firstKey]) && s[secondKey] === f[firstKey]),
21
21
  })),
22
- switch: <T>(items: T[] = [], item: T): T[] => use([...items], res => {
23
- on(res.indexOf(item), i => (i !== -1 ? res.splice(i, 1) : res.push(item)));
24
- return res;
25
- }),
22
+ switch: <T>(items: T[] = [], item: T): T[] =>
23
+ use([...items], res => {
24
+ on(res.indexOf(item), i => (i !== -1 ? res.splice(i, 1) : res.push(item)));
25
+ return res;
26
+ }),
26
27
  splitIn: <T>(items: T[] = [], length = 2): T[][] => {
27
28
  const res: T[][] = Array.from({ length }, () => []);
28
29
  items.forEach((i, index) => res[index % length].push(i));
29
30
  return res;
30
- }
31
- };
31
+ },
32
+ };
@@ -1,4 +1,4 @@
1
- type Falsy = false | 0 | -0 | 0n | '' | null | undefined;
1
+ type Falsy = false | 0 | 0n | '' | null | undefined;
2
2
  type Truthy<T = unknown> = Exclude<T, Falsy>;
3
3
 
4
4
  export const isFalsy = (v?: unknown): v is Falsy => !v;
package/src/types/List.ts CHANGED
@@ -1,14 +1,14 @@
1
- import { ArrayLike, toArray } from "./Array";
2
- import { Constructor, on } from "./Constructor";
3
- import { json, Json } from "./Json";
4
- import { isArray, isDefined, isEmpty } from "./Is";
5
- import { isA } from "./IsA";
6
- import { Get, GetProperty, ofGet, ofProperty } from "./Get";
7
- import { Id } from "./Id";
8
- import { asString } from "./Text";
9
- import { tryTo } from "./Try";
10
- import { meta } from "./Meta";
11
- import { Optional } from "./Types";
1
+ import { ArrayLike, toArray } from './Array';
2
+ import { Constructor, on } from './Constructor';
3
+ import { json, Json } from './Json';
4
+ import { isArray, isDefined, isEmpty } from './Is';
5
+ import { isA } from './IsA';
6
+ import { Get, GetProperty, ofGet, ofProperty } from './Get';
7
+ import { Id } from './Id';
8
+ import { asString } from './Text';
9
+ import { tryTo } from './Try';
10
+ import { meta } from './Meta';
11
+ import { Optional } from './Types';
12
12
 
13
13
  export class List<T = unknown> extends Array<T> {
14
14
  asc(p: GetProperty<T, any>): List<T> {
@@ -200,14 +200,13 @@ export class List<T = unknown> extends Array<T> {
200
200
  }
201
201
 
202
202
  chunk(chunkSize: number): List<List<T>> {
203
- return this.reduce((acc, _, index) =>
204
- (index % chunkSize === 0) ? on(acc, a => a.push(this.slice(index, index + chunkSize))) : acc, toList<List<T>>());
203
+ return this.reduce((acc, _, index) => (index % chunkSize === 0 ? on(acc, a => a.push(this.slice(index, index + chunkSize))) : acc), toList<List<T>>());
205
204
  }
206
205
  }
207
206
 
208
207
  export const toList = <T = unknown>(...items: ArrayLike<T>): List<T> => new List<T>().add(...items);
209
208
 
210
- export const isList = <T>(l?: unknown): l is List<T> => isDefined(l) && isArray(l) && isA<List<T>>(l, "first", "last", "asc", "desc");
209
+ export const isList = <T>(l?: unknown): l is List<T> => isDefined(l) && isArray(l) && isA<List<T>>(l, 'first', 'last', 'asc', 'desc');
211
210
 
212
211
  export const asList = <T>(c: Constructor<T>, items: unknown | unknown[] = []): List<T> => toList<T>(toArray(items).map(i => new c(i)));
213
212
 
package/src/types/Meta.ts CHANGED
@@ -59,4 +59,3 @@ class PropertyMeta {
59
59
  export const meta = (subject: unknown): ClassMeta => new ClassMeta(subject ?? {});
60
60
 
61
61
  export const entries = <T = unknown>(subject: Record<string, T>): List<Entry<T>> => meta(subject).entries<T>();
62
-
@@ -1,7 +1,7 @@
1
- import { Json } from "../types";
1
+ import { Json } from '../types';
2
2
 
3
3
  export const base64 = {
4
- decode: (data: string): string => Buffer.from(data, "base64").toString("utf-8"),
5
- encode: (data: string): string => Buffer.from(data, "utf-8").toString("base64"),
6
- toJson: (data: string): Json => JSON.parse(base64.decode(data))
4
+ decode: (data: string): string => Buffer.from(data, 'base64').toString('utf-8'),
5
+ encode: (data: string): string => Buffer.from(data, 'utf-8').toString('base64'),
6
+ toJson: (data: string): Json => JSON.parse(base64.decode(data)),
7
7
  };
package/src/utils/Log.ts CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  export function log<T>(t: T): T;
3
2
  export function log<T>(label: string, t: T): T;
4
3
  export function log<T>(labelOrT: string | T, t?: T): T {
@@ -9,4 +8,4 @@ export function log<T>(labelOrT: string | T, t?: T): T {
9
8
  console.log(labelOrT);
10
9
  return labelOrT as T;
11
10
  }
12
- }
11
+ }
@@ -12,10 +12,10 @@ class Topic extends Sentence {
12
12
  it = new Sentence('it', this);
13
13
  anything = new Sentence('anything', this);
14
14
  id = (id: Id) => new Sentence(`id '${id}'`, this);
15
- your = (subject?: unknown) => new Sentence(`your ${subject ?? 'item'}`, this);
16
- a = (subject?: unknown) => new Sentence(subject ? `a ${subject}` : 'an item', this);
17
- an = (subject?: unknown) => new Sentence(`an ${subject ?? 'item'}`, this);
18
- any = (subjects?: unknown) => new Sentence(`any ${subjects ?? 'items'}`, this);
15
+ your = (subject?: Text) => new Sentence(`your ${subject ?? 'item'}`, this);
16
+ a = (subject?: Text) => new Sentence(subject ? `a ${subject}` : 'an item', this);
17
+ an = (subject?: Text) => new Sentence(`an ${subject ?? 'item'}`, this);
18
+ any = (subjects?: Text) => new Sentence(`any ${subjects ?? 'items'}`, this);
19
19
  }
20
20
 
21
21
  class Verb extends Sentence {
@@ -29,6 +29,9 @@ export const includes = (sub: string, message?: string): PropertyDecorator =>
29
29
  export const inList = (values: unknown[], message?: Text): PropertyDecorator =>
30
30
  constraint(v => isDefined(v) && isIn(v, values), message ?? 'Value {actual} must appear in list.');
31
31
 
32
+ export const inOptionalList = (values: unknown[], message?: Text): PropertyDecorator =>
33
+ constraint(v => !isDefined(v) || isIn(v, values), message ?? 'Value {actual} must appear in list.');
34
+
32
35
  export const gt = (limit: number, message?: Text): PropertyDecorator => constraint(v => v > limit, message ?? `Value {actual} must be larger than '${limit}'.`);
33
36
 
34
37
  export const gte = (limit: number, message?: Text): PropertyDecorator =>