@nu-art/ts-common 0.203.44 → 0.203.46
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/core/exceptions/http-codes.d.ts +3 -0
- package/core/exceptions/http-codes.js +1 -0
- package/core/exceptions/types.d.ts +1 -1
- package/core/module-manager.d.ts +12 -12
- package/db/dependencies-test.d.ts +5 -0
- package/db/dependencies-test.js +6 -0
- package/db/types.d.ts +24 -11
- package/package.json +1 -1
- package/tools/Replacer.js +1 -2
- package/utils/array-tools.d.ts +11 -11
- package/utils/object-tools.d.ts +2 -2
- package/utils/tools.d.ts +4 -4
- package/utils/tools.js +3 -1
- package/utils/types.d.ts +10 -7
- package/validator/type-validators.d.ts +8 -8
- package/validator/validator-core.d.ts +9 -10
- package/validator/validator-core.js +4 -5
|
@@ -123,6 +123,9 @@ export declare const HttpCodes: {
|
|
|
123
123
|
readonly ENTITY_IS_OUTDATED: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
|
|
124
124
|
code: number;
|
|
125
125
|
};
|
|
126
|
+
readonly INTERNAL_MISMATCH: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
|
|
127
|
+
code: number;
|
|
128
|
+
};
|
|
126
129
|
readonly OPERATION_FAILED: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
|
|
127
130
|
code: number;
|
|
128
131
|
};
|
package/core/module-manager.d.ts
CHANGED
|
@@ -5,23 +5,23 @@ import { Module } from './module';
|
|
|
5
5
|
import { Logger } from './logger/Logger';
|
|
6
6
|
export declare function moduleResolver(): Module<any, any, import("..").Validator<any> | import("..").TypeValidator<any>>[];
|
|
7
7
|
export declare const RuntimeModules: () => {
|
|
8
|
-
filter: <T
|
|
9
|
-
find: <T_1
|
|
10
|
-
some: <T_2
|
|
11
|
-
map: <T_3
|
|
12
|
-
forEach: <T_4
|
|
13
|
-
includes: <T_5
|
|
8
|
+
filter: <T>(filter: (item: T, index: number, array: T[]) => boolean) => T[];
|
|
9
|
+
find: <T_1>(filter: (item: T_1, index: number, array: T_1[]) => boolean) => T_1;
|
|
10
|
+
some: <T_2>(filter: (item: T_2, index: number, array: T_2[]) => boolean) => T_2;
|
|
11
|
+
map: <T_3, S>(processor: (item: T_3, index: number, array: T_3[]) => S) => S[];
|
|
12
|
+
forEach: <T_4>(processor: (item: T_4, index: number, array: T_4[]) => void) => void;
|
|
13
|
+
includes: <T_5>(module: T_5) => boolean;
|
|
14
14
|
all: Module<any, any, import("..").Validator<any> | import("..").TypeValidator<any>>[];
|
|
15
15
|
};
|
|
16
16
|
export declare class ModuleManager extends Logger {
|
|
17
17
|
protected config: any;
|
|
18
18
|
readonly modules: {
|
|
19
|
-
filter: <T
|
|
20
|
-
find: <T_1
|
|
21
|
-
some: <T_2
|
|
22
|
-
map: <T_3
|
|
23
|
-
forEach: <T_4
|
|
24
|
-
includes: <T_5
|
|
19
|
+
filter: <T>(filter: (item: T, index: number, array: T[]) => boolean) => T[];
|
|
20
|
+
find: <T_1>(filter: (item: T_1, index: number, array: T_1[]) => boolean) => T_1;
|
|
21
|
+
some: <T_2>(filter: (item: T_2, index: number, array: T_2[]) => boolean) => T_2;
|
|
22
|
+
map: <T_3, S>(processor: (item: T_3, index: number, array: T_3[]) => S) => S[];
|
|
23
|
+
forEach: <T_4>(processor: (item: T_4, index: number, array: T_4[]) => void) => void;
|
|
24
|
+
includes: <T_5>(module: T_5) => boolean;
|
|
25
25
|
all: Module<any, any, import("..").Validator<any> | import("..").TypeValidator<any>>[];
|
|
26
26
|
};
|
|
27
27
|
static instance: ModuleManager;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
type NonEmptyObject<T> = T extends object ? (keyof T extends never ? never : T) : never;
|
|
2
|
+
export type DotNotation<T extends object> = NonNullable<T extends object ? {
|
|
3
|
+
[K in keyof T]: K extends string ? T[K] extends object ? NonEmptyObject<T[K]> extends never ? T[K] extends string | string[] ? `${K & string}` : never : `${K & string}.${DotNotation<T[K]>}` : `${K & string}` : never;
|
|
4
|
+
}[keyof T] : ''>;
|
|
5
|
+
export {};
|
package/db/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DB_Object,
|
|
1
|
+
import { DB_Object, DotNotation, DotNotationValueType, OmitDBObject, SubsetObjectByKeys, UniqueId } from '../utils/types';
|
|
2
2
|
import { ValidatorTypeResolver } from '../validator/validator-core';
|
|
3
3
|
export type DBIndex<T extends DB_Object> = {
|
|
4
4
|
id: string;
|
|
@@ -18,9 +18,8 @@ export type VersionsDeclaration<Versions extends VersionType[] = ['1.0.0'], Type
|
|
|
18
18
|
versions: Versions;
|
|
19
19
|
types: Types;
|
|
20
20
|
};
|
|
21
|
-
export type
|
|
22
|
-
|
|
23
|
-
proto: Proto;
|
|
21
|
+
export type ProtoDependencies<T extends object> = {
|
|
22
|
+
[K in DotNotation<T>]?: DBProto<any>;
|
|
24
23
|
};
|
|
25
24
|
type Exact<T, Shape> = T & {
|
|
26
25
|
[K in Exclude<keyof Shape, keyof T>]?: never;
|
|
@@ -35,14 +34,20 @@ type Exact<T, Shape> = T & {
|
|
|
35
34
|
* @template Dependencies (Future Use) Defines dependencies or relationships to other database objects.
|
|
36
35
|
*/
|
|
37
36
|
export type Proto_DB_Object<T extends DB_Object, DatabaseName extends string, GeneratedKeys extends keyof T | never, Versions extends VersionsDeclaration<VersionType[]>, UniqueKeys extends keyof T = Default_UniqueKey, Dependencies extends Exact<{
|
|
38
|
-
[K in
|
|
37
|
+
[K in DotNotation<T>]?: DBProto<any>;
|
|
39
38
|
}, Dependencies> = never> = {
|
|
40
39
|
type: T;
|
|
41
40
|
dbName: DatabaseName;
|
|
42
41
|
generatedKeys: GeneratedKeys | keyof DB_Object;
|
|
43
42
|
versions: Versions;
|
|
44
43
|
uniqueKeys: UniqueKeys;
|
|
45
|
-
dependencies: Dependencies;
|
|
44
|
+
dependencies: keyof Dependencies extends never ? never : Dependencies;
|
|
45
|
+
};
|
|
46
|
+
type DependenciesImpl<T extends object, D extends ProtoDependencies<T>> = {
|
|
47
|
+
[K in keyof D]: D[K] extends DBProto<any> ? {
|
|
48
|
+
dbName: D[K]['dbName'];
|
|
49
|
+
fieldType: TypeOfTypeAsString<DotNotationValueType<T, K & string>>;
|
|
50
|
+
} : never;
|
|
46
51
|
};
|
|
47
52
|
/**
|
|
48
53
|
* Extends Proto_DB_Object with additional UI and validation details.
|
|
@@ -52,6 +57,7 @@ export type Proto_DB_Object<T extends DB_Object, DatabaseName extends string, Ge
|
|
|
52
57
|
* @template GeneratedSubType The subset of P's type that is auto-generated.
|
|
53
58
|
*/
|
|
54
59
|
export type DBProto<P extends Proto_DB_Object<any, string, any, VersionsDeclaration<VersionType[]>, any, any>, ModifiableSubType = Omit<P['type'], P['generatedKeys'] | keyof DB_Object>, GeneratedSubType = SubsetObjectByKeys<P['type'], P['generatedKeys']>> = {
|
|
60
|
+
proto: P;
|
|
55
61
|
uiType: ModifiableSubType & Partial<GeneratedSubType> & Partial<DB_Object>;
|
|
56
62
|
preDbType: ModifiableSubType & Partial<GeneratedSubType>;
|
|
57
63
|
dbType: P['type'];
|
|
@@ -67,6 +73,7 @@ export type DBProto<P extends Proto_DB_Object<any, string, any, VersionsDeclarat
|
|
|
67
73
|
};
|
|
68
74
|
metadata?: Metadata<OmitDBObject<P['type']>>;
|
|
69
75
|
lockKeys?: (keyof P['type'])[];
|
|
76
|
+
dependencies: DependenciesImpl<P['type'], P['dependencies']>;
|
|
70
77
|
};
|
|
71
78
|
/**
|
|
72
79
|
* Represents the definition of a database entity with metadata and validation rules.
|
|
@@ -86,6 +93,7 @@ export type DBDef_V3<Proto extends DBProto<any, any, any>> = {
|
|
|
86
93
|
indices?: Proto['indices'];
|
|
87
94
|
lockKeys?: Proto['lockKeys'];
|
|
88
95
|
metadata?: Proto['metadata'];
|
|
96
|
+
dependencies?: Proto['dependencies'];
|
|
89
97
|
};
|
|
90
98
|
/**
|
|
91
99
|
* @field version - First item in the array is current version, Must pass all past versions with the current, default version is 1.0.0
|
|
@@ -107,21 +115,26 @@ export type DBDef<T extends DB_Object, Ks extends keyof T = Default_UniqueKey> =
|
|
|
107
115
|
TTL?: number;
|
|
108
116
|
lastUpdatedTTL?: number;
|
|
109
117
|
};
|
|
110
|
-
type
|
|
118
|
+
export type test = TypeOfTypeAsString<DotNotationValueType<{
|
|
119
|
+
a?: {
|
|
120
|
+
b?: string;
|
|
121
|
+
};
|
|
122
|
+
}, 'a.b'>>;
|
|
123
|
+
export type TypeOfTypeAsString<ValueType> = ValueType extends any[] ? ValueType extends string[] ? 'string[]' : ValueType extends number[] ? 'number[]' : ValueType extends boolean[] ? 'boolean[]' : ValueType extends object[] ? 'object[]' : 'array' : ValueType extends string ? 'string' : ValueType extends number ? 'number' : ValueType extends boolean ? 'boolean' : ValueType extends object ? 'object' : never;
|
|
111
124
|
export type MetadataProperty<ValueType> = {
|
|
112
|
-
valueType:
|
|
125
|
+
valueType: TypeOfTypeAsString<ValueType>;
|
|
113
126
|
optional: boolean;
|
|
114
127
|
description: string;
|
|
115
128
|
};
|
|
116
|
-
export type MetadataObject<T
|
|
129
|
+
export type MetadataObject<T> = {
|
|
117
130
|
[K in keyof T]-?: MetadataNested<T[K]>;
|
|
118
131
|
};
|
|
119
|
-
export type MetadataNested<T
|
|
132
|
+
export type MetadataNested<T> = T extends (infer I)[] ? MetadataProperty<T> & {
|
|
120
133
|
metadata: Metadata<I>;
|
|
121
134
|
} : T extends object ? MetadataProperty<T> & {
|
|
122
135
|
metadata: MetadataObject<T>;
|
|
123
136
|
} : MetadataProperty<T>;
|
|
124
|
-
export type Metadata<T
|
|
137
|
+
export type Metadata<T> = T extends (infer I)[] ? MetadataProperty<T> & {
|
|
125
138
|
metadata: Metadata<I>;
|
|
126
139
|
} : T extends object ? MetadataObject<T> : MetadataProperty<T>;
|
|
127
140
|
export {};
|
package/package.json
CHANGED
package/tools/Replacer.js
CHANGED
|
@@ -53,10 +53,9 @@ class Replacer extends Logger_1.Logger {
|
|
|
53
53
|
replaceParams(content = '', runtime) {
|
|
54
54
|
const matches = content.match(Replacer.Regexp_paramGroup);
|
|
55
55
|
return (matches === null || matches === void 0 ? void 0 : matches.reduce((toRet, match) => {
|
|
56
|
-
var _a;
|
|
57
56
|
let param = match;
|
|
58
57
|
while (Replacer.Regexp_param.test(param))
|
|
59
|
-
param =
|
|
58
|
+
param = param.match(Replacer.Regexp_param)[1];
|
|
60
59
|
if (param === undefined)
|
|
61
60
|
return toRet;
|
|
62
61
|
const value = this.resolveParam(param, toRet, runtime);
|
package/utils/array-tools.d.ts
CHANGED
|
@@ -74,7 +74,7 @@ export declare function sortArray<T>(array: T[], map?: keyof T | (keyof T)[] | (
|
|
|
74
74
|
/**
|
|
75
75
|
* "splits" array into given size of chunks and then does "action" on chunk and return to array of actions on chunks +-
|
|
76
76
|
* */
|
|
77
|
-
export declare function batchAction<T
|
|
77
|
+
export declare function batchAction<T = any, R = any>(arr: T[], chunk: number, action: (elements: T[]) => Promise<R | R[]>): Promise<R[]>;
|
|
78
78
|
/**
|
|
79
79
|
* Processes an array of promise-returning tasks sequentially.
|
|
80
80
|
*
|
|
@@ -94,7 +94,7 @@ export declare function batchAction<T extends any = any, R extends any = any>(ar
|
|
|
94
94
|
* @param promises
|
|
95
95
|
*/
|
|
96
96
|
export declare function Promise_all_sequentially<T>(promises: Array<() => Promise<T>>): Promise<T[]>;
|
|
97
|
-
export declare function batchActionParallel<T
|
|
97
|
+
export declare function batchActionParallel<T = any, R = any>(arr: T[], chunk: number, action: (elements: T[]) => Promise<R | R[]>): Promise<R[]>;
|
|
98
98
|
/**
|
|
99
99
|
* Returns a flat array from an array of arrays.
|
|
100
100
|
* @param arr An array that is potentially a matrix
|
|
@@ -102,21 +102,21 @@ export declare function batchActionParallel<T extends any = any, R extends any =
|
|
|
102
102
|
*/
|
|
103
103
|
export declare function flatArray<T extends any[], K = NestedArrayType<T>>(arr: T, result?: K[]): K[];
|
|
104
104
|
export declare function filterFlatInstances<T extends any[], K = NestedArrayType<T>>(arr: T, result?: K[]): Exclude<K, undefined>[];
|
|
105
|
-
export declare function groupArrayBy<T
|
|
105
|
+
export declare function groupArrayBy<T, K extends string | number>(arr: T[], mapper: (item: T, index: number) => K): {
|
|
106
106
|
key: K;
|
|
107
107
|
values: T[];
|
|
108
108
|
}[];
|
|
109
|
-
export declare function toggleInArray<T
|
|
110
|
-
export declare function generateArray<T
|
|
111
|
-
export declare function asArray<T
|
|
112
|
-
export declare function asOptionalArray<T
|
|
113
|
-
export declare function lastElement<T
|
|
114
|
-
export declare function firstElement<T
|
|
115
|
-
export declare function arrayIncludesAny<T
|
|
109
|
+
export declare function toggleInArray<T = string, K = (T extends object ? keyof T : T)>(arr: T[], item: T, mapper?: (item: T) => K): void;
|
|
110
|
+
export declare function generateArray<T = number>(length: number, mapper?: (index: number) => T): T[];
|
|
111
|
+
export declare function asArray<T>(toBeArray: T | T[]): T[];
|
|
112
|
+
export declare function asOptionalArray<T>(toBeArray?: T | T[]): T[] | undefined;
|
|
113
|
+
export declare function lastElement<T>(array: T[] | undefined): T | undefined;
|
|
114
|
+
export declare function firstElement<T>(array?: T[]): T | undefined;
|
|
115
|
+
export declare function arrayIncludesAny<T>(arr1: T[], arr2: T[]): boolean;
|
|
116
116
|
/**
|
|
117
117
|
* Returns true if arr1 returns the entirety of arr2
|
|
118
118
|
* @param arr1
|
|
119
119
|
* @param arr2
|
|
120
120
|
*/
|
|
121
|
-
export declare function arrayIncludesAll<T
|
|
121
|
+
export declare function arrayIncludesAll<T>(arr1: T[], arr2: T[]): boolean;
|
|
122
122
|
export {};
|
package/utils/object-tools.d.ts
CHANGED
|
@@ -7,10 +7,10 @@ export declare function _values<T extends TS_Object = TS_Object>(object: T): (T[
|
|
|
7
7
|
export declare function _setTypedProp<T extends TS_Object>(instance: T, key: keyof T, value: T[keyof T]): void;
|
|
8
8
|
export declare function cloneArr<T>(value: T[]): T[];
|
|
9
9
|
export declare function cloneObj<T extends TS_Object>(obj: T): T;
|
|
10
|
-
export declare function partialCompare<T
|
|
10
|
+
export declare function partialCompare<T>(one?: T, two?: T, keysToFilterOut?: (keyof T)[]): boolean;
|
|
11
11
|
/**
|
|
12
12
|
* Returns true for equal.
|
|
13
13
|
*/
|
|
14
|
-
export declare function compare<T
|
|
14
|
+
export declare function compare<T>(one?: T, two?: T, keys?: (keyof T)[]): boolean;
|
|
15
15
|
export declare function assert<T>(message: string, expected: T, actual: T): void;
|
|
16
16
|
export declare function filterKeys<T extends TS_Object = TS_Object>(obj: T, keys?: keyof T | (keyof T)[], filter?: (k: keyof T, obj: T) => boolean): T;
|
package/utils/tools.d.ts
CHANGED
|
@@ -10,10 +10,10 @@ export declare const EmptyArray: readonly never[];
|
|
|
10
10
|
export declare const voidFunction: () => Promise<void>;
|
|
11
11
|
export declare const functionThatReturnsFalse: () => false;
|
|
12
12
|
export declare const functionThatReturnsTrue: () => true;
|
|
13
|
-
export declare const resolveContent: <T
|
|
14
|
-
export declare const resolveFunctionOrValue: <T
|
|
15
|
-
export declare function exists<T
|
|
16
|
-
export declare function freeze<T
|
|
13
|
+
export declare const resolveContent: <T = any, P extends any[] = any[]>(content: ResolvableContent<T, P>, ...param: P) => T;
|
|
14
|
+
export declare const resolveFunctionOrValue: <T = any, P extends any[] = any[]>(content: ResolvableContent<T, P>, ...param: P) => T;
|
|
15
|
+
export declare function exists<T = any>(item: T | undefined | null): item is T;
|
|
16
|
+
export declare function freeze<T = any>(item: T): Readonly<T>;
|
|
17
17
|
export declare const logicalXOR: (a: boolean, b: boolean) => boolean;
|
|
18
18
|
export type KeyBinder<K extends string, Type> = {
|
|
19
19
|
Key: K;
|
package/utils/tools.js
CHANGED
|
@@ -66,7 +66,9 @@ exports.voidFunction = Object.freeze(() => __awaiter(void 0, void 0, void 0, fun
|
|
|
66
66
|
}));
|
|
67
67
|
exports.functionThatReturnsFalse = Object.freeze(() => false);
|
|
68
68
|
exports.functionThatReturnsTrue = Object.freeze(() => true);
|
|
69
|
-
const resolveContent = (content, ...param) =>
|
|
69
|
+
const resolveContent = (content, ...param) => {
|
|
70
|
+
return typeof content === 'function' ? content(...param) : content;
|
|
71
|
+
};
|
|
70
72
|
exports.resolveContent = resolveContent;
|
|
71
73
|
exports.resolveFunctionOrValue = exports.resolveContent;
|
|
72
74
|
function exists(item) {
|
package/utils/types.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ export type SubsetObjectByValue<T, ExpectedType> = SubsetObjectByKeys<T, SubsetK
|
|
|
52
52
|
export type OptionalKeys<T extends TS_Object> = Exclude<{
|
|
53
53
|
[K in keyof T]: T extends Record<K, T[K]> ? never : K;
|
|
54
54
|
}[keyof T], undefined>;
|
|
55
|
-
export type MandatoryKeys<T extends TS_Object, V
|
|
55
|
+
export type MandatoryKeys<T extends TS_Object, V = any> = Exclude<{
|
|
56
56
|
[K in keyof T]: T extends Record<K, T[K]> ? (T[K] extends V ? K : never) : never;
|
|
57
57
|
}[keyof T], undefined>;
|
|
58
58
|
export type RequireOptionals<T extends TS_Object, Keys extends OptionalKeys<T> = OptionalKeys<T>> = Pick<T, Exclude<keyof T, Keys>> & {
|
|
@@ -68,7 +68,7 @@ export type RequireOnlyOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<
|
|
|
68
68
|
[K in Keys]-?: Required<Pick<T, K>> & Partial<Record<Exclude<Keys, K>, undefined>>;
|
|
69
69
|
}[Keys];
|
|
70
70
|
export type Constructor<T> = new (...args: any) => T;
|
|
71
|
-
export type ArrayType<T
|
|
71
|
+
export type ArrayType<T> = T extends (infer I)[] ? I : never;
|
|
72
72
|
export type NestedArrayType<T extends any[]> = T extends (infer I)[] ? I extends any[] ? NestedArrayType<I> : I : never;
|
|
73
73
|
export type PartialProperties<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
74
74
|
export type KeyValue = TypedKeyValue<string, string>;
|
|
@@ -185,9 +185,10 @@ export type RecursiveWritable<T> = T extends ReadonlyArray<infer R> ? RecursiveW
|
|
|
185
185
|
* type Profile = { name: string; contacts: { email: { primary: string; secondary: string } } };
|
|
186
186
|
* type ProfilePaths = DotNotation<Profile>; // 'name' | 'contacts' | 'contacts.email' | 'contacts.email.primary' | 'contacts.email.secondary'
|
|
187
187
|
*/
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
188
|
+
type NonEmptyObject<T> = T extends object ? (keyof T extends never ? never : T) : never;
|
|
189
|
+
export type DotNotation<T extends object> = NonNullable<T extends object ? {
|
|
190
|
+
[K in keyof T]: K extends string ? T[K] extends object ? NonEmptyObject<T[K]> extends never ? T[K] extends string | string[] ? `${K & string}` : never : `${K & string}.${DotNotation<T[K]>}` : `${K & string}` : never;
|
|
191
|
+
}[keyof T] : ''>;
|
|
191
192
|
/**
|
|
192
193
|
* Replaces the type of nested property within an object, based on a specified path.
|
|
193
194
|
*
|
|
@@ -213,11 +214,12 @@ export type DotNotation<T> = T extends object ? {
|
|
|
213
214
|
* type NewProfile = ManipulateInnerPropValue<Profile, 'contacts.email.primary', boolean>;
|
|
214
215
|
* // Result: { name: string; contacts: { email: { primary: boolean; secondary: string } } }
|
|
215
216
|
*/
|
|
216
|
-
export type ManipulateInnerPropValue<ObjectType, PropertyPath extends DotNotation<ObjectType>, NewValueType> = PropertyPath extends `${infer Key}.${infer Rest}` ? Key extends keyof ObjectType ? {
|
|
217
|
-
[Prop in keyof ObjectType]: Prop extends Key ? Rest extends DotNotation<ObjectType[Key]> ? ManipulateInnerPropValue<ObjectType[Key], Rest, NewValueType> : never : ObjectType[Prop];
|
|
217
|
+
export type ManipulateInnerPropValue<ObjectType extends object, PropertyPath extends DotNotation<ObjectType>, NewValueType> = PropertyPath extends `${infer Key}.${infer Rest}` ? Key extends keyof ObjectType ? {
|
|
218
|
+
[Prop in keyof ObjectType]: Prop extends Key ? ObjectType[Key] extends object ? Rest extends DotNotation<ObjectType[Key]> ? ManipulateInnerPropValue<ObjectType[Key], Rest, NewValueType> : never : ObjectType[Prop] : never;
|
|
218
219
|
} : never : {
|
|
219
220
|
[Prop in keyof ObjectType]: Prop extends PropertyPath ? NewValueType : ObjectType[Prop];
|
|
220
221
|
};
|
|
222
|
+
export type DotNotationValueType<ObjectType extends object, Path extends string> = Path extends `${infer First}.${infer Rest}` ? First extends keyof ObjectType ? NonNullable<ObjectType[First]> extends object ? DotNotationValueType<NonNullable<ObjectType[First]>, Rest> : never : never : Path extends keyof ObjectType ? NonNullable<ObjectType[Path]> : never;
|
|
221
223
|
export type Exact<T> = {
|
|
222
224
|
[K in keyof T]: T[K];
|
|
223
225
|
} & {
|
|
@@ -232,3 +234,4 @@ export type Exact<T> = {
|
|
|
232
234
|
export type WithRequired<T, K extends keyof T> = T & {
|
|
233
235
|
[P in K]-?: T[P];
|
|
234
236
|
};
|
|
237
|
+
export {};
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import { InvalidResult, InvalidResultObject, Validator, ValidatorTypeResolver } from './validator-core';
|
|
2
2
|
import { ArrayType, AuditBy, RangeTimestamp, TypedMap } from '../utils/types';
|
|
3
3
|
export declare const tsValidateDynamicObject: <T extends object>(valuesValidator: ValidatorTypeResolver<T[keyof T]>, keysValidator: ValidatorTypeResolver<string>, mandatory?: boolean) => (import("./validator-core").ValidatorImpl<any> | ((input?: T | undefined) => InvalidResultObject<T> | undefined))[];
|
|
4
|
-
export declare const tsValidateUnion: <T
|
|
5
|
-
export declare const tsValidateCustom: <T
|
|
4
|
+
export declare const tsValidateUnion: <T>(validators: ValidatorTypeResolver<T>[], mandatory?: boolean) => import("./validator-core").ValidatorImpl<any>[];
|
|
5
|
+
export declare const tsValidateCustom: <T>(processor: (input?: T | undefined, parentInput?: any) => InvalidResult<T>, mandatory?: boolean) => Validator<T>[];
|
|
6
6
|
declare const typeFunc: (type: any) => "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
|
|
7
7
|
type types = ReturnType<typeof typeFunc>;
|
|
8
8
|
type validatorObject<T> = {
|
|
9
9
|
[k in types]?: ValidatorTypeResolver<T>;
|
|
10
10
|
};
|
|
11
|
-
export declare const tsValidateUnionV3: <T
|
|
11
|
+
export declare const tsValidateUnionV3: <T>(validatorObject: validatorObject<T>, mandatory?: boolean) => (import("./validator-core").ValidatorImpl<any> | ((input?: T | undefined) => "Input does not match any of the possible types" | InvalidResult<T> | undefined))[];
|
|
12
12
|
export declare const tsValidateArray: <T extends any[], I extends ArrayType<T> = ArrayType<T>>(validator: ValidatorTypeResolver<I> | ValidatorTypeResolver<I>[], mandatory?: boolean, minimumLength?: number) => Validator<I[]>;
|
|
13
13
|
export declare const tsValidateString: (length?: number | [number, number], mandatory?: boolean) => Validator<string>;
|
|
14
14
|
export declare const tsValidateStringMinLength: (length: number, mandatory?: boolean) => Validator<string>;
|
|
15
15
|
export declare const tsValidateNumber: (mandatory?: boolean) => Validator<number>;
|
|
16
16
|
export declare const tsValidateEnum: (enumType: TypedMap<number | string>, mandatory?: boolean) => Validator<number | string>;
|
|
17
17
|
export declare const tsValidateBoolean: (mandatory?: boolean) => Validator<boolean>;
|
|
18
|
-
export declare const tsValidateValue: <T>(values: T[], mandatory?: boolean) => Validator<any>;
|
|
18
|
+
export declare const tsValidateValue: <T>(values: readonly T[] | T[], mandatory?: boolean) => Validator<any>;
|
|
19
19
|
export declare const tsValidateIsInRange: (ranges: [number, number][], mandatory?: boolean) => Validator<number>;
|
|
20
20
|
export declare const tsValidateRange: (mandatory?: boolean) => Validator<[number, number] | undefined>;
|
|
21
21
|
export declare const tsValidateRegexp: (regexp: RegExp, mandatory?: boolean) => Validator<string>;
|
|
22
22
|
export declare const tsValidateTimestamp: (interval?: number, mandatory?: boolean) => Validator<number>;
|
|
23
|
-
export declare const tsValidateAudit: (range?: RangeTimestamp) => (audit?: AuditBy) =>
|
|
24
|
-
export declare const tsValidateNonMandatoryObject: <T extends object>(validator: ValidatorTypeResolver<T>) => ((input?: T | undefined) =>
|
|
25
|
-
export declare const tsValidateOptionalObject: <T extends object>(validator: ValidatorTypeResolver<T>) => ((input?: T | undefined) =>
|
|
26
|
-
export declare const tsValidator_valueByKey: <T
|
|
23
|
+
export declare const tsValidateAudit: (range?: RangeTimestamp) => (audit?: AuditBy) => string | undefined;
|
|
24
|
+
export declare const tsValidateNonMandatoryObject: <T extends object | undefined>(validator: ValidatorTypeResolver<T>) => (import("./validator-core").ValidatorImpl<any> | ((input?: T | undefined) => InvalidResult<T> | undefined))[];
|
|
25
|
+
export declare const tsValidateOptionalObject: <T extends object | undefined>(validator: ValidatorTypeResolver<T>) => (import("./validator-core").ValidatorImpl<any> | ((input?: T | undefined) => InvalidResult<T> | undefined))[];
|
|
26
|
+
export declare const tsValidator_valueByKey: <T>(validatorObject: {
|
|
27
27
|
[k: string]: Validator<any> | import("./validator-core").TypeValidator<any>;
|
|
28
28
|
}, prop?: string) => ValidatorTypeResolver<T>;
|
|
29
29
|
export declare const tsValidator_ArrayOfObjectsByKey: <T extends Object>(key: keyof T, validatorMap: {
|
|
@@ -8,24 +8,23 @@ import { CustomException } from '../core/exceptions/exceptions';
|
|
|
8
8
|
* K extends [infer E1, infer E2, infer E3] ? [Validator<E1>,Validator<E2>,Validator<E2>] :
|
|
9
9
|
* K extends [infer E1, infer E2, infer E3, infer E4] ? [Validator<E1>,Validator<E2>,Validator<E2>,Validator<E4>] :
|
|
10
10
|
*/
|
|
11
|
-
export type ValidatorTypeResolver<K> = K extends [
|
|
12
|
-
export type ValidatorImpl<P> = (p?: P) => (InvalidResult<P> | undefined);
|
|
11
|
+
export type ValidatorTypeResolver<K> = K extends [any] ? Validator<K> : K extends [any, any] ? Validator<K> : K extends [any, any, any] ? Validator<K> : K extends [any, any, any, any] ? Validator<K> : K extends any[] ? Validator<K> : K extends TS_Object ? TypeValidator<K> | Validator<K> : Validator<K>;
|
|
12
|
+
export type ValidatorImpl<P> = (p?: P, parentObj?: any) => (InvalidResult<P> | undefined);
|
|
13
13
|
export type Validator<P> = ValidatorImpl<P> | ValidatorImpl<P>[];
|
|
14
14
|
export type TypeValidator<T extends TS_Object> = {
|
|
15
15
|
[P in keyof T]-?: ValidatorTypeResolver<T[P]>;
|
|
16
16
|
};
|
|
17
|
-
export type InvalidResultObject<T
|
|
17
|
+
export type InvalidResultObject<T> = {
|
|
18
18
|
[K in keyof T]?: InvalidResult<T[K]>;
|
|
19
19
|
};
|
|
20
|
-
export type InvalidResultArray<T
|
|
21
|
-
export type InvalidResult<T
|
|
22
|
-
export declare class ValidationException<T
|
|
20
|
+
export type InvalidResultArray<T> = InvalidResult<T> | undefined;
|
|
21
|
+
export type InvalidResult<T> = T extends object ? InvalidResultObject<T> | string | undefined : T extends (infer I)[] ? (InvalidResultArray<I>[]) | string | undefined : string | undefined;
|
|
22
|
+
export declare class ValidationException<T> extends CustomException {
|
|
23
23
|
input?: T;
|
|
24
24
|
result?: InvalidResult<T>;
|
|
25
25
|
constructor(debugMessage: string, input?: T, result?: InvalidResult<T>, e?: Error);
|
|
26
26
|
}
|
|
27
|
-
export declare const assertValidateMandatoryProperty: (mandatory: boolean, input?: any) => void;
|
|
28
27
|
export declare const tsValidateExists: (mandatory?: boolean) => ValidatorImpl<any>;
|
|
29
|
-
export declare const tsValidate: <T
|
|
30
|
-
export declare const tsValidateResult: <T
|
|
31
|
-
export declare const tsValidateObject: <T>(__validator: TypeValidator<
|
|
28
|
+
export declare const tsValidate: <T>(instance: T | undefined, _validator: ValidatorTypeResolver<T>, strict?: boolean) => InvalidResult<T> | undefined;
|
|
29
|
+
export declare const tsValidateResult: <T>(instance: T | undefined, _validator: ValidatorTypeResolver<T>, key?: keyof T | undefined, parentInstance?: any) => InvalidResult<T> | undefined;
|
|
30
|
+
export declare const tsValidateObject: <T extends object>(__validator: TypeValidator<T>, instance: T, path?: string) => InvalidResultObject<T> | undefined;
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.tsValidateObject = exports.tsValidateResult = exports.tsValidate = exports.tsValidateExists = exports.
|
|
20
|
+
exports.tsValidateObject = exports.tsValidateResult = exports.tsValidate = exports.tsValidateExists = exports.ValidationException = void 0;
|
|
21
21
|
const object_tools_1 = require("../utils/object-tools");
|
|
22
22
|
const exceptions_1 = require("../core/exceptions/exceptions");
|
|
23
23
|
class ValidationException extends exceptions_1.CustomException {
|
|
@@ -29,9 +29,6 @@ class ValidationException extends exceptions_1.CustomException {
|
|
|
29
29
|
}
|
|
30
30
|
exports.ValidationException = ValidationException;
|
|
31
31
|
const CONST_NO_ERROR = '###';
|
|
32
|
-
const assertValidateMandatoryProperty = (mandatory, input) => {
|
|
33
|
-
};
|
|
34
|
-
exports.assertValidateMandatoryProperty = assertValidateMandatoryProperty;
|
|
35
32
|
const tsValidateExists = (mandatory = true) => {
|
|
36
33
|
return (input) => {
|
|
37
34
|
if (input !== undefined && input !== null)
|
|
@@ -74,7 +71,9 @@ const tsValidateResult = (instance, _validator, key, parentInstance) => {
|
|
|
74
71
|
return 'No validator provided!';
|
|
75
72
|
const validator = typeof _validator === 'function' ? [_validator] : _validator;
|
|
76
73
|
if (Array.isArray(validator)) {
|
|
77
|
-
const result = validator.reduce((result, __validator) =>
|
|
74
|
+
const result = validator.reduce((result, __validator) => {
|
|
75
|
+
return result === CONST_NO_ERROR ? result : result || __validator(instance, parentInstance);
|
|
76
|
+
}, undefined);
|
|
78
77
|
return result !== CONST_NO_ERROR ? result : undefined;
|
|
79
78
|
}
|
|
80
79
|
if (typeof validator === 'object') {
|