Skip to content

Commit 51e34b2

Browse files
authored
deps(std): bump dependencies and prefer their lighter submodules (#422)
* deps: bump to latest `std` * fix(deps): use `BufReader` and `BufWriter` modules * deps: use `bytes/copy` module directly * deps: prefer `crypto/crypto` module * deps: prefer submodules of `async` module * deps: bump test dependencies * deps: prefer submodules of `datetime` * deps!: upgrade to `[email protected]` * fix: remove use of deprecated `hex.encode` function * deps!: update test dependencies * fix(test): update test imports --------- Co-authored-by: Basti Ortiz <[email protected]>
1 parent 427b77d commit 51e34b2

File tree

8 files changed

+47
-56
lines changed

8 files changed

+47
-56
lines changed

connection/auth.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import { crypto, hex } from "../deps.ts";
22

33
const encoder = new TextEncoder();
4-
const decoder = new TextDecoder();
54

65
async function md5(bytes: Uint8Array): Promise<string> {
7-
return decoder.decode(
8-
hex.encode(new Uint8Array(await crypto.subtle.digest("MD5", bytes))),
9-
);
6+
return hex.encodeHex(await crypto.subtle.digest("MD5", bytes));
107
}
118

129
// AuthenticationMD5Password

connection/scram.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function escape(str: string): string {
134134
}
135135

136136
function generateRandomNonce(size: number): string {
137-
return base64.encode(crypto.getRandomValues(new Uint8Array(size)));
137+
return base64.encodeBase64(crypto.getRandomValues(new Uint8Array(size)));
138138
}
139139

140140
function parseScramAttributes(message: string): Record<string, string> {
@@ -223,7 +223,7 @@ export class Client {
223223
throw new Error(Reason.BadSalt);
224224
}
225225
try {
226-
salt = base64.decode(attrs.s);
226+
salt = base64.decodeBase64(attrs.s);
227227
} catch {
228228
throw new Error(Reason.BadSalt);
229229
}
@@ -261,7 +261,7 @@ export class Client {
261261

262262
this.#auth_message += "," + responseWithoutProof;
263263

264-
const proof = base64.encode(
264+
const proof = base64.encodeBase64(
265265
computeScramProof(
266266
await computeScramSignature(
267267
this.#auth_message,
@@ -294,7 +294,7 @@ export class Client {
294294
throw new Error(attrs.e ?? Reason.Rejected);
295295
}
296296

297-
const verifier = base64.encode(
297+
const verifier = base64.encodeBase64(
298298
await computeScramSignature(
299299
this.#auth_message,
300300
this.#key_signatures.server,

deps.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
export * as base64 from "https://deno.land/[email protected]/encoding/base64.ts";
2-
export * as hex from "https://deno.land/[email protected]/encoding/hex.ts";
3-
export * as date from "https://deno.land/[email protected]/datetime/mod.ts";
4-
export {
5-
BufReader,
6-
BufWriter,
7-
} from "https://deno.land/[email protected]/io/buffer.ts";
8-
export { copy } from "https://deno.land/[email protected]/bytes/mod.ts";
9-
export { crypto } from "https://deno.land/[email protected]/crypto/mod.ts";
10-
export {
11-
type Deferred,
12-
deferred,
13-
delay,
14-
} from "https://deno.land/[email protected]/async/mod.ts";
15-
export { bold, yellow } from "https://deno.land/[email protected]/fmt/colors.ts";
1+
export * as base64 from "https://deno.land/[email protected]/encoding/base64.ts";
2+
export * as hex from "https://deno.land/[email protected]/encoding/hex.ts";
3+
export { parse as parseDate } from "https://deno.land/[email protected]/datetime/parse.ts";
4+
export { BufReader } from "https://deno.land/[email protected]/io/buf_reader.ts";
5+
export { BufWriter } from "https://deno.land/[email protected]/io/buf_writer.ts";
6+
export { copy } from "https://deno.land/[email protected]/bytes/copy.ts";
7+
export { crypto } from "https://deno.land/[email protected]/crypto/crypto.ts";
8+
export { delay } from "https://deno.land/[email protected]/async/delay.ts";
9+
export { bold, yellow } from "https://deno.land/[email protected]/fmt/colors.ts";
1610
export {
1711
fromFileUrl,
1812
isAbsolute,
1913
join as joinPath,
20-
} from "https://deno.land/std@0.160.0/path/mod.ts";
14+
} from "https://deno.land/std@0.214.0/path/mod.ts";

query/decoders.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { date } from "../deps.ts";
1+
import { parseDate } from "../deps.ts";
22
import { parseArray } from "./array_parser.ts";
33
import type {
44
Box,
@@ -127,7 +127,7 @@ export function decodeDate(dateStr: string): Date | number {
127127
return Number(-Infinity);
128128
}
129129

130-
return date.parse(dateStr, "yyyy-MM-dd");
130+
return parseDate(dateStr, "yyyy-MM-dd");
131131
}
132132

133133
export function decodeDateArray(value: string) {

tests/connection_test.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import {
22
assertEquals,
33
assertRejects,
4-
deferred,
4+
copyStream,
55
joinPath,
6-
streams,
76
} from "./test_deps.ts";
87
import {
98
getClearConfiguration,
@@ -38,8 +37,8 @@ function createProxy(
3837
aborted = true;
3938
});
4039
await Promise.all([
41-
streams.copy(conn, outbound),
42-
streams.copy(outbound, conn),
40+
copyStream(conn, outbound),
41+
copyStream(outbound, conn),
4342
]).catch(() => {});
4443

4544
if (!aborted) {
@@ -374,15 +373,15 @@ Deno.test("Closes connection on bad TLS availability verification", async functi
374373
);
375374

376375
// Await for server initialization
377-
const initialized = deferred();
376+
const initialized = Promise.withResolvers();
378377
server.onmessage = ({ data }) => {
379378
if (data !== "initialized") {
380379
initialized.reject(`Unexpected message "${data}" received from worker`);
381380
}
382-
initialized.resolve();
381+
initialized.resolve(null);
383382
};
384383
server.postMessage("initialize");
385-
await initialized;
384+
await initialized.promise;
386385

387386
const client = new Client({
388387
database: "none",
@@ -413,17 +412,17 @@ Deno.test("Closes connection on bad TLS availability verification", async functi
413412
await client.end();
414413
}
415414

416-
const closed = deferred();
415+
const closed = Promise.withResolvers();
417416
server.onmessage = ({ data }) => {
418417
if (data !== "closed") {
419418
closed.reject(
420419
`Unexpected message "${data}" received from worker`,
421420
);
422421
}
423-
closed.resolve();
422+
closed.resolve(null);
424423
};
425424
server.postMessage("close");
426-
await closed;
425+
await closed.promise;
427426
server.terminate();
428427

429428
assertEquals(bad_tls_availability_message, true);
@@ -438,15 +437,15 @@ async function mockReconnection(attempts: number) {
438437
);
439438

440439
// Await for server initialization
441-
const initialized = deferred();
440+
const initialized = Promise.withResolvers();
442441
server.onmessage = ({ data }) => {
443442
if (data !== "initialized") {
444443
initialized.reject(`Unexpected message "${data}" received from worker`);
445444
}
446-
initialized.resolve();
445+
initialized.resolve(null);
447446
};
448447
server.postMessage("initialize");
449-
await initialized;
448+
await initialized.promise;
450449

451450
const client = new Client({
452451
connection: {
@@ -483,17 +482,17 @@ async function mockReconnection(attempts: number) {
483482
await client.end();
484483
}
485484

486-
const closed = deferred();
485+
const closed = Promise.withResolvers();
487486
server.onmessage = ({ data }) => {
488487
if (data !== "closed") {
489488
closed.reject(
490489
`Unexpected message "${data}" received from worker`,
491490
);
492491
}
493-
closed.resolve();
492+
closed.resolve(null);
494493
};
495494
server.postMessage("close");
496-
await closed;
495+
await closed.promise;
497496
server.terminate();
498497

499498
// If reconnections are set to zero, it will attempt to connect at least once, but won't

tests/data_types_test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assertEquals, base64, date } from "./test_deps.ts";
1+
import { assertEquals, base64, formatDate, parseDate } from "./test_deps.ts";
22
import { getMainConfiguration } from "./config.ts";
33
import { generateSimpleClientTest } from "./helpers.ts";
44
import type {
@@ -34,7 +34,7 @@ function generateRandomPoint(max_value = 100): Point {
3434

3535
const CHARS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
3636
function randomBase64(): string {
37-
return base64.encode(
37+
return base64.encodeBase64(
3838
Array.from(
3939
{ length: Math.ceil(Math.random() * 256) },
4040
() => CHARS[Math.floor(Math.random() * CHARS.length)],
@@ -671,7 +671,7 @@ Deno.test(
671671
`SELECT decode('${base64_string}','base64')`,
672672
);
673673

674-
assertEquals(result.rows[0][0], base64.decode(base64_string));
674+
assertEquals(result.rows[0][0], base64.decodeBase64(base64_string));
675675
}),
676676
);
677677

@@ -691,7 +691,7 @@ Deno.test(
691691

692692
assertEquals(
693693
result.rows[0][0],
694-
strings.map(base64.decode),
694+
strings.map(base64.decodeBase64),
695695
);
696696
}),
697697
);
@@ -931,7 +931,7 @@ Deno.test(
931931
);
932932

933933
assertEquals(result.rows[0], [
934-
date.parse(date_text, "yyyy-MM-dd"),
934+
parseDate(date_text, "yyyy-MM-dd"),
935935
Infinity,
936936
]);
937937
}),
@@ -941,7 +941,7 @@ Deno.test(
941941
"date array",
942942
testClient(async (client) => {
943943
await client.queryArray(`SET SESSION TIMEZONE TO '${timezone}'`);
944-
const dates = ["2020-01-01", date.format(new Date(), "yyyy-MM-dd")];
944+
const dates = ["2020-01-01", formatDate(new Date(), "yyyy-MM-dd")];
945945

946946
const { rows: result } = await client.queryArray<[[Date, Date]]>(
947947
"SELECT ARRAY[$1::DATE, $2]",
@@ -950,7 +950,7 @@ Deno.test(
950950

951951
assertEquals(
952952
result[0][0],
953-
dates.map((d) => date.parse(d, "yyyy-MM-dd")),
953+
dates.map((d) => parseDate(d, "yyyy-MM-dd")),
954954
);
955955
}),
956956
);

tests/test_deps.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ export {
66
assertObjectMatch,
77
assertRejects,
88
assertThrows,
9-
} from "https://deno.land/[email protected]/testing/asserts.ts";
10-
export * as streams from "https://deno.land/[email protected]/streams/conversion.ts";
9+
} from "https://deno.land/[email protected]/assert/mod.ts";
10+
export { format as formatDate } from "https://deno.land/[email protected]/datetime/format.ts";
11+
export { copy as copyStream } from "https://deno.land/[email protected]/io/copy.ts";

utils/deferred.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Deferred, deferred } from "../deps.ts";
1+
export type Deferred<T> = ReturnType<typeof Promise.withResolvers<T>>;
22

33
export class DeferredStack<T> {
44
#elements: Array<T>;
@@ -30,9 +30,9 @@ export class DeferredStack<T> {
3030
this.#size++;
3131
return await this.#creator();
3232
}
33-
const d = deferred<T>();
33+
const d = Promise.withResolvers<T>();
3434
this.#queue.push(d);
35-
return await d;
35+
return await d.promise;
3636
}
3737

3838
push(value: T): void {
@@ -112,9 +112,9 @@ export class DeferredAccessStack<T> {
112112
} else {
113113
// If there are not elements left in the stack, it will await the call until
114114
// at least one is restored and then return it
115-
const d = deferred<T>();
115+
const d = Promise.withResolvers<T>();
116116
this.#queue.push(d);
117-
element = await d;
117+
element = await d.promise;
118118
}
119119

120120
if (!await this.#checkElementInitialization(element)) {

0 commit comments

Comments
 (0)