Skip to content
Permalink
Browse files

fix: export more joi models

  • Loading branch information...
kirillgroshkov committed May 22, 2019
1 parent f0de056 commit f33dff4c391e800f9e14059b8133fbc2c9510ba8
@@ -20,6 +20,15 @@ import { requireEnvKeys } from './util/env.util'
import { LRUMemoCache } from './util/lruMemoCache'
import { unzipBuffer, unzipToString, zipBuffer, zipString } from './util/zip.util'
import { ExtendedJoi, Joi } from './validation/joi/joi.extensions'
import {
AnySchemaTyped,
ArraySchemaTyped,
BooleanSchemaTyped,
NumberSchemaTyped,
ObjectSchemaTyped,
SchemaTyped,
StringSchemaTyped,
} from './validation/joi/joi.model'
import {
anyObjectSchema,
anySchema,
@@ -49,10 +58,6 @@ import {
} from './validation/joi/joi.validation.util'

export {
// todo: in progress, not exported yet
// LUXON_ISO_DATE_FORMAT,
// localDateUtil,
// localTimeUtil,
JoiValidationError,
JoiValidationResult,
validate,
@@ -69,6 +74,13 @@ export {
objectSchema,
anySchema,
anyObjectSchema,
SchemaTyped,
AnySchemaTyped,
ArraySchemaTyped,
BooleanSchemaTyped,
NumberSchemaTyped,
ObjectSchemaTyped,
StringSchemaTyped,
idSchema,
unixTimestampSchema,
verSchema,
@@ -2,7 +2,7 @@ import { NumberSchema, StringSchema } from '@hapi/joi'
import * as JoiLib from '@hapi/joi'
import { DateStringExtension, dateStringExtension } from './dateString.extension'
import { DividableExtension, dividableExtension } from './dividable.extension'
import { AnySchemaT } from './joi.model'
import { AnySchemaTyped } from './joi.model'

export const Joi: ExtendedJoi = JoiLib.defaults(schema => {
// hack to prevent infinite recursion due to .empty('') where '' is a stringSchema itself
@@ -27,9 +27,9 @@ export interface ExtendedJoi extends JoiLib.Root {
export interface ExtendedStringSchema
extends StringSchema,
DateStringExtension,
AnySchemaT<string> {}
AnySchemaTyped<string> {}

export interface ExtendedNumberSchema
extends NumberSchema,
DividableExtension,
AnySchemaT<number> {}
AnySchemaTyped<number> {}
@@ -13,7 +13,7 @@ import {
} from '@hapi/joi'

export type SchemaTyped<IN, OUT = IN> =
| AnySchemaT<IN, OUT>
| AnySchemaTyped<IN, OUT>
| ArraySchemaTyped<IN>
| AlternativesSchemaTyped<IN>
| BinarySchemaTyped
@@ -29,15 +29,15 @@ export type SchemaTyped<IN, OUT = IN> =
* IN - value before validation/conversion
* OUT - value after validation/conversion (can be different due to conversion, stripping, etc)
*/
export interface AnySchemaT<IN, OUT = IN> extends AnySchema {}
export interface AnySchemaTyped<IN, OUT = IN> extends AnySchema {}

export interface ArraySchemaTyped<T> extends ArraySchema, AnySchemaT<T[]> {}
export interface ArraySchemaTyped<T> extends ArraySchema, AnySchemaTyped<T[]> {}
export interface AlternativesSchemaTyped<T> extends AlternativesSchema {}
export interface BinarySchemaTyped extends BinarySchema, AnySchemaT<Buffer> {}
export interface BooleanSchemaTyped extends BooleanSchema, AnySchemaT<boolean> {}
export interface BinarySchemaTyped extends BinarySchema, AnySchemaTyped<Buffer> {}
export interface BooleanSchemaTyped extends BooleanSchema, AnySchemaTyped<boolean> {}
export interface DateSchemaTyped<T> extends DateSchema {}
export interface FunctionSchemaTyped<T> extends FunctionSchema {}
export interface NumberSchemaTyped extends NumberSchema, AnySchemaT<number> {}
export interface ObjectSchemaTyped<IN, OUT> extends ObjectSchema, AnySchemaT<IN, OUT> {}
export interface StringSchemaTyped extends StringSchema, AnySchemaT<string> {}
export interface NumberSchemaTyped extends NumberSchema, AnySchemaTyped<number> {}
export interface ObjectSchemaTyped<IN, OUT> extends ObjectSchema, AnySchemaTyped<IN, OUT> {}
export interface StringSchemaTyped extends StringSchema, AnySchemaTyped<string> {}
export interface LazySchemaTyped<T> extends LazySchema {}
@@ -1,5 +1,10 @@
import { Joi } from './joi.extensions'
import { AnySchemaT, ArraySchemaTyped, BooleanSchemaTyped, ObjectSchemaTyped } from './joi.model'
import {
AnySchemaTyped,
ArraySchemaTyped,
BooleanSchemaTyped,
ObjectSchemaTyped,
} from './joi.model'

// Should all booleans be optional as a convention? So undefined will be just treated as false?
export const booleanSchema = Joi.boolean() as BooleanSchemaTyped
@@ -9,12 +14,12 @@ export const integerSchema = Joi.number().integer()
export const dateStringSchema = stringSchema.dateString()
export const binarySchema = Joi.binary()

export function arraySchema<T> (items?: AnySchemaT<T, T>): ArraySchemaTyped<T> {
export function arraySchema<T> (items?: AnySchemaTyped<T, T>): ArraySchemaTyped<T> {
return items ? Joi.array().items(items) : Joi.array()
}

export function objectSchema<IN, OUT = IN> (
schema?: { [key in keyof Partial<IN>]: AnySchemaT<IN[key]> },
schema?: { [key in keyof Partial<IN>]: AnySchemaTyped<IN[key]> },
): ObjectSchemaTyped<IN, OUT> {
return Joi.object(schema)
}
@@ -9,7 +9,7 @@
import { ValidationError, ValidationOptions } from '@hapi/joi'
import { isObject } from '@naturalcycles/js-lib'
import { Joi } from './joi.extensions'
import { AnySchemaT } from './joi.model'
import { AnySchemaTyped } from './joi.model'
import { JoiValidationError } from './joi.validation.error'

export interface JoiValidationResult<T = any> {
@@ -43,7 +43,7 @@ const defaultOptions: ValidationOptions = {
*/
export function validate<IN, OUT = IN> (
value: IN,
schema?: AnySchemaT<IN, OUT>,
schema?: AnySchemaTyped<IN, OUT>,
objectName?: string,
options: ValidationOptions = {},
): OUT {
@@ -70,7 +70,7 @@ export function validate<IN, OUT = IN> (
*/
export function getValidationResult<IN, OUT = IN> (
value: IN,
schema?: AnySchemaT<IN, OUT>,
schema?: AnySchemaTyped<IN, OUT>,
objectName?: string,
options: ValidationOptions = {},
): JoiValidationResult<OUT> {
@@ -10,16 +10,16 @@
"@babel/highlight" "^7.0.0"

"@babel/core@^7.1.0":
version "7.4.4"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.4.4.tgz#84055750b05fcd50f9915a826b44fa347a825250"
integrity sha512-lQgGX3FPRgbz2SKmhMtYgJvVzGZrmjaF4apZ2bLwofAKiSjxU0drPh4S/VasyYXwaTs+A1gvQ45BN8SQJzHsQQ==
version "7.4.5"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.4.5.tgz#081f97e8ffca65a9b4b0fdc7e274e703f000c06a"
integrity sha512-OvjIh6aqXtlsA8ujtGKfC7LYWksYSX8yQcM8Ay3LuvVeQ63lcOKgoZWVqcpFwkd29aYU9rVx7jxhfhiEDV9MZA==
dependencies:
"@babel/code-frame" "^7.0.0"
"@babel/generator" "^7.4.4"
"@babel/helpers" "^7.4.4"
"@babel/parser" "^7.4.4"
"@babel/parser" "^7.4.5"
"@babel/template" "^7.4.4"
"@babel/traverse" "^7.4.4"
"@babel/traverse" "^7.4.5"
"@babel/types" "^7.4.4"
convert-source-map "^1.1.0"
debug "^4.1.0"
@@ -86,10 +86,10 @@
esutils "^2.0.2"
js-tokens "^4.0.0"

"@babel/parser@^7.1.0", "@babel/parser@^7.4.3", "@babel/parser@^7.4.4":
version "7.4.4"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.4.4.tgz#5977129431b8fe33471730d255ce8654ae1250b6"
integrity sha512-5pCS4mOsL+ANsFZGdvNLybx4wtqAZJ0MJjMHxvzI3bvIsz6sQvzW8XX92EYIkiPtIvcfG3Aj+Ir5VNyjnZhP7w==
"@babel/parser@^7.1.0", "@babel/parser@^7.4.3", "@babel/parser@^7.4.4", "@babel/parser@^7.4.5":
version "7.4.5"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.4.5.tgz#04af8d5d5a2b044a2a1bffacc1e5e6673544e872"
integrity sha512-9mUqkL1FF5T7f0WDFfAoDdiMVPWsdD1gZYzSnaXsxUCUqzuch/8of9G3VUSNiZmMBoRxT3neyVsqeiL/ZPcjew==

"@babel/plugin-syntax-object-rest-spread@^7.0.0":
version "7.2.0"
@@ -99,9 +99,9 @@
"@babel/helper-plugin-utils" "^7.0.0"

"@babel/runtime@^7.0.0":
version "7.4.4"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.4.4.tgz#dc2e34982eb236803aa27a07fea6857af1b9171d"
integrity sha512-w0+uT71b6Yi7i5SE0co4NioIpSYS6lLiXvCzWzGSKvpK5vdQtCbICHMj+gbAKAOtxiV6HsVh/MBdaF9EQ6faSg==
version "7.4.5"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.4.5.tgz#582bb531f5f9dc67d2fcb682979894f75e253f12"
integrity sha512-TuI4qpWZP6lGOGIuGWtp9sPluqYICmbk8T/1vpSysqJxRPkudh/ofFWyqdcMsDf2s7KvDL4/YHgKyvcS3g9CJQ==
dependencies:
regenerator-runtime "^0.13.2"

@@ -114,16 +114,16 @@
"@babel/parser" "^7.4.4"
"@babel/types" "^7.4.4"

"@babel/traverse@^7.1.0", "@babel/traverse@^7.4.3", "@babel/traverse@^7.4.4":
version "7.4.4"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.4.4.tgz#0776f038f6d78361860b6823887d4f3937133fe8"
integrity sha512-Gw6qqkw/e6AGzlyj9KnkabJX7VcubqPtkUQVAwkc0wUMldr3A/hezNB3Rc5eIvId95iSGkGIOe5hh1kMKf951A==
"@babel/traverse@^7.1.0", "@babel/traverse@^7.4.3", "@babel/traverse@^7.4.4", "@babel/traverse@^7.4.5":
version "7.4.5"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.4.5.tgz#4e92d1728fd2f1897dafdd321efbff92156c3216"
integrity sha512-Vc+qjynwkjRmIFGxy0KYoPj4FdVDxLej89kMHFsWScq999uX+pwcX4v9mWRjW0KcAYTPAuVQl2LKP1wEVLsp+A==
dependencies:
"@babel/code-frame" "^7.0.0"
"@babel/generator" "^7.4.4"
"@babel/helper-function-name" "^7.1.0"
"@babel/helper-split-export-declaration" "^7.4.4"
"@babel/parser" "^7.4.4"
"@babel/parser" "^7.4.5"
"@babel/types" "^7.4.4"
debug "^4.1.0"
globals "^11.1.0"
@@ -528,9 +528,9 @@
semantic-release "^15.10.8"

"@naturalcycles/time-lib@^1.0.0":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@naturalcycles/time-lib/-/time-lib-1.0.3.tgz#512f5bd2b2ef405bb7639881b6aeca2a6c22b215"
integrity sha512-MIuSl+IKY+oEQcoNYRXEsvww5uUrh0E7cjMsQxESsrXXxG787GEmrTwlxOElw1f3BtdztL/z7/8FBkkOYZZlgg==
version "1.1.0"
resolved "https://registry.yarnpkg.com/@naturalcycles/time-lib/-/time-lib-1.1.0.tgz#821c049bfbc06b6d512fa3eb373c16aba85fd192"
integrity sha512-14YonE5wvFrQmho/jhIphd96IXRj8O7pPhZ42cS6FNjIZrCQFKVNl5O3PXxLniim84rAoYKrXKl6eKgyO/JV0w==
dependencies:
dayjs "^1.8.14"

@@ -1807,9 +1807,9 @@ copy-descriptor@^0.1.0:
integrity sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=

core-js@^2.4.0, core-js@^2.5.0:
version "2.6.6"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.6.tgz#00eb6d6bf815471cc16d8563edd7d38786dec50b"
integrity sha512-Mt/LaAym54NXnrjEMdo918cT2h70tqb/Yl7T3uPHQHRm5SxVoqlKmerUy4mL11k8saSBDWQ7ULIHxmeFyT3pfg==
version "2.6.8"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.8.tgz#dc3a1e633a04267944e0cb850d3880f340248139"
integrity sha512-RWlREFU74TEkdXzyl1bka66O3kYp8jeTXrvJZDzVVMH8AiHUSOFpL1yfhQJ+wHocAm1m+4971W1PPzfLuCv1vg==

core-util-is@1.0.2, core-util-is@~1.0.0:
version "1.0.2"
@@ -2495,6 +2495,13 @@ find-up@^3.0.0:
dependencies:
locate-path "^3.0.0"

find-up@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/find-up/-/find-up-4.0.0.tgz#c367f8024de92efb75f2d4906536d24682065c3a"
integrity sha512-zoH7ZWPkRdgwYCDVoQTzqjG8JSPANhtvLhh4KVUHyKnaUJJrNeFmWIkTcNuJmR3GLMEmGYEf2S2bjgx26JTF+Q==
dependencies:
locate-path "^5.0.0"

find-versions@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/find-versions/-/find-versions-3.1.0.tgz#10161f29cf3eb4350dec10a29bdde75bff0df32d"
@@ -4284,6 +4291,13 @@ locate-path@^3.0.0:
p-locate "^3.0.0"
path-exists "^3.0.0"

locate-path@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-5.0.0.tgz#1afba396afd676a6d42504d0a67a3a7eb9f62aa0"
integrity sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==
dependencies:
p-locate "^4.1.0"

lock-verify@^2.0.2, lock-verify@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/lock-verify/-/lock-verify-2.1.0.tgz#fff4c918b8db9497af0c5fa7f6d71555de3ceb47"
@@ -4846,9 +4860,9 @@ nan@^2.0.5, nan@^2.12.1:
integrity sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==

nanoid@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-2.0.2.tgz#2163edc84828cd42f9b8e4578979a4b5ffc1bb18"
integrity sha512-X4yQ8VHoFvHcykGunT2Jxrsm1c4vH5UKtau7LLJYXO1istCRE3jD8JxDyGCzN+h7dpWBCvWaSYgloRuphKRqUQ==
version "2.0.3"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-2.0.3.tgz#dde999e173bc9d7bd2ee2746b89909ade98e075e"
integrity sha512-NbaoqdhIYmY6FXDRB4eYtDVC9Z9eCbn8TyaiC16LNKtpPv/aqa0tOPD8y6gNE4yUNnaZ7LLhYtXOev/6+cBtfw==

nanomatch@^1.2.9:
version "1.2.13"
@@ -5483,7 +5497,7 @@ p-locate@^3.0.0:
dependencies:
p-limit "^2.0.0"

p-locate@^4.0.0:
p-locate@^4.0.0, p-locate@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-4.1.0.tgz#a3428bb7088b3a60292f66919278b7c297ad4f07"
integrity sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==
@@ -5708,11 +5722,11 @@ pkg-dir@^3.0.0:
find-up "^3.0.0"

pkg-dir@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-4.1.0.tgz#aaeb91c0d3b9c4f74a44ad849f4de34781ae01de"
integrity sha512-55k9QN4saZ8q518lE6EFgYiu95u3BWkSajCifhdQjvLvmr8IpnRbhI+UGpWJQfa0KzDguHeeWT1ccO1PmkOi3A==
version "4.2.0"
resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-4.2.0.tgz#f099133df7ede422e81d1d8448270eeb3e4261f3"
integrity sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==
dependencies:
find-up "^3.0.0"
find-up "^4.0.0"

please-upgrade-node@^3.0.2, please-upgrade-node@^3.1.1:
version "3.1.1"
@@ -5775,9 +5789,9 @@ promise-retry@^1.1.1:
retry "^0.10.0"

prompts@^2.0.1:
version "2.0.4"
resolved "https://registry.yarnpkg.com/prompts/-/prompts-2.0.4.tgz#179f9d4db3128b9933aa35f93a800d8fce76a682"
integrity sha512-HTzM3UWp/99A0gk51gAegwo1QRYA7xjcZufMNe33rCclFszUYAuHe1fIN/3ZmiHeGPkUsNaRyQm1hHOfM0PKxA==
version "2.1.0"
resolved "https://registry.yarnpkg.com/prompts/-/prompts-2.1.0.tgz#bf90bc71f6065d255ea2bdc0fe6520485c1b45db"
integrity sha512-+x5TozgqYdOwWsQFZizE/Tra3fKvAoy037kOyU6cgz84n8f6zxngLOV4O32kTwt9FcLCxAqw0P/c8rOr9y+Gfg==
dependencies:
kleur "^3.0.2"
sisteransi "^1.0.0"
@@ -6872,9 +6886,9 @@ symbol-tree@^3.2.2:
integrity sha1-rifbOPZgp64uHDt9G8KQgZuFGeY=

synchronous-promise@^2.0.6:
version "2.0.7"
resolved "https://registry.yarnpkg.com/synchronous-promise/-/synchronous-promise-2.0.7.tgz#3574b3d2fae86b145356a4b89103e1577f646fe3"
integrity sha512-16GbgwTmFMYFyQMLvtQjvNWh30dsFe1cAW5Fg1wm5+dg84L9Pe36mftsIRU95/W2YsISxsz/xq4VB23sqpgb/A==
version "2.0.8"
resolved "https://registry.yarnpkg.com/synchronous-promise/-/synchronous-promise-2.0.8.tgz#01fd026fffdbf2d3d39ec06ee1a7c971578136f7"
integrity sha512-xYavZtFC1vKgJu0AOSYdrLeikNCsNwmUeZaV1XF9cMqEhBVVxLq6rEbYzOGrF1MV2MNPkhsJqqiXuQ4a76CEUg==

tar@^2.0.0:
version "2.2.2"
@@ -7128,9 +7142,9 @@ typescript@^3.4.5:
integrity sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw==

uglify-js@^3.1.4:
version "3.5.14"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.5.14.tgz#edf2a322c37fd7173a954fb35af199b52fb10946"
integrity sha512-dgyjIw8KFK6AyVl5vm2tEqPewv5TKGEiiVFLI1LbF+oHua/Njd8tZk3lIbF1AWU1rNdEg7scaceADb4zqCcWXg==
version "3.5.15"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.5.15.tgz#fe2b5378fd0b09e116864041437bff889105ce24"
integrity sha512-fe7aYFotptIddkwcm6YuA0HmknBZ52ZzOsUxZEdhhkSsz7RfjHDX2QDxwKTiv4JQ5t5NhfmpgAK+J7LiDhKSqg==
dependencies:
commander "~2.20.0"
source-map "~0.6.1"

0 comments on commit f33dff4

Please sign in to comment.
You can’t perform that action at this time.