Comparing version 4.0.1 to 4.1.0
@@ -15,3 +15,4 @@ /* jshint browserify: true */ | ||
schemas = require('../../lib/schemas'), | ||
types = require('../../lib/types'); | ||
types = require('../../lib/types'), | ||
values = require('../../lib/values'); | ||
@@ -31,4 +32,6 @@ | ||
assemble: schemas.assemble, | ||
combine: values.combine, | ||
infer: values.infer, | ||
parse: parse, | ||
types: types.builtins | ||
}; |
@@ -13,3 +13,4 @@ /* jshint browserify: true */ | ||
var files = require('./lib/files'), | ||
types = require('../../lib/types'); | ||
types = require('../../lib/types'), | ||
values = require('../../lib/values'); | ||
@@ -24,4 +25,6 @@ | ||
Type: types.Type, | ||
combine: values.combine, | ||
infer: values.infer, | ||
parse: parse, | ||
types: types.builtins | ||
}; |
@@ -14,3 +14,4 @@ /* jshint node: true */ | ||
schemas = require('../../lib/schemas'), | ||
types = require('../../lib/types'); | ||
types = require('../../lib/types'), | ||
values = require('../../lib/values'); | ||
@@ -30,2 +31,4 @@ | ||
assemble: schemas.assemble, | ||
combine: values.combine, | ||
infer: values.infer, | ||
parse: parse, | ||
@@ -32,0 +35,0 @@ streams: containers.streams, |
/* jshint node: true */ | ||
// TODO: Add streams which prefix each record with its length. | ||
'use strict'; | ||
@@ -4,0 +6,0 @@ |
@@ -19,2 +19,3 @@ /* jshint node: true */ | ||
utils = require('./utils'), | ||
values = require('./values'), | ||
fs = require('fs'); | ||
@@ -105,5 +106,7 @@ | ||
assemble: schemas.assemble, | ||
combine: values.combine, | ||
createFileDecoder: createFileDecoder, | ||
createFileEncoder: createFileEncoder, | ||
extractFileHeader: extractFileHeader, | ||
infer: values.infer, | ||
parse: parse, | ||
@@ -110,0 +113,0 @@ streams: containers.streams, |
@@ -84,3 +84,5 @@ /* jshint node: true */ | ||
} | ||
opts.namespace = attrs.namespace; | ||
if (attrs.namespace !== undefined) { | ||
opts.namespace = attrs.namespace; | ||
} | ||
if (opts.namespace && !~name.indexOf('.')) { | ||
@@ -966,4 +968,6 @@ name = f('%s.%s', opts.namespace, name); | ||
var requestName = 'org.apache.avro.ipc.Request'; // Placeholder name. | ||
this._requestType = new types.builtins.RecordType({ | ||
this._requestType = types.createType({ | ||
type: 'record', | ||
name: requestName, | ||
namespace: opts.namespace || '', | ||
fields: attrs.request | ||
@@ -970,0 +974,0 @@ }, opts); |
@@ -11,2 +11,3 @@ /* jshint node: true */ | ||
var files = require('./files'), | ||
utils = require('./utils'), | ||
path = require('path'), | ||
@@ -565,54 +566,11 @@ util = require('util'); | ||
/** | ||
* Returns end of JSON object, -1 if the end of the string is reached first. | ||
* Returns end of JSON object, throwing an error if the end is reached first. | ||
* | ||
* To keep the implementation simple, this function isn't a JSON validator. It | ||
* will gladly return a result for invalid JSON (which is OK since that will be | ||
* promptly rejected by the JSON parser). What matters is that it is guaranteed | ||
* to return the correct end when presented with valid JSON. | ||
* | ||
*/ | ||
Tokenizer.prototype._endOfJson = function () { | ||
var pos = this._pos; | ||
var str = this._str; | ||
// Handle the case of a simple literal separately. | ||
var c = str.charAt(pos++); | ||
if (/[\d-]/.test(c)) { | ||
while (/[eE\d.+-]/.test(str.charAt(pos))) { | ||
pos++; | ||
} | ||
return pos; | ||
} else if (/true|null/.test(str.slice(pos - 1, pos + 3))) { | ||
return pos + 3; | ||
} else if (/false/.test(str.slice(pos - 1, pos + 4))) { | ||
return pos + 4; | ||
var pos = utils.jsonEnd(this._str, this._pos); | ||
if (pos < 0) { | ||
throw new Error('invalid JSON at ' + this._pos); | ||
} | ||
// String, object, or array. | ||
var depth = 0; | ||
var literal = false; | ||
do { | ||
switch (c) { | ||
case '{': | ||
case '[': | ||
if (!literal) { depth++; } | ||
break; | ||
case '}': | ||
case ']': | ||
if (!literal && !--depth) { | ||
return pos; | ||
} | ||
break; | ||
case '"': | ||
literal = !literal; | ||
if (!depth && !literal) { | ||
return pos; | ||
} | ||
break; | ||
case '\\': | ||
pos++; // Skip the next character. | ||
} | ||
} while ((c = str.charAt(pos++))); | ||
throw new Error('invalid JSON at ' + this._pos); | ||
return pos; | ||
}; | ||
@@ -619,0 +577,0 @@ |
@@ -9,3 +9,3 @@ /* jshint node: true */ | ||
/** | ||
* Various utilities used accross this library. | ||
* Various utilities used across this library. | ||
* | ||
@@ -115,2 +115,59 @@ */ | ||
/** | ||
* Returns offset in the string of the end of JSON object (-1 if past the end). | ||
* | ||
* To keep the implementation simple, this function isn't a JSON validator. It | ||
* will gladly return a result for invalid JSON (which is OK since that will be | ||
* promptly rejected by the JSON parser). What matters is that it is guaranteed | ||
* to return the correct end when presented with valid JSON. | ||
* | ||
* @param str {String} Input string containing serialized JSON.. | ||
* @param pos {Number} Starting position. | ||
* | ||
*/ | ||
function jsonEnd(str, pos) { | ||
pos = pos | 0; | ||
// Handle the case of a simple literal separately. | ||
var c = str.charAt(pos++); | ||
if (/[\d-]/.test(c)) { | ||
while (/[eE\d.+-]/.test(str.charAt(pos))) { | ||
pos++; | ||
} | ||
return pos; | ||
} else if (/true|null/.test(str.slice(pos - 1, pos + 3))) { | ||
return pos + 3; | ||
} else if (/false/.test(str.slice(pos - 1, pos + 4))) { | ||
return pos + 4; | ||
} | ||
// String, object, or array. | ||
var depth = 0; | ||
var literal = false; | ||
do { | ||
switch (c) { | ||
case '{': | ||
case '[': | ||
if (!literal) { depth++; } | ||
break; | ||
case '}': | ||
case ']': | ||
if (!literal && !--depth) { | ||
return pos; | ||
} | ||
break; | ||
case '"': | ||
literal = !literal; | ||
if (!depth && !literal) { | ||
return pos; | ||
} | ||
break; | ||
case '\\': | ||
pos++; // Skip the next character. | ||
} | ||
} while ((c = str.charAt(pos++))); | ||
return -1; | ||
} | ||
/** | ||
* "Abstract" function to help with "subclassing". | ||
@@ -638,2 +695,3 @@ * | ||
compare: compare, | ||
jsonEnd: jsonEnd, | ||
toMap: toMap, | ||
@@ -640,0 +698,0 @@ singleIndexOf: singleIndexOf, |
{ | ||
"name": "avsc", | ||
"version": "4.0.1", | ||
"version": "4.1.0", | ||
"description": "Avro for JavaScript", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/mtth/avsc", |
@@ -11,4 +11,4 @@ # Avsc [![NPM version](https://img.shields.io/npm/v/avsc.svg)](https://www.npmjs.com/package/avsc) [![Build status](https://travis-ci.org/mtth/avsc.svg?branch=master)](https://travis-ci.org/mtth/avsc) [![Coverage status](https://coveralls.io/repos/mtth/avsc/badge.svg?branch=master&service=github)](https://coveralls.io/github/mtth/avsc?branch=master) | ||
JSON with much smaller encodings. | ||
+ All the Avro goodness, including [schema evolution][schema-evolution] and | ||
[remote procedure calls][rpc]. | ||
+ All the Avro goodness and more: [type inference][type-inference], [schema | ||
evolution][schema-evolution], and [remote procedure calls][rpc]. | ||
+ Support for [serializing arbitrary JavaScript objects][logical-types]. | ||
@@ -47,3 +47,3 @@ + Unopinionated [64-bit integer compatibility][custom-long]. | ||
+ Encode and decode values: | ||
+ Encode and decode values from a known schema: | ||
@@ -63,2 +63,16 @@ ```javascript | ||
+ Infer a value's type and encode similar values: | ||
```javascript | ||
var val = {city: 'Cambridge', zipCodes: ['02138', '02139'], visits: 2}; | ||
var type = avro.infer(val); | ||
// We can now encode the value: | ||
var buf = type.toBuffer(val); | ||
// And also any values with a matching structure: | ||
var bufs = [ | ||
type.toBuffer({city: 'Seattle', zipCodes: ['98101'], visits: 3}), | ||
type.toBuffer({city: 'NYC', zipCodes: [], visits: 0}) | ||
]; | ||
``` | ||
+ Get a [readable stream][readable-stream] of decoded values from an Avro | ||
@@ -77,4 +91,6 @@ container file: | ||
avro.assemble('./Ping.avdl', function (err, attrs) { | ||
var protocol = avro.parse(attrs); | ||
protocol.on('ping', function (req, ee, cb) { cb(null, 'pong'); }); | ||
// Generate the protocol and attach a handler for `ping` messages: | ||
var protocol = avro.parse(attrs) | ||
.on('ping', function (req, ee, cb) { cb(null, 'pong'); }); | ||
// Respond on any incoming connection: | ||
require('net').createServer() | ||
@@ -89,2 +105,3 @@ .on('connection', function (con) { protocol.createListener(con); }) | ||
[benchmarks]: https://github.com/mtth/avsc/wiki/Benchmarks | ||
[type-inference]: https://github.com/mtth/avsc/wiki/Advanced-usage#type-inference | ||
[schema-evolution]: https://github.com/mtth/avsc/wiki/Advanced-usage#schema-evolution | ||
@@ -91,0 +108,0 @@ [logical-types]: https://github.com/mtth/avsc/wiki/Advanced-usage#logical-types |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
191351
16
6258
112