UNPKG

@naturalcycles/db-lib

Version:

Lowest Common Denominator API to supported Databases

55 lines (54 loc) 1.92 kB
import { _range } from '@naturalcycles/js-lib/array/range.js'; import { jsonSchema } from '@naturalcycles/js-lib/json-schema'; import { baseDBEntitySchema, binarySchema, booleanSchema, numberSchema, objectSchema, stringSchema, } from '@naturalcycles/nodejs-lib/joi'; const MOCK_TS_2018_06_21 = 1529539200; export const TEST_TABLE = 'TEST_TABLE'; export const testItemBMSchema = objectSchema({ k1: stringSchema, k2: stringSchema.allow(null).optional(), k3: numberSchema.optional(), even: booleanSchema.optional(), b1: binarySchema.optional(), nested: objectSchema({ foo: numberSchema, }).optional(), }).concat(baseDBEntitySchema); export const testItemTMSchema = objectSchema({ k1: stringSchema, even: booleanSchema.optional(), }); export const testItemBMJsonSchema = jsonSchema .rootObject({ // todo: figure out how to not copy-paste these 3 fields id: jsonSchema.string(), // todo: not strictly needed here created: jsonSchema.unixTimestamp(), updated: jsonSchema.unixTimestamp(), k1: jsonSchema.string(), k2: jsonSchema.oneOf([jsonSchema.string(), jsonSchema.null()]).optional(), k3: jsonSchema.number().optional(), even: jsonSchema.boolean().optional(), b1: jsonSchema.buffer().optional(), }) .baseDBEntity() .build(); export function createTestItemDBM(num = 1) { return { id: `id${num}`, k1: `v${num}`, k2: `v${num * 2}`, k3: num, even: num % 2 === 0, nested: { foo: num }, created: MOCK_TS_2018_06_21, updated: MOCK_TS_2018_06_21, }; } export function createTestItemBM(num = 1) { return createTestItemDBM(num); } export function createTestItemsDBM(count = 1) { return _range(1, count + 1).map(num => createTestItemDBM(num)); } export function createTestItemsBM(count = 1) { return _range(1, count + 1).map(num => createTestItemBM(num)); }