@thisisagile/easy 10.5.14 → 10.5.17
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/Repo.d.ts +6 -6
- package/dist/process/Search.d.ts +5 -5
- package/dist/process/Search.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 +5 -5
- package/dist/types/PageList.d.ts +7 -0
- package/dist/types/{TotalList.js → PageList.js} +4 -4
- package/dist/types/PageList.js.map +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/index.js.map +1 -1
- package/package.json +2 -2
- package/src/domain/Repo.ts +6 -6
- package/src/process/Search.ts +5 -5
- package/src/services/RouteGateway.ts +5 -5
- package/src/types/Gateway.ts +5 -5
- package/src/types/PageList.ts +9 -0
- package/src/types/index.ts +1 -1
- package/dist/types/TotalList.d.ts +0 -6
- package/dist/types/TotalList.js.map +0 -1
- package/src/types/TotalList.ts +0 -10
package/dist/domain/Repo.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { Constructor, Gateway, Id, Json, JsonValue, Key,
|
|
1
|
+
import { Constructor, Gateway, Id, Json, JsonValue, Key, PageList } from '../types';
|
|
2
2
|
import { Struct } from './Struct';
|
|
3
3
|
export declare class Repo<T extends Struct> {
|
|
4
4
|
protected ctor: Constructor<T>;
|
|
5
5
|
private readonly gateway;
|
|
6
6
|
constructor(ctor: Constructor<T>, gateway: Gateway);
|
|
7
7
|
create: (item: T | Json) => T;
|
|
8
|
-
all(): Promise<
|
|
8
|
+
all(): Promise<PageList<T>>;
|
|
9
9
|
byId(id: Id): Promise<T>;
|
|
10
|
-
byIds(...ids: Id[]): Promise<
|
|
11
|
-
byKey(key: Key): Promise<
|
|
12
|
-
by(key: keyof T, value: JsonValue): Promise<
|
|
13
|
-
search(q: JsonValue): Promise<
|
|
10
|
+
byIds(...ids: Id[]): Promise<PageList<T>>;
|
|
11
|
+
byKey(key: Key): Promise<PageList<T>>;
|
|
12
|
+
by(key: keyof T, value: JsonValue): Promise<PageList<T>>;
|
|
13
|
+
search(q: JsonValue): Promise<PageList<T>>;
|
|
14
14
|
exists(id: Id): Promise<boolean>;
|
|
15
15
|
add(t: T | Json): Promise<T>;
|
|
16
16
|
update(id: Id, json: Json): Promise<T>;
|
package/dist/process/Search.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Repo, Struct } from '../domain';
|
|
2
|
-
import { Id, JsonValue, Key,
|
|
2
|
+
import { Id, JsonValue, Key, PageList } from '../types';
|
|
3
3
|
export declare class Search<T extends Struct> {
|
|
4
4
|
protected repo: Repo<T>;
|
|
5
5
|
constructor(repo: Repo<T>);
|
|
6
|
-
all: () => Promise<
|
|
6
|
+
all: () => Promise<PageList<T>>;
|
|
7
7
|
byId: (id: Id) => Promise<T>;
|
|
8
|
-
byIds: (...ids: Id[]) => Promise<
|
|
9
|
-
byKey: (key: Key) => Promise<
|
|
10
|
-
search: (query: JsonValue) => Promise<
|
|
8
|
+
byIds: (...ids: Id[]) => Promise<PageList<T>>;
|
|
9
|
+
byKey: (key: Key) => Promise<PageList<T>>;
|
|
10
|
+
search: (query: JsonValue) => Promise<PageList<T>>;
|
|
11
11
|
exists: (id: Id) => Promise<boolean>;
|
|
12
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Search.js","sourceRoot":"","sources":["../../src/process/Search.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"Search.js","sourceRoot":"","sources":["../../src/process/Search.ts"],"names":[],"mappings":";;;AACA,oCAAoF;AACpF,oCAAmC;AAEnC,MAAa,MAAM;IACjB,YAAsB,IAAa;QAAb,SAAI,GAAJ,IAAI,CAAS;QAGnC,QAAG,GAAG,GAAyB,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;QAElD,SAAI,GAAG,CAAC,EAAM,EAAc,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAElD,UAAK,GAAG,CAAC,GAAG,GAAS,EAAwB,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC;QAExE,UAAK,GAAG,CAAC,GAAQ,EAAwB,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAEjE,WAAM,GAAG,CAAC,KAAgB,EAAwB,EAAE,CAClD,IAAA,cAAM,EAAC,KAAK,CAAC;aACV,IAAI,CAAC,kBAAU,EAAE,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;aAC1C,IAAI,CAAC,IAAA,eAAO,EAAC,IAAA,cAAM,GAAK,CAAC,CAAC,CAAC;QAEhC,WAAM,GAAG,CAAC,EAAM,EAAoB,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAf5D,CAAC;CAgBF;AAlBD,wBAkBC"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { Api } from './Api';
|
|
2
|
-
import { Func, Gateway, Id, Json, JsonValue,
|
|
2
|
+
import { Func, Gateway, Id, Json, JsonValue, PageList, 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<PageList<Json>>;
|
|
10
10
|
getOne(uri: Uri, options?: RequestOptions): Promise<Json | undefined>;
|
|
11
|
-
all(): Promise<
|
|
11
|
+
all(): Promise<PageList<Json>>;
|
|
12
12
|
byId(id: Id): Promise<Json | undefined>;
|
|
13
|
-
search(q: JsonValue): Promise<
|
|
13
|
+
search(q: JsonValue): Promise<PageList<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 => (0, types_1.
|
|
15
|
+
return this.api.get(uri, options).then(r => (0, types_1.toPageList)(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":"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"}
|
package/dist/types/Gateway.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Json, JsonValue } from './Json';
|
|
2
2
|
import { Id } from './Id';
|
|
3
|
-
import {
|
|
3
|
+
import { PageList } from './PageList';
|
|
4
4
|
export declare abstract class Gateway {
|
|
5
|
-
all(): Promise<
|
|
5
|
+
all(): Promise<PageList<Json>>;
|
|
6
6
|
byId(id: Id): Promise<Json | undefined>;
|
|
7
|
-
by(key: string, value: JsonValue): Promise<
|
|
8
|
-
byIds(...ids: Id[]): Promise<
|
|
9
|
-
search(q: JsonValue): Promise<
|
|
7
|
+
by(key: string, value: JsonValue): Promise<PageList<Json>>;
|
|
8
|
+
byIds(...ids: Id[]): Promise<PageList<Json>>;
|
|
9
|
+
search(q: JsonValue): Promise<PageList<Json>>;
|
|
10
10
|
exists(id: Id): Promise<boolean>;
|
|
11
11
|
add(item: Json): Promise<Json>;
|
|
12
12
|
update(item: Json): Promise<Json>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.toPageList = void 0;
|
|
4
4
|
const List_1 = require("./List");
|
|
5
|
-
const
|
|
5
|
+
const toPageList = (items, total) => {
|
|
6
6
|
const list = (0, List_1.toList)(...items ?? []);
|
|
7
7
|
list.total = total;
|
|
8
8
|
return list;
|
|
9
9
|
};
|
|
10
|
-
exports.
|
|
11
|
-
//# sourceMappingURL=
|
|
10
|
+
exports.toPageList = toPageList;
|
|
11
|
+
//# sourceMappingURL=PageList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PageList.js","sourceRoot":"","sources":["../../src/types/PageList.ts"],"names":[],"mappings":";;;AAAA,iCAAsC;AAI/B,MAAM,UAAU,GAAG,CAAI,KAAW,EAAE,KAAc,EAAe,EAAE;IACxE,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,UAAU,cAIrB"}
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
|
@@ -41,7 +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("./
|
|
44
|
+
__exportStar(require("./PageList"), exports);
|
|
45
45
|
__exportStar(require("./Try"), exports);
|
|
46
46
|
__exportStar(require("./Uri"), exports);
|
|
47
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,
|
|
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,6CAA2B;AAC3B,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.17",
|
|
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.17",
|
|
35
35
|
"@types/form-urlencoded": "^4.4.0",
|
|
36
36
|
"@types/jsonwebtoken": "^8.5.8",
|
|
37
37
|
"@types/validator": "^13.7.2"
|
package/src/domain/Repo.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
JsonValue,
|
|
10
10
|
Key,
|
|
11
11
|
toJson,
|
|
12
|
-
|
|
12
|
+
PageList,
|
|
13
13
|
} from '../types';
|
|
14
14
|
import { when } from '../validation';
|
|
15
15
|
import { reject, resolve } from '../utils';
|
|
@@ -21,7 +21,7 @@ export class Repo<T extends Struct> {
|
|
|
21
21
|
|
|
22
22
|
create = (item: T | Json): T => (isValidatable(item) ? item : new this.ctor(item));
|
|
23
23
|
|
|
24
|
-
all(): Promise<
|
|
24
|
+
all(): Promise<PageList<T>> {
|
|
25
25
|
return this.gateway.all().then(js => js.map(j => new this.ctor(j)));
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -32,19 +32,19 @@ export class Repo<T extends Struct> {
|
|
|
32
32
|
.then(j => new this.ctor(j));
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
byIds(...ids: Id[]): Promise<
|
|
35
|
+
byIds(...ids: Id[]): Promise<PageList<T>> {
|
|
36
36
|
return this.gateway.byIds(...ids).then(j => asList(this.ctor, j));
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
byKey(key: Key): Promise<
|
|
39
|
+
byKey(key: Key): Promise<PageList<T>> {
|
|
40
40
|
return this.gateway.by('key', key).then(js => js.map(j => new this.ctor(j)));
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
by(key: keyof T, value: JsonValue): Promise<
|
|
43
|
+
by(key: keyof T, value: JsonValue): Promise<PageList<T>> {
|
|
44
44
|
return this.gateway.by(key.toString(), value).then(js => js.map(j => new this.ctor(j)));
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
search(q: JsonValue): Promise<
|
|
47
|
+
search(q: JsonValue): Promise<PageList<T>> {
|
|
48
48
|
return this.gateway.search(q).then(js => js.map(j => new this.ctor(j)));
|
|
49
49
|
}
|
|
50
50
|
|
package/src/process/Search.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { Repo, Struct } from '../domain';
|
|
2
|
-
import { choose, Id, isNotEmpty, JsonValue, Key, toList,
|
|
2
|
+
import { choose, Id, isNotEmpty, JsonValue, Key, toList, PageList } from '../types';
|
|
3
3
|
import { resolve } from '../utils';
|
|
4
4
|
|
|
5
5
|
export class Search<T extends Struct> {
|
|
6
6
|
constructor(protected repo: Repo<T>) {
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
all = (): Promise<
|
|
9
|
+
all = (): Promise<PageList<T>> => this.repo.all();
|
|
10
10
|
|
|
11
11
|
byId = (id: Id): Promise<T> => this.repo.byId(id);
|
|
12
12
|
|
|
13
|
-
byIds = (...ids: Id[]): Promise<
|
|
13
|
+
byIds = (...ids: Id[]): Promise<PageList<T>> => this.repo.byIds(...ids);
|
|
14
14
|
|
|
15
|
-
byKey = (key: Key): Promise<
|
|
15
|
+
byKey = (key: Key): Promise<PageList<T>> => this.repo.byKey(key);
|
|
16
16
|
|
|
17
|
-
search = (query: JsonValue): Promise<
|
|
17
|
+
search = (query: JsonValue): Promise<PageList<T>> =>
|
|
18
18
|
choose(query)
|
|
19
19
|
.case(isNotEmpty, q => this.repo.search(q))
|
|
20
20
|
.else(resolve(toList<T>()));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Api } from './Api';
|
|
2
|
-
import { Func, Gateway, Id, Json, JsonValue,
|
|
2
|
+
import { Func, Gateway, Id, Json, JsonValue, PageList, toPageList, 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 =>
|
|
10
|
+
get(uri: Uri, options?: RequestOptions): Promise<PageList<Json>> {
|
|
11
|
+
return this.api.get(uri, options).then(r => toPageList<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<PageList<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<PageList<Json>> {
|
|
27
27
|
return this.get(this.route().query(q));
|
|
28
28
|
}
|
|
29
29
|
|
package/src/types/Gateway.ts
CHANGED
|
@@ -2,10 +2,10 @@ import { Json, JsonValue } from './Json';
|
|
|
2
2
|
import { Id } from './Id';
|
|
3
3
|
import { Exception } from './Exception';
|
|
4
4
|
import { reject } from '../utils';
|
|
5
|
-
import {
|
|
5
|
+
import { PageList } from './PageList';
|
|
6
6
|
|
|
7
7
|
export abstract class Gateway {
|
|
8
|
-
all(): Promise<
|
|
8
|
+
all(): Promise<PageList<Json>> {
|
|
9
9
|
return reject(Exception.IsNotImplemented);
|
|
10
10
|
}
|
|
11
11
|
|
|
@@ -13,15 +13,15 @@ export abstract class Gateway {
|
|
|
13
13
|
return reject(Exception.IsNotImplemented);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
by(key: string, value: JsonValue): Promise<
|
|
16
|
+
by(key: string, value: JsonValue): Promise<PageList<Json>> {
|
|
17
17
|
return reject(Exception.IsNotImplemented);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
byIds(...ids: Id[]): Promise<
|
|
20
|
+
byIds(...ids: Id[]): Promise<PageList<Json>> {
|
|
21
21
|
return reject(Exception.IsNotImplemented);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
search(q: JsonValue): Promise<
|
|
24
|
+
search(q: JsonValue): Promise<PageList<Json>> {
|
|
25
25
|
return reject(Exception.IsNotImplemented);
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { List, toList } from './List';
|
|
2
|
+
|
|
3
|
+
export type PageList<T> = List<T> & { skip?: number, take?: number, total?: number };
|
|
4
|
+
|
|
5
|
+
export const toPageList = <T>(items?: T[], total?: number): PageList<T> => {
|
|
6
|
+
const list = toList<T>(...items ?? []);
|
|
7
|
+
(list as any).total = total;
|
|
8
|
+
return list;
|
|
9
|
+
};
|
package/src/types/index.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TotalList.js","sourceRoot":"","sources":["../../src/types/TotalList.ts"],"names":[],"mappings":";;;AAAA,iCAAsC;AAK/B,MAAM,WAAW,GAAG,CAAI,KAAoB,EAAE,KAAc,EAAgB,EAAE;IACnF,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,WAAW,eAItB"}
|
package/src/types/TotalList.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { List, toList } from './List';
|
|
2
|
-
import { ArrayLike } from './Array';
|
|
3
|
-
|
|
4
|
-
export type TotalList<T> = List<T> & { total?: number };
|
|
5
|
-
|
|
6
|
-
export const toTotalList = <T>(items?: ArrayLike<T>, total?: number): TotalList<T> => {
|
|
7
|
-
const list = toList<T>(...items ?? []);
|
|
8
|
-
(list as any).total = total;
|
|
9
|
-
return list;
|
|
10
|
-
};
|