Socket
Socket
Sign inDemoInstall

tedious

Package Overview
Dependencies
Maintainers
8
Versions
227
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tedious - npm Package Compare versions

Comparing version 12.0.0 to 12.1.0

2

lib/always-encrypted/get-parameter-encryption-metadata.js

@@ -108,5 +108,5 @@ "use strict";

});
connection.makeRequest(metadataRequest, _packet.TYPE.RPC_REQUEST, new _rpcrequestPayload.default(metadataRequest.sqlTextOrProcedure, metadataRequest.parameters, connection.currentTransactionDescriptor(), connection.config.options));
connection.makeRequest(metadataRequest, _packet.TYPE.RPC_REQUEST, new _rpcrequestPayload.default(metadataRequest.sqlTextOrProcedure, metadataRequest.parameters, connection.currentTransactionDescriptor(), connection.config.options, connection.databaseCollation));
};
exports.getParameterEncryptionMetadata = getParameterEncryptionMetadata;

@@ -115,3 +115,3 @@ "use strict";

try {
value = c.type.validate(value);
value = c.type.validate(value, c.collation);
} catch (error) {

@@ -258,3 +258,3 @@ return callback(error);

*/
constructor(table, connectionOptions, {
constructor(table, collation, connectionOptions, {
checkConstraints = false,

@@ -310,5 +310,7 @@ fireTriggers = false,

this.rowCount = void 0;
this.collation = void 0;
this.error = undefined;
this.canceled = false;
this.executionStarted = false;
this.collation = collation;
this.table = table;

@@ -377,3 +379,4 @@ this.options = connectionOptions;

objName: objName,
nullable: nullable
nullable: nullable,
collation: this.collation
};

@@ -425,7 +428,7 @@

this.rowToPacketTransform.write(this.columns.map((column, i) => {
return column.type.validate(row[i]);
return column.type.validate(row[i], column.collation);
}));
} else {
this.rowToPacketTransform.write(this.columns.map(column => {
return column.type.validate(row[column.objName]);
return column.type.validate(row[column.objName], column.collation);
}));

@@ -432,0 +435,0 @@ }

@@ -6,5 +6,5 @@ "use strict";

});
exports.codepageBySortId = exports.codepageByLcid = void 0;
exports.Collation = exports.Flags = exports.codepageBySortId = exports.codepageByLanguageId = void 0;
// http://technet.microsoft.com/en-us/library/aa176553(v=sql.80).aspx
const codepageByLcid = {
const codepageByLanguageId = {
// Arabic_*

@@ -14,2 +14,4 @@ [0x0401]: 'CP1256',

// Chinese_Traditional_Stroke_Count_*
// Chinese_Taiwan_Bopomofo_*
// Chinese_Traditional_Bopomofo_*
[0x0404]: 'CP950',

@@ -34,2 +36,3 @@ // Czech_*

// Hungarian_*
// Hungarian_Technical_*
[0x040E]: 'CP1250',

@@ -40,2 +43,4 @@ // Icelandic_*

// Japanese_XJIS_*
// Japanese_Unicode_*
// Japanese_Bushu_Kakusu_*
[0x0411]: 'CP932',

@@ -73,156 +78,79 @@ // Korean_*

[0x0425]: 'CP1257',
// Latvian_BIN
// Latvian_*
[0x0426]: 'CP1257',
// Lithuanian_BIN
// Lithuanian_*
[0x0427]: 'CP1257',
// Persian_100_BIN
// Persian_*
[0x0429]: 'CP1256',
// Vietnamese_BIN
// Vietnamese_*
[0x042A]: 'CP1258',
// Azeri_Latin_100_BIN
// Azeri_Latin_*
[0x042C]: 'CP1254',
// Upper_Sorbian_100_BIN
// Upper_Sorbian_*
[0x042E]: 'CP1252',
// Macedonian_FYROM_90_BIN
// Macedonian_FYROM_*
[0x042F]: 'CP1251',
// Sami_Norway_100_BIN
// Sami_Norway_*
[0x043B]: 'CP1252',
// Kazakh_90_BIN
// Kazakh_*
[0x043F]: 'CP1251',
// Turkmen_100_BIN
// Turkmen_*
[0x0442]: 'CP1250',
// Uzbek_Latin_90_BIN
// Uzbek_Latin_*
[0x0443]: 'CP1254',
// Tatar_90_BIN
// Tatar_*
[0x0444]: 'CP1251',
// Welsh_100_BIN
// Welsh_*
[0x0452]: 'CP1252',
// Frisian_100_BIN
// Frisian_*
[0x0462]: 'CP1252',
// Bashkir_100_BIN
// Bashkir_*
[0x046D]: 'CP1251',
// Mapudungan_100_BIN
// Mapudungan_*
[0x047A]: 'CP1252',
// Mohawk_100_BIN
// Mohawk_*
[0x047C]: 'CP1252',
// Breton_100_BIN
// Breton_*
[0x047E]: 'CP1252',
// Uighur_100_BIN
// Uighur_*
[0x0480]: 'CP1256',
// Corsican_100_BIN
// Corsican_*
[0x0483]: 'CP1252',
// Yakut_100_BIN
// Yakut_*
[0x0485]: 'CP1251',
// Dari_100_BIN
// Dari_*
[0x048C]: 'CP1256',
// Chinese_PRC_BIN
// Chinese_Simplified_Pinyin_100_BIN
// Chinese_PRC_*
// Chinese_Simplified_Pinyin_*
// Chinese_PRC_Stroke_*
// Chinese_Simplified_Stroke_Order_*
[0x0804]: 'CP936',
// Serbian_Latin_100_BIN
// Serbian_Latin_*
[0x081A]: 'CP1250',
// Azeri_Cyrillic_100_BIN
// Azeri_Cyrillic_*
[0x082C]: 'CP1251',
// Sami_Sweden_Finland_100_BIN
// Sami_Sweden_Finland_*
[0x083B]: 'CP1252',
// Tamazight_100_BIN
// Tamazight_*
[0x085F]: 'CP1252',
// Chinese_Hong_Kong_Stroke_90_BIN
// Chinese_Hong_Kong_Stroke_*
[0x0C04]: 'CP950',
// Modern_Spanish_BIN
// Modern_Spanish_*
[0x0C0A]: 'CP1252',
// Serbian_Cyrillic_100_BIN
// Serbian_Cyrillic_*
[0x0C1A]: 'CP1251',
// Chinese_Traditional_Pinyin_100_BIN
// Chinese_Traditional_Pinyin_*
// Chinese_Traditional_Stroke_Order_*
[0x1404]: 'CP950',
// Bosnian_Latin_100_BIN
// Bosnian_Latin_*
[0x141A]: 'CP1250',
// Bosnian_Cyrillic_100_BIN
// Bosnian_Cyrillic_*
[0x201A]: 'CP1251',
// German
// German_PhoneBook_*
[0x0407]: 'CP1252',
// German_PhoneBook_BIN
[0x10407]: 'CP1252',
// Hungarian_Technical_BIN
[0x1040E]: 'CP1250',
// Japanese_Unicode_BIN
[0x10411]: 'CP932',
// Georgian_Modern_Sort_BIN
[0x10437]: 'CP1252',
// Chinese_PRC_Stroke_BIN
// Chinese_Simplified_Stroke_Order_100_BIN
[0x20804]: 'CP936',
// Chinese_Traditional_Stroke_Order_100_BIN
[0x21404]: 'CP950',
// Chinese_Taiwan_Bopomofo_BIN
// Chinese_Traditional_Bopomofo_100_BIN
[0x30404]: 'CP950',
// Japanese_Bushu_Kakusu_100_BIN
[0x40411]: 'CP932',
// These LCIDs might not actually be supported by SQL Server
[0x0436]: 'CP1252',
[0x0801]: 'CP1256',
[0x0C01]: 'CP1256',
[0x1001]: 'CP1256',
[0x1401]: 'CP1256',
[0x1801]: 'CP1256',
[0x1C01]: 'CP1256',
[0x2001]: 'CP1256',
[0x2401]: 'CP1256',
[0x2801]: 'CP1256',
[0x2C01]: 'CP1256',
[0x3001]: 'CP1256',
[0x3401]: 'CP1256',
[0x3801]: 'CP1256',
[0x3C01]: 'CP1256',
[0x4001]: 'CP1256',
[0x42D]: 'CP1252',
[0x423]: 'CP1251',
[0x402]: 'CP1251',
[0x403]: 'CP1252',
[0x1004]: 'CP936',
[0x413]: 'CP1252',
[0x813]: 'CP1252',
[0x809]: 'CP1252',
[0x1009]: 'CP1252',
[0x1409]: 'CP1252',
[0xC09]: 'CP1252',
[0x1809]: 'CP1252',
[0x1C09]: 'CP1252',
[0x2409]: 'CP1252',
[0x2009]: 'CP1252',
[0x0438]: 'CP1252',
[0x80C]: 'CP1252',
[0x100C]: 'CP1252',
[0xC0C]: 'CP1252',
[0x140C]: 'CP1252',
[0x807]: 'CP1252',
[0xC07]: 'CP1252',
[0x1007]: 'CP1252',
[0x1407]: 'CP1252',
[0x439]: 'CPUTF8',
[0x104E]: 'CP1250',
[0x421]: 'CP1252',
[0x410]: 'CP1252',
[0x810]: 'CP1252',
[0x827]: 'CP1257',
[0x814]: 'CP1252',
[0x816]: 'CP1252',
[0x416]: 'CP1252',
[0x80A]: 'CP1252',
[0x100A]: 'CP1252',
[0x140A]: 'CP1252',
[0x180A]: 'CP1252',
[0x1C0A]: 'CP1252',
[0x200A]: 'CP1252',
[0x240A]: 'CP1252',
[0x280A]: 'CP1252',
[0x2C0A]: 'CP1252',
[0x300A]: 'CP1252',
[0x340A]: 'CP1252',
[0x380A]: 'CP1252',
[0x3C0A]: 'CP1252',
[0x400A]: 'CP1252',
[0x41D]: 'CP1252'
// Georgian_Modern_Sort_*
[0x0437]: 'CP1252'
};
exports.codepageByLcid = codepageByLcid;
exports.codepageByLanguageId = codepageByLanguageId;
const codepageBySortId = {

@@ -376,2 +304,67 @@ [30]: 'CP437',

};
exports.codepageBySortId = codepageBySortId;
exports.codepageBySortId = codepageBySortId;
const Flags = {
IGNORE_CASE: 1 << 0,
IGNORE_ACCENT: 1 << 1,
IGNORE_KANA: 1 << 2,
IGNORE_WIDTH: 1 << 3,
BINARY: 1 << 4,
BINARY2: 1 << 5,
UTF8: 1 << 6
};
exports.Flags = Flags;
class Collation {
static fromBuffer(buffer, offset = 0) {
let lcid = (buffer[offset + 2] & 0x0F) << 16;
lcid |= buffer[offset + 1] << 8;
lcid |= buffer[offset + 0];
let flags = (buffer[offset + 3] & 0x0F) << 4;
flags |= (buffer[offset + 2] & 0xF0) >>> 4;
const version = (buffer[offset + 3] & 0xF0) >>> 4;
const sortId = buffer[offset + 4];
return new this(lcid, flags, version, sortId);
}
constructor(lcid, flags, version, sortId) {
this.lcid = void 0;
this.flags = void 0;
this.version = void 0;
this.sortId = void 0;
this.codepage = void 0;
this.buffer = void 0;
this.buffer = undefined;
this.lcid = lcid;
this.flags = flags;
this.version = version;
this.sortId = sortId;
if (this.flags & Flags.UTF8) {
this.codepage = 'utf-8';
} else if (this.sortId) {
this.codepage = codepageBySortId[this.sortId];
} else {
// The last 16 bits of the LCID are the language id.
// The first 4 bits define additional sort orders.
const languageId = this.lcid & 0xFFFF;
this.codepage = codepageByLanguageId[languageId];
}
}
toBuffer() {
if (this.buffer) {
return this.buffer;
}
this.buffer = Buffer.alloc(5);
this.buffer[0] = this.lcid & 0xFF;
this.buffer[1] = this.lcid >>> 8 & 0xFF;
this.buffer[2] = this.lcid >>> 16 & 0x0F | (this.flags & 0x0F) << 4;
this.buffer[3] = (this.flags & 0xF0) >>> 4 | (this.version & 0x0F) << 4;
this.buffer[4] = this.sortId & 0xFF;
return this.buffer;
}
}
exports.Collation = Collation;

@@ -7,2 +7,7 @@ "use strict";

exports.default = void 0;
var _iconvLite = _interopRequireDefault(require("iconv-lite"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const NULL_LENGTH = Buffer.from([0xFF, 0xFF]);

@@ -15,5 +20,3 @@ const Char = {

declaration: function (parameter) {
// const value = parameter.value as null | string | { toString(): string };
const value = parameter.value; // Temporary solution. Remove 'any' later.
const value = parameter.value;
let length;

@@ -24,3 +27,3 @@

} else if (value != null) {
length = value.toString().length || 1;
length = value.length || 1;
} else if (value === null && !parameter.output) {

@@ -40,3 +43,3 @@ length = 1;

resolveLength: function (parameter) {
const value = parameter.value; // Temporary solution. Remove 'any' later.
const value = parameter.value;

@@ -46,7 +49,3 @@ if (parameter.length != null) {

} else if (value != null) {
if (Buffer.isBuffer(value)) {
return value.length || 1;
} else {
return value.toString().length || 1;
}
return value.length || 1;
} else {

@@ -61,2 +60,7 @@ return this.maximumLength;

buffer.writeUInt16LE(parameter.length, 1);
if (parameter.collation) {
parameter.collation.toBuffer().copy(buffer, 3, 0, 5);
}
return buffer;

@@ -66,9 +70,10 @@ },

generateParameterLength(parameter, options) {
if (parameter.value == null) {
const value = parameter.value;
if (value == null) {
return NULL_LENGTH;
}
const length = Buffer.byteLength(parameter.value.toString(), 'ascii');
const buffer = Buffer.alloc(2);
buffer.writeUInt16LE(length, 0);
buffer.writeUInt16LE(value.length, 0);
return buffer;

@@ -85,3 +90,3 @@ },

validate: function (value) {
validate: function (value, collation) {
if (value == null) {

@@ -99,3 +104,11 @@ return null;

return value;
if (!collation) {
throw new Error('No collation was set by the server for the current connection.');
}
if (!collation.codepage) {
throw new Error('The collation set by the server has no associated encoding.');
}
return _iconvLite.default.encode(value, collation.codepage);
}

@@ -102,0 +115,0 @@ };

@@ -55,2 +55,7 @@ "use strict";

buffer.writeUInt16LE(parameter.length * 2, 1);
if (parameter.collation) {
parameter.collation.toBuffer().copy(buffer, 3, 0, 5);
}
return buffer;

@@ -57,0 +62,0 @@ },

@@ -29,4 +29,8 @@ "use strict";

buffer.writeUInt8(this.id, 0);
buffer.writeInt32LE(parameter.length, 1); // TODO: Collation handling
buffer.writeInt32LE(parameter.length, 1);
if (parameter.collation) {
parameter.collation.toBuffer().copy(buffer, 5, 0, 5);
}
return buffer;

@@ -33,0 +37,0 @@ },

@@ -64,2 +64,6 @@ "use strict";

if (parameter.collation) {
parameter.collation.toBuffer().copy(buffer, 3, 0, 5);
}
return buffer;

@@ -66,0 +70,0 @@ },

@@ -7,2 +7,7 @@ "use strict";

exports.default = void 0;
var _iconvLite = _interopRequireDefault(require("iconv-lite"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const NULL_LENGTH = Buffer.from([0xFF, 0xFF, 0xFF, 0xFF]);

@@ -18,3 +23,3 @@ const Text = {

resolveLength: function (parameter) {
const value = parameter.value; // Temporary solution. Remove 'any' later.
const value = parameter.value;

@@ -31,4 +36,8 @@ if (value != null) {

buffer.writeUInt8(this.id, 0);
buffer.writeInt32LE(parameter.length, 1); // TODO: Collation handling
buffer.writeInt32LE(parameter.length, 1);
if (parameter.collation) {
parameter.collation.toBuffer().copy(buffer, 5, 0, 5);
}
return buffer;

@@ -38,3 +47,5 @@ },

generateParameterLength(parameter, options) {
if (parameter.value == null) {
const value = parameter.value;
if (value == null) {
return NULL_LENGTH;

@@ -44,3 +55,3 @@ }

const buffer = Buffer.alloc(4);
buffer.writeInt32LE(parameter.value.length, 0);
buffer.writeInt32LE(value.length, 0);
return buffer;

@@ -50,9 +61,11 @@ },

generateParameterData: function* (parameter, options) {
if (parameter.value == null) {
const value = parameter.value;
if (value == null) {
return;
}
yield Buffer.from(parameter.value.toString(), 'ascii');
yield value;
},
validate: function (value) {
validate: function (value, collation) {
if (value == null) {

@@ -70,3 +83,11 @@ return null;

return value;
if (!collation) {
throw new Error('No collation was set by the server for the current connection.');
}
if (!collation.codepage) {
throw new Error('The collation set by the server has no associated encoding.');
}
return _iconvLite.default.encode(value, collation.codepage);
}

@@ -73,0 +94,0 @@ };

@@ -7,2 +7,7 @@ "use strict";

exports.default = void 0;
var _iconvLite = _interopRequireDefault(require("iconv-lite"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const MAX = (1 << 16) - 1;

@@ -19,4 +24,3 @@ const UNKNOWN_PLP_LEN = Buffer.from([0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]);

declaration: function (parameter) {
const value = parameter.value; // Temporary solution. Remove 'any' later.
const value = parameter.value;
let length;

@@ -27,3 +31,3 @@

} else if (value != null) {
length = value.toString().length || 1;
length = value.length || 1;
} else if (value === null && !parameter.output) {

@@ -42,3 +46,3 @@ length = 1;

resolveLength: function (parameter) {
const value = parameter.value; // Temporary solution. Remove 'any' later.
const value = parameter.value;

@@ -48,7 +52,3 @@ if (parameter.length != null) {

} else if (value != null) {
if (Buffer.isBuffer(parameter.value)) {
return value.length || 1;
} else {
return value.toString().length || 1;
}
return value.length || 1;
} else {

@@ -69,2 +69,6 @@ return this.maximumLength;

if (parameter.collation) {
parameter.collation.toBuffer().copy(buffer, 3, 0, 5);
}
return buffer;

@@ -74,3 +78,5 @@ },

generateParameterLength(parameter, options) {
if (parameter.value == null) {
const value = parameter.value;
if (value == null) {
if (parameter.length <= this.maximumLength) {

@@ -83,12 +89,5 @@ return NULL_LENGTH;

let value = parameter.value;
if (parameter.length <= this.maximumLength) {
if (!Buffer.isBuffer(value)) {
value = value.toString();
}
const length = Buffer.byteLength(value, 'ascii');
const buffer = Buffer.alloc(2);
buffer.writeUInt16LE(length, 0);
buffer.writeUInt16LE(value.length, 0);
return buffer;

@@ -101,31 +100,16 @@ } else {

*generateParameterData(parameter, options) {
if (parameter.value == null) {
const value = parameter.value;
if (value == null) {
return;
}
let value = parameter.value;
if (!Buffer.isBuffer(value)) {
value = value.toString();
}
if (parameter.length <= this.maximumLength) {
if (Buffer.isBuffer(value)) {
yield value;
} else {
yield Buffer.from(value, 'ascii');
}
yield value;
} else {
const length = Buffer.byteLength(value, 'ascii');
if (length > 0) {
if (value.length > 0) {
const buffer = Buffer.alloc(4);
buffer.writeUInt32LE(length, 0);
buffer.writeUInt32LE(value.length, 0);
yield buffer;
if (Buffer.isBuffer(value)) {
yield value;
} else {
yield Buffer.from(value, 'ascii');
}
yield value;
}

@@ -137,3 +121,3 @@

validate: function (value) {
validate: function (value, collation) {
if (value == null) {

@@ -151,3 +135,11 @@ return null;

return value;
if (!collation) {
throw new Error('No collation was set by the server for the current connection.');
}
if (!collation.codepage) {
throw new Error('The collation set by the server has no associated encoding.');
}
return _iconvLite.default.encode(value, collation.codepage);
}

@@ -154,0 +146,0 @@ };

@@ -18,19 +18,3 @@ "use strict";

parser.readBuffer(5, collationData => {
let lcid = (collationData[2] & 0x0F) << 16;
lcid |= collationData[1] << 8;
lcid |= collationData[0]; // This may not be extracting the correct nibbles in the correct order.
let flags = collationData[3] >> 4;
flags |= collationData[2] & 0xF0; // This may not be extracting the correct nibble.
const version = collationData[3] & 0x0F;
const sortId = collationData[4];
const codepage = _collation.codepageBySortId[sortId] || _collation.codepageByLcid[lcid] || 'CP1252';
callback({
lcid,
flags,
version,
sortId,
codepage
});
callback(_collation.Collation.fromBuffer(collationData));
});

@@ -37,0 +21,0 @@ }

@@ -306,3 +306,3 @@ "use strict";

validateParameters() {
validateParameters(collation) {
for (let i = 0, len = this.parameters.length; i < len; i++) {

@@ -312,3 +312,3 @@ const parameter = this.parameters[i];

try {
parameter.value = parameter.type.validate(parameter.value);
parameter.value = parameter.type.validate(parameter.value, collation);
} catch (error) {

@@ -315,0 +315,0 @@ throw new _errors.RequestError('Validation failed for parameter \'' + parameter.name + '\'. ' + error.message, 'EPARAM');

@@ -32,3 +32,3 @@ "use strict";

class RpcRequestPayload {
constructor(procedure, parameters, txnDescriptor, options) {
constructor(procedure, parameters, txnDescriptor, options, collation) {
this.procedure = void 0;

@@ -38,2 +38,3 @@ this.parameters = void 0;

this.txnDescriptor = void 0;
this.collation = void 0;
this.procedure = procedure;

@@ -43,2 +44,3 @@ this.parameters = parameters;

this.txnDescriptor = txnDescriptor;
this.collation = collation;
}

@@ -115,2 +117,6 @@

if (this.collation) {
param.collation = this.collation;
}
yield type.generateTypeInfo(param, this.options);

@@ -117,0 +123,0 @@ yield type.generateParameterLength(param, this.options);

@@ -8,2 +8,4 @@ "use strict";

var _collation = require("../collation");
var _token = require("./token");

@@ -98,3 +100,7 @@

case 'SQL_COLLATION':
return callback(new _token.CollationChangeToken(newValue, oldValue));
{
const newCollation = newValue.length ? _collation.Collation.fromBuffer(newValue) : undefined;
const oldCollation = oldValue.length ? _collation.Collation.fromBuffer(oldValue) : undefined;
return callback(new _token.CollationChangeToken(newCollation, oldCollation));
}

@@ -101,0 +107,0 @@ case 'BEGIN_TXN':

@@ -30,3 +30,3 @@ {

"license": "MIT",
"version": "12.0.0",
"version": "12.1.0",
"main": "./lib/tedious.js",

@@ -33,0 +33,0 @@ "repository": {

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc