Skip to content

Commit

Permalink
Replace custom code with uuid library (Azure#355)
Browse files Browse the repository at this point in the history
  • Loading branch information
southpolesteve authored Jun 20, 2019
1 parent c5034fd commit 5418e5b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 38 deletions.
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions src/client/Item/Items.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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 = {};
Expand Down
35 changes: 0 additions & 35 deletions src/common/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5418e5b

Please sign in to comment.