diff --git a/package-lock.json b/package-lock.json index 3b5cd3cedb07..1e7765553502 100644 --- a/package-lock.json +++ b/package-lock.json @@ -311,6 +311,15 @@ "integrity": "sha512-EquzRwzAAs04anQ8/6MYXFKvHoD+MIlF+gu87EDda7dN9zrKvQYHsc9VFAPB1xY4tUHQVvBMtjsHrvof2EE1Mg==", "dev": true }, + "@types/uuid": { + "version": "3.4.4", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-3.4.4.tgz", + "integrity": "sha512-tPIgT0GUmdJQNSHxp0X2jnpQfBSTfGxUMc/2CXBU2mnyTFVYVa2ojpoQ74w0U2yn2vw3jnC640+77lkFFpdVDw==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/z-schema": { "version": "3.16.31", "resolved": "https://registry.npmjs.org/@types/z-schema/-/z-schema-3.16.31.tgz", diff --git a/package.json b/package.json index 7ed8c40d1cdc..a4614a9d83bb 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "@types/sinon": "7.0.10", "@types/tunnel": "^0.0.0", "@types/underscore": "^1.8.8", + "@types/uuid": "3.4.4", "abort-controller": "3.0.0", "cross-env": "5.2.0", "dotenv": "8.0.0", diff --git a/src/client/Item/Items.ts b/src/client/Item/Items.ts index aa49c07b5e38..af0e71c185f1 100644 --- a/src/client/Item/Items.ts +++ b/src/client/Item/Items.ts @@ -1,7 +1,8 @@ +import uuid from "uuid/v4"; import { ChangeFeedIterator } from "../../ChangeFeedIterator"; import { ChangeFeedOptions } from "../../ChangeFeedOptions"; import { ClientContext } from "../../ClientContext"; -import { generateGuidId, getIdFromLink, getPathFromLink, isResourceValid, ResourceType } from "../../common"; +import { getIdFromLink, getPathFromLink, isResourceValid, ResourceType } from "../../common"; import { extractPartitionKey } from "../../extractPartitionKey"; import { FetchFunctionCallback, SqlQuerySpec } from "../../queryExecutionContext"; import { QueryIterator } from "../../queryIterator"; @@ -189,7 +190,7 @@ export class Items { // Generate random document id if the id is missing in the payload and // options.disableAutomaticIdGeneration != true if ((body.id === undefined || body.id === "") && !options.disableAutomaticIdGeneration) { - body.id = generateGuidId(); + body.id = uuid(); } const err = {}; @@ -241,7 +242,7 @@ export class Items { // Generate random document id if the id is missing in the payload and // options.disableAutomaticIdGeneration != true if ((body.id === undefined || body.id === "") && !options.disableAutomaticIdGeneration) { - body.id = generateGuidId(); + body.id = uuid(); } const err = {}; diff --git a/src/common/helper.ts b/src/common/helper.ts index 8f03673d8d0f..b9871ad3acf0 100644 --- a/src/common/helper.ts +++ b/src/common/helper.ts @@ -93,41 +93,6 @@ export function getHexaDigit() { return Math.floor(Math.random() * 16).toString(16); } -// TODO: replace with well known library? -export function generateGuidId() { - let id = ""; - - for (let i = 0; i < 8; i++) { - id += getHexaDigit(); - } - - id += "-"; - - for (let i = 0; i < 4; i++) { - id += getHexaDigit(); - } - - id += "-"; - - for (let i = 0; i < 4; i++) { - id += getHexaDigit(); - } - - id += "-"; - - for (let i = 0; i < 4; i++) { - id += getHexaDigit(); - } - - id += "-"; - - for (let i = 0; i < 12; i++) { - id += getHexaDigit(); - } - - return id; -} - export function parsePath(path: string) { const pathParts = []; let currentIndex = 0;