Skip to content

Installation

Install the package in your app with:

bash
npm install json-rest-schema

If you are working in this repo and want to run the documentation site locally:

bash
npm install
npm run docs:dev

Build the full static site, including the standalone React and Vue demo apps, with:

bash
npm run docs:build

Preview that built site locally with:

bash
npm run docs:preview

Upgrading to 1.0.17

Version 1.0.17 intentionally replaces the old permissive temporal behavior. There are no compatibility aliases or legacy parsers:

  • date, time, and dateTime now validate JSON strings and return the exact input string unchanged. They no longer return JavaScript Date objects or parse numbers, locale text, SQL datetime strings, or other Date.parse() inputs.
  • date accepts only a real calendar date written as YYYY-MM-DD.
  • time accepts an offset-free HH:MM[:SS[.fraction]] value.
  • dateTime accepts a calendar-valid RFC 3339 datetime with seconds and a mandatory Z or ±HH:MM offset.
  • timestamp has been removed. Use epochMilliseconds or epochSeconds; both accept an integer number or canonical base-10 integer string and return a number.
  • temporalPrecision limits fractional-second digits for time and dateTime. Excess precision is rejected, never truncated.
  • Applied defaults now pass through the normal type and validator pipeline.

Use this prompt with an agent working on an existing application:

Upgrade this application to json-rest-schema 1.0.17 without adding compatibility or legacy parsing. Find every temporal schema field and trace its producers, consumers, HTTP representation, database mapping, defaults, fixtures, and tests. Replace type: 'timestamp' with epochMilliseconds or epochSeconds only after verifying the actual unit. Keep date values as valid YYYY-MM-DD strings, time values as offset-free HH:MM[:SS[.fraction]] strings, and dateTime values as RFC 3339 strings with seconds and an explicit timezone. Convert JavaScript Date objects explicitly at application boundaries; do not make the schema accept them. For datetime-local controls, apply the product's intended timezone before producing RFC 3339—do not append Z unless the entered value is defined as UTC. Remove code that expects validation to return a Date or normalize a temporal string. Make storage adapters translate between these wire strings and database-native values. Update defaults to the new forms. Add tests for impossible dates, timezone-required datetimes, fractional precision, JSON round trips, repeated validation, captured HTTP payloads, and the relevant database round trip. Run the full test, lint, typecheck, and build suites and report every changed temporal contract.

The published docs site is the best place to read the same manual as shorter chapters for:

  • create / replace / patch semantics
  • nested object and array contracts
  • recursive runtime validation and transport export
  • field introspection and path-scoped validation
  • React Hook Form, Vue + Vuetify, and VeeValidate adapters
  • demo app walkthroughs

GPL-3.0-only