From 5c511af50798201516b1f00af15217afff4640c9 Mon Sep 17 00:00:00 2001 From: Musale Martin Date: Mon, 18 Nov 2024 13:50:05 +0300 Subject: [PATCH 1/5] Update std-uritemplate to v2.0.0 --- package-lock.json | 9 +++++---- packages/abstractions/package.json | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index bd5e13a40..12b81ca39 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3528,9 +3528,10 @@ "dev": true }, "node_modules/@std-uritemplate/std-uritemplate": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/@std-uritemplate/std-uritemplate/-/std-uritemplate-1.0.6.tgz", - "integrity": "sha512-+S9kAqK60nZZyvhvesoXut6NB9qB80VTpNsdiOeHmE0FAMOEsJy9/dakDL3xMp3kNRFvviw0mX9WPSuasvSxCQ==" + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@std-uritemplate/std-uritemplate/-/std-uritemplate-2.0.1.tgz", + "integrity": "sha512-HC5kiXCa7Mxrv7SI7qH4ECfC1H+vFG15COBtX8aUur8EGEWK17RH3QVyBxtyjUXE448O4fGhQHh3kirEvPGWjw==", + "license": "Apache-2.0" }, "node_modules/@swc/helpers": { "version": "0.5.13", @@ -16413,7 +16414,7 @@ "license": "MIT", "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" diff --git a/packages/abstractions/package.json b/packages/abstractions/package.json index fc68547e1..7d32b96d9 100644 --- a/packages/abstractions/package.json +++ b/packages/abstractions/package.json @@ -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" @@ -46,4 +46,4 @@ "browserslist": [ "defaults" ] -} +} \ No newline at end of file From 108e2bb23659f749b64bcdce71076af632cead90 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Wed, 18 Dec 2024 12:27:26 -0500 Subject: [PATCH 2/5] draft: implements missing types Signed-off-by: Vincent Biret --- packages/abstractions/src/requestInformation.ts | 2 +- .../abstractions/test/common/requestInformation.ts | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/abstractions/src/requestInformation.ts b/packages/abstractions/src/requestInformation.ts index c711966f6..2b8386935 100644 --- a/packages/abstractions/src/requestInformation.ts +++ b/packages/abstractions/src/requestInformation.ts @@ -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) { diff --git a/packages/abstractions/test/common/requestInformation.ts b/packages/abstractions/test/common/requestInformation.ts index 9ae3dbfba..2776dd463 100644 --- a/packages/abstractions/test/common/requestInformation.ts +++ b/packages/abstractions/test/common/requestInformation.ts @@ -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"; @@ -25,6 +25,8 @@ interface GetQueryParameters { endTime?: TimeOnly; endDate?: DateOnly; timeStamp?: Date; + time?: TimeOnly; + duration?: Duration; } const getQueryParameterMapper: Record = { @@ -221,13 +223,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&time=23:12:00.0000000`; 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({ 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({ 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"), time: TimeOnly.parse("23:12:00.0000000") }, getQueryParameterMapper); assert.equal(requestInformation.URL, expected); }); From d18bb7f9bd84c06f3f7ed66b6cd5e730125f5f69 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Wed, 18 Dec 2024 12:28:53 -0500 Subject: [PATCH 3/5] chore: removes redundant time test Signed-off-by: Vincent Biret --- packages/abstractions/test/common/requestInformation.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/abstractions/test/common/requestInformation.ts b/packages/abstractions/test/common/requestInformation.ts index 2776dd463..e6ab2e53e 100644 --- a/packages/abstractions/test/common/requestInformation.ts +++ b/packages/abstractions/test/common/requestInformation.ts @@ -223,13 +223,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&duration=P1D&time=23:12:00.0000000`; + 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,duration}"; - requestInformation.setQueryStringParametersFromRawObject({ 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"), time: TimeOnly.parse("23:12:00.0000000") }, getQueryParameterMapper); + requestInformation.setQueryStringParametersFromRawObject({ 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); }); From 6aa295dc5acfdb496750557f57c9a17af5f4fec2 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Wed, 18 Dec 2024 12:29:53 -0500 Subject: [PATCH 4/5] chore: linting Signed-off-by: Vincent Biret --- packages/abstractions/test/common/requestInformation.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/abstractions/test/common/requestInformation.ts b/packages/abstractions/test/common/requestInformation.ts index e6ab2e53e..1388acc2e 100644 --- a/packages/abstractions/test/common/requestInformation.ts +++ b/packages/abstractions/test/common/requestInformation.ts @@ -25,8 +25,7 @@ interface GetQueryParameters { endTime?: TimeOnly; endDate?: DateOnly; timeStamp?: Date; - time?: TimeOnly; - duration?: Duration; + duration?: Duration; } const getQueryParameterMapper: Record = { From d78a9cb8602b07e96e430350ab4e84ec40681fe3 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Thu, 19 Dec 2024 13:50:11 -0500 Subject: [PATCH 5/5] fix: missing duration normalization Signed-off-by: Vincent Biret --- packages/abstractions/src/requestInformation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/abstractions/src/requestInformation.ts b/packages/abstractions/src/requestInformation.ts index 2b8386935..d8cb1e87a 100644 --- a/packages/abstractions/src/requestInformation.ts +++ b/packages/abstractions/src/requestInformation.ts @@ -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; });