Ignore:
Timestamp:
03/05/14 22:44:48 (11 years ago)
Author:
hendrikvanantwerpen
Message:

Completed migration to API, without CouchDB proxy.

Move to API is now completed. The full API is password protected, a very
limited API is exposed for respondents, which works with secrets that
are passed in URLs.

Serverside the HTTPResult class was introduced, which is similar to
Promises, but specifically for HTTP. It carries a status code and
response and makes it easier to extract parts of async handling in
separate functions.

Fixed a bug in our schema (it seems optional attributes don't exist but
a required list does). Verification of our schema by grunt-tv4 didn't
work yet. Our schema is organized the wrong way (this is fixable),
but the json-schema schema has problems with simple types and $refs.

Location:
Dev/trunk/src/node_modules/tv4
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/src/node_modules/tv4/README.md

    r484 r487  
    8585## Cyclical JavaScript objects
    8686
    87 While they don't occur in proper JSON, JavaScript does support self-referencing objects. Any of the above calls support an optional final argument, checkRecursive. If true, tv4 will handle self-referencing objects properly - this slows down validation slightly, but that's better than a hanging script.
     87While they don't occur in proper JSON, JavaScript does support self-referencing objects. Any of the above calls support an optional third argument: `checkRecursive`. If true, tv4 will handle self-referencing objects properly - this slows down validation slightly, but that's better than a hanging script.
    8888
    8989Consider this data, notice how both `a` and `b` refer to each other:
     
    9999```
    100100
    101 If the final checkRecursive argument were missing, this would throw a "too much recursion" error.
    102 
    103 To enable supprot for this pass `true` as additional argument to any of the regular validation methods:
     101If the `checkRecursive` argument were missing, this would throw a "too much recursion" error.
     102
     103To enable support for this, pass `true` as additional argument to any of the regular validation methods:
    104104
    105105```javascript
    106106tv4.validate(a, aSchema, true);
    107 tv4.validate(a, schema, asynchronousFunction, true);
    108 
    109107tv4.validateResult(data, aSchema, true);
    110108tv4.validateMultiple(data, aSchema, true);
    111109```
    112110
     111## The `banUnknownProperties` flag
     112
     113Sometimes, it is desirable to flag all unknown properties as an error.  This is especially useful during development, to catch typos and the like, even when extra custom-defined properties are allowed.
     114
     115As such, tv4 implements ["ban unknown properties" mode](https://github.com/json-schema/json-schema/wiki/ban-unknown-properties-mode-\(v5-proposal\)), enabled by a fourth-argument flag:
     116
     117```javascript
     118tv4.validate(data, schema, checkRecursive, true);
     119tv4.validateResult(data, schema, checkRecursive, true);
     120tv4.validateMultiple(data, schema, checkRecursive, true);
     121```
     122
    113123## API
    114124
     
    229239##### addFormat(format, validationFunction)
    230240
    231 Add a custom format validator.
     241Add a custom format validator. (There are no built-in format validators.)
    232242
    233243* `format` is a string, corresponding to the `"format"` value in schemas.
  • Dev/trunk/src/node_modules/tv4/package.json

    r484 r487  
    11{
    22  "name": "tv4",
    3   "version": "1.0.11",
     3  "version": "1.0.16",
    44  "author": {
    55    "name": "Geraint Luff"
     
    5151    "grunt-markdown": "~0.3.0",
    5252    "grunt-component": "~0.1.4",
    53     "grunt-push-release": "~0.1.1"
     53    "grunt-push-release": "~0.1.1",
     54    "grunt-regex-replace": "~0.2.5"
    5455  },
    5556  "engines": {
     
    5758  },
    5859  "scripts": {
    59     "test": "grunt test"
     60    "test": "grunt test",
     61    "prepublish": "grunt prepublish"
    6062  },
    61   "readme": "# Tiny Validator (for v4 JSON Schema)\n\n[![Build Status](https://secure.travis-ci.org/geraintluff/tv4.png?branch=master)](http://travis-ci.org/geraintluff/tv4) [![Dependency Status](https://gemnasium.com/geraintluff/tv4.png)](https://gemnasium.com/geraintluff/tv4) [![NPM version](https://badge.fury.io/js/tv4.png)](http://badge.fury.io/js/tv4)\n\nUse [json-schema](http://json-schema.org/) [draft v4](http://json-schema.org/latest/json-schema-core.html) to validate simple values and complex objects using a rich [validation vocabulary](http://json-schema.org/latest/json-schema-validation.html) ([examples](http://json-schema.org/examples.html)).\n\nThere is support for `$ref` with JSON Pointer fragment paths (```other-schema.json#/properties/myKey```).\n\n## Usage 1: Simple validation\n\n```javascript\nvar valid = tv4.validate(data, schema);\n```\n\nIf validation returns ```false```, then an explanation of why validation failed can be found in ```tv4.error```.\n\nThe error object will look something like:\n```json\n{\n    \"code\": 0,\n    \"message\": \"Invalid type: string\",\n    \"dataPath\": \"/intKey\",\n    \"schemaKey\": \"/properties/intKey/type\"\n}\n```\n\nThe `\"code\"` property will refer to one of the values in `tv4.errorCodes` - in this case, `tv4.errorCodes.INVALID_TYPE`.\n\nTo enable external schema to be referenced, you use:\n```javascript\ntv4.addSchema(url, schema);\n```\n\nIf schemas are referenced (```$ref```) but not known, then validation will return ```true``` and the missing schema(s) will be listed in ```tv4.missing```. For more info see the API documentation below.\n\n## Usage 2: Multi-threaded validation\n\nStoring the error and missing schemas does not work well in multi-threaded environments, so there is an alternative syntax:\n\n```javascript\nvar result = tv4.validateResult(data, schema);\n```\n\nThe result will look something like:\n```json\n{\n    \"valid\": false,\n    \"error\": {...},\n    \"missing\": [...]\n}\n```\n\n## Usage 3: Multiple errors\n\nNormally, `tv4` stops when it encounters the first validation error.  However, you can collect an array of validation errors using:\n\n```javascript\nvar result = tv4.validateMultiple(data, schema);\n```\n\nThe result will look something like:\n```json\n{\n    \"valid\": false,\n    \"errors\": [\n        {...},\n        ...\n    ],\n    \"missing\": [...]\n}\n```\n\n## Asynchronous validation\n\nSupport for asynchronous validation (where missing schemas are fetched) can be added by including an extra JavaScript file.  Currently, the only version requires jQuery (`tv4.async-jquery.js`), but the code is very short and should be fairly easy to modify for other libraries (such as MooTools).\n\nUsage:\n\n```javascript\ntv4.validate(data, schema, function (isValid, validationError) { ... });\n```\n\n`validationFailure` is simply taken from `tv4.error`.\n\n## Cyclical JavaScript objects\n\nWhile they don't occur in proper JSON, JavaScript does support self-referencing objects. Any of the above calls support an optional final argument, checkRecursive. If true, tv4 will handle self-referencing objects properly - this slows down validation slightly, but that's better than a hanging script.\n\nConsider this data, notice how both `a` and `b` refer to each other:\n\n```javascript\nvar a = {};\nvar b = { a: a };\na.b = b;\nvar aSchema = { properties: { b: { $ref: 'bSchema' }}};\nvar bSchema = { properties: { a: { $ref: 'aSchema' }}};\ntv4.addSchema('aSchema', aSchema);\ntv4.addSchema('bSchema', bSchema);\n```\n\nIf the final checkRecursive argument were missing, this would throw a \"too much recursion\" error. \n\nTo enable supprot for this pass `true` as additional argument to any of the regular validation methods: \n\n```javascript\ntv4.validate(a, aSchema, true);\ntv4.validate(a, schema, asynchronousFunction, true);\n\ntv4.validateResult(data, aSchema, true); \ntv4.validateMultiple(data, aSchema, true);\n```\n\n## API\n\nThere are additional api commands available for more complex use-cases:\n\n##### addSchema(uri, schema)\nPre-register a schema for reference by other schema and synchronous validation.\n\n````js\ntv4.addSchema('http://example.com/schema', { ... });\n````\n\n* `uri` the uri to identify this schema.\n* `schema` the schema object.\n\nSchemas that have their `id` property set can be added directly.\n\n````js\ntv4.addSchema({ ... });\n````\n\n##### getSchema(uri)\n\nReturn a schema from the cache.\n\n* `uri` the uri of the schema (may contain a `#` fragment)\n\n````js\nvar schema = tv4.getSchema('http://example.com/schema');\n````\n\n##### getSchemaMap()\n\nReturn a shallow copy of the schema cache, mapping schema document URIs to schema objects.\n\n````\nvar map = tv4.getSchemaMap();\n\nvar schema = map[uri];\n````\n\n##### getSchemaUris(filter)\n\nReturn an Array with known schema document URIs.\n\n* `filter` optional RegExp to filter URIs\n\n````\nvar arr = tv4.getSchemaUris();\n\n// optional filter using a RegExp\nvar arr = tv4.getSchemaUris(/^https?://example.com/);\n````\n\n##### getMissingUris(filter)\n\nReturn an Array with schema document URIs that are used as `$ref` in known schemas but which currently have no associated schema data.\n\nUse this in combination with `tv4.addSchema(uri, schema)` to preload the cache for complete synchronous validation with.\n\n* `filter` optional RegExp to filter URIs\n\n````\nvar arr = tv4.getMissingUris();\n\n// optional filter using a RegExp\nvar arr = tv4.getMissingUris(/^https?://example.com/);\n````\n\n##### dropSchemas()\n\nDrop all known schema document URIs from the cache.\n\n````\ntv4.dropSchemas();\n````\n\n##### freshApi()\n\nReturn a new tv4 instance with no shared state.\n\n````\nvar otherTV4 = tv4.freshApi();\n````\n\n##### reset()\n\nManually reset validation status from the simple `tv4.validate(data, schema)`. Although tv4 will self reset on each validation there are some implementation scenarios where this is useful.\n\n````\ntv4.reset();\n````\n\n##### language(code)\n\nSelect the language map used for reporting.\n\n* `code` is a language code, like `'en'` or `'en-gb'`\n\n````\ntv4.language('en-gb');\n````\n\n##### addLanguage(code, map)\n\nAdd a new language map for selection by `tv4.language(code)`\n\n* `code` is new language code\n* `map` is an object mapping error IDs or constant names (e.g. `103` or `\"NUMBER_MAXIMUM\"`) to language strings.\n\n````\ntv4.addLanguage('fr', { ... });\n\n// select for use\ntv4.language('fr')\n````\n\n##### addFormat(format, validationFunction)\n\nAdd a custom format validator.\n\n* `format` is a string, corresponding to the `\"format\"` value in schemas.\n* `validationFunction` is a function that either returns:\n  * `null` (meaning no error)\n  * an error string (explaining the reason for failure)\n\n````\ntv4.addFormat('decimal-digits', function (data, schema) {\n\tif (typeof data === 'string' && !/^[0-9]+$/.test(data)) {\n\t\treturn null;\n\t}\n\treturn \"must be string of decimal digits\";\n});\n````\n\nAlternatively, multiple formats can be added at the same time using an object:\n````\ntv4.addFormat({\n\t'my-format': function () {...},\n\t'other-format': function () {...}\n});\n````\n\n## Demos\n\n### Basic usage\n<div class=\"content inline-demo\" markdown=\"1\" data-demo=\"demo1\">\n<pre class=\"code\" id=\"demo1\">\nvar schema = {\n\t\"items\": {\n\t\t\"type\": \"boolean\"\n\t}\n};\nvar data1 = [true, false];\nvar data2 = [true, 123];\n\nalert(\"data 1: \" + tv4.validate(data1, schema)); // true\nalert(\"data 2: \" + tv4.validate(data2, schema)); // false\nalert(\"data 2 error: \" + JSON.stringify(tv4.error, null, 4));\n</pre>\n</div>\n\n### Use of <code>$ref</code>\n<div class=\"content inline-demo\" markdown=\"1\" data-demo=\"demo2\">\n<pre class=\"code\" id=\"demo2\">\nvar schema = {\n\t\"type\": \"array\",\n\t\"items\": {\"$ref\": \"#\"}\n};\nvar data1 = [[], [[]]];\nvar data2 = [[], [true, []]];\n\nalert(\"data 1: \" + tv4.validate(data1, schema)); // true\nalert(\"data 2: \" + tv4.validate(data2, schema)); // false\n</pre>\n</div>\n\n### Missing schema\n<div class=\"content inline-demo\" markdown=\"1\" data-demo=\"demo3\">\n<pre class=\"code\" id=\"demo3\">\nvar schema = {\n\t\"type\": \"array\",\n\t\"items\": {\"$ref\": \"http://example.com/schema\" }\n};\nvar data = [1, 2, 3];\n\nalert(\"Valid: \" + tv4.validate(data, schema)); // true\nalert(\"Missing schemas: \" + JSON.stringify(tv4.missing));\n</pre>\n</div>\n\n### Referencing remote schema\n<div class=\"content inline-demo\" markdown=\"1\" data-demo=\"demo4\">\n<pre class=\"code\" id=\"demo4\">\ntv4.addSchema(\"http://example.com/schema\", {\n\t\"definitions\": {\n\t\t\"arrayItem\": {\"type\": \"boolean\"}\n\t}\n});\nvar schema = {\n\t\"type\": \"array\",\n\t\"items\": {\"$ref\": \"http://example.com/schema#/definitions/arrayItem\" }\n};\nvar data1 = [true, false, true];\nvar data2 = [1, 2, 3];\n\nalert(\"data 1: \" + tv4.validate(data1, schema)); // true\nalert(\"data 2: \" + tv4.validate(data2, schema)); // false\n</pre>\n</div>\n\n## Supported platforms\n\n* Node.js\n* All modern browsers\n* IE >= 7\n\n## Installation\n\nYou can manually download [`tv4.js`](https://raw.github.com/geraintluff/tv4/master/tv4.js) or the minified [`tv4.min.js`](https://raw.github.com/geraintluff/tv4/master/tv4.min.js) and include it in your html to create the global `tv4` variable.\n\nAlternately use it as a CommonJS module:\n\n````js\nvar tv4 = require('tv4');\n````\n\n#### npm\n\n````\n$ npm install tv4\n````\n\n#### bower\n\n````\n$ bower install tv4\n````\n\n#### component.io\n\n````\n$ component install geraintluff/tv4\n````\n\n## Build and test\n\nYou can rebuild and run the node and browser tests using node.js and [grunt](http://http://gruntjs.com/):\n\nMake sure you have the global grunt cli command:\n````\n$ npm install grunt-cli -g\n````\n\nClone the git repos, open a shell in the root folder and install the development dependencies:\n\n````\n$ npm install\n````\n\nRebuild and run the tests:\n````\n$ grunt\n````\n\nIt will run a build and display one Spec-style report for the node.js and two Dot-style reports for both the plain and minified browser tests (via phantomJS). You can also use your own browser to manually run the suites by opening [`test/index.html`](http://geraintluff.github.io/tv4/test/index.html) and [`test/index-min.html`](http://geraintluff.github.io/tv4/test/index-min.html).\n\n## Contributing\n\nPull-requests for fixes and expansions are welcome. Edit the partial files in `/source` and add your tests in a suitable suite or folder under `/test/tests` and run `grunt` to rebuild and run the test suite. Try to maintain an idiomatic coding style and add tests for any new features. It is recommend to discuss big changes in an Issue.\n\n## Packages using tv4\n\n* [chai-json-schema](http://chaijs.com/plugins/chai-json-schema) is a [Chai Assertion Library](http://chaijs.com) plugin to assert values against json-schema.\n* [grunt-tv4](http://www.github.com/Bartvds/grunt-tv4) is a plugin for [Grunt](http://http://gruntjs.com/) that uses tv4 to bulk validate json files.\n\n## License\n\nThe code is available as \"public domain\", meaning that it is completely free to use, without any restrictions at all.  Read the full license [here](http://geraintluff.github.com/tv4/LICENSE.txt).\n\nIt's also available under an [MIT license](http://jsonary.com/LICENSE.txt).\n",
     63  "readme": "# Tiny Validator (for v4 JSON Schema)\n\n[![Build Status](https://secure.travis-ci.org/geraintluff/tv4.png?branch=master)](http://travis-ci.org/geraintluff/tv4) [![Dependency Status](https://gemnasium.com/geraintluff/tv4.png)](https://gemnasium.com/geraintluff/tv4) [![NPM version](https://badge.fury.io/js/tv4.png)](http://badge.fury.io/js/tv4)\n\nUse [json-schema](http://json-schema.org/) [draft v4](http://json-schema.org/latest/json-schema-core.html) to validate simple values and complex objects using a rich [validation vocabulary](http://json-schema.org/latest/json-schema-validation.html) ([examples](http://json-schema.org/examples.html)).\n\nThere is support for `$ref` with JSON Pointer fragment paths (```other-schema.json#/properties/myKey```).\n\n## Usage 1: Simple validation\n\n```javascript\nvar valid = tv4.validate(data, schema);\n```\n\nIf validation returns ```false```, then an explanation of why validation failed can be found in ```tv4.error```.\n\nThe error object will look something like:\n```json\n{\n    \"code\": 0,\n    \"message\": \"Invalid type: string\",\n    \"dataPath\": \"/intKey\",\n    \"schemaKey\": \"/properties/intKey/type\"\n}\n```\n\nThe `\"code\"` property will refer to one of the values in `tv4.errorCodes` - in this case, `tv4.errorCodes.INVALID_TYPE`.\n\nTo enable external schema to be referenced, you use:\n```javascript\ntv4.addSchema(url, schema);\n```\n\nIf schemas are referenced (```$ref```) but not known, then validation will return ```true``` and the missing schema(s) will be listed in ```tv4.missing```. For more info see the API documentation below.\n\n## Usage 2: Multi-threaded validation\n\nStoring the error and missing schemas does not work well in multi-threaded environments, so there is an alternative syntax:\n\n```javascript\nvar result = tv4.validateResult(data, schema);\n```\n\nThe result will look something like:\n```json\n{\n    \"valid\": false,\n    \"error\": {...},\n    \"missing\": [...]\n}\n```\n\n## Usage 3: Multiple errors\n\nNormally, `tv4` stops when it encounters the first validation error.  However, you can collect an array of validation errors using:\n\n```javascript\nvar result = tv4.validateMultiple(data, schema);\n```\n\nThe result will look something like:\n```json\n{\n    \"valid\": false,\n    \"errors\": [\n        {...},\n        ...\n    ],\n    \"missing\": [...]\n}\n```\n\n## Asynchronous validation\n\nSupport for asynchronous validation (where missing schemas are fetched) can be added by including an extra JavaScript file.  Currently, the only version requires jQuery (`tv4.async-jquery.js`), but the code is very short and should be fairly easy to modify for other libraries (such as MooTools).\n\nUsage:\n\n```javascript\ntv4.validate(data, schema, function (isValid, validationError) { ... });\n```\n\n`validationFailure` is simply taken from `tv4.error`.\n\n## Cyclical JavaScript objects\n\nWhile they don't occur in proper JSON, JavaScript does support self-referencing objects. Any of the above calls support an optional third argument: `checkRecursive`. If true, tv4 will handle self-referencing objects properly - this slows down validation slightly, but that's better than a hanging script.\n\nConsider this data, notice how both `a` and `b` refer to each other:\n\n```javascript\nvar a = {};\nvar b = { a: a };\na.b = b;\nvar aSchema = { properties: { b: { $ref: 'bSchema' }}};\nvar bSchema = { properties: { a: { $ref: 'aSchema' }}};\ntv4.addSchema('aSchema', aSchema);\ntv4.addSchema('bSchema', bSchema);\n```\n\nIf the `checkRecursive` argument were missing, this would throw a \"too much recursion\" error. \n\nTo enable support for this, pass `true` as additional argument to any of the regular validation methods: \n\n```javascript\ntv4.validate(a, aSchema, true);\ntv4.validateResult(data, aSchema, true); \ntv4.validateMultiple(data, aSchema, true);\n```\n\n## The `banUnknownProperties` flag\n\nSometimes, it is desirable to flag all unknown properties as an error.  This is especially useful during development, to catch typos and the like, even when extra custom-defined properties are allowed.\n\nAs such, tv4 implements [\"ban unknown properties\" mode](https://github.com/json-schema/json-schema/wiki/ban-unknown-properties-mode-\\(v5-proposal\\)), enabled by a fourth-argument flag:\n\n```javascript\ntv4.validate(data, schema, checkRecursive, true);\ntv4.validateResult(data, schema, checkRecursive, true);\ntv4.validateMultiple(data, schema, checkRecursive, true);\n```\n\n## API\n\nThere are additional api commands available for more complex use-cases:\n\n##### addSchema(uri, schema)\nPre-register a schema for reference by other schema and synchronous validation.\n\n````js\ntv4.addSchema('http://example.com/schema', { ... });\n````\n\n* `uri` the uri to identify this schema.\n* `schema` the schema object.\n\nSchemas that have their `id` property set can be added directly.\n\n````js\ntv4.addSchema({ ... });\n````\n\n##### getSchema(uri)\n\nReturn a schema from the cache.\n\n* `uri` the uri of the schema (may contain a `#` fragment)\n\n````js\nvar schema = tv4.getSchema('http://example.com/schema');\n````\n\n##### getSchemaMap()\n\nReturn a shallow copy of the schema cache, mapping schema document URIs to schema objects.\n\n````\nvar map = tv4.getSchemaMap();\n\nvar schema = map[uri];\n````\n\n##### getSchemaUris(filter)\n\nReturn an Array with known schema document URIs.\n\n* `filter` optional RegExp to filter URIs\n\n````\nvar arr = tv4.getSchemaUris();\n\n// optional filter using a RegExp\nvar arr = tv4.getSchemaUris(/^https?://example.com/);\n````\n\n##### getMissingUris(filter)\n\nReturn an Array with schema document URIs that are used as `$ref` in known schemas but which currently have no associated schema data.\n\nUse this in combination with `tv4.addSchema(uri, schema)` to preload the cache for complete synchronous validation with.\n\n* `filter` optional RegExp to filter URIs\n\n````\nvar arr = tv4.getMissingUris();\n\n// optional filter using a RegExp\nvar arr = tv4.getMissingUris(/^https?://example.com/);\n````\n\n##### dropSchemas()\n\nDrop all known schema document URIs from the cache.\n\n````\ntv4.dropSchemas();\n````\n\n##### freshApi()\n\nReturn a new tv4 instance with no shared state.\n\n````\nvar otherTV4 = tv4.freshApi();\n````\n\n##### reset()\n\nManually reset validation status from the simple `tv4.validate(data, schema)`. Although tv4 will self reset on each validation there are some implementation scenarios where this is useful.\n\n````\ntv4.reset();\n````\n\n##### language(code)\n\nSelect the language map used for reporting.\n\n* `code` is a language code, like `'en'` or `'en-gb'`\n\n````\ntv4.language('en-gb');\n````\n\n##### addLanguage(code, map)\n\nAdd a new language map for selection by `tv4.language(code)`\n\n* `code` is new language code\n* `map` is an object mapping error IDs or constant names (e.g. `103` or `\"NUMBER_MAXIMUM\"`) to language strings.\n\n````\ntv4.addLanguage('fr', { ... });\n\n// select for use\ntv4.language('fr')\n````\n\n##### addFormat(format, validationFunction)\n\nAdd a custom format validator. (There are no built-in format validators.)\n\n* `format` is a string, corresponding to the `\"format\"` value in schemas.\n* `validationFunction` is a function that either returns:\n  * `null` (meaning no error)\n  * an error string (explaining the reason for failure)\n\n````\ntv4.addFormat('decimal-digits', function (data, schema) {\n\tif (typeof data === 'string' && !/^[0-9]+$/.test(data)) {\n\t\treturn null;\n\t}\n\treturn \"must be string of decimal digits\";\n});\n````\n\nAlternatively, multiple formats can be added at the same time using an object:\n````\ntv4.addFormat({\n\t'my-format': function () {...},\n\t'other-format': function () {...}\n});\n````\n\n## Demos\n\n### Basic usage\n<div class=\"content inline-demo\" markdown=\"1\" data-demo=\"demo1\">\n<pre class=\"code\" id=\"demo1\">\nvar schema = {\n\t\"items\": {\n\t\t\"type\": \"boolean\"\n\t}\n};\nvar data1 = [true, false];\nvar data2 = [true, 123];\n\nalert(\"data 1: \" + tv4.validate(data1, schema)); // true\nalert(\"data 2: \" + tv4.validate(data2, schema)); // false\nalert(\"data 2 error: \" + JSON.stringify(tv4.error, null, 4));\n</pre>\n</div>\n\n### Use of <code>$ref</code>\n<div class=\"content inline-demo\" markdown=\"1\" data-demo=\"demo2\">\n<pre class=\"code\" id=\"demo2\">\nvar schema = {\n\t\"type\": \"array\",\n\t\"items\": {\"$ref\": \"#\"}\n};\nvar data1 = [[], [[]]];\nvar data2 = [[], [true, []]];\n\nalert(\"data 1: \" + tv4.validate(data1, schema)); // true\nalert(\"data 2: \" + tv4.validate(data2, schema)); // false\n</pre>\n</div>\n\n### Missing schema\n<div class=\"content inline-demo\" markdown=\"1\" data-demo=\"demo3\">\n<pre class=\"code\" id=\"demo3\">\nvar schema = {\n\t\"type\": \"array\",\n\t\"items\": {\"$ref\": \"http://example.com/schema\" }\n};\nvar data = [1, 2, 3];\n\nalert(\"Valid: \" + tv4.validate(data, schema)); // true\nalert(\"Missing schemas: \" + JSON.stringify(tv4.missing));\n</pre>\n</div>\n\n### Referencing remote schema\n<div class=\"content inline-demo\" markdown=\"1\" data-demo=\"demo4\">\n<pre class=\"code\" id=\"demo4\">\ntv4.addSchema(\"http://example.com/schema\", {\n\t\"definitions\": {\n\t\t\"arrayItem\": {\"type\": \"boolean\"}\n\t}\n});\nvar schema = {\n\t\"type\": \"array\",\n\t\"items\": {\"$ref\": \"http://example.com/schema#/definitions/arrayItem\" }\n};\nvar data1 = [true, false, true];\nvar data2 = [1, 2, 3];\n\nalert(\"data 1: \" + tv4.validate(data1, schema)); // true\nalert(\"data 2: \" + tv4.validate(data2, schema)); // false\n</pre>\n</div>\n\n## Supported platforms\n\n* Node.js\n* All modern browsers\n* IE >= 7\n\n## Installation\n\nYou can manually download [`tv4.js`](https://raw.github.com/geraintluff/tv4/master/tv4.js) or the minified [`tv4.min.js`](https://raw.github.com/geraintluff/tv4/master/tv4.min.js) and include it in your html to create the global `tv4` variable.\n\nAlternately use it as a CommonJS module:\n\n````js\nvar tv4 = require('tv4');\n````\n\n#### npm\n\n````\n$ npm install tv4\n````\n\n#### bower\n\n````\n$ bower install tv4\n````\n\n#### component.io\n\n````\n$ component install geraintluff/tv4\n````\n\n## Build and test\n\nYou can rebuild and run the node and browser tests using node.js and [grunt](http://http://gruntjs.com/):\n\nMake sure you have the global grunt cli command:\n````\n$ npm install grunt-cli -g\n````\n\nClone the git repos, open a shell in the root folder and install the development dependencies:\n\n````\n$ npm install\n````\n\nRebuild and run the tests:\n````\n$ grunt\n````\n\nIt will run a build and display one Spec-style report for the node.js and two Dot-style reports for both the plain and minified browser tests (via phantomJS). You can also use your own browser to manually run the suites by opening [`test/index.html`](http://geraintluff.github.io/tv4/test/index.html) and [`test/index-min.html`](http://geraintluff.github.io/tv4/test/index-min.html).\n\n## Contributing\n\nPull-requests for fixes and expansions are welcome. Edit the partial files in `/source` and add your tests in a suitable suite or folder under `/test/tests` and run `grunt` to rebuild and run the test suite. Try to maintain an idiomatic coding style and add tests for any new features. It is recommend to discuss big changes in an Issue.\n\n## Packages using tv4\n\n* [chai-json-schema](http://chaijs.com/plugins/chai-json-schema) is a [Chai Assertion Library](http://chaijs.com) plugin to assert values against json-schema.\n* [grunt-tv4](http://www.github.com/Bartvds/grunt-tv4) is a plugin for [Grunt](http://http://gruntjs.com/) that uses tv4 to bulk validate json files.\n\n## License\n\nThe code is available as \"public domain\", meaning that it is completely free to use, without any restrictions at all.  Read the full license [here](http://geraintluff.github.com/tv4/LICENSE.txt).\n\nIt's also available under an [MIT license](http://jsonary.com/LICENSE.txt).\n",
    6264  "readmeFilename": "README.md",
    6365  "bugs": {
     
    6567  },
    6668  "homepage": "https://github.com/geraintluff/tv4",
    67   "_id": "tv4@1.0.11",
    68   "_from": "tv4@"
     69  "_id": "tv4@1.0.16",
     70  "dist": {
     71    "shasum": "f35372c01e94355b7aaff5860455fd231e2d9802"
     72  },
     73  "_from": "tv4@1.0.16",
     74  "_resolved": "https://registry.npmjs.org/tv4/-/tv4-1.0.16.tgz"
    6975}
  • Dev/trunk/src/node_modules/tv4/tv4.async-jquery.js

    r484 r487  
    44if (typeof (tv4.asyncValidate) === 'undefined') {
    55        tv4.syncValidate = tv4.validate;
    6         tv4.validate = function (data, schema, callback, checkRecursive) {
     6        tv4.validate = function (data, schema, callback, checkRecursive, banUnknownProperties) {
    77                if (typeof (callback) === 'undefined') {
    8                         return this.syncValidate(data, schema, checkRecursive);
     8                        return this.syncValidate(data, schema, checkRecursive, banUnknownProperties);
    99                } else {
    10                         return this.asyncValidate(data, schema, callback, checkRecursive);
     10                        return this.asyncValidate(data, schema, callback, checkRecursive, banUnknownProperties);
    1111                }
    1212        };
    13         tv4.asyncValidate = function (data, schema, callback, checkRecursive) {
     13        tv4.asyncValidate = function (data, schema, callback, checkRecursive, banUnknownProperties) {
    1414                var $ = jQuery;
    15                 var result = tv4.validate(data, schema, checkRecursive);
     15                var result = tv4.validate(data, schema, checkRecursive, banUnknownProperties);
    1616                if (!tv4.missing.length) {
    1717                        callback(result, tv4.error);
     
    2828                        // When all requests done, try again
    2929                        $.when.apply($, missingSchemas).done(function () {
    30                                 var result = tv4.asyncValidate(data, schema, callback, checkRecursive);
     30                                var result = tv4.asyncValidate(data, schema, callback, checkRecursive, banUnknownProperties);
    3131                        });
    3232                }
  • Dev/trunk/src/node_modules/tv4/tv4.js

    r484 r487  
    133133                this.scannedFrozen = [];
    134134                this.scannedFrozenSchemas = [];
    135                 this.key = 'tv4_validation_id';
     135                this.scannedFrozenValidationErrors = [];
     136                this.validatedSchemasKey = 'tv4_validation_id';
     137                this.validationErrorsKey = 'tv4_validation_errors_id';
    136138        }
    137139        if (trackUnknownProperties) {
     
    240242};
    241243ValidatorContext.prototype.searchSchemas = function (schema, url) {
    242         if (typeof schema.id === "string") {
    243                 if (isTrustedUrl(url, schema.id)) {
    244                         if (this.schemas[schema.id] === undefined) {
    245                                 this.schemas[schema.id] = schema;
    246                         }
    247                 }
    248         }
    249         if (typeof schema === "object") {
     244        if (schema && typeof schema === "object") {
     245                if (typeof schema.id === "string") {
     246                        if (isTrustedUrl(url, schema.id)) {
     247                                if (this.schemas[schema.id] === undefined) {
     248                                        this.schemas[schema.id] = schema;
     249                                }
     250                        }
     251                }
    250252                for (var key in schema) {
    251253                        if (key !== "enum") {
     
    264266ValidatorContext.prototype.addSchema = function (url, schema) {
    265267        //overload
    266         if (typeof schema === 'undefined') {
     268        if (typeof url !== 'string' || typeof schema === 'undefined') {
    267269                if (typeof url === 'object' && typeof url.id === 'string') {
    268270                        schema = url;
     
    331333        }
    332334
    333         if (this.checkRecursive && (typeof data) === 'object') {
     335        var startErrorCount = this.errors.length;
     336        var frozenIndex, scannedFrozenSchemaIndex = null, scannedSchemasIndex = null;
     337        if (this.checkRecursive && data && typeof data === 'object') {
    334338                topLevel = !this.scanned.length;
    335                 if (data[this.key] && data[this.key].indexOf(schema) !== -1) { return null; }
    336                 var frozenIndex;
     339                if (data[this.validatedSchemasKey]) {
     340                        var schemaIndex = data[this.validatedSchemasKey].indexOf(schema);
     341                        if (schemaIndex !== -1) {
     342                                this.errors = this.errors.concat(data[this.validationErrorsKey][schemaIndex]);
     343                                return null;
     344                        }
     345                }
    337346                if (Object.isFrozen(data)) {
    338347                        frozenIndex = this.scannedFrozen.indexOf(data);
    339                         if (frozenIndex !== -1 && this.scannedFrozenSchemas[frozenIndex].indexOf(schema) !== -1) { return null; }
     348                        if (frozenIndex !== -1) {
     349                                var frozenSchemaIndex = this.scannedFrozenSchemas[frozenIndex].indexOf(schema);
     350                                if (frozenSchemaIndex !== -1) {
     351                                        this.errors = this.errors.concat(this.scannedFrozenValidationErrors[frozenIndex][frozenSchemaIndex]);
     352                                        return null;
     353                                }
     354                        }
    340355                }
    341356                this.scanned.push(data);
     
    346361                                this.scannedFrozenSchemas.push([]);
    347362                        }
    348                         this.scannedFrozenSchemas[frozenIndex].push(schema);
     363                        scannedFrozenSchemaIndex = this.scannedFrozenSchemas[frozenIndex].length;
     364                        this.scannedFrozenSchemas[frozenIndex][scannedFrozenSchemaIndex] = schema;
     365                        this.scannedFrozenValidationErrors[frozenIndex][scannedFrozenSchemaIndex] = [];
    349366                } else {
    350                         if (!data[this.key]) {
     367                        if (!data[this.validatedSchemasKey]) {
    351368                                try {
    352                                         Object.defineProperty(data, this.key, {
     369                                        Object.defineProperty(data, this.validatedSchemasKey, {
     370                                                value: [],
     371                                                configurable: true
     372                                        });
     373                                        Object.defineProperty(data, this.validationErrorsKey, {
    353374                                                value: [],
    354375                                                configurable: true
     
    356377                                } catch (e) {
    357378                                        //IE 7/8 workaround
    358                                         data[this.key] = [];
    359                                 }
    360                         }
    361                         data[this.key].push(schema);
     379                                        data[this.validatedSchemasKey] = [];
     380                                        data[this.validationErrorsKey] = [];
     381                                }
     382                        }
     383                        scannedSchemasIndex = data[this.validatedSchemasKey].length;
     384                        data[this.validatedSchemasKey][scannedSchemasIndex] = schema;
     385                        data[this.validationErrorsKey][scannedSchemasIndex] = [];
    362386                }
    363387        }
     
    376400                while (this.scanned.length) {
    377401                        var item = this.scanned.pop();
    378                         delete item[this.key];
     402                        delete item[this.validatedSchemasKey];
    379403                }
    380404                this.scannedFrozen = [];
     
    391415                        this.prefixErrors(errorCount, dataPart, schemaPart);
    392416                }
     417        }
     418       
     419        if (scannedFrozenSchemaIndex !== null) {
     420                this.scannedFrozenValidationErrors[frozenIndex][scannedFrozenSchemaIndex] = this.errors.slice(startErrorCount);
     421        } else if (scannedSchemasIndex !== null) {
     422                data[this.validationErrorsKey][scannedSchemasIndex] = this.errors.slice(startErrorCount);
    393423        }
    394424
     
    9961026}
    9971027function normSchema(schema, baseUri) {
    998         if (baseUri === undefined) {
    999                 baseUri = schema.id;
    1000         } else if (typeof schema.id === "string") {
    1001                 baseUri = resolveUrl(baseUri, schema.id);
    1002                 schema.id = baseUri;
    1003         }
    1004         if (typeof schema === "object") {
     1028        if (schema && typeof schema === "object") {
     1029                if (baseUri === undefined) {
     1030                        baseUri = schema.id;
     1031                } else if (typeof schema.id === "string") {
     1032                        baseUri = resolveUrl(baseUri, schema.id);
     1033                        schema.id = baseUri;
     1034                }
    10051035                if (Array.isArray(schema)) {
    10061036                        for (var i = 0; i < schema.length; i++) {
     
    10501080        FORMAT_CUSTOM: 500,
    10511081        // Schema structure
    1052         CIRCULAR_REFERENCE: 500,
     1082        CIRCULAR_REFERENCE: 600,
    10531083        // Non-standard validation options
    10541084        UNKNOWN_PROPERTY: 1000
     
    10911121
    10921122function ValidationError(code, message, dataPath, schemaPath, subErrors) {
     1123        Error.call(this);
    10931124        if (code === undefined) {
    10941125                throw new Error ("No code supplied for error: "+ message);
    10951126        }
     1127        this.message = message;
    10961128        this.code = code;
    1097         this.message = message;
    10981129        this.dataPath = dataPath || "";
    10991130        this.schemaPath = schemaPath || "";
    11001131        this.subErrors = subErrors || null;
    1101 }
    1102 ValidationError.prototype = new Error();
     1132
     1133        var err = new Error(this.message);
     1134        this.stack = err.stack || err.stacktrace;
     1135        if (!this.stack) {
     1136                try {
     1137                        throw err;
     1138                }
     1139                catch(err) {
     1140                        this.stack = err.stack || err.stacktrace;
     1141                }
     1142        }
     1143}
     1144ValidationError.prototype = Object.create(Error.prototype);
     1145ValidationError.prototype.constructor = ValidationError;
     1146ValidationError.prototype.name = 'ValidationError';
     1147
    11031148ValidationError.prototype.prefixWith = function (dataPrefix, schemaPrefix) {
    11041149        if (dataPrefix !== null) {
     
    12651310
    12661311})(this);
    1267 
    1268 //@ sourceMappingURL=tv4.js.map
Note: See TracChangeset for help on using the changeset viewer.