@naturalcycles/db-lib 8.54.1 → 8.54.3
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/cnst.js +1 -1
- package/dist/commondao/common.dao.d.ts +2 -2
- package/dist/commondao/common.dao.js +1 -1
- package/dist/commondao/common.dao.model.d.ts +4 -4
- package/dist/commondao/common.dao.model.js +1 -1
- package/dist/db.model.js +2 -2
- package/dist/kv/commonKeyValueDao.js +2 -2
- package/dist/testing/test.model.d.ts +3 -3
- package/dist/timeseries/commonTimeSeriesDao.js +2 -1
- package/dist/validation/index.d.ts +7 -7
- package/dist/validation/index.js +1 -1
- package/package.json +1 -1
- package/readme.md +1 -1
- package/src/adapter/file/file.db.ts +1 -1
- package/src/adapter/file/localFile.persistence.plugin.ts +1 -1
- package/src/commondao/common.dao.model.ts +4 -4
- package/src/commondao/common.dao.ts +10 -10
- package/src/kv/commonKeyValueDao.ts +2 -2
- package/src/query/dbQuery.ts +4 -1
- package/src/testing/dbTest.ts +1 -1
- package/src/testing/test.model.ts +2 -2
- package/src/timeseries/commonTimeSeriesDao.ts +3 -3
- package/src/validation/index.ts +11 -2
package/dist/cnst.js
CHANGED
|
@@ -7,4 +7,4 @@ var DBLibError;
|
|
|
7
7
|
DBLibError["DAO_IS_READ_ONLY"] = "DAO_IS_READ_ONLY";
|
|
8
8
|
DBLibError["NON_UNIQUE_ID"] = "NON_UNIQUE_ID";
|
|
9
9
|
DBLibError["OBJECT_IS_IMMUTABLE"] = "OBJECT_IS_IMMUTABLE";
|
|
10
|
-
})(DBLibError
|
|
10
|
+
})(DBLibError || (exports.DBLibError = DBLibError = {}));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AnyObject, AsyncMapper, JsonSchemaObject, JsonSchemaRootObject, ObjectWithId, Promisable, Saved, UnixTimestampMillisNumber, Unsaved, ZodSchema } from '@naturalcycles/js-lib';
|
|
2
|
-
import { AjvSchema,
|
|
2
|
+
import { AjvSchema, ObjectSchema, ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
3
3
|
import { DBDeleteByIdsOperation, DBModelType, DBOperation, DBPatch, DBSaveBatchOperation, RunQueryResult } from '../db.model';
|
|
4
4
|
import { DBQuery, RunnableDBQuery } from '../query/dbQuery';
|
|
5
5
|
import { CommonDaoCfg, CommonDaoCreateOptions, CommonDaoOptions, CommonDaoSaveOptions, CommonDaoStreamForEachOptions, CommonDaoStreamOptions } from './common.dao.model';
|
|
@@ -145,7 +145,7 @@ export declare class CommonDao<BM extends Partial<ObjectWithId<ID>>, DBM extends
|
|
|
145
145
|
*
|
|
146
146
|
* Does NOT mutate the object.
|
|
147
147
|
*/
|
|
148
|
-
validateAndConvert<IN, OUT = IN>(obj: Partial<IN>, schema:
|
|
148
|
+
validateAndConvert<IN, OUT = IN>(obj: Partial<IN>, schema: ObjectSchema<IN> | AjvSchema<IN> | ZodSchema<IN> | undefined, modelType: DBModelType, opt?: CommonDaoOptions): OUT;
|
|
149
149
|
getTableSchema(): Promise<JsonSchemaRootObject<DBM>>;
|
|
150
150
|
createTable(schema: JsonSchemaObject<DBM>, opt?: CommonDaoCreateOptions): Promise<void>;
|
|
151
151
|
/**
|
|
@@ -215,7 +215,7 @@ class CommonDao {
|
|
|
215
215
|
}
|
|
216
216
|
throwRequiredError(id, opt) {
|
|
217
217
|
const table = opt.table || this.cfg.table;
|
|
218
|
-
throw new js_lib_1.AppError(`DB row required, but not found
|
|
218
|
+
throw new js_lib_1.AppError(`DB row required, but not found in ${table}`, {
|
|
219
219
|
code: cnst_1.DBLibError.DB_ROW_REQUIRED,
|
|
220
220
|
table,
|
|
221
221
|
id,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CommonLogger, ErrorMode, ObjectWithId, Promisable, Saved, ZodError, ZodSchema } from '@naturalcycles/js-lib';
|
|
2
|
-
import { AjvSchema, AjvValidationError, JoiValidationError,
|
|
2
|
+
import { AjvSchema, AjvValidationError, JoiValidationError, ObjectSchema, TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib';
|
|
3
3
|
import { CommonDB } from '../common.db';
|
|
4
4
|
import { CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions } from '../db.model';
|
|
5
5
|
export interface CommonDaoHooks<BM extends Partial<ObjectWithId<ID>>, DBM extends ObjectWithId<ID>, TM, ID extends string | number> {
|
|
@@ -110,9 +110,9 @@ export interface CommonDaoCfg<BM extends Partial<ObjectWithId<ID>>, DBM extends
|
|
|
110
110
|
/**
|
|
111
111
|
* Joi, AjvSchema or ZodSchema is supported.
|
|
112
112
|
*/
|
|
113
|
-
dbmSchema?:
|
|
114
|
-
bmSchema?:
|
|
115
|
-
tmSchema?:
|
|
113
|
+
dbmSchema?: ObjectSchema<DBM> | AjvSchema<DBM> | ZodSchema<DBM>;
|
|
114
|
+
bmSchema?: ObjectSchema<BM> | AjvSchema<BM> | ZodSchema<BM>;
|
|
115
|
+
tmSchema?: ObjectSchema<TM> | AjvSchema<TM> | ZodSchema<TM>;
|
|
116
116
|
excludeFromIndexes?: (keyof DBM)[];
|
|
117
117
|
/**
|
|
118
118
|
* Defaults to false.
|
|
@@ -19,4 +19,4 @@ var CommonDaoLogLevel;
|
|
|
19
19
|
* Log EVERYTHING - all data passing in and out (max 10 rows). Very verbose!
|
|
20
20
|
*/
|
|
21
21
|
CommonDaoLogLevel[CommonDaoLogLevel["DATA_FULL"] = 30] = "DATA_FULL";
|
|
22
|
-
})(CommonDaoLogLevel
|
|
22
|
+
})(CommonDaoLogLevel || (exports.CommonDaoLogLevel = CommonDaoLogLevel = {}));
|
package/dist/db.model.js
CHANGED
|
@@ -5,13 +5,13 @@ var DBRelation;
|
|
|
5
5
|
(function (DBRelation) {
|
|
6
6
|
DBRelation["ONE_TO_ONE"] = "ONE_TO_ONE";
|
|
7
7
|
DBRelation["ONE_TO_MANY"] = "ONE_TO_MANY";
|
|
8
|
-
})(DBRelation
|
|
8
|
+
})(DBRelation || (exports.DBRelation = DBRelation = {}));
|
|
9
9
|
var DBModelType;
|
|
10
10
|
(function (DBModelType) {
|
|
11
11
|
DBModelType["DBM"] = "DBM";
|
|
12
12
|
DBModelType["BM"] = "BM";
|
|
13
13
|
DBModelType["TM"] = "TM";
|
|
14
|
-
})(DBModelType
|
|
14
|
+
})(DBModelType || (exports.DBModelType = DBModelType = {}));
|
|
15
15
|
/**
|
|
16
16
|
* Allows to construct a query similar to:
|
|
17
17
|
*
|
|
@@ -44,7 +44,7 @@ class CommonKeyValueDao {
|
|
|
44
44
|
const [r] = await this.getByIds([id]);
|
|
45
45
|
if (!r) {
|
|
46
46
|
const { table } = this.cfg;
|
|
47
|
-
throw new js_lib_1.AppError(`DB row required, but not found
|
|
47
|
+
throw new js_lib_1.AppError(`DB row required, but not found in ${table}`, {
|
|
48
48
|
code: cnst_1.DBLibError.DB_ROW_REQUIRED,
|
|
49
49
|
table,
|
|
50
50
|
id,
|
|
@@ -56,7 +56,7 @@ class CommonKeyValueDao {
|
|
|
56
56
|
const [r] = await this.cfg.db.getByIds(this.cfg.table, [id]);
|
|
57
57
|
if (!r) {
|
|
58
58
|
const { table } = this.cfg;
|
|
59
|
-
throw new js_lib_1.AppError(`DB row required, but not found
|
|
59
|
+
throw new js_lib_1.AppError(`DB row required, but not found in ${table}`, {
|
|
60
60
|
code: cnst_1.DBLibError.DB_ROW_REQUIRED,
|
|
61
61
|
table,
|
|
62
62
|
id,
|
|
@@ -15,9 +15,9 @@ export interface TestItemTM {
|
|
|
15
15
|
k1: string;
|
|
16
16
|
even?: boolean;
|
|
17
17
|
}
|
|
18
|
-
export declare const testItemBMSchema: import("
|
|
19
|
-
export declare const testItemDBMSchema: import("
|
|
20
|
-
export declare const testItemTMSchema: import("
|
|
18
|
+
export declare const testItemBMSchema: import("joi").ObjectSchema<TestItemBM>;
|
|
19
|
+
export declare const testItemDBMSchema: import("joi").ObjectSchema<TestItemDBM>;
|
|
20
|
+
export declare const testItemTMSchema: import("joi").ObjectSchema<TestItemTM>;
|
|
21
21
|
export declare const testItemBMJsonSchema: JsonSchemaObject<TestItemBM>;
|
|
22
22
|
export declare const testItemDBMJsonSchema: JsonSchemaObject<TestItemDBM>;
|
|
23
23
|
export declare function createTestItemDBM(num?: number): TestItemDBM;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommonTimeSeriesDao = void 0;
|
|
4
|
+
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
4
5
|
const __1 = require("..");
|
|
5
6
|
const dbQuery_1 = require("../query/dbQuery");
|
|
6
7
|
const _TIMESERIES_RAW = '_TIMESERIES_RAW';
|
|
@@ -20,7 +21,7 @@ class CommonTimeSeriesDao {
|
|
|
20
21
|
async getSeries() {
|
|
21
22
|
return (await this.cfg.db.getTables())
|
|
22
23
|
.map(t => /^(.*)_TIMESERIES_RAW$/.exec(t)?.[1])
|
|
23
|
-
.filter(
|
|
24
|
+
.filter(js_lib_1._isTruthy);
|
|
24
25
|
}
|
|
25
26
|
// convenience method
|
|
26
27
|
async save(series, tsMillis, value) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { CommonDBOptions, CommonDBSaveOptions } from '../db.model';
|
|
2
|
-
import { DBQuery, DBQueryFilter, DBQueryOrder } from '../query/dbQuery';
|
|
3
|
-
export declare const commonDBOptionsSchema: import("
|
|
4
|
-
export declare const commonDBSaveOptionsSchema: import("
|
|
5
|
-
export declare const dbQueryFilterOperatorSchema: import("@naturalcycles/nodejs-lib/dist/validation/joi/string.extensions").
|
|
6
|
-
export declare const dbQueryFilterSchema: import("
|
|
7
|
-
export declare const dbQueryOrderSchema: import("
|
|
8
|
-
export declare const dbQuerySchema: import("
|
|
2
|
+
import { DBQuery, DBQueryFilter, DBQueryFilterOperator, DBQueryOrder } from '../query/dbQuery';
|
|
3
|
+
export declare const commonDBOptionsSchema: import("joi").ObjectSchema<CommonDBOptions>;
|
|
4
|
+
export declare const commonDBSaveOptionsSchema: import("joi").ObjectSchema<CommonDBSaveOptions<any>>;
|
|
5
|
+
export declare const dbQueryFilterOperatorSchema: import("@naturalcycles/nodejs-lib/dist/validation/joi/string.extensions").StringSchema<DBQueryFilterOperator>;
|
|
6
|
+
export declare const dbQueryFilterSchema: import("joi").ObjectSchema<DBQueryFilter<import("@naturalcycles/js-lib").AnyObjectWithId<string | number>>>;
|
|
7
|
+
export declare const dbQueryOrderSchema: import("joi").ObjectSchema<DBQueryOrder<import("@naturalcycles/js-lib").AnyObjectWithId<string | number>>>;
|
|
8
|
+
export declare const dbQuerySchema: import("joi").ObjectSchema<DBQuery<any>>;
|
package/dist/validation/index.js
CHANGED
|
@@ -10,7 +10,7 @@ exports.commonDBOptionsSchema = (0, nodejs_lib_1.objectSchema)({
|
|
|
10
10
|
exports.commonDBSaveOptionsSchema = (0, nodejs_lib_1.objectSchema)({
|
|
11
11
|
excludeFromIndexes: (0, nodejs_lib_1.arraySchema)(nodejs_lib_1.stringSchema).optional(),
|
|
12
12
|
}).concat(exports.commonDBOptionsSchema);
|
|
13
|
-
exports.dbQueryFilterOperatorSchema = nodejs_lib_1.
|
|
13
|
+
exports.dbQueryFilterOperatorSchema = nodejs_lib_1.Joi.string().valid(...dbQuery_1.dbQueryFilterOperatorValues);
|
|
14
14
|
exports.dbQueryFilterSchema = (0, nodejs_lib_1.objectSchema)({
|
|
15
15
|
name: nodejs_lib_1.stringSchema,
|
|
16
16
|
op: exports.dbQueryFilterOperatorSchema,
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](https://www.npmjs.com/package/@naturalcycles/db-lib)
|
|
6
6
|
[](https://github.com/prettier/prettier)
|
|
7
7
|
[](https://github.com/NaturalCycles/db-lib)
|
|
8
|
-
[](https://github.com/NaturalCycles/db-lib/actions)
|
|
9
9
|
|
|
10
10
|
Defines 3 things:
|
|
11
11
|
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
AjvSchema,
|
|
12
12
|
AjvValidationError,
|
|
13
13
|
JoiValidationError,
|
|
14
|
-
|
|
14
|
+
ObjectSchema,
|
|
15
15
|
TransformLogProgressOptions,
|
|
16
16
|
TransformMapOptions,
|
|
17
17
|
} from '@naturalcycles/nodejs-lib'
|
|
@@ -148,9 +148,9 @@ export interface CommonDaoCfg<
|
|
|
148
148
|
/**
|
|
149
149
|
* Joi, AjvSchema or ZodSchema is supported.
|
|
150
150
|
*/
|
|
151
|
-
dbmSchema?:
|
|
152
|
-
bmSchema?:
|
|
153
|
-
tmSchema?:
|
|
151
|
+
dbmSchema?: ObjectSchema<DBM> | AjvSchema<DBM> | ZodSchema<DBM>
|
|
152
|
+
bmSchema?: ObjectSchema<BM> | AjvSchema<BM> | ZodSchema<BM>
|
|
153
|
+
tmSchema?: ObjectSchema<TM> | AjvSchema<TM> | ZodSchema<TM>
|
|
154
154
|
|
|
155
155
|
excludeFromIndexes?: (keyof DBM)[]
|
|
156
156
|
|
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
AjvValidationError,
|
|
31
31
|
getValidationResult,
|
|
32
32
|
JoiValidationError,
|
|
33
|
-
|
|
33
|
+
ObjectSchema,
|
|
34
34
|
ReadableTyped,
|
|
35
35
|
stringId,
|
|
36
36
|
transformBuffer,
|
|
@@ -249,7 +249,7 @@ export class CommonDao<
|
|
|
249
249
|
|
|
250
250
|
private throwRequiredError(id: ID, opt: CommonDaoOptions): never {
|
|
251
251
|
const table = opt.table || this.cfg.table
|
|
252
|
-
throw new AppError(`DB row required, but not found
|
|
252
|
+
throw new AppError(`DB row required, but not found in ${table}`, {
|
|
253
253
|
code: DBLibError.DB_ROW_REQUIRED,
|
|
254
254
|
table,
|
|
255
255
|
id,
|
|
@@ -453,7 +453,7 @@ export class CommonDao<
|
|
|
453
453
|
if (partialQuery || opt.raw) return dbm as any
|
|
454
454
|
|
|
455
455
|
if (this.cfg.hooks!.afterLoad) {
|
|
456
|
-
dbm = (await this.cfg.hooks!.afterLoad(dbm))
|
|
456
|
+
dbm = (await this.cfg.hooks!.afterLoad(dbm))!
|
|
457
457
|
if (dbm === null) return SKIP
|
|
458
458
|
}
|
|
459
459
|
|
|
@@ -503,7 +503,7 @@ export class CommonDao<
|
|
|
503
503
|
if (partialQuery || opt.raw) return dbm
|
|
504
504
|
|
|
505
505
|
if (this.cfg.hooks!.afterLoad) {
|
|
506
|
-
dbm = (await this.cfg.hooks!.afterLoad(dbm))
|
|
506
|
+
dbm = (await this.cfg.hooks!.afterLoad(dbm))!
|
|
507
507
|
if (dbm === null) return SKIP
|
|
508
508
|
}
|
|
509
509
|
|
|
@@ -550,7 +550,7 @@ export class CommonDao<
|
|
|
550
550
|
transformMap<any, DBM>(
|
|
551
551
|
async dbm => {
|
|
552
552
|
if (this.cfg.hooks!.afterLoad) {
|
|
553
|
-
dbm = (await this.cfg.hooks!.afterLoad(dbm))
|
|
553
|
+
dbm = (await this.cfg.hooks!.afterLoad(dbm))!
|
|
554
554
|
if (dbm === null) return SKIP
|
|
555
555
|
}
|
|
556
556
|
|
|
@@ -592,7 +592,7 @@ export class CommonDao<
|
|
|
592
592
|
transformMap<DBM, Saved<BM>>(
|
|
593
593
|
async dbm => {
|
|
594
594
|
if (this.cfg.hooks!.afterLoad) {
|
|
595
|
-
dbm = (await this.cfg.hooks!.afterLoad(dbm))
|
|
595
|
+
dbm = (await this.cfg.hooks!.afterLoad(dbm))!
|
|
596
596
|
if (dbm === null) return SKIP
|
|
597
597
|
}
|
|
598
598
|
|
|
@@ -765,7 +765,7 @@ export class CommonDao<
|
|
|
765
765
|
let dbm = await this.bmToDBM(bm as BM, opt)
|
|
766
766
|
|
|
767
767
|
if (this.cfg.hooks!.beforeSave) {
|
|
768
|
-
dbm = (await this.cfg.hooks!.beforeSave(dbm))
|
|
768
|
+
dbm = (await this.cfg.hooks!.beforeSave(dbm))!
|
|
769
769
|
if (dbm === null && !opt.tx) return bm as any
|
|
770
770
|
}
|
|
771
771
|
|
|
@@ -852,7 +852,7 @@ export class CommonDao<
|
|
|
852
852
|
const assignGeneratedIds = opt.assignGeneratedIds || this.cfg.assignGeneratedIds
|
|
853
853
|
|
|
854
854
|
if (this.cfg.hooks!.beforeSave) {
|
|
855
|
-
row = (await this.cfg.hooks!.beforeSave(row))
|
|
855
|
+
row = (await this.cfg.hooks!.beforeSave(row))!
|
|
856
856
|
if (row === null) return dbm
|
|
857
857
|
}
|
|
858
858
|
|
|
@@ -1178,7 +1178,7 @@ export class CommonDao<
|
|
|
1178
1178
|
*/
|
|
1179
1179
|
validateAndConvert<IN, OUT = IN>(
|
|
1180
1180
|
obj: Partial<IN>,
|
|
1181
|
-
schema:
|
|
1181
|
+
schema: ObjectSchema<IN> | AjvSchema<IN> | ZodSchema<IN> | undefined,
|
|
1182
1182
|
modelType: DBModelType,
|
|
1183
1183
|
opt: CommonDaoOptions = {},
|
|
1184
1184
|
): OUT {
|
|
@@ -1231,7 +1231,7 @@ export class CommonDao<
|
|
|
1231
1231
|
})
|
|
1232
1232
|
} else {
|
|
1233
1233
|
// Joi
|
|
1234
|
-
const vr = getValidationResult
|
|
1234
|
+
const vr = getValidationResult(obj, schema, objectName)
|
|
1235
1235
|
error = vr.error
|
|
1236
1236
|
convertedValue = vr.value
|
|
1237
1237
|
}
|
|
@@ -90,7 +90,7 @@ export class CommonKeyValueDao<T> {
|
|
|
90
90
|
|
|
91
91
|
if (!r) {
|
|
92
92
|
const { table } = this.cfg
|
|
93
|
-
throw new AppError(`DB row required, but not found
|
|
93
|
+
throw new AppError(`DB row required, but not found in ${table}`, {
|
|
94
94
|
code: DBLibError.DB_ROW_REQUIRED,
|
|
95
95
|
table,
|
|
96
96
|
id,
|
|
@@ -105,7 +105,7 @@ export class CommonKeyValueDao<T> {
|
|
|
105
105
|
|
|
106
106
|
if (!r) {
|
|
107
107
|
const { table } = this.cfg
|
|
108
|
-
throw new AppError(`DB row required, but not found
|
|
108
|
+
throw new AppError(`DB row required, but not found in ${table}`, {
|
|
109
109
|
code: DBLibError.DB_ROW_REQUIRED,
|
|
110
110
|
table,
|
|
111
111
|
id,
|
package/src/query/dbQuery.ts
CHANGED
|
@@ -244,7 +244,10 @@ export class RunnableDBQuery<
|
|
|
244
244
|
/**
|
|
245
245
|
* Pass `table` to override table.
|
|
246
246
|
*/
|
|
247
|
-
constructor(
|
|
247
|
+
constructor(
|
|
248
|
+
public dao: CommonDao<BM, DBM, TM, ID>,
|
|
249
|
+
table?: string,
|
|
250
|
+
) {
|
|
248
251
|
super(table || dao.cfg.table)
|
|
249
252
|
}
|
|
250
253
|
|
package/src/testing/dbTest.ts
CHANGED
|
@@ -112,7 +112,7 @@ export function runCommonDBTest(
|
|
|
112
112
|
deepFreeze(items)
|
|
113
113
|
const item1 = items[0]!
|
|
114
114
|
|
|
115
|
-
const queryAll = () => DBQuery.create<TestItemDBM>(TEST_TABLE)
|
|
115
|
+
const queryAll = (): DBQuery<TestItemDBM> => DBQuery.create<TestItemDBM>(TEST_TABLE)
|
|
116
116
|
|
|
117
117
|
test('ping', async () => {
|
|
118
118
|
await db.ping()
|
|
@@ -35,7 +35,7 @@ export const testItemBMSchema = objectSchema<TestItemBM>({
|
|
|
35
35
|
k3: numberSchema.optional(),
|
|
36
36
|
even: booleanSchema.optional(),
|
|
37
37
|
b1: binarySchema.optional(),
|
|
38
|
-
}).concat(baseDBEntitySchema)
|
|
38
|
+
}).concat(baseDBEntitySchema as any)
|
|
39
39
|
|
|
40
40
|
export const testItemDBMSchema = objectSchema<TestItemDBM>({
|
|
41
41
|
k1: stringSchema,
|
|
@@ -43,7 +43,7 @@ export const testItemDBMSchema = objectSchema<TestItemDBM>({
|
|
|
43
43
|
k3: numberSchema.optional(),
|
|
44
44
|
even: booleanSchema.optional(),
|
|
45
45
|
b1: binarySchema.optional(),
|
|
46
|
-
}).concat(savedDBEntitySchema)
|
|
46
|
+
}).concat(savedDBEntitySchema as any)
|
|
47
47
|
|
|
48
48
|
export const testItemTMSchema = objectSchema<TestItemTM>({
|
|
49
49
|
k1: stringSchema,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ObjectWithId } from '@naturalcycles/js-lib'
|
|
1
|
+
import { _isTruthy, ObjectWithId } from '@naturalcycles/js-lib'
|
|
2
2
|
import { DBTransaction } from '..'
|
|
3
3
|
import { DBQuery } from '../query/dbQuery'
|
|
4
4
|
import {
|
|
@@ -26,8 +26,8 @@ export class CommonTimeSeriesDao {
|
|
|
26
26
|
|
|
27
27
|
async getSeries(): Promise<string[]> {
|
|
28
28
|
return (await this.cfg.db.getTables())
|
|
29
|
-
.map(t => /^(.*)_TIMESERIES_RAW$/.exec(t)?.[1]
|
|
30
|
-
.filter(
|
|
29
|
+
.map(t => /^(.*)_TIMESERIES_RAW$/.exec(t)?.[1])
|
|
30
|
+
.filter(_isTruthy)
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
// convenience method
|
package/src/validation/index.ts
CHANGED
|
@@ -3,11 +3,18 @@ import {
|
|
|
3
3
|
arraySchema,
|
|
4
4
|
booleanSchema,
|
|
5
5
|
integerSchema,
|
|
6
|
+
Joi,
|
|
6
7
|
objectSchema,
|
|
7
8
|
stringSchema,
|
|
8
9
|
} from '@naturalcycles/nodejs-lib'
|
|
9
10
|
import { CommonDBOptions, CommonDBSaveOptions } from '../db.model'
|
|
10
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
DBQuery,
|
|
13
|
+
DBQueryFilter,
|
|
14
|
+
DBQueryFilterOperator,
|
|
15
|
+
dbQueryFilterOperatorValues,
|
|
16
|
+
DBQueryOrder,
|
|
17
|
+
} from '../query/dbQuery'
|
|
11
18
|
|
|
12
19
|
export const commonDBOptionsSchema = objectSchema<CommonDBOptions>({
|
|
13
20
|
onlyCache: booleanSchema.optional(),
|
|
@@ -18,7 +25,9 @@ export const commonDBSaveOptionsSchema = objectSchema<CommonDBSaveOptions>({
|
|
|
18
25
|
excludeFromIndexes: arraySchema(stringSchema).optional(),
|
|
19
26
|
}).concat(commonDBOptionsSchema)
|
|
20
27
|
|
|
21
|
-
export const dbQueryFilterOperatorSchema =
|
|
28
|
+
export const dbQueryFilterOperatorSchema = Joi.string<DBQueryFilterOperator>().valid(
|
|
29
|
+
...dbQueryFilterOperatorValues,
|
|
30
|
+
)
|
|
22
31
|
|
|
23
32
|
export const dbQueryFilterSchema = objectSchema<DBQueryFilter>({
|
|
24
33
|
name: stringSchema,
|