Skip to content

Commit 56903f1

Browse files
authored
Update README.md
1 parent 118a53e commit 56903f1

File tree

1 file changed

+23
-204
lines changed

1 file changed

+23
-204
lines changed

README.md

Lines changed: 23 additions & 204 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
1-
# node-restify-validation
2-
```diff
3-
-Maintener wanted
4-
```
5-
Validation for REST Services built with [node-restify](https://github.com/mcavage/node-restify) in node.js
1+
# restify-fresh-validation
2+
3+
Up-to-date request validation middleware for [Restify](http://restify.com/)
4+
5+
This is a maintained fork of the long-abandoned, maintainer-unreachable original [node-restify-validation](https://github.com/z0mt3c/node-restify-validation) package.
6+
7+
## WIP
8+
9+
We're in the process of updating the package to address all pending issues, pull requests, vulns and outdated dependencies. Please bear with us for a little longer.
610

11+
<!--
712
[![Build Status](https://travis-ci.org/gchauvet/node-restify-validation.png)](https://travis-ci.org/gchauvet/node-restify-validation)
813
[![Coverage Status](https://coveralls.io/repos/gchauvet/node-restify-validation/badge.png?branch=master)](https://coveralls.io/r/gchauvet/node-restify-validation?branch=master)
914
[![Dependency Status](https://gemnasium.com/gchauvet/node-restify-validation.png)](https://gemnasium.com/gchauvet/node-restify-validation)
15+
-->
1016

1117
## Requirements
12-
* node-restify-validation requires at least restify 2.6.0 since the validation model is defined in the route-object. (https://github.com/mcavage/node-restify/pull/408)
1318

14-
## Simple request validation with node-restify
19+
* Restify 2.6+, but compatible with Restify 7's router changes (2018).
20+
21+
## Simple request validation with Restify
22+
23+
**WIP: this README will get updated as we work through issues.**
24+
1525
Goal of this little project is to have the validation rules / schema as close to the route itself as possible on one hand without messing up the logic with further LOCs on the other hand.
1626

1727
Example:
@@ -119,199 +129,10 @@ Example:
119129
## Use
120130
Simply install it through npm
121131

122-
npm install node-restify-validation
123-
124-
125-
## Documentation powered by swagger
126-
On top of the validation schema the [node-restify-swagger](https://github.com/z0mt3c/node-restify-swagger) library should later-on generate the swagger resources to provide a hands-on documentation.
127-
128-
129-
## Supported validations
130-
131-
```javascript
132-
isRequired: true | function()
133-
equalTo: {'fieldName'}
134-
```
135-
136-
Powered by [node-validator](https://github.com/chriso/validator.js).
137-
138-
contains
139-
equals
140-
is
141-
isAfter
142-
isAlpha
143-
isAlphanumeric
144-
isBefore
145-
isBoolean
146-
isCreditCard
147-
isDate
148-
isDecimal
149-
isDivisibleBy
150-
isEmail
151-
isFloat
152-
isHexColor
153-
isHexadecimal
154-
isIP
155-
isIPNet
156-
isIPv4
157-
isIPv6
158-
isIn
159-
isInt
160-
isNatural
161-
isLowercase
162-
isNumeric
163-
isUUID
164-
isUUIDv3
165-
isUUIDv4
166-
isUppercase
167-
isUrl
168-
max
169-
min
170-
not
171-
notContains
172-
notIn
173-
notRegex
174-
regex
175-
176-
## Nested validation
177-
178-
Validation nesting allows validating content that contains objects and arrays.
179-
180-
### isArray
181-
182-
Validates that specified value is an array. It can take a boolean value or
183-
an object with the following attributes:
184-
185-
- minLength - minimum number of elements (use with `{ isRequired: true }`)
186-
- maxLength - maximum number of elements
187-
- element - validation specification for elements inside the array
188-
189-
190-
```
191-
{
192-
content: {
193-
comments: {
194-
isArray: true
195-
},
196-
emailAddresses: {
197-
isRequired: true,
198-
isArray: {
199-
minLength: 1,
200-
maxLength: 10,
201-
element: { isEmail: true }
202-
}
203-
}
204-
}
205-
}
206-
```
207-
208-
### isObject
209-
210-
Validates that the specified value is an object. It can take a boolean value or
211-
and object with the following attributes:
212-
213-
- properties: validation specification for the contents of the object
214-
215-
```
216-
{
217-
content: {
218-
data: {
219-
isObject: true
220-
},
221-
person: {
222-
isRequired: true,
223-
isObject: {
224-
properties: {
225-
first: { isRequired: true },
226-
last: { isRequired: true },
227-
middle: { isRequired: false },
228-
address: {
229-
isObject: {
230-
properties: {
231-
street: { isRequired: true },
232-
city: { isRequired: true },
233-
state: { isRequired: true }
234-
}
235-
}
236-
},
237-
emails: {
238-
isArray: {
239-
maxLength: 5,
240-
element: { isEmail: true }
241-
}
242-
}
243-
}
244-
}
245-
}
246-
}
247-
}
248-
```
249-
250-
### isDictionary
251-
252-
Validates that specified value is a dictionary. It can take a boolean value or
253-
an object with the following attributes:
132+
npm install restify-fresh-validation
254133

255-
- minLength - minimum number of elements (use with `{ isRequired: true }`)
256-
- maxLength - maximum number of elements
257-
- key - validation specification for the dictionary keys
258-
- value - validation specification for the dictionary values
259-
260-
261-
```
262-
{
263-
content: {
264-
users: {
265-
isDictionary: {
266-
minLength: 1,
267-
maxLength: 10,
268-
key: { isEmail: true },
269-
value: {
270-
isObject: {
271-
name: { isRequired: true },
272-
phone: { isRequired: true },
273-
year: { isInt: true }
274-
}
275-
}
276-
}
277-
}
278-
}
279-
}
280-
```
281-
282-
## Conditional validations
283-
All validation parameters are able to deal with functions as parameters.
284-
285-
For instance the parameterMatches-Condition:
286-
```javascript
287-
module.exports.paramMatches = function (params) {
288-
return conditionalChecker(params, function (matches, value) {
289-
var result;
290-
if (_.isArray(matches)) {
291-
result = _.contains(matches, value);
292-
} else {
293-
result = _.isEqual(matches, value);
294-
}
295-
return result;
296-
});
297-
};
298-
```
299-
Which will be used for instance as follows:
300-
301-
```javascript
302-
var validation = isRequired: require('node-restify-validation');
303-
//...
304-
parameter: { isRequired: validation.when.paramMatches({(scope: '...',) variable: 'param1', matches: ['a', 'b']}) }
305-
```
306-
307-
As result the parameter will only be required when param1 matches a or b. The called method will have a context (this) containing the following information:
308-
309-
* req: the request object
310-
* scope: (real) current scope validation
311-
* validationModel: the complete validation model
312-
* validationRules: the validationRules for the current atribute
313-
* options: the options which have initially been passed
314-
* recentErrors: errors which have been computed until now
134+
<!-- FIXME: CHECK ORIGINAL VALIDATOR.JS FEATURES THAT SEEM TO HAVE BEEN DUPLICATED HERE, DELEGATE TO VALIDATOR INSTEAD -->
135+
<!-- FIXME: EXPLORE CONDITIONAL VALIDATION ORIGINAL INFO -->
315136

316137
## Models
317138

@@ -395,14 +216,12 @@ server.use(restifyValidation.validationPlugin({
395216
}));
396217
```
397218
398-
## Inspiration
399-
node-restify-validation was & is inspired by [backbone.validation](https://github.com/thedersen/backbone.validation).
400-
In terms of validation node-restify-validation makes use of [node-validator](https://github.com/chriso/node-validator).
401-
402219
## License
220+
403221
The MIT License (MIT)
404222
405-
Copyright (c) 2014 Timo Behrmann, Guillaume Chauvet
223+
Copyright (c) 2022 Christophe Porteneuve / Delicious Insights
224+
Original (forked) code copyright (c) 2014 Timo Behrmann, Guillaume Chauvet
406225
407226
Permission is hereby granted, free of charge, to any person obtaining a copy
408227
of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)