Skip to content

Commit c3b5aeb

Browse files
committed
Remove hapi/joi
1 parent 7937a1f commit c3b5aeb

22 files changed

+387
-167
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,6 @@ The very powerful
430430
[`libphonenumber` library](https://github.com/googlei18n/libphonenumber) is available to take
431431
_that_ format, parse and display it in whatever display format you want. It can also be used to
432432
parse user input and _get_ the E.164 format to pass _into_ a schema.
433-
It uses [`libphonenumber-js` library](https://github.com/catamphetamine/libphonenumber-js).
434433

435434
### PostalCode
436435

bundle-test/webpack.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const path = require('path');
22

33
module.exports = {
4-
target: 'node',
54
mode: 'production',
65
output: {
76
filename: 'index.js',

package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
},
3737
"devDependencies": {
3838
"@types/graphql": "14.2.3",
39-
"@types/hapi__joi": "15.0.3",
4039
"@types/jest": "24.0.17",
4140
"graphql": "14.4.2",
4241
"jest": "24.8.0",
@@ -60,9 +59,6 @@
6059
]
6160
},
6261
"dependencies": {
63-
"@hapi/joi": "15.1.0",
64-
"graphql-currency-scalars": "0.0.1",
65-
"graphql-type-json": "0.3.0",
66-
"libphonenumber-js": "1.7.22"
62+
"graphql-type-json": "0.3.0"
6763
}
68-
}
64+
}

src/resolvers/GUID.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import { GraphQLScalarType, GraphQLError, Kind } from 'graphql';
2-
import { assert, string } from '@hapi/joi';
2+
3+
const GUID_REGEX = /^[0-9a-f]{8}-?[0-9a-f]{4}-?[1-5][0-9a-f]{3}-?[89ab][0-9a-f]{3}-?[0-9a-f]{12}$/i;
34

45
const validate = (value: any) => {
5-
assert(value, string(), new TypeError(`Value is not string: ${value}`));
6-
assert(value, string().guid(), new TypeError(`Value is not a valid GUID: ${value}`));
7-
return value;
6+
if (typeof value !== 'string') {
7+
throw new TypeError(`Value is not string: ${value}`);
8+
}
9+
10+
if (!(GUID_REGEX.test(value))) {
11+
throw new TypeError(`Value is not a valid GUID: ${value}`);
12+
}
13+
14+
return value;
815
};
916

1017
export default new GraphQLScalarType({

src/resolvers/HSL.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import { GraphQLScalarType, GraphQLError, Kind } from 'graphql';
2-
import { assert, string } from '@hapi/joi';
2+
3+
const HSL_REGEX = /^hsl\(\s*(-?\d+|-?\d*.\d+)\s*,\s*(-?\d+|-?\d*.\d+)%\s*,\s*(-?\d+|-?\d*.\d+)%\s*\)$/;
34

45
const validate = (value: any) => {
5-
assert(value, string(), new TypeError(`Value is not string: ${value}`));
6-
assert(value, string().regex(/^hsl\(\s*(-?\d+|-?\d*.\d+)\s*,\s*(-?\d+|-?\d*.\d+)%\s*,\s*(-?\d+|-?\d*.\d+)%\s*\)$/),
7-
new TypeError(`Value is not a valid HSL color: ${value}`));
8-
return value;
6+
if (typeof value !== 'string') {
7+
throw new TypeError(`Value is not string: ${value}`);
8+
}
9+
10+
if (!(HSL_REGEX.test(value))) {
11+
throw new TypeError(`Value is not a valid HSL color: ${value}`);
12+
}
13+
14+
return value;
915
};
1016

1117
export default new GraphQLScalarType({

src/resolvers/HSLA.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import { GraphQLScalarType, GraphQLError, Kind } from 'graphql';
2-
import { assert, string } from '@hapi/joi';
2+
3+
const HSLA_REGEX = /^hsla\(\s*(-?\d+|-?\d*.\d+)\s*,\s*(-?\d+|-?\d*.\d+)%\s*,\s*(-?\d+|-?\d*.\d+)%\s*,\s*(-?\d+|-?\d*.\d+)\s*\)$/;
34

45
const validate = (value: any) => {
5-
assert(value, string(), new TypeError(`Value is not string: ${value}`));
6-
assert(value, string().regex(/^hsla\(\s*(-?\d+|-?\d*.\d+)\s*,\s*(-?\d+|-?\d*.\d+)%\s*,\s*(-?\d+|-?\d*.\d+)%\s*,\s*(-?\d+|-?\d*.\d+)\s*\)$/),
7-
new TypeError(`Value is not a valid HSLA color: ${value}`));
6+
if (typeof value !== 'string') {
7+
throw new TypeError(`Value is not string: ${value}`);
8+
}
9+
10+
if (!(HSLA_REGEX.test(value))) {
11+
throw new TypeError(`Value is not a valid HSLA color: ${value}`);
12+
}
13+
814
return value;
915
};
1016

src/resolvers/HexColorCode.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import { GraphQLScalarType, GraphQLError, Kind } from 'graphql';
2-
import { assert, string } from '@hapi/joi';
2+
3+
const HEX_COLOR_CODE = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}|[A-Fa-f0-9]{8})$/;
34

45
const validate = (value: any) => {
5-
assert(value, string(), new TypeError(`Value is not string: ${value}`));
6-
assert(value, string().regex(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}|[A-Fa-f0-9]{8})$/), new TypeError(`Value is not a valid HexColorCode: ${value}`));
6+
if (typeof value !== 'string') {
7+
throw new TypeError(`Value is not string: ${value}`);
8+
}
9+
10+
if (!(HEX_COLOR_CODE.test(value))) {
11+
throw new TypeError(`Value is not a valid HexColorCode: ${value}`);
12+
}
13+
714
return value;
815
};
916

