Skip to content

Commit ced60d1

Browse files
authored
Merge pull request #1475 from markovav-official/feature/custom-guid-type
fix: getting rid of unnecessary guid-typescript dependency
2 parents 50868c8 + 7a7c9ed commit ced60d1

19 files changed

+45
-50
lines changed

package-lock.json

-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/abstractions/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"dependencies": {
3737
"@opentelemetry/api": "^1.7.0",
3838
"@std-uritemplate/std-uritemplate": "^1.0.1",
39-
"guid-typescript": "^1.0.9",
4039
"tinyduration": "^3.3.0",
4140
"tslib": "^2.6.2",
4241
"uuid": "^11.0.2"

packages/abstractions/src/multipartBody.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* See License in the project root for license information.
55
* -------------------------------------------------------------------------------------------
66
*/
7-
import { Guid } from "guid-typescript";
87
import type { RequestAdapter } from "./requestAdapter";
98
import type { ModelSerializerFunction, Parsable, ParseNode, SerializationWriter } from "./serialization";
9+
import { createGuid } from "./utils/guidUtils";
1010

1111
/**
1212
* Defines an interface for a multipart body for request or response.
@@ -19,7 +19,7 @@ export class MultipartBody implements Parsable {
1919
* Instantiates a new MultipartBody.
2020
*/
2121
public constructor() {
22-
this._boundary = Guid.create().toString().replace(/-/g, "");
22+
this._boundary = createGuid().replace(/-/g, "");
2323
}
2424
/**
2525
* Adds or replaces a part with the given name, content type and content.

packages/abstractions/src/requestInformation.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import type { RequestConfiguration } from "./requestConfiguration";
1818
import type { RequestOption } from "./requestOption";
1919
import type { ModelSerializerFunction, Parsable, SerializationWriter } from "./serialization";
2020
import { TimeOnly } from "./timeOnly";
21-
import { Guid } from "guid-typescript";
2221

2322
/** This class represents an abstract HTTP request. */
2423
export class RequestInformation implements RequestInformationSetContent {
@@ -241,7 +240,7 @@ export class RequestInformation implements RequestInformationSetContent {
241240
};
242241

243242
private normalizeValue(value: unknown): unknown {
244-
if (value instanceof Guid || value instanceof DateOnly || value instanceof TimeOnly) {
243+
if (value instanceof DateOnly || value instanceof TimeOnly) {
245244
return value.toString();
246245
}
247246
if (value instanceof Date) {
@@ -268,7 +267,7 @@ export class RequestInformation implements RequestInformationSetContent {
268267
}
269268
}
270269
if (typeof v === "boolean" || typeof v === "number" || typeof v === "string" || Array.isArray(v)) this.queryParameters[key] = v;
271-
else if (v instanceof Guid || v instanceof DateOnly || v instanceof TimeOnly) this.queryParameters[key] = v.toString();
270+
else if (v instanceof DateOnly || v instanceof TimeOnly) this.queryParameters[key] = v.toString();
272271
else if (v instanceof Date) this.queryParameters[key] = v.toISOString();
273272
else if (v === undefined) this.queryParameters[key] = undefined;
274273
});

packages/abstractions/src/serialization/parseNode.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* See License in the project root for license information.
55
* -------------------------------------------------------------------------------------------
66
*/
7-
import type { Guid } from "guid-typescript";
7+
import type { Guid } from "../utils/guidUtils";
88

99
import type { DateOnly } from "../dateOnly";
1010
import type { Duration } from "../duration";

packages/abstractions/src/serialization/serializationWriter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* See License in the project root for license information.
55
* -------------------------------------------------------------------------------------------
66
*/
7-
import type { Guid } from "guid-typescript";
7+
import type { Guid } from "../utils/guidUtils";
88

99
import type { DateOnly } from "../dateOnly";
1010
import type { Duration } from "../duration";

packages/abstractions/src/utils/guidUtils.ts

+31-10
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,38 @@
44
* See License in the project root for license information.
55
* -------------------------------------------------------------------------------------------
66
*/
7-
import { Guid } from "guid-typescript";
7+
export type Guid = string;
8+
9+
const guidValidator = new RegExp("^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$", "i");
10+
11+
/**
12+
* Checks if the string is a valid GUID.
13+
* @param source the string to check.
14+
* @returns unchanged string if it is a valid GUID; otherwise, undefined.
15+
*/
16+
export const parseGuidString = (source?: string) => {
17+
if (source && guidValidator.test(source)) {
18+
return source;
19+
}
20+
return undefined;
21+
};
22+
23+
/**
24+
* Generates a GUID.
25+
* @returns a GUID.
26+
*/
27+
export const createGuid = () => [gen(2), gen(1), gen(1), gen(1), gen(3)].join("-");
828

929
/**
10-
* Parses a string into a Guid object.
11-
* @param source The source string.
12-
* @returns The Guid object.
30+
* Generates a part of a GUID.
31+
* @param count the number of 2 byte chunks to generate.
32+
* @returns a part of a GUID.
1333
*/
14-
export function parseGuidString(source?: string): Guid | undefined {
15-
if (source && Guid.isGuid(source)) {
16-
return Guid.parse(source);
17-
} else {
18-
return undefined;
34+
export const gen = (count: number) => {
35+
let out = "";
36+
for (let i = 0; i < count; i++) {
37+
// eslint-disable-next-line no-bitwise
38+
out += (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
1939
}
20-
}
40+
return out;
41+
};

packages/abstractions/test/common/requestInformation.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77

88
import { assert, describe, it } from "vitest";
99

10-
import { DateOnly, HttpMethod, type Parsable, parseGuidString, type RequestAdapter, RequestInformation, type SerializationWriter, type SerializationWriterFactory, TimeOnly } from "../../src";
10+
import { DateOnly, HttpMethod, type Guid, type Parsable, parseGuidString, type RequestAdapter, RequestInformation, type SerializationWriter, type SerializationWriterFactory, TimeOnly } from "../../src";
1111
import { MultipartBody } from "../../src/multipartBody";
1212
import { TestEnum } from "./store/testEnum";
13-
import { Guid } from "guid-typescript";
1413

1514
interface GetQueryParameters {
1615
select?: string[];
@@ -225,7 +224,7 @@ describe("RequestInformation", () => {
225224
const expected: string = `http://localhost/users/33933a8d-32bb-c6a8-784a-f60b5a1dd66a/2021-12-12?objectId=83afbf49-5583-152c-d7fb-176105d518bc&startDate=2021-12-12&startTime=23%3A12%3A00.0000000&timeStamp=2024-06-11T00%3A00%3A00.000Z`;
226225
const requestInformation = new RequestInformation(HttpMethod.GET);
227226
requestInformation.pathParameters["baseurl"] = baseUrl;
228-
requestInformation.pathParameters["userId"] = Guid.parse("33933a8d-32bb-c6a8-784a-f60b5a1dd66a");
227+
requestInformation.pathParameters["userId"] = parseGuidString("33933a8d-32bb-c6a8-784a-f60b5a1dd66a");
229228
requestInformation.pathParameters["date"] = DateOnly.parse("2021-12-12");
230229
requestInformation.urlTemplate = "http://localhost/users/{userId}/{date}{?objectId,startDate,startTime,endDate,endTime,timeStamp}";
231230
requestInformation.setQueryStringParametersFromRawObject<GetQueryParameters>({ objectId: parseGuidString("83afbf49-5583-152c-d7fb-176105d518bc"), startDate: new DateOnly({ year: 2021, month: 12, day: 12 }), startTime: new TimeOnly({ hours: 23, minutes: 12 }), timeStamp: new Date("2024-06-11T00:00:00.000Z") }, getQueryParameterMapper);

packages/http/fetch/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"dependencies": {
3737
"@microsoft/kiota-abstractions": "^1.0.0-preview.73",
3838
"@opentelemetry/api": "^1.7.0",
39-
"guid-typescript": "^1.0.9",
4039
"tslib": "^2.6.2"
4140
},
4241
"publishConfig": {

packages/http/fetch/test/common/mockParseNodeFactory.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
*/
77

88
/* eslint-disable @typescript-eslint/no-unused-vars */
9-
import type { DateOnly, Duration, Parsable, ParsableFactory, ParseNode, ParseNodeFactory, TimeOnly } from "@microsoft/kiota-abstractions";
10-
import type { Guid } from "guid-typescript";
9+
import type { DateOnly, Duration, Guid, Parsable, ParsableFactory, ParseNode, ParseNodeFactory, TimeOnly } from "@microsoft/kiota-abstractions";
1110

1211
export class MockParseNodeFactory implements ParseNodeFactory {
1312
parseNodeValue: ParseNode;

packages/serialization/form/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
"homepage": "https://github.com/microsoft/kiota-typescript#readme",
4141
"dependencies": {
4242
"@microsoft/kiota-abstractions": "^1.0.0-preview.73",
43-
"guid-typescript": "^1.0.9",
4443
"tslib": "^2.6.2"
4544
},
4645
"publishConfig": {

packages/serialization/form/src/formSerializationWriter.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
*/
77

88
/* eslint-disable @typescript-eslint/no-unused-expressions */
9-
import { DateOnly, Duration, type ModelSerializerFunction, type Parsable, type SerializationWriter, TimeOnly } from "@microsoft/kiota-abstractions";
10-
import type { Guid } from "guid-typescript";
9+
import { DateOnly, Duration, type Guid, type ModelSerializerFunction, type Parsable, type SerializationWriter, TimeOnly } from "@microsoft/kiota-abstractions";
1110

1211
export class FormSerializationWriter implements SerializationWriter {
1312
public writeByteArrayValue(

packages/serialization/json/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
"homepage": "https://github.com/microsoft/kiota-typescript#readme",
4141
"dependencies": {
4242
"@microsoft/kiota-abstractions": "^1.0.0-preview.73",
43-
"guid-typescript": "^1.0.9",
4443
"tslib": "^2.6.2"
4544
},
4645
"publishConfig": {

packages/serialization/json/src/jsonSerializationWriter.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
*/
77

88
/* eslint-disable @typescript-eslint/no-unused-expressions */
9-
import { DateOnly, Duration, isUntypedNode, type ModelSerializerFunction, type Parsable, type SerializationWriter, TimeOnly, type UntypedNode, isUntypedBoolean, isUntypedString, isUntypedNull, isUntypedNumber, isUntypedObject, isUntypedArray, inNodeEnv } from "@microsoft/kiota-abstractions";
10-
import type { Guid } from "guid-typescript";
9+
import { DateOnly, Duration, type Guid, isUntypedNode, type ModelSerializerFunction, type Parsable, type SerializationWriter, TimeOnly, type UntypedNode, isUntypedBoolean, isUntypedString, isUntypedNull, isUntypedNumber, isUntypedObject, isUntypedArray, inNodeEnv } from "@microsoft/kiota-abstractions";
1110

1211
export class JsonSerializationWriter implements SerializationWriter {
1312
public writeByteArrayValue(key?: string, value?: ArrayBuffer): void {

packages/serialization/json/test/common/testEntity.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
* -------------------------------------------------------------------------------------------
66
*/
77

8-
import type { BackedModel, BackingStore, Parsable, ParseNode, SerializationWriter } from "@microsoft/kiota-abstractions";
9-
import { Guid } from "guid-typescript";
8+
import type { BackedModel, BackingStore, Guid, Parsable, ParseNode, SerializationWriter } from "@microsoft/kiota-abstractions";
109

1110
const fakeBackingStore: BackingStore = {} as BackingStore;
1211

packages/serialization/multipart/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"homepage": "https://github.com/microsoft/kiota-typescript#readme",
3737
"dependencies": {
3838
"@microsoft/kiota-abstractions": "^1.0.0-preview.73",
39-
"guid-typescript": "^1.0.9",
4039
"tslib": "^2.6.2"
4140
},
4241
"devDependencies": {

packages/serialization/multipart/src/multipartSerializationWriter.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
*/
77

88
/* eslint-disable @typescript-eslint/no-unused-expressions */
9-
import { type DateOnly, type Duration, MultipartBody, type Parsable, type SerializationWriter, type ModelSerializerFunction, type TimeOnly } from "@microsoft/kiota-abstractions";
10-
import type { Guid } from "guid-typescript";
9+
import { type DateOnly, type Duration, type Guid, MultipartBody, type Parsable, type SerializationWriter, type ModelSerializerFunction, type TimeOnly } from "@microsoft/kiota-abstractions";
1110

1211
/** Serialization writer for multipart/form-data */
1312
export class MultipartSerializationWriter implements SerializationWriter {

packages/serialization/text/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
"homepage": "https://github.com/microsoft/kiota-typescript#readme",
4141
"dependencies": {
4242
"@microsoft/kiota-abstractions": "^1.0.0-preview.73",
43-
"guid-typescript": "^1.0.9",
4443
"tslib": "^2.6.2"
4544
},
4645
"publishConfig": {

packages/serialization/text/src/textSerializationWriter.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
*/
77

88
/* eslint-disable @typescript-eslint/no-unused-vars */
9-
import { inNodeEnv, type DateOnly, type Duration, type ModelSerializerFunction, type Parsable, type SerializationWriter, type TimeOnly } from "@microsoft/kiota-abstractions";
10-
import type { Guid } from "guid-typescript";
9+
import { inNodeEnv, type DateOnly, type Duration, type Guid, type ModelSerializerFunction, type Parsable, type SerializationWriter, type TimeOnly } from "@microsoft/kiota-abstractions";
1110

1211
export class TextSerializationWriter implements SerializationWriter {
1312
public writeByteArrayValue(key?: string, value?: ArrayBuffer | null): void {

0 commit comments

Comments
 (0)