Loading lib/kinetic.js +51 −27 Original line number Diff line number Diff line Loading @@ -894,7 +894,6 @@ class PutPDU extends PDU { InitPDU * @param {Buffer} keyArg - key of the item to put. * @param {number} chunkSize - size of the chunk to put. * @param {Buffer} tagArg - the hash of the value to put. * @param {Object} optionsArg - optional : * {String} [options.synchronization = WRITEBACK] - to * specify if the data must be written to disk immediately, Loading @@ -903,21 +902,27 @@ class PutPDU extends PDU { * true ignores potential version mismatches and carries out * the operation. * {string} [options.algorithm] - algorithm used for the tag * {Buffer} dbVersion - version of the item in the database * {Buffer} newVersion - new version of the item to put * {Buffer} [options.dbVersion] - version of the item in the * database * {Buffer} [options.newVersion] - new version of the item to * put * {Buffer} [options.tag] - the hash of the value to put. * @returns {Kinetic} - message structure following the kinetic protocol */ constructor(sequence, connectionID, clusterVersion, keyArg, chunkSize, tagArg, optionsArg) { optionsArg) { super(); const options = optionsArg || {}; let dbVersion = null; let newVersion = null; let tag = null; const key = validateBufferOrStringArgument(keyArg); const tag = validateVersionArgument(tagArg); if (options.tag) tag = validateVersionArgument(options.tag); if (options.dbVersion) dbVersion = validateVersionArgument(options.dbVersion); if (options.newVersion) Loading @@ -941,8 +946,8 @@ class PutPDU extends PDU { force: typeof options.force === "boolean" ? options.force : null, tag, algorithm: validateAlgo(options.algorithm) || algorithms.SHA1, algorithm: tag ? validateAlgo(options.algorithm) || algorithms.SHA1 : null, }, }, }); Loading Loading @@ -1029,18 +1034,25 @@ class GetResponsePDU extends PDU { * @param {Buffer} keyArg - key of the item to gotten item. * @param {number} chunkSize - size of the got chunk. * @param {Buffer} dbVersionArg - The version of the item in the database. * @param {Buffer} tagArg - the hash of the value to put. * @param {string} algorithm - algorithm used for the tag. * @param {Object} optionsArg - optional : * {string} [options.algorithm] - algorithm used for the * tag * {Buffer} [options.tag] - the hash of the value to put. * @returns {Kinetic} - message structure following the kinetic protocol */ constructor(ackSequence, code, errorMessageArg, keyArg, chunkSize, dbVersionArg, tagArg, algorithm) { chunkSize, dbVersionArg, optionsArg) { super(); const options = optionsArg || {}; let tag = null; if (options.tag) tag = validateVersionArgument(options.tag); const detailedMessage = validateBufferOrStringArgument(errorMessageArg); const key = validateBufferOrStringArgument(keyArg); const dbVersion = validateVersionArgument(dbVersionArg); const tag = validateVersionArgument(tagArg); this._chunkSize = chunkSize; this.setCommand({ Loading @@ -1053,8 +1065,8 @@ class GetResponsePDU extends PDU { key, dbVersion, tag, algorithm: validateAlgo(algorithm) || algorithms.SHA1, algorithm: tag ? validateAlgo(options.algorithm) || algorithms.SHA1 : null, }, }, status: { Loading Loading @@ -1260,20 +1272,26 @@ class GetNextResponsePDU extends PDU { * request in a TCP connection * @param {Buffer} keyArg - key for the value that is being returned. * @param {number} dbVersionArg - the version of the object in the DB * @param {Buffer} tagArg - the hash of the value to put. * @param {number} code - response code (SUCCESS, FAIL) * @param {Buffer} errorMessageArg - Detailed error message. * @param {string} algorithm - algorithm used for the tag. * @param {Object} optionsArg - optional : * {string} [options.algorithm] - algorithm used for the * tag * {Buffer} [options.tag] - the hash of the value to put. * @returns {Kinetic} - message structure following the kinetic protocol */ constructor( ackSequence, keyArg, dbVersionArg, tagArg, code, errorMessageArg, algorithm) { ackSequence, keyArg, dbVersionArg, code, errorMessageArg, optionsArg) { super(); const options = optionsArg || {}; let tag = null; if (options.tag) tag = validateVersionArgument(options.tag); const detailedMessage = validateBufferOrStringArgument(errorMessageArg); const key = validateBufferOrStringArgument(keyArg); const tag = validateVersionArgument(tagArg); const dbVersion = validateVersionArgument(dbVersionArg); this.setCommand({ Loading @@ -1286,8 +1304,8 @@ class GetNextResponsePDU extends PDU { key, dbVersion, tag, algorithm: validateAlgo(algorithm) || algorithms.SHA1, algorithm: tag ? validateAlgo(options.algorithm) || algorithms.SHA1 : null, }, }, status: { Loading Loading @@ -1340,20 +1358,26 @@ class GetPreviousResponsePDU extends PDU { * request in a TCP connection * @param {Buffer} keyArg - key for the value that is being returned. * @param {number} dbVersionArg - the version of the object in the DB * @param {Buffer} tagArg - the hash of the value to put. * @param {number} code - response code (SUCCESS, FAIL) * @param {Buffer} errorMessageArg - Detailed error message. * @param {string} algorithm - algorithm used for the tag. * @param {Object} optionsArg - optional : * {string} [options.algorithm] - algorithm used for the * tag * {Buffer} [options.tag] - the hash of the value to put. * @returns {Kinetic} - message structure following the kinetic protocol */ constructor( ackSequence, keyArg, dbVersionArg, tagArg, code, errorMessageArg, algorithm) { ackSequence, keyArg, dbVersionArg, code, errorMessageArg, optionsArg) { super(); const options = optionsArg || {}; let tag = null; if (options.tag) tag = validateVersionArgument(options.tag); const detailedMessage = validateBufferOrStringArgument(errorMessageArg); const key = validateBufferOrStringArgument(keyArg); const tag = validateVersionArgument(tagArg); const dbVersion = validateVersionArgument(dbVersionArg); this.setCommand({ Loading @@ -1366,8 +1390,8 @@ class GetPreviousResponsePDU extends PDU { key, dbVersion, tag, algorithm: validateAlgo(algorithm) || algorithms.SHA1, algorithm: tag ? validateAlgo(options.algorithm) || algorithms.SHA1 : null, }, }, status: { Loading tests/functional/simulTest.js +2 −3 Original line number Diff line number Diff line Loading @@ -49,7 +49,6 @@ const requestsArr = [ function requestsLauncher(request, client, optionsA) { let pdu; let tag; const options = optionsA || {}; Loading @@ -58,11 +57,11 @@ function requestsLauncher(request, client, optionsA) { pdu = new kinetic.NoOpPDU(sequence, connectionID, clusterVersion); break; case 'put': tag = crypto options.tag = crypto .createHmac('sha1', 'asdfasdf').update(chunk).digest(); pdu = new kinetic.PutPDU( sequence, connectionID, clusterVersion, options.key || key, chunk.length, tag, options); chunk.length, options); break; case 'get': pdu = new kinetic.GetPDU( Loading tests/unit/kinetic.js +16 −17 Original line number Diff line number Diff line Loading @@ -701,14 +701,13 @@ describe('kinetic.PDU encoding()', () => { const options = { dbVersion: Buffer.from('2', 'utf8'), newVersion: Buffer.from('3', 'utf8'), tag: crypto .createHmac('sha1', 'asdfasdf').update(chunk).digest(), }; const tag = crypto .createHmac('sha1', 'asdfasdf').update(chunk).digest(); const k = new kinetic.PutPDU( 1, connectionID, clusterVersion, 'string', chunk.length, tag, options); 'string', chunk.length, options); const result = Buffer.concat([k.read(), chunk]); Loading @@ -731,14 +730,13 @@ describe('kinetic.PDU encoding()', () => { dbVersion: Buffer.from('2', 'utf8'), newVersion: Buffer.from('3', 'utf8'), force: true, tag: crypto .createHmac('sha1', 'asdfasdf').update(chunk).digest(), }; const tag = crypto .createHmac('sha1', 'asdfasdf').update(chunk).digest(); const k = new kinetic.PutPDU( 1, connectionID, clusterVersion, 'string', chunk.length, tag, options); 'string', chunk.length, options); const result = Buffer.concat([k.read(), chunk]); Loading @@ -761,14 +759,13 @@ describe('kinetic.PDU encoding()', () => { dbVersion: Buffer.from('2', 'utf8'), newVersion: Buffer.from('3', 'utf8'), force: false, tag: crypto .createHmac('sha1', 'asdfasdf').update(chunk).digest(), }; const tag = crypto .createHmac('sha1', 'asdfasdf').update(chunk).digest(); const k = new kinetic.PutPDU( 1, connectionID, clusterVersion, 'string', chunk.length, tag, options); 'string', chunk.length, options); const result = Buffer.concat([k.read(), chunk]); Loading Loading @@ -854,7 +851,7 @@ describe('kinetic.PDU encoding()', () => { const pdu = new kinetic.GetResponsePDU( 1, 1, Buffer.alloc(0), Buffer.from('qwer', 'utf8'), chunk.length, Buffer.from('1', 'utf8'), tag); chunk.length, Buffer.from('1', 'utf8'), { tag }); const result = Buffer.concat([pdu.read(), chunk]); Loading Loading @@ -1190,9 +1187,10 @@ describe('kinetic.PutPDU()', () => { const tag = crypto .createHmac('sha1', 'asdfasdf').update('HelloWorld').digest(); const k = new kinetic.PutPDU( 1, connectionID, clusterVersion, "string", 12, tag, 1, connectionID, clusterVersion, "string", 12, { dbVersion: { a: 1 }, newVersion: Buffer.from('3', 'utf8'), tag, }); k; done(new Error("constructor accepted object-typed key")); Loading @@ -1210,7 +1208,7 @@ describe('kinetic.PutPDU()', () => { .createHmac('sha1', 'asdfasdf').update('HelloWorld').digest(); const k = new kinetic.PutPDU( 1, connectionID, clusterVersion, "string", 12, tag, { newVersion: 346 }); "string", 12, { newVersion: 346, tag }); k; done(); } catch (e) { Loading @@ -1223,9 +1221,10 @@ describe('kinetic.PutPDU()', () => { const tag = crypto .createHmac('sha1', 'asdfasdf').update('HelloWorld').digest(); const k = new kinetic.PutPDU( 1, connectionID, clusterVersion, 'string', 12, tag, 1, connectionID, clusterVersion, 'string', 12, { dbVersion: Buffer.from('2', 'utf8'), newVersion: { s: 'abc' } newVersion: { s: 'abc' }, tag, }); k; done(new Error("constructor accepted string-typed key")); Loading Loading
lib/kinetic.js +51 −27 Original line number Diff line number Diff line Loading @@ -894,7 +894,6 @@ class PutPDU extends PDU { InitPDU * @param {Buffer} keyArg - key of the item to put. * @param {number} chunkSize - size of the chunk to put. * @param {Buffer} tagArg - the hash of the value to put. * @param {Object} optionsArg - optional : * {String} [options.synchronization = WRITEBACK] - to * specify if the data must be written to disk immediately, Loading @@ -903,21 +902,27 @@ class PutPDU extends PDU { * true ignores potential version mismatches and carries out * the operation. * {string} [options.algorithm] - algorithm used for the tag * {Buffer} dbVersion - version of the item in the database * {Buffer} newVersion - new version of the item to put * {Buffer} [options.dbVersion] - version of the item in the * database * {Buffer} [options.newVersion] - new version of the item to * put * {Buffer} [options.tag] - the hash of the value to put. * @returns {Kinetic} - message structure following the kinetic protocol */ constructor(sequence, connectionID, clusterVersion, keyArg, chunkSize, tagArg, optionsArg) { optionsArg) { super(); const options = optionsArg || {}; let dbVersion = null; let newVersion = null; let tag = null; const key = validateBufferOrStringArgument(keyArg); const tag = validateVersionArgument(tagArg); if (options.tag) tag = validateVersionArgument(options.tag); if (options.dbVersion) dbVersion = validateVersionArgument(options.dbVersion); if (options.newVersion) Loading @@ -941,8 +946,8 @@ class PutPDU extends PDU { force: typeof options.force === "boolean" ? options.force : null, tag, algorithm: validateAlgo(options.algorithm) || algorithms.SHA1, algorithm: tag ? validateAlgo(options.algorithm) || algorithms.SHA1 : null, }, }, }); Loading Loading @@ -1029,18 +1034,25 @@ class GetResponsePDU extends PDU { * @param {Buffer} keyArg - key of the item to gotten item. * @param {number} chunkSize - size of the got chunk. * @param {Buffer} dbVersionArg - The version of the item in the database. * @param {Buffer} tagArg - the hash of the value to put. * @param {string} algorithm - algorithm used for the tag. * @param {Object} optionsArg - optional : * {string} [options.algorithm] - algorithm used for the * tag * {Buffer} [options.tag] - the hash of the value to put. * @returns {Kinetic} - message structure following the kinetic protocol */ constructor(ackSequence, code, errorMessageArg, keyArg, chunkSize, dbVersionArg, tagArg, algorithm) { chunkSize, dbVersionArg, optionsArg) { super(); const options = optionsArg || {}; let tag = null; if (options.tag) tag = validateVersionArgument(options.tag); const detailedMessage = validateBufferOrStringArgument(errorMessageArg); const key = validateBufferOrStringArgument(keyArg); const dbVersion = validateVersionArgument(dbVersionArg); const tag = validateVersionArgument(tagArg); this._chunkSize = chunkSize; this.setCommand({ Loading @@ -1053,8 +1065,8 @@ class GetResponsePDU extends PDU { key, dbVersion, tag, algorithm: validateAlgo(algorithm) || algorithms.SHA1, algorithm: tag ? validateAlgo(options.algorithm) || algorithms.SHA1 : null, }, }, status: { Loading Loading @@ -1260,20 +1272,26 @@ class GetNextResponsePDU extends PDU { * request in a TCP connection * @param {Buffer} keyArg - key for the value that is being returned. * @param {number} dbVersionArg - the version of the object in the DB * @param {Buffer} tagArg - the hash of the value to put. * @param {number} code - response code (SUCCESS, FAIL) * @param {Buffer} errorMessageArg - Detailed error message. * @param {string} algorithm - algorithm used for the tag. * @param {Object} optionsArg - optional : * {string} [options.algorithm] - algorithm used for the * tag * {Buffer} [options.tag] - the hash of the value to put. * @returns {Kinetic} - message structure following the kinetic protocol */ constructor( ackSequence, keyArg, dbVersionArg, tagArg, code, errorMessageArg, algorithm) { ackSequence, keyArg, dbVersionArg, code, errorMessageArg, optionsArg) { super(); const options = optionsArg || {}; let tag = null; if (options.tag) tag = validateVersionArgument(options.tag); const detailedMessage = validateBufferOrStringArgument(errorMessageArg); const key = validateBufferOrStringArgument(keyArg); const tag = validateVersionArgument(tagArg); const dbVersion = validateVersionArgument(dbVersionArg); this.setCommand({ Loading @@ -1286,8 +1304,8 @@ class GetNextResponsePDU extends PDU { key, dbVersion, tag, algorithm: validateAlgo(algorithm) || algorithms.SHA1, algorithm: tag ? validateAlgo(options.algorithm) || algorithms.SHA1 : null, }, }, status: { Loading Loading @@ -1340,20 +1358,26 @@ class GetPreviousResponsePDU extends PDU { * request in a TCP connection * @param {Buffer} keyArg - key for the value that is being returned. * @param {number} dbVersionArg - the version of the object in the DB * @param {Buffer} tagArg - the hash of the value to put. * @param {number} code - response code (SUCCESS, FAIL) * @param {Buffer} errorMessageArg - Detailed error message. * @param {string} algorithm - algorithm used for the tag. * @param {Object} optionsArg - optional : * {string} [options.algorithm] - algorithm used for the * tag * {Buffer} [options.tag] - the hash of the value to put. * @returns {Kinetic} - message structure following the kinetic protocol */ constructor( ackSequence, keyArg, dbVersionArg, tagArg, code, errorMessageArg, algorithm) { ackSequence, keyArg, dbVersionArg, code, errorMessageArg, optionsArg) { super(); const options = optionsArg || {}; let tag = null; if (options.tag) tag = validateVersionArgument(options.tag); const detailedMessage = validateBufferOrStringArgument(errorMessageArg); const key = validateBufferOrStringArgument(keyArg); const tag = validateVersionArgument(tagArg); const dbVersion = validateVersionArgument(dbVersionArg); this.setCommand({ Loading @@ -1366,8 +1390,8 @@ class GetPreviousResponsePDU extends PDU { key, dbVersion, tag, algorithm: validateAlgo(algorithm) || algorithms.SHA1, algorithm: tag ? validateAlgo(options.algorithm) || algorithms.SHA1 : null, }, }, status: { Loading
tests/functional/simulTest.js +2 −3 Original line number Diff line number Diff line Loading @@ -49,7 +49,6 @@ const requestsArr = [ function requestsLauncher(request, client, optionsA) { let pdu; let tag; const options = optionsA || {}; Loading @@ -58,11 +57,11 @@ function requestsLauncher(request, client, optionsA) { pdu = new kinetic.NoOpPDU(sequence, connectionID, clusterVersion); break; case 'put': tag = crypto options.tag = crypto .createHmac('sha1', 'asdfasdf').update(chunk).digest(); pdu = new kinetic.PutPDU( sequence, connectionID, clusterVersion, options.key || key, chunk.length, tag, options); chunk.length, options); break; case 'get': pdu = new kinetic.GetPDU( Loading
tests/unit/kinetic.js +16 −17 Original line number Diff line number Diff line Loading @@ -701,14 +701,13 @@ describe('kinetic.PDU encoding()', () => { const options = { dbVersion: Buffer.from('2', 'utf8'), newVersion: Buffer.from('3', 'utf8'), tag: crypto .createHmac('sha1', 'asdfasdf').update(chunk).digest(), }; const tag = crypto .createHmac('sha1', 'asdfasdf').update(chunk).digest(); const k = new kinetic.PutPDU( 1, connectionID, clusterVersion, 'string', chunk.length, tag, options); 'string', chunk.length, options); const result = Buffer.concat([k.read(), chunk]); Loading @@ -731,14 +730,13 @@ describe('kinetic.PDU encoding()', () => { dbVersion: Buffer.from('2', 'utf8'), newVersion: Buffer.from('3', 'utf8'), force: true, tag: crypto .createHmac('sha1', 'asdfasdf').update(chunk).digest(), }; const tag = crypto .createHmac('sha1', 'asdfasdf').update(chunk).digest(); const k = new kinetic.PutPDU( 1, connectionID, clusterVersion, 'string', chunk.length, tag, options); 'string', chunk.length, options); const result = Buffer.concat([k.read(), chunk]); Loading @@ -761,14 +759,13 @@ describe('kinetic.PDU encoding()', () => { dbVersion: Buffer.from('2', 'utf8'), newVersion: Buffer.from('3', 'utf8'), force: false, tag: crypto .createHmac('sha1', 'asdfasdf').update(chunk).digest(), }; const tag = crypto .createHmac('sha1', 'asdfasdf').update(chunk).digest(); const k = new kinetic.PutPDU( 1, connectionID, clusterVersion, 'string', chunk.length, tag, options); 'string', chunk.length, options); const result = Buffer.concat([k.read(), chunk]); Loading Loading @@ -854,7 +851,7 @@ describe('kinetic.PDU encoding()', () => { const pdu = new kinetic.GetResponsePDU( 1, 1, Buffer.alloc(0), Buffer.from('qwer', 'utf8'), chunk.length, Buffer.from('1', 'utf8'), tag); chunk.length, Buffer.from('1', 'utf8'), { tag }); const result = Buffer.concat([pdu.read(), chunk]); Loading Loading @@ -1190,9 +1187,10 @@ describe('kinetic.PutPDU()', () => { const tag = crypto .createHmac('sha1', 'asdfasdf').update('HelloWorld').digest(); const k = new kinetic.PutPDU( 1, connectionID, clusterVersion, "string", 12, tag, 1, connectionID, clusterVersion, "string", 12, { dbVersion: { a: 1 }, newVersion: Buffer.from('3', 'utf8'), tag, }); k; done(new Error("constructor accepted object-typed key")); Loading @@ -1210,7 +1208,7 @@ describe('kinetic.PutPDU()', () => { .createHmac('sha1', 'asdfasdf').update('HelloWorld').digest(); const k = new kinetic.PutPDU( 1, connectionID, clusterVersion, "string", 12, tag, { newVersion: 346 }); "string", 12, { newVersion: 346, tag }); k; done(); } catch (e) { Loading @@ -1223,9 +1221,10 @@ describe('kinetic.PutPDU()', () => { const tag = crypto .createHmac('sha1', 'asdfasdf').update('HelloWorld').digest(); const k = new kinetic.PutPDU( 1, connectionID, clusterVersion, 'string', 12, tag, 1, connectionID, clusterVersion, 'string', 12, { dbVersion: Buffer.from('2', 'utf8'), newVersion: { s: 'abc' } newVersion: { s: 'abc' }, tag, }); k; done(new Error("constructor accepted string-typed key")); Loading