Comparing version 0.3.0 to 0.4.0
25
index.js
const { | ||
ObjectView, StringView, TypeViewMixin, BooleanView, | ||
ObjectView, StringView, TypeViewMixin, BooleanView, ArrayView, | ||
} = require('structurae'); | ||
@@ -92,3 +92,3 @@ const ObjectIdView = require('./lib/objectid-view'); | ||
let index = 0; | ||
while (caret < bson.length - 1) { | ||
while (caret < bson.byteLength - 1) { | ||
const elementType = bson[caret]; | ||
@@ -113,10 +113,15 @@ if (!BSONTypes[elementType]) { | ||
start = index * length; | ||
hasValue = start < view.length && valueLength; | ||
hasValue = start < view.byteLength && valueLength; | ||
} else { | ||
const fieldName = this.getFieldName(bson.subarray(nameStart, nameEnd), View); | ||
hasValue = fieldName && valueLength; | ||
const fieldOptions = View.layout[fieldName]; | ||
start = fieldOptions.start; | ||
fieldLength = fieldOptions.length; | ||
SubView = fieldOptions.View; | ||
if (fieldName) { | ||
const fieldOptions = View.layout[fieldName]; | ||
start = fieldOptions.start; | ||
fieldLength = fieldOptions.length; | ||
SubView = fieldOptions.View; | ||
const hasTypeConflict = ((elementType === 0x03 | ||
&& !(SubView.prototype instanceof ObjectView)) | ||
|| (elementType === 0x04 && !(SubView.prototype instanceof ArrayView))); | ||
hasValue = !!valueLength && !hasTypeConflict; | ||
} | ||
} | ||
@@ -160,3 +165,3 @@ if (hasValue) { | ||
const { encodedFields, fields } = View; | ||
const nameLength = name.length; | ||
const nameLength = name.byteLength; | ||
outer: for (let i = 0; i < encodedFields.length; i++) { | ||
@@ -170,3 +175,3 @@ const fieldName = encodedFields[i]; | ||
} | ||
return false; | ||
return undefined; | ||
} | ||
@@ -173,0 +178,0 @@ |
{ | ||
"name": "bsonview", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Schema-based BSON using structurae's ObjectView binary protocol.", | ||
@@ -36,3 +36,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"structurae": "^3.0.1" | ||
"structurae": "^3.0.3" | ||
}, | ||
@@ -45,3 +45,3 @@ "devDependencies": { | ||
"eslint-plugin-import": "^2.20.2", | ||
"jest": "^25.2.6", | ||
"jest": "^25.2.7", | ||
"json-schema-faker": "^0.5.0-rcv.24" | ||
@@ -48,0 +48,0 @@ }, |
13913
345
Updatedstructurae@^3.0.3