Skip to content

Commit

Permalink
3.2.0: Verison bump, detect missing elements when building
Browse files Browse the repository at this point in the history
  • Loading branch information
ethan7g committed Mar 20, 2019
1 parent 5453a0c commit 8b7d0d7
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/types/boolean.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
'name': 'boolean',
'parse': (buf, from, data) => {
if (buf.length - from < 1) {
return {
Expand Down
1 change: 1 addition & 0 deletions lib/types/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const path = require('path')
const varint = require(path.join(__dirname, 'varint.js'))

module.exports = {
'name': 'buffer',
'parse': (buf, from, data) => {
if (buf.length - from < 1) {
return {
Expand Down
1 change: 1 addition & 0 deletions lib/types/double.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
'name': 'double',
'parse': (buf, from, data) => {
if (buf.length - from < 8) {
return {
Expand Down
1 change: 1 addition & 0 deletions lib/types/float.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
'name': 'float',
'parse': (buf, from, data) => {
if (buf.length - from < 4) {
return {
Expand Down
1 change: 1 addition & 0 deletions lib/types/instance.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
'name': 'instance',
'parse': (buf, from, data) => {
const parseResult = data.of.parse(buf, from, {
'returnDetails': true
Expand Down
1 change: 1 addition & 0 deletions lib/types/int.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
'name': 'int',
'parse': (buf, from, data) => {
const readBytes = data.size / 8

Expand Down
1 change: 1 addition & 0 deletions lib/types/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const path = require('path')
const varint = require(path.join(__dirname, 'varint.js'))

module.exports = {
'name': 'list',
'parse': (buf, from, data) => {
if (buf.length - from < 1) {
return {
Expand Down
1 change: 1 addition & 0 deletions lib/types/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const genMapSchema = (data) => {
}

module.exports = {
'name': 'map',
'parse': (buf, from, data) => {
if (buf.length - from < 1) {
return {
Expand Down
1 change: 1 addition & 0 deletions lib/types/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const path = require('path')
const varint = require(path.join(__dirname, 'varint.js'))

module.exports = {
'name': 'string',
'parse': (buf, from, data) => {
if (buf.length - from < 1) {
return {
Expand Down
1 change: 1 addition & 0 deletions lib/types/uint.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
'name': 'uint',
'parse': (buf, from, data) => {
const readBytes = data.size / 8

Expand Down
2 changes: 2 additions & 0 deletions lib/types/varint.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const calcBytes = (number) => {

module.exports = {}

module.exports.name = 'varint'

module.exports.parsePrefix = (buf, from) => {
const prefix = buf[from]

Expand Down
4 changes: 4 additions & 0 deletions model/Schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ module.exports = class Schema {
const writeContent = []

for (let i = 0; i < this.elements.length; i++) {
if (typeof data[this.elements[i].name] === 'undefined') {
throw new Error('Missing element: ' + this.elements[i].type.name + ' ' + this.elements[i].name)
}

writeContent.push({
'value': data[this.elements[i].name],
'serializerData': this.elements[i]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "protocore",
"version": "3.1.1",
"version": "3.2.0",
"description": "Specify and deploy performant binary protocol structures in Node",
"main": "index.js",
"scripts": {
Expand Down
24 changes: 24 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,30 @@ w.add('Map protospec functionality', (result) => {
result(true, 'Validated built data. (Protospec success!)')
})

w.add('Detect missing elements', (result) => {
const testSchema = protospec.importAll(`
def ping
varint time
`).ping

const testData = {

}

try {
testSchema.build(testData)
}
catch (err) {
result(true, 'Error as expected.')

return
}

result(false, 'Expected error to be thrown.')
})

w.test()

process.stdin.on('data', () => {})

0 comments on commit 8b7d0d7

Please sign in to comment.