@orioro/util 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/PromiseLikeEventEmitter/index.d.ts +10 -0
- package/dist/array/arrayChunk.d.ts +1 -0
- package/dist/array/index.d.ts +1 -0
- package/dist/debug/debugFn/index.d.ts +15 -0
- package/dist/debug/debugFn/util.d.ts +1 -0
- package/dist/debug/debugFn.d.ts +15 -0
- package/dist/debug/deepFreeze.d.ts +5 -0
- package/dist/debug/index.d.ts +3 -0
- package/dist/debug/wait.d.ts +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.mjs +773 -763
- package/dist/interpolate/index.d.ts +14 -0
- package/dist/maybeFn.d.ts +1 -0
- package/dist/pickPaths/index.d.ts +4 -0
- package/dist/promise/batchFn.d.ts +47 -0
- package/dist/promise/index.d.ts +3 -0
- package/dist/promise/promiseReduce.d.ts +1 -0
- package/dist/promise/resolveNestedPromises.d.ts +14 -0
- package/dist/promise/types.d.ts +2 -0
- package/dist/resolvePaths/index.d.ts +4 -0
- package/dist/switchValue.d.ts +9 -0
- package/dist/typeOf.d.ts +7 -0
- package/dist/validate/async/index.d.ts +18 -0
- package/dist/validate/async/validateAsyncFn.d.ts +2 -0
- package/dist/validate/async/validators/index.d.ts +2 -0
- package/dist/validate/async/validators/logical.d.ts +4 -0
- package/dist/validate/async/validators/shape.d.ts +7 -0
- package/dist/validate/async/validators/tmpand.d.ts +2 -0
- package/dist/validate/async/validators/tmpor.d.ts +2 -0
- package/dist/validate/common/ValidationError.d.ts +11 -0
- package/dist/validate/common/util/defaultErrorMessage.d.ts +2 -0
- package/dist/validate/common/util/index.d.ts +3 -0
- package/dist/validate/common/util/parseValidatorInput.d.ts +5 -0
- package/dist/validate/common/util/resolveValidationResult.d.ts +6 -0
- package/dist/validate/common/validators/index.d.ts +1 -0
- package/dist/validate/common/validators/type.d.ts +9 -0
- package/dist/validate/index.d.ts +3 -0
- package/dist/validate/sync/index.d.ts +18 -0
- package/dist/validate/sync/validateSyncFn.d.ts +2 -0
- package/dist/validate/sync/validators/index.d.ts +2 -0
- package/dist/validate/sync/validators/logical.d.ts +4 -0
- package/dist/validate/sync/validators/shape.d.ts +7 -0
- package/dist/validate/types/async.d.ts +5 -0
- package/dist/validate/types/common.d.ts +27 -0
- package/dist/validate/types/index.d.ts +3 -0
- package/dist/validate/types/sync.d.ts +5 -0
- package/package.json +6 -2
- package/babel.config.cjs +0 -13
- package/coverage/clover.xml +0 -491
- package/coverage/coverage-final.json +0 -29
- package/coverage/lcov-report/ValidationError.ts.html +0 -184
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -296
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov-report/src/debug/deepFreeze.ts.html +0 -157
- package/coverage/lcov-report/src/debug/index.html +0 -146
- package/coverage/lcov-report/src/debug/index.ts.html +0 -91
- package/coverage/lcov-report/src/debug/wait.ts.html +0 -127
- package/coverage/lcov-report/src/index.html +0 -131
- package/coverage/lcov-report/src/interpolate/index.html +0 -116
- package/coverage/lcov-report/src/interpolate/index.ts.html +0 -277
- package/coverage/lcov-report/src/maybeFn.ts.html +0 -94
- package/coverage/lcov-report/src/promise/index.html +0 -146
- package/coverage/lcov-report/src/promise/index.ts.html +0 -91
- package/coverage/lcov-report/src/promise/promiseReduce.ts.html +0 -130
- package/coverage/lcov-report/src/promise/resolveNestedPromises.ts.html +0 -271
- package/coverage/lcov-report/src/switchValue.ts.html +0 -253
- package/coverage/lcov-report/src/typeOf.ts.html +0 -328
- package/coverage/lcov-report/src/validate/ValidationError.ts.html +0 -184
- package/coverage/lcov-report/src/validate/async/index.html +0 -131
- package/coverage/lcov-report/src/validate/async/index.ts.html +0 -241
- package/coverage/lcov-report/src/validate/async/parseValidator.ts.html +0 -136
- package/coverage/lcov-report/src/validate/async/validateAsyncFn.ts.html +0 -208
- package/coverage/lcov-report/src/validate/async/validators/and.ts.html +0 -154
- package/coverage/lcov-report/src/validate/async/validators/index.html +0 -146
- package/coverage/lcov-report/src/validate/async/validators/index.ts.html +0 -91
- package/coverage/lcov-report/src/validate/async/validators/logical.ts.html +0 -253
- package/coverage/lcov-report/src/validate/async/validators/or.ts.html +0 -151
- package/coverage/lcov-report/src/validate/async/validators/shape.ts.html +0 -565
- package/coverage/lcov-report/src/validate/common/ValidationError.ts.html +0 -184
- package/coverage/lcov-report/src/validate/common/index.html +0 -116
- package/coverage/lcov-report/src/validate/common/util/defaultErrorMessage.ts.html +0 -163
- package/coverage/lcov-report/src/validate/common/util/index.html +0 -161
- package/coverage/lcov-report/src/validate/common/util/index.ts.html +0 -94
- package/coverage/lcov-report/src/validate/common/util/parseValidator.ts.html +0 -316
- package/coverage/lcov-report/src/validate/common/util/parseValidatorInput.ts.html +0 -316
- package/coverage/lcov-report/src/validate/common/util/resolveValidationResult.ts.html +0 -277
- package/coverage/lcov-report/src/validate/common/util/validatorParser.ts.html +0 -316
- package/coverage/lcov-report/src/validate/common/validators/index.html +0 -131
- package/coverage/lcov-report/src/validate/common/validators/index.ts.html +0 -88
- package/coverage/lcov-report/src/validate/common/validators/type.ts.html +0 -388
- package/coverage/lcov-report/src/validate/fmtValidationResult.ts.html +0 -268
- package/coverage/lcov-report/src/validate/index.html +0 -116
- package/coverage/lcov-report/src/validate/index.ts.html +0 -94
- package/coverage/lcov-report/src/validate/makeValidate.ts.html +0 -634
- package/coverage/lcov-report/src/validate/specUtil/commonTests.js.html +0 -1324
- package/coverage/lcov-report/src/validate/specUtil/index.html +0 -116
- package/coverage/lcov-report/src/validate/sync/index.html +0 -131
- package/coverage/lcov-report/src/validate/sync/index.ts.html +0 -244
- package/coverage/lcov-report/src/validate/sync/parseValidator.ts.html +0 -136
- package/coverage/lcov-report/src/validate/sync/validateSyncFn.ts.html +0 -223
- package/coverage/lcov-report/src/validate/sync/validators/and.ts.html +0 -148
- package/coverage/lcov-report/src/validate/sync/validators/index.html +0 -146
- package/coverage/lcov-report/src/validate/sync/validators/index.ts.html +0 -91
- package/coverage/lcov-report/src/validate/sync/validators/logical.ts.html +0 -226
- package/coverage/lcov-report/src/validate/sync/validators/or.ts.html +0 -130
- package/coverage/lcov-report/src/validate/sync/validators/shape.ts.html +0 -523
- package/coverage/lcov-report/src/validate/sync/validators/type.ts.html +0 -154
- package/coverage/lcov-report/src/validate/syncValidators/and.ts.html +0 -157
- package/coverage/lcov-report/src/validate/syncValidators/index.html +0 -176
- package/coverage/lcov-report/src/validate/syncValidators/index.ts.html +0 -97
- package/coverage/lcov-report/src/validate/syncValidators/or.ts.html +0 -127
- package/coverage/lcov-report/src/validate/syncValidators/shape.ts.html +0 -559
- package/coverage/lcov-report/src/validate/syncValidators/string.ts.html +0 -163
- package/coverage/lcov-report/src/validate/syncValidators/type.ts.html +0 -154
- package/coverage/lcov-report/src/validate/util/defaultErrorMessage.ts.html +0 -169
- package/coverage/lcov-report/src/validate/util/index.html +0 -146
- package/coverage/lcov-report/src/validate/util/index.ts.html +0 -91
- package/coverage/lcov-report/src/validate/util/resolveValidationResult.ts.html +0 -253
- package/coverage/lcov-report/src/validate/validate.ts.html +0 -220
- package/coverage/lcov-report/src/validate/validateAsync.ts.html +0 -220
- package/coverage/lcov-report/src/validate/validators/and.ts.html +0 -157
- package/coverage/lcov-report/src/validate/validators/index.html +0 -176
- package/coverage/lcov-report/src/validate/validators/index.ts.html +0 -97
- package/coverage/lcov-report/src/validate/validators/or.ts.html +0 -127
- package/coverage/lcov-report/src/validate/validators/shape.ts.html +0 -541
- package/coverage/lcov-report/src/validate/validators/type.ts.html +0 -154
- package/coverage/lcov-report/src/validate_/ValidationError.ts.html +0 -184
- package/coverage/lcov-report/src/validate_/fmtValidationResult.ts.html +0 -268
- package/coverage/lcov-report/src/validate_/index.html +0 -161
- package/coverage/lcov-report/src/validate_/makeValidate.ts.html +0 -634
- package/coverage/lcov-report/src/validate_/validate.ts.html +0 -220
- package/coverage/lcov-report/switchValue.ts.html +0 -253
- package/coverage/lcov-report/typeOf.ts.html +0 -331
- package/coverage/lcov-report/validate.ts.html +0 -757
- package/coverage/lcov.info +0 -1056
- package/jest.config.js +0 -6
- package/rollup.config.mjs +0 -6
- package/src/PromiseLikeEventEmitter/index.ts +0 -35
- package/src/array/arrayChunk.ts +0 -7
- package/src/array/index.ts +0 -1
- package/src/debug/debugFn/index.ts +0 -48
- package/src/debug/debugFn/util.ts +0 -27
- package/src/debug/deepFreeze.ts +0 -26
- package/src/debug/index.ts +0 -3
- package/src/debug/wait.ts +0 -14
- package/src/index.ts +0 -8
- package/src/interpolate/index.spec.ts +0 -20
- package/src/interpolate/index.ts +0 -64
- package/src/maybeFn.ts +0 -3
- package/src/promise/batchFn.spec.ts +0 -92
- package/src/promise/batchFn.ts +0 -176
- package/src/promise/index.ts +0 -3
- package/src/promise/promiseReduce.ts +0 -15
- package/src/promise/resolveNestedPromises.spec.ts +0 -205
- package/src/promise/resolveNestedPromises.ts +0 -83
- package/src/promise/types.ts +0 -2
- package/src/switchValue.spec.ts +0 -30
- package/src/switchValue.ts +0 -59
- package/src/typeOf.spec.ts +0 -47
- package/src/typeOf.ts +0 -81
- package/src/validate/__snapshots__/index.spec.ts.snap +0 -9
- package/src/validate/async/index.spec.ts +0 -236
- package/src/validate/async/index.ts +0 -52
- package/src/validate/async/validateAsyncFn.ts +0 -41
- package/src/validate/async/validators/index.ts +0 -2
- package/src/validate/async/validators/logical.ts +0 -56
- package/src/validate/async/validators/shape.ts +0 -160
- package/src/validate/async/validators/tmpand.ts +0 -24
- package/src/validate/async/validators/tmpor.ts +0 -21
- package/src/validate/common/ValidationError.ts +0 -33
- package/src/validate/common/util/defaultErrorMessage.ts +0 -26
- package/src/validate/common/util/index.ts +0 -3
- package/src/validate/common/util/parseValidatorInput.ts +0 -77
- package/src/validate/common/util/resolveValidationResult.ts +0 -64
- package/src/validate/common/validators/index.ts +0 -1
- package/src/validate/common/validators/type.ts +0 -101
- package/src/validate/index.spec.ts +0 -5
- package/src/validate/index.ts +0 -3
- package/src/validate/specUtil/commonTests.js +0 -413
- package/src/validate/sync/index.spec.ts +0 -81
- package/src/validate/sync/index.ts +0 -53
- package/src/validate/sync/validateSyncFn.ts +0 -46
- package/src/validate/sync/validators/index.ts +0 -2
- package/src/validate/sync/validators/logical.ts +0 -47
- package/src/validate/sync/validators/shape.ts +0 -146
- package/src/validate/types/async.ts +0 -20
- package/src/validate/types/common.ts +0 -70
- package/src/validate/types/index.ts +0 -3
- package/src/validate/types/sync.ts +0 -20
- package/tsconfig.json +0 -11
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @function $stringInterpolate
|
|
3
|
+
* @param {String} template Basic JS template string like `${value.path}` value
|
|
4
|
+
* interpolation. It is possible to access nested properties
|
|
5
|
+
* through dot `.` notation. Keywords between braces are
|
|
6
|
+
* only interpreted as paths to the value. No logic
|
|
7
|
+
* supported: loops, conditionals, etc.
|
|
8
|
+
* @param {Object | Array} data Data context to be used for interpolation
|
|
9
|
+
*/
|
|
10
|
+
export declare function interpolate(template: string, data: {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
} | any[], { maxLength }?: {
|
|
13
|
+
maxLength?: number;
|
|
14
|
+
}): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function maybeFn(input: any, ...args: any[]): any;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { PromiseLikeEventEmitter } from '../PromiseLikeEventEmitter';
|
|
2
|
+
type BatchFnOptions = {
|
|
3
|
+
skip?: (input: any) => Promise<boolean> | boolean;
|
|
4
|
+
batchSize?: number;
|
|
5
|
+
};
|
|
6
|
+
type Batch = {
|
|
7
|
+
index: number;
|
|
8
|
+
items: any[];
|
|
9
|
+
};
|
|
10
|
+
export declare const SKIPPED: unique symbol;
|
|
11
|
+
type EventTypes = {
|
|
12
|
+
batchStart: (data: {
|
|
13
|
+
batch: Batch;
|
|
14
|
+
}) => void;
|
|
15
|
+
batchProgress: (data: {
|
|
16
|
+
batch: Batch;
|
|
17
|
+
progress: number;
|
|
18
|
+
results: any[];
|
|
19
|
+
}) => void;
|
|
20
|
+
itemStart: (data: {
|
|
21
|
+
batch: Batch;
|
|
22
|
+
item: any;
|
|
23
|
+
}) => void;
|
|
24
|
+
itemSkip: (data: {
|
|
25
|
+
batch: Batch;
|
|
26
|
+
item: any;
|
|
27
|
+
}) => void;
|
|
28
|
+
progress: (data: {
|
|
29
|
+
type: 'data' | 'skip' | 'error';
|
|
30
|
+
batch: Batch;
|
|
31
|
+
item: any;
|
|
32
|
+
result: any;
|
|
33
|
+
progress: number;
|
|
34
|
+
}) => void;
|
|
35
|
+
results: (data: {
|
|
36
|
+
results: any[];
|
|
37
|
+
}) => void;
|
|
38
|
+
error: (err: Error) => void;
|
|
39
|
+
};
|
|
40
|
+
export declare function batchFn(fn: (input: any) => Promise<any> | any, { batchSize, skip }?: BatchFnOptions): (items: any[]) => PromiseLikeEventEmitter<any[], EventTypes>;
|
|
41
|
+
type ParsedBatchResults = {
|
|
42
|
+
results: any[];
|
|
43
|
+
errors: Error[];
|
|
44
|
+
skipped: any[];
|
|
45
|
+
};
|
|
46
|
+
export declare function parseBatchedResults(inputs: any, results: any[]): ParsedBatchResults;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function promiseReduce<ItemType = any, AccType = any>(inputArr: ItemType[], reducerFn: (acc: AccType, input: ItemType, index: number) => AccType | Promise<AccType>, initial: AccType): Promise<AccType>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AnyArray, AnyObject } from './types';
|
|
2
|
+
type ResolveCtx = {
|
|
3
|
+
root: AnyArray | AnyObject;
|
|
4
|
+
depth: number;
|
|
5
|
+
};
|
|
6
|
+
type ResolveOptions = {
|
|
7
|
+
mode: 'eager' | 'lazy';
|
|
8
|
+
maxDepth: number;
|
|
9
|
+
clone: false | (<T = {
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
} | any[]>(obj: T) => T);
|
|
12
|
+
};
|
|
13
|
+
export declare function resolveNestedPromises(node: AnyArray | AnyObject, options?: Partial<ResolveOptions>, ctx?: ResolveCtx): Promise<AnyArray | AnyObject>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type Criteria = string | symbol | RegExp | ((input: any) => boolean);
|
|
2
|
+
type ObjectSwitchCases<ValueType = any> = {
|
|
3
|
+
[key: string | symbol]: ValueType;
|
|
4
|
+
};
|
|
5
|
+
type TupleSwitchCases<ValueType = any> = ([Criteria, ValueType] | [ValueType])[];
|
|
6
|
+
export type SwitchCases<ValueType = any> = ObjectSwitchCases<ValueType> | TupleSwitchCases<ValueType>;
|
|
7
|
+
export declare function switchValue<ValueType = any>(input: any, cases: SwitchCases): ValueType | undefined;
|
|
8
|
+
export declare function switchExec<ArgsType extends any[] = any[]>(input: any, cases: SwitchCases<(...args: any[]) => any>, ...args: ArgsType): any;
|
|
9
|
+
export {};
|
package/dist/typeOf.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type TypeTest = (value: any) => boolean;
|
|
2
|
+
type TypeMap = Record<string, TypeTest>;
|
|
3
|
+
export declare function typeMap<T extends TypeMap>(typeMap: T): T;
|
|
4
|
+
export declare function makeTypeOf<T extends TypeMap>(typeMap: T): (value: any) => keyof T | null;
|
|
5
|
+
export type DEFAULT_TYPE_NAMES = 'null' | 'undefined' | 'boolean' | 'number' | 'bigint' | 'string' | 'symbol' | 'function' | 'object' | 'array' | 'regexp' | 'nan' | 'date' | 'map' | 'weakmap' | 'set' | 'weakset' | 'promise' | 'error';
|
|
6
|
+
export declare const typeOf: (value: any) => "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "map" | "error" | "null" | "array" | "regexp" | "nan" | "date" | "weakmap" | "set" | "weakset" | "promise" | null;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as common from '../common/validators';
|
|
2
|
+
import * as asyncValidators from './validators';
|
|
3
|
+
import { DetailedInvalid, AsyncValidatorSystem, Valid } from '../types';
|
|
4
|
+
declare function assertValidAsync<InputT = any>(validator: AsyncValidatorSystem['ValidatorInput'], input: InputT): Promise<InputT>;
|
|
5
|
+
interface ValidateAsync {
|
|
6
|
+
(validatorInput: AsyncValidatorSystem['ValidatorInput'], input: any): Promise<Valid | DetailedInvalid>;
|
|
7
|
+
type: typeof common.typeValidator;
|
|
8
|
+
obj: typeof asyncValidators.obj;
|
|
9
|
+
objOf: typeof asyncValidators.objOf;
|
|
10
|
+
tuple: typeof asyncValidators.tuple;
|
|
11
|
+
arrayOf: typeof asyncValidators.arrayOf;
|
|
12
|
+
and: typeof asyncValidators.and;
|
|
13
|
+
or: typeof asyncValidators.or;
|
|
14
|
+
not: typeof asyncValidators.not;
|
|
15
|
+
assertValid: typeof assertValidAsync;
|
|
16
|
+
}
|
|
17
|
+
export declare const validateAsync: ValidateAsync;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { AsyncValidatorSystem } from '../../types';
|
|
2
|
+
export declare function and(validators: AsyncValidatorSystem['ValidatorInput'][]): AsyncValidatorSystem['ValidatorFn'];
|
|
3
|
+
export declare function or(validators: AsyncValidatorSystem['ValidatorInput'][]): AsyncValidatorSystem['ValidatorFn'];
|
|
4
|
+
export declare function not(validator: AsyncValidatorSystem['ValidatorInput']): AsyncValidatorSystem['ValidatorFn'];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AsyncValidatorSystem } from '../../types';
|
|
2
|
+
export declare function obj(objShape: {
|
|
3
|
+
[key: string]: AsyncValidatorSystem['ValidatorInput'];
|
|
4
|
+
}): AsyncValidatorSystem['ValidatorFn'];
|
|
5
|
+
export declare function objOf(ofType: AsyncValidatorSystem['ValidatorInput']): AsyncValidatorSystem['ValidatorFn'];
|
|
6
|
+
export declare function tuple(tupleShape: AsyncValidatorSystem['ValidatorInput'][]): AsyncValidatorSystem['ValidatorFn'];
|
|
7
|
+
export declare function arrayOf(ofType: AsyncValidatorSystem['ValidatorInput']): AsyncValidatorSystem['ValidatorFn'];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DetailedInvalid } from '../types';
|
|
2
|
+
export declare class ValidationError extends Error {
|
|
3
|
+
input: any;
|
|
4
|
+
code?: string;
|
|
5
|
+
error?: Error;
|
|
6
|
+
path?: string;
|
|
7
|
+
nestedErrors?: DetailedInvalid[];
|
|
8
|
+
name: string;
|
|
9
|
+
constructor({ message, ...details }: DetailedInvalid);
|
|
10
|
+
toJSON(): DetailedInvalid;
|
|
11
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DetailedInvalid, Valid, ValidatorErrorMessageFn, ValidatorResult } from '../../types';
|
|
2
|
+
export declare function resolveValidationResult({ input, result, errorMessage, }: {
|
|
3
|
+
input: any;
|
|
4
|
+
result: ValidatorResult;
|
|
5
|
+
errorMessage: ValidatorErrorMessageFn;
|
|
6
|
+
}): Valid | DetailedInvalid;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './type';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DEFAULT_TYPE_NAMES } from '../../../typeOf';
|
|
2
|
+
import { CommonValidatorFn } from '../../types';
|
|
3
|
+
type ParsedExpectedType = {
|
|
4
|
+
type: DEFAULT_TYPE_NAMES;
|
|
5
|
+
required: boolean;
|
|
6
|
+
};
|
|
7
|
+
type ExpectedTypesInput = (string | ParsedExpectedType)[] | string | ParsedExpectedType;
|
|
8
|
+
export declare function typeValidator(expectedTypesInput: ExpectedTypesInput): CommonValidatorFn;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as common from '../common/validators';
|
|
2
|
+
import * as sync from './validators';
|
|
3
|
+
import { DetailedInvalid, SyncValidatorSystem, Valid } from '../types';
|
|
4
|
+
declare function assertValidSync<InputT = any>(validator: SyncValidatorSystem['ValidatorInput'], input: InputT): InputT;
|
|
5
|
+
interface Validate {
|
|
6
|
+
(validatorInput: SyncValidatorSystem['ValidatorInput'], input: any): Valid | DetailedInvalid;
|
|
7
|
+
type: typeof common.typeValidator;
|
|
8
|
+
obj: typeof sync.obj;
|
|
9
|
+
objOf: typeof sync.objOf;
|
|
10
|
+
tuple: typeof sync.tuple;
|
|
11
|
+
arrayOf: typeof sync.arrayOf;
|
|
12
|
+
and: typeof sync.and;
|
|
13
|
+
or: typeof sync.or;
|
|
14
|
+
not: typeof sync.not;
|
|
15
|
+
assertValid: typeof assertValidSync;
|
|
16
|
+
}
|
|
17
|
+
export declare const validate: Validate;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SyncValidatorSystem } from '../../types';
|
|
2
|
+
export declare function and(validators: SyncValidatorSystem['ValidatorInput'][]): SyncValidatorSystem['ValidatorFn'];
|
|
3
|
+
export declare function or(validators: SyncValidatorSystem['ValidatorInput'][]): SyncValidatorSystem['ValidatorFn'];
|
|
4
|
+
export declare function not(validator: SyncValidatorSystem['ValidatorInput']): SyncValidatorSystem['ValidatorFn'];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SyncValidatorSystem } from '../../types';
|
|
2
|
+
export declare function obj(objShape: {
|
|
3
|
+
[key: string]: SyncValidatorSystem['ValidatorInput'];
|
|
4
|
+
}): SyncValidatorSystem['ValidatorFn'];
|
|
5
|
+
export declare function objOf(ofType: SyncValidatorSystem['ValidatorInput']): SyncValidatorSystem['ValidatorFn'];
|
|
6
|
+
export declare function tuple(tupleShape: SyncValidatorSystem['ValidatorInput'][]): SyncValidatorSystem['ValidatorFn'];
|
|
7
|
+
export declare function arrayOf(ofType: SyncValidatorSystem['ValidatorInput']): SyncValidatorSystem['ValidatorFn'];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { DetailedInvalid, Valid, ValidatorResult, ValidatorSystem } from './common';
|
|
2
|
+
export type AsyncValidatorSystem = ValidatorSystem<(input: any, context: {
|
|
3
|
+
validateAsync: AsyncValidateFn;
|
|
4
|
+
}) => ValidatorResult | Promise<ValidatorResult>>;
|
|
5
|
+
export type AsyncValidateFn = (validatorInput: AsyncValidatorSystem['ValidatorInput'], input: any) => Promise<Valid | DetailedInvalid>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type Valid = true;
|
|
2
|
+
export type SimpleInvalid = false | undefined | null;
|
|
3
|
+
export type ErrorMessageInvalid = string;
|
|
4
|
+
export type ErrorInvalid = Error;
|
|
5
|
+
export type DetailedInvalid = {
|
|
6
|
+
input: any;
|
|
7
|
+
message?: string;
|
|
8
|
+
code?: string;
|
|
9
|
+
error?: Error;
|
|
10
|
+
path?: string;
|
|
11
|
+
nestedErrors?: DetailedInvalid[];
|
|
12
|
+
expectedTypes?: string;
|
|
13
|
+
};
|
|
14
|
+
export type ValidatorResult = Valid | SimpleInvalid | ErrorMessageInvalid | ErrorInvalid | DetailedInvalid;
|
|
15
|
+
export type ValidatorErrorMessageFn = (props: DetailedInvalid) => string;
|
|
16
|
+
export type ValidatorErrorMessageInput = string | ValidatorErrorMessageFn;
|
|
17
|
+
export type CommonValidatorFn = (input: any) => ValidatorResult;
|
|
18
|
+
type _ValidatorFnInput<ValidatorFn> = string | {
|
|
19
|
+
[key: string]: _ValidatorFnInput<ValidatorFn> | [_ValidatorFnInput<ValidatorFn>, ValidatorErrorMessageInput];
|
|
20
|
+
} | ValidatorFn;
|
|
21
|
+
export type ValidatorSystem<ValidatorFn> = {
|
|
22
|
+
ValidatorFn: ValidatorFn;
|
|
23
|
+
ValidatorFnInput: _ValidatorFnInput<ValidatorFn>;
|
|
24
|
+
Validator: [ValidatorFn, ValidatorErrorMessageFn];
|
|
25
|
+
ValidatorInput: _ValidatorFnInput<ValidatorFn> | [_ValidatorFnInput<ValidatorFn>, ValidatorErrorMessageInput];
|
|
26
|
+
};
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { DetailedInvalid, Valid, ValidatorResult, ValidatorSystem } from './common';
|
|
2
|
+
export type SyncValidatorSystem = ValidatorSystem<(input: any, context: {
|
|
3
|
+
validateSync: SyncValidateFn;
|
|
4
|
+
}) => ValidatorResult>;
|
|
5
|
+
export type SyncValidateFn = (validatorInput: SyncValidatorSystem['ValidatorInput'], input: any) => Valid | DetailedInvalid;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orioro/util",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"packageManager": "yarn@4.0.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
".": "./dist/index.mjs",
|
|
10
10
|
"./*": "./dist/*"
|
|
11
11
|
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
12
15
|
"publishConfig": {
|
|
13
16
|
"access": "public"
|
|
14
17
|
},
|
|
@@ -17,7 +20,8 @@
|
|
|
17
20
|
"build:watch": "rollup --config ./rollup.config.mjs --watch",
|
|
18
21
|
"build": "rollup --config ./rollup.config.mjs",
|
|
19
22
|
"test": "jest",
|
|
20
|
-
"dev": "jest --watch"
|
|
23
|
+
"dev": "jest --watch",
|
|
24
|
+
"prepublish": "yarn build"
|
|
21
25
|
},
|
|
22
26
|
"devDependencies": {
|
|
23
27
|
"@orioro/dev": "0.0.0",
|
package/babel.config.cjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// TODO: keep track of babel + jest support for esm and update
|
|
3
|
-
// accordingly
|
|
4
|
-
// https://stackoverflow.com/questions/61146112/error-while-loading-config-you-appear-to-be-using-a-native-ecmascript-module-c
|
|
5
|
-
//
|
|
6
|
-
// import { BABEL_PRESET } from '@orioro/dev/ts'
|
|
7
|
-
|
|
8
|
-
// export default BABEL_PRESET
|
|
9
|
-
|
|
10
|
-
module.exports = {
|
|
11
|
-
presets: ['@babel/preset-env', '@babel/preset-typescript'],
|
|
12
|
-
exclude: 'node_modules/**',
|
|
13
|
-
}
|