Skip to content

Commit 7ac131e

Browse files
committed
Please eslint
1 parent 4467d11 commit 7ac131e

File tree

8 files changed

+113
-89
lines changed

8 files changed

+113
-89
lines changed

cjs/src/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,18 @@ function parseUrl(url) {
486486
host = host.slice(host.indexOf('://') + 3).split(/[?/]/)[0]
487487
host = decodeURIComponent(host.slice(host.indexOf('@') + 1))
488488

489+
const urlObj = new URL(url.replace(host, host.split(',')[0]))
490+
489491
return {
490-
url: new URL(url.replace(host, host.split(',')[0])),
492+
url: {
493+
username: decodeURIComponent(urlObj.username),
494+
password: decodeURIComponent(urlObj.password),
495+
host: urlObj.host,
496+
hostname: urlObj.hostname,
497+
port: urlObj.port,
498+
pathname: urlObj.pathname,
499+
searchParams: urlObj.searchParams
500+
},
491501
multihost: host.indexOf(',') > -1 && host
492502
}
493503
}

cjs/src/types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ const builders = Object.entries({
164164
update(first, rest, parameters, types, options) {
165165
return (rest.length ? rest.flat() : Object.keys(first)).map(x =>
166166
escapeIdentifier(options.transform.column.to ? options.transform.column.to(x) : x) +
167-
'=' + handleValue(first[x], parameters, types, options)
167+
'=' + stringifyValue('values', first[x], parameters, types, options)
168168
)
169169
},
170170

cjs/tests/index.js

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,11 @@ t('Connect using uri', async() =>
351351
})]
352352
)
353353

