@sdflc/backend-helpers 1.0.72 → 1.0.75
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/build/BaseGateway.d.ts +5 -2
- package/build/BaseGateway.js +19 -6
- package/package.json +1 -1
package/build/BaseGateway.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DateTimeHelpers, Logger } from '@sdflc/utils';
|
|
2
|
-
import { ApiContext, BaseGatewayPropsInterface, BuildListQueryArgsInterface, ListArgsInterface } from './interfaces';
|
|
2
|
+
import { ApiContext, BaseGatewayPropsInterface, BuildListQueryArgsInterface, CacheInterface, ListArgsInterface, LoaderInterface } from './interfaces';
|
|
3
3
|
import { Database } from './Database';
|
|
4
4
|
declare class BaseGateway {
|
|
5
5
|
protected config: BaseGatewayPropsInterface;
|
|
@@ -8,7 +8,10 @@ declare class BaseGateway {
|
|
|
8
8
|
protected dateTime: DateTimeHelpers;
|
|
9
9
|
protected dateTimeNow: Date;
|
|
10
10
|
constructor(props: BaseGatewayPropsInterface);
|
|
11
|
+
getConfig(): BaseGatewayPropsInterface;
|
|
11
12
|
setConfigPart(props: BaseGatewayPropsInterface): this;
|
|
13
|
+
setLoader(loader: LoaderInterface): this;
|
|
14
|
+
setLoaderConfig(config: CacheInterface): this;
|
|
12
15
|
generateId(args?: any): Promise<string>;
|
|
13
16
|
onListFilter(query: any, filterParams: any): Promise<void>;
|
|
14
17
|
onUpdateFilter(query: any, filterParams: any): Promise<number>;
|
|
@@ -25,7 +28,7 @@ declare class BaseGateway {
|
|
|
25
28
|
getIdField(): string;
|
|
26
29
|
get(id: any): Promise<any>;
|
|
27
30
|
getMany(ids: any[]): Promise<any>;
|
|
28
|
-
buildListQuery(args?: BuildListQueryArgsInterface): any
|
|
31
|
+
buildListQuery(args?: BuildListQueryArgsInterface): Promise<any>;
|
|
29
32
|
list(args?: ListArgsInterface): Promise<any>;
|
|
30
33
|
create(args: any): Promise<any[]>;
|
|
31
34
|
update(where: any, params: any): Promise<any>;
|
package/build/BaseGateway.js
CHANGED
|
@@ -15,11 +15,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.BaseGateway = void 0;
|
|
16
16
|
const uuid_1 = require("uuid");
|
|
17
17
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
18
|
+
const check_types_1 = __importDefault(require("check-types"));
|
|
18
19
|
const lodash_1 = require("lodash");
|
|
19
20
|
const utils_1 = require("@sdflc/utils");
|
|
20
21
|
const DataCache_1 = require("./DataCache");
|
|
21
22
|
const constants_1 = require("./constants");
|
|
22
|
-
const check_types_1 = __importDefault(require("check-types"));
|
|
23
23
|
const DEFAULT_CHUNCK_SIZE = 2500;
|
|
24
24
|
class BaseGateway {
|
|
25
25
|
constructor(props) {
|
|
@@ -42,10 +42,21 @@ class BaseGateway {
|
|
|
42
42
|
this.logger = (props === null || props === void 0 ? void 0 : props.logger) instanceof utils_1.Logger ? props.logger : new utils_1.Logger({ level: utils_1.LoggerLevels.WARNING });
|
|
43
43
|
this.loader = check_types_1.default.function((_c = this.config) === null || _c === void 0 ? void 0 : _c.loader) ? this.config.loader : new DataCache_1.DataCache(this.config);
|
|
44
44
|
}
|
|
45
|
+
getConfig() {
|
|
46
|
+
return this.config;
|
|
47
|
+
}
|
|
45
48
|
setConfigPart(props) {
|
|
46
49
|
Object.assign(this.config, props);
|
|
47
50
|
return this;
|
|
48
51
|
}
|
|
52
|
+
setLoader(loader) {
|
|
53
|
+
this.loader = loader;
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
setLoaderConfig(config) {
|
|
57
|
+
this.loader = new DataCache_1.DataCache(Object.assign(Object.assign({}, this.config), config));
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
49
60
|
// eslint-disable-next-line
|
|
50
61
|
generateId(args) {
|
|
51
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -283,10 +294,12 @@ class BaseGateway {
|
|
|
283
294
|
});
|
|
284
295
|
}
|
|
285
296
|
buildListQuery(args) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
297
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
298
|
+
const { fieldsToUse } = args || {};
|
|
299
|
+
const query = this.getBuilder();
|
|
300
|
+
query.select(fieldsToUse);
|
|
301
|
+
return { query };
|
|
302
|
+
});
|
|
290
303
|
}
|
|
291
304
|
list(args) {
|
|
292
305
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -297,7 +310,7 @@ class BaseGateway {
|
|
|
297
310
|
}
|
|
298
311
|
const shouldUseCache = useCache != null ? useCache : !this.config.noCache;
|
|
299
312
|
const fieldsToUse = !shouldUseCache && Array.isArray(this.config.selectFields) ? this.config.selectFields : this.getIdField();
|
|
300
|
-
const query = this.buildListQuery({ filter, params, fieldsToUse, useCache: shouldUseCache });
|
|
313
|
+
const { query } = yield this.buildListQuery({ filter, params, fieldsToUse, useCache: shouldUseCache });
|
|
301
314
|
yield this.onListFilter(query, filter);
|
|
302
315
|
if (limit && !isNaN(limit) && limit > 0) {
|
|
303
316
|
query.offset(offset).limit(limit);
|
package/package.json
CHANGED