UNPKG

@naturalcycles/nodejs-lib

Version:
71 lines 2.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const joi_extensions_1 = require("./joi.extensions"); // Should all booleans be optional as a convention? So undefined will be just treated as false? exports.booleanSchema = joi_extensions_1.Joi.boolean(); exports.stringSchema = joi_extensions_1.Joi.string(); exports.numberSchema = joi_extensions_1.Joi.number(); exports.integerSchema = joi_extensions_1.Joi.number().integer(); exports.dateStringSchema = exports.stringSchema.dateString(); exports.binarySchema = joi_extensions_1.Joi.binary(); exports.urlSchema = (scheme = 'https') => joi_extensions_1.Joi.string().uri({ scheme }); function arraySchema(items) { return items ? joi_extensions_1.Joi.array().items(items) : joi_extensions_1.Joi.array(); } exports.arraySchema = arraySchema; function objectSchema(schema) { return joi_extensions_1.Joi.object(schema); } exports.objectSchema = objectSchema; exports.anySchema = joi_extensions_1.Joi.any(); exports.anyObjectSchema = joi_extensions_1.Joi.object().options({ stripUnknown: false }); // 1g498efj5sder3324zer /** * [a-z0-9_]* * 6-16 length */ exports.idSchema = exports.stringSchema .regex(/^[a-z0-9_]*$/) .min(6) .max(64); /** * `_` should NOT be allowed to be able to use slug-ids as part of natural ids with `_` separator. */ exports.SLUG_PATTERN = /^[a-z0-9-]*$/; /** * "Slug" - a valid URL, filename, etc. */ exports.slugSchema = exports.stringSchema .regex(exports.SLUG_PATTERN) .min(1) .max(255); // 16725225600 is 2500-01-01 exports.unixTimestampSchema = exports.numberSchema .integer() .min(0) .max(16725225600); // 2 exports.verSchema = exports.numberSchema .optional() .integer() .min(1) .max(100); /** * Be careful, by default emailSchema does TLD validation. To disable it - use `stringSchema.email({tld: false}).lowercase()` */ exports.emailSchema = exports.stringSchema.email().lowercase(); /** * Pattern is simplified for our use, it's not a canonical SemVer. */ exports.SEM_VER_PATTERN = /^[0-9]+\.[0-9]+\.[0-9]+$/; exports.semVerSchema = exports.stringSchema.regex(exports.SEM_VER_PATTERN); // todo: .error(() => 'should be SemVer') exports.userAgentSchema = exports.stringSchema.min(10).max(400); exports.utcOffsetSchema = exports.numberSchema .min(-14 * 60) .max(14 * 60) .dividable(15); // todo: we used to have format as "192.168.0.1/192.168.0.2" (slash with provided X-Forwarded-For value) // maybe it'll break this validation exports.ipAddressSchema = exports.stringSchema.ip(); //# sourceMappingURL=joi.shared.schemas.js.map