diff --git a/.npmrc b/.npmrc new file mode 100644 index 00000000..41583e36 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +@jsr:registry=https://npm.jsr.io diff --git a/package.json b/package.json index ed84669f..4a122581 100644 --- a/package.json +++ b/package.json @@ -100,6 +100,9 @@ "schemas", "generate" ], + "dependencies": { + "@jsr/nrfcloud__validate-with-typebox": "1.0.0" + }, "peerDependencies": { "@hello.nrfcloud.com/proto-map": "^16.6.4", "@sinclair/typebox": "^0.34.48", diff --git a/validator/validateWithTypeBox.ts b/validator/validateWithTypeBox.ts index b9d16a16..c8f00354 100644 --- a/validator/validateWithTypeBox.ts +++ b/validator/validateWithTypeBox.ts @@ -1,24 +1,4 @@ -import type { Static, TSchema } from '@sinclair/typebox' -import { TypeCompiler, type ValueError } from '@sinclair/typebox/compiler' - /** - * Validate the value against the given TypeBox schema + * Re-export validateWithTypeBox from the shared package */ -export const validateWithTypeBox = ( - schema: T, -): ((value: unknown) => - | { value: Static } - | { - errors: ValueError[] - }) => { - const C = TypeCompiler.Compile(schema) - return (value: unknown) => { - const firstError = C.Errors(value).First() - if (firstError !== undefined) { - return { - errors: [...C.Errors(value)], - } - } - return { value: value as Static } - } -} +export { validateWithTypeBox } from '@jsr/nrfcloud__validate-with-typebox'