Fix changes to InputValidator to resolve accidental breaking changes (#5403)

* Fix changes to InputValidator to resolve accidental breaking changes

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Show changes working by removing no longer required empty props objects

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix type errors

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix async validation errors not being displayed

- And fix validation errors sometimes being displayed multiple times

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Simplify builders for validators

- Replace the boolean type params on `function inputValidator` with a
  new builder `function inputValidatorWithRequiredProps` to make the
  code easier to read

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Introduce unionizing functions for input validators

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Remove RequiredProps type param

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2022-06-10 06:41:29 -04:00
1 parent 3d64425df2
commit 5420780ae0
6 files changed
+244 -98

No files matched your search

+8
View File
@@ -137,6 +137,14 @@ export function hasDefiniteField<Field extends keyof T, T>(field: Field): (val:
return (val): val is T & { [f in Field]-?: NonNullable<T[Field]> } => val[field] != null;
}
export function isPromiseSettledRejected<T>(result: PromiseSettledResult<T>): result is PromiseRejectedResult {
return result.status === "rejected";
}
export function isPromiseSettledFulfilled<T>(result: PromiseSettledResult<T>): result is PromiseFulfilledResult<T> {
return result.status === "fulfilled";
}
export function isErrnoException(error: unknown): error is NodeJS.ErrnoException {
return isObject(error)
&& hasOptionalTypedProperty(error, "code", isString)