@thisisagile/easy 10.9.0 → 10.10.2

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.
@@ -11,6 +11,6 @@ export declare type PageOptions = {
11
11
  export declare type PageList<T> = List<T> & Omit<PageOptions, 'sort'> & {
12
12
  total?: number;
13
13
  };
14
- export declare const toPageList: <T>(items?: T[] | undefined, options?: (PageOptions & {
14
+ export declare const toPageList: <T>(items?: T[] | undefined, options?: (Omit<PageOptions, "sort"> & {
15
15
  total?: number | undefined;
16
16
  }) | undefined) => PageList<T>;
@@ -2,13 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toPageList = void 0;
4
4
  const List_1 = require("./List");
5
- const Json_1 = require("./Json");
6
5
  const toPageList = (items, options) => {
7
- const o = Json_1.json.defaults(options, { take: 250, skip: 0 });
8
6
  const list = (0, List_1.toList)(...(items ?? []));
9
- list.take = o.take;
10
- list.skip = o.skip;
11
- list.total = o.total;
7
+ list.take = options?.take ?? 250;
8
+ list.skip = options?.skip ?? 0;
9
+ list.total = options?.total;
12
10
  return list;
13
11
  };
14
12
  exports.toPageList = toPageList;
@@ -1 +1 @@
1
- {"version":3,"file":"PageList.js","sourceRoot":"","sources":["../../src/types/PageList.ts"],"names":[],"mappings":";;;AAAA,iCAAsC;AACtC,iCAA8B;AAQvB,MAAM,UAAU,GAAG,CAAK,KAAW,EAAE,OAA0C,EAAe,EAAE;IACrG,MAAM,CAAC,GAAG,WAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;IACzD,MAAM,IAAI,GAAG,IAAA,aAAM,EAAI,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAQ,CAAC;IAChD,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;IACnB,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;IACnB,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;IACrB,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAPW,QAAA,UAAU,cAOrB"}
1
+ {"version":3,"file":"PageList.js","sourceRoot":"","sources":["../../src/types/PageList.ts"],"names":[],"mappings":";;;AAAA,iCAAsC;AAQ/B,MAAM,UAAU,GAAG,CAAI,KAAW,EAAE,OAAwD,EAAe,EAAE;IAClH,MAAM,IAAI,GAAG,IAAA,aAAM,EAAI,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAQ,CAAC;IAChD,IAAI,CAAC,IAAI,GAAG,OAAO,EAAE,IAAI,IAAI,GAAG,CAAC;IACjC,IAAI,CAAC,IAAI,GAAG,OAAO,EAAE,IAAI,IAAI,CAAC,CAAC;IAC/B,IAAI,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,CAAC;IAC5B,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AANW,QAAA,UAAU,cAMrB"}
@@ -0,0 +1,10 @@
1
+ import { ErrorOrigin } from '../types';
2
+ export declare class Retry<T = any> {
3
+ readonly subject: () => Promise<T>;
4
+ readonly times: number;
5
+ readonly interval: number;
6
+ readonly prevError?: ErrorOrigin | undefined;
7
+ constructor(subject: () => Promise<T>, times?: number, interval?: number, prevError?: ErrorOrigin | undefined);
8
+ run: () => Promise<T>;
9
+ }
10
+ export declare const retry: <T>(subject: () => Promise<T>, times?: number | undefined, interval?: number | undefined, prevError?: ErrorOrigin | undefined) => Promise<T>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.retry = exports.Retry = void 0;
4
+ const types_1 = require("../types");
5
+ const validation_1 = require("../validation");
6
+ const Wait_1 = require("./Wait");
7
+ class Retry {
8
+ constructor(subject, times = 3, interval = 1000, prevError) {
9
+ this.subject = subject;
10
+ this.times = times;
11
+ this.interval = interval;
12
+ this.prevError = prevError;
13
+ this.run = () => (0, validation_1.when)(this.times)
14
+ .not.isTrue.reject(this.prevError ?? types_1.Exception.CouldNotExecute)
15
+ .then(() => this.subject().catch(async (e) => {
16
+ await (0, Wait_1.wait)(this.interval);
17
+ return (0, exports.retry)(this.subject, this.times - 1, this.interval, e);
18
+ }));
19
+ }
20
+ }
21
+ exports.Retry = Retry;
22
+ const retry = (subject, times, interval, prevError) => new Retry(subject, times, interval, prevError).run();
23
+ exports.retry = retry;
24
+ //# sourceMappingURL=Retry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Retry.js","sourceRoot":"","sources":["../../src/utils/Retry.ts"],"names":[],"mappings":";;;AAAA,oCAAkD;AAClD,8CAAqC;AACrC,iCAA8B;AAE9B,MAAa,KAAK;IAChB,YAAqB,OAAyB,EAAW,QAAQ,CAAC,EAAW,WAAW,IAAI,EAAW,SAAuB;QAAzG,YAAO,GAAP,OAAO,CAAkB;QAAW,UAAK,GAAL,KAAK,CAAI;QAAW,aAAQ,GAAR,QAAQ,CAAO;QAAW,cAAS,GAAT,SAAS,CAAc;QAE9H,QAAG,GAAG,GAAe,EAAE,CACrB,IAAA,iBAAI,EAAC,IAAI,CAAC,KAAK,CAAC;aACb,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,IAAI,iBAAS,CAAC,eAAe,CAAC;aAC9D,IAAI,CAAC,GAAG,EAAE,CACT,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,KAAK,EAAC,CAAC,EAAC,EAAE;YAC7B,MAAM,IAAA,WAAI,EAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC1B,OAAO,IAAA,aAAK,EAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;QAC/D,CAAC,CAAC,CACH,CAAC;IAV2H,CAAC;CAWnI;AAZD,sBAYC;AAEM,MAAM,KAAK,GAAG,CAAI,OAAyB,EAAE,KAAc,EAAE,QAAiB,EAAE,SAAuB,EAAc,EAAE,CAC5H,IAAI,KAAK,CAAI,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,GAAG,EAAE,CAAC;AAD7C,QAAA,KAAK,SACwC"}
@@ -0,0 +1,5 @@
1
+ export declare class Wait {
2
+ static wait(ms?: number): Promise<void>;
3
+ static seconds(s?: number): Promise<void>;
4
+ }
5
+ export declare const wait: (millis: number) => Promise<void>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.wait = exports.Wait = void 0;
4
+ class Wait {
5
+ static wait(ms = 0) {
6
+ return new Promise(resolve => setTimeout(resolve, ms));
7
+ }
8
+ static seconds(s = 0) {
9
+ return this.wait(s * 1000);
10
+ }
11
+ }
12
+ exports.Wait = Wait;
13
+ const wait = (millis) => Wait.wait(millis);
14
+ exports.wait = wait;
15
+ //# sourceMappingURL=Wait.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Wait.js","sourceRoot":"","sources":["../../src/utils/Wait.ts"],"names":[],"mappings":";;;AAAA,MAAa,IAAI;IACf,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC;QAChB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IACzD,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC;QAClB,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAC7B,CAAC;CACF;AARD,oBAQC;AAEM,MAAM,IAAI,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAA7C,QAAA,IAAI,QAAyC"}
@@ -4,7 +4,9 @@ export * from './Log';
4
4
  export * from './Mapper';
5
5
  export * from './Promise';
6
6
  export * from './Property';
7
+ export * from './Retry';
7
8
  export * from './State';
8
9
  export * from './Sentence';
9
10
  export * from './Traverse';
10
11
  export * from './View';
12
+ export * from './Wait';
@@ -20,8 +20,10 @@ __exportStar(require("./Log"), exports);
20
20
  __exportStar(require("./Mapper"), exports);
21
21
  __exportStar(require("./Promise"), exports);
22
22
  __exportStar(require("./Property"), exports);
23
+ __exportStar(require("./Retry"), exports);
23
24
  __exportStar(require("./State"), exports);
24
25
  __exportStar(require("./Sentence"), exports);
25
26
  __exportStar(require("./Traverse"), exports);
26
27
  __exportStar(require("./View"), exports);
28
+ __exportStar(require("./Wait"), exports);
27
29
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,uCAAqB;AACrB,wCAAsB;AACtB,2CAAyB;AACzB,4CAA0B;AAC1B,6CAA2B;AAC3B,0CAAwB;AACxB,6CAA2B;AAC3B,6CAA2B;AAC3B,yCAAuB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,uCAAqB;AACrB,wCAAsB;AACtB,2CAAyB;AACzB,4CAA0B;AAC1B,6CAA2B;AAC3B,0CAAwB;AACxB,0CAAwB;AACxB,6CAA2B;AAC3B,6CAA2B;AAC3B,yCAAuB;AACvB,yCAAuB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thisisagile/easy",
3
- "version": "10.9.0",
3
+ "version": "10.10.2",
4
4
  "description": "Straightforward library for building domain-driven microservice architectures",
5
5
  "author": "Sander Hoogendoorn",
6
6
  "license": "MIT",
@@ -31,7 +31,7 @@
31
31
  "access": "public"
32
32
  },
33
33
  "devDependencies": {
34
- "@thisisagile/easy-test": "10.9.0",
34
+ "@thisisagile/easy-test": "10.10.2",
35
35
  "@types/form-urlencoded": "^4.4.0",
36
36
  "@types/jsonwebtoken": "^8.5.8",
37
37
  "@types/validator": "^13.7.2"
@@ -1,17 +1,15 @@
1
1
  import { List, toList } from './List';
2
- import { json } from './Json';
3
2
 
4
- export type Sort = { key: string, value: -1 | 1 };
3
+ export type Sort = { key: string; value: -1 | 1 };
5
4
 
6
- export type PageOptions = { take?: number, skip?: number, sort?: Sort[] };
5
+ export type PageOptions = { take?: number; skip?: number; sort?: Sort[] };
7
6
 
8
7
  export type PageList<T> = List<T> & Omit<PageOptions, 'sort'> & { total?: number };
9
8
 
10
- export const toPageList = <T>( items?: T[], options?: PageOptions & { total?: number }): PageList<T> => {
11
- const o = json.defaults(options, { take: 250, skip: 0 });
9
+ export const toPageList = <T>(items?: T[], options?: Omit<PageOptions, 'sort'> & { total?: number }): PageList<T> => {
12
10
  const list = toList<T>(...(items ?? [])) as any;
13
- list.take = o.take;
14
- list.skip = o.skip;
15
- list.total = o.total;
11
+ list.take = options?.take ?? 250;
12
+ list.skip = options?.skip ?? 0;
13
+ list.total = options?.total;
16
14
  return list;
17
15
  };
@@ -0,0 +1,20 @@
1
+ import { ErrorOrigin, Exception } from '../types';
2
+ import { when } from '../validation';
3
+ import { wait } from './Wait';
4
+
5
+ export class Retry<T = any> {
6
+ constructor(readonly subject: () => Promise<T>, readonly times = 3, readonly interval = 1000, readonly prevError?: ErrorOrigin) {}
7
+
8
+ run = (): Promise<T> =>
9
+ when(this.times)
10
+ .not.isTrue.reject(this.prevError ?? Exception.CouldNotExecute)
11
+ .then(() =>
12
+ this.subject().catch(async e => {
13
+ await wait(this.interval);
14
+ return retry(this.subject, this.times - 1, this.interval, e);
15
+ })
16
+ );
17
+ }
18
+
19
+ export const retry = <T>(subject: () => Promise<T>, times?: number, interval?: number, prevError?: ErrorOrigin): Promise<T> =>
20
+ new Retry<T>(subject, times, interval, prevError).run();
@@ -0,0 +1,11 @@
1
+ export class Wait {
2
+ static wait(ms = 0): Promise<void> {
3
+ return new Promise(resolve => setTimeout(resolve, ms));
4
+ }
5
+
6
+ static seconds(s = 0) {
7
+ return this.wait(s * 1000);
8
+ }
9
+ }
10
+
11
+ export const wait = (millis: number) => Wait.wait(millis);
@@ -4,7 +4,9 @@ export * from './Log';
4
4
  export * from './Mapper';
5
5
  export * from './Promise';
6
6
  export * from './Property';
7
+ export * from './Retry';
7
8
  export * from './State';
8
9
  export * from './Sentence';
9
10
  export * from './Traverse';
10
11
  export * from './View';
12
+ export * from './Wait';