354+
t('Options from uri with special characters in user and pass', async() => {
355+
const opt = postgres({ user: 'öla', pass: 'pass^word' }).options
356+
return [[opt.user, opt.pass].toString(), 'öla,pass^word']
357+
})
358+
354359
t('Fail with proper error on no host', async() =>
355360
['ECONNREFUSED', (await new Promise((resolve, reject) => {
356361
const sql = postgres('postgres://localhost:33333/' + options.db, {
@@ -540,7 +545,7 @@ t('Connection end does not cancel query', async() => {
540545

541546
const promise = sql`select 1 as x`.execute()
542547

543-
sql.end()
548+
await sql.end()
544549

545550
return [1, (await promise)[0].x]
546551
})
@@ -616,39 +621,37 @@ t('Transform deeply nested json object in arrays', async() => {
616621
...options,
617622
transform: postgres.camel
618623
})
619-
return ['childObj_deeplyNestedObj_grandchildObj', (await sql`select '[{"nested_obj": {"child_obj": 2, "deeply_nested_obj": {"grandchild_obj": 3}}}]'::jsonb as x`)[0].x
620-
.map((x) => {
621-
let result;
622-
for (const key in x) {
623-
const result1 = Object.keys(x[key]);
624-
const result2 = Object.keys(x[key].deeplyNestedObj);
625-
626-
result = [...result1, ...result2];
627-
}
628-
629-
return result;
630-
})[0]
631-
.join('_')]
624+
return [
625+
'childObj_deeplyNestedObj_grandchildObj',
626+
(await sql`
627+
select '[{"nested_obj": {"child_obj": 2, "deeply_nested_obj": {"grandchild_obj": 3}}}]'::jsonb as x
628+
`)[0].x.map(x => {
629+
let result
630+
for (const key in x)
631+
result = [...Object.keys(x[key]), ...Object.keys(x[key].deeplyNestedObj)]
632+
return result
633+
})[0]
634+
.join('_')
635+
]
632636
})
633637

634638
t('Transform deeply nested json array in arrays', async() => {
635639
const sql = postgres({
636640
...options,
637641
transform: postgres.camel
638642
})
639-
return ['childArray_deeplyNestedArray_grandchildArray', (await sql`select '[{"nested_array": [{"child_array": 2, "deeply_nested_array": [{"grandchild_array":3}]}]}]'::jsonb AS x`)[0].x
640-
.map((x) => {
641-
let result;
642-
for (const key in x) {
643-
const result1 = Object.keys(x[key][0]);
644-
const result2 = Object.keys(x[key][0].deeplyNestedArray[0]);
645-
646-
result = [...result1, ...result2];
647-
}
648-
649-
return result;
650-
})[0]
651-
.join('_')]
643+
return [
644+
'childArray_deeplyNestedArray_grandchildArray',
645+
(await sql`
646+
select '[{"nested_array": [{"child_array": 2, "deeply_nested_array": [{"grandchild_array":3}]}]}]'::jsonb AS x
647+
`)[0].x.map((x) => {
648+
let result
649+
for (const key in x)
650+
result = [...Object.keys(x[key][0]), ...Object.keys(x[key][0].deeplyNestedArray[0])]
651+
return result
652+
})[0]
653+
.join('_')
654+
]
652655
})
653656

654657
t('Bypass transform for json primitive', async() => {
@@ -1630,7 +1633,7 @@ t('connect_timeout error message includes host:port', { timeout: 20 }, async() =
16301633
err = e.message
16311634
})
16321635
server.close()
1633-
return [["write CONNECT_TIMEOUT 127.0.0.1:", port].join(""), err]
1636+
return [['write CONNECT_TIMEOUT 127.0.0.1:', port].join(''), err]
16341637
})
16351638

16361639
t('requests works after single connect_timeout', async() => {

deno/src/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,18 @@ function parseUrl(url) {
487487
host = host.slice(host.indexOf('://') + 3).split(/[?/]/)[0]
488488
host = decodeURIComponent(host.slice(host.indexOf('@') + 1))
489489

490+
const urlObj = new URL(url.replace(host, host.split(',')[0]))
491+
490492
return {
491-
url: new URL(url.replace(host, host.split(',')[0])),
493+
url: {
494+
username: decodeURIComponent(urlObj.username),
495+
password: decodeURIComponent(urlObj.password),
496+
host: urlObj.host,
497+
hostname: urlObj.hostname,
498+
port: urlObj.port,
499+
pathname: urlObj.pathname,
500+
searchParams: urlObj.searchParams
501+
},
492502
multihost: host.indexOf(',') > -1 && host
493503
}
494504
}

deno/src/types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ const builders = Object.entries({
165165
update(first, rest, parameters, types, options) {
166166
return (rest.length ? rest.flat() : Object.keys(first)).map(x =>
167167
escapeIdentifier(options.transform.column.to ? options.transform.column.to(x) : x) +
168-
'=' + handleValue(first[x], parameters, types, options)
168+
'=' + stringifyValue('values', first[x], parameters, types, options)
169169
)
170170
},
171171

deno/tests/index.js

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,11 @@ t('Connect using uri', async() =>
353353
})]
354354
)
355355

356+
t('Options from uri with special characters in user and pass', async() => {
357+
const opt = postgres({ user: 'öla', pass: 'pass^word' }).options
358+
return [[opt.user, opt.pass].toString(), 'öla,pass^word']
359+
})
360+
356361
t('Fail with proper error on no host', async() =>
357362
['ECONNREFUSED', (await new Promise((resolve, reject) => {
358363
const sql = postgres('postgres://localhost:33333/' + options.db, {
@@ -542,7 +547,7 @@ t('Connection end does not cancel query', async() => {
542547

543548
const promise = sql`select 1 as x`.execute()
544549

545-
sql.end()
550+
await sql.end()
546551

547552
return [1, (await promise)[0].x]
548553
})
@@ -618,39 +623,37 @@ t('Transform deeply nested json object in arrays', async() => {
618623
...options,
619624
transform: postgres.camel
620625
})
621-
return ['childObj_deeplyNestedObj_grandchildObj', (await sql`select '[{"nested_obj": {"child_obj": 2, "deeply_nested_obj": {"grandchild_obj": 3}}}]'::jsonb as x`)[0].x
622-
.map((x) => {
623-
let result;
624-
for (const key in x) {
625-
const result1 = Object.keys(x[key]);
626-
const result2 = Object.keys(x[key].deeplyNestedObj);
627-
628-
result = [...result1, ...result2];
629-
}
630-
631-
return result;
632-
})[0]
633-
.join('_')]
626+
return [
627+
'childObj_deeplyNestedObj_grandchildObj',
628+
(await sql`
629+
select '[{"nested_obj": {"child_obj": 2, "deeply_nested_obj": {"grandchild_obj": 3}}}]'::jsonb as x
630+
`)[0].x.map(x => {
631+
let result
632+
for (const key in x)
633+
result = [...Object.keys(x[key]), ...Object.keys(x[key].deeplyNestedObj)]
634+
return result
635+
})[0]
636+
.join('_')
637+
]
634638
})
635639

636640
t('Transform deeply nested json array in arrays', async() => {
637641
const sql = postgres({
638642
...options,
639643
transform: postgres.camel
640644
})
641-
return ['childArray_deeplyNestedArray_grandchildArray', (await sql`select '[{"nested_array": [{"child_array": 2, "deeply_nested_array": [{"grandchild_array":3}]}]}]'::jsonb AS x`)[0].x
642-
.map((x) => {
643-
let result;
644-
for (const key in x) {
645-
const result1 = Object.keys(x[key][0]);
646-
const result2 = Object.keys(x[key][0].deeplyNestedArray[0]);
647-
648-
result = [...result1, ...result2];
649-
}
650-
651-
return result;
652-
})[0]
653-
.join('_')]
645+
return [
646+
'childArray_deeplyNestedArray_grandchildArray',
647+
(await sql`
648+
select '[{"nested_array": [{"child_array": 2, "deeply_nested_array": [{"grandchild_array":3}]}]}]'::jsonb AS x
649+
`)[0].x.map((x) => {
650+
let result
651+
for (const key in x)
652+
result = [...Object.keys(x[key][0]), ...Object.keys(x[key][0].deeplyNestedArray[0])]
653+
return result
654+
})[0]
655+
.join('_')
656+
]
654657
})
655658

656659
t('Bypass transform for json primitive', async() => {
@@ -1632,7 +1635,7 @@ t('connect_timeout error message includes host:port', { timeout: 20 }, async() =
16321635
err = e.message
16331636
})
16341637
server.close()
1635-
return [["write CONNECT_TIMEOUT 127.0.0.1:", port].join(""), err]
1638+
return [['write CONNECT_TIMEOUT 127.0.0.1:', port].join(''), err]
16361639
})
16371640

16381641
t('requests works after single connect_timeout', async() => {

src/types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ const builders = Object.entries({
164164
update(first, rest, parameters, types, options) {
165165
return (rest.length ? rest.flat() : Object.keys(first)).map(x =>
166166
escapeIdentifier(options.transform.column.to ? options.transform.column.to(x) : x) +
167-
'=' + handleValue(first[x], parameters, types, options)
167+
'=' + stringifyValue('values', first[x], parameters, types, options)
168168
)
169169
},
170170

tests/index.js

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ t('Connection end does not cancel query', async() => {
545545

546546
const promise = sql`select 1 as x`.execute()
547547

548-
sql.end()
548+
await sql.end()
549549

550550
return [1, (await promise)[0].x]
551551
})
@@ -621,39 +621,37 @@ t('Transform deeply nested json object in arrays', async() => {
621621
...options,
622622
transform: postgres.camel
623623
})
624-
return ['childObj_deeplyNestedObj_grandchildObj', (await sql`select '[{"nested_obj": {"child_obj": 2, "deeply_nested_obj": {"grandchild_obj": 3}}}]'::jsonb as x`)[0].x
625-
.map((x) => {
626-
let result;
627-
for (const key in x) {
628-
const result1 = Object.keys(x[key]);
629-
const result2 = Object.keys(x[key].deeplyNestedObj);
630-
631-
result = [...result1, ...result2];
632-
}
633-
634-
return result;
635-
})[0]
636-
.join('_')]
624+
return [
625+
'childObj_deeplyNestedObj_grandchildObj',
626+
(await sql`
627+
select '[{"nested_obj": {"child_obj": 2, "deeply_nested_obj": {"grandchild_obj": 3}}}]'::jsonb as x
628+
`)[0].x.map(x => {
629+
let result
630+
for (const key in x)
631+
result = [...Object.keys(x[key]), ...Object.keys(x[key].deeplyNestedObj)]
632+
return result
633+
})[0]
634+
.join('_')
635+
]
637636
})
638637

639638
t('Transform deeply nested json array in arrays', async() => {
640639
const sql = postgres({
641640
...options,
642641
transform: postgres.camel
643642
})
644-
return ['childArray_deeplyNestedArray_grandchildArray', (await sql`select '[{"nested_array": [{"child_array": 2, "deeply_nested_array": [{"grandchild_array":3}]}]}]'::jsonb AS x`)[0].x
645-
.map((x) => {
646-
let result;
647-
for (const key in x) {
648-
const result1 = Object.keys(x[key][0]);
649-
const result2 = Object.keys(x[key][0].deeplyNestedArray[0]);
650-
651-
result = [...result1, ...result2];
652-
}
653-
654-
return result;
655-
})[0]
656-
.join('_')]
643+
return [
644+
'childArray_deeplyNestedArray_grandchildArray',
645+
(await sql`
646+
select '[{"nested_array": [{"child_array": 2, "deeply_nested_array": [{"grandchild_array":3}]}]}]'::jsonb AS x
647+
`)[0].x.map((x) => {
648+
let result
649+
for (const key in x)
650+
result = [...Object.keys(x[key][0]), ...Object.keys(x[key][0].deeplyNestedArray[0])]
651+
return result
652+
})[0]
653+
.join('_')
654+
]
657655
})
658656

659657
t('Bypass transform for json primitive', async() => {
@@ -1635,7 +1633,7 @@ t('connect_timeout error message includes host:port', { timeout: 20 }, async() =
16351633
err = e.message
16361634
})
16371635
server.close()
1638-
return [["write CONNECT_TIMEOUT 127.0.0.1:", port].join(""), err]
1636+
return [['write CONNECT_TIMEOUT 127.0.0.1:', port].join(''), err]
16391637
})
16401638

16411639
t('requests works after single connect_timeout', async() => {

0 commit comments

Comments
 (0)