Skip to content

Commit cf12831

Browse files
authored
Merge pull request #1489 from microsoft/feat/drop-nativedate
fix: update std-uritemplate to v2.0.0
2 parents 476e4ec + d78a9cb commit cf12831

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

package-lock.json

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

packages/abstractions/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
},
3636
"dependencies": {
3737
"@opentelemetry/api": "^1.7.0",
38-
"@std-uritemplate/std-uritemplate": "^1.0.1",
38+
"@std-uritemplate/std-uritemplate": "^2.0.0",
3939
"tinyduration": "^3.3.0",
4040
"tslib": "^2.6.2",
4141
"uuid": "^11.0.2"
@@ -46,4 +46,4 @@
4646
"browserslist": [
4747
"defaults"
4848
]
49-
}
49+
}

packages/abstractions/src/requestInformation.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ export class RequestInformation implements RequestInformationSetContent {
240240
};
241241

242242
private normalizeValue(value: unknown): unknown {
243-
if (value instanceof DateOnly || value instanceof TimeOnly) {
243+
if (value instanceof DateOnly || value instanceof TimeOnly || value instanceof Duration) {
244244
return value.toString();
245245
}
246246
if (value instanceof Date) {
@@ -267,7 +267,7 @@ export class RequestInformation implements RequestInformationSetContent {
267267
}
268268
}
269269
if (typeof v === "boolean" || typeof v === "number" || typeof v === "string" || Array.isArray(v)) this.queryParameters[key] = v;
270-
else if (v instanceof DateOnly || v instanceof TimeOnly) this.queryParameters[key] = v.toString();
270+
else if (v instanceof DateOnly || v instanceof TimeOnly || v instanceof Duration) this.queryParameters[key] = v.toString();
271271
else if (v instanceof Date) this.queryParameters[key] = v.toISOString();
272272
else if (v === undefined) this.queryParameters[key] = undefined;
273273
});

packages/abstractions/test/common/requestInformation.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

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

10-
import { DateOnly, HttpMethod, type Guid, 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, Duration } from "../../src";
1111
import { MultipartBody } from "../../src/multipartBody";
1212
import { TestEnum } from "./store/testEnum";
1313

@@ -25,6 +25,7 @@ interface GetQueryParameters {
2525
endTime?: TimeOnly;
2626
endDate?: DateOnly;
2727
timeStamp?: Date;
28+
duration?: Duration;
2829
}
2930

3031
const getQueryParameterMapper: Record<string, string> = {
@@ -221,13 +222,13 @@ describe("RequestInformation", () => {
221222
});
222223

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

0 commit comments

Comments
 (0)