@thisisagile/easy 10.5.8 → 10.5.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.
- package/dist/http/RestResult.d.ts +1 -1
- package/dist/http/RestResult.js +3 -2
- package/dist/http/RestResult.js.map +1 -1
- package/dist/services/RouteGateway.d.ts +4 -4
- package/dist/services/RouteGateway.js +1 -1
- package/dist/services/RouteGateway.js.map +1 -1
- package/dist/types/Gateway.d.ts +1 -1
- package/dist/types/Gateway.js.map +1 -1
- package/dist/types/List.d.ts +0 -3
- package/dist/types/TotalledList.d.ts +6 -0
- package/dist/types/TotalledList.js +11 -0
- package/dist/types/TotalledList.js.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/package.json +2 -2
- package/src/http/RestResult.ts +4 -3
- package/src/services/RouteGateway.ts +5 -5
- package/src/types/Gateway.ts +1 -1
- package/src/types/List.ts +0 -1
- package/src/types/TotalledList.ts +10 -0
- package/src/types/index.ts +1 -0
|
@@ -15,7 +15,7 @@ export declare type RestResult = {
|
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
17
|
export declare const rest: {
|
|
18
|
-
toData: (status: HttpStatus, items?: Json[]) => RestResult;
|
|
18
|
+
toData: (status: HttpStatus, items?: Json[], totalItems?: number | undefined) => RestResult;
|
|
19
19
|
toError: (status: HttpStatus, errors?: Result[]) => RestResult;
|
|
20
20
|
to: (payload?: any | any[], status?: HttpStatus | undefined) => RestResult;
|
|
21
21
|
};
|
package/dist/http/RestResult.js
CHANGED
|
@@ -7,11 +7,12 @@ const Response_1 = require("./Response");
|
|
|
7
7
|
const hasErrors = (a) => (0, types_1.isDefined)(a?.error?.errors);
|
|
8
8
|
const hasItems = (a) => (0, types_1.isDefined)(a?.data.items);
|
|
9
9
|
exports.rest = {
|
|
10
|
-
toData: (status, items = []) => ({
|
|
10
|
+
toData: (status, items = [], totalItems) => ({
|
|
11
11
|
data: {
|
|
12
12
|
code: status.status,
|
|
13
13
|
items: (0, types_1.toList)(items),
|
|
14
14
|
itemCount: items.length,
|
|
15
|
+
totalItems
|
|
15
16
|
},
|
|
16
17
|
}),
|
|
17
18
|
toError: (status, errors = [(0, types_1.toResult)(status.name)]) => ({
|
|
@@ -30,7 +31,7 @@ exports.rest = {
|
|
|
30
31
|
.type(types_1.isResults, r => exports.rest.toError(status ?? HttpStatus_1.HttpStatus.BadRequest, r.results))
|
|
31
32
|
.type(Response_1.isResponse, r => exports.rest.toError(status ?? HttpStatus_1.HttpStatus.byId(r.body.error?.code), r.body.error?.errors))
|
|
32
33
|
.type(hasErrors, e => exports.rest.toError(status ?? HttpStatus_1.HttpStatus.byId(e.error.code, HttpStatus_1.HttpStatus.BadRequest), e.error.errors))
|
|
33
|
-
.type(hasItems, d => exports.rest.toData(status ?? HttpStatus_1.HttpStatus.byId(d.data.code, HttpStatus_1.HttpStatus.Ok), d.data.items))
|
|
34
|
+
.type(hasItems, d => exports.rest.toData(status ?? HttpStatus_1.HttpStatus.byId(d.data.code, HttpStatus_1.HttpStatus.Ok), d.data.items, d.data.totalItems))
|
|
34
35
|
.else(p => exports.rest.toData(status ?? HttpStatus_1.HttpStatus.Ok, (0, types_1.toList)(p))),
|
|
35
36
|
};
|
|
36
37
|
const isRestResult = (r) => (0, types_1.isDefined)(r) && ((0, types_1.isDefined)(r.data) || (0, types_1.isDefined)(r.error));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RestResult.js","sourceRoot":"","sources":["../../src/http/RestResult.ts"],"names":[],"mappings":";;;AAAA,oCAakB;AAClB,6CAAwD;AACxD,yCAAwC;AAOxC,MAAM,SAAS,GAAG,CAAC,CAAM,EAA0D,EAAE,CAAC,IAAA,iBAAS,EAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAClH,MAAM,QAAQ,GAAG,CAAC,CAAM,
|
|
1
|
+
{"version":3,"file":"RestResult.js","sourceRoot":"","s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AC,CAAC;SACxH,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,YAAI,CAAC,MAAM,CAAC,MAAM,IAAI,uBAAU,CAAC,EAAE,EAAE,IAAA,cAAM,EAAC,CAAC,CAAC,CAAC,CAAC;CAChE,CAAC;AAEK,MAAM,YAAY,GAAG,CAAC,CAAU,EAAmB,EAAE,CAAC,IAAA,iBAAS,EAAC,CAAC,CAAC,IAAI,CAAC,IAAA,iBAAS,EAAE,CAAgB,CAAC,IAAI,CAAC,IAAI,IAAA,iBAAS,EAAE,CAAgB,CAAC,KAAK,CAAC,CAAC,CAAC;AAA1I,QAAA,YAAY,gBAA8H"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { Api } from './Api';
|
|
2
|
-
import { Func, Gateway, Id, Json, JsonValue,
|
|
2
|
+
import { Func, Gateway, Id, Json, JsonValue, TotalledList, Uri } from '../types';
|
|
3
3
|
import { RequestOptions } from '../http';
|
|
4
4
|
export declare class RouteGateway extends Gateway {
|
|
5
5
|
readonly route: Func<Uri>;
|
|
6
6
|
readonly routeId: Func<Uri>;
|
|
7
7
|
readonly api: Api;
|
|
8
8
|
constructor(route: Func<Uri>, routeId: Func<Uri>, api?: Api);
|
|
9
|
-
get(uri: Uri, options?: RequestOptions): Promise<
|
|
9
|
+
get(uri: Uri, options?: RequestOptions): Promise<TotalledList<Json>>;
|
|
10
10
|
getOne(uri: Uri, options?: RequestOptions): Promise<Json | undefined>;
|
|
11
|
-
all(): Promise<
|
|
11
|
+
all(): Promise<TotalledList<Json>>;
|
|
12
12
|
byId(id: Id): Promise<Json | undefined>;
|
|
13
|
-
search(q: JsonValue): Promise<
|
|
13
|
+
search(q: JsonValue): Promise<TotalledList<Json>>;
|
|
14
14
|
exists(id: Id): Promise<boolean>;
|
|
15
15
|
add(item: Json): Promise<Json>;
|
|
16
16
|
update(item: Json): Promise<Json>;
|
|
@@ -12,7 +12,7 @@ class RouteGateway extends types_1.Gateway {
|
|
|
12
12
|
this.api = api;
|
|
13
13
|
}
|
|
14
14
|
get(uri, options) {
|
|
15
|
-
return this.api.get(uri, options).then(r => r.body.data?.items
|
|
15
|
+
return this.api.get(uri, options).then(r => (0, types_1.toTotalledList)(r.body.data?.items, r.body.data?.totalItems));
|
|
16
16
|
}
|
|
17
17
|
getOne(uri, options) {
|
|
18
18
|
return this.get(uri, options).then(r => r.first());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RouteGateway.js","sourceRoot":"","sources":["../../src/services/RouteGateway.ts"],"names":[],"mappings":";;;AAAA,+BAA4B;AAC5B,
|
|
1
|
+
{"version":3,"file":"RouteGateway.js","sourceRoot":"","sources":["../../src/services/RouteGateway.ts"],"names":[],"mappings":";;;AAAA,+BAA4B;AAC5B,oCAAiG;AACjG,kCAAqD;AAErD,MAAa,YAAa,SAAQ,eAAO;IACvC,YAAqB,KAAgB,EAAW,OAAkB,EAAW,MAAW,IAAI,SAAG,EAAE;QAC/F,KAAK,EAAE,CAAC;QADW,UAAK,GAAL,KAAK,CAAW;QAAW,YAAO,GAAP,OAAO,CAAW;QAAW,QAAG,GAAH,GAAG,CAAiB;IAEjG,CAAC;IAED,GAAG,CAAC,GAAQ,EAAE,OAAwB;QACpC,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAA,sBAAc,EAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC;IACjH,CAAC;IAED,MAAM,CAAC,GAAQ,EAAE,OAAwB;QACvC,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;IACrD,CAAC;IAED,GAAG;QACD,OAAO,IAAI,CAAC,GAA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AK,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACtG,CAAC;IAED,MAAM,CAAC,IAAU;QACf,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACpG,CAAC;IAED,MAAM,CAAC,EAAM;QACX,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;IACjE,CAAC;CACF;AA9CD,oCA8CC"}
|
package/dist/types/Gateway.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { TotalledList } from './List';
|
|
2
1
|
import { Json, JsonValue } from './Json';
|
|
3
2
|
import { Id } from './Id';
|
|
3
|
+
import { TotalledList } from './TotalledList';
|
|
4
4
|
export declare abstract class Gateway {
|
|
5
5
|
all(): Promise<TotalledList<Json>>;
|
|
6
6
|
byId(id: Id): Promise<Json | undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Gateway.js","sourceRoot":"","sources":["../../src/types/Gateway.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"Gateway.js","sourceRoot":"","sources":["../../src/types/Gateway.ts"],"names":[],"mappings":";;;AAEA,2CAAwC;AACxC,oCAAkC;AAGlC,MAAsB,OAAO;IAC3B,GAAG;QACD,OAAO,IAAA,cAAM,EAAC,qBAAS,CAAC,gBAAgB,CAAC,CAAC;IAC5C,CAAC;IAED,IAAI,CAAC,EAAM;QACT,OAAO,IAAA,cAAM,EAAC,qBAAS,CAAC,gBAAgB,CAAC,CAAC;IAC5C,CAAC;IAED,EAAE,CAAC,GAAW,EAAE,KAAgB;QAC9B,OAAO,IAAA,cAAM,EAAC,qBAAS,CAAC,gBAAgB,CAAC,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,GAAG,GAAS;QAChB,OAAO,IAAA,cAAM,EAAC,qBAAS,CAAC,gBAAgB,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,CAAC,CAAY;QACjB,OAAO,IAAA,cAAM,EAAC,qBAAS,CAAC,gBAAgB,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,CAAC,EAAM;QACX,OAAO,IAAA,cAAM,EAAC,qBAAS,CAAC,gBAAgB,CAAC,CAAC;IAC5C,CAAC;IAED,GAAG,CAAC,IAAU;QACZ,OAAO,IAAA,cAAM,EAAC,qBAAS,CAAC,gBAAgB,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,CAAC,IAAU;QACf,OAAO,IAAA,cAAM,EAAC,qBAAS,CAAC,gBAAgB,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,CAAC,EAAM;QACX,OAAO,IAAA,cAAM,EAAC,qBAAS,CAAC,gBAAgB,CAAC,CAAC;IAC5C,CAAC;CACF;AApCD,0BAoCC"}
|
package/dist/types/List.d.ts
CHANGED
|
@@ -36,6 +36,3 @@ export declare class List<T = unknown> extends Array<T> {
|
|
|
36
36
|
export declare const toList: <T = unknown>(...items: ArrayLike<T>) => List<T>;
|
|
37
37
|
export declare const isList: <T>(l?: unknown) => l is List<T>;
|
|
38
38
|
export declare const asList: <T>(c: Constructor<T>, items?: unknown | unknown[]) => List<T>;
|
|
39
|
-
export declare type TotalledList<T> = List<T> & {
|
|
40
|
-
total?: number;
|
|
41
|
-
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toTotalledList = void 0;
|
|
4
|
+
const List_1 = require("./List");
|
|
5
|
+
const toTotalledList = (items, total) => {
|
|
6
|
+
const list = (0, List_1.toList)(...items ?? []);
|
|
7
|
+
list.total = total;
|
|
8
|
+
return list;
|
|
9
|
+
};
|
|
10
|
+
exports.toTotalledList = toTotalledList;
|
|
11
|
+
//# sourceMappingURL=TotalledList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TotalledList.js","sourceRoot":"","sources":["../../src/types/TotalledList.ts"],"names":[],"mappings":";;;AAAA,iCAAsC;AAK/B,MAAM,cAAc,GAAG,CAAI,KAAoB,EAAE,KAAc,EAAmB,EAAE;IACzF,MAAM,IAAI,GAAG,IAAA,aAAM,EAAI,GAAG,KAAK,IAAI,EAAE,CAAC,CAAC;IACtC,IAAY,CAAC,KAAK,GAAG,KAAK,CAAC;IAC5B,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAJW,QAAA,cAAc,kBAIzB"}
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
|
@@ -41,6 +41,7 @@ __exportStar(require("./Results"), exports);
|
|
|
41
41
|
__exportStar(require("./Tag"), exports);
|
|
42
42
|
__exportStar(require("./Template"), exports);
|
|
43
43
|
__exportStar(require("./Text"), exports);
|
|
44
|
+
__exportStar(require("./TotalledList"), exports);
|
|
44
45
|
__exportStar(require("./Try"), exports);
|
|
45
46
|
__exportStar(require("./Uri"), exports);
|
|
46
47
|
__exportStar(require("./Uuid"), exports);
|
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,4CAA0B;AAC1B,yCAAuB;AACvB,gDAA8B;AAC9B,4CAA0B;AAC1B,yCAAuB;AACvB,gDAA8B;AAC9B,8CAA4B;AAC5B,yCAAuB;AACvB,4CAA0B;AAC1B,wCAAsB;AACtB,uCAAqB;AACrB,6CAA2B;AAC3B,uCAAqB;AACrB,wCAAsB;AACtB,2CAAyB;AACzB,4CAA0B;AAC1B,yCAAuB;AACvB,yCAAuB;AACvB,4CAA0B;AAC1B,yCAAuB;AACvB,2CAAyB;AACzB,2CAAyB;AACzB,4CAA0B;AAC1B,wCAAsB;AACtB,6CAA2B;AAC3B,yCAAuB;AACvB,wCAAsB;AACtB,wCAAsB;AACtB,yCAAuB;AACvB,gDAA8B;AAC9B,0CAAwB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,4CAA0B;AAC1B,yCAAuB;AACvB,gDAA8B;AAC9B,4CAA0B;AAC1B,yCAAuB;AACvB,gDAA8B;AAC9B,8CAA4B;AAC5B,yCAAuB;AACvB,4CAA0B;AAC1B,wCAAsB;AACtB,uCAAqB;AACrB,6CAA2B;AAC3B,uCAAqB;AACrB,wCAAsB;AACtB,2CAAyB;AACzB,4CAA0B;AAC1B,yCAAuB;AACvB,yCAAuB;AACvB,4CAA0B;AAC1B,yCAAuB;AACvB,2CAAyB;AACzB,2CAAyB;AACzB,4CAA0B;AAC1B,wCAAsB;AACtB,6CAA2B;AAC3B,yCAAuB;AACvB,iDAA+B;AAC/B,wCAAsB;AACtB,wCAAsB;AACtB,yCAAuB;AACvB,gDAA8B;AAC9B,0CAAwB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thisisagile/easy",
|
|
3
|
-
"version": "10.5.
|
|
3
|
+
"version": "10.5.12",
|
|
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.5.
|
|
34
|
+
"@thisisagile/easy-test": "10.5.12",
|
|
35
35
|
"@types/form-urlencoded": "^4.4.0",
|
|
36
36
|
"@types/jsonwebtoken": "^8.5.8",
|
|
37
37
|
"@types/validator": "^13.7.2"
|
package/src/http/RestResult.ts
CHANGED
|
@@ -21,14 +21,15 @@ export type RestResult = {
|
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
const hasErrors = (a: any): a is { error: { code: number; errors: List<Result> } } => isDefined(a?.error?.errors);
|
|
24
|
-
const hasItems = (a: any): a is { data: { code: number; items: List<Json
|
|
24
|
+
const hasItems = (a: any): a is { data: { code: number; items: List<Json>, totalItems?: number } } => isDefined(a?.data.items);
|
|
25
25
|
|
|
26
26
|
export const rest = {
|
|
27
|
-
toData: (status: HttpStatus, items: Json[] = []): RestResult => ({
|
|
27
|
+
toData: (status: HttpStatus, items: Json[] = [], totalItems?: number): RestResult => ({
|
|
28
28
|
data: {
|
|
29
29
|
code: status.status,
|
|
30
30
|
items: toList(items),
|
|
31
31
|
itemCount: items.length,
|
|
32
|
+
totalItems
|
|
32
33
|
},
|
|
33
34
|
}),
|
|
34
35
|
toError: (status: HttpStatus, errors: Result[] = [toResult(status.name)]): RestResult => ({
|
|
@@ -48,7 +49,7 @@ export const rest = {
|
|
|
48
49
|
.type(isResults, r => rest.toError(status ?? HttpStatus.BadRequest, r.results))
|
|
49
50
|
.type(isResponse, r => rest.toError(status ?? HttpStatus.byId(r.body.error?.code as Id), r.body.error?.errors))
|
|
50
51
|
.type(hasErrors, e => rest.toError(status ?? HttpStatus.byId(e.error.code, HttpStatus.BadRequest), e.error.errors))
|
|
51
|
-
.type(hasItems, d => rest.toData(status ?? HttpStatus.byId(d.data.code, HttpStatus.Ok), d.data.items))
|
|
52
|
+
.type(hasItems, d => rest.toData(status ?? HttpStatus.byId(d.data.code, HttpStatus.Ok), d.data.items, d.data.totalItems))
|
|
52
53
|
.else(p => rest.toData(status ?? HttpStatus.Ok, toList(p))),
|
|
53
54
|
};
|
|
54
55
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Api } from './Api';
|
|
2
|
-
import { Func, Gateway, Id, Json, JsonValue,
|
|
2
|
+
import { Func, Gateway, Id, Json, JsonValue, TotalledList, toTotalledList, Uri } from '../types';
|
|
3
3
|
import { HttpStatus, RequestOptions } from '../http';
|
|
4
4
|
|
|
5
5
|
export class RouteGateway extends Gateway {
|
|
@@ -7,15 +7,15 @@ export class RouteGateway extends Gateway {
|
|
|
7
7
|
super();
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
get(uri: Uri, options?: RequestOptions): Promise<
|
|
11
|
-
return this.api.get(uri, options).then(r => r.body.data?.items
|
|
10
|
+
get(uri: Uri, options?: RequestOptions): Promise<TotalledList<Json>> {
|
|
11
|
+
return this.api.get(uri, options).then(r => toTotalledList<Json>(r.body.data?.items, r.body.data?.totalItems));
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
getOne(uri: Uri, options?: RequestOptions): Promise<Json | undefined> {
|
|
15
15
|
return this.get(uri, options).then(r => r.first());
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
all(): Promise<
|
|
18
|
+
all(): Promise<TotalledList<Json>> {
|
|
19
19
|
return this.get(this.route());
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -23,7 +23,7 @@ export class RouteGateway extends Gateway {
|
|
|
23
23
|
return this.getOne(this.routeId().id(id));
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
search(q: JsonValue): Promise<
|
|
26
|
+
search(q: JsonValue): Promise<TotalledList<Json>> {
|
|
27
27
|
return this.get(this.route().query(q));
|
|
28
28
|
}
|
|
29
29
|
|
package/src/types/Gateway.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { TotalledList } from './List';
|
|
2
1
|
import { Json, JsonValue } from './Json';
|
|
3
2
|
import { Id } from './Id';
|
|
4
3
|
import { Exception } from './Exception';
|
|
5
4
|
import { reject } from '../utils';
|
|
5
|
+
import { TotalledList } from './TotalledList';
|
|
6
6
|
|
|
7
7
|
export abstract class Gateway {
|
|
8
8
|
all(): Promise<TotalledList<Json>> {
|
package/src/types/List.ts
CHANGED
|
@@ -87,4 +87,3 @@ export const isList = <T>(l?: unknown): l is List<T> => isDefined(l) && isArray(
|
|
|
87
87
|
export const asList = <T>(c: Constructor<T>, items: unknown | unknown[] = []): List<T> => toList<T>(toArray(items).map(i => new c(i)));
|
|
88
88
|
|
|
89
89
|
|
|
90
|
-
export type TotalledList<T> = List<T> & {total?: number};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { List, toList } from './List';
|
|
2
|
+
import { ArrayLike } from './Array';
|
|
3
|
+
|
|
4
|
+
export type TotalledList<T> = List<T> & { total?: number };
|
|
5
|
+
|
|
6
|
+
export const toTotalledList = <T>(items?: ArrayLike<T>, total?: number): TotalledList<T> => {
|
|
7
|
+
const list = toList<T>(...items ?? []);
|
|
8
|
+
(list as any).total = total;
|
|
9
|
+
return list;
|
|
10
|
+
};
|