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,29 @@
|
||||
import type { TSESTree } from '@typescript-eslint/utils';
|
||||
import type { InferMessageIdsTypeFromRule, InferOptionsTypeFromRule } from '../util';
|
||||
declare const baseRule: import("@typescript-eslint/utils/ts-eslint").RuleModule<"noMagic", [{
|
||||
detectObjects?: boolean;
|
||||
enforceConst?: boolean;
|
||||
ignore?: (number | string)[];
|
||||
ignoreArrayIndexes?: boolean;
|
||||
ignoreEnums?: boolean;
|
||||
ignoreNumericLiteralTypes?: boolean;
|
||||
ignoreReadonlyClassProperties?: boolean;
|
||||
ignoreTypeIndexes?: boolean;
|
||||
}], unknown, {
|
||||
Literal(node: TSESTree.Literal): void;
|
||||
}>;
|
||||
export type Options = InferOptionsTypeFromRule<typeof baseRule>;
|
||||
export type MessageIds = InferMessageIdsTypeFromRule<typeof baseRule>;
|
||||
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"noMagic", [{
|
||||
detectObjects?: boolean;
|
||||
enforceConst?: boolean;
|
||||
ignore?: (number | string)[];
|
||||
ignoreArrayIndexes?: boolean;
|
||||
ignoreEnums?: boolean;
|
||||
ignoreNumericLiteralTypes?: boolean;
|
||||
ignoreReadonlyClassProperties?: boolean;
|
||||
ignoreTypeIndexes?: boolean;
|
||||
}], import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
||||
name: string;
|
||||
};
|
||||
export default _default;
|
||||
@@ -0,0 +1,42 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference lib="es2015.iterable" />
|
||||
/// <reference lib="es2020.intl" />
|
||||
/// <reference lib="es2020.symbol.wellknown" />
|
||||
|
||||
interface String {
|
||||
/**
|
||||
* Matches a string with a regular expression, and returns an iterable of matches
|
||||
* containing the results of that search.
|
||||
* @param regexp A regular expression
|
||||
*/
|
||||
matchAll(regexp: RegExp): RegExpStringIterator<RegExpExecArray>;
|
||||
|
||||
/** Converts all alphabetic characters to lowercase, taking into account the host environment's current locale. */
|
||||
toLocaleLowerCase(locales?: Intl.LocalesArgument): string;
|
||||
|
||||
/** Returns a string where all alphabetic characters have been converted to uppercase, taking into account the host environment's current locale. */
|
||||
toLocaleUpperCase(locales?: Intl.LocalesArgument): string;
|
||||
|
||||
/**
|
||||
* Determines whether two strings are equivalent in the current or specified locale.
|
||||
* @param that String to compare to target string
|
||||
* @param locales A locale string or array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. This parameter must conform to BCP 47 standards; see the Intl.Collator object for details.
|
||||
* @param options An object that contains one or more properties that specify comparison options. see the Intl.Collator object for details.
|
||||
*/
|
||||
localeCompare(that: string, locales?: Intl.LocalesArgument, options?: Intl.CollatorOptions): number;
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
import { IncomingHttpHeaders } from './header'
|
||||
import Client from './client'
|
||||
|
||||
export default Errors
|
||||
|
||||
declare namespace Errors {
|
||||
export class UndiciError extends Error {
|
||||
name: string
|
||||
code: string
|
||||
}
|
||||
|
||||
/** Connect timeout error. */
|
||||
export class ConnectTimeoutError extends UndiciError {
|
||||
name: 'ConnectTimeoutError'
|
||||
code: 'UND_ERR_CONNECT_TIMEOUT'
|
||||
}
|
||||
|
||||
/** A header exceeds the `headersTimeout` option. */
|
||||
export class HeadersTimeoutError extends UndiciError {
|
||||
name: 'HeadersTimeoutError'
|
||||
code: 'UND_ERR_HEADERS_TIMEOUT'
|
||||
}
|
||||
|
||||
/** Headers overflow error. */
|
||||
export class HeadersOverflowError extends UndiciError {
|
||||
name: 'HeadersOverflowError'
|
||||
code: 'UND_ERR_HEADERS_OVERFLOW'
|
||||
}
|
||||
|
||||
/** A body exceeds the `bodyTimeout` option. */
|
||||
export class BodyTimeoutError extends UndiciError {
|
||||
name: 'BodyTimeoutError'
|
||||
code: 'UND_ERR_BODY_TIMEOUT'
|
||||
}
|
||||
|
||||
export class ResponseError extends UndiciError {
|
||||
constructor (
|
||||
message: string,
|
||||
code: number,
|
||||
options: {
|
||||
headers?: IncomingHttpHeaders | string[] | null,
|
||||
body?: null | Record<string, any> | string
|
||||
}
|
||||
)
|
||||
name: 'ResponseError'
|
||||
code: 'UND_ERR_RESPONSE'
|
||||
statusCode: number
|
||||
body: null | Record<string, any> | string
|
||||
headers: IncomingHttpHeaders | string[] | null
|
||||
}
|
||||
|
||||
/** Passed an invalid argument. */
|
||||
export class InvalidArgumentError extends UndiciError {
|
||||
name: 'InvalidArgumentError'
|
||||
code: 'UND_ERR_INVALID_ARG'
|
||||
}
|
||||
|
||||
/** Returned an invalid value. */
|
||||
export class InvalidReturnValueError extends UndiciError {
|
||||
name: 'InvalidReturnValueError'
|
||||
code: 'UND_ERR_INVALID_RETURN_VALUE'
|
||||
}
|
||||
|
||||
/** The request has been aborted by the user. */
|
||||
export class RequestAbortedError extends UndiciError {
|
||||
name: 'AbortError'
|
||||
code: 'UND_ERR_ABORTED'
|
||||
}
|
||||
|
||||
/** Expected error with reason. */
|
||||
export class InformationalError extends UndiciError {
|
||||
name: 'InformationalError'
|
||||
code: 'UND_ERR_INFO'
|
||||
}
|
||||
|
||||
/** Request body length does not match content-length header. */
|
||||
export class RequestContentLengthMismatchError extends UndiciError {
|
||||
name: 'RequestContentLengthMismatchError'
|
||||
code: 'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH'
|
||||
}
|
||||
|
||||
/** Response body length does not match content-length header. */
|
||||
export class ResponseContentLengthMismatchError extends UndiciError {
|
||||
name: 'ResponseContentLengthMismatchError'
|
||||
code: 'UND_ERR_RES_CONTENT_LENGTH_MISMATCH'
|
||||
}
|
||||
|
||||
/** Trying to use a destroyed client. */
|
||||
export class ClientDestroyedError extends UndiciError {
|
||||
name: 'ClientDestroyedError'
|
||||
code: 'UND_ERR_DESTROYED'
|
||||
}
|
||||
|
||||
/** Trying to use a closed client. */
|
||||
export class ClientClosedError extends UndiciError {
|
||||
name: 'ClientClosedError'
|
||||
code: 'UND_ERR_CLOSED'
|
||||
}
|
||||
|
||||
/** There is an error with the socket. */
|
||||
export class SocketError extends UndiciError {
|
||||
name: 'SocketError'
|
||||
code: 'UND_ERR_SOCKET'
|
||||
socket: Client.SocketInfo | null
|
||||
}
|
||||
|
||||
/** Encountered unsupported functionality. */
|
||||
export class NotSupportedError extends UndiciError {
|
||||
name: 'NotSupportedError'
|
||||
code: 'UND_ERR_NOT_SUPPORTED'
|
||||
}
|
||||
|
||||
/** No upstream has been added to the BalancedPool. */
|
||||
export class BalancedPoolMissingUpstreamError extends UndiciError {
|
||||
name: 'MissingUpstreamError'
|
||||
code: 'UND_ERR_BPL_MISSING_UPSTREAM'
|
||||
}
|
||||
|
||||
export class HTTPParserError extends UndiciError {
|
||||
name: 'HTTPParserError'
|
||||
code: string
|
||||
}
|
||||
|
||||
/** The response exceed the length allowed. */
|
||||
export class ResponseExceededMaxSizeError extends UndiciError {
|
||||
name: 'ResponseExceededMaxSizeError'
|
||||
code: 'UND_ERR_RES_EXCEEDED_MAX_SIZE'
|
||||
}
|
||||
|
||||
export class RequestRetryError extends UndiciError {
|
||||
constructor (
|
||||
message: string,
|
||||
statusCode: number,
|
||||
headers?: IncomingHttpHeaders | string[] | null,
|
||||
body?: null | Record<string, any> | string
|
||||
)
|
||||
name: 'RequestRetryError'
|
||||
code: 'UND_ERR_REQ_RETRY'
|
||||
statusCode: number
|
||||
data: {
|
||||
count: number;
|
||||
}
|
||||
|
||||
headers: Record<string, string | string[]>
|
||||
}
|
||||
|
||||
export class SecureProxyConnectionError extends UndiciError {
|
||||
constructor (
|
||||
cause?: Error,
|
||||
message?: string,
|
||||
options?: Record<any, any>
|
||||
)
|
||||
name: 'SecureProxyConnectionError'
|
||||
code: 'UND_ERR_PRX_TLS'
|
||||
}
|
||||
|
||||
export class MaxOriginsReachedError extends UndiciError {
|
||||
name: 'MaxOriginsReachedError'
|
||||
code: 'UND_ERR_MAX_ORIGINS_REACHED'
|
||||
}
|
||||
|
||||
/** SOCKS5 proxy related error. */
|
||||
export class Socks5ProxyError extends UndiciError {
|
||||
constructor (
|
||||
message?: string,
|
||||
code?: string
|
||||
)
|
||||
name: 'Socks5ProxyError'
|
||||
code: string
|
||||
}
|
||||
|
||||
/** WebSocket decompressed message exceeded maximum size. */
|
||||
export class MessageSizeExceededError extends UndiciError {
|
||||
name: 'MessageSizeExceededError'
|
||||
code: 'UND_ERR_WS_MESSAGE_SIZE_EXCEEDED'
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 typescript-eslint and other contributors
|
||||
|
||||
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,31 @@
|
||||
import type { TSESTree } from '../../ts-estree';
|
||||
type IsSpecificTokenFunction<SpecificToken extends TSESTree.Token> = (token: TSESTree.Token) => token is SpecificToken;
|
||||
type IsNotSpecificTokenFunction<SpecificToken extends TSESTree.Token> = (token: TSESTree.Token) => token is Exclude<TSESTree.Token, SpecificToken>;
|
||||
type PunctuatorTokenWithValue<Value extends string> = {
|
||||
value: Value;
|
||||
} & TSESTree.PunctuatorToken;
|
||||
type IsPunctuatorTokenWithValueFunction<Value extends string> = IsSpecificTokenFunction<PunctuatorTokenWithValue<Value>>;
|
||||
type IsNotPunctuatorTokenWithValueFunction<Value extends string> = IsNotSpecificTokenFunction<PunctuatorTokenWithValue<Value>>;
|
||||
export declare const isArrowToken: IsPunctuatorTokenWithValueFunction<'=>'>;
|
||||
export declare const isNotArrowToken: IsNotPunctuatorTokenWithValueFunction<'=>'>;
|
||||
export declare const isClosingBraceToken: IsPunctuatorTokenWithValueFunction<'}'>;
|
||||
export declare const isNotClosingBraceToken: IsNotPunctuatorTokenWithValueFunction<'}'>;
|
||||
export declare const isClosingBracketToken: IsPunctuatorTokenWithValueFunction<']'>;
|
||||
export declare const isNotClosingBracketToken: IsNotPunctuatorTokenWithValueFunction<']'>;
|
||||
export declare const isClosingParenToken: IsPunctuatorTokenWithValueFunction<')'>;
|
||||
export declare const isNotClosingParenToken: IsNotPunctuatorTokenWithValueFunction<')'>;
|
||||
export declare const isColonToken: IsPunctuatorTokenWithValueFunction<':'>;
|
||||
export declare const isNotColonToken: IsNotPunctuatorTokenWithValueFunction<':'>;
|
||||
export declare const isCommaToken: IsPunctuatorTokenWithValueFunction<','>;
|
||||
export declare const isNotCommaToken: IsNotPunctuatorTokenWithValueFunction<','>;
|
||||
export declare const isCommentToken: IsSpecificTokenFunction<TSESTree.Comment>;
|
||||
export declare const isNotCommentToken: IsNotSpecificTokenFunction<TSESTree.Comment>;
|
||||
export declare const isOpeningBraceToken: IsPunctuatorTokenWithValueFunction<'{'>;
|
||||
export declare const isNotOpeningBraceToken: IsNotPunctuatorTokenWithValueFunction<'{'>;
|
||||
export declare const isOpeningBracketToken: IsPunctuatorTokenWithValueFunction<'['>;
|
||||
export declare const isNotOpeningBracketToken: IsNotPunctuatorTokenWithValueFunction<'['>;
|
||||
export declare const isOpeningParenToken: IsPunctuatorTokenWithValueFunction<'('>;
|
||||
export declare const isNotOpeningParenToken: IsNotPunctuatorTokenWithValueFunction<'('>;
|
||||
export declare const isSemicolonToken: IsPunctuatorTokenWithValueFunction<';'>;
|
||||
export declare const isNotSemicolonToken: IsNotPunctuatorTokenWithValueFunction<';'>;
|
||||
export {};
|
||||
@@ -0,0 +1,147 @@
|
||||
"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 (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = default_1;
|
||||
const util = __importStar(require("../core/util.cjs"));
|
||||
const error = () => {
|
||||
const Sizable = {
|
||||
string: { unit: "символа", verb: "да съдържа" },
|
||||
file: { unit: "байта", verb: "да съдържа" },
|
||||
array: { unit: "елемента", verb: "да съдържа" },
|
||||
set: { unit: "елемента", verb: "да съдържа" },
|
||||
};
|
||||
function getSizing(origin) {
|
||||
return Sizable[origin] ?? null;
|
||||
}
|
||||
const FormatDictionary = {
|
||||
regex: "вход",
|
||||
email: "имейл адрес",
|
||||
url: "URL",
|
||||
emoji: "емоджи",
|
||||
uuid: "UUID",
|
||||
uuidv4: "UUIDv4",
|
||||
uuidv6: "UUIDv6",
|
||||
nanoid: "nanoid",
|
||||
guid: "GUID",
|
||||
cuid: "cuid",
|
||||
cuid2: "cuid2",
|
||||
ulid: "ULID",
|
||||
xid: "XID",
|
||||
ksuid: "KSUID",
|
||||
datetime: "ISO време",
|
||||
date: "ISO дата",
|
||||
time: "ISO време",
|
||||
duration: "ISO продължителност",
|
||||
ipv4: "IPv4 адрес",
|
||||
ipv6: "IPv6 адрес",
|
||||
cidrv4: "IPv4 диапазон",
|
||||
cidrv6: "IPv6 диапазон",
|
||||
base64: "base64-кодиран низ",
|
||||
base64url: "base64url-кодиран низ",
|
||||
json_string: "JSON низ",
|
||||
e164: "E.164 номер",
|
||||
jwt: "JWT",
|
||||
template_literal: "вход",
|
||||
};
|
||||
const TypeDictionary = {
|
||||
nan: "NaN",
|
||||
number: "число",
|
||||
array: "масив",
|
||||
};
|
||||
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 `Невалиден вход: очакван instanceof ${issue.expected}, получен ${received}`;
|
||||
}
|
||||
return `Невалиден вход: очакван ${expected}, получен ${received}`;
|
||||
}
|
||||
case "invalid_value":
|
||||
if (issue.values.length === 1)
|
||||
return `Невалиден вход: очакван ${util.stringifyPrimitive(issue.values[0])}`;
|
||||
return `Невалидна опция: очаквано едно от ${util.joinValues(issue.values, "|")}`;
|
||||
case "too_big": {
|
||||
const adj = issue.inclusive ? "<=" : "<";
|
||||
const sizing = getSizing(issue.origin);
|
||||
if (sizing)
|
||||
return `Твърде голямо: очаква се ${issue.origin ?? "стойност"} да съдържа ${adj}${issue.maximum.toString()} ${sizing.unit ?? "елемента"}`;
|
||||
return `Твърде голямо: очаква се ${issue.origin ?? "стойност"} да бъде ${adj}${issue.maximum.toString()}`;
|
||||
}
|
||||
case "too_small": {
|
||||
const adj = issue.inclusive ? ">=" : ">";
|
||||
const sizing = getSizing(issue.origin);
|
||||
if (sizing) {
|
||||
return `Твърде малко: очаква се ${issue.origin} да съдържа ${adj}${issue.minimum.toString()} ${sizing.unit}`;
|
||||
}
|
||||
return `Твърде малко: очаква се ${issue.origin} да бъде ${adj}${issue.minimum.toString()}`;
|
||||
}
|
||||
case "invalid_format": {
|
||||
const _issue = issue;
|
||||
if (_issue.format === "starts_with") {
|
||||
return `Невалиден низ: трябва да започва с "${_issue.prefix}"`;
|
||||
}
|
||||
if (_issue.format === "ends_with")
|
||||
return `Невалиден низ: трябва да завършва с "${_issue.suffix}"`;
|
||||
if (_issue.format === "includes")
|
||||
return `Невалиден низ: трябва да включва "${_issue.includes}"`;
|
||||
if (_issue.format === "regex")
|
||||
return `Невалиден низ: трябва да съвпада с ${_issue.pattern}`;
|
||||
let invalid_adj = "Невалиден";
|
||||
if (_issue.format === "emoji")
|
||||
invalid_adj = "Невалидно";
|
||||
if (_issue.format === "datetime")
|
||||
invalid_adj = "Невалидно";
|
||||
if (_issue.format === "date")
|
||||
invalid_adj = "Невалидна";
|
||||
if (_issue.format === "time")
|
||||
invalid_adj = "Невалидно";
|
||||
if (_issue.format === "duration")
|
||||
invalid_adj = "Невалидна";
|
||||
return `${invalid_adj} ${FormatDictionary[_issue.format] ?? issue.format}`;
|
||||
}
|
||||
case "not_multiple_of":
|
||||
return `Невалидно число: трябва да бъде кратно на ${issue.divisor}`;
|
||||
case "unrecognized_keys":
|
||||
return `Неразпознат${issue.keys.length > 1 ? "и" : ""} ключ${issue.keys.length > 1 ? "ове" : ""}: ${util.joinValues(issue.keys, ", ")}`;
|
||||
case "invalid_key":
|
||||
return `Невалиден ключ в ${issue.origin}`;
|
||||
case "invalid_union":
|
||||
return "Невалиден вход";
|
||||
case "invalid_element":
|
||||
return `Невалидна стойност в ${issue.origin}`;
|
||||
default:
|
||||
return `Невалиден вход`;
|
||||
}
|
||||
};
|
||||
};
|
||||
function default_1() {
|
||||
return {
|
||||
localeError: error(),
|
||||
};
|
||||
}
|
||||
module.exports = exports.default;
|
||||
@@ -0,0 +1,5 @@
|
||||
var assertClassBrand = require("./assertClassBrand.js");
|
||||
function _classPrivateMethodGet(s, a, r) {
|
||||
return assertClassBrand(a, s), r;
|
||||
}
|
||||
module.exports = _classPrivateMethodGet, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
||||
@@ -0,0 +1,140 @@
|
||||
"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 (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = default_1;
|
||||
const util = __importStar(require("../core/util.cjs"));
|
||||
const error = () => {
|
||||
const Sizable = {
|
||||
string: { unit: "characters", verb: "to have" },
|
||||
file: { unit: "bytes", verb: "to have" },
|
||||
array: { unit: "items", verb: "to have" },
|
||||
set: { unit: "items", verb: "to have" },
|
||||
map: { unit: "entries", verb: "to have" },
|
||||
};
|
||||
function getSizing(origin) {
|
||||
return Sizable[origin] ?? null;
|
||||
}
|
||||
const FormatDictionary = {
|
||||
regex: "input",
|
||||
email: "email address",
|
||||
url: "URL",
|
||||
emoji: "emoji",
|
||||
uuid: "UUID",
|
||||
uuidv4: "UUIDv4",
|
||||
uuidv6: "UUIDv6",
|
||||
nanoid: "nanoid",
|
||||
guid: "GUID",
|
||||
cuid: "cuid",
|
||||
cuid2: "cuid2",
|
||||
ulid: "ULID",
|
||||
xid: "XID",
|
||||
ksuid: "KSUID",
|
||||
datetime: "ISO datetime",
|
||||
date: "ISO date",
|
||||
time: "ISO time",
|
||||
duration: "ISO duration",
|
||||
ipv4: "IPv4 address",
|
||||
ipv6: "IPv6 address",
|
||||
mac: "MAC address",
|
||||
cidrv4: "IPv4 range",
|
||||
cidrv6: "IPv6 range",
|
||||
base64: "base64-encoded string",
|
||||
base64url: "base64url-encoded string",
|
||||
json_string: "JSON string",
|
||||
e164: "E.164 number",
|
||||
jwt: "JWT",
|
||||
template_literal: "input",
|
||||
};
|
||||
// type names: missing keys = do not translate (use raw value via ?? fallback)
|
||||
const TypeDictionary = {
|
||||
// Compatibility: "nan" -> "NaN" for display
|
||||
nan: "NaN",
|
||||
// All other type names omitted - they fall back to raw values via ?? operator
|
||||
};
|
||||
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;
|
||||
return `Invalid input: expected ${expected}, received ${received}`;
|
||||
}
|
||||
case "invalid_value":
|
||||
if (issue.values.length === 1)
|
||||
return `Invalid input: expected ${util.stringifyPrimitive(issue.values[0])}`;
|
||||
return `Invalid option: expected one of ${util.joinValues(issue.values, "|")}`;
|
||||
case "too_big": {
|
||||
const adj = issue.inclusive ? "<=" : "<";
|
||||
const sizing = getSizing(issue.origin);
|
||||
if (sizing)
|
||||
return `Too big: expected ${issue.origin ?? "value"} to have ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elements"}`;
|
||||
return `Too big: expected ${issue.origin ?? "value"} to be ${adj}${issue.maximum.toString()}`;
|
||||
}
|
||||
case "too_small": {
|
||||
const adj = issue.inclusive ? ">=" : ">";
|
||||
const sizing = getSizing(issue.origin);
|
||||
if (sizing) {
|
||||
return `Too small: expected ${issue.origin} to have ${adj}${issue.minimum.toString()} ${sizing.unit}`;
|
||||
}
|
||||
return `Too small: expected ${issue.origin} to be ${adj}${issue.minimum.toString()}`;
|
||||
}
|
||||
case "invalid_format": {
|
||||
const _issue = issue;
|
||||
if (_issue.format === "starts_with") {
|
||||
return `Invalid string: must start with "${_issue.prefix}"`;
|
||||
}
|
||||
if (_issue.format === "ends_with")
|
||||
return `Invalid string: must end with "${_issue.suffix}"`;
|
||||
if (_issue.format === "includes")
|
||||
return `Invalid string: must include "${_issue.includes}"`;
|
||||
if (_issue.format === "regex")
|
||||
return `Invalid string: must match pattern ${_issue.pattern}`;
|
||||
return `Invalid ${FormatDictionary[_issue.format] ?? issue.format}`;
|
||||
}
|
||||
case "not_multiple_of":
|
||||
return `Invalid number: must be a multiple of ${issue.divisor}`;
|
||||
case "unrecognized_keys":
|
||||
return `Unrecognized key${issue.keys.length > 1 ? "s" : ""}: ${util.joinValues(issue.keys, ", ")}`;
|
||||
case "invalid_key":
|
||||
return `Invalid key in ${issue.origin}`;
|
||||
case "invalid_union":
|
||||
if (issue.options && Array.isArray(issue.options) && issue.options.length > 0) {
|
||||
const opts = issue.options.map((o) => `'${o}'`).join(" | ");
|
||||
return `Invalid discriminator value. Expected ${opts}`;
|
||||
}
|
||||
return "Invalid input";
|
||||
case "invalid_element":
|
||||
return `Invalid value in ${issue.origin}`;
|
||||
default:
|
||||
return `Invalid input`;
|
||||
}
|
||||
};
|
||||
};
|
||||
function default_1() {
|
||||
return {
|
||||
localeError: error(),
|
||||
};
|
||||
}
|
||||
module.exports = exports.default;
|
||||
@@ -0,0 +1,119 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const type_utils_1 = require("@typescript-eslint/type-utils");
|
||||
const utils_1 = require("@typescript-eslint/utils");
|
||||
const typescript_1 = require("typescript");
|
||||
const util_1 = require("../util");
|
||||
const testTypeFlag = (flagsToCheck) => type => (0, util_1.isTypeFlagSet)(type, flagsToCheck);
|
||||
const optionTesters = [
|
||||
['Any', util_1.isTypeAnyType],
|
||||
[
|
||||
'Array',
|
||||
(type, checker, recursivelyCheckType) => (checker.isArrayType(type) || checker.isTupleType(type)) &&
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
recursivelyCheckType(type.getNumberIndexType()),
|
||||
],
|
||||
// eslint-disable-next-line @typescript-eslint/internal/prefer-ast-types-enum
|
||||
['Boolean', testTypeFlag(typescript_1.TypeFlags.BooleanLike)],
|
||||
['Nullish', testTypeFlag(typescript_1.TypeFlags.Null | typescript_1.TypeFlags.Undefined)],
|
||||
['Number', testTypeFlag(typescript_1.TypeFlags.NumberLike | typescript_1.TypeFlags.BigIntLike)],
|
||||
[
|
||||
'RegExp',
|
||||
(type, checker) => (0, util_1.getTypeName)(checker, type) === 'RegExp',
|
||||
],
|
||||
['Never', util_1.isTypeNeverType],
|
||||
].map(([type, tester]) => ({
|
||||
type,
|
||||
option: `allow${type}`,
|
||||
tester,
|
||||
}));
|
||||
exports.default = (0, util_1.createRule)({
|
||||
name: 'restrict-template-expressions',
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'Enforce template literal expressions to be of `string` type',
|
||||
recommended: {
|
||||
recommended: true,
|
||||
strict: [
|
||||
{
|
||||
allowAny: false,
|
||||
allowBoolean: false,
|
||||
allowNever: false,
|
||||
allowNullish: false,
|
||||
allowNumber: false,
|
||||
allowRegExp: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
requiresTypeChecking: true,
|
||||
},
|
||||
messages: {
|
||||
invalidType: 'Invalid type "{{type}}" of template literal expression.',
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
type: 'object',
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
...Object.fromEntries(optionTesters.map(({ type, option }) => [
|
||||
option,
|
||||
{
|
||||
type: 'boolean',
|
||||
description: `Whether to allow \`${type.toLowerCase()}\` typed values in template expressions.`,
|
||||
},
|
||||
])),
|
||||
allow: {
|
||||
description: `Types to allow in template expressions.`,
|
||||
...type_utils_1.typeOrValueSpecifiersSchema,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
defaultOptions: [
|
||||
{
|
||||
allow: [{ name: ['Error', 'URL', 'URLSearchParams'], from: 'lib' }],
|
||||
allowAny: true,
|
||||
allowBoolean: true,
|
||||
allowNullish: true,
|
||||
allowNumber: true,
|
||||
allowRegExp: true,
|
||||
},
|
||||
],
|
||||
create(context, [{ allow, ...options }]) {
|
||||
const services = (0, util_1.getParserServices)(context);
|
||||
const { program } = services;
|
||||
const checker = program.getTypeChecker();
|
||||
const enabledOptionTesters = optionTesters.filter(({ option }) => options[option]);
|
||||
return {
|
||||
TemplateLiteral(node) {
|
||||
// don't check tagged template literals
|
||||
if (node.parent.type === utils_1.AST_NODE_TYPES.TaggedTemplateExpression) {
|
||||
return;
|
||||
}
|
||||
for (const expression of node.expressions) {
|
||||
const expressionType = (0, util_1.getConstrainedTypeAtLocation)(services, expression);
|
||||
if (!recursivelyCheckType(expressionType)) {
|
||||
context.report({
|
||||
node: expression,
|
||||
messageId: 'invalidType',
|
||||
data: { type: checker.typeToString(expressionType) },
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
function recursivelyCheckType(innerType) {
|
||||
if (innerType.isUnion()) {
|
||||
return innerType.types.every(recursivelyCheckType);
|
||||
}
|
||||
if (innerType.isIntersection()) {
|
||||
return innerType.types.some(recursivelyCheckType);
|
||||
}
|
||||
return ((0, util_1.isTypeFlagSet)(innerType, typescript_1.TypeFlags.StringLike) ||
|
||||
(0, util_1.matchesTypeOrBaseType)(services, type => (0, type_utils_1.typeMatchesSomeSpecifier)(type, allow, program), innerType) ||
|
||||
enabledOptionTesters.some(({ tester }) => tester(innerType, checker, recursivelyCheckType)));
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
/* eslint-disable no-eval */
|
||||
|
||||
eval(`
|
||||
const pino = require('../../../')
|
||||
|
||||
const logger = pino(
|
||||
pino.transport({
|
||||
target: 'pino/file'
|
||||
})
|
||||
)
|
||||
|
||||
logger.info('done!')
|
||||
`)
|
||||
@@ -0,0 +1,8 @@
|
||||
import _typeof from "./typeof.js";
|
||||
import assertThisInitialized from "./assertThisInitialized.js";
|
||||
function _possibleConstructorReturn(t, e) {
|
||||
if (e && ("object" == _typeof(e) || "function" == typeof e)) return e;
|
||||
if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
|
||||
return assertThisInitialized(t);
|
||||
}
|
||||
export { _possibleConstructorReturn as default };
|
||||
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
/* eslint-disable @typescript-eslint/no-namespace */
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
@@ -0,0 +1,12 @@
|
||||
export var ScriptKind;
|
||||
(function (ScriptKind) {
|
||||
ScriptKind[ScriptKind["Unknown"] = 0] = "Unknown";
|
||||
ScriptKind[ScriptKind["JS"] = 1] = "JS";
|
||||
ScriptKind[ScriptKind["JSX"] = 2] = "JSX";
|
||||
ScriptKind[ScriptKind["TS"] = 3] = "TS";
|
||||
ScriptKind[ScriptKind["TSX"] = 4] = "TSX";
|
||||
ScriptKind[ScriptKind["External"] = 5] = "External";
|
||||
ScriptKind[ScriptKind["JSON"] = 6] = "JSON";
|
||||
ScriptKind[ScriptKind["Deferred"] = 7] = "Deferred";
|
||||
})(ScriptKind || (ScriptKind = {}));
|
||||
//# sourceMappingURL=scriptKind.enum.js.map
|
||||
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getESLintCoreRule = void 0;
|
||||
exports.maybeGetESLintCoreRule = maybeGetESLintCoreRule;
|
||||
const utils_1 = require("@typescript-eslint/utils");
|
||||
const use_at_your_own_risk_1 = require("eslint/use-at-your-own-risk");
|
||||
const getESLintCoreRule = (ruleId) => utils_1.ESLintUtils.nullThrows(use_at_your_own_risk_1.builtinRules.get(ruleId), `ESLint's core rule '${ruleId}' not found.`);
|
||||
exports.getESLintCoreRule = getESLintCoreRule;
|
||||
function maybeGetESLintCoreRule(ruleId) {
|
||||
try {
|
||||
return (0, exports.getESLintCoreRule)(ruleId);
|
||||
}
|
||||
catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
# ModuleImporter
|
||||
|
||||
by [Nicholas C. Zakas](https://humanwhocodes.com)
|
||||
|
||||
If you find this useful, please consider supporting my work with a [donation](https://humanwhocodes.com/donate).
|
||||
|
||||
## Description
|
||||
|
||||
A utility for seamlessly importing modules in Node.js regardless if they are CommonJS or ESM format. Under the hood, this uses `import()` and relies on Node.js's CommonJS compatibility to work correctly. This ensures that the correct locations and formats are used for CommonJS so you can call one method and not worry about any compatibility issues.
|
||||
|
||||
The problem with the default `import()` is that it always resolves relative to the file location in which it is called. If you want to resolve from a different location, you need to jump through a few hoops to achieve that. This package makes it easy to both resolve and import modules from any directory.
|
||||
|
||||
## Usage
|
||||
|
||||
### Node.js
|
||||
|
||||
Install using [npm][npm] or [yarn][yarn]:
|
||||
|
||||
```
|
||||
npm install @humanwhocodes/module-importer
|
||||
|
||||
# or
|
||||
|
||||
yarn add @humanwhocodes/module-importer
|
||||
```
|
||||
|
||||
Import into your Node.js project:
|
||||
|
||||
```js
|
||||
// CommonJS
|
||||
const { ModuleImporter } = require("@humanwhocodes/module-importer");
|
||||
|
||||
// ESM
|
||||
import { ModuleImporter } from "@humanwhocodes/module-importer";
|
||||
```
|
||||
|
||||
### Bun
|
||||
|
||||
Install using this command:
|
||||
|
||||
```
|
||||
bun add @humanwhocodes/module-importer
|
||||
```
|
||||
|
||||
Import into your Bun project:
|
||||
|
||||
```js
|
||||
import { ModuleImporter } from "@humanwhocodes/module-importer";
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
After importing, create a new instance of `ModuleImporter` to start emitting events:
|
||||
|
||||
```js
|
||||
// cwd can be omitted to use process.cwd()
|
||||
const importer = new ModuleImporter(cwd);
|
||||
|
||||
// you can resolve the location of any package
|
||||
const location = importer.resolve("./some-file.cjs");
|
||||
|
||||
// you can also import directly
|
||||
const module = importer.import("./some-file.cjs");
|
||||
```
|
||||
|
||||
For both `resolve()` and `import()`, you can pass in package names and filenames.
|
||||
|
||||
## Developer Setup
|
||||
|
||||
1. Fork the repository
|
||||
2. Clone your fork
|
||||
3. Run `npm install` to setup dependencies
|
||||
4. Run `npm test` to run tests
|
||||
|
||||
## License
|
||||
|
||||
Apache 2.0
|
||||
|
||||
[npm]: https://npmjs.com/
|
||||
[yarn]: https://yarnpkg.com/
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
// THIS CODE WAS AUTOMATICALLY GENERATED
|
||||
// DO NOT EDIT THIS CODE BY HAND
|
||||
// RUN THE FOLLOWING COMMAND FROM THE WORKSPACE ROOT TO REGENERATE:
|
||||
// npx nx generate-lib repo
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.es2023_array = void 0;
|
||||
const base_config_1 = require("./base-config");
|
||||
exports.es2023_array = {
|
||||
libs: [],
|
||||
variables: [
|
||||
['Array', base_config_1.TYPE],
|
||||
['ReadonlyArray', base_config_1.TYPE],
|
||||
['Int8Array', base_config_1.TYPE],
|
||||
['Uint8Array', base_config_1.TYPE],
|
||||
['Uint8ClampedArray', base_config_1.TYPE],
|
||||
['Int16Array', base_config_1.TYPE],
|
||||
['Uint16Array', base_config_1.TYPE],
|
||||
['Int32Array', base_config_1.TYPE],
|
||||
['Uint32Array', base_config_1.TYPE],
|
||||
['Float32Array', base_config_1.TYPE],
|
||||
['Float64Array', base_config_1.TYPE],
|
||||
['BigInt64Array', base_config_1.TYPE],
|
||||
['BigUint64Array', base_config_1.TYPE],
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,97 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABLITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference no-default-lib="true"/>
|
||||
|
||||
interface Atomics {
|
||||
/**
|
||||
* Adds a value to the value at the given position in the array, returning the original value.
|
||||
* Until this atomic operation completes, any other read or write operation against the array
|
||||
* will block.
|
||||
*/
|
||||
add(typedArray: BigInt64Array | BigUint64Array, index: number, value: bigint): bigint;
|
||||
|
||||
/**
|
||||
* Stores the bitwise AND of a value with the value at the given position in the array,
|
||||
* returning the original value. Until this atomic operation completes, any other read or
|
||||
* write operation against the array will block.
|
||||
*/
|
||||
and(typedArray: BigInt64Array | BigUint64Array, index: number, value: bigint): bigint;
|
||||
|
||||
/**
|
||||
* Replaces the value at the given position in the array if the original value equals the given
|
||||
* expected value, returning the original value. Until this atomic operation completes, any
|
||||
* other read or write operation against the array will block.
|
||||
*/
|
||||
compareExchange(typedArray: BigInt64Array | BigUint64Array, index: number, expectedValue: bigint, replacementValue: bigint): bigint;
|
||||
|
||||
/**
|
||||
* Replaces the value at the given position in the array, returning the original value. Until
|
||||
* this atomic operation completes, any other read or write operation against the array will
|
||||
* block.
|
||||
*/
|
||||
exchange(typedArray: BigInt64Array | BigUint64Array, index: number, value: bigint): bigint;
|
||||
|
||||
/**
|
||||
* Returns the value at the given position in the array. Until this atomic operation completes,
|
||||
* any other read or write operation against the array will block.
|
||||
*/
|
||||
load(typedArray: BigInt64Array | BigUint64Array, index: number): bigint;
|
||||
|
||||
/**
|
||||
* Stores the bitwise OR of a value with the value at the given position in the array,
|
||||
* returning the original value. Until this atomic operation completes, any other read or write
|
||||
* operation against the array will block.
|
||||
*/
|
||||
or(typedArray: BigInt64Array | BigUint64Array, index: number, value: bigint): bigint;
|
||||
|
||||
/**
|
||||
* Stores a value at the given position in the array, returning the new value. Until this
|
||||
* atomic operation completes, any other read or write operation against the array will block.
|
||||
*/
|
||||
store(typedArray: BigInt64Array | BigUint64Array, index: number, value: bigint): bigint;
|
||||
|
||||
/**
|
||||
* Subtracts a value from the value at the given position in the array, returning the original
|
||||
* value. Until this atomic operation completes, any other read or write operation against the
|
||||
* array will block.
|
||||
*/
|
||||
sub(typedArray: BigInt64Array | BigUint64Array, index: number, value: bigint): bigint;
|
||||
|
||||
/**
|
||||
* If the value at the given position in the array is equal to the provided value, the current
|
||||
* agent is put to sleep causing execution to suspend until the timeout expires (returning
|
||||
* `"timed-out"`) or until the agent is awoken (returning `"ok"`); otherwise, returns
|
||||
* `"not-equal"`.
|
||||
*/
|
||||
wait(typedArray: BigInt64Array, index: number, value: bigint, timeout?: number): "ok" | "not-equal" | "timed-out";
|
||||
|
||||
/**
|
||||
* Wakes up sleeping agents that are waiting on the given index of the array, returning the
|
||||
* number of agents that were awoken.
|
||||
* @param typedArray A shared BigInt64Array.
|
||||
* @param index The position in the typedArray to wake up on.
|
||||
* @param count The number of sleeping agents to notify. Defaults to +Infinity.
|
||||
*/
|
||||
notify(typedArray: BigInt64Array, index: number, count?: number): number;
|
||||
|
||||
/**
|
||||
* Stores the bitwise XOR of a value with the value at the given position in the array,
|
||||
* returning the original value. Until this atomic operation completes, any other read or write
|
||||
* operation against the array will block.
|
||||
*/
|
||||
xor(typedArray: BigInt64Array | BigUint64Array, index: number, value: bigint): bigint;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"nodeBuilderFlags.js","sourceRoot":"","sources":["../../src/enums/nodeBuilderFlags.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,MAAM,CAAC,IAAI,gBAAqB,CAAC;AACjC,CAAC,UAAU,gBAAgB;IACvB,gBAAgB,CAAC,gBAAgB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC;IACxD,gBAAgB,CAAC,gBAAgB,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,GAAG,cAAc,CAAC;IACxE,gBAAgB,CAAC,gBAAgB,CAAC,yBAAyB,CAAC,GAAG,CAAC,CAAC,GAAG,yBAAyB,CAAC;IAC9F,gBAAgB,CAAC,gBAAgB,CAAC,oCAAoC,CAAC,GAAG,CAAC,CAAC,GAAG,oCAAoC,CAAC;IACpH,gBAAgB,CAAC,gBAAgB,CAAC,uBAAuB,CAAC,GAAG,CAAC,CAAC,GAAG,uBAAuB,CAAC;IAC1F,gBAAgB,CAAC,gBAAgB,CAAC,qCAAqC,CAAC,GAAG,EAAE,CAAC,GAAG,qCAAqC,CAAC;IACvH,gBAAgB,CAAC,gBAAgB,CAAC,+BAA+B,CAAC,GAAG,EAAE,CAAC,GAAG,+BAA+B,CAAC;IAC3G,gBAAgB,CAAC,gBAAgB,CAAC,uBAAuB,CAAC,GAAG,EAAE,CAAC,GAAG,uBAAuB,CAAC;IAC3F,gBAAgB,CAAC,gBAAgB,CAAC,yBAAyB,CAAC,GAAG,GAAG,CAAC,GAAG,yBAAyB,CAAC;IAChG,gBAAgB,CAAC,gBAAgB,CAAC,uBAAuB,CAAC,GAAG,GAAG,CAAC,GAAG,uBAAuB,CAAC;IAC5F,gBAAgB,CAAC,gBAAgB,CAAC,oCAAoC,CAAC,GAAG,GAAG,CAAC,GAAG,oCAAoC,CAAC;IACtH,gBAAgB,CAAC,gBAAgB,CAAC,yBAAyB,CAAC,GAAG,IAAI,CAAC,GAAG,yBAAyB,CAAC;IACjG,gBAAgB,CAAC,gBAAgB,CAAC,mCAAmC,CAAC,GAAG,IAAI,CAAC,GAAG,mCAAmC,CAAC;IACrH,gBAAgB,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,GAAG,IAAI,CAAC,GAAG,mBAAmB,CAAC;IACrF,gBAAgB,CAAC,gBAAgB,CAAC,wBAAwB,CAAC,GAAG,IAAI,CAAC,GAAG,wBAAwB,CAAC;IAC/F,gBAAgB,CAAC,gBAAgB,CAAC,oCAAoC,CAAC,GAAG,KAAK,CAAC,GAAG,oCAAoC,CAAC;IACxH,gBAAgB,CAAC,gBAAgB,CAAC,qCAAqC,CAAC,GAAG,SAAS,CAAC,GAAG,qCAAqC,CAAC;IAC9H,gBAAgB,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,GAAG,SAAS,CAAC,GAAG,iBAAiB,CAAC;IACtF,gBAAgB,CAAC,gBAAgB,CAAC,6BAA6B,CAAC,GAAG,UAAU,CAAC,GAAG,6BAA6B,CAAC;IAC/G,gBAAgB,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,GAAG,QAAQ,CAAC,GAAG,mBAAmB,CAAC;IACzF,gBAAgB,CAAC,gBAAgB,CAAC,yBAAyB,CAAC,GAAG,SAAS,CAAC,GAAG,yBAAyB,CAAC;IACtG,gBAAgB,CAAC,gBAAgB,CAAC,0BAA0B,CAAC,GAAG,KAAK,CAAC,GAAG,0BAA0B,CAAC;IACpG,gBAAgB,CAAC,gBAAgB,CAAC,uCAAuC,CAAC,GAAG,KAAK,CAAC,GAAG,uCAAuC,CAAC;IAC9H,gBAAgB,CAAC,gBAAgB,CAAC,0BAA0B,CAAC,GAAG,MAAM,CAAC,GAAG,0BAA0B,CAAC;IACrG,gBAAgB,CAAC,gBAAgB,CAAC,+BAA+B,CAAC,GAAG,MAAM,CAAC,GAAG,+BAA+B,CAAC;IAC/G,gBAAgB,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,GAAG,MAAM,CAAC,GAAG,iBAAiB,CAAC;IACnF,gBAAgB,CAAC,gBAAgB,CAAC,yBAAyB,CAAC,GAAG,OAAO,CAAC,GAAG,yBAAyB,CAAC;IACpG,gBAAgB,CAAC,gBAAgB,CAAC,yBAAyB,CAAC,GAAG,OAAO,CAAC,GAAG,yBAAyB,CAAC;IACpG,gBAAgB,CAAC,gBAAgB,CAAC,+BAA+B,CAAC,GAAG,QAAQ,CAAC,GAAG,+BAA+B,CAAC;IACjH,gBAAgB,CAAC,gBAAgB,CAAC,cAAc,CAAC,GAAG,QAAQ,CAAC,GAAG,cAAc,CAAC;IAC/E,gBAAgB,CAAC,gBAAgB,CAAC,qBAAqB,CAAC,GAAG,OAAO,CAAC,GAAG,qBAAqB,CAAC;IAC5F,gBAAgB,CAAC,gBAAgB,CAAC,aAAa,CAAC,GAAG,OAAO,CAAC,GAAG,aAAa,CAAC;IAC5E,gBAAgB,CAAC,gBAAgB,CAAC,qBAAqB,CAAC,GAAG,QAAQ,CAAC,GAAG,qBAAqB,CAAC;AACjG,CAAC,CAAC,CAAC,gBAAgB,IAAI,CAAC,gBAAgB,GAAG,EAAE,CAAC,CAAC,CAAC"}
|
||||
@@ -0,0 +1,200 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert')
|
||||
const { test } = require('node:test')
|
||||
const serializer = require('../lib/err')
|
||||
const { wrapErrorSerializer } = require('../')
|
||||
|
||||
test('serializes Error objects', () => {
|
||||
const serialized = serializer(Error('foo'))
|
||||
assert.strictEqual(serialized.type, 'Error')
|
||||
assert.strictEqual(serialized.message, 'foo')
|
||||
assert.match(serialized.stack, /err\.test\.js:/)
|
||||
})
|
||||
|
||||
test('serializes Error objects with extra properties', () => {
|
||||
const err = Error('foo')
|
||||
err.statusCode = 500
|
||||
const serialized = serializer(err)
|
||||
assert.strictEqual(serialized.type, 'Error')
|
||||
assert.strictEqual(serialized.message, 'foo')
|
||||
assert.ok(serialized.statusCode)
|
||||
assert.strictEqual(serialized.statusCode, 500)
|
||||
assert.match(serialized.stack, /err\.test\.js:/)
|
||||
})
|
||||
|
||||
test('serializes Error objects with subclass "type"', () => {
|
||||
class MyError extends Error {}
|
||||
const err = new MyError('foo')
|
||||
const serialized = serializer(err)
|
||||
assert.strictEqual(serialized.type, 'MyError')
|
||||
})
|
||||
|
||||
test('serializes nested errors', () => {
|
||||
const err = Error('foo')
|
||||
err.inner = Error('bar')
|
||||
const serialized = serializer(err)
|
||||
assert.strictEqual(serialized.type, 'Error')
|
||||
assert.strictEqual(serialized.message, 'foo')
|
||||
assert.match(serialized.stack, /err\.test\.js:/)
|
||||
assert.strictEqual(serialized.inner.type, 'Error')
|
||||
assert.strictEqual(serialized.inner.message, 'bar')
|
||||
assert.match(serialized.inner.stack, /Error: bar/)
|
||||
assert.match(serialized.inner.stack, /err\.test\.js:/)
|
||||
})
|
||||
|
||||
test('serializes error causes', () => {
|
||||
for (const cause of [
|
||||
Error('bar'),
|
||||
{ message: 'bar', stack: 'Error: bar: err.test.js:' }
|
||||
]) {
|
||||
const err = Error('foo')
|
||||
err.cause = cause
|
||||
err.cause.cause = Error('abc')
|
||||
const serialized = serializer(err)
|
||||
assert.strictEqual(serialized.type, 'Error')
|
||||
assert.strictEqual(serialized.message, 'foo: bar: abc')
|
||||
assert.match(serialized.stack, /err\.test\.js:/)
|
||||
assert.match(serialized.stack, /Error: foo/)
|
||||
assert.match(serialized.stack, /Error: bar/)
|
||||
assert.match(serialized.stack, /Error: abc/)
|
||||
assert.ok(!serialized.cause)
|
||||
}
|
||||
})
|
||||
|
||||
test('serializes error causes with VError support', function (t) {
|
||||
// Fake VError-style setup
|
||||
const err = Error('foo: bar')
|
||||
err.foo = 'abc'
|
||||
err.cause = function () {
|
||||
const err = Error('bar')
|
||||
err.cause = Error(this.foo)
|
||||
return err
|
||||
}
|
||||
const serialized = serializer(err)
|
||||
assert.strictEqual(serialized.type, 'Error')
|
||||
assert.strictEqual(serialized.message, 'foo: bar: abc')
|
||||
assert.match(serialized.stack, /err\.test\.js:/)
|
||||
assert.match(serialized.stack, /Error: foo/)
|
||||
assert.match(serialized.stack, /Error: bar/)
|
||||
assert.match(serialized.stack, /Error: abc/)
|
||||
})
|
||||
|
||||
test('keeps non-error cause', () => {
|
||||
const err = Error('foo')
|
||||
err.cause = 'abc'
|
||||
const serialized = serializer(err)
|
||||
assert.strictEqual(serialized.type, 'Error')
|
||||
assert.strictEqual(serialized.message, 'foo')
|
||||
assert.strictEqual(serialized.cause, 'abc')
|
||||
})
|
||||
|
||||
test('prevents infinite recursion', () => {
|
||||
const err = Error('foo')
|
||||
err.inner = err
|
||||
const serialized = serializer(err)
|
||||
assert.strictEqual(serialized.type, 'Error')
|
||||
assert.strictEqual(serialized.message, 'foo')
|
||||
assert.match(serialized.stack, /err\.test\.js:/)
|
||||
assert.ok(!serialized.inner)
|
||||
})
|
||||
|
||||
test('cleans up infinite recursion tracking', () => {
|
||||
const err = Error('foo')
|
||||
const bar = Error('bar')
|
||||
err.inner = bar
|
||||
bar.inner = err
|
||||
|
||||
serializer(err)
|
||||
const serialized = serializer(err)
|
||||
|
||||
assert.strictEqual(serialized.type, 'Error')
|
||||
assert.strictEqual(serialized.message, 'foo')
|
||||
assert.match(serialized.stack, /err\.test\.js:/)
|
||||
assert.ok(serialized.inner)
|
||||
assert.strictEqual(serialized.inner.type, 'Error')
|
||||
assert.strictEqual(serialized.inner.message, 'bar')
|
||||
assert.match(serialized.inner.stack, /Error: bar/)
|
||||
assert.ok(!serialized.inner.inner)
|
||||
})
|
||||
|
||||
test('err.raw is available', () => {
|
||||
const err = Error('foo')
|
||||
const serialized = serializer(err)
|
||||
assert.strictEqual(serialized.raw, err)
|
||||
})
|
||||
|
||||
test('redefined err.constructor doesnt crash serializer', () => {
|
||||
function check (a, name) {
|
||||
assert.strictEqual(a.type, name)
|
||||
assert.strictEqual(a.message, 'foo')
|
||||
}
|
||||
|
||||
const err1 = TypeError('foo')
|
||||
err1.constructor = '10'
|
||||
|
||||
const err2 = TypeError('foo')
|
||||
err2.constructor = undefined
|
||||
|
||||
const err3 = Error('foo')
|
||||
err3.constructor = null
|
||||
|
||||
const err4 = Error('foo')
|
||||
err4.constructor = 10
|
||||
|
||||
class MyError extends Error {}
|
||||
const err5 = new MyError('foo')
|
||||
err5.constructor = undefined
|
||||
|
||||
check(serializer(err1), 'TypeError')
|
||||
check(serializer(err2), 'TypeError')
|
||||
check(serializer(err3), 'Error')
|
||||
check(serializer(err4), 'Error')
|
||||
// We do not expect 'MyError' because err5.constructor has been blown away.
|
||||
// `err5.name` is 'Error' from the base class prototype.
|
||||
check(serializer(err5), 'Error')
|
||||
})
|
||||
|
||||
test('pass through anything that does not look like an Error', () => {
|
||||
function check (a) {
|
||||
assert.strictEqual(serializer(a), a)
|
||||
}
|
||||
|
||||
check('foo')
|
||||
check({ hello: 'world' })
|
||||
check([1, 2])
|
||||
})
|
||||
|
||||
test('can wrap err serializers', () => {
|
||||
const err = Error('foo')
|
||||
err.foo = 'foo'
|
||||
const serializer = wrapErrorSerializer(function (err) {
|
||||
delete err.foo
|
||||
err.bar = 'bar'
|
||||
return err
|
||||
})
|
||||
const serialized = serializer(err)
|
||||
assert.strictEqual(serialized.type, 'Error')
|
||||
assert.strictEqual(serialized.message, 'foo')
|
||||
assert.match(serialized.stack, /err\.test\.js:/)
|
||||
assert.ok(!serialized.foo)
|
||||
assert.strictEqual(serialized.bar, 'bar')
|
||||
})
|
||||
|
||||
test('serializes aggregate errors', { skip: !global.AggregateError }, () => {
|
||||
const foo = new Error('foo')
|
||||
const bar = new Error('bar')
|
||||
for (const aggregate of [
|
||||
new AggregateError([foo, bar], 'aggregated message'),
|
||||
{ errors: [foo, bar], message: 'aggregated message', stack: 'err.test.js:' }
|
||||
]) {
|
||||
const serialized = serializer(aggregate)
|
||||
assert.strictEqual(serialized.message, 'aggregated message')
|
||||
assert.strictEqual(serialized.aggregateErrors.length, 2)
|
||||
assert.strictEqual(serialized.aggregateErrors[0].message, 'foo')
|
||||
assert.strictEqual(serialized.aggregateErrors[1].message, 'bar')
|
||||
assert.match(serialized.aggregateErrors[0].stack, /^Error: foo/)
|
||||
assert.match(serialized.aggregateErrors[1].stack, /^Error: bar/)
|
||||
assert.match(serialized.stack, /err\.test\.js:/)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,290 @@
|
||||
declare module 'net' {
|
||||
import * as stream from 'stream';
|
||||
import EventEmitter = require('events');
|
||||
import * as dns from 'dns';
|
||||
|
||||
type LookupFunction = (
|
||||
hostname: string,
|
||||
options: dns.LookupOneOptions,
|
||||
callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void,
|
||||
) => void;
|
||||
|
||||
interface AddressInfo {
|
||||
address: string;
|
||||
family: string;
|
||||
port: number;
|
||||
}
|
||||
|
||||
interface SocketConstructorOpts {
|
||||
fd?: number | undefined;
|
||||
allowHalfOpen?: boolean | undefined;
|
||||
readable?: boolean | undefined;
|
||||
writable?: boolean | undefined;
|
||||
}
|
||||
|
||||
interface OnReadOpts {
|
||||
buffer: Uint8Array | (() => Uint8Array);
|
||||
/**
|
||||
* This function is called for every chunk of incoming data.
|
||||
* Two arguments are passed to it: the number of bytes written to buffer and a reference to buffer.
|
||||
* Return false from this function to implicitly pause() the socket.
|
||||
*/
|
||||
callback(bytesWritten: number, buf: Uint8Array): boolean;
|
||||
}
|
||||
|
||||
interface ConnectOpts {
|
||||
/**
|
||||
* If specified, incoming data is stored in a single buffer and passed to the supplied callback when data arrives on the socket.
|
||||
* Note: this will cause the streaming functionality to not provide any data, however events like 'error', 'end', and 'close' will
|
||||
* still be emitted as normal and methods like pause() and resume() will also behave as expected.
|
||||
*/
|
||||
onread?: OnReadOpts | undefined;
|
||||
}
|
||||
|
||||
interface TcpSocketConnectOpts extends ConnectOpts {
|
||||
port: number;
|
||||
host?: string | undefined;
|
||||
localAddress?: string | undefined;
|
||||
localPort?: number | undefined;
|
||||
hints?: number | undefined;
|
||||
family?: number | undefined;
|
||||
lookup?: LookupFunction | undefined;
|
||||
}
|
||||
|
||||
interface IpcSocketConnectOpts extends ConnectOpts {
|
||||
path: string;
|
||||
}
|
||||
|
||||
type SocketConnectOpts = TcpSocketConnectOpts | IpcSocketConnectOpts;
|
||||
type SocketReadyState = 'opening' | 'open' | 'readOnly' | 'writeOnly' | 'closed';
|
||||
|
||||
class Socket extends stream.Duplex {
|
||||
constructor(options?: SocketConstructorOpts);
|
||||
|
||||
// Extended base methods
|
||||
write(buffer: Uint8Array | string, cb?: (err?: Error) => void): boolean;
|
||||
write(str: Uint8Array | string, encoding?: string, cb?: (err?: Error) => void): boolean;
|
||||
|
||||
connect(options: SocketConnectOpts, connectionListener?: () => void): this;
|
||||
connect(port: number, host: string, connectionListener?: () => void): this;
|
||||
connect(port: number, connectionListener?: () => void): this;
|
||||
connect(path: string, connectionListener?: () => void): this;
|
||||
|
||||
setEncoding(encoding?: string): this;
|
||||
pause(): this;
|
||||
resume(): this;
|
||||
setTimeout(timeout: number, callback?: () => void): this;
|
||||
setNoDelay(noDelay?: boolean): this;
|
||||
setKeepAlive(enable?: boolean, initialDelay?: number): this;
|
||||
address(): AddressInfo | string;
|
||||
unref(): void;
|
||||
ref(): void;
|
||||
|
||||
readonly bufferSize: number;
|
||||
readonly bytesRead: number;
|
||||
readonly bytesWritten: number;
|
||||
readonly connecting: boolean;
|
||||
readonly destroyed: boolean;
|
||||
readonly localAddress: string;
|
||||
readonly localPort: number;
|
||||
/**
|
||||
* This property represents the state of the connection as a string.
|
||||
* @see {https://nodejs.org/api/net.html#socketreadystate}
|
||||
* @since v0.5.0
|
||||
*/
|
||||
readonly readyState: SocketReadyState;
|
||||
readonly remoteAddress?: string | undefined;
|
||||
readonly remoteFamily?: string | undefined;
|
||||
readonly remotePort?: number | undefined;
|
||||
/**
|
||||
* The socket timeout in milliseconds as set by socket.setTimeout(). It is undefined if a timeout has not been set.
|
||||
* @since v10.7.0
|
||||
*/
|
||||
readonly timeout?: number | undefined;
|
||||
|
||||
// Extended base methods
|
||||
end(cb?: () => void): this;
|
||||
end(buffer: Uint8Array | string, cb?: () => void): this;
|
||||
end(str: Uint8Array | string, encoding?: string, cb?: () => void): this;
|
||||
|
||||
/**
|
||||
* events.EventEmitter
|
||||
* 1. close
|
||||
* 2. connect
|
||||
* 3. data
|
||||
* 4. drain
|
||||
* 5. end
|
||||
* 6. error
|
||||
* 7. lookup
|
||||
* 8. timeout
|
||||
*/
|
||||
addListener(event: string, listener: (...args: any[]) => void): this;
|
||||
addListener(event: "close", listener: (had_error: boolean) => void): this;
|
||||
addListener(event: "connect", listener: () => void): this;
|
||||
addListener(event: "data", listener: (data: Buffer) => void): this;
|
||||
addListener(event: "drain", listener: () => void): this;
|
||||
addListener(event: "end", listener: () => void): this;
|
||||
addListener(event: "error", listener: (err: Error) => void): this;
|
||||
addListener(event: "lookup", listener: (err: Error, address: string, family: string | number, host: string) => void): this;
|
||||
addListener(event: "ready", listener: () => void): this;
|
||||
addListener(event: "timeout", listener: () => void): this;
|
||||
|
||||
emit(event: string | symbol, ...args: any[]): boolean;
|
||||
emit(event: "close", had_error: boolean): boolean;
|
||||
emit(event: "connect"): boolean;
|
||||
emit(event: "data", data: Buffer): boolean;
|
||||
emit(event: "drain"): boolean;
|
||||
emit(event: "end"): boolean;
|
||||
emit(event: "error", err: Error): boolean;
|
||||
emit(event: "lookup", err: Error, address: string, family: string | number, host: string): boolean;
|
||||
emit(event: "ready"): boolean;
|
||||
emit(event: "timeout"): boolean;
|
||||
|
||||
on(event: string, listener: (...args: any[]) => void): this;
|
||||
on(event: "close", listener: (had_error: boolean) => void): this;
|
||||
on(event: "connect", listener: () => void): this;
|
||||
on(event: "data", listener: (data: Buffer) => void): this;
|
||||
on(event: "drain", listener: () => void): this;
|
||||
on(event: "end", listener: () => void): this;
|
||||
on(event: "error", listener: (err: Error) => void): this;
|
||||
on(event: "lookup", listener: (err: Error, address: string, family: string | number, host: string) => void): this;
|
||||
on(event: "ready", listener: () => void): this;
|
||||
on(event: "timeout", listener: () => void): this;
|
||||
|
||||
once(event: string, listener: (...args: any[]) => void): this;
|
||||
once(event: "close", listener: (had_error: boolean) => void): this;
|
||||
once(event: "connect", listener: () => void): this;
|
||||
once(event: "data", listener: (data: Buffer) => void): this;
|
||||
once(event: "drain", listener: () => void): this;
|
||||
once(event: "end", listener: () => void): this;
|
||||
once(event: "error", listener: (err: Error) => void): this;
|
||||
once(event: "lookup", listener: (err: Error, address: string, family: string | number, host: string) => void): this;
|
||||
once(event: "ready", listener: () => void): this;
|
||||
once(event: "timeout", listener: () => void): this;
|
||||
|
||||
prependListener(event: string, listener: (...args: any[]) => void): this;
|
||||
prependListener(event: "close", listener: (had_error: boolean) => void): this;
|
||||
prependListener(event: "connect", listener: () => void): this;
|
||||
prependListener(event: "data", listener: (data: Buffer) => void): this;
|
||||
prependListener(event: "drain", listener: () => void): this;
|
||||
prependListener(event: "end", listener: () => void): this;
|
||||
prependListener(event: "error", listener: (err: Error) => void): this;
|
||||
prependListener(event: "lookup", listener: (err: Error, address: string, family: string | number, host: string) => void): this;
|
||||
prependListener(event: "ready", listener: () => void): this;
|
||||
prependListener(event: "timeout", listener: () => void): this;
|
||||
|
||||
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
||||
prependOnceListener(event: "close", listener: (had_error: boolean) => void): this;
|
||||
prependOnceListener(event: "connect", listener: () => void): this;
|
||||
prependOnceListener(event: "data", listener: (data: Buffer) => void): this;
|
||||
prependOnceListener(event: "drain", listener: () => void): this;
|
||||
prependOnceListener(event: "end", listener: () => void): this;
|
||||
prependOnceListener(event: "error", listener: (err: Error) => void): this;
|
||||
prependOnceListener(event: "lookup", listener: (err: Error, address: string, family: string | number, host: string) => void): this;
|
||||
prependOnceListener(event: "ready", listener: () => void): this;
|
||||
prependOnceListener(event: "timeout", listener: () => void): this;
|
||||
}
|
||||
|
||||
interface ListenOptions {
|
||||
port?: number | undefined;
|
||||
host?: string | undefined;
|
||||
backlog?: number | undefined;
|
||||
path?: string | undefined;
|
||||
exclusive?: boolean | undefined;
|
||||
readableAll?: boolean | undefined;
|
||||
writableAll?: boolean | undefined;
|
||||
/**
|
||||
* @default false
|
||||
*/
|
||||
ipv6Only?: boolean | undefined;
|
||||
}
|
||||
|
||||
// https://github.com/nodejs/node/blob/master/lib/net.js
|
||||
class Server extends EventEmitter {
|
||||
constructor(connectionListener?: (socket: Socket) => void);
|
||||
constructor(options?: { allowHalfOpen?: boolean | undefined, pauseOnConnect?: boolean | undefined }, connectionListener?: (socket: Socket) => void);
|
||||
|
||||
listen(port?: number, hostname?: string, backlog?: number, listeningListener?: () => void): this;
|
||||
listen(port?: number, hostname?: string, listeningListener?: () => void): this;
|
||||
listen(port?: number, backlog?: number, listeningListener?: () => void): this;
|
||||
listen(port?: number, listeningListener?: () => void): this;
|
||||
listen(path: string, backlog?: number, listeningListener?: () => void): this;
|
||||
listen(path: string, listeningListener?: () => void): this;
|
||||
listen(options: ListenOptions, listeningListener?: () => void): this;
|
||||
listen(handle: any, backlog?: number, listeningListener?: () => void): this;
|
||||
listen(handle: any, listeningListener?: () => void): this;
|
||||
close(callback?: (err?: Error) => void): this;
|
||||
address(): AddressInfo | string | null;
|
||||
getConnections(cb: (error: Error | null, count: number) => void): void;
|
||||
ref(): this;
|
||||
unref(): this;
|
||||
maxConnections: number;
|
||||
connections: number;
|
||||
listening: boolean;
|
||||
|
||||
/**
|
||||
* events.EventEmitter
|
||||
* 1. close
|
||||
* 2. connection
|
||||
* 3. error
|
||||
* 4. listening
|
||||
*/
|
||||
addListener(event: string, listener: (...args: any[]) => void): this;
|
||||
addListener(event: "close", listener: () => void): this;
|
||||
addListener(event: "connection", listener: (socket: Socket) => void): this;
|
||||
addListener(event: "error", listener: (err: Error) => void): this;
|
||||
addListener(event: "listening", listener: () => void): this;
|
||||
|
||||
emit(event: string | symbol, ...args: any[]): boolean;
|
||||
emit(event: "close"): boolean;
|
||||
emit(event: "connection", socket: Socket): boolean;
|
||||
emit(event: "error", err: Error): boolean;
|
||||
emit(event: "listening"): boolean;
|
||||
|
||||
on(event: string, listener: (...args: any[]) => void): this;
|
||||
on(event: "close", listener: () => void): this;
|
||||
on(event: "connection", listener: (socket: Socket) => void): this;
|
||||
on(event: "error", listener: (err: Error) => void): this;
|
||||
on(event: "listening", listener: () => void): this;
|
||||
|
||||
once(event: string, listener: (...args: any[]) => void): this;
|
||||
once(event: "close", listener: () => void): this;
|
||||
once(event: "connection", listener: (socket: Socket) => void): this;
|
||||
once(event: "error", listener: (err: Error) => void): this;
|
||||
once(event: "listening", listener: () => void): this;
|
||||
|
||||
prependListener(event: string, listener: (...args: any[]) => void): this;
|
||||
prependListener(event: "close", listener: () => void): this;
|
||||
prependListener(event: "connection", listener: (socket: Socket) => void): this;
|
||||
prependListener(event: "error", listener: (err: Error) => void): this;
|
||||
prependListener(event: "listening", listener: () => void): this;
|
||||
|
||||
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
||||
prependOnceListener(event: "close", listener: () => void): this;
|
||||
prependOnceListener(event: "connection", listener: (socket: Socket) => void): this;
|
||||
prependOnceListener(event: "error", listener: (err: Error) => void): this;
|
||||
prependOnceListener(event: "listening", listener: () => void): this;
|
||||
}
|
||||
|
||||
interface TcpNetConnectOpts extends TcpSocketConnectOpts, SocketConstructorOpts {
|
||||
timeout?: number | undefined;
|
||||
}
|
||||
|
||||
interface IpcNetConnectOpts extends IpcSocketConnectOpts, SocketConstructorOpts {
|
||||
timeout?: number | undefined;
|
||||
}
|
||||
|
||||
type NetConnectOpts = TcpNetConnectOpts | IpcNetConnectOpts;
|
||||
|
||||
function createServer(connectionListener?: (socket: Socket) => void): Server;
|
||||
function createServer(options?: { allowHalfOpen?: boolean | undefined, pauseOnConnect?: boolean | undefined }, connectionListener?: (socket: Socket) => void): Server;
|
||||
function connect(options: NetConnectOpts, connectionListener?: () => void): Socket;
|
||||
function connect(port: number, host?: string, connectionListener?: () => void): Socket;
|
||||
function connect(path: string, connectionListener?: () => void): Socket;
|
||||
function createConnection(options: NetConnectOpts, connectionListener?: () => void): Socket;
|
||||
function createConnection(port: number, host?: string, connectionListener?: () => void): Socket;
|
||||
function createConnection(path: string, connectionListener?: () => void): Socket;
|
||||
function isIP(input: string): number;
|
||||
function isIPv4(input: string): boolean;
|
||||
function isIPv6(input: string): boolean;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FlatESLint = void 0;
|
||||
/* eslint-disable @typescript-eslint/no-namespace */
|
||||
const eslint_1 = require("eslint");
|
||||
const use_at_your_own_risk_1 = __importDefault(require("eslint/use-at-your-own-risk"));
|
||||
/**
|
||||
* The ESLint class is the primary class to use in Node.js applications.
|
||||
* This class depends on the Node.js fs module and the file system, so you cannot use it in browsers.
|
||||
*
|
||||
* If you want to lint code on browsers, use the Linter class instead.
|
||||
*/
|
||||
class FlatESLint extends (use_at_your_own_risk_1.default.FlatESLint ??
|
||||
eslint_1.ESLint) {
|
||||
}
|
||||
exports.FlatESLint = FlatESLint;
|
||||
@@ -0,0 +1,62 @@
|
||||
'use strict'
|
||||
|
||||
const SemVer = require('../classes/semver')
|
||||
const parse = require('./parse')
|
||||
const { safeRe: re, t } = require('../internal/re')
|
||||
|
||||
const coerce = (version, options) => {
|
||||
if (version instanceof SemVer) {
|
||||
return version
|
||||
}
|
||||
|
||||
if (typeof version === 'number') {
|
||||
version = String(version)
|
||||
}
|
||||
|
||||
if (typeof version !== 'string') {
|
||||
return null
|
||||
}
|
||||
|
||||
options = options || {}
|
||||
|
||||
let match = null
|
||||
if (!options.rtl) {
|
||||
match = version.match(options.includePrerelease ? re[t.COERCEFULL] : re[t.COERCE])
|
||||
} else {
|
||||
// Find the right-most coercible string that does not share
|
||||
// a terminus with a more left-ward coercible string.
|
||||
// Eg, '1.2.3.4' wants to coerce '2.3.4', not '3.4' or '4'
|
||||
// With includePrerelease option set, '1.2.3.4-rc' wants to coerce '2.3.4-rc', not '2.3.4'
|
||||
//
|
||||
// Walk through the string checking with a /g regexp
|
||||
// Manually set the index so as to pick up overlapping matches.
|
||||
// Stop when we get a match that ends at the string end, since no
|
||||
// coercible string can be more right-ward without the same terminus.
|
||||
const coerceRtlRegex = options.includePrerelease ? re[t.COERCERTLFULL] : re[t.COERCERTL]
|
||||
let next
|
||||
while ((next = coerceRtlRegex.exec(version)) &&
|
||||
(!match || match.index + match[0].length !== version.length)
|
||||
) {
|
||||
if (!match ||
|
||||
next.index + next[0].length !== match.index + match[0].length) {
|
||||
match = next
|
||||
}
|
||||
coerceRtlRegex.lastIndex = next.index + next[1].length + next[2].length
|
||||
}
|
||||
// leave it in a clean state
|
||||
coerceRtlRegex.lastIndex = -1
|
||||
}
|
||||
|
||||
if (match === null) {
|
||||
return null
|
||||
}
|
||||
|
||||
const major = match[2]
|
||||
const minor = match[3] || '0'
|
||||
const patch = match[4] || '0'
|
||||
const prerelease = options.includePrerelease && match[5] ? `-${match[5]}` : ''
|
||||
const build = options.includePrerelease && match[6] ? `+${match[6]}` : ''
|
||||
|
||||
return parse(`${major}.${minor}.${patch}${prerelease}${build}`, options)
|
||||
}
|
||||
module.exports = coerce
|
||||
@@ -0,0 +1,6 @@
|
||||
export * from "./errors.cjs";
|
||||
export * from "./helpers/parseUtil.cjs";
|
||||
export * from "./helpers/typeAliases.cjs";
|
||||
export * from "./helpers/util.cjs";
|
||||
export * from "./types.cjs";
|
||||
export * from "./ZodError.cjs";
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"for + if": {
|
||||
"name": "for + if",
|
||||
"browser": "Edge 14.14393.0 (Windows 10 0.0.0)",
|
||||
"suite": "itar-long",
|
||||
"hz": 26381.694221257356,
|
||||
"success": true,
|
||||
"fastest": false,
|
||||
"rme": 0.014195682606163837,
|
||||
"rhz": 0.9244556621814648,
|
||||
"sampleSize": 210
|
||||
},
|
||||
"while + if": {
|
||||
"name": "while + if",
|
||||
"browser": "Edge 14.14393.0 (Windows 10 0.0.0)",
|
||||
"suite": "itar-long",
|
||||
"hz": 23771.041213810397,
|
||||
"success": true,
|
||||
"fastest": false,
|
||||
"rme": 0.020663938617191867,
|
||||
"rhz": 0.8329743139979672,
|
||||
"sampleSize": 206
|
||||
},
|
||||
"array join": {
|
||||
"name": "array join",
|
||||
"browser": "Edge 14.14393.0 (Windows 10 0.0.0)",
|
||||
"suite": "itar-long",
|
||||
"hz": 28537.544092708253,
|
||||
"success": true,
|
||||
"fastest": true,
|
||||
"rme": 0.014926600493283032,
|
||||
"rhz": 1,
|
||||
"sampleSize": 209
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
function getRandomInt(max: number) {
|
||||
return Math.floor(Math.random() * Math.floor(max));
|
||||
}
|
||||
|
||||
const testSymbol = Symbol("test");
|
||||
|
||||
export class Mocker {
|
||||
pick = (...args: any[]): any => {
|
||||
return args[getRandomInt(args.length)];
|
||||
};
|
||||
|
||||
get string(): string {
|
||||
return Math.random().toString(36).substring(7);
|
||||
}
|
||||
get number(): number {
|
||||
return Math.random() * 100;
|
||||
}
|
||||
get bigint(): bigint {
|
||||
return BigInt(Math.floor(Math.random() * 10000));
|
||||
}
|
||||
get boolean(): boolean {
|
||||
return Math.random() < 0.5;
|
||||
}
|
||||
get date(): Date {
|
||||
return new Date(Math.floor(Date.now() * Math.random()));
|
||||
}
|
||||
get symbol(): symbol {
|
||||
return testSymbol;
|
||||
}
|
||||
get null(): null {
|
||||
return null;
|
||||
}
|
||||
get undefined(): undefined {
|
||||
return undefined;
|
||||
}
|
||||
get stringOptional(): string | undefined {
|
||||
return this.pick(this.string, this.undefined);
|
||||
}
|
||||
get stringNullable(): string | null {
|
||||
return this.pick(this.string, this.null);
|
||||
}
|
||||
get numberOptional(): number | undefined {
|
||||
return this.pick(this.number, this.undefined);
|
||||
}
|
||||
get numberNullable(): number | null {
|
||||
return this.pick(this.number, this.null);
|
||||
}
|
||||
get booleanOptional(): boolean | undefined {
|
||||
return this.pick(this.boolean, this.undefined);
|
||||
}
|
||||
get booleanNullable(): boolean | null {
|
||||
return this.pick(this.boolean, this.null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user