Skip to content

Commit 5b368b0

Browse files
committed
Please eslint
1 parent 5fefec9 commit 5b368b0

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
@@ -352,6 +352,11 @@ t('Connect using uri', async() =>
352352
})]
353353
)
354354

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

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

544-
sql.end()
549+
await sql.end()
545550

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

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

655658
t('Bypass transform for json primitive', async() => {
@@ -1628,7 +1631,7 @@ t('connect_timeout error message includes host:port', { timeout: 20 }, async() =
16281631
err = e.message
16291632
})
16301633
server.close()
1631-
return [["write CONNECT_TIMEOUT 127.0.0.1:", port].join(""), err]
1634+
return [['write CONNECT_TIMEOUT 127.0.0.1:', port].join(''), err]
16321635
})
16331636

16341637
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
@@ -354,6 +354,11 @@ t('Connect using uri', async() =>
354354
})]
355355
)
356356

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

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

546-
sql.end()
551+
await sql.end()
547552

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

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

657660
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() => {

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
@@ -546,7 +546,7 @@ t('Connection end does not cancel query', async() => {
546546

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

549-
sql.end()
549+
await sql.end()
550550

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

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

660658
t('Bypass transform for json primitive', async() => {
@@ -1633,7 +1631,7 @@ t('connect_timeout error message includes host:port', { timeout: 20 }, async() =
16331631
err = e.message
16341632
})
16351633
server.close()
1636-
return [["write CONNECT_TIMEOUT 127.0.0.1:", port].join(""), err]
1634+
return [['write CONNECT_TIMEOUT 127.0.0.1:', port].join(''), err]
16371635
})
16381636

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

0 commit comments

Comments
 (0)