secret
Created

starting to define schema for Resource

  • Download Gist
partial.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
var description = {
"default": "",
"description": "the description of the property"
};
 
var message = {
"default": "",
"description": "custom error message to be shown on error"
};
 
var conform = {
"default": function(val) {
return val;
},
"description": "value must satisify this custom method"
};
 
var fakeSchema = {
"String": {
"default": {
"default": "",
"description": "the default value ( a string )"
},
"description": description,
"format": {
"default": "",
"description": "a pre-defined format the value should match",
"enum": ["email", "url"]
},
"message": message,
"minLength": {
"default": 0,
"description": "the minimum length of the string"
},
"maxLength": {
"default": 10,
"description": "the maximum length of the string"
},
"enum": {
"default": "[]",
"description": "value must be contained in this array"
},
"pattern": {
"default": new RegExp(),
"description": "value must satisify this regex pattern"
},
"conform": conform
},
 
"Number": {
"default": {
"default": 0,
"description": "the default value ( a number )"
},
"description": description,
"message": message,
"minimum": {
"default": 0,
"description": "the default value ( a number )"
},
"maximum": {
"default": 0,
"description": "the default value ( a number )"
},
"conform": conform
},
 
"Boolean": {
"default": {
"default": false,
"description": "the default value ( a boolean )"
},
"description": description,
"message": message
},
 
"Array": {
"default": {
"default": "[]",
"description": "the default value ( an array )"
},
"description": description,
"message": message
},
 
"Object": {
"default": {
"default": "{}",
"description": "the default value ( an object )"
},
"description": description,
"message": message
}
 
};

Number actually have "within" defined as an array of two: minimum, maximum
String have "Length" likewise an array :minLength, maxLength - have to say that they fail
The exclusiveMinimum.. Are actually implemented in revalidator, so should easily be in the resourceful.
Sanitize is currently a chained function if using bultins (abs, upper...) , but a property if you customize
I made https://github.com/raix/resourceful/wiki/Define-resources where i tried to (tried some markdown, not quite there...) but then i discovered the revalidator api witch speakes of the json schema. Well still learning, kind of a newbe here :)

There's a bunch of stuff missing and wrong here. This isn't for review, it was a reference for myself.

No need to point it out. It's why I made a ticket and linked this from https://github.com/flatiron/resourceful/issues/115

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.