Skip to content

Commit

Permalink
Merge pull request #1489 from microsoft/feat/drop-nativedate
Browse files Browse the repository at this point in the history
fix: update std-uritemplate to v2.0.0
  • Loading branch information
baywet authored Dec 19, 2024
2 parents 476e4ec + d78a9cb commit cf12831
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
9 changes: 5 additions & 4 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions packages/abstractions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"dependencies": {
"@opentelemetry/api": "^1.7.0",
"@std-uritemplate/std-uritemplate": "^1.0.1",
"@std-uritemplate/std-uritemplate": "^2.0.0",
"tinyduration": "^3.3.0",
"tslib": "^2.6.2",
"uuid": "^11.0.2"
Expand All @@ -46,4 +46,4 @@
"browserslist": [
"defaults"
]
}
}
4 changes: 2 additions & 2 deletions packages/abstractions/src/requestInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export class RequestInformation implements RequestInformationSetContent {
};

private normalizeValue(value: unknown): unknown {
if (value instanceof DateOnly || value instanceof TimeOnly) {
if (value instanceof DateOnly || value instanceof TimeOnly || value instanceof Duration) {
return value.toString();
}
if (value instanceof Date) {
Expand All @@ -267,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 DateOnly || v instanceof TimeOnly) this.queryParameters[key] = v.toString();
else if (v instanceof DateOnly || v instanceof TimeOnly || v instanceof Duration) 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
9 changes: 5 additions & 4 deletions packages/abstractions/test/common/requestInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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

import { DateOnly, HttpMethod, type Guid, type Parsable, parseGuidString, type RequestAdapter, RequestInformation, type SerializationWriter, type SerializationWriterFactory, TimeOnly } from "../../src";
import { DateOnly, HttpMethod, type Guid, type Parsable, parseGuidString, type RequestAdapter, RequestInformation, type SerializationWriter, type SerializationWriterFactory, TimeOnly, Duration } from "../../src";
import { MultipartBody } from "../../src/multipartBody";
import { TestEnum } from "./store/testEnum";

Expand All @@ -25,6 +25,7 @@ interface GetQueryParameters {
endTime?: TimeOnly;
endDate?: DateOnly;
timeStamp?: Date;
duration?: Duration;
}

const getQueryParameterMapper: Record<string, string> = {
Expand Down Expand Up @@ -221,13 +222,13 @@ describe("RequestInformation", () => {
});

it("should correctly handle custom type in query/path parameter", () => {
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`;
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&duration=P1D`;
const requestInformation = new RequestInformation(HttpMethod.GET);
requestInformation.pathParameters["baseurl"] = baseUrl;
requestInformation.pathParameters["userId"] = parseGuidString("33933a8d-32bb-c6a8-784a-f60b5a1dd66a");
requestInformation.pathParameters["date"] = DateOnly.parse("2021-12-12");
requestInformation.urlTemplate = "http://localhost/users/{userId}/{date}{?objectId,startDate,startTime,endDate,endTime,timeStamp}";
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);
requestInformation.urlTemplate = "http://localhost/users/{userId}/{date}{?objectId,startDate,startTime,endDate,endTime,timeStamp,duration}";
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"), duration: Duration.parse("P1D") }, getQueryParameterMapper);
assert.equal(requestInformation.URL, expected);
});

Expand Down

0 comments on commit cf12831

Please sign in to comment.