This plugin for Joi adds validation for Neo4j (Cypher) types that are not mapped to native javascript, as explained here
Type | Supported |
---|---|
Date | ✅ |
Time | ❌ |
LocalTime | ❌ |
DateTime | ✅ |
LocalDateTime | ✅ |
Duration | ❌ |
Point | ✅ |
Package | version |
---|---|
neo4j-driver | >=4.0.0 |
joi | >=17 |
yarn add joi4j
# or
npm install joi4j
// import necessary validators and extend Joi
const { neo4jDate, neo4jDateTime } = require('joi4j');
const Joi = require('joi').extend(neo4jDate, neo4jDateTime);
try {
const schema = Joi.neo4jDate();
const date = await schema.validateAsync("2019-12-08");
// date is a neo4j.types.Date
} catch (error) {
...
}
The library exports a type to help you extend Joi and benefit from ts autocomplete:
import BaseJoi, { Root } from 'joi';
import { Joi4j, neo4jPoint, neo4jDate } = require('joi4j');
// Extend BaseJoi and add Joi4j typing
const Joi: Root & Joi4j = BaseJoi.extend(neo4jPoint, neo4jDate);
Validates that the input is a correct Neo4j Date instance. If the convert
preference is true
(enabled by default), a string or native javascript Date
object will be converted to a Neo4j Date.
const schema = Joi.neo4jDate();
await schema.validateAsync('2019-12-08');
Specifies the value must be greater than or equal to date
.
Specifies the value must be less than or equal to date
.
Specifies the value must be greater than date
.
Specifies the value must be less than date
.
Validates that the input is a correct Neo4j DateTime instance. If the convert
preference is true
(enabled by default), a string or native javascript Date
. object will be converted to a Neo4j DateTime.
const schema = Joi.neo4jDateTime();
await schema.validateAsync('2019-12-08T13:59:18+02:00');
Specifies the value must be greater than or equal to date
.
Specifies the value must be less than or equal to date
.
Specifies the value must be greater than date
.
Specifies the value must be less than date
.
Validates that the input is a correct Neo4j LocalDateTime instance. If the convert
preference is true
(enabled by default), a string or native javascript Date
. object will be converted to a Neo4j LocalDateTime.
const schema = Joi.neo4jLocalDateTime();
await schema.validateAsync('2019-12-08T13:59:18+02:00');
Specifies the value must be greater than or equal to date
.
Specifies the value must be less than or equal to date
.
Specifies the value must be greater than date
.
Specifies the value must be less than date
.
Validates that the input is a correct Neo4j Point.
If the convert
preference is true
(enabled by default), a key-value pair object will be converted to a Neo4j Point if specified. If not provided, the srid will be assumed from the keys.
const schema = Joi.neo4jPoint();
await schema.validateAsync({ lon: 2.154007, lat: 41.390205 });
Validates that the point is a correct coordinates point (latitude, longitude [, height])
Validates that the point is a correct coordinates point (x, y [, z])
.
Validates that the point is a correct 2D point (no height or z is given).
Validates that the point is a correct 2D point (either height or z is given).