equipped 4.0.0-alpha.5 → 4.0.0-alpha.7
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 +48 -15
- package/lib/validations/index.js +16 -2
- 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.0.0-alpha.7](https://github.com/kevinand11/equipped/compare/v4.0.0-alpha.6...v4.0.0-alpha.7) (2023-02-14)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* update valleyed version ([638ea0a](https://github.com/kevinand11/equipped/commit/638ea0a2c91967ae897f83b8ea9da480dcd1a7bf))
|
|
11
|
+
|
|
12
|
+
## [4.0.0-alpha.6](https://github.com/kevinand11/equipped/compare/v4.0.0-alpha.5...v4.0.0-alpha.6) (2023-02-14)
|
|
13
|
+
|
|
5
14
|
## [4.0.0-alpha.5](https://github.com/kevinand11/equipped/compare/v4.0.0-alpha.4...v4.0.0-alpha.5) (2023-02-14)
|
|
6
15
|
|
|
7
16
|
|
|
@@ -1,8 +1,37 @@
|
|
|
1
1
|
import * as Validate from 'valleyed';
|
|
2
2
|
import { VCore } from 'valleyed/lib/api/core';
|
|
3
3
|
import { StorageFile } from '../storage';
|
|
4
|
+
type Phone = {
|
|
5
|
+
code: string;
|
|
6
|
+
number: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const Schema: {
|
|
9
|
+
or: <T extends VCore<any, any>[]>(options: T, err?: string | undefined) => import("valleyed/lib/api/junctions").VOr<T>;
|
|
10
|
+
and: <I, O>(options: VCore<I, O>[], err?: string | undefined) => import("valleyed/lib/api/junctions").VAnd<I, O>;
|
|
11
|
+
string: (err?: string | undefined) => import("valleyed/lib/api/strings").VString;
|
|
12
|
+
number: (err?: string | undefined) => import("valleyed/lib/api/numbers").VNumber;
|
|
13
|
+
boolean: (err?: string | undefined) => import("valleyed/lib/api/booleans").VBoolean;
|
|
14
|
+
time: <T_1 extends Validate.Timeable = Validate.Timeable>(err?: string | undefined) => import("valleyed/lib/api/times").VTime<T_1>;
|
|
15
|
+
file: (err?: string | undefined) => import("valleyed/lib/api/files").VFile;
|
|
16
|
+
array: <I_1, O_1>(comparer: VCore<I_1, O_1>, err?: string | undefined) => import("valleyed/lib/api/arrays").VArray<I_1, O_1>;
|
|
17
|
+
tuple: <T_2 extends readonly VCore<any, any>[]>(schema: readonly [...T_2], err?: string | undefined) => import("valleyed/lib/api/tuples").VTuple<T_2>;
|
|
18
|
+
object: <T_3 extends Record<string, VCore<any, any>>>(schema: T_3, trim?: boolean | undefined, err?: string | undefined) => import("valleyed/lib/api/objects").VObject<T_3>;
|
|
19
|
+
record: <VI, VO>(vCom: VCore<VI, VO>, err?: string | undefined) => import("valleyed/lib/api/records").VRecord<VI, VO>;
|
|
20
|
+
map: <KI, VI_1, KO, VO_1>(kCom: VCore<KI, KO>, vCom: VCore<VI_1, VO_1>, err?: string | undefined) => import("valleyed/lib/api/records").VMap<KI, VI_1, KO, VO_1>;
|
|
21
|
+
null: (err?: string | undefined) => VCore<null, null>;
|
|
22
|
+
undefined: (err?: string | undefined) => VCore<undefined, undefined>;
|
|
23
|
+
instanceof: <T_4>(classDef: new () => T_4, err?: string | undefined) => VCore<T_4, T_4>;
|
|
24
|
+
any: <T_5 = any>() => VCore<T_5, T_5>;
|
|
25
|
+
force: {
|
|
26
|
+
string: (err?: string | undefined) => import("valleyed/lib/api/strings").VString;
|
|
27
|
+
number: (err?: string | undefined) => import("valleyed/lib/api/numbers").VNumber;
|
|
28
|
+
boolean: (err?: string | undefined) => import("valleyed/lib/api/booleans").VBoolean;
|
|
29
|
+
time: (err?: string | undefined) => import("valleyed/lib/api/times").VTime<Date>;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
4
32
|
export declare const Validation: {
|
|
5
33
|
isNotTruncated: (error?: string) => Validate.Rule<StorageFile>;
|
|
34
|
+
isValidPhone: (error?: string) => Validate.Rule<Phone>;
|
|
6
35
|
Validator: typeof Validate.Validator;
|
|
7
36
|
v: {
|
|
8
37
|
or: <T extends VCore<any, any>[]>(options: T, err?: string | undefined) => import("valleyed/lib/api/junctions").VOr<T>;
|
|
@@ -20,7 +49,7 @@ export declare const Validation: {
|
|
|
20
49
|
null: (err?: string | undefined) => VCore<null, null>;
|
|
21
50
|
undefined: (err?: string | undefined) => VCore<undefined, undefined>;
|
|
22
51
|
instanceof: <T_4>(classDef: new () => T_4, err?: string | undefined) => VCore<T_4, T_4>;
|
|
23
|
-
any: () => VCore<
|
|
52
|
+
any: <T_5 = any>() => VCore<T_5, T_5>;
|
|
24
53
|
force: {
|
|
25
54
|
string: (err?: string | undefined) => import("valleyed/lib/api/strings").VString;
|
|
26
55
|
number: (err?: string | undefined) => import("valleyed/lib/api/numbers").VNumber;
|
|
@@ -28,21 +57,21 @@ export declare const Validation: {
|
|
|
28
57
|
time: (err?: string | undefined) => import("valleyed/lib/api/times").VTime<Date>;
|
|
29
58
|
};
|
|
30
59
|
};
|
|
31
|
-
isValid: <
|
|
60
|
+
isValid: <T>(value: T) => {
|
|
32
61
|
valid: true;
|
|
33
62
|
errors: string[];
|
|
34
|
-
value:
|
|
63
|
+
value: T;
|
|
35
64
|
};
|
|
36
|
-
isInvalid: <
|
|
65
|
+
isInvalid: <T_1>(errors: string[], value: T_1) => {
|
|
37
66
|
valid: false;
|
|
38
67
|
errors: string[];
|
|
39
68
|
value: unknown;
|
|
40
69
|
};
|
|
41
|
-
makeRule: <
|
|
42
|
-
makeSanitizer: <
|
|
43
|
-
check: <
|
|
70
|
+
makeRule: <T_2>(func: Validate.Rule<T_2>) => Validate.Rule<T_2>;
|
|
71
|
+
makeSanitizer: <T_3>(func: Validate.Sanitizer<T_3>) => (val: T_3) => T_3;
|
|
72
|
+
check: <T_4>(value: T_4, rules: Validate.Rule<T_4>[], options?: Partial<Validate.Options> | undefined) => {
|
|
44
73
|
errors: string[];
|
|
45
|
-
value:
|
|
74
|
+
value: T_4;
|
|
46
75
|
valid: boolean;
|
|
47
76
|
};
|
|
48
77
|
isShallowEqualTo: <Type>(compare: Type, error?: string | undefined) => Validate.Rule<Type>;
|
|
@@ -67,7 +96,7 @@ export declare const Validation: {
|
|
|
67
96
|
isUndefined: (error?: string | undefined) => Validate.Rule<undefined>;
|
|
68
97
|
isNull: (error?: string | undefined) => Validate.Rule<null>;
|
|
69
98
|
isBoolean: (error?: string | undefined) => Validate.Rule<boolean>;
|
|
70
|
-
isInstanceOf: <
|
|
99
|
+
isInstanceOf: <T_5>(classDef: new () => T_5, error?: string | undefined) => Validate.Rule<T_5>;
|
|
71
100
|
fileMimeTypes: string[];
|
|
72
101
|
videoMimeTypes: string[];
|
|
73
102
|
audioMimeTypes: string[];
|
|
@@ -76,13 +105,13 @@ export declare const Validation: {
|
|
|
76
105
|
isAudio: (error?: string | undefined) => Validate.Rule<Validate.File>;
|
|
77
106
|
isVideo: (error?: string | undefined) => Validate.Rule<Validate.File>;
|
|
78
107
|
isFile: (error?: string | undefined) => Validate.Rule<Validate.File>;
|
|
79
|
-
isTuple: <
|
|
108
|
+
isTuple: <T_6 extends readonly ((v: any, idx: number) => boolean)[]>(comparer: readonly [...T_6], error?: string | undefined) => Validate.Rule<{ [K in keyof T_6]: T_6[K] extends (v: infer V, idx: number) => boolean ? V : never; }>;
|
|
80
109
|
isRecord: <V_1>(com: (cur: V_1) => boolean, error?: string | undefined) => Validate.Rule<Record<string, V_1>>;
|
|
81
110
|
isMap: <K_1, V_2>(kCom: (cur: K_1) => boolean, vCom: (cur: V_2) => boolean, error?: string | undefined) => Validate.Rule<Map<K_1, V_2>>;
|
|
82
|
-
isCustom: <
|
|
83
|
-
isTime: <
|
|
84
|
-
isLaterThan: <
|
|
85
|
-
isEarlierThan: <
|
|
111
|
+
isCustom: <T_7>(validity: (v: T_7) => boolean, error?: string | undefined) => Validate.Rule<T_7>;
|
|
112
|
+
isTime: <T_8 extends Validate.Timeable>(error?: string | undefined) => Validate.Rule<T_8>;
|
|
113
|
+
isLaterThan: <T_9 extends Validate.Timeable>(compare: Validate.Timeable, error?: string | undefined) => Validate.Rule<T_9>;
|
|
114
|
+
isEarlierThan: <T_10 extends Validate.Timeable>(compare: Validate.Timeable, error?: string | undefined) => Validate.Rule<T_10>;
|
|
86
115
|
capitalize: (text: string) => string;
|
|
87
116
|
stripHTML: (html: string) => string;
|
|
88
117
|
trimToLength: (body: string, length: number) => string;
|
|
@@ -98,7 +127,7 @@ export declare const Validation: {
|
|
|
98
127
|
values: Type_7[];
|
|
99
128
|
}[];
|
|
100
129
|
getAlphabet: (num: number) => string;
|
|
101
|
-
addToArray: <
|
|
130
|
+
addToArray: <T_11>(array: T_11[], item: T_11, getKey: (a: T_11) => any, getComparer: (a: T_11) => string | number, asc?: boolean | undefined) => T_11[];
|
|
102
131
|
divideByZero: (num: number, den: number) => number;
|
|
103
132
|
getPercentage: (num: number, den: number) => number;
|
|
104
133
|
getRandomSample: <Type_8>(population: Type_8[], n: number) => Type_8[];
|
|
@@ -115,4 +144,8 @@ export declare const Hash: {
|
|
|
115
144
|
hash: (password: string) => Promise<string>;
|
|
116
145
|
compare: (plainPassword: string, hashed: string) => Promise<boolean>;
|
|
117
146
|
};
|
|
147
|
+
declare module 'valleyed/lib/rules/files' {
|
|
148
|
+
interface File extends StorageFile {
|
|
149
|
+
}
|
|
150
|
+
}
|
|
118
151
|
export {};
|
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.validateReq = exports.validate = exports.Validation = void 0;
|
|
26
|
+
exports.Hash = exports.validateReq = 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");
|
|
@@ -34,7 +34,21 @@ const isNotTruncated = (error) => Validate.makeRule((file) => {
|
|
|
34
34
|
const valid = val ? !val.isTruncated : true;
|
|
35
35
|
return valid ? Validate.isValid(val) : Validate.isInvalid([error], val);
|
|
36
36
|
});
|
|
37
|
-
|
|
37
|
+
const isValidPhone = (error) => Validate.makeRule((value) => {
|
|
38
|
+
const phone = value;
|
|
39
|
+
const { code = '', number = '' } = phone ?? {};
|
|
40
|
+
const isValidCode = Validate.isString()(code).valid &&
|
|
41
|
+
code.startsWith('+') &&
|
|
42
|
+
Validate.isNumber()(parseInt(code.slice(1))).valid;
|
|
43
|
+
const isValidNumber = Validate.isNumber()(parseInt(number)).valid;
|
|
44
|
+
if (!isValidCode)
|
|
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);
|
|
49
|
+
});
|
|
50
|
+
exports.Schema = Validate.v;
|
|
51
|
+
exports.Validation = { ...Validate, isNotTruncated, isValidPhone };
|
|
38
52
|
const validate = (data, rules) => {
|
|
39
53
|
const errors = Object.entries(data)
|
|
40
54
|
.map(([key, value]) => ({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "equipped",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.7",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"pug": "^3.0.2",
|
|
58
58
|
"redis": "^4.6.4",
|
|
59
59
|
"socket.io": "4.6.0",
|
|
60
|
-
"valleyed": "^4.0.
|
|
60
|
+
"valleyed": "^4.0.4-alpha.1"
|
|
61
61
|
},
|
|
62
62
|
"repository": {
|
|
63
63
|
"url": "git://github.com/kevinand11/equipped.git"
|