Comparing version
@@ -34,6 +34,18 @@ "use strict"; | ||
encode() { | ||
var _a, _b, _c; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const ctor = this[CTOR]; | ||
validateSchema(ctor.schema); | ||
return ctor.schema.toBuffer(this); | ||
try { | ||
return ctor.schema.toBuffer(this); | ||
} | ||
catch (err) { | ||
const fields = (_c = (_b = (_a = ctor) === null || _a === void 0 ? void 0 : _a['schema']) === null || _b === void 0 ? void 0 : _b['_fieldsByName']) !== null && _c !== void 0 ? _c : {}; | ||
for (const field in fields) { | ||
if (typeof this[field] === 'undefined') { | ||
throw new Error(`${ctor.name} has no value defined for "${field}"`); | ||
} | ||
} | ||
throw err; | ||
} | ||
}); | ||
@@ -40,0 +52,0 @@ } |
@@ -22,6 +22,5 @@ "use strict"; | ||
constructor(base) { | ||
var _a, _b; | ||
super(); | ||
this.number = (_a = base === null || base === void 0 ? void 0 : base.number) !== null && _a !== void 0 ? _a : null; | ||
this.hash = (_b = base === null || base === void 0 ? void 0 : base.hash) !== null && _b !== void 0 ? _b : null; | ||
this.number = base === null || base === void 0 ? void 0 : base.number; | ||
this.hash = base === null || base === void 0 ? void 0 : base.hash; | ||
} | ||
@@ -102,2 +101,6 @@ helper() { | ||
})); | ||
it('Should log the missing fields', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const block = new Block({ hash: '0x1010' }); | ||
yield expect(() => block.encode()).rejects.toThrowError('Block has no value defined for "number"'); | ||
})); | ||
it('Should provide useful class errors', () => __awaiter(void 0, void 0, void 0, function* () { | ||
@@ -104,0 +107,0 @@ class Block extends _1.Avro { |
{ | ||
"name": "avsc-tsc", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Utility library to encode and decode typescript classes in Avro format", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
18431
7.23%239
6.7%