WIP: bootstrap and partial real Solana watcher implementation
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env -S node
|
||||
|
||||
import process from 'node:process';
|
||||
|
||||
import { run } from '../dist/cli.mjs';
|
||||
|
||||
run(process.argv);
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"sha256.d.ts","sourceRoot":"","sources":["../src/sha256.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EACL,MAAM,IAAI,OAAO,EACjB,MAAM,IAAI,OAAO,EACjB,MAAM,IAAI,OAAO,EACjB,MAAM,IAAI,OAAO,EAClB,MAAM,WAAW,CAAC;AACnB,6DAA6D;AAC7D,eAAO,MAAM,MAAM,EAAE,OAAO,OAAiB,CAAC;AAC9C,6DAA6D;AAC7D,eAAO,MAAM,MAAM,EAAE,OAAO,OAAiB,CAAC;AAC9C,6DAA6D;AAC7D,eAAO,MAAM,MAAM,EAAE,OAAO,OAAiB,CAAC;AAC9C,6DAA6D;AAC7D,eAAO,MAAM,MAAM,EAAE,OAAO,OAAiB,CAAC"}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { expect, test } from "vitest";
|
||||
import nl from "../../../locales/nl.js";
|
||||
|
||||
test("Dutch locale error messages", () => {
|
||||
const { localeError } = nl();
|
||||
|
||||
// Test invalid_type
|
||||
expect(
|
||||
localeError({
|
||||
code: "invalid_type",
|
||||
expected: "string",
|
||||
input: 123,
|
||||
})
|
||||
).toBe("Ongeldige invoer: verwacht string, ontving getal");
|
||||
|
||||
// Test too_big with sizing
|
||||
expect(
|
||||
localeError({
|
||||
code: "too_big",
|
||||
origin: "string",
|
||||
maximum: 10,
|
||||
inclusive: true,
|
||||
input: "test string that is too long",
|
||||
})
|
||||
).toBe("Te lang: verwacht dat string <=10 tekens heeft");
|
||||
|
||||
// Test too_small with sizing
|
||||
expect(
|
||||
localeError({
|
||||
code: "too_small",
|
||||
origin: "array",
|
||||
minimum: 5,
|
||||
inclusive: false,
|
||||
input: [1, 2],
|
||||
})
|
||||
).toBe("Te klein: verwacht dat array >5 elementen heeft");
|
||||
|
||||
// Test invalid_format
|
||||
expect(
|
||||
localeError({
|
||||
code: "invalid_format",
|
||||
format: "email",
|
||||
input: "invalid-email",
|
||||
})
|
||||
).toBe("Ongeldig: emailadres");
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
# Installation
|
||||
> `npm install --save @types/node`
|
||||
|
||||
# Summary
|
||||
This package contains type definitions for Node.js (https://nodejs.org/).
|
||||
|
||||
# Details
|
||||
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node/v12.
|
||||
|
||||
### Additional Details
|
||||
* Last updated: Tue, 07 Jun 2022 19:01:37 GMT
|
||||
* Dependencies: none
|
||||
* Global values: `Buffer`, `NodeJS`, `__dirname`, `__filename`, `clearImmediate`, `clearInterval`, `clearTimeout`, `console`, `exports`, `global`, `module`, `process`, `queueMicrotask`, `require`, `setImmediate`, `setInterval`, `setTimeout`
|
||||
|
||||
# Credits
|
||||
These definitions were written by [Microsoft TypeScript](https://github.com/Microsoft), [DefinitelyTyped](https://github.com/DefinitelyTyped), [Alberto Schiabel](https://github.com/jkomyno), [Alvis HT Tang](https://github.com/alvis), [Andrew Makarov](https://github.com/r3nya), [Benjamin Toueg](https://github.com/btoueg), [Chigozirim C.](https://github.com/smac89), [David Junger](https://github.com/touffy), [Deividas Bakanas](https://github.com/DeividasBakanas), [Eugene Y. Q. Shen](https://github.com/eyqs), [Hannes Magnusson](https://github.com/Hannes-Magnusson-CK), [Hoàng Văn Khải](https://github.com/KSXGitHub), [Huw](https://github.com/hoo29), [Kelvin Jin](https://github.com/kjin), [Klaus Meinhardt](https://github.com/ajafff), [Lishude](https://github.com/islishude), [Mariusz Wiktorczyk](https://github.com/mwiktorczyk), [Mohsen Azimi](https://github.com/mohsen1), [Nicolas Even](https://github.com/n-e), [Nikita Galkin](https://github.com/galkin), [Parambir Singh](https://github.com/parambirs), [Sebastian Silbermann](https://github.com/eps1lon), [Simon Schick](https://github.com/SimonSchick), [Thomas den Hollander](https://github.com/ThomasdenH), [Wilco Bakker](https://github.com/WilcoBakker), [wwwy3y3](https://github.com/wwwy3y3), [Zane Hannan AU](https://github.com/ZaneHannanAU), [Samuel Ainsworth](https://github.com/samuela), [Kyle Uehlein](https://github.com/kuehlein), [Thanik Bhongbhibhat](https://github.com/bhongy), [Marcin Kopacz](https://github.com/chyzwar), [Trivikram Kamat](https://github.com/trivikr), [Junxiao Shi](https://github.com/yoursunny), [Ilia Baryshnikov](https://github.com/qwelias), and [ExE Boss](https://github.com/ExE-Boss).
|
||||
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Mathias Buus
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
@@ -0,0 +1,119 @@
|
||||
import type { $ZodStringFormats } from "../core/checks.js";
|
||||
import type * as errors from "../core/errors.js";
|
||||
import * as util from "../core/util.js";
|
||||
|
||||
const error: () => errors.$ZodErrorMap = () => {
|
||||
const Sizable: Record<string, { unit: string; verb: string }> = {
|
||||
string: { unit: "stafi", verb: "að hafa" },
|
||||
file: { unit: "bæti", verb: "að hafa" },
|
||||
array: { unit: "hluti", verb: "að hafa" },
|
||||
set: { unit: "hluti", verb: "að hafa" },
|
||||
};
|
||||
|
||||
function getSizing(origin: string): { unit: string; verb: string } | null {
|
||||
return Sizable[origin] ?? null;
|
||||
}
|
||||
|
||||
const FormatDictionary: {
|
||||
[k in $ZodStringFormats | (string & {})]?: string;
|
||||
} = {
|
||||
regex: "gildi",
|
||||
email: "netfang",
|
||||
url: "vefslóð",
|
||||
emoji: "emoji",
|
||||
uuid: "UUID",
|
||||
uuidv4: "UUIDv4",
|
||||
uuidv6: "UUIDv6",
|
||||
nanoid: "nanoid",
|
||||
guid: "GUID",
|
||||
cuid: "cuid",
|
||||
cuid2: "cuid2",
|
||||
ulid: "ULID",
|
||||
xid: "XID",
|
||||
ksuid: "KSUID",
|
||||
datetime: "ISO dagsetning og tími",
|
||||
date: "ISO dagsetning",
|
||||
time: "ISO tími",
|
||||
duration: "ISO tímalengd",
|
||||
ipv4: "IPv4 address",
|
||||
ipv6: "IPv6 address",
|
||||
cidrv4: "IPv4 range",
|
||||
cidrv6: "IPv6 range",
|
||||
base64: "base64-encoded strengur",
|
||||
base64url: "base64url-encoded strengur",
|
||||
json_string: "JSON strengur",
|
||||
e164: "E.164 tölugildi",
|
||||
jwt: "JWT",
|
||||
template_literal: "gildi",
|
||||
};
|
||||
|
||||
const TypeDictionary: {
|
||||
[k in errors.$ZodInvalidTypeExpected | (string & {})]?: string;
|
||||
} = {
|
||||
nan: "NaN",
|
||||
number: "númer",
|
||||
array: "fylki",
|
||||
};
|
||||
|
||||
return (issue) => {
|
||||
switch (issue.code) {
|
||||
case "invalid_type": {
|
||||
const expected = TypeDictionary[issue.expected] ?? issue.expected;
|
||||
const receivedType = util.parsedType(issue.input);
|
||||
const received = TypeDictionary[receivedType] ?? receivedType;
|
||||
if (/^[A-Z]/.test(issue.expected)) {
|
||||
return `Rangt gildi: Þú slóst inn ${received} þar sem á að vera instanceof ${issue.expected}`;
|
||||
}
|
||||
return `Rangt gildi: Þú slóst inn ${received} þar sem á að vera ${expected}`;
|
||||
}
|
||||
|
||||
case "invalid_value":
|
||||
if (issue.values.length === 1) return `Rangt gildi: gert ráð fyrir ${util.stringifyPrimitive(issue.values[0])}`;
|
||||
return `Ógilt val: má vera eitt af eftirfarandi ${util.joinValues(issue.values, "|")}`;
|
||||
case "too_big": {
|
||||
const adj = issue.inclusive ? "<=" : "<";
|
||||
const sizing = getSizing(issue.origin);
|
||||
if (sizing)
|
||||
return `Of stórt: gert er ráð fyrir að ${issue.origin ?? "gildi"} hafi ${adj}${issue.maximum.toString()} ${sizing.unit ?? "hluti"}`;
|
||||
return `Of stórt: gert er ráð fyrir að ${issue.origin ?? "gildi"} sé ${adj}${issue.maximum.toString()}`;
|
||||
}
|
||||
case "too_small": {
|
||||
const adj = issue.inclusive ? ">=" : ">";
|
||||
const sizing = getSizing(issue.origin);
|
||||
if (sizing) {
|
||||
return `Of lítið: gert er ráð fyrir að ${issue.origin} hafi ${adj}${issue.minimum.toString()} ${sizing.unit}`;
|
||||
}
|
||||
|
||||
return `Of lítið: gert er ráð fyrir að ${issue.origin} sé ${adj}${issue.minimum.toString()}`;
|
||||
}
|
||||
case "invalid_format": {
|
||||
const _issue = issue as errors.$ZodStringFormatIssues;
|
||||
if (_issue.format === "starts_with") {
|
||||
return `Ógildur strengur: verður að byrja á "${_issue.prefix}"`;
|
||||
}
|
||||
if (_issue.format === "ends_with") return `Ógildur strengur: verður að enda á "${_issue.suffix}"`;
|
||||
if (_issue.format === "includes") return `Ógildur strengur: verður að innihalda "${_issue.includes}"`;
|
||||
if (_issue.format === "regex") return `Ógildur strengur: verður að fylgja mynstri ${_issue.pattern}`;
|
||||
return `Rangt ${FormatDictionary[_issue.format] ?? issue.format}`;
|
||||
}
|
||||
case "not_multiple_of":
|
||||
return `Röng tala: verður að vera margfeldi af ${issue.divisor}`;
|
||||
case "unrecognized_keys":
|
||||
return `Óþekkt ${issue.keys.length > 1 ? "ir lyklar" : "ur lykill"}: ${util.joinValues(issue.keys, ", ")}`;
|
||||
case "invalid_key":
|
||||
return `Rangur lykill í ${issue.origin}`;
|
||||
case "invalid_union":
|
||||
return "Rangt gildi";
|
||||
case "invalid_element":
|
||||
return `Rangt gildi í ${issue.origin}`;
|
||||
default:
|
||||
return `Rangt gildi`;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export default function (): { localeError: errors.$ZodErrorMap } {
|
||||
return {
|
||||
localeError: error(),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "monthly"
|
||||
open-pull-requests-limit: 10
|
||||
|
||||
- package-ecosystem: "npm"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
open-pull-requests-limit: 10
|
||||
@@ -0,0 +1,713 @@
|
||||
declare module 'tls' {
|
||||
import * as net from 'net';
|
||||
import * as stream from 'stream';
|
||||
|
||||
const CLIENT_RENEG_LIMIT: number;
|
||||
const CLIENT_RENEG_WINDOW: number;
|
||||
|
||||
interface Certificate {
|
||||
/**
|
||||
* Country code.
|
||||
*/
|
||||
C: string;
|
||||
/**
|
||||
* Street.
|
||||
*/
|
||||
ST: string;
|
||||
/**
|
||||
* Locality.
|
||||
*/
|
||||
L: string;
|
||||
/**
|
||||
* Organization.
|
||||
*/
|
||||
O: string;
|
||||
/**
|
||||
* Organizational unit.
|
||||
*/
|
||||
OU: string;
|
||||
/**
|
||||
* Common name.
|
||||
*/
|
||||
CN: string;
|
||||
}
|
||||
|
||||
interface PeerCertificate {
|
||||
subject: Certificate;
|
||||
issuer: Certificate;
|
||||
subjectaltname: string;
|
||||
infoAccess: { [index: string]: string[] | undefined };
|
||||
modulus: string;
|
||||
exponent: string;
|
||||
valid_from: string;
|
||||
valid_to: string;
|
||||
fingerprint: string;
|
||||
fingerprint256: string;
|
||||
ext_key_usage: string[];
|
||||
serialNumber: string;
|
||||
raw: Buffer;
|
||||
}
|
||||
|
||||
interface DetailedPeerCertificate extends PeerCertificate {
|
||||
issuerCertificate: DetailedPeerCertificate;
|
||||
}
|
||||
|
||||
interface CipherNameAndProtocol {
|
||||
/**
|
||||
* The cipher name.
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* SSL/TLS protocol version.
|
||||
*/
|
||||
version: string;
|
||||
}
|
||||
|
||||
interface EphemeralKeyInfo {
|
||||
/**
|
||||
* The supported types are 'DH' and 'ECDH'.
|
||||
*/
|
||||
type: string;
|
||||
/**
|
||||
* The name property is available only when type is 'ECDH'.
|
||||
*/
|
||||
name?: string | undefined;
|
||||
/**
|
||||
* The size of parameter of an ephemeral key exchange.
|
||||
*/
|
||||
size: number;
|
||||
}
|
||||
|
||||
interface KeyObject {
|
||||
/**
|
||||
* Private keys in PEM format.
|
||||
*/
|
||||
pem: string | Buffer;
|
||||
/**
|
||||
* Optional passphrase.
|
||||
*/
|
||||
passphrase?: string | undefined;
|
||||
}
|
||||
|
||||
interface PxfObject {
|
||||
/**
|
||||
* PFX or PKCS12 encoded private key and certificate chain.
|
||||
*/
|
||||
buf: string | Buffer;
|
||||
/**
|
||||
* Optional passphrase.
|
||||
*/
|
||||
passphrase?: string | undefined;
|
||||
}
|
||||
|
||||
interface TLSSocketOptions extends SecureContextOptions, CommonConnectionOptions {
|
||||
/**
|
||||
* If true the TLS socket will be instantiated in server-mode.
|
||||
* Defaults to false.
|
||||
*/
|
||||
isServer?: boolean | undefined;
|
||||
/**
|
||||
* An optional net.Server instance.
|
||||
*/
|
||||
server?: net.Server | undefined;
|
||||
|
||||
/**
|
||||
* An optional Buffer instance containing a TLS session.
|
||||
*/
|
||||
session?: Buffer | undefined;
|
||||
/**
|
||||
* If true, specifies that the OCSP status request extension will be
|
||||
* added to the client hello and an 'OCSPResponse' event will be
|
||||
* emitted on the socket before establishing a secure communication
|
||||
*/
|
||||
requestOCSP?: boolean | undefined;
|
||||
}
|
||||
|
||||
class TLSSocket extends net.Socket {
|
||||
/**
|
||||
* Construct a new tls.TLSSocket object from an existing TCP socket.
|
||||
*/
|
||||
constructor(socket: net.Socket, options?: TLSSocketOptions);
|
||||
|
||||
/**
|
||||
* A boolean that is true if the peer certificate was signed by one of the specified CAs, otherwise false.
|
||||
*/
|
||||
authorized: boolean;
|
||||
/**
|
||||
* The reason why the peer's certificate has not been verified.
|
||||
* This property becomes available only when tlsSocket.authorized === false.
|
||||
*/
|
||||
authorizationError: Error;
|
||||
/**
|
||||
* Static boolean value, always true.
|
||||
* May be used to distinguish TLS sockets from regular ones.
|
||||
*/
|
||||
encrypted: true;
|
||||
|
||||
/**
|
||||
* String containing the selected ALPN protocol.
|
||||
* Before a handshake has completed, this value is always null.
|
||||
* When a handshake is completed but not ALPN protocol was selected, tlsSocket.alpnProtocol equals false.
|
||||
*/
|
||||
alpnProtocol: string | false | null;
|
||||
|
||||
/**
|
||||
* Returns an object representing the local certificate. The returned
|
||||
* object has some properties corresponding to the fields of the
|
||||
* certificate.
|
||||
*
|
||||
* See tls.TLSSocket.getPeerCertificate() for an example of the
|
||||
* certificate structure.
|
||||
*
|
||||
* If there is no local certificate, an empty object will be returned.
|
||||
* If the socket has been destroyed, null will be returned.
|
||||
*/
|
||||
getCertificate(): PeerCertificate | object | null;
|
||||
/**
|
||||
* Returns an object representing the cipher name and the SSL/TLS protocol version of the current connection.
|
||||
* @returns Returns an object representing the cipher name
|
||||
* and the SSL/TLS protocol version of the current connection.
|
||||
*/
|
||||
getCipher(): CipherNameAndProtocol;
|
||||
/**
|
||||
* Returns an object representing the type, name, and size of parameter
|
||||
* of an ephemeral key exchange in Perfect Forward Secrecy on a client
|
||||
* connection. It returns an empty object when the key exchange is not
|
||||
* ephemeral. As this is only supported on a client socket; null is
|
||||
* returned if called on a server socket. The supported types are 'DH'
|
||||
* and 'ECDH'. The name property is available only when type is 'ECDH'.
|
||||
*
|
||||
* For example: { type: 'ECDH', name: 'prime256v1', size: 256 }.
|
||||
*/
|
||||
getEphemeralKeyInfo(): EphemeralKeyInfo | object | null;
|
||||
/**
|
||||
* Returns the latest Finished message that has
|
||||
* been sent to the socket as part of a SSL/TLS handshake, or undefined
|
||||
* if no Finished message has been sent yet.
|
||||
*
|
||||
* As the Finished messages are message digests of the complete
|
||||
* handshake (with a total of 192 bits for TLS 1.0 and more for SSL
|
||||
* 3.0), they can be used for external authentication procedures when
|
||||
* the authentication provided by SSL/TLS is not desired or is not
|
||||
* enough.
|
||||
*
|
||||
* Corresponds to the SSL_get_finished routine in OpenSSL and may be
|
||||
* used to implement the tls-unique channel binding from RFC 5929.
|
||||
*/
|
||||
getFinished(): Buffer | undefined;
|
||||
/**
|
||||
* Returns an object representing the peer's certificate.
|
||||
* The returned object has some properties corresponding to the field of the certificate.
|
||||
* If detailed argument is true the full chain with issuer property will be returned,
|
||||
* if false only the top certificate without issuer property.
|
||||
* If the peer does not provide a certificate, it returns null or an empty object.
|
||||
* @param detailed - If true; the full chain with issuer property will be returned.
|
||||
* @returns An object representing the peer's certificate.
|
||||
*/
|
||||
getPeerCertificate(detailed: true): DetailedPeerCertificate;
|
||||
getPeerCertificate(detailed?: false): PeerCertificate;
|
||||
getPeerCertificate(detailed?: boolean): PeerCertificate | DetailedPeerCertificate;
|
||||
/**
|
||||
* Returns the latest Finished message that is expected or has actually
|
||||
* been received from the socket as part of a SSL/TLS handshake, or
|
||||
* undefined if there is no Finished message so far.
|
||||
*
|
||||
* As the Finished messages are message digests of the complete
|
||||
* handshake (with a total of 192 bits for TLS 1.0 and more for SSL
|
||||
* 3.0), they can be used for external authentication procedures when
|
||||
* the authentication provided by SSL/TLS is not desired or is not
|
||||
* enough.
|
||||
*
|
||||
* Corresponds to the SSL_get_peer_finished routine in OpenSSL and may
|
||||
* be used to implement the tls-unique channel binding from RFC 5929.
|
||||
*/
|
||||
getPeerFinished(): Buffer | undefined;
|
||||
/**
|
||||
* Returns a string containing the negotiated SSL/TLS protocol version of the current connection.
|
||||
* The value `'unknown'` will be returned for connected sockets that have not completed the handshaking process.
|
||||
* The value `null` will be returned for server sockets or disconnected client sockets.
|
||||
* See https://www.openssl.org/docs/man1.0.2/ssl/SSL_get_version.html for more information.
|
||||
* @returns negotiated SSL/TLS protocol version of the current connection
|
||||
*/
|
||||
getProtocol(): string | null;
|
||||
/**
|
||||
* Could be used to speed up handshake establishment when reconnecting to the server.
|
||||
* @returns ASN.1 encoded TLS session or undefined if none was negotiated.
|
||||
*/
|
||||
getSession(): Buffer | undefined;
|
||||
/**
|
||||
* Returns a list of signature algorithms shared between the server and
|
||||
* the client in the order of decreasing preference.
|
||||
*/
|
||||
getSharedSigalgs(): string[];
|
||||
/**
|
||||
* NOTE: Works only with client TLS sockets.
|
||||
* Useful only for debugging, for session reuse provide session option to tls.connect().
|
||||
* @returns TLS session ticket or undefined if none was negotiated.
|
||||
*/
|
||||
getTLSTicket(): Buffer | undefined;
|
||||
/**
|
||||
* Returns true if the session was reused, false otherwise.
|
||||
*/
|
||||
isSessionReused(): boolean;
|
||||
/**
|
||||
* Initiate TLS renegotiation process.
|
||||
*
|
||||
* NOTE: Can be used to request peer's certificate after the secure connection has been established.
|
||||
* ANOTHER NOTE: When running as the server, socket will be destroyed with an error after handshakeTimeout timeout.
|
||||
* @param options - The options may contain the following fields: rejectUnauthorized,
|
||||
* requestCert (See tls.createServer() for details).
|
||||
* @param callback - callback(err) will be executed with null as err, once the renegotiation
|
||||
* is successfully completed.
|
||||
* @return `undefined` when socket is destroy, `false` if negotiaion can't be initiated.
|
||||
*/
|
||||
renegotiate(options: { rejectUnauthorized?: boolean | undefined, requestCert?: boolean | undefined }, callback: (err: Error | null) => void): undefined | boolean;
|
||||
/**
|
||||
* Set maximum TLS fragment size (default and maximum value is: 16384, minimum is: 512).
|
||||
* Smaller fragment size decreases buffering latency on the client: large fragments are buffered by
|
||||
* the TLS layer until the entire fragment is received and its integrity is verified;
|
||||
* large fragments can span multiple roundtrips, and their processing can be delayed due to packet
|
||||
* loss or reordering. However, smaller fragments add extra TLS framing bytes and CPU overhead,
|
||||
* which may decrease overall server throughput.
|
||||
* @param size - TLS fragment size (default and maximum value is: 16384, minimum is: 512).
|
||||
* @returns Returns true on success, false otherwise.
|
||||
*/
|
||||
setMaxSendFragment(size: number): boolean;
|
||||
|
||||
/**
|
||||
* Disables TLS renegotiation for this TLSSocket instance. Once called,
|
||||
* attempts to renegotiate will trigger an 'error' event on the
|
||||
* TLSSocket.
|
||||
*/
|
||||
disableRenegotiation(): void;
|
||||
|
||||
/**
|
||||
* When enabled, TLS packet trace information is written to `stderr`. This can be
|
||||
* used to debug TLS connection problems.
|
||||
*
|
||||
* Note: The format of the output is identical to the output of `openssl s_client
|
||||
* -trace` or `openssl s_server -trace`. While it is produced by OpenSSL's
|
||||
* `SSL_trace()` function, the format is undocumented, can change without notice,
|
||||
* and should not be relied on.
|
||||
*/
|
||||
enableTrace(): void;
|
||||
|
||||
addListener(event: string, listener: (...args: any[]) => void): this;
|
||||
addListener(event: "OCSPResponse", listener: (response: Buffer) => void): this;
|
||||
addListener(event: "secureConnect", listener: () => void): this;
|
||||
addListener(event: "session", listener: (session: Buffer) => void): this;
|
||||
addListener(event: "keylog", listener: (line: Buffer) => void): this;
|
||||
|
||||
emit(event: string | symbol, ...args: any[]): boolean;
|
||||
emit(event: "OCSPResponse", response: Buffer): boolean;
|
||||
emit(event: "secureConnect"): boolean;
|
||||
emit(event: "session", session: Buffer): boolean;
|
||||
emit(event: "keylog", line: Buffer): boolean;
|
||||
|
||||
on(event: string, listener: (...args: any[]) => void): this;
|
||||
on(event: "OCSPResponse", listener: (response: Buffer) => void): this;
|
||||
on(event: "secureConnect", listener: () => void): this;
|
||||
on(event: "session", listener: (session: Buffer) => void): this;
|
||||
on(event: "keylog", listener: (line: Buffer) => void): this;
|
||||
|
||||
once(event: string, listener: (...args: any[]) => void): this;
|
||||
once(event: "OCSPResponse", listener: (response: Buffer) => void): this;
|
||||
once(event: "secureConnect", listener: () => void): this;
|
||||
once(event: "session", listener: (session: Buffer) => void): this;
|
||||
once(event: "keylog", listener: (line: Buffer) => void): this;
|
||||
|
||||
prependListener(event: string, listener: (...args: any[]) => void): this;
|
||||
prependListener(event: "OCSPResponse", listener: (response: Buffer) => void): this;
|
||||
prependListener(event: "secureConnect", listener: () => void): this;
|
||||
prependListener(event: "session", listener: (session: Buffer) => void): this;
|
||||
prependListener(event: "keylog", listener: (line: Buffer) => void): this;
|
||||
|
||||
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
||||
prependOnceListener(event: "OCSPResponse", listener: (response: Buffer) => void): this;
|
||||
prependOnceListener(event: "secureConnect", listener: () => void): this;
|
||||
prependOnceListener(event: "session", listener: (session: Buffer) => void): this;
|
||||
prependOnceListener(event: "keylog", listener: (line: Buffer) => void): this;
|
||||
}
|
||||
|
||||
interface CommonConnectionOptions {
|
||||
/**
|
||||
* An optional TLS context object from tls.createSecureContext()
|
||||
*/
|
||||
secureContext?: SecureContext | undefined;
|
||||
|
||||
/**
|
||||
* When enabled, TLS packet trace information is written to `stderr`. This can be
|
||||
* used to debug TLS connection problems.
|
||||
* @default false
|
||||
*/
|
||||
enableTrace?: boolean | undefined;
|
||||
/**
|
||||
* If true the server will request a certificate from clients that
|
||||
* connect and attempt to verify that certificate. Defaults to
|
||||
* false.
|
||||
*/
|
||||
requestCert?: boolean | undefined;
|
||||
/**
|
||||
* An array of strings or a Buffer naming possible ALPN protocols.
|
||||
* (Protocols should be ordered by their priority.)
|
||||
*/
|
||||
ALPNProtocols?: string[] | Uint8Array[] | Uint8Array | undefined;
|
||||
/**
|
||||
* SNICallback(servername, cb) <Function> A function that will be
|
||||
* called if the client supports SNI TLS extension. Two arguments
|
||||
* will be passed when called: servername and cb. SNICallback should
|
||||
* invoke cb(null, ctx), where ctx is a SecureContext instance.
|
||||
* (tls.createSecureContext(...) can be used to get a proper
|
||||
* SecureContext.) If SNICallback wasn't provided the default callback
|
||||
* with high-level API will be used (see below).
|
||||
*/
|
||||
SNICallback?: ((servername: string, cb: (err: Error | null, ctx: SecureContext) => void) => void) | undefined;
|
||||
/**
|
||||
* If true the server will reject any connection which is not
|
||||
* authorized with the list of supplied CAs. This option only has an
|
||||
* effect if requestCert is true.
|
||||
* @default true
|
||||
*/
|
||||
rejectUnauthorized?: boolean | undefined;
|
||||
}
|
||||
|
||||
interface TlsOptions extends SecureContextOptions, CommonConnectionOptions {
|
||||
/**
|
||||
* Abort the connection if the SSL/TLS handshake does not finish in the
|
||||
* specified number of milliseconds. A 'tlsClientError' is emitted on
|
||||
* the tls.Server object whenever a handshake times out. Default:
|
||||
* 120000 (120 seconds).
|
||||
*/
|
||||
handshakeTimeout?: number | undefined;
|
||||
/**
|
||||
* The number of seconds after which a TLS session created by the
|
||||
* server will no longer be resumable. See Session Resumption for more
|
||||
* information. Default: 300.
|
||||
*/
|
||||
sessionTimeout?: number | undefined;
|
||||
/**
|
||||
* 48-bytes of cryptographically strong pseudo-random data.
|
||||
*/
|
||||
ticketKeys?: Buffer | undefined;
|
||||
}
|
||||
|
||||
interface ConnectionOptions extends SecureContextOptions, CommonConnectionOptions {
|
||||
host?: string | undefined;
|
||||
port?: number | undefined;
|
||||
path?: string | undefined; // Creates unix socket connection to path. If this option is specified, `host` and `port` are ignored.
|
||||
socket?: stream.Duplex | undefined; // Establish secure connection on a given socket rather than creating a new socket
|
||||
checkServerIdentity?: typeof checkServerIdentity | undefined;
|
||||
servername?: string | undefined; // SNI TLS Extension
|
||||
session?: Buffer | undefined;
|
||||
minDHSize?: number | undefined;
|
||||
lookup?: net.LookupFunction | undefined;
|
||||
timeout?: number | undefined;
|
||||
}
|
||||
|
||||
class Server extends net.Server {
|
||||
/**
|
||||
* The server.addContext() method adds a secure context that will be
|
||||
* used if the client request's SNI name matches the supplied hostname
|
||||
* (or wildcard).
|
||||
*/
|
||||
addContext(hostName: string, credentials: SecureContextOptions): void;
|
||||
/**
|
||||
* Returns the session ticket keys.
|
||||
*/
|
||||
getTicketKeys(): Buffer;
|
||||
/**
|
||||
*
|
||||
* The server.setSecureContext() method replaces the
|
||||
* secure context of an existing server. Existing connections to the
|
||||
* server are not interrupted.
|
||||
*/
|
||||
setSecureContext(details: SecureContextOptions): void;
|
||||
/**
|
||||
* The server.setSecureContext() method replaces the secure context of
|
||||
* an existing server. Existing connections to the server are not
|
||||
* interrupted.
|
||||
*/
|
||||
setTicketKeys(keys: Buffer): void;
|
||||
|
||||
/**
|
||||
* events.EventEmitter
|
||||
* 1. tlsClientError
|
||||
* 2. newSession
|
||||
* 3. OCSPRequest
|
||||
* 4. resumeSession
|
||||
* 5. secureConnection
|
||||
* 6. keylog
|
||||
*/
|
||||
addListener(event: string, listener: (...args: any[]) => void): this;
|
||||
addListener(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this;
|
||||
addListener(event: "newSession", listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void): this;
|
||||
addListener(event: "OCSPRequest", listener: (certificate: Buffer, issuer: Buffer, callback: (err: Error | null, resp: Buffer) => void) => void): this;
|
||||
addListener(event: "resumeSession", listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void): this;
|
||||
addListener(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this;
|
||||
addListener(event: "keylog", listener: (line: Buffer, tlsSocket: TLSSocket) => void): this;
|
||||
|
||||
emit(event: string | symbol, ...args: any[]): boolean;
|
||||
emit(event: "tlsClientError", err: Error, tlsSocket: TLSSocket): boolean;
|
||||
emit(event: "newSession", sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void): boolean;
|
||||
emit(event: "OCSPRequest", certificate: Buffer, issuer: Buffer, callback: (err: Error | null, resp: Buffer) => void): boolean;
|
||||
emit(event: "resumeSession", sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void): boolean;
|
||||
emit(event: "secureConnection", tlsSocket: TLSSocket): boolean;
|
||||
emit(event: "keylog", line: Buffer, tlsSocket: TLSSocket): boolean;
|
||||
|
||||
on(event: string, listener: (...args: any[]) => void): this;
|
||||
on(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this;
|
||||
on(event: "newSession", listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void): this;
|
||||
on(event: "OCSPRequest", listener: (certificate: Buffer, issuer: Buffer, callback: (err: Error | null, resp: Buffer) => void) => void): this;
|
||||
on(event: "resumeSession", listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void): this;
|
||||
on(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this;
|
||||
on(event: "keylog", listener: (line: Buffer, tlsSocket: TLSSocket) => void): this;
|
||||
|
||||
once(event: string, listener: (...args: any[]) => void): this;
|
||||
once(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this;
|
||||
once(event: "newSession", listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void): this;
|
||||
once(event: "OCSPRequest", listener: (certificate: Buffer, issuer: Buffer, callback: (err: Error | null, resp: Buffer) => void) => void): this;
|
||||
once(event: "resumeSession", listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void): this;
|
||||
once(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this;
|
||||
once(event: "keylog", listener: (line: Buffer, tlsSocket: TLSSocket) => void): this;
|
||||
|
||||
prependListener(event: string, listener: (...args: any[]) => void): this;
|
||||
prependListener(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this;
|
||||
prependListener(event: "newSession", listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void): this;
|
||||
prependListener(event: "OCSPRequest", listener: (certificate: Buffer, issuer: Buffer, callback: (err: Error | null, resp: Buffer) => void) => void): this;
|
||||
prependListener(event: "resumeSession", listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void): this;
|
||||
prependListener(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this;
|
||||
prependListener(event: "keylog", listener: (line: Buffer, tlsSocket: TLSSocket) => void): this;
|
||||
|
||||
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
||||
prependOnceListener(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this;
|
||||
prependOnceListener(event: "newSession", listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void): this;
|
||||
prependOnceListener(event: "OCSPRequest", listener: (certificate: Buffer, issuer: Buffer, callback: (err: Error | null, resp: Buffer) => void) => void): this;
|
||||
prependOnceListener(event: "resumeSession", listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void): this;
|
||||
prependOnceListener(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this;
|
||||
prependOnceListener(event: "keylog", listener: (line: Buffer, tlsSocket: TLSSocket) => void): this;
|
||||
}
|
||||
|
||||
interface SecurePair {
|
||||
encrypted: TLSSocket;
|
||||
cleartext: TLSSocket;
|
||||
}
|
||||
|
||||
type SecureVersion = 'TLSv1.3' | 'TLSv1.2' | 'TLSv1.1' | 'TLSv1';
|
||||
|
||||
interface SecureContextOptions {
|
||||
/**
|
||||
* Optionally override the trusted CA certificates. Default is to trust
|
||||
* the well-known CAs curated by Mozilla. Mozilla's CAs are completely
|
||||
* replaced when CAs are explicitly specified using this option.
|
||||
*/
|
||||
ca?: string | Buffer | Array<string | Buffer> | undefined;
|
||||
/**
|
||||
* Cert chains in PEM format. One cert chain should be provided per
|
||||
* private key. Each cert chain should consist of the PEM formatted
|
||||
* certificate for a provided private key, followed by the PEM
|
||||
* formatted intermediate certificates (if any), in order, and not
|
||||
* including the root CA (the root CA must be pre-known to the peer,
|
||||
* see ca). When providing multiple cert chains, they do not have to
|
||||
* be in the same order as their private keys in key. If the
|
||||
* intermediate certificates are not provided, the peer will not be
|
||||
* able to validate the certificate, and the handshake will fail.
|
||||
*/
|
||||
cert?: string | Buffer | Array<string | Buffer> | undefined;
|
||||
/**
|
||||
* Colon-separated list of supported signature algorithms. The list
|
||||
* can contain digest algorithms (SHA256, MD5 etc.), public key
|
||||
* algorithms (RSA-PSS, ECDSA etc.), combination of both (e.g
|
||||
* 'RSA+SHA384') or TLS v1.3 scheme names (e.g. rsa_pss_pss_sha512).
|
||||
*/
|
||||
sigalgs?: string | undefined;
|
||||
/**
|
||||
* Cipher suite specification, replacing the default. For more
|
||||
* information, see modifying the default cipher suite. Permitted
|
||||
* ciphers can be obtained via tls.getCiphers(). Cipher names must be
|
||||
* uppercased in order for OpenSSL to accept them.
|
||||
*/
|
||||
ciphers?: string | undefined;
|
||||
/**
|
||||
* Name of an OpenSSL engine which can provide the client certificate.
|
||||
*/
|
||||
clientCertEngine?: string | undefined;
|
||||
/**
|
||||
* PEM formatted CRLs (Certificate Revocation Lists).
|
||||
*/
|
||||
crl?: string | Buffer | Array<string | Buffer> | undefined;
|
||||
/**
|
||||
* Diffie Hellman parameters, required for Perfect Forward Secrecy. Use
|
||||
* openssl dhparam to create the parameters. The key length must be
|
||||
* greater than or equal to 1024 bits or else an error will be thrown.
|
||||
* Although 1024 bits is permissible, use 2048 bits or larger for
|
||||
* stronger security. If omitted or invalid, the parameters are
|
||||
* silently discarded and DHE ciphers will not be available.
|
||||
*/
|
||||
dhparam?: string | Buffer | undefined;
|
||||
/**
|
||||
* A string describing a named curve or a colon separated list of curve
|
||||
* NIDs or names, for example P-521:P-384:P-256, to use for ECDH key
|
||||
* agreement. Set to auto to select the curve automatically. Use
|
||||
* crypto.getCurves() to obtain a list of available curve names. On
|
||||
* recent releases, openssl ecparam -list_curves will also display the
|
||||
* name and description of each available elliptic curve. Default:
|
||||
* tls.DEFAULT_ECDH_CURVE.
|
||||
*/
|
||||
ecdhCurve?: string | undefined;
|
||||
/**
|
||||
* Attempt to use the server's cipher suite preferences instead of the
|
||||
* client's. When true, causes SSL_OP_CIPHER_SERVER_PREFERENCE to be
|
||||
* set in secureOptions
|
||||
*/
|
||||
honorCipherOrder?: boolean | undefined;
|
||||
/**
|
||||
* Private keys in PEM format. PEM allows the option of private keys
|
||||
* being encrypted. Encrypted keys will be decrypted with
|
||||
* options.passphrase. Multiple keys using different algorithms can be
|
||||
* provided either as an array of unencrypted key strings or buffers,
|
||||
* or an array of objects in the form {pem: <string|buffer>[,
|
||||
* passphrase: <string>]}. The object form can only occur in an array.
|
||||
* object.passphrase is optional. Encrypted keys will be decrypted with
|
||||
* object.passphrase if provided, or options.passphrase if it is not.
|
||||
*/
|
||||
key?: string | Buffer | Array<Buffer | KeyObject> | undefined;
|
||||
/**
|
||||
* Name of an OpenSSL engine to get private key from. Should be used
|
||||
* together with privateKeyIdentifier.
|
||||
*/
|
||||
privateKeyEngine?: string | undefined;
|
||||
/**
|
||||
* Identifier of a private key managed by an OpenSSL engine. Should be
|
||||
* used together with privateKeyEngine. Should not be set together with
|
||||
* key, because both options define a private key in different ways.
|
||||
*/
|
||||
privateKeyIdentifier?: string | undefined;
|
||||
/**
|
||||
* Optionally set the maximum TLS version to allow. One
|
||||
* of `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. Cannot be specified along with the
|
||||
* `secureProtocol` option, use one or the other.
|
||||
* **Default:** `'TLSv1.3'`, unless changed using CLI options. Using
|
||||
* `--tls-max-v1.2` sets the default to `'TLSv1.2'`. Using `--tls-max-v1.3` sets the default to
|
||||
* `'TLSv1.3'`. If multiple of the options are provided, the highest maximum is used.
|
||||
*/
|
||||
maxVersion?: SecureVersion | undefined;
|
||||
/**
|
||||
* Optionally set the minimum TLS version to allow. One
|
||||
* of `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`. Cannot be specified along with the
|
||||
* `secureProtocol` option, use one or the other. It is not recommended to use
|
||||
* less than TLSv1.2, but it may be required for interoperability.
|
||||
* **Default:** `'TLSv1.2'`, unless changed using CLI options. Using
|
||||
* `--tls-v1.0` sets the default to `'TLSv1'`. Using `--tls-v1.1` sets the default to
|
||||
* `'TLSv1.1'`. Using `--tls-min-v1.3` sets the default to
|
||||
* 'TLSv1.3'. If multiple of the options are provided, the lowest minimum is used.
|
||||
*/
|
||||
minVersion?: SecureVersion | undefined;
|
||||
/**
|
||||
* Shared passphrase used for a single private key and/or a PFX.
|
||||
*/
|
||||
passphrase?: string | undefined;
|
||||
/**
|
||||
* PFX or PKCS12 encoded private key and certificate chain. pfx is an
|
||||
* alternative to providing key and cert individually. PFX is usually
|
||||
* encrypted, if it is, passphrase will be used to decrypt it. Multiple
|
||||
* PFX can be provided either as an array of unencrypted PFX buffers,
|
||||
* or an array of objects in the form {buf: <string|buffer>[,
|
||||
* passphrase: <string>]}. The object form can only occur in an array.
|
||||
* object.passphrase is optional. Encrypted PFX will be decrypted with
|
||||
* object.passphrase if provided, or options.passphrase if it is not.
|
||||
*/
|
||||
pfx?: string | Buffer | Array<string | Buffer | PxfObject> | undefined;
|
||||
/**
|
||||
* Optionally affect the OpenSSL protocol behavior, which is not
|
||||
* usually necessary. This should be used carefully if at all! Value is
|
||||
* a numeric bitmask of the SSL_OP_* options from OpenSSL Options
|
||||
*/
|
||||
secureOptions?: number | undefined; // Value is a numeric bitmask of the `SSL_OP_*` options
|
||||
/**
|
||||
* Legacy mechanism to select the TLS protocol version to use, it does
|
||||
* not support independent control of the minimum and maximum version,
|
||||
* and does not support limiting the protocol to TLSv1.3. Use
|
||||
* minVersion and maxVersion instead. The possible values are listed as
|
||||
* SSL_METHODS, use the function names as strings. For example, use
|
||||
* 'TLSv1_1_method' to force TLS version 1.1, or 'TLS_method' to allow
|
||||
* any TLS protocol version up to TLSv1.3. It is not recommended to use
|
||||
* TLS versions less than 1.2, but it may be required for
|
||||
* interoperability. Default: none, see minVersion.
|
||||
*/
|
||||
secureProtocol?: string | undefined;
|
||||
/**
|
||||
* Opaque identifier used by servers to ensure session state is not
|
||||
* shared between applications. Unused by clients.
|
||||
*/
|
||||
sessionIdContext?: string | undefined;
|
||||
/**
|
||||
* 48-bytes of cryptographically strong pseudo-random data.
|
||||
* See Session Resumption for more information.
|
||||
*/
|
||||
ticketKeys?: Buffer | undefined;
|
||||
/**
|
||||
* The number of seconds after which a TLS session created by the
|
||||
* server will no longer be resumable. See Session Resumption for more
|
||||
* information. Default: 300.
|
||||
*/
|
||||
sessionTimeout?: number | undefined;
|
||||
}
|
||||
|
||||
interface SecureContext {
|
||||
context: any;
|
||||
}
|
||||
|
||||
/*
|
||||
* Verifies the certificate `cert` is issued to host `host`.
|
||||
* @host The hostname to verify the certificate against
|
||||
* @cert PeerCertificate representing the peer's certificate
|
||||
*
|
||||
* Returns Error object, populating it with the reason, host and cert on failure. On success, returns undefined.
|
||||
*/
|
||||
function checkServerIdentity(host: string, cert: PeerCertificate): Error | undefined;
|
||||
function createServer(secureConnectionListener?: (socket: TLSSocket) => void): Server;
|
||||
function createServer(options: TlsOptions, secureConnectionListener?: (socket: TLSSocket) => void): Server;
|
||||
function connect(options: ConnectionOptions, secureConnectListener?: () => void): TLSSocket;
|
||||
function connect(port: number, host?: string, options?: ConnectionOptions, secureConnectListener?: () => void): TLSSocket;
|
||||
function connect(port: number, options?: ConnectionOptions, secureConnectListener?: () => void): TLSSocket;
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
function createSecurePair(credentials?: SecureContext, isServer?: boolean, requestCert?: boolean, rejectUnauthorized?: boolean): SecurePair;
|
||||
function createSecureContext(options?: SecureContextOptions): SecureContext;
|
||||
function getCiphers(): string[];
|
||||
|
||||
/**
|
||||
* The default curve name to use for ECDH key agreement in a tls server.
|
||||
* The default value is 'auto'. See tls.createSecureContext() for further
|
||||
* information.
|
||||
*/
|
||||
let DEFAULT_ECDH_CURVE: string;
|
||||
/**
|
||||
* The default value of the maxVersion option of
|
||||
* tls.createSecureContext(). It can be assigned any of the supported TLS
|
||||
* protocol versions, 'TLSv1.3', 'TLSv1.2', 'TLSv1.1', or 'TLSv1'. Default:
|
||||
* 'TLSv1.3', unless changed using CLI options. Using --tls-max-v1.2 sets
|
||||
* the default to 'TLSv1.2'. Using --tls-max-v1.3 sets the default to
|
||||
* 'TLSv1.3'. If multiple of the options are provided, the highest maximum
|
||||
* is used.
|
||||
*/
|
||||
let DEFAULT_MAX_VERSION: SecureVersion;
|
||||
/**
|
||||
* The default value of the minVersion option of tls.createSecureContext().
|
||||
* It can be assigned any of the supported TLS protocol versions,
|
||||
* 'TLSv1.3', 'TLSv1.2', 'TLSv1.1', or 'TLSv1'. Default: 'TLSv1.2', unless
|
||||
* changed using CLI options. Using --tls-min-v1.0 sets the default to
|
||||
* 'TLSv1'. Using --tls-min-v1.1 sets the default to 'TLSv1.1'. Using
|
||||
* --tls-min-v1.3 sets the default to 'TLSv1.3'. If multiple of the options
|
||||
* are provided, the lowest minimum is used.
|
||||
*/
|
||||
let DEFAULT_MIN_VERSION: SecureVersion;
|
||||
|
||||
/**
|
||||
* An immutable array of strings representing the root certificates (in PEM
|
||||
* format) used for verifying peer certificates. This is the default value
|
||||
* of the ca option to tls.createSecureContext().
|
||||
*/
|
||||
const rootCertificates: ReadonlyArray<string>;
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
'use strict'
|
||||
|
||||
const refs = {
|
||||
exit: [],
|
||||
beforeExit: []
|
||||
}
|
||||
const functions = {
|
||||
exit: onExit,
|
||||
beforeExit: onBeforeExit
|
||||
}
|
||||
|
||||
let registry
|
||||
|
||||
function ensureRegistry () {
|
||||
if (registry === undefined) {
|
||||
registry = new FinalizationRegistry(clear)
|
||||
}
|
||||
}
|
||||
|
||||
function install (event) {
|
||||
if (refs[event].length > 0) {
|
||||
return
|
||||
}
|
||||
|
||||
process.on(event, functions[event])
|
||||
}
|
||||
|
||||
function uninstall (event) {
|
||||
if (refs[event].length > 0) {
|
||||
return
|
||||
}
|
||||
process.removeListener(event, functions[event])
|
||||
if (refs.exit.length === 0 && refs.beforeExit.length === 0) {
|
||||
registry = undefined
|
||||
}
|
||||
}
|
||||
|
||||
function onExit () {
|
||||
callRefs('exit')
|
||||
}
|
||||
|
||||
function onBeforeExit () {
|
||||
callRefs('beforeExit')
|
||||
}
|
||||
|
||||
function callRefs (event) {
|
||||
for (const ref of refs[event]) {
|
||||
const obj = ref.deref()
|
||||
const fn = ref.fn
|
||||
|
||||
// This should always happen, however GC is
|
||||
// undeterministic so it might not happen.
|
||||
/* istanbul ignore else */
|
||||
if (obj !== undefined) {
|
||||
fn(obj, event)
|
||||
}
|
||||
}
|
||||
refs[event] = []
|
||||
}
|
||||
|
||||
function clear (ref) {
|
||||
for (const event of ['exit', 'beforeExit']) {
|
||||
const index = refs[event].indexOf(ref)
|
||||
refs[event].splice(index, index + 1)
|
||||
uninstall(event)
|
||||
}
|
||||
}
|
||||
|
||||
function _register (event, obj, fn) {
|
||||
if (obj === undefined) {
|
||||
throw new Error('the object can\'t be undefined')
|
||||
}
|
||||
install(event)
|
||||
const ref = new WeakRef(obj)
|
||||
ref.fn = fn
|
||||
|
||||
ensureRegistry()
|
||||
registry.register(obj, ref)
|
||||
refs[event].push(ref)
|
||||
}
|
||||
|
||||
function register (obj, fn) {
|
||||
_register('exit', obj, fn)
|
||||
}
|
||||
|
||||
function registerBeforeExit (obj, fn) {
|
||||
_register('beforeExit', obj, fn)
|
||||
}
|
||||
|
||||
function unregister (obj) {
|
||||
if (registry === undefined) {
|
||||
return
|
||||
}
|
||||
registry.unregister(obj)
|
||||
for (const event of ['exit', 'beforeExit']) {
|
||||
refs[event] = refs[event].filter((ref) => {
|
||||
const _obj = ref.deref()
|
||||
return _obj && _obj !== obj
|
||||
})
|
||||
uninstall(event)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
register,
|
||||
registerBeforeExit,
|
||||
unregister
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
type Parse = typeof parse
|
||||
|
||||
declare namespace parse {
|
||||
export type ParseOptions = {
|
||||
/**
|
||||
* What to do when a `__proto__` key is found.
|
||||
* - `'error'` - throw a `SyntaxError` when a `__proto__` key is found. This is the default value.
|
||||
* - `'remove'` - deletes any `__proto__` keys from the result object.
|
||||
* - `'ignore'` - skips all validation (same as calling `JSON.parse()` directly).
|
||||
*/
|
||||
protoAction?: 'error' | 'remove' | 'ignore';
|
||||
/**
|
||||
* What to do when a `constructor` key is found.
|
||||
* - `'error'` - throw a `SyntaxError` when a `constructor.prototype` key is found. This is the default value.
|
||||
* - `'remove'` - deletes any `constructor` keys from the result object.
|
||||
* - `'ignore'` - skips all validation (same as calling `JSON.parse()` directly).
|
||||
*/
|
||||
constructorAction?: 'error' | 'remove' | 'ignore';
|
||||
/** If `true`, returns `null` instead of throwing an error when a security issue is found. */
|
||||
safe?: boolean;
|
||||
}
|
||||
|
||||
export type ScanOptions = ParseOptions
|
||||
|
||||
export type Reviver = (this: any, key: string, value: any) => any
|
||||
|
||||
/**
|
||||
* Parses a given JSON-formatted text into an object.
|
||||
*
|
||||
* @param text The JSON text string.
|
||||
* @param reviver The `JSON.parse()` optional `reviver` argument.
|
||||
* @param options Optional configuration object.
|
||||
* @returns The parsed object.
|
||||
*/
|
||||
export const parse: Parse
|
||||
|
||||
/**
|
||||
* Safely parses a given JSON-formatted text into an object.
|
||||
*
|
||||
* @param text The JSON text string.
|
||||
* @param reviver The `JSON.parse()` optional `reviver` argument.
|
||||
* @returns The parsed object, or `undefined` if there was an error or if the JSON contained possibly insecure properties.
|
||||
*/
|
||||
export function safeParse (text: string | Buffer, reviver?: Reviver | null): any
|
||||
|
||||
/**
|
||||
* Scans a given object for prototype properties.
|
||||
*
|
||||
* @param obj The object being scanned.
|
||||
* @param options Optional configuration object.
|
||||
* @returns The object, or `null` if onError is set to `nullify`
|
||||
*/
|
||||
export function scan (obj: { [key: string | number]: any }, options?: ParseOptions): any
|
||||
|
||||
export { parse as default }
|
||||
}
|
||||
|
||||
declare function parse (text: string | Buffer, options?: parse.ParseOptions): any
|
||||
declare function parse (text: string | Buffer, reviver?: parse.Reviver | null, options?: parse.ParseOptions): any
|
||||
export = parse
|
||||
@@ -0,0 +1,21 @@
|
||||
import { type CurveFnWithCreate } from './_shortw_utils.ts';
|
||||
import { type H2CHasher } from './abstract/hash-to-curve.ts';
|
||||
/** NIST P256 (aka secp256r1, prime256v1) curve, ECDSA and ECDH methods. */
|
||||
export declare const p256: CurveFnWithCreate;
|
||||
/** Hashing / encoding to p256 points / field. RFC 9380 methods. */
|
||||
export declare const p256_hasher: H2CHasher<bigint>;
|
||||
/** NIST P384 (aka secp384r1) curve, ECDSA and ECDH methods. */
|
||||
export declare const p384: CurveFnWithCreate;
|
||||
/** Hashing / encoding to p384 points / field. RFC 9380 methods. */
|
||||
export declare const p384_hasher: H2CHasher<bigint>;
|
||||
/** NIST P521 (aka secp521r1) curve, ECDSA and ECDH methods. */
|
||||
export declare const p521: CurveFnWithCreate;
|
||||
/** @deprecated use `p256` for consistency with `p256_hasher` */
|
||||
export declare const secp256r1: typeof p256;
|
||||
/** @deprecated use `p384` for consistency with `p384_hasher` */
|
||||
export declare const secp384r1: typeof p384;
|
||||
/** @deprecated use `p521` for consistency with `p521_hasher` */
|
||||
export declare const secp521r1: typeof p521;
|
||||
/** Hashing / encoding to p521 points / field. RFC 9380 methods. */
|
||||
export declare const p521_hasher: H2CHasher<bigint>;
|
||||
//# sourceMappingURL=nist.d.ts.map
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"keys-while": {
|
||||
"name": "keys-while",
|
||||
"browser": "Chrome 60.0.3112 (Windows 7 0.0.0)",
|
||||
"suite": "iter",
|
||||
"hz": 56574.051312644304,
|
||||
"success": true,
|
||||
"fastest": true,
|
||||
"rme": 0.011898094024098757,
|
||||
"rhz": 1,
|
||||
"sampleSize": 172
|
||||
},
|
||||
"keys-for": {
|
||||
"name": "keys-for",
|
||||
"browser": "Chrome 60.0.3112 (Windows 7 0.0.0)",
|
||||
"suite": "iter",
|
||||
"hz": 55589.971512360826,
|
||||
"success": true,
|
||||
"fastest": true,
|
||||
"rme": 0.015368014920102797,
|
||||
"rhz": 0.9826054564336365,
|
||||
"sampleSize": 170
|
||||
},
|
||||
"incr-for": {
|
||||
"name": "incr-for",
|
||||
"browser": "Chrome 60.0.3112 (Windows 7 0.0.0)",
|
||||
"suite": "iter",
|
||||
"hz": 17263.158679413995,
|
||||
"success": true,
|
||||
"fastest": false,
|
||||
"rme": 0.022115589132274314,
|
||||
"rhz": 0.3051426984433706,
|
||||
"sampleSize": 170
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,182 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const utils_1 = require("@typescript-eslint/utils");
|
||||
const tsutils = __importStar(require("ts-api-utils"));
|
||||
const util_1 = require("../util");
|
||||
var ArgumentType;
|
||||
(function (ArgumentType) {
|
||||
ArgumentType[ArgumentType["Other"] = 0] = "Other";
|
||||
ArgumentType[ArgumentType["String"] = 1] = "String";
|
||||
ArgumentType[ArgumentType["RegExp"] = 2] = "RegExp";
|
||||
ArgumentType[ArgumentType["Both"] = 3] = "Both";
|
||||
})(ArgumentType || (ArgumentType = {}));
|
||||
exports.default = (0, util_1.createRule)({
|
||||
name: 'prefer-regexp-exec',
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
docs: {
|
||||
description: 'Enforce `RegExp#exec` over `String#match` if no global flag is provided',
|
||||
recommended: 'stylistic',
|
||||
requiresTypeChecking: true,
|
||||
},
|
||||
fixable: 'code',
|
||||
messages: {
|
||||
regExpExecOverStringMatch: 'Use the `RegExp#exec()` method instead.',
|
||||
},
|
||||
schema: [],
|
||||
},
|
||||
defaultOptions: [],
|
||||
create(context) {
|
||||
const globalScope = context.sourceCode.getScope(context.sourceCode.ast);
|
||||
const services = (0, util_1.getParserServices)(context);
|
||||
const checker = services.program.getTypeChecker();
|
||||
/**
|
||||
* Check if a given node type is a string.
|
||||
* @param type The node type to check.
|
||||
*/
|
||||
function isStringType(type) {
|
||||
return (0, util_1.getTypeName)(checker, type) === 'string';
|
||||
}
|
||||
/**
|
||||
* Check if a given node type is a RegExp.
|
||||
* @param type The node type to check.
|
||||
*/
|
||||
function isRegExpType(type) {
|
||||
return (0, util_1.getTypeName)(checker, type) === 'RegExp';
|
||||
}
|
||||
function collectArgumentTypes(types) {
|
||||
let result = ArgumentType.Other;
|
||||
for (const type of types) {
|
||||
if (isRegExpType(type)) {
|
||||
result |= ArgumentType.RegExp;
|
||||
}
|
||||
else if (isStringType(type)) {
|
||||
result |= ArgumentType.String;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Returns true if and only if we have syntactic proof that the /g flag is
|
||||
* absent. Returns false in all other cases (i.e. it still might or might
|
||||
* not contain the global flag).
|
||||
*/
|
||||
function definitelyDoesNotContainGlobalFlag(node) {
|
||||
if ((node.type === utils_1.AST_NODE_TYPES.CallExpression ||
|
||||
node.type === utils_1.AST_NODE_TYPES.NewExpression) &&
|
||||
node.callee.type === utils_1.AST_NODE_TYPES.Identifier &&
|
||||
node.callee.name === 'RegExp') {
|
||||
const flags = node.arguments.at(1);
|
||||
if (!flags) {
|
||||
return true;
|
||||
}
|
||||
const flagsValue = (0, util_1.getStaticValue)(flags, globalScope);
|
||||
return (!!flagsValue &&
|
||||
(typeof flagsValue.value !== 'string' ||
|
||||
!flagsValue.value.includes('g')));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return {
|
||||
'CallExpression[arguments.length=1] > MemberExpression'(memberNode) {
|
||||
if (!(0, util_1.isStaticMemberAccessOfValue)(memberNode, context, 'match')) {
|
||||
return;
|
||||
}
|
||||
const objectNode = memberNode.object;
|
||||
const callNode = memberNode.parent;
|
||||
const [argumentNode] = callNode.arguments;
|
||||
const argumentValue = (0, util_1.getStaticValue)(argumentNode, globalScope);
|
||||
if (!isStringType(services.getTypeAtLocation(objectNode))) {
|
||||
return;
|
||||
}
|
||||
// Don't report regular expressions with global flag.
|
||||
if ((!argumentValue &&
|
||||
!definitelyDoesNotContainGlobalFlag(argumentNode)) ||
|
||||
(argumentValue &&
|
||||
argumentValue.value instanceof RegExp &&
|
||||
argumentValue.value.flags.includes('g'))) {
|
||||
return;
|
||||
}
|
||||
if (argumentNode.type === utils_1.AST_NODE_TYPES.Literal &&
|
||||
typeof argumentNode.value === 'string') {
|
||||
let regExp;
|
||||
try {
|
||||
regExp = RegExp(argumentNode.value);
|
||||
}
|
||||
catch {
|
||||
return;
|
||||
}
|
||||
return context.report({
|
||||
node: memberNode.property,
|
||||
messageId: 'regExpExecOverStringMatch',
|
||||
fix: (0, util_1.getWrappingFixer)({
|
||||
node: callNode,
|
||||
innerNode: [objectNode],
|
||||
sourceCode: context.sourceCode,
|
||||
wrap: objectCode => `${regExp.toString()}.exec(${objectCode})`,
|
||||
}),
|
||||
});
|
||||
}
|
||||
const argumentType = services.getTypeAtLocation(argumentNode);
|
||||
const argumentTypes = collectArgumentTypes(tsutils.unionConstituents(argumentType));
|
||||
switch (argumentTypes) {
|
||||
case ArgumentType.RegExp:
|
||||
return context.report({
|
||||
node: memberNode.property,
|
||||
messageId: 'regExpExecOverStringMatch',
|
||||
fix: (0, util_1.getWrappingFixer)({
|
||||
node: callNode,
|
||||
innerNode: [objectNode, argumentNode],
|
||||
sourceCode: context.sourceCode,
|
||||
wrap: (objectCode, argumentCode) => `${argumentCode}.exec(${objectCode})`,
|
||||
}),
|
||||
});
|
||||
case ArgumentType.String:
|
||||
return context.report({
|
||||
node: memberNode.property,
|
||||
messageId: 'regExpExecOverStringMatch',
|
||||
fix: (0, util_1.getWrappingFixer)({
|
||||
node: callNode,
|
||||
innerNode: [objectNode, argumentNode],
|
||||
sourceCode: context.sourceCode,
|
||||
wrap: (objectCode, argumentCode) => `RegExp(${argumentCode}).exec(${objectCode})`,
|
||||
}),
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,209 @@
|
||||
/**
|
||||
* @fileoverview Tracks performance of individual rules.
|
||||
* @author Brandon Mills
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const { startTime, endTime } = require("../shared/stats");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/* c8 ignore next */
|
||||
/**
|
||||
* Align the string to left
|
||||
* @param {string} str string to evaluate
|
||||
* @param {number} len length of the string
|
||||
* @param {string} ch delimiter character
|
||||
* @returns {string} modified string
|
||||
* @private
|
||||
*/
|
||||
function alignLeft(str, len, ch) {
|
||||
return str + new Array(len - str.length + 1).join(ch || " ");
|
||||
}
|
||||
|
||||
/* c8 ignore next */
|
||||
/**
|
||||
* Align the string to right
|
||||
* @param {string} str string to evaluate
|
||||
* @param {number} len length of the string
|
||||
* @param {string} ch delimiter character
|
||||
* @returns {string} modified string
|
||||
* @private
|
||||
*/
|
||||
function alignRight(str, len, ch) {
|
||||
return new Array(len - str.length + 1).join(ch || " ") + str;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Module definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const enabled = !!process.env.TIMING;
|
||||
|
||||
const HEADERS = ["Rule", "Time (ms)", "Relative"];
|
||||
const ALIGN = [alignLeft, alignRight, alignRight];
|
||||
|
||||
/**
|
||||
* Decide how many rules to show in the output list.
|
||||
* @returns {number} the number of rules to show
|
||||
*/
|
||||
function getListSize() {
|
||||
const MINIMUM_SIZE = 10;
|
||||
|
||||
if (typeof process.env.TIMING !== "string") {
|
||||
return MINIMUM_SIZE;
|
||||
}
|
||||
|
||||
if (process.env.TIMING.toLowerCase() === "all") {
|
||||
return Number.POSITIVE_INFINITY;
|
||||
}
|
||||
|
||||
const TIMING_ENV_VAR_AS_INTEGER = Number.parseInt(process.env.TIMING, 10);
|
||||
|
||||
return TIMING_ENV_VAR_AS_INTEGER > 10
|
||||
? TIMING_ENV_VAR_AS_INTEGER
|
||||
: MINIMUM_SIZE;
|
||||
}
|
||||
|
||||
/* c8 ignore next */
|
||||
/**
|
||||
* display the data
|
||||
* @param {Object} data Data object to be displayed
|
||||
* @returns {void} prints modified string with console.log
|
||||
* @private
|
||||
*/
|
||||
function display(data) {
|
||||
let total = 0;
|
||||
const rows = Object.keys(data)
|
||||
.map(key => {
|
||||
const time = data[key];
|
||||
|
||||
total += time;
|
||||
return [key, time];
|
||||
})
|
||||
.sort((a, b) => b[1] - a[1])
|
||||
.slice(0, getListSize());
|
||||
|
||||
rows.forEach(row => {
|
||||
row.push(`${((row[1] * 100) / total).toFixed(1)}%`);
|
||||
row[1] = row[1].toFixed(3);
|
||||
});
|
||||
|
||||
rows.unshift(HEADERS);
|
||||
|
||||
const widths = [];
|
||||
|
||||
rows.forEach(row => {
|
||||
const len = row.length;
|
||||
|
||||
for (let i = 0; i < len; i++) {
|
||||
const n = row[i].length;
|
||||
|
||||
if (!widths[i] || n > widths[i]) {
|
||||
widths[i] = n;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const table = rows.map(row =>
|
||||
row.map((cell, index) => ALIGN[index](cell, widths[index])).join(" | "),
|
||||
);
|
||||
|
||||
table.splice(
|
||||
1,
|
||||
0,
|
||||
widths
|
||||
.map((width, index) => {
|
||||
const extraAlignment =
|
||||
index !== 0 && index !== widths.length - 1 ? 2 : 1;
|
||||
|
||||
return ALIGN[index](":", width + extraAlignment, "-");
|
||||
})
|
||||
.join("|"),
|
||||
);
|
||||
|
||||
console.log(table.join("\n")); // eslint-disable-line no-console -- Debugging function
|
||||
}
|
||||
|
||||
/* c8 ignore next */
|
||||
module.exports = (function () {
|
||||
const data = Object.create(null);
|
||||
let displayEnabled = true;
|
||||
|
||||
/**
|
||||
* Time the run
|
||||
* @param {any} key key from the data object
|
||||
* @param {Function} fn function to be called
|
||||
* @param {boolean} stats if 'stats' is true, return the result and the time difference
|
||||
* @returns {Function} function to be executed
|
||||
* @private
|
||||
*/
|
||||
function time(key, fn, stats) {
|
||||
return function (...args) {
|
||||
const t = startTime();
|
||||
const result = fn(...args);
|
||||
const tdiff = endTime(t);
|
||||
|
||||
if (enabled) {
|
||||
if (typeof data[key] === "undefined") {
|
||||
data[key] = 0;
|
||||
}
|
||||
|
||||
data[key] += tdiff;
|
||||
}
|
||||
|
||||
return stats ? { result, tdiff } : result;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a shallow copy of the collected timings data.
|
||||
* @returns {Record<string, number>} mapping of ruleId to total time in ms
|
||||
*/
|
||||
function getData() {
|
||||
return { ...data };
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges rule timing totals collected elsewhere into this process' totals.
|
||||
* @param {Record<string, number>} dataToMerge mapping of ruleId to total time in ms
|
||||
* @returns {void}
|
||||
*/
|
||||
function mergeData(dataToMerge) {
|
||||
for (const [key, value] of Object.entries(dataToMerge)) {
|
||||
if (typeof data[key] === "undefined") {
|
||||
data[key] = 0;
|
||||
}
|
||||
data[key] += value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables printing of timing data on process exit.
|
||||
* Intended for worker threads or non-main contexts.
|
||||
* @returns {void}
|
||||
*/
|
||||
function disableDisplay() {
|
||||
displayEnabled = false;
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
process.on("exit", () => {
|
||||
if (displayEnabled && Object.keys(data).length > 0) {
|
||||
display(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
time,
|
||||
enabled,
|
||||
getListSize,
|
||||
getData,
|
||||
mergeData,
|
||||
disableDisplay,
|
||||
};
|
||||
})();
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"main": "../../cjs/_class_apply_descriptor_get.cjs",
|
||||
"module": "../../esm/_class_apply_descriptor_get.js"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
|
||||
function _iterable_to_array_limit_loose(arr, i) {
|
||||
var _i = arr && (typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]);
|
||||
|
||||
if (_i == null) return;
|
||||
|
||||
var _arr = [];
|
||||
|
||||
for (_i = _i.call(arr), _step; !(_step = _i.next()).done;) {
|
||||
_arr.push(_step.value);
|
||||
if (i && _arr.length === i) break;
|
||||
}
|
||||
|
||||
return _arr;
|
||||
}
|
||||
exports._ = _iterable_to_array_limit_loose;
|
||||
@@ -0,0 +1,2 @@
|
||||
import type { TSESLint, TSESTree } from '@typescript-eslint/utils';
|
||||
export declare function rangeToLoc(sourceCode: TSESLint.SourceCode, range: TSESLint.AST.Range): TSESTree.SourceLocation;
|
||||
@@ -0,0 +1,68 @@
|
||||
import { Readable } from 'node:stream'
|
||||
import { Blob } from 'node:buffer'
|
||||
|
||||
export default BodyReadable
|
||||
|
||||
declare class BodyReadable extends Readable {
|
||||
constructor (opts: {
|
||||
resume: (this: Readable, size: number) => void | null;
|
||||
abort: () => void | null;
|
||||
contentType?: string;
|
||||
contentLength?: number;
|
||||
highWaterMark?: number;
|
||||
})
|
||||
|
||||
/** Consumes and returns the body as a string
|
||||
* https://fetch.spec.whatwg.org/#dom-body-text
|
||||
*/
|
||||
text (): Promise<string>
|
||||
|
||||
/** Consumes and returns the body as a JavaScript Object
|
||||
* https://fetch.spec.whatwg.org/#dom-body-json
|
||||
*/
|
||||
json (): Promise<unknown>
|
||||
|
||||
/** Consumes and returns the body as a Blob
|
||||
* https://fetch.spec.whatwg.org/#dom-body-blob
|
||||
*/
|
||||
blob (): Promise<Blob>
|
||||
|
||||
/** Consumes and returns the body as an Uint8Array
|
||||
* https://fetch.spec.whatwg.org/#dom-body-bytes
|
||||
*/
|
||||
bytes (): Promise<Uint8Array>
|
||||
|
||||
/** Consumes and returns the body as an ArrayBuffer
|
||||
* https://fetch.spec.whatwg.org/#dom-body-arraybuffer
|
||||
*/
|
||||
arrayBuffer (): Promise<ArrayBuffer>
|
||||
|
||||
/** Not implemented
|
||||
*
|
||||
* https://fetch.spec.whatwg.org/#dom-body-formdata
|
||||
*/
|
||||
formData (): Promise<never>
|
||||
|
||||
/** Returns true if the body is not null and the body has been consumed
|
||||
*
|
||||
* Otherwise, returns false
|
||||
*
|
||||
* https://fetch.spec.whatwg.org/#dom-body-bodyused
|
||||
*/
|
||||
readonly bodyUsed: boolean
|
||||
|
||||
/**
|
||||
* If body is null, it should return null as the body
|
||||
*
|
||||
* If body is not null, should return the body as a ReadableStream
|
||||
*
|
||||
* https://fetch.spec.whatwg.org/#dom-body-body
|
||||
*/
|
||||
readonly body: never | undefined
|
||||
|
||||
/** Dumps the response body by reading `limit` number of bytes.
|
||||
* @param opts.limit Number of bytes to read (optional) - Default: 131072
|
||||
* @param opts.signal AbortSignal to cancel the operation (optional)
|
||||
*/
|
||||
dump (opts?: { limit: number; signal?: AbortSignal }): Promise<void>
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<h1 align="center">TypeScript API Utils</h1>
|
||||
|
||||
<p align="center">
|
||||
Utility functions for working with TypeScript's API.
|
||||
Successor to the wonderful tsutils.
|
||||
🛠️️
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/JoshuaKGoldberg/ts-api-utils/blob/main/.github/CODE_OF_CONDUCT.md" target="_blank"><img alt="🤝 Code of Conduct: Kept" src="https://img.shields.io/badge/%F0%9F%A4%9D_code_of_conduct-kept-21bb42" /></a>
|
||||
<a href="https://codecov.io/gh/JoshuaKGoldberg/ts-api-utils" target="_blank"><img alt="🧪 Coverage" src="https://img.shields.io/codecov/c/github/JoshuaKGoldberg/ts-api-utils?label=%F0%9F%A7%AA%20coverage" /></a>
|
||||
<a href="#" target="_blank"><img alt="📚 Documentation Coverage" src="https://raw.githubusercontent.com/JoshuaKGoldberg/ts-api-utils/refs/heads/main/docs/coverage.svg" /></a>
|
||||
<a href="https://github.com/JoshuaKGoldberg/ts-api-utils/blob/main/LICENSE.md" target="_blank"><img alt="📝 License: MIT" src="https://img.shields.io/badge/%F0%9F%93%9D_license-MIT-21bb42.svg"></a>
|
||||
<a href="http://npmjs.com/package/ts-api-utils"><img alt="📦 npm version" src="https://img.shields.io/npm/v/ts-api-utils?color=21bb42&label=%F0%9F%93%A6%20npm" /></a>
|
||||
<img alt="💪 TypeScript: Strict" src="https://img.shields.io/badge/%F0%9F%92%AA_typescript-strict-21bb42.svg" />
|
||||
</p>
|
||||
|
||||
## Usage
|
||||
|
||||
```shell
|
||||
npm i ts-api-utils
|
||||
```
|
||||
|
||||
```ts
|
||||
import * as tsutils from "ts-api-utils";
|
||||
|
||||
tsutils.forEachToken(/* ... */);
|
||||
```
|
||||
|
||||
### API
|
||||
|
||||
`ts-api-utils` provides many utility functions.
|
||||
Check out our API docs for details:
|
||||
|
||||
📝 [ts-api-utils API docs](https://joshuakgoldberg.github.io/ts-api-utils).
|
||||
|
||||
## Development
|
||||
|
||||
See [`.github/CONTRIBUTING.md`](./.github/CONTRIBUTING.md).
|
||||
Thanks! 💖
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,63 @@
|
||||
{
|
||||
"name": "@eslint/plugin-kit",
|
||||
"version": "0.7.2",
|
||||
"description": "Utilities for building ESLint plugins.",
|
||||
"author": "Nicholas C. Zakas",
|
||||
"type": "module",
|
||||
"main": "dist/esm/index.js",
|
||||
"types": "dist/esm/index.d.ts",
|
||||
"exports": {
|
||||
"require": {
|
||||
"types": "./dist/cjs/index.d.cts",
|
||||
"default": "./dist/cjs/index.cjs"
|
||||
},
|
||||
"import": {
|
||||
"types": "./dist/esm/index.d.ts",
|
||||
"default": "./dist/esm/index.js"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/eslint/rewrite.git",
|
||||
"directory": "packages/plugin-kit"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/eslint/rewrite/issues"
|
||||
},
|
||||
"homepage": "https://github.com/eslint/rewrite/tree/main/packages/plugin-kit#readme",
|
||||
"scripts": {
|
||||
"build:dedupe-types": "node ../../tools/dedupe-types.js dist/cjs/index.cjs dist/esm/index.js",
|
||||
"build:cts": "node ../../tools/build-cts.js dist/esm/index.d.ts dist/cjs/index.d.cts && node -e \"fs.cpSync('dist/esm/types.d.ts', 'dist/cjs/types.d.cts')\"",
|
||||
"build": "rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && npm run build:cts",
|
||||
"lint:types": "attw --pack",
|
||||
"pretest": "npm run build",
|
||||
"test": "npm run test:types && npm run test:unit",
|
||||
"test:coverage": "npm run build && c8 npm run test:unit",
|
||||
"test:jsr": "npx -y jsr@latest publish --dry-run",
|
||||
"test:types": "tsc -p tests/types/tsconfig.json",
|
||||
"test:unit": "mocha \"tests/**/*.test.js\""
|
||||
},
|
||||
"keywords": [
|
||||
"eslint",
|
||||
"eslintplugin",
|
||||
"eslint-plugin"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@eslint/core": "^1.2.1",
|
||||
"levn": "^0.4.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/levn": "^0.4.0",
|
||||
"rollup-plugin-copy": "^3.5.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.19.0 || ^22.13.0 || >=24"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
export declare const EXPANSION_MAX = 100000;
|
||||
export declare const EXPANSION_MAX_LENGTH = 4000000;
|
||||
export type BraceExpansionOptions = {
|
||||
max?: number;
|
||||
maxLength?: number;
|
||||
};
|
||||
export declare function expand(str: string, options?: BraceExpansionOptions): string[];
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
export { };
|
||||
@@ -0,0 +1,60 @@
|
||||
# flatted (Go)
|
||||
|
||||
A super light and fast circular JSON parser.
|
||||
|
||||
## Usage
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/WebReflection/flatted/golang/pkg/flatted"
|
||||
)
|
||||
|
||||
type Group struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
Name string `json:"name"`
|
||||
Friend *User `json:"friend"`
|
||||
Group *Group `json:"group"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
group := &Group{Name: "Developers"}
|
||||
alice := &User{Name: "Alice", Group: group}
|
||||
bob := &User{Name: "Bob", Group: group}
|
||||
|
||||
alice.Friend = bob
|
||||
bob.Friend = alice // Circular reference
|
||||
|
||||
// Stringify Alice
|
||||
s, _ := flatted.Stringify(alice)
|
||||
fmt.Println(s)
|
||||
// Output: [{"name":"Alice","friend":"1","group":"2"},{"name":"Bob","friend":"0","group":"2"},{"name":"Developers"}]
|
||||
|
||||
// Flattening in action:
|
||||
// Index "0" is Alice, Index "1" is Bob, Index "2" is the shared Group.
|
||||
|
||||
// Parse back into a generic map structure
|
||||
res, _ := flatted.Parse(s)
|
||||
aliceMap := res.(map[string]any)
|
||||
fmt.Println(aliceMap["name"]) // Alice
|
||||
}
|
||||
```
|
||||
|
||||
## CLI
|
||||
|
||||
Build the binary using the provided Makefile:
|
||||
|
||||
```bash
|
||||
make build
|
||||
```
|
||||
|
||||
Then use it to parse flatted JSON from stdin:
|
||||
|
||||
```bash
|
||||
echo '[{"a":"1"},"b"]' | ./flatted
|
||||
```
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user