UNPKG

@naturalcycles/db-lib

Version:

Lowest Common Denominator API to supported Databases

56 lines (55 loc) 1.93 kB
import { _range } from '@naturalcycles/js-lib/array/range.js'; import { j } from '@naturalcycles/nodejs-lib/ajv'; 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 TEST_TABLE_2 = 'TEST_TABLE_2'; 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 = j.object .dbEntity({ // todo: figure out how to not copy-paste these 3 fields id: j.string(), // todo: not strictly needed here created: j.number().integer().unixTimestamp(), updated: j.number().integer().unixTimestamp(), k1: j.string(), k2: j.string().nullable().optional(), k3: j.number().optional(), even: j.boolean().optional(), b1: j.buffer().optional(), nested: j.object.infer({ foo: j.number() }).optional(), }) .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)); }