Comparing version 1.0.6 to 1.0.7
26
index.js
@@ -31,3 +31,3 @@ const Types = require('./src/types') | ||
definitions = Object.assign({}, definitions) //clone | ||
for(const key in config.customTypes) { // custom types overwrite definations | ||
for(const key in config.customTypes) { // custom types overwrite definitions | ||
delete definitions[key] | ||
@@ -39,15 +39,19 @@ } | ||
const {errors, structs} = create(definitions, types) | ||
const extend = (parent, child) => { | ||
const combined = Object.assign(parent, child) | ||
const {structs, errors} = create(combined, types) | ||
return { | ||
errors, | ||
structs, | ||
extend: child => extend(combined, child) | ||
} | ||
} | ||
// /** Extend with more JSON type definitions (like: base.json). */ | ||
// const extend = (parent, child) => { | ||
// const combined = Object.assign(parent, child) | ||
// const {structs, errors} = create(combined, types) | ||
// return { | ||
// errors, | ||
// structs, | ||
// extend: child => extend(combined, child) | ||
// } | ||
// } | ||
return { | ||
errors, | ||
structs, | ||
extend: child => extend(definitions, child) | ||
types | ||
// extend: child => extend(definitions, child) | ||
} | ||
@@ -54,0 +58,0 @@ } |
{ | ||
"name": "fcbuffer", | ||
"description": "Serialization library geared towards immutable data storage such as blockchains.", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -99,2 +99,10 @@ const ByteBuffer = require('bytebuffer') | ||
fromObject (serializedObject) { | ||
const fromObject_struct = config.override[`${name}.fromObject`] | ||
if(fromObject_struct) { | ||
const ret = fromObject_struct(serializedObject) | ||
if(ret != null) { | ||
return ret | ||
} | ||
} | ||
let result = {} | ||
@@ -104,2 +112,5 @@ let field = null | ||
for (field in fields) { | ||
if(config.debug) { | ||
console.error(name, field) | ||
} | ||
const type = fields[field] | ||
@@ -153,3 +164,2 @@ if (field === '') { | ||
try { | ||
let b = new ByteBuffer(ByteBuffer.DEFAULT_CAPACITY, ByteBuffer.LITTLE_ENDIAN) | ||
@@ -156,0 +166,0 @@ if (serializedObject != null) { |
@@ -42,7 +42,8 @@ const BN = require('bn.js') | ||
config = Object.assign({defaults: false, debug: false, customTypes: {}}, config) | ||
const allTypes = Object.assign(types, config.customTypes) | ||
const createTypeReducer = (map, name) => { | ||
const allTypes = Object.assign({}, types, config.customTypes) | ||
const createTypeReducer = baseTypes => (map, name) => { | ||
map[name] = (...args) => { | ||
const type = createType(name, config, ...args) | ||
const type = createType(name, config, args, baseTypes, allTypes) | ||
return type | ||
@@ -52,6 +53,10 @@ } | ||
} | ||
const typeMap = Object.keys(allTypes).reduce(createTypeReducer, {}) | ||
typeMap.config = config | ||
return typeMap | ||
const baseTypes = Object.keys(types) | ||
.reduce(createTypeReducer(), {}) | ||
const customTypes = Object.keys(config.customTypes || {}) | ||
.reduce(createTypeReducer(baseTypes), {}) | ||
return Object.assign({}, baseTypes, customTypes, {config}) | ||
} | ||
@@ -64,4 +69,4 @@ | ||
*/ | ||
function createType (typeName, config, ...args) { | ||
const Type = types[typeName] | ||
function createType (typeName, config, args, baseTypes, allTypes) { | ||
const Type = baseTypes ? allTypes[typeName] : types[typeName] | ||
const [fn, v = {}] = Type(...args) | ||
@@ -71,3 +76,3 @@ const validation = Object.assign(v, config) | ||
// if(typeName === 'Vector') console.log('typeName', validation) | ||
const type = fn(validation) | ||
const type = fn(validation, baseTypes) | ||
return type | ||
@@ -74,0 +79,0 @@ } |
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
67859
1015