Remove node builtin usage in favor of universal packages/APIs (#328)
* Remove node builtin usage in favor of universal packages/APIs * make node 8 happy * Run consumer tests * Extract build * Script refactor * Fix typo * Add more typescript versions * Update gitignore * Add test for getUserAgent
This commit is contained in:
Родитель
6f80385f17
Коммит
48d2496761
|
@ -265,9 +265,9 @@ dist-esm/
|
|||
dist-test/
|
||||
dist-commonjs/
|
||||
temp/
|
||||
ts-test/package-lock.json
|
||||
ts-test/package.json
|
||||
ts-test/*.js
|
||||
consumer-test/package-lock.json
|
||||
consumer-test/package.json
|
||||
consumer-test/*.js
|
||||
test/**/*.js
|
||||
test/**/*.js.map
|
||||
test/**/*.d.ts
|
||||
|
|
|
@ -60,11 +60,12 @@ jobs:
|
|||
- script: npm run build
|
||||
displayName: "npm run build"
|
||||
|
||||
- bash: ACCOUNT_HOST=$COSMOSDBEMULATOR_ENDPOINT NODE_TLS_REJECT_UNAUTHORIZED="0" npm run test
|
||||
failOnStderr: true
|
||||
- bash: npm run test -- --forbid-only
|
||||
displayName: "npm test"
|
||||
env:
|
||||
MOCHA_TIMEOUT: 100000
|
||||
- bash: npm run test-consumer
|
||||
displayName: "TypeScript consumer tests"
|
||||
# - job: NightlyEmulator
|
||||
# pool:
|
||||
# vmImage: vs2017-win2016
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const execa = require("execa");
|
||||
|
||||
let versions = ["3.0", "3.1"];
|
||||
let versions = ["3.0", "3.1", "3.2", "3.3", "3.4"];
|
||||
|
||||
if (!process.env.SKIP_LATEST) {
|
||||
versions.push("latest");
|
||||
|
|
|
@ -950,7 +950,6 @@
|
|||
"version": "6.0.5",
|
||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz",
|
||||
"integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"nice-try": "^1.0.4",
|
||||
"path-key": "^2.0.1",
|
||||
|
@ -1170,7 +1169,6 @@
|
|||
"version": "1.4.1",
|
||||
"resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.1.tgz",
|
||||
"integrity": "sha512-1MkrZNvWTKCaigbn+W15elq2BB/L22nqrSY5DKlo3X6+vclJm8Bb5djXJBmEX6fS3+zCh/F4VBK5Z2KxJt4s2Q==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"once": "^1.4.0"
|
||||
}
|
||||
|
@ -1362,7 +1360,6 @@
|
|||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/execa/-/execa-1.0.0.tgz",
|
||||
"integrity": "sha512-adbxcyWV46qiHyvSp50TKt05tB4tK3HcmF7/nxfAdhnox83seTDbwnaqKO4sXRy7roHAIFqJP/Rw/AuEbX61LA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"cross-spawn": "^6.0.0",
|
||||
"get-stream": "^4.0.0",
|
||||
|
@ -1377,7 +1374,6 @@
|
|||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz",
|
||||
"integrity": "sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"pump": "^3.0.0"
|
||||
}
|
||||
|
@ -1386,7 +1382,6 @@
|
|||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",
|
||||
"integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"end-of-stream": "^1.1.0",
|
||||
"once": "^1.3.1"
|
||||
|
@ -2804,8 +2799,7 @@
|
|||
"is-stream": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
|
||||
"integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=",
|
||||
"dev": true
|
||||
"integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ="
|
||||
},
|
||||
"is-valid-glob": {
|
||||
"version": "0.3.0",
|
||||
|
@ -2837,8 +2831,7 @@
|
|||
"isexe": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
|
||||
"integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=",
|
||||
"dev": true
|
||||
"integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA="
|
||||
},
|
||||
"isobject": {
|
||||
"version": "3.0.1",
|
||||
|
@ -3156,6 +3149,11 @@
|
|||
"yallist": "^2.1.2"
|
||||
}
|
||||
},
|
||||
"macos-release": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/macos-release/-/macos-release-2.2.0.tgz",
|
||||
"integrity": "sha512-iV2IDxZaX8dIcM7fG6cI46uNmHUxHE4yN+Z8tKHAW1TBPMZDIKHf/3L+YnOuj/FK9il14UaVdHmiQ1tsi90ltA=="
|
||||
},
|
||||
"make-error": {
|
||||
"version": "1.3.5",
|
||||
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.5.tgz",
|
||||
|
@ -3510,8 +3508,7 @@
|
|||
"nice-try": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.4.tgz",
|
||||
"integrity": "sha512-2NpiFHqC87y/zFke0fC0spBXL3bBsoh/p5H1EFhshxjCR5+0g2d6BiXbUFz9v1sAcxsk2htp2eQnNIci2dIYcA==",
|
||||
"dev": true
|
||||
"integrity": "sha512-2NpiFHqC87y/zFke0fC0spBXL3bBsoh/p5H1EFhshxjCR5+0g2d6BiXbUFz9v1sAcxsk2htp2eQnNIci2dIYcA=="
|
||||
},
|
||||
"nise": {
|
||||
"version": "1.4.10",
|
||||
|
@ -3557,7 +3554,6 @@
|
|||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz",
|
||||
"integrity": "sha1-NakjLfo11wZ7TLLd8jV7GHFTbF8=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"path-key": "^2.0.0"
|
||||
}
|
||||
|
@ -3654,7 +3650,6 @@
|
|||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"wrappy": "1"
|
||||
}
|
||||
|
@ -3697,6 +3692,15 @@
|
|||
"integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=",
|
||||
"dev": true
|
||||
},
|
||||
"os-name": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/os-name/-/os-name-3.1.0.tgz",
|
||||
"integrity": "sha512-h8L+8aNjNcMpo/mAIBPn5PXCM16iyPGjHNWo6U1YO8sJTMHtEtyczI6QJnLoplswm6goopQkqc7OAnjhWcugVg==",
|
||||
"requires": {
|
||||
"macos-release": "^2.2.0",
|
||||
"windows-release": "^3.1.0"
|
||||
}
|
||||
},
|
||||
"os-tmpdir": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
|
||||
|
@ -3706,8 +3710,7 @@
|
|||
"p-finally": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz",
|
||||
"integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=",
|
||||
"dev": true
|
||||
"integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4="
|
||||
},
|
||||
"pac-proxy-agent": {
|
||||
"version": "3.0.0",
|
||||
|
@ -3789,8 +3792,7 @@
|
|||
"path-key": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz",
|
||||
"integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=",
|
||||
"dev": true
|
||||
"integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A="
|
||||
},
|
||||
"path-parse": {
|
||||
"version": "1.0.5",
|
||||
|
@ -4105,8 +4107,7 @@
|
|||
"semver": {
|
||||
"version": "5.5.0",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz",
|
||||
"integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==",
|
||||
"dev": true
|
||||
"integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA=="
|
||||
},
|
||||
"set-getter": {
|
||||
"version": "0.1.0",
|
||||
|
@ -4156,7 +4157,6 @@
|
|||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz",
|
||||
"integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"shebang-regex": "^1.0.0"
|
||||
}
|
||||
|
@ -4164,8 +4164,7 @@
|
|||
"shebang-regex": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz",
|
||||
"integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=",
|
||||
"dev": true
|
||||
"integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM="
|
||||
},
|
||||
"shelljs": {
|
||||
"version": "0.8.3",
|
||||
|
@ -4181,8 +4180,7 @@
|
|||
"signal-exit": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz",
|
||||
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=",
|
||||
"dev": true
|
||||
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0="
|
||||
},
|
||||
"sinon": {
|
||||
"version": "7.2.7",
|
||||
|
@ -4521,8 +4519,7 @@
|
|||
"strip-eof": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz",
|
||||
"integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=",
|
||||
"dev": true
|
||||
"integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8="
|
||||
},
|
||||
"thunkify": {
|
||||
"version": "2.1.2",
|
||||
|
@ -4804,6 +4801,14 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"universal-user-agent": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-2.1.0.tgz",
|
||||
"integrity": "sha512-8itiX7G05Tu3mGDTdNY2fB4KJ8MgZLS54RdG6PkkfwMAavrXu1mV/lls/GABx9O3Rw4PnTtasxrvbMQoBYY92Q==",
|
||||
"requires": {
|
||||
"os-name": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"universalify": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
|
||||
|
@ -4951,11 +4956,18 @@
|
|||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/which/-/which-1.3.0.tgz",
|
||||
"integrity": "sha512-xcJpopdamTuY5duC/KnTTNBraPK54YwpenP4lzxU8H91GudWpFv38u0CKjclE1Wi2EH2EDz5LRcHcKbCIzqGyg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"isexe": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"windows-release": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://registry.npmjs.org/windows-release/-/windows-release-3.2.0.tgz",
|
||||
"integrity": "sha512-QTlz2hKLrdqukrsapKsINzqMgOUpQW268eJ0OaOpJN32h272waxR9fkB9VoWRtK7uKHG5EHJcTXQBD8XZVJkFA==",
|
||||
"requires": {
|
||||
"execa": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"wordwrap": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz",
|
||||
|
@ -4965,8 +4977,7 @@
|
|||
"wrappy": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
|
||||
"dev": true
|
||||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
|
||||
},
|
||||
"ws": {
|
||||
"version": "3.3.3",
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
"test": "tsc -b --verbose && mocha -r esm -r dotenv/config -r ./test/common/setup.js \"./test/**/*.spec.js\" --timeout 100000",
|
||||
"prepack": "npm install && npm run build",
|
||||
"test-browser": "karma start ./karma.config.js --single-run",
|
||||
"ci": "npm run build && npm run test -- --forbid-only && node consumer-test.js"
|
||||
"test-consumer": "node consumer-test.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@microsoft/api-extractor": "6.3.0",
|
||||
|
@ -86,7 +86,8 @@
|
|||
"node-fetch": "2.3.0",
|
||||
"priorityqueuejs": "1.0.0",
|
||||
"semaphore": "1.0.5",
|
||||
"tslib": "^1.9.3"
|
||||
"tslib": "^1.9.3",
|
||||
"universal-user-agent": "2.1.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import * as os from "os";
|
||||
import userAgent from "universal-user-agent";
|
||||
import { Constants } from "./constants";
|
||||
|
||||
/** @hidden */
|
||||
|
@ -9,34 +9,6 @@ export function getPlatformDefaultHeaders(): { [key: string]: string } {
|
|||
return defaultHeaders;
|
||||
}
|
||||
|
||||
export function getDecodedDataLength(encodedData: string): number {
|
||||
const buffer = Buffer.from(encodedData, "base64");
|
||||
return buffer.length;
|
||||
}
|
||||
|
||||
export function getUserAgent() {
|
||||
// gets the user agent in the following format
|
||||
// "{OSName}/{OSVersion} Nodejs/{NodejsVersion} documentdb-nodejs-sdk/{SDKVersion}"
|
||||
// for example:
|
||||
// "linux/3.4.0+ Nodejs/v0.10.25 documentdb-nodejs-sdk/1.10.0"
|
||||
// "win32/10.0.14393 Nodejs/v4.4.7 documentdb-nodejs-sdk/1.10.0"
|
||||
const osName = getSafeUserAgentSegmentInfo(os.platform());
|
||||
const osVersion = getSafeUserAgentSegmentInfo(os.release());
|
||||
const nodejsVersion = getSafeUserAgentSegmentInfo(process.version);
|
||||
|
||||
const userAgent = `${osName}/${osVersion} Nodejs/${nodejsVersion} ${Constants.SDKName}/${Constants.SDKVersion}`;
|
||||
return userAgent;
|
||||
}
|
||||
|
||||
export function getSafeUserAgentSegmentInfo(s: string) {
|
||||
// catch null, undefined, etc
|
||||
if (typeof s !== "string") {
|
||||
s = "unknown";
|
||||
}
|
||||
// remove all white spaces
|
||||
s = s.replace(/\s+/g, "");
|
||||
if (!s) {
|
||||
s = "unknown";
|
||||
}
|
||||
return s;
|
||||
return `${userAgent()} ${Constants.SDKName}/${Constants.SDKVersion}`;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import * as url from "url";
|
||||
import { Constants, OperationType, ResourceType, sleep } from "./common";
|
||||
import { CosmosClientOptions } from "./CosmosClientOptions";
|
||||
import { DatabaseAccount } from "./documents";
|
||||
|
@ -196,7 +195,7 @@ export class GlobalEndpointManager {
|
|||
// For defaultEndpoint like 'https://contoso.documents.azure.com:443/' parse it to generate URL format
|
||||
// This defaultEndpoint should be global endpoint(and cannot be a locational endpoint)
|
||||
// and we agreed to document that
|
||||
const endpointUrl = url.parse(defaultEndpoint, true, true);
|
||||
const endpointUrl = new URL(defaultEndpoint);
|
||||
|
||||
// hostname attribute in endpointUrl will return 'contoso.documents.azure.com'
|
||||
if (endpointUrl.hostname) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import * as http from "http";
|
||||
import * as net from "net";
|
||||
import { URL } from "url";
|
||||
import ProxyAgent from "proxy-agent";
|
||||
import * as url from "url";
|
||||
import { CosmosClient } from "../../dist-esm/index";
|
||||
import { endpoint, masterKey } from "../common/_testConfig";
|
||||
import { addEntropy } from "../common/TestHelpers";
|
||||
|
@ -15,7 +15,7 @@ if (!isBrowser()) {
|
|||
});
|
||||
|
||||
proxy.on("connect", (req, clientSocket, head) => {
|
||||
const serverUrl = url.parse(`http://${req.url}`);
|
||||
const serverUrl = new URL(`http://${req.url}`);
|
||||
const serverSocket = net.connect(
|
||||
parseInt(serverUrl.port, 10),
|
||||
serverUrl.hostname,
|
||||
|
|
|
@ -1,48 +1,25 @@
|
|||
import assert from "assert";
|
||||
import * as os from "os";
|
||||
import * as util from "util";
|
||||
import { getSafeUserAgentSegmentInfo, getUserAgent } from "../../dist-esm/common/index";
|
||||
import { Constants } from "../../dist-esm/index";
|
||||
import { getUserAgent } from "../../dist-esm/common";
|
||||
|
||||
const packageJson = require("../../package.json");
|
||||
const packageVersion = packageJson["version"];
|
||||
const constantVersion = Constants.SDKVersion;
|
||||
|
||||
const userAgent = getUserAgent();
|
||||
|
||||
describe("getUserAgent", function() {
|
||||
it("getUserAgent()", function() {
|
||||
const userAgent = getUserAgent();
|
||||
const expectedUserAgent = util.format(
|
||||
"%s/%s Nodejs/%s azure-cosmos-js/%s",
|
||||
os.platform(),
|
||||
os.release(),
|
||||
process.version,
|
||||
Constants.SDKVersion
|
||||
);
|
||||
assert.strictEqual(userAgent, expectedUserAgent, "invalid UserAgent format");
|
||||
it("should contain the current SDK version", () => {
|
||||
assert(userAgent.includes(packageVersion));
|
||||
});
|
||||
|
||||
describe("Platform.getSafeUserAgentSegmentInfo()", function() {
|
||||
it("Removing spaces", function() {
|
||||
const safeString = getSafeUserAgentSegmentInfo("a b c");
|
||||
assert.strictEqual(safeString, "abc");
|
||||
});
|
||||
it("empty string handling", function() {
|
||||
const safeString = getSafeUserAgentSegmentInfo("");
|
||||
assert.strictEqual(safeString, "unknown");
|
||||
});
|
||||
it("undefined", function() {
|
||||
const safeString = getSafeUserAgentSegmentInfo(undefined);
|
||||
assert.strictEqual(safeString, "unknown");
|
||||
});
|
||||
it("null", function() {
|
||||
const safeString = getSafeUserAgentSegmentInfo(null);
|
||||
assert.strictEqual(safeString, "unknown");
|
||||
});
|
||||
it("should contain the current node version", () => {
|
||||
assert(userAgent.includes(process.version.replace("v", "")));
|
||||
});
|
||||
});
|
||||
|
||||
describe("Version", function() {
|
||||
it("should have matching constant version & package version", function() {
|
||||
const packageVersion = packageJson["version"];
|
||||
const constantVersion = Constants.SDKVersion;
|
||||
assert.equal(constantVersion, packageVersion, "Package.json and Constants.SDKVersion don't match");
|
||||
});
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче