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: update std-uritemplate to v2.0.0 #1489

Merged
merged 6 commits into from
Dec 19, 2024
Merged
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
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
Loading