src/resolvers/Hexadecimal.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import { GraphQLScalarType, GraphQLError, Kind } from 'graphql';
2-
import { assert, string } from '@hapi/joi';
2+
3+
const HEXADECIMAL_REGEX = /^[a-f0-9]+$/i;
34

45
const validate = (value: any) => {
5-
assert(value, string(), new TypeError(`Value is not string: ${value}`));
6-
assert(value, string().hex(), new TypeError(`Value is not a valid hexadecimal value: ${value}`));
6+
if (typeof value !== 'string') {
7+
throw new TypeError(`Value is not string: ${value}`);
8+
}
9+
10+
if (!(HEXADECIMAL_REGEX.test(value))) {
11+
throw new TypeError(`Value is not a valid hexadecimal value: ${value}`);
12+
}
13+
714
return value;
815
};
916

src/resolvers/IPv4.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import { GraphQLScalarType, GraphQLError, Kind } from 'graphql';
2-
import { assert, string } from '@hapi/joi';
2+
3+
const IPV4_REGEX = /^(?:(?:(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\/(?:[0-9]|[1-2][0-9]|3[0-2]))?)$/;
34

45
const validate = (value: any) => {
5-
assert(value, string(), new TypeError(`Value is not string: ${value}`));
6-
assert(value, string().ip({ version: `ipv4` }), new TypeError(`Value is not a valid IPv4 address: ${value}`));
6+
if (typeof value !== 'string') {
7+
throw new TypeError(`Value is not string: ${value}`);
8+
}
9+
10+
if (!(IPV4_REGEX.test(value))) {
11+
throw new TypeError(`Value is not a valid IPv4 address: ${value}`);
12+
}
13+
714
return value;
815
};
916

src/resolvers/IPv6.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import { GraphQLScalarType, GraphQLError, Kind } from 'graphql';
2-
import { assert, string } from '@hapi/joi';
32

3+
const IPV6_REGEX = /^(?:(?:(?:[0-9A-Fa-f]{1,4}:){6}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))|::(?:[0-9A-Fa-f]{1,4}:){5}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:0?0?[0-9]|0?[1-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-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))|(?:(?:[0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})?::[0-9A-Fa-f]{1,4}|(?:(?:[0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})?::)(?:\/(?:0?0?[0-9]|0?[1-9][0-9]|1[01][0-9]|12[0-8]))?)$/;
44
const validate = (value: any) => {
5-
assert(value, string(), new TypeError(`Value is not string: ${value}`));
6-
assert(value, string().ip({ version: `ipv6` }), new TypeError(`Value is not a valid IPv6 address: ${value}`));
5+
if (typeof value !== 'string') {
6+
throw new TypeError(`Value is not string: ${value}`);
7+
}
8+
9+
if (!(IPV6_REGEX.test(value))) {
10+
throw new TypeError(`Value is not a valid IPv6 address: ${value}`);
11+
}
12+
713
return value;
814
};
915

0 commit comments

Comments
 (0)