equipped 4.1.2 → 4.1.4
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 +9 -0
- package/lib/validations/index.d.ts +36 -33
- package/lib/validations/index.js +10 -31
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [4.1.4](https://github.com/kevinand11/equipped/compare/v4.1.3...v4.1.4) (2023-03-14)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* update to latest version of valleyed ([60c8c95](https://github.com/kevinand11/equipped/commit/60c8c95d0e0164d6f7934a6396da05b0543d7fbe))
|
|
11
|
+
|
|
12
|
+
### [4.1.3](https://github.com/kevinand11/equipped/compare/v4.1.2...v4.1.3) (2023-03-11)
|
|
13
|
+
|
|
5
14
|
### [4.1.2](https://github.com/kevinand11/equipped/compare/v4.1.1...v4.1.2) (2023-03-11)
|
|
6
15
|
|
|
7
16
|
### [4.1.1](https://github.com/kevinand11/equipped/compare/v4.1.0...v4.1.1) (2023-03-10)
|
|
@@ -5,22 +5,24 @@ type Phone = {
|
|
|
5
5
|
number: string;
|
|
6
6
|
};
|
|
7
7
|
export declare const Schema: {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
is: <T = any>(value: T) => Validate.VCore<T>;
|
|
9
|
+
in: <T_1 = any>(values: readonly T_1[], comparer?: ((val: any, arrayItem: T_1) => boolean) | undefined) => Validate.VCore<T_1>;
|
|
10
|
+
or: <T_2 extends Validate.VCore<any>[]>(options: T_2, err?: string | undefined) => import("valleyed/lib/api/junctions").VOr<T_2>;
|
|
11
|
+
and: <I>(options: Validate.VCore<I>[], err?: string | undefined) => import("valleyed/lib/api/junctions").VAnd<I>;
|
|
10
12
|
string: (err?: string | undefined) => import("valleyed/lib/api/strings").VString;
|
|
11
13
|
number: (err?: string | undefined) => import("valleyed/lib/api/numbers").VNumber;
|
|
12
14
|
boolean: (err?: string | undefined) => import("valleyed/lib/api/booleans").VBoolean;
|
|
13
|
-
time: <
|
|
15
|
+
time: <T_3 extends Validate.Timeable = Validate.Timeable>(err?: string | undefined) => import("valleyed/lib/api/times").VTime<T_3>;
|
|
14
16
|
file: (err?: string | undefined) => import("valleyed/lib/api/files").VFile;
|
|
15
|
-
array: <I_1
|
|
16
|
-
tuple: <
|
|
17
|
-
object: <
|
|
18
|
-
record: <VI
|
|
19
|
-
map: <KI, VI_1
|
|
20
|
-
null: (err?: string | undefined) => Validate.VCore<null
|
|
21
|
-
undefined: (err?: string | undefined) => Validate.VCore<undefined
|
|
22
|
-
instanceof: <
|
|
23
|
-
any: <
|
|
17
|
+
array: <I_1>(comparer: Validate.VCore<I_1>, err?: string | undefined) => import("valleyed/lib/api/arrays").VArray<I_1>;
|
|
18
|
+
tuple: <T_4 extends readonly Validate.VCore<any>[]>(schema: readonly [...T_4], err?: string | undefined) => import("valleyed/lib/api/tuples").VTuple<T_4>;
|
|
19
|
+
object: <T_5 extends Record<string, Validate.VCore<any>>>(schema: T_5, trim?: boolean | undefined, err?: string | undefined) => import("valleyed/lib/api/objects").VObject<T_5>;
|
|
20
|
+
record: <VI>(vCom: Validate.VCore<VI>, err?: string | undefined) => import("valleyed/lib/api/records").VRecord<VI>;
|
|
21
|
+
map: <KI, VI_1>(kCom: Validate.VCore<KI>, vCom: Validate.VCore<VI_1>, err?: string | undefined) => import("valleyed/lib/api/records").VMap<KI, VI_1>;
|
|
22
|
+
null: (err?: string | undefined) => Validate.VCore<null>;
|
|
23
|
+
undefined: (err?: string | undefined) => Validate.VCore<undefined>;
|
|
24
|
+
instanceof: <T_6>(classDef: new () => T_6, err?: string | undefined) => Validate.VCore<T_6>;
|
|
25
|
+
any: <T_7 = any>() => Validate.VCore<T_7>;
|
|
24
26
|
force: {
|
|
25
27
|
string: (err?: string | undefined) => import("valleyed/lib/api/strings").VString;
|
|
26
28
|
number: (err?: string | undefined) => import("valleyed/lib/api/numbers").VNumber;
|
|
@@ -34,22 +36,24 @@ export declare const Validation: {
|
|
|
34
36
|
Validator: typeof Validate.Validator;
|
|
35
37
|
VCore: typeof Validate.VCore;
|
|
36
38
|
v: {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
is: <T = any>(value: T) => Validate.VCore<T>;
|
|
40
|
+
in: <T_1 = any>(values: readonly T_1[], comparer?: ((val: any, arrayItem: T_1) => boolean) | undefined) => Validate.VCore<T_1>;
|
|
41
|
+
or: <T_2 extends Validate.VCore<any>[]>(options: T_2, err?: string | undefined) => import("valleyed/lib/api/junctions").VOr<T_2>;
|
|
42
|
+
and: <I>(options: Validate.VCore<I>[], err?: string | undefined) => import("valleyed/lib/api/junctions").VAnd<I>;
|
|
39
43
|
string: (err?: string | undefined) => import("valleyed/lib/api/strings").VString;
|
|
40
44
|
number: (err?: string | undefined) => import("valleyed/lib/api/numbers").VNumber;
|
|
41
45
|
boolean: (err?: string | undefined) => import("valleyed/lib/api/booleans").VBoolean;
|
|
42
|
-
time: <
|
|
46
|
+
time: <T_3 extends Validate.Timeable = Validate.Timeable>(err?: string | undefined) => import("valleyed/lib/api/times").VTime<T_3>;
|
|
43
47
|
file: (err?: string | undefined) => import("valleyed/lib/api/files").VFile;
|
|
44
|
-
array: <I_1
|
|
45
|
-
tuple: <
|
|
46
|
-
object: <
|
|
47
|
-
record: <VI
|
|
48
|
-
map: <KI, VI_1
|
|
49
|
-
null: (err?: string | undefined) => Validate.VCore<null
|
|
50
|
-
undefined: (err?: string | undefined) => Validate.VCore<undefined
|
|
51
|
-
instanceof: <
|
|
52
|
-
any: <
|
|
48
|
+
array: <I_1>(comparer: Validate.VCore<I_1>, err?: string | undefined) => import("valleyed/lib/api/arrays").VArray<I_1>;
|
|
49
|
+
tuple: <T_4 extends readonly Validate.VCore<any>[]>(schema: readonly [...T_4], err?: string | undefined) => import("valleyed/lib/api/tuples").VTuple<T_4>;
|
|
50
|
+
object: <T_5 extends Record<string, Validate.VCore<any>>>(schema: T_5, trim?: boolean | undefined, err?: string | undefined) => import("valleyed/lib/api/objects").VObject<T_5>;
|
|
51
|
+
record: <VI>(vCom: Validate.VCore<VI>, err?: string | undefined) => import("valleyed/lib/api/records").VRecord<VI>;
|
|
52
|
+
map: <KI, VI_1>(kCom: Validate.VCore<KI>, vCom: Validate.VCore<VI_1>, err?: string | undefined) => import("valleyed/lib/api/records").VMap<KI, VI_1>;
|
|
53
|
+
null: (err?: string | undefined) => Validate.VCore<null>;
|
|
54
|
+
undefined: (err?: string | undefined) => Validate.VCore<undefined>;
|
|
55
|
+
instanceof: <T_6>(classDef: new () => T_6, err?: string | undefined) => Validate.VCore<T_6>;
|
|
56
|
+
any: <T_7 = any>() => Validate.VCore<T_7>;
|
|
53
57
|
force: {
|
|
54
58
|
string: (err?: string | undefined) => import("valleyed/lib/api/strings").VString;
|
|
55
59
|
number: (err?: string | undefined) => import("valleyed/lib/api/numbers").VNumber;
|
|
@@ -58,7 +62,7 @@ export declare const Validation: {
|
|
|
58
62
|
};
|
|
59
63
|
};
|
|
60
64
|
isEqualTo: <Type>(compare: Type, comparer?: ((val: any, compare: Type) => boolean) | undefined, error?: string | undefined) => Validate.Rule<Type>;
|
|
61
|
-
arrayContains: <Type_1>(array: Type_1[], comparer?: ((val: any, arrayItem: Type_1) => boolean) | undefined, error?: string | undefined) => Validate.Rule<Type_1>;
|
|
65
|
+
arrayContains: <Type_1>(array: readonly Type_1[], comparer?: ((val: any, arrayItem: Type_1) => boolean) | undefined, error?: string | undefined) => Validate.Rule<Type_1>;
|
|
62
66
|
isString: (error?: string | undefined) => Validate.Rule<any>;
|
|
63
67
|
isLengthOf: (length: number, stripHTMLTags?: boolean | undefined, error?: string | undefined) => Validate.Rule<string>;
|
|
64
68
|
isMinOf: (length: number, stripHTMLTags?: boolean | undefined, error?: string | undefined) => Validate.Rule<string>;
|
|
@@ -66,6 +70,7 @@ export declare const Validation: {
|
|
|
66
70
|
isEmail: (error?: string | undefined) => Validate.Rule<string>;
|
|
67
71
|
isUrl: (error?: string | undefined) => Validate.Rule<string>;
|
|
68
72
|
isNumber: (error?: string | undefined) => Validate.Rule<any>;
|
|
73
|
+
isInt: (error?: string | undefined) => Validate.Rule<any>;
|
|
69
74
|
isMoreThan: (compare: number, error?: string | undefined) => Validate.Rule<number>;
|
|
70
75
|
isMoreThanOrEqualTo: (compare: number, error?: string | undefined) => Validate.Rule<number>;
|
|
71
76
|
isLessThan: (compare: number, error?: string | undefined) => Validate.Rule<number>;
|
|
@@ -129,18 +134,16 @@ export declare const Validation: {
|
|
|
129
134
|
makeRule: <T_9>(func: Validate.Rule<T_9>) => Validate.Rule<T_9>;
|
|
130
135
|
makeSanitizer: <T_10>(func: Validate.Sanitizer<T_10>) => (val: T_10) => T_10;
|
|
131
136
|
check: <T_11>(value: T_11, rules: Validate.Rule<T_11>[], options?: Partial<Validate.Options> | undefined) => {
|
|
137
|
+
valid: false;
|
|
138
|
+
errors: string[];
|
|
139
|
+
value: unknown;
|
|
140
|
+
} | {
|
|
141
|
+
valid: true;
|
|
132
142
|
errors: string[];
|
|
133
143
|
value: T_11;
|
|
134
|
-
valid: boolean;
|
|
135
144
|
};
|
|
136
145
|
};
|
|
137
|
-
|
|
138
|
-
required?: boolean | (() => boolean);
|
|
139
|
-
nullable?: boolean;
|
|
140
|
-
rules: Validate.Rule<T>[];
|
|
141
|
-
};
|
|
142
|
-
export declare const validate: <Keys extends Record<string, any>>(data: Keys, rules: Record<keyof Keys, Rules<any>>) => Keys;
|
|
143
|
-
export declare const validateReq: <T extends Record<string, Validate.VCore<any, any>>>(schema: T, value: Record<string, any>) => { [K in keyof T]: import("valleyed/lib/api/base").ExtractO<T[K]>; };
|
|
146
|
+
export declare const validate: <T extends Record<string, Validate.VCore<any>>>(schema: T, value: Record<string, any>) => { [K in keyof T]: import("valleyed/lib/api/base").ExtractI<T[K]>; };
|
|
144
147
|
export declare const Hash: {
|
|
145
148
|
hash: (password: string) => Promise<string>;
|
|
146
149
|
compare: (plainPassword: string, hashed: string) => Promise<boolean>;
|
package/lib/validations/index.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.Hash = exports.
|
|
26
|
+
exports.Hash = exports.validate = exports.Validation = exports.Schema = void 0;
|
|
27
27
|
const bcrypt = __importStar(require("bcryptjs"));
|
|
28
28
|
const Validate = __importStar(require("valleyed"));
|
|
29
29
|
const errors_1 = require("../errors");
|
|
@@ -35,40 +35,19 @@ const isNotTruncated = (error) => Validate.makeRule((file) => {
|
|
|
35
35
|
return valid ? Validate.isValid(val) : Validate.isInvalid([error], val);
|
|
36
36
|
});
|
|
37
37
|
const isValidPhone = (error) => Validate.makeRule((value) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return Validate.isInvalid([error ?? 'invalid phone code'], phone);
|
|
46
|
-
if (!isValidNumber)
|
|
47
|
-
return Validate.isInvalid([error ?? 'invalid phone number'], phone);
|
|
48
|
-
return Validate.isValid(phone);
|
|
38
|
+
return Validate.v.object({
|
|
39
|
+
code: Validate.v.string().custom((val) => {
|
|
40
|
+
return val.startsWith('+') &&
|
|
41
|
+
Validate.v.force.number(val.slice(1)).parse(val).valid;
|
|
42
|
+
}, error ?? 'invalid phone code'),
|
|
43
|
+
number: Validate.v.force.number(error ?? 'invalid phone number').transform((val) => val.toString())
|
|
44
|
+
}).parse(value);
|
|
49
45
|
});
|
|
50
46
|
const file = Validate.v.file;
|
|
51
47
|
Validate.v.file = (...args) => file(...args).addRule(isNotTruncated());
|
|
52
48
|
exports.Schema = Validate.v;
|
|
53
49
|
exports.Validation = { ...Validate, isNotTruncated, isValidPhone };
|
|
54
|
-
const validate = (
|
|
55
|
-
const errors = Object.entries(data)
|
|
56
|
-
.map(([key, value]) => ({
|
|
57
|
-
key,
|
|
58
|
-
validity: exports.Validation.Validator.and(value, [rules[key].rules], {
|
|
59
|
-
required: rules[key].required,
|
|
60
|
-
nullable: rules[key].nullable
|
|
61
|
-
})
|
|
62
|
-
}));
|
|
63
|
-
const failed = errors.some(({ validity }) => !validity.valid);
|
|
64
|
-
if (failed)
|
|
65
|
-
throw new errors_1.ValidationError(errors
|
|
66
|
-
.filter(({ validity }) => !validity.valid)
|
|
67
|
-
.map(({ key, validity }) => ({ field: key, messages: validity.errors })));
|
|
68
|
-
return data;
|
|
69
|
-
};
|
|
70
|
-
exports.validate = validate;
|
|
71
|
-
const validateReq = (schema, value) => {
|
|
50
|
+
const validate = (schema, value) => {
|
|
72
51
|
const validity = exports.Validation.v.object(schema).parse(value);
|
|
73
52
|
if (validity.valid)
|
|
74
53
|
return validity.value;
|
|
@@ -87,7 +66,7 @@ const validateReq = (schema, value) => {
|
|
|
87
66
|
throw new errors_1.ValidationError(Object.entries(errorsObject)
|
|
88
67
|
.map(([key, value]) => ({ field: key, messages: value })));
|
|
89
68
|
};
|
|
90
|
-
exports.
|
|
69
|
+
exports.validate = validate;
|
|
91
70
|
const hash = async (password) => {
|
|
92
71
|
password = password.trim();
|
|
93
72
|
if (!password)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "equipped",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"redis": "^4.6.5",
|
|
67
67
|
"socket.io": "4.6.1",
|
|
68
68
|
"supertest": "^6.3.3",
|
|
69
|
-
"valleyed": "^4.1.
|
|
69
|
+
"valleyed": "^4.1.2"
|
|
70
70
|
},
|
|
71
71
|
"repository": {
|
|
72
72
|
"url": "git://github.com/kevinand11/equipped.git"
|