Skip to content

Commit c3bbff9

Browse files
committed
Do not use 'util' imports
1 parent 0a80c9a commit c3bbff9

File tree

5 files changed

+20
-27
lines changed

5 files changed

+20
-27
lines changed

src/schema-generation/filter-input-types/filter-fields.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { getNamedType, GraphQLInputType, GraphQLList, GraphQLNonNull } from 'graphql';
22
import { ZonedDateTime } from 'js-joda';
3-
import { isArray } from 'util';
43
import { EnumType, Field, ScalarType, Type, TypeKind } from '../../model';
54
import {
65
BinaryOperationQueryNode,
@@ -264,7 +263,7 @@ export class AndFilterField implements FilterField {
264263
}
265264

266265
getFilterNode(sourceNode: QueryNode, filterValue: AnyValue): QueryNode {
267-
if (!isArray(filterValue) || !filterValue.length) {
266+
if (!Array.isArray(filterValue) || !filterValue.length) {
268267
return new ConstBoolQueryNode(true);
269268
}
270269
const values = (filterValue || []) as ReadonlyArray<PlainObject>;
@@ -285,7 +284,7 @@ export class OrFilterField implements FilterField {
285284
}
286285

287286
getFilterNode(sourceNode: QueryNode, filterValue: AnyValue): QueryNode {
288-
if (!isArray(filterValue)) {
287+
if (!Array.isArray(filterValue)) {
289288
return new ConstBoolQueryNode(true); // regard as omitted
290289
}
291290
const values = filterValue as ReadonlyArray<PlainObject>;

src/schema/scalars/fixed-point-decimals.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { GraphQLError, GraphQLScalarType, Kind, print, ValueNode } from 'graphql';
2-
import { inspect } from 'util';
32

43
function createFixedPointDecimalType(decimals: number) {
54
const typeName = `Decimal${decimals}`;
@@ -12,18 +11,18 @@ function createFixedPointDecimalType(decimals: number) {
1211
function coerceFixedPointDecimal(value: unknown) {
1312
// same logic like Float
1413
if (typeof value !== 'number' || !isFinite(value)) {
15-
throw new GraphQLError(`${typeName} cannot represent non numeric value: `.concat(inspect(value)));
14+
throw new GraphQLError(`${typeName} cannot represent non numeric value: `.concat(JSON.stringify(value)));
1615
}
1716

1817
const num = Number(value.toFixed(decimals));
1918
if (num > maxValue) {
2019
throw new GraphQLError(
21-
`${typeName} cannot represent value larger than ${maxValueStr}: `.concat(inspect(value))
20+
`${typeName} cannot represent value larger than ${maxValueStr}: `.concat(JSON.stringify(value))
2221
);
2322
}
2423
if (num < minValue) {
2524
throw new GraphQLError(
26-
`${typeName} cannot represent value smaller than ${minValueStr}: `.concat(inspect(value))
25+
`${typeName} cannot represent value smaller than ${minValueStr}: `.concat(JSON.stringify(value))
2726
);
2827
}
2928

@@ -42,12 +41,12 @@ function createFixedPointDecimalType(decimals: number) {
4241
const num = Number(value.toFixed(decimals));
4342
if (num > maxValue) {
4443
throw new GraphQLError(
45-
`${typeName} cannot represent value larger than ${maxValueStr}: `.concat(inspect(value))
44+
`${typeName} cannot represent value larger than ${maxValueStr}: `.concat(JSON.stringify(value))
4645
);
4746
}
4847
if (num < minValue) {
4948
throw new GraphQLError(
50-
`${typeName} cannot represent value smaller than ${minValueStr}: `.concat(inspect(value))
49+
`${typeName} cannot represent value smaller than ${minValueStr}: `.concat(JSON.stringify(value))
5150
);
5251
}
5352

src/schema/scalars/int53.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
import { GraphQLError, GraphQLScalarType, Kind, print, ValueNode } from 'graphql';
2-
import { inspect } from 'util';
32

43
function coerceInt53(value: unknown) {
54
if (typeof value !== 'number' || !Number.isInteger(value)) {
6-
throw new GraphQLError(`Int53 cannot represent non-integer value: ${inspect(value)}`);
5+
throw new GraphQLError(`Int53 cannot represent non-integer value: ${JSON.stringify(value)}`);
76
}
87

98
if (value > Number.MAX_SAFE_INTEGER) {
109
throw new GraphQLError(
11-
`Int53 cannot represent value larger than ${Number.MAX_SAFE_INTEGER}: ${inspect(value)}`
10+
`Int53 cannot represent value larger than ${Number.MAX_SAFE_INTEGER}: ${JSON.stringify(value)}`
1211
);
1312
}
1413

1514
if (value < Number.MIN_SAFE_INTEGER) {
1615
throw new GraphQLError(
17-
`Int53 cannot represent value smaller than ${Number.MIN_SAFE_INTEGER}: ${inspect(value)}`
16+
`Int53 cannot represent value smaller than ${Number.MIN_SAFE_INTEGER}: ${JSON.stringify(value)}`
1817
);
1918
}
2019

src/utils/error-with-cause.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { inspect } from 'util';
2-
31
/**
42
* ErrorWithCause extends the default node Error to support causes.
53
* Each error can have one cause. The stack of the causing error is appended
@@ -26,5 +24,5 @@ function extractMessage(message: string, cause?: Error | unknown): string {
2624
if (cause instanceof Error) {
2725
return `${message}: ${cause.message}`;
2826
}
29-
return `${message}: NonError: ${inspect(cause)}`;
27+
return `${message}: NonError: ${cause}`;
3028
}

src/utils/visitor.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import { isArray } from 'util';
2-
31
export type VisitResult<T> = {
4-
recurse?: boolean
5-
newValue: T
6-
}
2+
recurse?: boolean;
3+
newValue: T;
4+
};
75

86
export type Visitor<T> = {
9-
enter?(object: T, key: string|undefined): VisitResult<T>,
10-
leave?(object: T, key: string|undefined): T
7+
enter?(object: T, key: string | undefined): VisitResult<T>;
8+
leave?(object: T, key: string | undefined): T;
119
};
1210

1311
export function visitObject<T>(node: T, visitor: Visitor<T>): T {
@@ -44,24 +42,24 @@ function visitObjectProperties<T>(object: T, visitor: Visitor<T>): T {
4442
return newObj;
4543
}
4644

47-
function visitObjectOrArray<T>(nodeOrArray: T|T[], visitor: Visitor<any>, key: string|undefined): T|T[] {
45+
function visitObjectOrArray<T>(nodeOrArray: T | T[], visitor: Visitor<any>, key: string | undefined): T | T[] {
4846
if (typeof nodeOrArray != 'object' || nodeOrArray === null) {
4947
return nodeOrArray;
5048
}
51-
if (!isArray(nodeOrArray)) {
49+
if (!Array.isArray(nodeOrArray)) {
5250
return visitObject0(nodeOrArray as T, visitor, key);
5351
}
5452
return nodeOrArray.map(item => visitObject0(item, visitor, key));
5553
}
5654

57-
function enter<T>(obj: T, visitor: Visitor<T>, key: string|undefined): VisitResult<T> {
55+
function enter<T>(obj: T, visitor: Visitor<T>, key: string | undefined): VisitResult<T> {
5856
if (visitor.enter) {
5957
return visitor.enter(obj, key);
6058
}
6159
return { newValue: obj };
6260
}
6361

64-
function leave<T>(obj: T, visitor: Visitor<T>, key: string|undefined): T {
62+
function leave<T>(obj: T, visitor: Visitor<T>, key: string | undefined): T {
6563
if (visitor.leave) {
6664
return visitor.leave(obj, key);
6765
}

0 commit comments

Comments
 (0)