Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: getting rid of unnecessary guid-typescript dependency #1474

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions package-lock.json

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

1 change: 0 additions & 1 deletion packages/abstractions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"dependencies": {
"@opentelemetry/api": "^1.7.0",
"@std-uritemplate/std-uritemplate": "^1.0.1",
"guid-typescript": "^1.0.9",
"tinyduration": "^3.3.0",
"tslib": "^2.6.2",
"uuid": "^11.0.2"
Expand Down
11 changes: 9 additions & 2 deletions packages/abstractions/src/multipartBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
import { Guid } from "guid-typescript";
import type { RequestAdapter } from "./requestAdapter";
import type { ModelSerializerFunction, Parsable, ParseNode, SerializationWriter } from "./serialization";
import { createGuid } from "./utils/guidUtils";

/**
* Defines an interface for a multipart body for request or response.
Expand All @@ -15,12 +15,14 @@ export class MultipartBody implements Parsable {
private readonly _boundary: string;
private readonly _parts: Record<string, MultipartEntry> = {};
public requestAdapter?: RequestAdapter;

/**
* Instantiates a new MultipartBody.
*/
public constructor() {
this._boundary = Guid.create().toString().replace(/-/g, "");
this._boundary = createGuid().replace(/-/g, "");
}

/**
* Adds or replaces a part with the given name, content type and content.
* @param partName the name of the part to add or replace.
Expand All @@ -42,6 +44,7 @@ export class MultipartBody implements Parsable {
serializationCallback,
};
}

/**
* Gets the content of the part with the given name.
* @param partName the name of the part to get the content for.
Expand All @@ -54,6 +57,7 @@ export class MultipartBody implements Parsable {
if (!candidate) return undefined;
return candidate.content as T;
}

/**
* Removes the part with the given name.
* @param partName the name of the part to remove.
Expand All @@ -66,6 +70,7 @@ export class MultipartBody implements Parsable {
delete this._parts[normalizePartName];
return true;
}

/**
* Gets the boundary used to separate each part.
* @returns the boundary value.
Expand All @@ -77,6 +82,7 @@ export class MultipartBody implements Parsable {
private normalizePartName(original: string): string {
return original.toLocaleLowerCase();
}

/**
* Lists all the parts in the multipart body.
* WARNING: meant for internal use only
Expand All @@ -86,6 +92,7 @@ export class MultipartBody implements Parsable {
return this._parts;
}
}

interface MultipartEntry {
contentType: string;
content: any;
Expand Down
5 changes: 2 additions & 3 deletions packages/abstractions/src/requestInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import type { RequestConfiguration } from "./requestConfiguration";
import type { RequestOption } from "./requestOption";
import type { ModelSerializerFunction, Parsable, SerializationWriter } from "./serialization";
import { TimeOnly } from "./timeOnly";
import { Guid } from "guid-typescript";

/** This class represents an abstract HTTP request. */
export class RequestInformation implements RequestInformationSetContent {
Expand Down Expand Up @@ -241,7 +240,7 @@ export class RequestInformation implements RequestInformationSetContent {
};

private normalizeValue(value: unknown): unknown {
if (value instanceof Guid || value instanceof DateOnly || value instanceof TimeOnly) {
if (value instanceof DateOnly || value instanceof TimeOnly) {
return value.toString();
}
if (value instanceof Date) {
Expand All @@ -268,7 +267,7 @@ export class RequestInformation implements RequestInformationSetContent {
}
}
if (typeof v === "boolean" || typeof v === "number" || typeof v === "string" || Array.isArray(v)) this.queryParameters[key] = v;
else if (v instanceof Guid || v instanceof DateOnly || v instanceof TimeOnly) this.queryParameters[key] = v.toString();
else if (v instanceof DateOnly || v instanceof TimeOnly) this.queryParameters[key] = v.toString();
else if (v instanceof Date) this.queryParameters[key] = v.toISOString();
else if (v === undefined) this.queryParameters[key] = undefined;
});
Expand Down
2 changes: 1 addition & 1 deletion packages/abstractions/src/serialization/parseNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
import type { Guid } from "guid-typescript";
import type { Guid } from "../utils/guidUtils";

import type { DateOnly } from "../dateOnly";
import type { Duration } from "../duration";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
import type { Guid } from "guid-typescript";
import type { Guid } from "../utils/guidUtils";

import type { DateOnly } from "../dateOnly";
import type { Duration } from "../duration";
Expand Down
40 changes: 30 additions & 10 deletions packages/abstractions/src/utils/guidUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,37 @@
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
import { Guid } from "guid-typescript";
export type Guid = string;

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");

/**
* Checks if the string is a valid GUID.
* @param source the string to check.
* @returns unchanged string if it is a valid GUID; otherwise, undefined.
*/
export const parseGuidString = (source?: string) => {
if (source && guidValidator.test(source)) {
return source;
}
return undefined;
};

/**
* Generates a GUID.
* @returns a GUID.
*/
export const createGuid = () => [gen(2), gen(1), gen(1), gen(1), gen(3)].join("-");

/**
* Parses a string into a Guid object.
* @param source The source string.
* @returns The Guid object.
* Generates a part of a GUID.
* @param count the number of 2 byte chunks to generate.
* @returns a part of a GUID.
*/
export function parseGuidString(source?: string): Guid | undefined {
if (source && Guid.isGuid(source)) {
return Guid.parse(source);
} else {
return undefined;
export const gen = (count: number) => {
let out = "";
for (let i = 0; i < count; i++) {
out += (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}
}
return out;
};
1 change: 0 additions & 1 deletion packages/http/fetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"dependencies": {
"@microsoft/kiota-abstractions": "^1.0.0-preview.73",
"@opentelemetry/api": "^1.7.0",
"guid-typescript": "^1.0.9",
"tslib": "^2.6.2"
},
"publishConfig": {
Expand Down
23 changes: 21 additions & 2 deletions packages/http/fetch/test/common/mockParseNodeFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,78 +6,97 @@
*/

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

export class MockParseNodeFactory implements ParseNodeFactory {
parseNodeValue: ParseNode;

/**
*
*/
constructor(parseNodeValue: ParseNode) {
this.parseNodeValue = parseNodeValue;
}

getValidContentType(): string {
return "application/json";
}

getRootParseNode(contentType: string, content: ArrayBuffer): ParseNode {
return this.parseNodeValue;
}
}

export class MockParseNode implements ParseNode {
returnObjectValue: Parsable;

/**
*
*/
constructor(returnObjectValue: Parsable) {
this.returnObjectValue = returnObjectValue;
}

getByteArrayValue(): ArrayBuffer | undefined {
throw new Error("Method not implemented.");
}

getStringValue(): string {
throw new Error("Method not implemented.");
}

getChildNode(identifier: string): ParseNode {
throw new Error("Method not implemented.");
}

getBooleanValue(): boolean {
throw new Error("Method not implemented.");
}

getNumberValue(): number {
throw new Error("Method not implemented.");
}

getGuidValue(): Guid {
throw new Error("Method not implemented.");
}

getDateValue(): Date {
throw new Error("Method not implemented.");
}

getDurationValue(): Duration | undefined {
throw new Error("Method not implemented.");
}

getDateOnlyValue(): DateOnly | undefined {
throw new Error("Method not implemented.");
}

getTimeOnlyValue(): TimeOnly | undefined {
throw new Error("Method not implemented.");
}

getCollectionOfPrimitiveValues<T>(): T[] | undefined {
throw new Error("Method not implemented.");
}

getCollectionOfObjectValues<T extends Parsable>(type: ParsableFactory<T>): T[] | undefined {
throw new Error("Method not implemented.");
}

getObjectValue<T extends Parsable>(type: ParsableFactory<T>): T {
return this.returnObjectValue as unknown as T;
}

getCollectionOfEnumValues<T>(type: any): T[] {
throw new Error("Method not implemented.");
}

getEnumValue<T>(type: any): T | undefined {
throw new Error("Method not implemented.");
}

onBeforeAssignFieldValues: ((value: Parsable) => void) | undefined;
onAfterAssignFieldValues: ((value: Parsable) => void) | undefined;
}
1 change: 0 additions & 1 deletion packages/serialization/form/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"homepage": "https://github.com/microsoft/kiota-typescript#readme",
"dependencies": {
"@microsoft/kiota-abstractions": "^1.0.0-preview.73",
"guid-typescript": "^1.0.9",
"tslib": "^2.6.2"
},
"publishConfig": {
Expand Down
10 changes: 3 additions & 7 deletions packages/serialization/form/src/formSerializationWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
*/

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

export class FormSerializationWriter implements SerializationWriter {
public writeByteArrayValue(
Expand All @@ -18,6 +17,7 @@ export class FormSerializationWriter implements SerializationWriter {
): void {
throw new Error("serialization of byt arrays is not supported with URI encoding");
}

private readonly writer: string[] = [];
private static readonly propertySeparator = `&`;
private depth = -1;
Expand Down Expand Up @@ -89,11 +89,7 @@ export class FormSerializationWriter implements SerializationWriter {
});
}
};
public writeCollectionOfObjectValues = <T extends Parsable>(
_key?: string,

_values?: T[] | null,
): void => {
public writeCollectionOfObjectValues = <T extends Parsable>(_key?: string, _values?: T[] | null): void => {
throw new Error(`serialization of collections is not supported with URI encoding`);
};
public writeObjectValue = <T extends Parsable>(key: string | undefined, value: T | null | undefined, serializerMethod: ModelSerializerFunction<T>): void => {
Expand Down
1 change: 0 additions & 1 deletion packages/serialization/json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"homepage": "https://github.com/microsoft/kiota-typescript#readme",
"dependencies": {
"@microsoft/kiota-abstractions": "^1.0.0-preview.73",
"guid-typescript": "^1.0.9",
"tslib": "^2.6.2"
},
"publishConfig": {
Expand Down
Loading