Skip to content

Commit

Permalink
Merge branch 'master' into SNOW-896752-node20
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pmotacki authored Sep 29, 2023
2 parents 3f7ae45 + a4bdd66 commit 9b369c3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 41 deletions.
10 changes: 3 additions & 7 deletions lib/connection/connection_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const ErrorCodes = Errors.codes;
const NativeTypes = require('./result/data_types').NativeTypes;
const GlobalConfig = require('../global_config');
const authenticationTypes = require('../authentication/authentication').authenticationTypes;
const stringSimilarity = require("string-similarity");
const levenshtein = require('fastest-levenshtein');
const RowMode = require('./../constants/row_mode');
const WAIT_FOR_BROWSER_ACTION_TIMEOUT = 120000;
const DEFAULT_PARAMS =
Expand Down Expand Up @@ -484,12 +484,8 @@ function ConnectionConfig(options, validateCredentials, qaMode, clientInfo)
{
if (!DEFAULT_PARAMS.includes(key))
{
var matches = stringSimilarity.findBestMatch(key, DEFAULT_PARAMS);
console.error(`"${key}" is an unknown connection parameter`);
if (matches.bestMatchIndex > 0)
{
console.error(`Did you mean "${matches.bestMatch.target}"`);
}
const result = levenshtein.closest(key, DEFAULT_PARAMS);
console.error(`"${key}" is an unknown connection parameter. Did you mean "${result}"?`);
}
}
}
Expand Down
27 changes: 3 additions & 24 deletions lib/http/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,8 @@ HttpClient.prototype.request = function (options)
timeout: timeout,
requestOCSP: true,
rejectUnauthorized: true,
// axios does not know how to decode response with content-encoding GZIP (it should be gzip)
// that we receive from GCS, so let's get response as arraybuffer and unzip it outside axios
// issue in axios about case insensitive content-encoding is marked as won't fix: https://github.com/axios/axios/issues/4280
// for all other responses we manually parse jsons or other structures from the server so they need to be text
// TODO SNOW-917244 we can get rid of this logic when axios > 1.5.0 will be release as it should contain fix https://github.com/axios/axios/issues/5890
responseType: options.url.includes('storage.googleapis.com') ? 'arraybuffer' : 'text',
// we manually parse jsons or other structures from the server so they need to be text
responseType: 'text',
};

let mock;
Expand All @@ -106,24 +102,7 @@ HttpClient.prototype.request = function (options)

request = axios.request(requestOptions).then(response => {
if (Util.isFunction(options.callback)) {
if (options.url.includes('storage.googleapis.com')) {
// we request that GCS returns body as arraybuffer, not text
// when it is GZIPped then we have to unzip it
// otherwise we should convert arraybuffer to string
// TODO SNOW-917244 we can get rid of this logic when axios > 1.5.0 will be release as it should contain fix https://github.com/axios/axios/issues/5890
try {
if (response.headers['content-encoding'] === 'GZIP') {
const unzippedData = zlib.gunzipSync(response.data).toString('utf-8');
return options.callback(null, normalizeResponse(response), unzippedData);
} else {
return options.callback(null, normalizeResponse(response), new TextDecoder('utf-8').decode(response.data));
}
} catch (e) {
return options.callback(e, null, null);
}
} else {
return options.callback(null, normalizeResponse(response), response.data);
}
return options.callback(null, normalizeResponse(response), response.data);
} else {
Logger.getInstance().trace(`Callback function was not provided for the call to ${options.url}`);
return null;
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "snowflake-sdk",
"version": "1.8.0",
"version": "1.9.0",
"description": "Node.js driver for Snowflake",
"dependencies": {
"@aws-sdk/client-s3": "^3.388.0",
Expand All @@ -10,7 +10,7 @@
"agent-base": "^6.0.2",
"asn1.js-rfc2560": "^5.0.0",
"asn1.js-rfc5280": "^3.0.0",
"axios": "^1.5.0",
"axios": "^1.5.1",
"big-integer": "^1.6.43",
"bignumber.js": "^2.4.0",
"binascii": "0.0.2",
Expand All @@ -20,6 +20,7 @@
"expand-tilde": "^2.0.2",
"extend": "^3.0.2",
"fast-xml-parser": "^4.2.5",
"fastest-levenshtein": "^1.0.16",
"generic-pool": "^3.8.2",
"glob": "^7.1.6",
"https-proxy-agent": "^5.0.1",
Expand All @@ -31,7 +32,6 @@
"open": "^7.3.1",
"python-struct": "^1.1.3",
"simple-lru-cache": "^0.0.2",
"string-similarity": "^4.0.4",
"tmp": "^0.2.1",
"uuid": "^8.3.2",
"winston": "^3.1.0"
Expand Down
11 changes: 4 additions & 7 deletions test/integration/testConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ describe("Connection test - validate default parameters", function () {
});
});
assert.deepEqual(output, [
'"waerhouse" is an unknown connection parameter\n',
'Did you mean "warehouse"\n',
'"waerhouse" is an unknown connection parameter. Did you mean "warehouse"?\n',
]);
});

Expand All @@ -162,7 +161,7 @@ describe("Connection test - validate default parameters", function () {
validateDefaultParameters: true,
});
});
assert.deepEqual(output, ['"db" is an unknown connection parameter\n']);
assert.deepEqual(output, ['"db" is an unknown connection parameter. Did you mean "host"?\n']);
});

it('Invalid "database" parameter', function () {
Expand All @@ -176,8 +175,7 @@ describe("Connection test - validate default parameters", function () {
});
});
assert.deepEqual(output, [
'"datbse" is an unknown connection parameter\n',
'Did you mean "database"\n',
'"datbse" is an unknown connection parameter. Did you mean "database"?\n',
]);
});

Expand Down Expand Up @@ -205,8 +203,7 @@ describe("Connection test - validate default parameters", function () {
});
});
assert.deepEqual(output, [
'"shcema" is an unknown connection parameter\n',
'Did you mean "schema"\n',
'"shcema" is an unknown connection parameter. Did you mean "schema"?\n',
]);
});
});
Expand Down

0 comments on commit 9b369c3

Please sign in to comment.