mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
chore: remove deprecated APIs across collections
, streams
, textproto
and uuid
(#2720)
This commit is contained in:
parent
40d071763f
commit
bddda3c473
@ -4,11 +4,6 @@
|
||||
import { BinarySearchNode, Direction } from "./binary_search_node.ts";
|
||||
export type { Direction };
|
||||
|
||||
/**
|
||||
* @deprecated (will be removed after 0.157.0) use Direction instead
|
||||
*/
|
||||
export type { Direction as direction };
|
||||
|
||||
export class RedBlackNode<T> extends BinarySearchNode<T> {
|
||||
declare parent: RedBlackNode<T> | null;
|
||||
declare left: RedBlackNode<T> | null;
|
||||
|
@ -3,78 +3,6 @@
|
||||
|
||||
import { BytesList } from "../bytes/bytes_list.ts";
|
||||
|
||||
const CR = "\r".charCodeAt(0);
|
||||
const LF = "\n".charCodeAt(0);
|
||||
|
||||
/** @deprecated (will be removed after 0.157.0) Use TextLineStream instead, as it can handle empty lines.
|
||||
*
|
||||
* Transform a stream into a stream where each chunk is divided by a newline,
|
||||
* be it `\n` or `\r\n`.
|
||||
*
|
||||
* ```ts
|
||||
* import { LineStream } from "./delimiter.ts";
|
||||
* const res = await fetch("https://example.com");
|
||||
* const lines = res.body!.pipeThrough(new LineStream());
|
||||
* ```
|
||||
*/
|
||||
export class LineStream extends TransformStream<Uint8Array, Uint8Array> {
|
||||
#bufs = new BytesList();
|
||||
#prevHadCR = false;
|
||||
|
||||
constructor() {
|
||||
super({
|
||||
transform: (chunk, controller) => {
|
||||
this.#handle(chunk, controller);
|
||||
},
|
||||
flush: (controller) => {
|
||||
controller.enqueue(this.#mergeBufs(false));
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
#handle(
|
||||
chunk: Uint8Array,
|
||||
controller: TransformStreamDefaultController<Uint8Array>,
|
||||
) {
|
||||
const lfIndex = chunk.indexOf(LF);
|
||||
|
||||
if (this.#prevHadCR) {
|
||||
this.#prevHadCR = false;
|
||||
if (lfIndex === 0) {
|
||||
controller.enqueue(this.#mergeBufs(true));
|
||||
this.#handle(chunk.subarray(1), controller);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (lfIndex === -1) {
|
||||
if (chunk.at(-1) === CR) {
|
||||
this.#prevHadCR = true;
|
||||
}
|
||||
this.#bufs.add(chunk);
|
||||
} else {
|
||||
let crOrLfIndex = lfIndex;
|
||||
if (chunk[lfIndex - 1] === CR) {
|
||||
crOrLfIndex--;
|
||||
}
|
||||
this.#bufs.add(chunk.subarray(0, crOrLfIndex));
|
||||
controller.enqueue(this.#mergeBufs(false));
|
||||
this.#handle(chunk.subarray(lfIndex + 1), controller);
|
||||
}
|
||||
}
|
||||
|
||||
#mergeBufs(prevHadCR: boolean): Uint8Array {
|
||||
const mergeBuf = this.#bufs.concat();
|
||||
this.#bufs = new BytesList();
|
||||
|
||||
if (prevHadCR) {
|
||||
return mergeBuf.subarray(0, -1);
|
||||
} else {
|
||||
return mergeBuf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface TextLineStreamOptions {
|
||||
/** Allow splitting by solo \r */
|
||||
allowCR: boolean;
|
||||
|
@ -2,44 +2,11 @@
|
||||
|
||||
import {
|
||||
DelimiterStream,
|
||||
LineStream,
|
||||
TextDelimiterStream,
|
||||
TextLineStream,
|
||||
} from "./delimiter.ts";
|
||||
import { assert, assertEquals } from "../testing/asserts.ts";
|
||||
|
||||
Deno.test("[streams] LineStream", async () => {
|
||||
const textStream = new ReadableStream({
|
||||
start(controller) {
|
||||
controller.enqueue("qwertzu");
|
||||
controller.enqueue("iopasd\r\nmnbvc");
|
||||
controller.enqueue("xylk\njhgfds\napoiuzt");
|
||||
controller.enqueue("qwr09eiqwrjiowqr\r");
|
||||
controller.enqueue("\nrewq0987654321");
|
||||
controller.close();
|
||||
},
|
||||
});
|
||||
|
||||
const lines = textStream
|
||||
.pipeThrough(new TextEncoderStream())
|
||||
.pipeThrough(new LineStream())
|
||||
.pipeThrough(new TextDecoderStream());
|
||||
const reader = lines.getReader();
|
||||
|
||||
const a = await reader.read();
|
||||
assertEquals(a.value, "qwertzuiopasd");
|
||||
const b = await reader.read();
|
||||
assertEquals(b.value, "mnbvcxylk");
|
||||
const c = await reader.read();
|
||||
assertEquals(c.value, "jhgfds");
|
||||
const d = await reader.read();
|
||||
assertEquals(d.value, "apoiuztqwr09eiqwrjiowqr");
|
||||
const e = await reader.read();
|
||||
assertEquals(e.value, "rewq0987654321");
|
||||
const f = await reader.read();
|
||||
assert(f.done);
|
||||
});
|
||||
|
||||
Deno.test("[streams] TextLineStream", async () => {
|
||||
const textStream = new ReadableStream({
|
||||
start(controller) {
|
||||
|
@ -631,19 +631,11 @@ export function assertThrows<E extends Error = Error>(
|
||||
msgIncludes?: string,
|
||||
msg?: string,
|
||||
): E;
|
||||
/** @deprecated (will be removed after 0.157.0) Use assertThrows(fn, msg) instead, which now returns thrown
|
||||
* value and you can assert on it. */
|
||||
export function assertThrows(
|
||||
fn: () => unknown,
|
||||
errorCallback: (e: Error) => unknown,
|
||||
msg?: string,
|
||||
): Error;
|
||||
export function assertThrows<E extends Error = Error>(
|
||||
fn: () => unknown,
|
||||
errorClassOrCallbackOrMsg?:
|
||||
errorClassOrMsg?:
|
||||
// deno-lint-ignore no-explicit-any
|
||||
| (new (...args: any[]) => E)
|
||||
| ((e: Error) => unknown)
|
||||
| string,
|
||||
msgIncludesOrMsg?: string,
|
||||
msg?: string,
|
||||
@ -651,31 +643,29 @@ export function assertThrows<E extends Error = Error>(
|
||||
// deno-lint-ignore no-explicit-any
|
||||
let ErrorClass: (new (...args: any[]) => E) | undefined = undefined;
|
||||
let msgIncludes: string | undefined = undefined;
|
||||
let errorCallback: ((e: Error) => unknown) | undefined = undefined;
|
||||
let err;
|
||||
|
||||
if (typeof errorClassOrCallbackOrMsg !== "string") {
|
||||
if (typeof errorClassOrMsg !== "string") {
|
||||
if (
|
||||
errorClassOrCallbackOrMsg === undefined ||
|
||||
errorClassOrCallbackOrMsg.prototype instanceof Error ||
|
||||
errorClassOrCallbackOrMsg.prototype === Error.prototype
|
||||
errorClassOrMsg === undefined ||
|
||||
errorClassOrMsg.prototype instanceof Error ||
|
||||
errorClassOrMsg.prototype === Error.prototype
|
||||
) {
|
||||
// deno-lint-ignore no-explicit-any
|
||||
ErrorClass = errorClassOrCallbackOrMsg as new (...args: any[]) => E;
|
||||
ErrorClass = errorClassOrMsg as new (...args: any[]) => E;
|
||||
msgIncludes = msgIncludesOrMsg;
|
||||
} else {
|
||||
errorCallback = errorClassOrCallbackOrMsg as (e: Error) => unknown;
|
||||
msg = msgIncludesOrMsg;
|
||||
}
|
||||
} else {
|
||||
msg = errorClassOrCallbackOrMsg;
|
||||
msg = errorClassOrMsg;
|
||||
}
|
||||
let doesThrow = false;
|
||||
const msgToAppendToError = msg ? `: ${msg}` : ".";
|
||||
try {
|
||||
fn();
|
||||
} catch (error) {
|
||||
if (ErrorClass || errorCallback) {
|
||||
if (ErrorClass) {
|
||||
if (error instanceof Error === false) {
|
||||
throw new AssertionError("A non-Error object was thrown.");
|
||||
}
|
||||
@ -685,9 +675,6 @@ export function assertThrows<E extends Error = Error>(
|
||||
msgIncludes,
|
||||
msg,
|
||||
);
|
||||
if (typeof errorCallback === "function") {
|
||||
errorCallback(error);
|
||||
}
|
||||
}
|
||||
err = error;
|
||||
doesThrow = true;
|
||||
@ -714,19 +701,11 @@ export function assertRejects<E extends Error = Error>(
|
||||
msgIncludes?: string,
|
||||
msg?: string,
|
||||
): Promise<E>;
|
||||
/** @deprecated (will be removed after 0.157.0) Use assertRejects(fn, msg) instead, which now returns rejected value
|
||||
* and you can assert on it. */
|
||||
export function assertRejects(
|
||||
fn: () => PromiseLike<unknown>,
|
||||
errorCallback: (e: Error) => unknown,
|
||||
msg?: string,
|
||||
): Promise<Error>;
|
||||
export async function assertRejects<E extends Error = Error>(
|
||||
fn: () => PromiseLike<unknown>,
|
||||
errorClassOrCallbackOrMsg?:
|
||||
errorClassOrMsg?:
|
||||
// deno-lint-ignore no-explicit-any
|
||||
| (new (...args: any[]) => E)
|
||||
| ((e: Error) => unknown)
|
||||
| string,
|
||||
msgIncludesOrMsg?: string,
|
||||
msg?: string,
|
||||
@ -734,24 +713,20 @@ export async function assertRejects<E extends Error = Error>(
|
||||
// deno-lint-ignore no-explicit-any
|
||||
let ErrorClass: (new (...args: any[]) => E) | undefined = undefined;
|
||||
let msgIncludes: string | undefined = undefined;
|
||||
let errorCallback: ((e: Error) => unknown) | undefined = undefined;
|
||||
let err;
|
||||
|
||||
if (typeof errorClassOrCallbackOrMsg !== "string") {
|
||||
if (typeof errorClassOrMsg !== "string") {
|
||||
if (
|
||||
errorClassOrCallbackOrMsg === undefined ||
|
||||
errorClassOrCallbackOrMsg.prototype instanceof Error ||
|
||||
errorClassOrCallbackOrMsg.prototype === Error.prototype
|
||||
errorClassOrMsg === undefined ||
|
||||
errorClassOrMsg.prototype instanceof Error ||
|
||||
errorClassOrMsg.prototype === Error.prototype
|
||||
) {
|
||||
// deno-lint-ignore no-explicit-any
|
||||
ErrorClass = errorClassOrCallbackOrMsg as new (...args: any[]) => E;
|
||||
ErrorClass = errorClassOrMsg as new (...args: any[]) => E;
|
||||
msgIncludes = msgIncludesOrMsg;
|
||||
} else {
|
||||
errorCallback = errorClassOrCallbackOrMsg as (e: Error) => unknown;
|
||||
msg = msgIncludesOrMsg;
|
||||
}
|
||||
} else {
|
||||
msg = errorClassOrCallbackOrMsg;
|
||||
msg = errorClassOrMsg;
|
||||
}
|
||||
let doesThrow = false;
|
||||
let isPromiseReturned = false;
|
||||
@ -772,7 +747,7 @@ export async function assertRejects<E extends Error = Error>(
|
||||
`Function throws when expected to reject${msgToAppendToError}`,
|
||||
);
|
||||
}
|
||||
if (ErrorClass || errorCallback) {
|
||||
if (ErrorClass) {
|
||||
if (error instanceof Error === false) {
|
||||
throw new AssertionError("A non-Error object was rejected.");
|
||||
}
|
||||
@ -782,9 +757,6 @@ export async function assertRejects<E extends Error = Error>(
|
||||
msgIncludes,
|
||||
msg,
|
||||
);
|
||||
if (typeof errorCallback == "function") {
|
||||
errorCallback(error);
|
||||
}
|
||||
}
|
||||
err = error;
|
||||
doesThrow = true;
|
||||
|
@ -826,38 +826,6 @@ Deno.test("assertRejects with synchronous function that throws", async () => {
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("assertThrows with non-error value thrown and error callback", () => {
|
||||
assertThrows(
|
||||
() => {
|
||||
assertThrows(
|
||||
() => {
|
||||
throw "Panic!";
|
||||
},
|
||||
(error: Error) => error,
|
||||
"Panic!",
|
||||
);
|
||||
},
|
||||
AssertionError,
|
||||
"A non-Error object was thrown.",
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("assertRejects with non-error value rejected and error callback", async () => {
|
||||
await assertRejects(
|
||||
() => {
|
||||
return assertRejects(
|
||||
() => {
|
||||
return Promise.reject("Panic!");
|
||||
},
|
||||
(error: Error) => error,
|
||||
"Panic!",
|
||||
);
|
||||
},
|
||||
AssertionError,
|
||||
"A non-Error object was rejected.",
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("assertRejects with PromiseLike", async () => {
|
||||
await assertRejects(
|
||||
() => ({
|
||||
@ -949,38 +917,6 @@ Deno.test("assertRejects with error class", async () => {
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("assertThrows with error callback", () => {
|
||||
assertThrows(
|
||||
() => {
|
||||
throw new AggregateError([new Error("foo"), new Error("bar")], "baz");
|
||||
},
|
||||
(error: Error) => {
|
||||
assert(error instanceof AggregateError);
|
||||
assertEquals(error.message, "baz");
|
||||
assertEquals(error.errors.length, 2);
|
||||
assertStringIncludes(error.errors[0].stack, "Error: foo");
|
||||
assertStringIncludes(error.errors[1].stack, "Error: bar");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("assertRejectes with error callback", async () => {
|
||||
await assertRejects(
|
||||
() => {
|
||||
return Promise.reject(
|
||||
new AggregateError([new Error("foo"), new Error("bar")], "baz"),
|
||||
);
|
||||
},
|
||||
(error: Error) => {
|
||||
assert(error instanceof AggregateError);
|
||||
assertEquals(error.message, "baz");
|
||||
assertEquals(error.errors.length, 2);
|
||||
assertStringIncludes(error.errors[0].stack, "Error: foo");
|
||||
assertStringIncludes(error.errors[1].stack, "Error: bar");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("assertThrows with thrown error returns caught error", () => {
|
||||
const error = assertThrows(
|
||||
() => {
|
||||
|
@ -131,13 +131,6 @@ export class TextProtoReader {
|
||||
}
|
||||
}
|
||||
|
||||
/** ReadMIMEHeader reads a MIME-style header from r.
|
||||
*
|
||||
* @deprecated (will be removed after 0.157.0) Use readMimeHeader instead. */
|
||||
readMIMEHeader(): Promise<Headers | null> {
|
||||
return this.readMimeHeader();
|
||||
}
|
||||
|
||||
async readLineSlice(): Promise<Uint8Array | null> {
|
||||
let line = new Uint8Array(0);
|
||||
let r: ReadLineResult | null = null;
|
||||
|
11
uuid/v4.ts
11
uuid/v4.ts
@ -19,14 +19,3 @@ const UUID_RE =
|
||||
export function validate(id: string): boolean {
|
||||
return UUID_RE.test(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated (will be removed after 0.157.0) v4 UUID generation is deprecated and will be removed in a future
|
||||
* std/uuid release. Use the web standard `globalThis.crypto.randomUUID()`
|
||||
* function instead.
|
||||
*
|
||||
* Generate a RFC4122 v4 UUID (pseudo-random).
|
||||
*/
|
||||
export function generate(): string {
|
||||
return crypto.randomUUID();
|
||||
}
|
||||
|
@ -1,22 +1,9 @@
|
||||
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
||||
import { assert, assertEquals } from "../testing/asserts.ts";
|
||||
import { generate, validate } from "./v4.ts";
|
||||
|
||||
Deno.test("[UUID] test_uuid_v4", () => {
|
||||
const u = generate();
|
||||
assertEquals(typeof u, "string", "returns a string");
|
||||
assert(u !== "", "return string is not empty");
|
||||
});
|
||||
|
||||
Deno.test("[UUID] test_uuid_v4_format", () => {
|
||||
for (let i = 0; i < 10000; i++) {
|
||||
const u = generate() as string;
|
||||
assert(validate(u), `${u} is not a valid uuid v4`);
|
||||
}
|
||||
});
|
||||
import { assert } from "../testing/asserts.ts";
|
||||
import { validate } from "./v4.ts";
|
||||
|
||||
Deno.test("[UUID] is_valid_uuid_v4", () => {
|
||||
const u = generate();
|
||||
const u = crypto.randomUUID();
|
||||
const t = "84fb7824-b951-490e-8afd-0c13228a8282";
|
||||
const n = "84fb7824-b951-490g-8afd-0c13228a8282";
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user