@microsoft/vscode-azext-utils
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -71,2 +71,3 @@ "use strict"; | ||
__exportStar(require("./utils/openUrl"), exports); | ||
__exportStar(require("./utils/randomUtils"), exports); | ||
__exportStar(require("./wizard/AzureNameStep"), exports); | ||
@@ -73,0 +74,0 @@ __exportStar(require("./wizard/AzureWizard"), exports); |
@@ -94,3 +94,3 @@ "use strict"; | ||
const scheme = getScheme(); | ||
const idHash = randomUtils_1.randomUtils.getPseudononymousStringHash(node.fullId, 'hex'); | ||
const idHash = yield randomUtils_1.randomUtils.getPseudononymousStringHash(node.fullId); | ||
// Remove special characters which may prove troublesome when parsing the uri. We'll allow the same set as `encodeUriComponent` | ||
@@ -97,0 +97,0 @@ const fileName = node.label.replace(/[^a-z0-9\-\_\.\!\~\*\'\(\)]/gi, '_'); |
@@ -32,3 +32,3 @@ "use strict"; | ||
disposables.push(quickPick); | ||
const recentlyUsedKey = getRecentlyUsedKey(options); | ||
const recentlyUsedKey = yield getRecentlyUsedKey(options); | ||
const groups = []; | ||
@@ -91,3 +91,4 @@ // eslint-disable-next-line @typescript-eslint/no-misused-promises, no-async-promise-executor | ||
if (recentlyUsedKey && !Array.isArray(result) && !result.suppressPersistence) { | ||
yield extensionVariables_1.ext.context.globalState.update(recentlyUsedKey, getRecentlyUsedValue(result)); | ||
const recentlyUsedValue = yield getRecentlyUsedValue(result); | ||
yield extensionVariables_1.ext.context.globalState.update(recentlyUsedKey, recentlyUsedValue); | ||
} | ||
@@ -136,8 +137,11 @@ return result; | ||
function getRecentlyUsedKey(options) { | ||
let recentlyUsedKey; | ||
const unhashedKey = options.id || options.placeHolder; | ||
if (unhashedKey && !options.canPickMany) { | ||
recentlyUsedKey = `showQuickPick.${randomUtils_1.randomUtils.getPseudononymousStringHash(unhashedKey)}`; | ||
} | ||
return recentlyUsedKey; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let recentlyUsedKey; | ||
const unhashedKey = options.id || options.placeHolder; | ||
if (unhashedKey && !options.canPickMany) { | ||
const hashKey = yield randomUtils_1.randomUtils.getPseudononymousStringHash(unhashedKey); | ||
recentlyUsedKey = `showQuickPick.${hashKey}`; | ||
} | ||
return recentlyUsedKey; | ||
}); | ||
} | ||
@@ -149,3 +153,3 @@ // Exported for testing. globalState should be undefined except for testing. | ||
globalState !== null && globalState !== void 0 ? globalState : (globalState = extensionVariables_1.ext.context.globalState); | ||
picks = bumpHighPriorityAndRecentlyUsed(picks, globalState, !!options.suppressPersistence, recentlyUsedKey); | ||
picks = yield bumpHighPriorityAndRecentlyUsed(picks, globalState, !!options.suppressPersistence, recentlyUsedKey); | ||
if (picks.length === 0) { | ||
@@ -180,24 +184,26 @@ if (options.noPicksMessage) { | ||
function bumpHighPriorityAndRecentlyUsed(picks, globalState, suppressPersistance, recentlyUsedKey) { | ||
const recentlyUsedValue = (suppressPersistance || !recentlyUsedKey) ? undefined : globalState.get(recentlyUsedKey); | ||
let recentlyUsedIndex = -1; | ||
if (recentlyUsedValue) { | ||
recentlyUsedIndex = picks.findIndex(p => getRecentlyUsedValue(p) === recentlyUsedValue); | ||
// Update recently used item's description | ||
if (recentlyUsedIndex >= 0) { | ||
const recentlyUsedItem = picks[recentlyUsedIndex]; | ||
if (!recentlyUsedItem.suppressPersistence) { | ||
const recentlyUsed = (0, localize_1.localize)('recentlyUsed', '(recently used)'); | ||
if (!recentlyUsedItem.description) { | ||
recentlyUsedItem.description = recentlyUsed; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const recentlyUsedValue = (suppressPersistance || !recentlyUsedKey) ? undefined : globalState.get(recentlyUsedKey); | ||
let recentlyUsedIndex = -1; | ||
if (recentlyUsedValue) { | ||
recentlyUsedIndex = yield asyncFindIndex(picks, (p) => __awaiter(this, void 0, void 0, function* () { return (yield getRecentlyUsedValue(p)) === recentlyUsedValue; })); | ||
// Update recently used item's description | ||
if (recentlyUsedIndex >= 0) { | ||
const recentlyUsedItem = picks[recentlyUsedIndex]; | ||
if (!recentlyUsedItem.suppressPersistence) { | ||
const recentlyUsed = (0, localize_1.localize)('recentlyUsed', '(recently used)'); | ||
if (!recentlyUsedItem.description) { | ||
recentlyUsedItem.description = recentlyUsed; | ||
} | ||
else if (!recentlyUsedItem.description.includes(recentlyUsed)) { | ||
recentlyUsedItem.description = `${recentlyUsedItem.description} ${recentlyUsed}`; | ||
} | ||
} | ||
else if (!recentlyUsedItem.description.includes(recentlyUsed)) { | ||
recentlyUsedItem.description = `${recentlyUsedItem.description} ${recentlyUsed}`; | ||
else { | ||
recentlyUsedIndex = -1; | ||
} | ||
} | ||
else { | ||
recentlyUsedIndex = -1; | ||
} | ||
} | ||
} | ||
return stableSortPicks(picks, recentlyUsedIndex); | ||
return stableSortPicks(picks, recentlyUsedIndex); | ||
}); | ||
} | ||
@@ -248,4 +254,25 @@ function stableSortPicks(picks, recentlyUsedIndex) { | ||
function getRecentlyUsedValue(item) { | ||
return randomUtils_1.randomUtils.getPseudononymousStringHash(item.id || item.label); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield randomUtils_1.randomUtils.getPseudononymousStringHash(item.id || item.label); | ||
}); | ||
} | ||
/** | ||
* Async FindIndex function | ||
* | ||
* @export | ||
* @template T | ||
* @param {T[]} elements | ||
* @param {CallBackFind<T>} cb | ||
* @returns {Promise<number>} | ||
*/ | ||
function asyncFindIndex(elements, cb) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
for (const [index, element] of elements.entries()) { | ||
if (yield cb(element, index, elements)) { | ||
return index; | ||
} | ||
} | ||
return -1; | ||
}); | ||
} | ||
//# sourceMappingURL=showQuickPick.js.map |
@@ -6,14 +6,31 @@ "use strict"; | ||
*--------------------------------------------------------------------------------------------*/ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.randomUtils = void 0; | ||
const crypto = require("crypto"); | ||
const crypto_1 = require("../node/crypto"); | ||
/* eslint-disable */ | ||
var randomUtils; | ||
(function (randomUtils) { | ||
function getPseudononymousStringHash(s, encoding = 'base64') { | ||
return crypto.createHash('sha256').update(s).digest(encoding); | ||
function getPseudononymousStringHash(s) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const buffer = Buffer.from(s); | ||
const hashBuffer = yield crypto_1.crypto.subtle.digest('SHA-256', buffer); | ||
const hashArray = Array.from(new Uint8Array(hashBuffer)); | ||
const hashHex = hashArray | ||
.map((b) => b.toString(16).padStart(2, "0")) | ||
.join(""); // convert bytes to hex string | ||
return hashHex; | ||
}); | ||
} | ||
randomUtils.getPseudononymousStringHash = getPseudononymousStringHash; | ||
function getRandomHexString(length = 6) { | ||
const buffer = crypto.randomBytes(Math.ceil(length / 2)); | ||
return buffer.toString('hex').slice(0, length); | ||
return crypto_1.crypto.randomUUID().slice(0, length); | ||
} | ||
@@ -20,0 +37,0 @@ randomUtils.getRandomHexString = getRandomHexString; |
{ | ||
"name": "@microsoft/vscode-azext-utils", | ||
"author": "Microsoft Corporation", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Common UI tools for developing Azure extensions for VS Code", | ||
@@ -6,0 +6,0 @@ "tags": [ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
387718
85
7465