@naturalcycles/db-lib 10.39.0 → 10.40.0

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.
@@ -4,7 +4,7 @@ import { _deepFreeze, _filterObject, _pick } from '@naturalcycles/js-lib/object'
4
4
  import { pMap } from '@naturalcycles/js-lib/promise/pMap.js';
5
5
  import { CommonDBType } from '../commondb/common.db.js';
6
6
  import { DBQuery } from '../query/dbQuery.js';
7
- import { createTestItemDBM, createTestItemsDBM, TEST_TABLE, testItemBMJsonSchema, } from './test.model.js';
7
+ import { createTestItemDBM, createTestItemsDBM, TEST_TABLE, testItemBMSchema, } from './test.model.js';
8
8
  export async function runCommonDBTest(db, quirks = {}) {
9
9
  // this is because vitest cannot be "required" from cjs
10
10
  const { test, expect } = await import('vitest');
@@ -19,7 +19,7 @@ export async function runCommonDBTest(db, quirks = {}) {
19
19
  // CREATE TABLE, DROP
20
20
  if (support.createTable) {
21
21
  test('createTable, dropIfExists=true', async () => {
22
- await db.createTable(TEST_TABLE, testItemBMJsonSchema, { dropIfExists: true });
22
+ await db.createTable(TEST_TABLE, testItemBMSchema.build(), { dropIfExists: true });
23
23
  });
24
24
  }
25
25
  if (support.queries) {
@@ -1,11 +1,11 @@
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 { getJoiValidationFunction } from '@naturalcycles/nodejs-lib/joi';
4
+ import { AjvSchema } from '@naturalcycles/nodejs-lib/ajv';
5
5
  import { Pipeline } from '@naturalcycles/nodejs-lib/stream';
6
6
  import { CommonDao } from '../commondao/common.dao.js';
7
7
  import { DBQuery } from '../query/dbQuery.js';
8
- import { createTestItemBM, createTestItemsBM, TEST_TABLE, testItemBMJsonSchema, testItemBMSchema, } from './test.model.js';
8
+ import { createTestItemBM, createTestItemsBM, TEST_TABLE, testItemBMSchema } from './test.model.js';
9
9
  export async function runCommonDaoTest(db, quirks = {}) {
10
10
  // this is because vitest cannot be "required" from cjs
11
11
  const { test, expect } = await import('vitest');
@@ -13,7 +13,7 @@ export async function runCommonDaoTest(db, quirks = {}) {
13
13
  const dao = new CommonDao({
14
14
  table: TEST_TABLE,
15
15
  db,
16
- validateBM: getJoiValidationFunction(testItemBMSchema),
16
+ validateBM: AjvSchema.create(testItemBMSchema).getValidationFunction(),
17
17
  });
18
18
  const items = createTestItemsBM(3);
19
19
  const itemsClone = _deepCopy(items);
@@ -29,7 +29,7 @@ export async function runCommonDaoTest(db, quirks = {}) {
29
29
  // CREATE TABLE, DROP
30
30
  if (support.createTable) {
31
31
  test('createTable, dropIfExists=true', async () => {
32
- await dao.createTable(testItemBMJsonSchema, { dropIfExists: true });
32
+ await dao.createTable(testItemBMSchema.build(), { dropIfExists: true });
33
33
  });
34
34
  }
35
35
  if (support.queries) {
@@ -4,6 +4,6 @@ import { runCommonDBTest } from './commonDBTest.js';
4
4
  import { runCommonKeyValueDaoTest } from './keyValueDaoTest.js';
5
5
  import { runCommonKeyValueDBTest } from './keyValueDBTest.js';
6
6
  import type { TestItemBM, TestItemDBM, TestItemTM } from './test.model.js';
7
- import { createTestItemBM, createTestItemDBM, createTestItemsBM, createTestItemsDBM, TEST_TABLE, testItemBMJsonSchema, testItemBMSchema, testItemTMSchema } from './test.model.js';
7
+ import { createTestItemBM, createTestItemDBM, createTestItemsBM, createTestItemsDBM, TEST_TABLE, testItemBMSchema, testItemTMSchema } from './test.model.js';
8
8
  export type { CommonDBImplementationQuirks, TestItemBM, TestItemDBM, TestItemTM };
9
- export { createTestItemBM, createTestItemDBM, createTestItemsBM, createTestItemsDBM, runCommonDaoTest, runCommonDBTest, runCommonKeyValueDaoTest, runCommonKeyValueDBTest, TEST_TABLE, testItemBMJsonSchema, testItemBMSchema, testItemTMSchema, };
9
+ export { createTestItemBM, createTestItemDBM, createTestItemsBM, createTestItemsDBM, runCommonDaoTest, runCommonDBTest, runCommonKeyValueDaoTest, runCommonKeyValueDBTest, TEST_TABLE, testItemBMSchema, testItemTMSchema, };
@@ -2,5 +2,5 @@ import { runCommonDaoTest } from './commonDaoTest.js';
2
2
  import { runCommonDBTest } from './commonDBTest.js';
3
3
  import { runCommonKeyValueDaoTest } from './keyValueDaoTest.js';
4
4
  import { runCommonKeyValueDBTest } from './keyValueDBTest.js';
5
- import { createTestItemBM, createTestItemDBM, createTestItemsBM, createTestItemsDBM, TEST_TABLE, testItemBMJsonSchema, testItemBMSchema, testItemTMSchema, } from './test.model.js';
6
- export { createTestItemBM, createTestItemDBM, createTestItemsBM, createTestItemsDBM, runCommonDaoTest, runCommonDBTest, runCommonKeyValueDaoTest, runCommonKeyValueDBTest, TEST_TABLE, testItemBMJsonSchema, testItemBMSchema, testItemTMSchema, };
5
+ import { createTestItemBM, createTestItemDBM, createTestItemsBM, createTestItemsDBM, TEST_TABLE, testItemBMSchema, testItemTMSchema, } from './test.model.js';
6
+ export { createTestItemBM, createTestItemDBM, createTestItemsBM, createTestItemsDBM, runCommonDaoTest, runCommonDBTest, runCommonKeyValueDaoTest, runCommonKeyValueDBTest, TEST_TABLE, testItemBMSchema, testItemTMSchema, };
@@ -1,5 +1,4 @@
1
1
  import type { BaseDBEntity } from '@naturalcycles/js-lib/types';
2
- import { type ObjectSchema } from '@naturalcycles/nodejs-lib/joi';
3
2
  export declare const TEST_TABLE = "TEST_TABLE";
4
3
  export declare const TEST_TABLE_2 = "TEST_TABLE_2";
5
4
  export interface TestItemBM extends BaseDBEntity {
@@ -18,9 +17,8 @@ export interface TestItemTM {
18
17
  k1: string;
19
18
  even?: boolean;
20
19
  }
21
- export declare const testItemBMSchema: ObjectSchema<TestItemBM>;
22
- export declare const testItemTMSchema: ObjectSchema<TestItemTM>;
23
- export declare const testItemBMJsonSchema: any;
20
+ export declare const testItemTMSchema: any;
21
+ export declare const testItemBMSchema: any;
24
22
  export declare function createTestItemDBM(num?: number): TestItemDBM;
25
23
  export declare function createTestItemBM(num?: number): TestItemBM;
26
24
  export declare function createTestItemsDBM(count?: number): TestItemDBM[];
@@ -1,25 +1,13 @@
1
1
  import { _range } from '@naturalcycles/js-lib/array/range.js';
2
2
  import { j } from '@naturalcycles/nodejs-lib/ajv';
3
- import { baseDBEntitySchema, binarySchema, booleanSchema, numberSchema, objectSchema, stringSchema, } from '@naturalcycles/nodejs-lib/joi';
4
3
  const MOCK_TS_2018_06_21 = 1529539200;
5
4
  export const TEST_TABLE = 'TEST_TABLE';
6
5
  export const TEST_TABLE_2 = 'TEST_TABLE_2';
7
- export const testItemBMSchema = objectSchema({
8
- k1: stringSchema,
9
- k2: stringSchema.allow(null).optional(),
10
- k3: numberSchema.optional(),
11
- even: booleanSchema.optional(),
12
- b1: binarySchema.optional(),
13
- nested: objectSchema({
14
- foo: numberSchema,
15
- }).optional(),
16
- }).concat(baseDBEntitySchema);
17
- export const testItemTMSchema = objectSchema({
18
- k1: stringSchema,
19
- even: booleanSchema.optional(),
6
+ export const testItemTMSchema = j.object({
7
+ k1: j.string(),
8
+ even: j.boolean().optional(),
20
9
  });
21
- export const testItemBMJsonSchema = j.object
22
- .dbEntity({
10
+ export const testItemBMSchema = j.object.dbEntity({
23
11
  // todo: figure out how to not copy-paste these 3 fields
24
12
  id: j.string(), // todo: not strictly needed here
25
13
  created: j.number().integer().unixTimestamp(),
@@ -30,8 +18,7 @@ export const testItemBMJsonSchema = j.object
30
18
  even: j.boolean().optional(),
31
19
  b1: j.buffer().optional(),
32
20
  nested: j.object.infer({ foo: j.number() }).optional(),
33
- })
34
- .build();
21
+ });
35
22
  export function createTestItemDBM(num = 1) {
36
23
  return {
37
24
  id: `id${num}`,
@@ -1,9 +1,9 @@
1
- import { type ObjectSchema, type StringSchema } from '@naturalcycles/nodejs-lib/joi';
2
- import type { CommonDBOptions, CommonDBSaveOptions } from '../db.model.js';
3
- import type { DBQuery, DBQueryFilter, DBQueryFilterOperator, DBQueryOrder } from '../query/dbQuery.js';
4
- export declare const commonDBOptionsSchema: ObjectSchema<CommonDBOptions>;
5
- export declare const commonDBSaveOptionsSchema: ObjectSchema<CommonDBSaveOptions<any>>;
6
- export declare const dbQueryFilterOperatorSchema: StringSchema<DBQueryFilterOperator>;
7
- export declare const dbQueryFilterSchema: ObjectSchema<DBQueryFilter<any>>;
8
- export declare const dbQueryOrderSchema: ObjectSchema<DBQueryOrder<any>>;
9
- export declare const dbQuerySchema: ObjectSchema<DBQuery<any>>;
1
+ import type { ObjectWithId } from '@naturalcycles/js-lib/types';
2
+ import { type JsonSchemaObjectBuilder } from '@naturalcycles/nodejs-lib/ajv';
3
+ import type { CommonDBOptions } from '../db.model.js';
4
+ export declare const commonDBOptionsSchema: () => JsonSchemaObjectBuilder<CommonDBOptions, CommonDBOptions>;
5
+ export declare const commonDBSaveOptionsSchema: <ROW extends ObjectWithId>() => any;
6
+ export declare const dbQueryFilterOperatorSchema: any;
7
+ export declare const dbQueryFilterSchema: <ROW extends ObjectWithId>() => any;
8
+ export declare const dbQueryOrderSchema: <ROW extends ObjectWithId>() => any;
9
+ export declare const dbQuerySchema: <ROW extends ObjectWithId>() => any;
@@ -1,29 +1,36 @@
1
- import { anySchema, arraySchema, booleanSchema, integerSchema, Joi, objectSchema, stringSchema, } from '@naturalcycles/nodejs-lib/joi';
2
- import { dbQueryFilterOperatorValues } from '../query/dbQuery.js';
3
- export const commonDBOptionsSchema = objectSchema({
4
- ['onlyCache']: booleanSchema.optional(),
5
- ['skipCache']: booleanSchema.optional(),
1
+ import { j, JsonSchemaAnyBuilder, } from '@naturalcycles/nodejs-lib/ajv';
2
+ import { dbQueryFilterOperatorValues, } from '../query/dbQuery.js';
3
+ // oxlint-disable typescript/explicit-function-return-type
4
+ // DBTransaction schema - validates presence without deep validation
5
+ const dbTransactionSchema = j.object.any().castAs();
6
+ // Schema that accepts any value (string, number, boolean, object, array, null)
7
+ const anyValueSchema = new JsonSchemaAnyBuilder({});
8
+ export const commonDBOptionsSchema = () => j.object({
9
+ tx: dbTransactionSchema.optional(),
6
10
  });
7
- export const commonDBSaveOptionsSchema = objectSchema({
8
- excludeFromIndexes: arraySchema(stringSchema).optional(),
9
- }).concat(commonDBOptionsSchema);
10
- export const dbQueryFilterOperatorSchema = Joi.string().valid(...dbQueryFilterOperatorValues);
11
- export const dbQueryFilterSchema = objectSchema({
12
- name: stringSchema,
11
+ export const commonDBSaveOptionsSchema = () => j.object({
12
+ tx: dbTransactionSchema.optional(),
13
+ excludeFromIndexes: j.array(j.string().castAs()).optional(),
14
+ saveMethod: j.enum(['upsert', 'insert', 'update']).optional(),
15
+ assignGeneratedIds: j.boolean().optional(),
16
+ });
17
+ export const dbQueryFilterOperatorSchema = j.enum(dbQueryFilterOperatorValues);
18
+ export const dbQueryFilterSchema = () => j.object({
19
+ name: j.string().castAs(),
13
20
  op: dbQueryFilterOperatorSchema,
14
- val: anySchema,
21
+ val: anyValueSchema,
15
22
  });
16
- export const dbQueryOrderSchema = objectSchema({
17
- name: stringSchema,
18
- descending: booleanSchema.optional(),
23
+ export const dbQueryOrderSchema = () => j.object({
24
+ name: j.string().castAs(),
25
+ descending: j.boolean().optional(),
19
26
  });
20
- export const dbQuerySchema = objectSchema({
21
- table: stringSchema,
22
- _filters: arraySchema(dbQueryFilterSchema).optional(),
23
- _limitValue: integerSchema.min(0).optional(),
24
- _offsetValue: integerSchema.min(0).optional(),
25
- _orders: arraySchema(dbQueryOrderSchema).optional(),
26
- _startCursor: stringSchema.optional(),
27
- _endCursor: stringSchema.optional(),
28
- _selectedFieldNames: arraySchema(stringSchema).optional(),
27
+ export const dbQuerySchema = () => j.object.infer({
28
+ table: j.string(),
29
+ _filters: j.array(dbQueryFilterSchema()).optional(),
30
+ _limitValue: j.number().integer().min(0).optional(),
31
+ _offsetValue: j.number().integer().min(0).optional(),
32
+ _orders: j.array(dbQueryOrderSchema()).optional(),
33
+ _startCursor: j.string().optional(),
34
+ _endCursor: j.string().optional(),
35
+ _selectedFieldNames: j.array(j.string().castAs()).optional(),
29
36
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/db-lib",
3
3
  "type": "module",
4
- "version": "10.39.0",
4
+ "version": "10.40.0",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@naturalcycles/nodejs-lib": "^15"
@@ -10,7 +10,7 @@ import {
10
10
  createTestItemDBM,
11
11
  createTestItemsDBM,
12
12
  TEST_TABLE,
13
- testItemBMJsonSchema,
13
+ testItemBMSchema,
14
14
  } from './test.model.js'
15
15
 
16
16
  /**
@@ -49,7 +49,7 @@ export async function runCommonDBTest(
49
49
  // CREATE TABLE, DROP
50
50
  if (support.createTable) {
51
51
  test('createTable, dropIfExists=true', async () => {
52
- await db.createTable(TEST_TABLE, testItemBMJsonSchema, { dropIfExists: true })
52
+ await db.createTable(TEST_TABLE, testItemBMSchema.build(), { dropIfExists: true })
53
53
  })
54
54
  }
55
55
 
@@ -1,20 +1,14 @@
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 { getJoiValidationFunction } from '@naturalcycles/nodejs-lib/joi'
4
+ import { AjvSchema } from '@naturalcycles/nodejs-lib/ajv'
5
5
  import { Pipeline } from '@naturalcycles/nodejs-lib/stream'
6
6
  import { CommonDao } from '../commondao/common.dao.js'
7
7
  import type { CommonDB } from '../commondb/common.db.js'
8
8
  import { DBQuery } from '../query/dbQuery.js'
9
9
  import type { CommonDBImplementationQuirks } from './commonDBTest.js'
10
10
  import type { TestItemBM } from './test.model.js'
11
- import {
12
- createTestItemBM,
13
- createTestItemsBM,
14
- TEST_TABLE,
15
- testItemBMJsonSchema,
16
- testItemBMSchema,
17
- } from './test.model.js'
11
+ import { createTestItemBM, createTestItemsBM, TEST_TABLE, testItemBMSchema } from './test.model.js'
18
12
 
19
13
  export async function runCommonDaoTest(
20
14
  db: CommonDB,
@@ -27,7 +21,7 @@ export async function runCommonDaoTest(
27
21
  const dao = new CommonDao({
28
22
  table: TEST_TABLE,
29
23
  db,
30
- validateBM: getJoiValidationFunction(testItemBMSchema),
24
+ validateBM: AjvSchema.create(testItemBMSchema).getValidationFunction(),
31
25
  })
32
26
 
33
27
  const items = createTestItemsBM(3)
@@ -47,7 +41,7 @@ export async function runCommonDaoTest(
47
41
  // CREATE TABLE, DROP
48
42
  if (support.createTable) {
49
43
  test('createTable, dropIfExists=true', async () => {
50
- await dao.createTable(testItemBMJsonSchema, { dropIfExists: true })
44
+ await dao.createTable(testItemBMSchema.build(), { dropIfExists: true })
51
45
  })
52
46
  }
53
47
 
@@ -10,7 +10,6 @@ import {
10
10
  createTestItemsBM,
11
11
  createTestItemsDBM,
12
12
  TEST_TABLE,
13
- testItemBMJsonSchema,
14
13
  testItemBMSchema,
15
14
  testItemTMSchema,
16
15
  } from './test.model.js'
@@ -27,7 +26,6 @@ export {
27
26
  runCommonKeyValueDaoTest,
28
27
  runCommonKeyValueDBTest,
29
28
  TEST_TABLE,
30
- testItemBMJsonSchema,
31
29
  testItemBMSchema,
32
30
  testItemTMSchema,
33
31
  }
@@ -1,15 +1,6 @@
1
1
  import { _range } from '@naturalcycles/js-lib/array/range.js'
2
2
  import type { BaseDBEntity, UnixTimestamp } from '@naturalcycles/js-lib/types'
3
3
  import { j } from '@naturalcycles/nodejs-lib/ajv'
4
- import {
5
- baseDBEntitySchema,
6
- binarySchema,
7
- booleanSchema,
8
- numberSchema,
9
- type ObjectSchema,
10
- objectSchema,
11
- stringSchema,
12
- } from '@naturalcycles/nodejs-lib/joi'
13
4
 
14
5
  const MOCK_TS_2018_06_21 = 1529539200 as UnixTimestamp
15
6
 
@@ -34,36 +25,23 @@ export interface TestItemTM {
34
25
  even?: boolean
35
26
  }
36
27
 
37
- export const testItemBMSchema: ObjectSchema<TestItemBM> = objectSchema<TestItemBM>({
38
- k1: stringSchema,
39
- k2: stringSchema.allow(null).optional(),
40
- k3: numberSchema.optional(),
41
- even: booleanSchema.optional(),
42
- b1: binarySchema.optional(),
43
- nested: objectSchema({
44
- foo: numberSchema,
45
- }).optional(),
46
- }).concat(baseDBEntitySchema as any)
47
-
48
- export const testItemTMSchema: ObjectSchema<TestItemTM> = objectSchema<TestItemTM>({
49
- k1: stringSchema,
50
- even: booleanSchema.optional(),
28
+ export const testItemTMSchema = j.object<TestItemTM>({
29
+ k1: j.string(),
30
+ even: j.boolean().optional(),
51
31
  })
52
32
 
53
- export const testItemBMJsonSchema = j.object
54
- .dbEntity<TestItemBM>({
55
- // todo: figure out how to not copy-paste these 3 fields
56
- id: j.string(), // todo: not strictly needed here
57
- created: j.number().integer().unixTimestamp(),
58
- updated: j.number().integer().unixTimestamp(),
59
- k1: j.string(),
60
- k2: j.string().nullable().optional(),
61
- k3: j.number().optional(),
62
- even: j.boolean().optional(),
63
- b1: j.buffer().optional(),
64
- nested: j.object.infer({ foo: j.number() }).optional(),
65
- })
66
- .build()
33
+ export const testItemBMSchema = j.object.dbEntity<TestItemBM>({
34
+ // todo: figure out how to not copy-paste these 3 fields
35
+ id: j.string(), // todo: not strictly needed here
36
+ created: j.number().integer().unixTimestamp(),
37
+ updated: j.number().integer().unixTimestamp(),
38
+ k1: j.string(),
39
+ k2: j.string().nullable().optional(),
40
+ k3: j.number().optional(),
41
+ even: j.boolean().optional(),
42
+ b1: j.buffer().optional(),
43
+ nested: j.object.infer({ foo: j.number() }).optional(),
44
+ })
67
45
 
68
46
  export function createTestItemDBM(num = 1): TestItemDBM {
69
47
  return {
@@ -1,57 +1,63 @@
1
+ import type { ObjectWithId } from '@naturalcycles/js-lib/types'
1
2
  import {
2
- anySchema,
3
- arraySchema,
4
- booleanSchema,
5
- integerSchema,
6
- Joi,
7
- type ObjectSchema,
8
- objectSchema,
9
- type StringSchema,
10
- stringSchema,
11
- } from '@naturalcycles/nodejs-lib/joi'
12
- import type { CommonDBOptions, CommonDBSaveOptions } from '../db.model.js'
13
- import type {
14
- DBQuery,
15
- DBQueryFilter,
16
- DBQueryFilterOperator,
17
- DBQueryOrder,
3
+ j,
4
+ JsonSchemaAnyBuilder,
5
+ type JsonSchemaObjectBuilder,
6
+ } from '@naturalcycles/nodejs-lib/ajv'
7
+ import type { CommonDBOptions, CommonDBSaveOptions, DBTransaction } from '../db.model.js'
8
+ import {
9
+ type DBQueryFilter,
10
+ dbQueryFilterOperatorValues,
11
+ type DBQueryOrder,
18
12
  } from '../query/dbQuery.js'
19
- import { dbQueryFilterOperatorValues } from '../query/dbQuery.js'
20
-
21
- export const commonDBOptionsSchema: ObjectSchema<CommonDBOptions> = objectSchema<CommonDBOptions>({
22
- ['onlyCache' as any]: booleanSchema.optional(),
23
- ['skipCache' as any]: booleanSchema.optional(),
24
- })
25
-
26
- export const commonDBSaveOptionsSchema: ObjectSchema<CommonDBSaveOptions<any>> = objectSchema<
27
- CommonDBSaveOptions<any>
28
- >({
29
- excludeFromIndexes: arraySchema(stringSchema).optional(),
30
- }).concat(commonDBOptionsSchema)
31
-
32
- export const dbQueryFilterOperatorSchema: StringSchema<DBQueryFilterOperator> =
33
- Joi.string<DBQueryFilterOperator>().valid(...dbQueryFilterOperatorValues)
34
-
35
- export const dbQueryFilterSchema: ObjectSchema<DBQueryFilter<any>> = objectSchema<
36
- DBQueryFilter<any>
37
- >({
38
- name: stringSchema,
39
- op: dbQueryFilterOperatorSchema,
40
- val: anySchema,
41
- })
42
-
43
- export const dbQueryOrderSchema: ObjectSchema<DBQueryOrder<any>> = objectSchema<DBQueryOrder<any>>({
44
- name: stringSchema,
45
- descending: booleanSchema.optional(),
46
- })
47
-
48
- export const dbQuerySchema: ObjectSchema<DBQuery<any>> = objectSchema<DBQuery<any>>({
49
- table: stringSchema,
50
- _filters: arraySchema(dbQueryFilterSchema).optional(),
51
- _limitValue: integerSchema.min(0).optional(),
52
- _offsetValue: integerSchema.min(0).optional(),
53
- _orders: arraySchema(dbQueryOrderSchema).optional(),
54
- _startCursor: stringSchema.optional(),
55
- _endCursor: stringSchema.optional(),
56
- _selectedFieldNames: arraySchema(stringSchema).optional(),
57
- })
13
+
14
+ // oxlint-disable typescript/explicit-function-return-type
15
+
16
+ // DBTransaction schema - validates presence without deep validation
17
+ const dbTransactionSchema = j.object.any().castAs<DBTransaction>()
18
+
19
+ // Schema that accepts any value (string, number, boolean, object, array, null)
20
+ const anyValueSchema = new JsonSchemaAnyBuilder<any, any, false>({})
21
+
22
+ export const commonDBOptionsSchema = (): JsonSchemaObjectBuilder<
23
+ CommonDBOptions,
24
+ CommonDBOptions
25
+ > =>
26
+ j.object<CommonDBOptions>({
27
+ tx: dbTransactionSchema.optional(),
28
+ })
29
+
30
+ export const commonDBSaveOptionsSchema = <ROW extends ObjectWithId>() =>
31
+ j.object<CommonDBSaveOptions<ROW>>({
32
+ tx: dbTransactionSchema.optional(),
33
+ excludeFromIndexes: j.array(j.string().castAs<keyof ROW>()).optional(),
34
+ saveMethod: j.enum(['upsert', 'insert', 'update'] as const).optional(),
35
+ assignGeneratedIds: j.boolean().optional(),
36
+ })
37
+
38
+ export const dbQueryFilterOperatorSchema = j.enum(dbQueryFilterOperatorValues)
39
+
40
+ export const dbQueryFilterSchema = <ROW extends ObjectWithId>() =>
41
+ j.object<DBQueryFilter<ROW>>({
42
+ name: j.string().castAs<keyof ROW>(),
43
+ op: dbQueryFilterOperatorSchema,
44
+ val: anyValueSchema,
45
+ })
46
+
47
+ export const dbQueryOrderSchema = <ROW extends ObjectWithId>() =>
48
+ j.object<DBQueryOrder<ROW>>({
49
+ name: j.string().castAs<keyof ROW>(),
50
+ descending: j.boolean().optional(),
51
+ })
52
+
53
+ export const dbQuerySchema = <ROW extends ObjectWithId>() =>
54
+ j.object.infer({
55
+ table: j.string(),
56
+ _filters: j.array(dbQueryFilterSchema<ROW>()).optional(),
57
+ _limitValue: j.number().integer().min(0).optional(),
58
+ _offsetValue: j.number().integer().min(0).optional(),
59
+ _orders: j.array(dbQueryOrderSchema<ROW>()).optional(),
60
+ _startCursor: j.string().optional(),
61
+ _endCursor: j.string().optional(),
62
+ _selectedFieldNames: j.array(j.string().castAs<keyof ROW>()).optional(),
63
+ })