@naturalcycles/db-lib 10.44.0 → 10.45.1
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/testing/commonDaoTest.js +1 -2
- package/dist/testing/test.model.d.ts +2 -2
- package/dist/validation/index.d.ts +1 -1
- package/dist/validation/index.js +5 -5
- package/package.json +1 -1
- package/src/testing/commonDaoTest.ts +1 -2
- package/src/testing/test.model.ts +13 -14
- package/src/validation/index.ts +7 -8
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { _sortBy } from '@naturalcycles/js-lib/array/sort.js';
|
|
2
2
|
import { localTime } from '@naturalcycles/js-lib/datetime/localTime.js';
|
|
3
3
|
import { _deepCopy, _filterObject, _omit, _pick } from '@naturalcycles/js-lib/object';
|
|
4
|
-
import { AjvSchema } from '@naturalcycles/nodejs-lib/ajv';
|
|
5
4
|
import { Pipeline } from '@naturalcycles/nodejs-lib/stream';
|
|
6
5
|
import { CommonDao } from '../commondao/common.dao.js';
|
|
7
6
|
import { DBQuery } from '../query/dbQuery.js';
|
|
@@ -13,7 +12,7 @@ export async function runCommonDaoTest(db, quirks = {}) {
|
|
|
13
12
|
const dao = new CommonDao({
|
|
14
13
|
table: TEST_TABLE,
|
|
15
14
|
db,
|
|
16
|
-
validateBM:
|
|
15
|
+
validateBM: testItemBMSchema.getValidationFunction(),
|
|
17
16
|
});
|
|
18
17
|
const items = createTestItemsBM(3);
|
|
19
18
|
const itemsClone = _deepCopy(items);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BaseDBEntity } from '@naturalcycles/js-lib/types';
|
|
2
|
-
import type {
|
|
2
|
+
import type { JSchema } from '@naturalcycles/nodejs-lib/ajv';
|
|
3
3
|
export declare const TEST_TABLE = "TEST_TABLE";
|
|
4
4
|
export declare const TEST_TABLE_2 = "TEST_TABLE_2";
|
|
5
5
|
export interface TestItemBM extends BaseDBEntity {
|
|
@@ -19,7 +19,7 @@ export interface TestItemTM {
|
|
|
19
19
|
even?: boolean;
|
|
20
20
|
}
|
|
21
21
|
export declare const testItemTMSchema: any;
|
|
22
|
-
export declare const testItemBMSchema:
|
|
22
|
+
export declare const testItemBMSchema: JSchema<TestItemBM, false>;
|
|
23
23
|
export declare function createTestItemDBM(num?: number): TestItemDBM;
|
|
24
24
|
export declare function createTestItemBM(num?: number): TestItemBM;
|
|
25
25
|
export declare function createTestItemsDBM(count?: number): TestItemDBM[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CommonDBOptions } from '../db.model.js';
|
|
2
|
-
export declare const commonDBOptionsSchema: () =>
|
|
2
|
+
export declare const commonDBOptionsSchema: () => JBuilder<CommonDBOptions, false>;
|
|
3
3
|
export declare const commonDBSaveOptionsSchema: <ROW extends ObjectWithId>() => any;
|
|
4
4
|
export declare const dbQueryFilterOperatorSchema: any;
|
|
5
5
|
export declare const dbQueryFilterSchema: <ROW extends ObjectWithId>() => any;
|
package/dist/validation/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { j,
|
|
1
|
+
import { j, JBuilder } from '@naturalcycles/nodejs-lib/ajv';
|
|
2
2
|
import { dbQueryFilterOperatorValues } from '../query/dbQuery.js';
|
|
3
3
|
// oxlint-disable typescript/explicit-function-return-type
|
|
4
4
|
// DBTransaction schema - validates presence without deep validation
|
|
5
|
-
const dbTransactionSchema = j.object.any()
|
|
5
|
+
const dbTransactionSchema = j.object.any();
|
|
6
6
|
// Schema that accepts any value (string, number, boolean, object, array, null)
|
|
7
|
-
const anyValueSchema = new
|
|
7
|
+
const anyValueSchema = new JBuilder({});
|
|
8
8
|
export const commonDBOptionsSchema = () => j.object({
|
|
9
|
-
tx: dbTransactionSchema.optional(),
|
|
9
|
+
tx: dbTransactionSchema.optional().castAs(),
|
|
10
10
|
});
|
|
11
11
|
export const commonDBSaveOptionsSchema = () => j.object({
|
|
12
|
-
tx: dbTransactionSchema.optional(),
|
|
12
|
+
tx: dbTransactionSchema.optional().castAs(),
|
|
13
13
|
excludeFromIndexes: j.array(j.string().castAs()).optional(),
|
|
14
14
|
saveMethod: j.enum(['upsert', 'insert', 'update']).optional(),
|
|
15
15
|
assignGeneratedIds: j.boolean().optional(),
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { _sortBy } from '@naturalcycles/js-lib/array/sort.js'
|
|
2
2
|
import { localTime } from '@naturalcycles/js-lib/datetime/localTime.js'
|
|
3
3
|
import { _deepCopy, _filterObject, _omit, _pick } from '@naturalcycles/js-lib/object'
|
|
4
|
-
import { AjvSchema } from '@naturalcycles/nodejs-lib/ajv'
|
|
5
4
|
import { Pipeline } from '@naturalcycles/nodejs-lib/stream'
|
|
6
5
|
import { CommonDao } from '../commondao/common.dao.js'
|
|
7
6
|
import type { CommonDB } from '../commondb/common.db.js'
|
|
@@ -21,7 +20,7 @@ export async function runCommonDaoTest(
|
|
|
21
20
|
const dao = new CommonDao({
|
|
22
21
|
table: TEST_TABLE,
|
|
23
22
|
db,
|
|
24
|
-
validateBM:
|
|
23
|
+
validateBM: testItemBMSchema.getValidationFunction(),
|
|
25
24
|
})
|
|
26
25
|
|
|
27
26
|
const items = createTestItemsBM(3)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { _range } from '@naturalcycles/js-lib/array/range.js'
|
|
2
2
|
import type { BaseDBEntity, UnixTimestamp } from '@naturalcycles/js-lib/types'
|
|
3
|
+
import type { JSchema } from '@naturalcycles/nodejs-lib/ajv'
|
|
3
4
|
import { j } from '@naturalcycles/nodejs-lib/ajv'
|
|
4
|
-
import type { JsonSchemaObjectBuilder } from '@naturalcycles/nodejs-lib/ajv'
|
|
5
5
|
|
|
6
6
|
const MOCK_TS_2018_06_21 = 1529539200 as UnixTimestamp
|
|
7
7
|
|
|
@@ -31,19 +31,18 @@ export const testItemTMSchema = j.object<TestItemTM>({
|
|
|
31
31
|
even: j.boolean().optional(),
|
|
32
32
|
})
|
|
33
33
|
|
|
34
|
-
export const testItemBMSchema:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
})
|
|
34
|
+
export const testItemBMSchema: JSchema<TestItemBM, false> = j.object.dbEntity<TestItemBM>({
|
|
35
|
+
// todo: figure out how to not copy-paste these 3 fields
|
|
36
|
+
id: j.string(), // todo: not strictly needed here
|
|
37
|
+
created: j.number().integer().unixTimestamp(),
|
|
38
|
+
updated: j.number().integer().unixTimestamp(),
|
|
39
|
+
k1: j.string(),
|
|
40
|
+
k2: j.string().nullable().optional(),
|
|
41
|
+
k3: j.number().optional(),
|
|
42
|
+
even: j.boolean().optional(),
|
|
43
|
+
b1: j.buffer().optional(),
|
|
44
|
+
nested: j.object.infer({ foo: j.number() }).optional(),
|
|
45
|
+
})
|
|
47
46
|
|
|
48
47
|
export function createTestItemDBM(num = 1): TestItemDBM {
|
|
49
48
|
return {
|
package/src/validation/index.ts
CHANGED
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
import type { ObjectWithId } from '@naturalcycles/js-lib/types'
|
|
2
|
-
import { j,
|
|
3
|
-
import type { JsonSchemaObjectBuilder } from '@naturalcycles/nodejs-lib/ajv'
|
|
2
|
+
import { j, JBuilder } from '@naturalcycles/nodejs-lib/ajv'
|
|
4
3
|
import type { CommonDBOptions, CommonDBSaveOptions, DBTransaction } from '../db.model.js'
|
|
5
|
-
import { dbQueryFilterOperatorValues } from '../query/dbQuery.js'
|
|
6
4
|
import type { DBQueryFilter, DBQueryOrder } from '../query/dbQuery.js'
|
|
5
|
+
import { dbQueryFilterOperatorValues } from '../query/dbQuery.js'
|
|
7
6
|
|
|
8
7
|
// oxlint-disable typescript/explicit-function-return-type
|
|
9
8
|
|
|
10
9
|
// DBTransaction schema - validates presence without deep validation
|
|
11
|
-
const dbTransactionSchema = j.object.any()
|
|
10
|
+
const dbTransactionSchema = j.object.any()
|
|
12
11
|
|
|
13
12
|
// Schema that accepts any value (string, number, boolean, object, array, null)
|
|
14
|
-
const anyValueSchema = new
|
|
13
|
+
const anyValueSchema = new JBuilder<any, false>({})
|
|
15
14
|
|
|
16
|
-
export const commonDBOptionsSchema = ():
|
|
15
|
+
export const commonDBOptionsSchema = (): JBuilder<CommonDBOptions, false> =>
|
|
17
16
|
j.object<CommonDBOptions>({
|
|
18
|
-
tx: dbTransactionSchema.optional(),
|
|
17
|
+
tx: dbTransactionSchema.optional().castAs<DBTransaction | undefined>(),
|
|
19
18
|
})
|
|
20
19
|
|
|
21
20
|
export const commonDBSaveOptionsSchema = <ROW extends ObjectWithId>() =>
|
|
22
21
|
j.object<CommonDBSaveOptions<ROW>>({
|
|
23
|
-
tx: dbTransactionSchema.optional(),
|
|
22
|
+
tx: dbTransactionSchema.optional().castAs<DBTransaction | undefined>(),
|
|
24
23
|
excludeFromIndexes: j.array(j.string().castAs<keyof ROW>()).optional(),
|
|
25
24
|
saveMethod: j.enum(['upsert', 'insert', 'update'] as const).optional(),
|
|
26
25
|
assignGeneratedIds: j.boolean().optional(),
|