diff --git a/customSchemas/index.ts b/customSchemas/index.ts index b8962dc3..8b4c1c67 100644 --- a/customSchemas/index.ts +++ b/customSchemas/index.ts @@ -39,6 +39,15 @@ export function Uint8ArrayType( return true; }, + (value) => { + if (!(value instanceof Uint8Array)) return 'expected Uint8Array'; + if (min !== undefined && value.byteLength < min) + return `Uint8Array byteLength must be >= ${min}`; + if (max !== undefined && value.byteLength > max) + return `Uint8Array byteLength must be <= ${max}`; + + return 'invalid Uint8Array'; + }, ); uint8ArrayCache.set(key, schema); @@ -86,6 +95,16 @@ export function DateType( return true; }, + (value) => { + if (!(value instanceof Date)) return 'expected Date'; + if (isNaN(value.getTime())) return 'expected valid Date'; + if (typeof min === 'number' && value.getTime() < min) + return `Date timestamp must be >= ${min}`; + if (typeof max === 'number' && value.getTime() > max) + return `Date timestamp must be <= ${max}`; + + return 'invalid Date'; + }, ); dateCache.set(key, schema); diff --git a/package.json b/package.json index 4881565b..3c73edf1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@replit/river", "description": "It's like tRPC but... with JSON Schema Support, duplex streaming and support for service multiplexing. Transport agnostic!", - "version": "0.217.0", + "version": "0.217.1", "type": "module", "exports": { ".": "./dist/router/index.js", diff --git a/router/errors.ts b/router/errors.ts index aa916964..376b0299 100644 --- a/router/errors.ts +++ b/router/errors.ts @@ -90,7 +90,9 @@ export function validationErrorToRiverErrors( if (propertyNames) { return propertyNames.map((prop) => ({ - path: `${error.instancePath}/${prop}`, + path: `${error.instancePath}/${prop + .replace(/~/g, '~0') + .replace(/\//g, '~1')}`, message: error.message, })); }