@naturalcycles/nodejs-lib
Advanced tools
Comparing version 6.0.0 to 6.1.0
@@ -0,1 +1,9 @@ | ||
# [6.1.0](https://github.com/NaturalCycles/nodejs-lib/compare/v6.0.0...v6.1.0) (2019-05-18) | ||
### Features | ||
* joi typings with IN and OUT types ([8ab6ccf](https://github.com/NaturalCycles/nodejs-lib/commit/8ab6ccf)) | ||
* stringId(), hashUtil (md5, ...) ([8110084](https://github.com/NaturalCycles/nodejs-lib/commit/8110084)) | ||
# [6.0.0](https://github.com/NaturalCycles/nodejs-lib/compare/v5.3.0...v6.0.0) (2019-05-18) | ||
@@ -2,0 +10,0 @@ |
import { processSharedUtil } from './infra/process.shared.util'; | ||
import { base64ToBuffer, base64ToString, bufferToBase64, hash, md5, stringToBase64 } from './security/hash.util'; | ||
import { stringId } from './security/id.util'; | ||
import { requireEnvKeys } from './util/env.util'; | ||
@@ -9,2 +11,2 @@ import { LRUMemoCache } from './util/lruMemoCache'; | ||
import { getValidationResult, JoiValidationResult, validate } from './validation/joi/joi.validation.util'; | ||
export { JoiValidationError, JoiValidationResult, validate, getValidationResult, Joi, ExtendedJoi, booleanSchema, stringSchema, numberSchema, integerSchema, dateStringSchema, arraySchema, binarySchema, objectSchema, anySchema, anyObjectSchema, idSchema, unixTimestampSchema, verSchema, emailSchema, SEM_VER_PATTERN, semVerSchema, userAgentSchema, utcOffsetSchema, ipAddressSchema, processSharedUtil, zipBuffer, unzipBuffer, zipString, unzipToString, requireEnvKeys, LRUMemoCache, }; | ||
export { JoiValidationError, JoiValidationResult, validate, getValidationResult, Joi, ExtendedJoi, booleanSchema, stringSchema, numberSchema, integerSchema, dateStringSchema, arraySchema, binarySchema, objectSchema, anySchema, anyObjectSchema, idSchema, unixTimestampSchema, verSchema, emailSchema, SEM_VER_PATTERN, semVerSchema, userAgentSchema, utcOffsetSchema, ipAddressSchema, processSharedUtil, zipBuffer, unzipBuffer, zipString, unzipToString, requireEnvKeys, LRUMemoCache, stringId, md5, hash, stringToBase64, base64ToString, bufferToBase64, base64ToBuffer, }; |
@@ -5,2 +5,11 @@ "use strict"; | ||
exports.processSharedUtil = process_shared_util_1.processSharedUtil; | ||
const hash_util_1 = require("./security/hash.util"); | ||
exports.base64ToBuffer = hash_util_1.base64ToBuffer; | ||
exports.base64ToString = hash_util_1.base64ToString; | ||
exports.bufferToBase64 = hash_util_1.bufferToBase64; | ||
exports.hash = hash_util_1.hash; | ||
exports.md5 = hash_util_1.md5; | ||
exports.stringToBase64 = hash_util_1.stringToBase64; | ||
const id_util_1 = require("./security/id.util"); | ||
exports.stringId = id_util_1.stringId; | ||
const env_util_1 = require("./util/env.util"); | ||
@@ -7,0 +16,0 @@ exports.requireEnvKeys = env_util_1.requireEnvKeys; |
/// <reference types="node" /> | ||
import { AlternativesSchema, AnySchema, ArraySchema, BinarySchema, BooleanSchema, DateSchema, FunctionSchema, LazySchema, NumberSchema, ObjectSchema, StringSchema } from '@hapi/joi'; | ||
export declare type SchemaTyped<T> = AnySchemaT<T> | ArraySchemaTyped<T> | AlternativesSchemaTyped<T> | BinarySchemaTyped | BooleanSchemaTyped | DateSchemaTyped<T> | FunctionSchemaTyped<T> | NumberSchemaTyped | ObjectSchemaTyped<T> | StringSchemaTyped | LazySchemaTyped<T>; | ||
export interface AnySchemaT<T> extends AnySchema { | ||
export declare type SchemaTyped<IN, OUT = IN> = AnySchemaT<IN, OUT> | ArraySchemaTyped<IN> | AlternativesSchemaTyped<IN> | BinarySchemaTyped | BooleanSchemaTyped | DateSchemaTyped<IN> | FunctionSchemaTyped<IN> | NumberSchemaTyped | ObjectSchemaTyped<IN, OUT> | StringSchemaTyped | LazySchemaTyped<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 { | ||
} | ||
@@ -20,3 +24,3 @@ export interface ArraySchemaTyped<T> extends ArraySchema, AnySchemaT<T[]> { | ||
} | ||
export interface ObjectSchemaTyped<T> extends ObjectSchema, AnySchemaT<T> { | ||
export interface ObjectSchemaTyped<IN, OUT> extends ObjectSchema, AnySchemaT<IN, OUT> { | ||
} | ||
@@ -23,0 +27,0 @@ export interface StringSchemaTyped extends StringSchema, AnySchemaT<string> { |
@@ -8,6 +8,6 @@ import { AnySchemaT, ArraySchemaTyped, BooleanSchemaTyped, ObjectSchemaTyped } from './joi.model'; | ||
export declare const binarySchema: import("@hapi/joi").BinarySchema; | ||
export declare function arraySchema<T>(items?: AnySchemaT<T>): ArraySchemaTyped<T>; | ||
export declare function objectSchema<T>(schema?: { | ||
[key in keyof T]: AnySchemaT<T[key]>; | ||
}): ObjectSchemaTyped<T>; | ||
export declare function arraySchema<T>(items?: AnySchemaT<T, T>): ArraySchemaTyped<T>; | ||
export declare function objectSchema<IN, OUT = IN>(schema?: { | ||
[key in keyof IN]: AnySchemaT<IN[key]>; | ||
}): ObjectSchemaTyped<IN, OUT>; | ||
export declare const anySchema: import("@hapi/joi").AnySchema; | ||
@@ -14,0 +14,0 @@ export declare const anyObjectSchema: import("@hapi/joi").ObjectSchema; |
@@ -15,3 +15,3 @@ import { ValidationOptions } from '@hapi/joi'; | ||
*/ | ||
export declare function validate<T>(value: T, schema?: AnySchemaT<T>, objectName?: string, options?: ValidationOptions): T; | ||
export declare function validate<IN, OUT = IN>(value: IN, schema?: AnySchemaT<IN, OUT>, objectName?: string, options?: ValidationOptions): OUT; | ||
/** | ||
@@ -24,2 +24,2 @@ * Validates with Joi. | ||
*/ | ||
export declare function getValidationResult<T>(value: T, schema?: AnySchemaT<T>, objectName?: string, options?: ValidationOptions): JoiValidationResult<T>; | ||
export declare function getValidationResult<IN, OUT = IN>(value: IN, schema?: AnySchemaT<IN, OUT>, objectName?: string, options?: ValidationOptions): JoiValidationResult<OUT>; |
{ | ||
"name": "@naturalcycles/nodejs-lib", | ||
"version": "6.0.0", | ||
"version": "6.1.0", | ||
"dependencies": { | ||
@@ -9,3 +9,4 @@ "@naturalcycles/js-lib": "^6.0.0", | ||
"lru-cache": "^5.1.1", | ||
"luxon": "^1.13.2" | ||
"luxon": "^1.13.2", | ||
"nanoid": "^2.0.2" | ||
}, | ||
@@ -12,0 +13,0 @@ "peerDependencies": { |
import { processSharedUtil } from './infra/process.shared.util' | ||
import { | ||
base64ToBuffer, | ||
base64ToString, | ||
bufferToBase64, | ||
hash, | ||
md5, | ||
stringToBase64, | ||
} from './security/hash.util' | ||
import { stringId } from './security/id.util' | ||
import { requireEnvKeys } from './util/env.util' | ||
@@ -71,2 +80,9 @@ import { LRUMemoCache } from './util/lruMemoCache' | ||
LRUMemoCache, | ||
stringId, | ||
md5, | ||
hash, | ||
stringToBase64, | ||
base64ToString, | ||
bufferToBase64, | ||
base64ToBuffer, | ||
} |
@@ -15,16 +15,20 @@ import { | ||
export type SchemaTyped<T> = | ||
| AnySchemaT<T> | ||
| ArraySchemaTyped<T> | ||
| AlternativesSchemaTyped<T> | ||
export type SchemaTyped<IN, OUT = IN> = | ||
| AnySchemaT<IN, OUT> | ||
| ArraySchemaTyped<IN> | ||
| AlternativesSchemaTyped<IN> | ||
| BinarySchemaTyped | ||
| BooleanSchemaTyped | ||
| DateSchemaTyped<T> | ||
| FunctionSchemaTyped<T> | ||
| DateSchemaTyped<IN> | ||
| FunctionSchemaTyped<IN> | ||
| NumberSchemaTyped | ||
| ObjectSchemaTyped<T> | ||
| ObjectSchemaTyped<IN, OUT> | ||
| StringSchemaTyped | ||
| LazySchemaTyped<T> | ||
| LazySchemaTyped<IN> | ||
export interface AnySchemaT<T> extends AnySchema {} | ||
/** | ||
* 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 {} | ||
@@ -38,4 +42,4 @@ export interface ArraySchemaTyped<T> extends ArraySchema, AnySchemaT<T[]> {} | ||
export interface NumberSchemaTyped extends NumberSchema, AnySchemaT<number> {} | ||
export interface ObjectSchemaTyped<T> extends ObjectSchema, AnySchemaT<T> {} | ||
export interface ObjectSchemaTyped<IN, OUT> extends ObjectSchema, AnySchemaT<IN, OUT> {} | ||
export interface StringSchemaTyped extends StringSchema, AnySchemaT<string> {} | ||
export interface LazySchemaTyped<T> extends LazySchema {} |
@@ -12,9 +12,9 @@ import { Joi } from './joi.extensions' | ||
export function arraySchema<T> (items?: AnySchemaT<T>): ArraySchemaTyped<T> { | ||
export function arraySchema<T> (items?: AnySchemaT<T, T>): ArraySchemaTyped<T> { | ||
return items ? Joi.array().items(items) : Joi.array() | ||
} | ||
export function objectSchema<T> ( | ||
schema?: { [key in keyof T]: AnySchemaT<T[key]> }, | ||
): ObjectSchemaTyped<T> { | ||
export function objectSchema<IN, OUT = IN> ( | ||
schema?: { [key in keyof IN]: AnySchemaT<IN[key]> }, | ||
): ObjectSchemaTyped<IN, OUT> { | ||
return Joi.object(schema) | ||
@@ -21,0 +21,0 @@ } |
@@ -44,9 +44,14 @@ /* | ||
*/ | ||
export function validate<T> ( | ||
value: T, | ||
schema?: AnySchemaT<T>, | ||
export function validate<IN, OUT = IN> ( | ||
value: IN, | ||
schema?: AnySchemaT<IN, OUT>, | ||
objectName?: string, | ||
options: ValidationOptions = {}, | ||
): T { | ||
const { value: returnValue, error } = getValidationResult(value, schema, objectName, options) | ||
): OUT { | ||
const { value: returnValue, error } = getValidationResult<IN, OUT>( | ||
value, | ||
schema, | ||
objectName, | ||
options, | ||
) | ||
@@ -67,9 +72,9 @@ if (error) { | ||
*/ | ||
export function getValidationResult<T> ( | ||
value: T, | ||
schema?: AnySchemaT<T>, | ||
export function getValidationResult<IN, OUT = IN> ( | ||
value: IN, | ||
schema?: AnySchemaT<IN, OUT>, | ||
objectName?: string, | ||
options: ValidationOptions = {}, | ||
): JoiValidationResult<T> { | ||
if (!schema) return { value } | ||
): JoiValidationResult<OUT> { | ||
if (!schema) return { value } as any | ||
@@ -81,4 +86,4 @@ const { value: returnValue, error } = Joi.validate(value, schema, { | ||
const vr: JoiValidationResult<T> = { | ||
value: returnValue, | ||
const vr: JoiValidationResult<OUT> = { | ||
value: (returnValue as any) as OUT, | ||
} | ||
@@ -85,0 +90,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
75589
63
1442
7
+ Addednanoid@^2.0.2
+ Addednanoid@2.1.11(transitive)