@orioro/util 0.13.0 → 0.14.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/CHANGELOG.md +18 -0
- package/dist/index.js +6 -2
- package/dist/index.mjs +6 -2
- package/dist/strExpr/syntheticJson.d.ts +1 -1
- package/package.json +1 -1
- package/dist/array/join.d.ts +0 -9
- package/dist/debug/debugFn.d.ts +0 -15
- package/dist/normalizeString/index.d.ts +0 -1
- package/dist/pathResolve/index.d.ts +0 -7
- package/dist/resolvePaths/index.d.ts +0 -4
- package/dist/strAutoCast/index.d.ts +0 -1
- package/dist/strAutoCast/strAutoCast.d.ts +0 -1
- package/dist/validate/async/index.d.ts +0 -18
- package/dist/validate/async/validateAsyncFn.d.ts +0 -2
- package/dist/validate/async/validators/index.d.ts +0 -2
- package/dist/validate/async/validators/logical.d.ts +0 -4
- package/dist/validate/async/validators/shape.d.ts +0 -7
- package/dist/validate/async/validators/tmpand.d.ts +0 -2
- package/dist/validate/async/validators/tmpor.d.ts +0 -2
- package/dist/validate/common/ValidationError.d.ts +0 -11
- package/dist/validate/common/util/defaultErrorMessage.d.ts +0 -2
- package/dist/validate/common/util/index.d.ts +0 -3
- package/dist/validate/common/util/parseValidatorInput.d.ts +0 -5
- package/dist/validate/common/util/resolveValidationResult.d.ts +0 -6
- package/dist/validate/common/validators/index.d.ts +0 -1
- package/dist/validate/common/validators/type.d.ts +0 -9
- package/dist/validate/index.d.ts +0 -3
- package/dist/validate/sync/index.d.ts +0 -18
- package/dist/validate/sync/validateSyncFn.d.ts +0 -2
- package/dist/validate/sync/validators/index.d.ts +0 -2
- package/dist/validate/sync/validators/logical.d.ts +0 -4
- package/dist/validate/sync/validators/shape.d.ts +0 -7
- package/dist/validate/types/async.d.ts +0 -5
- package/dist/validate/types/common.d.ts +0 -27
- package/dist/validate/types/index.d.ts +0 -3
- package/dist/validate/types/sync.d.ts +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @orioro/util
|
|
2
2
|
|
|
3
|
+
## 0.14.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- syntheticJson fallback to full json in case of error
|
|
8
|
+
|
|
9
|
+
## 0.13.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- undo export update
|
|
14
|
+
|
|
15
|
+
## 0.13.1
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- fix exports to support import (mjs) and require (js)
|
|
20
|
+
|
|
3
21
|
## 0.13.0
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
package/dist/index.js
CHANGED
|
@@ -1491,8 +1491,12 @@ function syntheticJson(str) {
|
|
|
1491
1491
|
// Step 3: Parse as JSON
|
|
1492
1492
|
try {
|
|
1493
1493
|
return JSON.parse(normalized);
|
|
1494
|
-
} catch (
|
|
1495
|
-
|
|
1494
|
+
} catch (err1) {
|
|
1495
|
+
try {
|
|
1496
|
+
return JSON.parse(str);
|
|
1497
|
+
} catch (err2) {
|
|
1498
|
+
throw new Error("Invalid synthetic JSON: ".concat(str));
|
|
1499
|
+
}
|
|
1496
1500
|
}
|
|
1497
1501
|
}
|
|
1498
1502
|
|
package/dist/index.mjs
CHANGED
|
@@ -1489,8 +1489,12 @@ function syntheticJson(str) {
|
|
|
1489
1489
|
// Step 3: Parse as JSON
|
|
1490
1490
|
try {
|
|
1491
1491
|
return JSON.parse(normalized);
|
|
1492
|
-
} catch (
|
|
1493
|
-
|
|
1492
|
+
} catch (err1) {
|
|
1493
|
+
try {
|
|
1494
|
+
return JSON.parse(str);
|
|
1495
|
+
} catch (err2) {
|
|
1496
|
+
throw new Error("Invalid synthetic JSON: ".concat(str));
|
|
1497
|
+
}
|
|
1494
1498
|
}
|
|
1495
1499
|
}
|
|
1496
1500
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function syntheticJson(str: string, maxLength?: number):
|
|
1
|
+
export declare function syntheticJson<T = unknown>(str: string, maxLength?: number): T;
|
package/package.json
CHANGED
package/dist/array/join.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
type Entry = Record<string, any>;
|
|
2
|
-
type Dataset = Entry[];
|
|
3
|
-
type OnKey = string;
|
|
4
|
-
type DatasetInput = Dataset | [OnKey, Dataset, string?];
|
|
5
|
-
export declare function join(datasets: DatasetInput[], { key: defaultOnKey, mode, }?: {
|
|
6
|
-
key?: string;
|
|
7
|
-
mode?: 'left' | 'inner';
|
|
8
|
-
}): Entry[];
|
|
9
|
-
export {};
|
package/dist/debug/debugFn.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Merge } from 'type-fest';
|
|
2
|
-
type AnyFn = (...args: any[]) => any;
|
|
3
|
-
export type FnCallLog<FnType extends AnyFn = AnyFn> = {
|
|
4
|
-
type: 'call';
|
|
5
|
-
callId: string;
|
|
6
|
-
fnName: string;
|
|
7
|
-
args: Parameters<FnType>;
|
|
8
|
-
};
|
|
9
|
-
export type FnResultLog<FnType extends AnyFn = AnyFn> = Merge<FnCallLog<FnType>, {
|
|
10
|
-
type: 'result';
|
|
11
|
-
result: ReturnType<FnType>;
|
|
12
|
-
}>;
|
|
13
|
-
export type FnDebugLog<FnType extends AnyFn = AnyFn> = FnCallLog<FnType> | FnResultLog<FnType>;
|
|
14
|
-
export declare function debugFn<FnType extends AnyFn = AnyFn>(fnName: string, fn: FnType, logCall?: (log: FnCallLog<FnType>) => void, logResult?: (log: FnResultLog<FnType>) => void): (...args: Parameters<FnType>) => ReturnType<FnType>;
|
|
15
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function normalizeString(str: string): string;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './strAutoCast';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function strAutoCast(str: string): string | boolean | number | JSON | null | undefined;
|
|
@@ -1,18 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,4 +0,0 @@
|
|
|
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'];
|
|
@@ -1,7 +0,0 @@
|
|
|
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'];
|
|
@@ -1,11 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './type';
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { TypeOfType } from '../../../typeOf';
|
|
2
|
-
import { CommonValidatorFn } from '../../types';
|
|
3
|
-
type ParsedExpectedType = {
|
|
4
|
-
type: TypeOfType;
|
|
5
|
-
required: boolean;
|
|
6
|
-
};
|
|
7
|
-
type ExpectedTypesInput = (string | ParsedExpectedType)[] | string | ParsedExpectedType;
|
|
8
|
-
export declare function typeValidator(expectedTypesInput: ExpectedTypesInput): CommonValidatorFn;
|
|
9
|
-
export {};
|
package/dist/validate/index.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,4 +0,0 @@
|
|
|
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'];
|
|
@@ -1,7 +0,0 @@
|
|
|
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'];
|
|
@@ -1,5 +0,0 @@
|
|
|
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>;
|
|
@@ -1,27 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,5 +0,0 @@
|
|
|
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;
|