Skip to content

Commit 1791fe8

Browse files
authored
Fix back compat (#38)
1 parent 102484e commit 1791fe8

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

.changeset/proud-bees-end.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nrfcloud/ts-json-schema-transformer": patch
3+
---
4+
5+
fix back compat with older runtimes

src/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,19 @@ export function noop(arg: unknown) {
207207
return arg;
208208
}
209209

210+
/**
211+
* @internal
212+
* @deprecated
213+
*/
214+
export function validationAssertion(validator: ValidateFunction<unknown>, obj: unknown) {
215+
if (!validator(obj)) {
216+
throw new ValidationError(`Validation error: ${validator.errors?.map(error => JSON.stringify(error)).join(", ")}`, {
217+
cause: validator.errors,
218+
});
219+
}
220+
return obj;
221+
}
222+
210223
type Exact<T, U> = IfEquals<T, U, T, never>;
211224
type IfEquals<T, U, Y = unknown, N = never> = (<G>() => G extends T ? 1 : 2) extends (<G>() => G extends U ? 1 : 2) ? Y
212225
: N;

0 commit comments

Comments
 (0)