Skip to content

Commit aed9954

Browse files
authored
pkg/clientgen: properly encode times in query strings (#1854)
1 parent 03d94b8 commit aed9954

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

pkg/clientgen/testdata/tsapp/expected_list_of_union_shared.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ export namespace svc {
8888

8989
type PickMethods<Type> = Omit<CallParameters, "method"> & {method?: Type}
9090

91-
type RequestType<Type extends (...args: any[]) => any> =
91+
type RequestType<Type extends (...args: any[]) => any> =
9292
Parameters<Type> extends [infer H, ...any[]] ? H : void;
9393

9494
type ResponseType<Type extends (...args: any[]) => any> = Awaited<ReturnType<Type>>;
9595

9696
function dateReviver(key: string, value: any): any {
9797
if (
98-
typeof value === "string" &&
99-
value.length >= 10 &&
98+
typeof value === "string" &&
99+
value.length >= 10 &&
100100
value.charCodeAt(0) >= 48 && // '0'
101101
value.charCodeAt(0) <= 57 // '9'
102102
) {

pkg/clientgen/testdata/tsapp/expected_shared.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,15 @@ export namespace svc {
150150

151151
type PickMethods<Type> = Omit<CallParameters, "method"> & {method?: Type}
152152

153-
type RequestType<Type extends (...args: any[]) => any> =
153+
type RequestType<Type extends (...args: any[]) => any> =
154154
Parameters<Type> extends [infer H, ...any[]] ? H : void;
155155

156156
type ResponseType<Type extends (...args: any[]) => any> = Awaited<ReturnType<Type>>;
157157

158158
function dateReviver(key: string, value: any): any {
159159
if (
160-
typeof value === "string" &&
161-
value.length >= 10 &&
160+
typeof value === "string" &&
161+
value.length >= 10 &&
162162
value.charCodeAt(0) >= 48 && // '0'
163163
value.charCodeAt(0) <= 57 // '9'
164164
) {

pkg/clientgen/testdata/tsapp/expected_stream_shared.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,15 @@ export namespace svc {
166166

167167
type PickMethods<Type> = Omit<CallParameters, "method"> & {method?: Type}
168168

169-
type RequestType<Type extends (...args: any[]) => any> =
169+
type RequestType<Type extends (...args: any[]) => any> =
170170
Parameters<Type> extends [infer H, ...any[]] ? H : void;
171171

172172
type ResponseType<Type extends (...args: any[]) => any> = Awaited<ReturnType<Type>>;
173173

174174
function dateReviver(key: string, value: any): any {
175175
if (
176-
typeof value === "string" &&
177-
value.length >= 10 &&
176+
typeof value === "string" &&
177+
value.length >= 10 &&
178178
value.charCodeAt(0) >= 48 && // '0'
179179
value.charCodeAt(0) <= 57 // '9'
180180
) {

pkg/clientgen/typescript.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,15 +1478,15 @@ export type JSONValue = string | number | boolean | null | JSONValue[] | {[key:
14781478
ts.WriteString(`
14791479
type PickMethods<Type> = Omit<CallParameters, "method"> & {method?: Type}
14801480
1481-
type RequestType<Type extends (...args: any[]) => any> =
1481+
type RequestType<Type extends (...args: any[]) => any> =
14821482
Parameters<Type> extends [infer H, ...any[]] ? H : void;
14831483
14841484
type ResponseType<Type extends (...args: any[]) => any> = Awaited<ReturnType<Type>>;
14851485
14861486
function dateReviver(key: string, value: any): any {
14871487
if (
1488-
typeof value === "string" &&
1489-
value.length >= 10 &&
1488+
typeof value === "string" &&
1489+
value.length >= 10 &&
14901490
value.charCodeAt(0) >= 48 && // '0'
14911491
value.charCodeAt(0) <= 57 // '9'
14921492
) {
@@ -1589,6 +1589,14 @@ func (ts *typescript) convertBuiltinToString(typ schema.Builtin, val string, isO
15891589
return val
15901590
case schema.Builtin_JSON:
15911591
code = fmt.Sprintf("JSON.stringify(%s)", val)
1592+
case schema.Builtin_TIME:
1593+
if ts.sharedTypes {
1594+
// If we're using shared types then this will actually be a Date object.
1595+
// Otherwise it will be a string.
1596+
code = fmt.Sprintf("%s.toISOString()", val)
1597+
} else {
1598+
code = fmt.Sprintf("String(%s)", val)
1599+
}
15921600
default:
15931601
code = fmt.Sprintf("String(%s)", val)
15941602
}

0 commit comments

Comments
 (0)