WIP: bootstrap and partial real Solana watcher implementation
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"errorTypeOverrides" | "literalOverridden" | "overridden" | "overrides" | "primitiveOverridden", [], import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
||||
name: string;
|
||||
};
|
||||
export default _default;
|
||||
@@ -0,0 +1,83 @@
|
||||
import type * as TSESLint from '../../ts-eslint';
|
||||
import type { TSESTree } from '../../ts-estree';
|
||||
/**
|
||||
* Get the proper location of a given function node to report.
|
||||
*
|
||||
* @see {@link https://eslint-community.github.io/eslint-utils/api/ast-utils.html#getfunctionheadlocation}
|
||||
*/
|
||||
export declare const getFunctionHeadLocation: (node: TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression, sourceCode: TSESLint.SourceCode) => TSESTree.SourceLocation;
|
||||
/**
|
||||
* Get the name and kind of a given function node.
|
||||
*
|
||||
* @see {@link https://eslint-community.github.io/eslint-utils/api/ast-utils.html#getfunctionnamewithkind}
|
||||
*/
|
||||
export declare const getFunctionNameWithKind: (node: TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression, sourceCode?: TSESLint.SourceCode) => string;
|
||||
/**
|
||||
* Get the property name of a given property node.
|
||||
* If the node is a computed property, this tries to compute the property name by the getStringIfConstant function.
|
||||
*
|
||||
* @see {@link https://eslint-community.github.io/eslint-utils/api/ast-utils.html#getpropertyname}
|
||||
* @returns The property name of the node. If the property name is not constant then it returns `null`.
|
||||
*/
|
||||
export declare const getPropertyName: (node: TSESTree.MemberExpression | TSESTree.MethodDefinition | TSESTree.Property | TSESTree.PropertyDefinition, initialScope?: TSESLint.Scope.Scope) => string | null;
|
||||
/**
|
||||
* Get the value of a given node if it can decide the value statically.
|
||||
* If the 2nd parameter `initialScope` was given, this function tries to resolve identifier references which are in the
|
||||
* given node as much as possible. In the resolving way, it does on the assumption that built-in global objects have
|
||||
* not been modified.
|
||||
* For example, it considers `Symbol.iterator`, `Symbol.for('k')`, ` String.raw``hello`` `, and `Object.freeze({a: 1}).a` as static, but `Symbol('k')` is not static.
|
||||
*
|
||||
* @see {@link https://eslint-community.github.io/eslint-utils/api/ast-utils.html#getstaticvalue}
|
||||
* @returns The `{ value: any }` shaped object. The `value` property is the static value. If it couldn't compute the
|
||||
* static value of the node, it returns `null`.
|
||||
*/
|
||||
export declare const getStaticValue: (node: TSESTree.Node, initialScope?: TSESLint.Scope.Scope) => {
|
||||
value: unknown;
|
||||
} | null;
|
||||
/**
|
||||
* Get the string value of a given node.
|
||||
* This function is a tiny wrapper of the getStaticValue function.
|
||||
*
|
||||
* @see {@link https://eslint-community.github.io/eslint-utils/api/ast-utils.html#getstringifconstant}
|
||||
*/
|
||||
export declare const getStringIfConstant: (node: TSESTree.Node, initialScope?: TSESLint.Scope.Scope) => string | null;
|
||||
/**
|
||||
* Check whether a given node has any side effect or not.
|
||||
* The side effect means that it may modify a certain variable or object member. This function considers the node which
|
||||
* contains the following types as the node which has side effects:
|
||||
* - `AssignmentExpression`
|
||||
* - `AwaitExpression`
|
||||
* - `CallExpression`
|
||||
* - `ImportExpression`
|
||||
* - `NewExpression`
|
||||
* - `UnaryExpression([operator = "delete"])`
|
||||
* - `UpdateExpression`
|
||||
* - `YieldExpression`
|
||||
* - When `options.considerGetters` is `true`:
|
||||
* - `MemberExpression`
|
||||
* - When `options.considerImplicitTypeConversion` is `true`:
|
||||
* - `BinaryExpression([operator = "==" | "!=" | "<" | "<=" | ">" | ">=" | "<<" | ">>" | ">>>" | "+" | "-" | "*" | "/" | "%" | "|" | "^" | "&" | "in"])`
|
||||
* - `MemberExpression([computed = true])`
|
||||
* - `MethodDefinition([computed = true])`
|
||||
* - `Property([computed = true])`
|
||||
* - `UnaryExpression([operator = "-" | "+" | "!" | "~"])`
|
||||
*
|
||||
* @see {@link https://eslint-community.github.io/eslint-utils/api/ast-utils.html#hassideeffect}
|
||||
*/
|
||||
export declare const hasSideEffect: (node: TSESTree.Node, sourceCode: TSESLint.SourceCode, options?: {
|
||||
considerGetters?: boolean;
|
||||
considerImplicitTypeConversion?: boolean;
|
||||
}) => boolean;
|
||||
export declare const isParenthesized: {
|
||||
(times: number, node: TSESTree.Node, sourceCode: TSESLint.SourceCode): boolean;
|
||||
/**
|
||||
* Check whether a given node is parenthesized or not.
|
||||
* This function detects it correctly even if it's parenthesized by specific syntax.
|
||||
*
|
||||
* @see {@link https://eslint-community.github.io/eslint-utils/api/ast-utils.html#isparenthesized}
|
||||
* @returns `true` if the node is parenthesized.
|
||||
* If `times` was given, it returns `true` only if the node is parenthesized the `times` times.
|
||||
* For example, `isParenthesized(2, node, sourceCode)` returns true for `((foo))`, but not for `(foo)`.
|
||||
*/
|
||||
(node: TSESTree.Node, sourceCode: TSESLint.SourceCode): boolean;
|
||||
};
|
||||
@@ -0,0 +1,53 @@
|
||||
import { createRequire } from 'node:module';
|
||||
import { pathToFileURL } from 'node:url';
|
||||
|
||||
const __require = createRequire(import.meta.url);
|
||||
let inspector;
|
||||
let session;
|
||||
/**
|
||||
* Enables debugging inside `worker_threads` and `child_process`.
|
||||
* Should be called as early as possible when worker/process has been set up.
|
||||
*/
|
||||
function setupInspect(ctx) {
|
||||
const config = ctx.config;
|
||||
const isEnabled = config.inspector.enabled;
|
||||
if (isEnabled) {
|
||||
inspector = __require("node:inspector");
|
||||
if (!(inspector.url() !== void 0)) {
|
||||
inspector.open(config.inspector.port, config.inspector.host, config.inspector.waitForDebugger);
|
||||
if (config.inspectBrk) {
|
||||
const firstTestFile = typeof ctx.files[0] === "string" ? ctx.files[0] : ctx.files[0].filepath;
|
||||
// Stop at first test file
|
||||
if (firstTestFile) {
|
||||
session = new inspector.Session();
|
||||
session.connect();
|
||||
session.post("Debugger.enable");
|
||||
session.post("Debugger.setBreakpointByUrl", {
|
||||
lineNumber: 0,
|
||||
url: pathToFileURL(firstTestFile)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const keepOpen = shouldKeepOpen(config);
|
||||
return function cleanup() {
|
||||
if (isEnabled && !keepOpen && inspector) {
|
||||
inspector.close();
|
||||
session?.disconnect();
|
||||
}
|
||||
};
|
||||
}
|
||||
function closeInspector(config) {
|
||||
const keepOpen = shouldKeepOpen(config);
|
||||
if (inspector && !keepOpen) {
|
||||
inspector.close();
|
||||
session?.disconnect();
|
||||
}
|
||||
}
|
||||
function shouldKeepOpen(config) {
|
||||
// In watch mode the inspector can persist re-runs if isolation is disabled and a single worker is used
|
||||
return config.watch && config.isolate === false && config.maxWorkers === 1;
|
||||
}
|
||||
|
||||
export { closeInspector as c, setupInspect as s };
|
||||
@@ -0,0 +1,8 @@
|
||||
import pino from '../../..'
|
||||
|
||||
const transport = pino.transport({
|
||||
target: 'pino/file',
|
||||
options: { destination: '1' }
|
||||
})
|
||||
const logger = pino(transport)
|
||||
logger.info('Hello')
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"signatureKind.enum.js","sourceRoot":"","sources":["../../src/enums/signatureKind.enum.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAE/F,MAAM,CAAN,IAAY,aAGX;AAHD,WAAY,aAAa;IACrB,iDAAQ,CAAA;IACR,2DAAa,CAAA;AACjB,CAAC,EAHW,aAAa,KAAb,aAAa,QAGxB"}
|
||||
@@ -0,0 +1,126 @@
|
||||
/** The Standard interface. */
|
||||
export interface StandardTypedV1<Input = unknown, Output = Input> {
|
||||
/** The Standard properties. */
|
||||
readonly "~standard": StandardTypedV1.Props<Input, Output>;
|
||||
}
|
||||
export declare namespace StandardTypedV1 {
|
||||
/** The Standard properties interface. */
|
||||
interface Props<Input = unknown, Output = Input> {
|
||||
/** The version number of the standard. */
|
||||
readonly version: 1;
|
||||
/** The vendor name of the schema library. */
|
||||
readonly vendor: string;
|
||||
/** Inferred types associated with the schema. */
|
||||
readonly types?: Types<Input, Output> | undefined;
|
||||
}
|
||||
/** The Standard types interface. */
|
||||
interface Types<Input = unknown, Output = Input> {
|
||||
/** The input type of the schema. */
|
||||
readonly input: Input;
|
||||
/** The output type of the schema. */
|
||||
readonly output: Output;
|
||||
}
|
||||
/** Infers the input type of a Standard. */
|
||||
type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
||||
/** Infers the output type of a Standard. */
|
||||
type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
||||
}
|
||||
/** The Standard Schema interface. */
|
||||
export interface StandardSchemaV1<Input = unknown, Output = Input> {
|
||||
/** The Standard Schema properties. */
|
||||
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
||||
}
|
||||
export declare namespace StandardSchemaV1 {
|
||||
/** The Standard Schema properties interface. */
|
||||
interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
|
||||
/** Validates unknown input values. */
|
||||
readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
|
||||
}
|
||||
/** The result interface of the validate function. */
|
||||
type Result<Output> = SuccessResult<Output> | FailureResult;
|
||||
/** The result interface if validation succeeds. */
|
||||
interface SuccessResult<Output> {
|
||||
/** The typed output value. */
|
||||
readonly value: Output;
|
||||
/** The absence of issues indicates success. */
|
||||
readonly issues?: undefined;
|
||||
}
|
||||
interface Options {
|
||||
/** Implicit support for additional vendor-specific parameters, if needed. */
|
||||
readonly libraryOptions?: Record<string, unknown> | undefined;
|
||||
}
|
||||
/** The result interface if validation fails. */
|
||||
interface FailureResult {
|
||||
/** The issues of failed validation. */
|
||||
readonly issues: ReadonlyArray<Issue>;
|
||||
}
|
||||
/** The issue interface of the failure output. */
|
||||
interface Issue {
|
||||
/** The error message of the issue. */
|
||||
readonly message: string;
|
||||
/** The path of the issue, if any. */
|
||||
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
||||
}
|
||||
/** The path segment interface of the issue. */
|
||||
interface PathSegment {
|
||||
/** The key representing a path segment. */
|
||||
readonly key: PropertyKey;
|
||||
}
|
||||
/** The Standard types interface. */
|
||||
interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {
|
||||
}
|
||||
/** Infers the input type of a Standard. */
|
||||
type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
|
||||
/** Infers the output type of a Standard. */
|
||||
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
||||
}
|
||||
/** The Standard JSON Schema interface. */
|
||||
export interface StandardJSONSchemaV1<Input = unknown, Output = Input> {
|
||||
/** The Standard JSON Schema properties. */
|
||||
readonly "~standard": StandardJSONSchemaV1.Props<Input, Output>;
|
||||
}
|
||||
export declare namespace StandardJSONSchemaV1 {
|
||||
/** The Standard JSON Schema properties interface. */
|
||||
interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
|
||||
/** Methods for generating the input/output JSON Schema. */
|
||||
readonly jsonSchema: Converter;
|
||||
}
|
||||
/** The Standard JSON Schema converter interface. */
|
||||
interface Converter {
|
||||
/** Converts the input type to JSON Schema. May throw if conversion is not supported. */
|
||||
readonly input: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
|
||||
/** Converts the output type to JSON Schema. May throw if conversion is not supported. */
|
||||
readonly output: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
|
||||
}
|
||||
/** The target version of the generated JSON Schema.
|
||||
*
|
||||
* It is *strongly recommended* that implementers support `"draft-2020-12"` and `"draft-07"`, as they are both in wide use.
|
||||
*
|
||||
* The `"openapi-3.0"` target is intended as a standardized specifier for OpenAPI 3.0 which is a superset of JSON Schema `"draft-04"`.
|
||||
*
|
||||
* All other targets can be implemented on a best-effort basis. Libraries should throw if they don't support a specified target.
|
||||
*/
|
||||
type Target = "draft-2020-12" | "draft-07" | "openapi-3.0" | ({} & string);
|
||||
/** The options for the input/output methods. */
|
||||
interface Options {
|
||||
/** Specifies the target version of the generated JSON Schema. Support for all versions is on a best-effort basis. If a given version is not supported, the library should throw. */
|
||||
readonly target: Target;
|
||||
/** Implicit support for additional vendor-specific parameters, if needed. */
|
||||
readonly libraryOptions?: Record<string, unknown> | undefined;
|
||||
}
|
||||
/** The Standard types interface. */
|
||||
interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {
|
||||
}
|
||||
/** Infers the input type of a Standard. */
|
||||
type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
|
||||
/** Infers the output type of a Standard. */
|
||||
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
||||
}
|
||||
export interface StandardSchemaWithJSONProps<Input = unknown, Output = Input> extends StandardSchemaV1.Props<Input, Output>, StandardJSONSchemaV1.Props<Input, Output> {
|
||||
}
|
||||
/**
|
||||
* An interface that combines StandardJSONSchema and StandardSchema.
|
||||
*/
|
||||
export interface StandardSchemaWithJSON<Input = unknown, Output = Input> {
|
||||
"~standard": StandardSchemaWithJSONProps<Input, Output>;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"main": "../../cjs/_ts_dispose_resources.cjs",
|
||||
"module": "../../esm/_ts_dispose_resources.js"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
"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.esnext_decorators = void 0;
|
||||
const base_config_1 = require("./base-config");
|
||||
const decorators_1 = require("./decorators");
|
||||
const es2015_symbol_1 = require("./es2015.symbol");
|
||||
exports.esnext_decorators = {
|
||||
libs: [es2015_symbol_1.es2015_symbol, decorators_1.decorators],
|
||||
variables: [
|
||||
['SymbolConstructor', base_config_1.TYPE],
|
||||
['Function', base_config_1.TYPE],
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,203 @@
|
||||
import * as util from "../core/util.js";
|
||||
const capitalizeFirstCharacter = (text) => {
|
||||
return text.charAt(0).toUpperCase() + text.slice(1);
|
||||
};
|
||||
function getUnitTypeFromNumber(number) {
|
||||
const abs = Math.abs(number);
|
||||
const last = abs % 10;
|
||||
const last2 = abs % 100;
|
||||
if ((last2 >= 11 && last2 <= 19) || last === 0)
|
||||
return "many";
|
||||
if (last === 1)
|
||||
return "one";
|
||||
return "few";
|
||||
}
|
||||
const error = () => {
|
||||
const Sizable = {
|
||||
string: {
|
||||
unit: {
|
||||
one: "simbolis",
|
||||
few: "simboliai",
|
||||
many: "simbolių",
|
||||
},
|
||||
verb: {
|
||||
smaller: {
|
||||
inclusive: "turi būti ne ilgesnė kaip",
|
||||
notInclusive: "turi būti trumpesnė kaip",
|
||||
},
|
||||
bigger: {
|
||||
inclusive: "turi būti ne trumpesnė kaip",
|
||||
notInclusive: "turi būti ilgesnė kaip",
|
||||
},
|
||||
},
|
||||
},
|
||||
file: {
|
||||
unit: {
|
||||
one: "baitas",
|
||||
few: "baitai",
|
||||
many: "baitų",
|
||||
},
|
||||
verb: {
|
||||
smaller: {
|
||||
inclusive: "turi būti ne didesnis kaip",
|
||||
notInclusive: "turi būti mažesnis kaip",
|
||||
},
|
||||
bigger: {
|
||||
inclusive: "turi būti ne mažesnis kaip",
|
||||
notInclusive: "turi būti didesnis kaip",
|
||||
},
|
||||
},
|
||||
},
|
||||
array: {
|
||||
unit: {
|
||||
one: "elementą",
|
||||
few: "elementus",
|
||||
many: "elementų",
|
||||
},
|
||||
verb: {
|
||||
smaller: {
|
||||
inclusive: "turi turėti ne daugiau kaip",
|
||||
notInclusive: "turi turėti mažiau kaip",
|
||||
},
|
||||
bigger: {
|
||||
inclusive: "turi turėti ne mažiau kaip",
|
||||
notInclusive: "turi turėti daugiau kaip",
|
||||
},
|
||||
},
|
||||
},
|
||||
set: {
|
||||
unit: {
|
||||
one: "elementą",
|
||||
few: "elementus",
|
||||
many: "elementų",
|
||||
},
|
||||
verb: {
|
||||
smaller: {
|
||||
inclusive: "turi turėti ne daugiau kaip",
|
||||
notInclusive: "turi turėti mažiau kaip",
|
||||
},
|
||||
bigger: {
|
||||
inclusive: "turi turėti ne mažiau kaip",
|
||||
notInclusive: "turi turėti daugiau kaip",
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
function getSizing(origin, unitType, inclusive, targetShouldBe) {
|
||||
const result = Sizable[origin] ?? null;
|
||||
if (result === null)
|
||||
return result;
|
||||
return {
|
||||
unit: result.unit[unitType],
|
||||
verb: result.verb[targetShouldBe][inclusive ? "inclusive" : "notInclusive"],
|
||||
};
|
||||
}
|
||||
const FormatDictionary = {
|
||||
regex: "įvestis",
|
||||
email: "el. pašto adresas",
|
||||
url: "URL",
|
||||
emoji: "jaustukas",
|
||||
uuid: "UUID",
|
||||
uuidv4: "UUIDv4",
|
||||
uuidv6: "UUIDv6",
|
||||
nanoid: "nanoid",
|
||||
guid: "GUID",
|
||||
cuid: "cuid",
|
||||
cuid2: "cuid2",
|
||||
ulid: "ULID",
|
||||
xid: "XID",
|
||||
ksuid: "KSUID",
|
||||
datetime: "ISO data ir laikas",
|
||||
date: "ISO data",
|
||||
time: "ISO laikas",
|
||||
duration: "ISO trukmė",
|
||||
ipv4: "IPv4 adresas",
|
||||
ipv6: "IPv6 adresas",
|
||||
cidrv4: "IPv4 tinklo prefiksas (CIDR)",
|
||||
cidrv6: "IPv6 tinklo prefiksas (CIDR)",
|
||||
base64: "base64 užkoduota eilutė",
|
||||
base64url: "base64url užkoduota eilutė",
|
||||
json_string: "JSON eilutė",
|
||||
e164: "E.164 numeris",
|
||||
jwt: "JWT",
|
||||
template_literal: "įvestis",
|
||||
};
|
||||
const TypeDictionary = {
|
||||
nan: "NaN",
|
||||
number: "skaičius",
|
||||
bigint: "sveikasis skaičius",
|
||||
string: "eilutė",
|
||||
boolean: "loginė reikšmė",
|
||||
undefined: "neapibrėžta reikšmė",
|
||||
function: "funkcija",
|
||||
symbol: "simbolis",
|
||||
array: "masyvas",
|
||||
object: "objektas",
|
||||
null: "nulinė reikšmė",
|
||||
};
|
||||
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 `Gautas tipas ${received}, o tikėtasi - instanceof ${issue.expected}`;
|
||||
}
|
||||
return `Gautas tipas ${received}, o tikėtasi - ${expected}`;
|
||||
}
|
||||
case "invalid_value":
|
||||
if (issue.values.length === 1)
|
||||
return `Privalo būti ${util.stringifyPrimitive(issue.values[0])}`;
|
||||
return `Privalo būti vienas iš ${util.joinValues(issue.values, "|")} pasirinkimų`;
|
||||
case "too_big": {
|
||||
const origin = TypeDictionary[issue.origin] ?? issue.origin;
|
||||
const sizing = getSizing(issue.origin, getUnitTypeFromNumber(Number(issue.maximum)), issue.inclusive ?? false, "smaller");
|
||||
if (sizing?.verb)
|
||||
return `${capitalizeFirstCharacter(origin ?? issue.origin ?? "reikšmė")} ${sizing.verb} ${issue.maximum.toString()} ${sizing.unit ?? "elementų"}`;
|
||||
const adj = issue.inclusive ? "ne didesnis kaip" : "mažesnis kaip";
|
||||
return `${capitalizeFirstCharacter(origin ?? issue.origin ?? "reikšmė")} turi būti ${adj} ${issue.maximum.toString()} ${sizing?.unit}`;
|
||||
}
|
||||
case "too_small": {
|
||||
const origin = TypeDictionary[issue.origin] ?? issue.origin;
|
||||
const sizing = getSizing(issue.origin, getUnitTypeFromNumber(Number(issue.minimum)), issue.inclusive ?? false, "bigger");
|
||||
if (sizing?.verb)
|
||||
return `${capitalizeFirstCharacter(origin ?? issue.origin ?? "reikšmė")} ${sizing.verb} ${issue.minimum.toString()} ${sizing.unit ?? "elementų"}`;
|
||||
const adj = issue.inclusive ? "ne mažesnis kaip" : "didesnis kaip";
|
||||
return `${capitalizeFirstCharacter(origin ?? issue.origin ?? "reikšmė")} turi būti ${adj} ${issue.minimum.toString()} ${sizing?.unit}`;
|
||||
}
|
||||
case "invalid_format": {
|
||||
const _issue = issue;
|
||||
if (_issue.format === "starts_with") {
|
||||
return `Eilutė privalo prasidėti "${_issue.prefix}"`;
|
||||
}
|
||||
if (_issue.format === "ends_with")
|
||||
return `Eilutė privalo pasibaigti "${_issue.suffix}"`;
|
||||
if (_issue.format === "includes")
|
||||
return `Eilutė privalo įtraukti "${_issue.includes}"`;
|
||||
if (_issue.format === "regex")
|
||||
return `Eilutė privalo atitikti ${_issue.pattern}`;
|
||||
return `Neteisingas ${FormatDictionary[_issue.format] ?? issue.format}`;
|
||||
}
|
||||
case "not_multiple_of":
|
||||
return `Skaičius privalo būti ${issue.divisor} kartotinis.`;
|
||||
case "unrecognized_keys":
|
||||
return `Neatpažint${issue.keys.length > 1 ? "i" : "as"} rakt${issue.keys.length > 1 ? "ai" : "as"}: ${util.joinValues(issue.keys, ", ")}`;
|
||||
case "invalid_key":
|
||||
return "Rastas klaidingas raktas";
|
||||
case "invalid_union":
|
||||
return "Klaidinga įvestis";
|
||||
case "invalid_element": {
|
||||
const origin = TypeDictionary[issue.origin] ?? issue.origin;
|
||||
return `${capitalizeFirstCharacter(origin ?? issue.origin ?? "reikšmė")} turi klaidingą įvestį`;
|
||||
}
|
||||
default:
|
||||
return "Klaidinga įvestis";
|
||||
}
|
||||
};
|
||||
};
|
||||
export default function () {
|
||||
return {
|
||||
localeError: error(),
|
||||
};
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,161 @@
|
||||
"use strict";
|
||||
// adapted from https://github.com/eslint/eslint/blob/5bdaae205c3a0089ea338b382df59e21d5b06436/lib/rules/utils/ast-utils.js#L1668-L1787
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getFunctionHeadLoc = getFunctionHeadLoc;
|
||||
const utils_1 = require("@typescript-eslint/utils");
|
||||
const astUtils_1 = require("./astUtils");
|
||||
/**
|
||||
* Gets the `(` token of the given function node.
|
||||
* @param node The function node to get.
|
||||
* @param sourceCode The source code object to get tokens.
|
||||
* @returns `(` token.
|
||||
*/
|
||||
function getOpeningParenOfParams(node, sourceCode) {
|
||||
// If the node is an arrow function and doesn't have parens, this returns the identifier of the first param.
|
||||
if (node.type === utils_1.AST_NODE_TYPES.ArrowFunctionExpression &&
|
||||
node.params.length === 1) {
|
||||
const argToken = utils_1.ESLintUtils.nullThrows(sourceCode.getFirstToken(node.params[0]), utils_1.ESLintUtils.NullThrowsReasons.MissingToken('parameter', 'arrow function'));
|
||||
const maybeParenToken = sourceCode.getTokenBefore(argToken);
|
||||
return maybeParenToken && (0, astUtils_1.isOpeningParenToken)(maybeParenToken)
|
||||
? maybeParenToken
|
||||
: argToken;
|
||||
}
|
||||
// Otherwise, returns paren.
|
||||
return node.id != null
|
||||
? utils_1.ESLintUtils.nullThrows(sourceCode.getTokenAfter(node.id, astUtils_1.isOpeningParenToken), utils_1.ESLintUtils.NullThrowsReasons.MissingToken('id', 'function'))
|
||||
: utils_1.ESLintUtils.nullThrows(sourceCode.getFirstToken(node, astUtils_1.isOpeningParenToken), utils_1.ESLintUtils.NullThrowsReasons.MissingToken('opening parenthesis', 'function'));
|
||||
}
|
||||
/**
|
||||
* Gets the location of the given function node for reporting.
|
||||
*
|
||||
* - `function foo() {}`
|
||||
* ^^^^^^^^^^^^
|
||||
* - `(function foo() {})`
|
||||
* ^^^^^^^^^^^^
|
||||
* - `(function() {})`
|
||||
* ^^^^^^^^
|
||||
* - `function* foo() {}`
|
||||
* ^^^^^^^^^^^^^
|
||||
* - `(function* foo() {})`
|
||||
* ^^^^^^^^^^^^^
|
||||
* - `(function*() {})`
|
||||
* ^^^^^^^^^
|
||||
* - `() => {}`
|
||||
* ^^
|
||||
* - `async () => {}`
|
||||
* ^^
|
||||
* - `({ foo: function foo() {} })`
|
||||
* ^^^^^^^^^^^^^^^^^
|
||||
* - `({ foo: function() {} })`
|
||||
* ^^^^^^^^^^^^^
|
||||
* - `({ ['foo']: function() {} })`
|
||||
* ^^^^^^^^^^^^^^^^^
|
||||
* - `({ [foo]: function() {} })`
|
||||
* ^^^^^^^^^^^^^^^
|
||||
* - `({ foo() {} })`
|
||||
* ^^^
|
||||
* - `({ foo: function* foo() {} })`
|
||||
* ^^^^^^^^^^^^^^^^^^
|
||||
* - `({ foo: function*() {} })`
|
||||
* ^^^^^^^^^^^^^^
|
||||
* - `({ ['foo']: function*() {} })`
|
||||
* ^^^^^^^^^^^^^^^^^^
|
||||
* - `({ [foo]: function*() {} })`
|
||||
* ^^^^^^^^^^^^^^^^
|
||||
* - `({ *foo() {} })`
|
||||
* ^^^^
|
||||
* - `({ foo: async function foo() {} })`
|
||||
* ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
* - `({ foo: async function() {} })`
|
||||
* ^^^^^^^^^^^^^^^^^^^
|
||||
* - `({ ['foo']: async function() {} })`
|
||||
* ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
* - `({ [foo]: async function() {} })`
|
||||
* ^^^^^^^^^^^^^^^^^^^^^
|
||||
* - `({ async foo() {} })`
|
||||
* ^^^^^^^^^
|
||||
* - `({ get foo() {} })`
|
||||
* ^^^^^^^
|
||||
* - `({ set foo(a) {} })`
|
||||
* ^^^^^^^
|
||||
* - `class A { constructor() {} }`
|
||||
* ^^^^^^^^^^^
|
||||
* - `class A { foo() {} }`
|
||||
* ^^^
|
||||
* - `class A { *foo() {} }`
|
||||
* ^^^^
|
||||
* - `class A { async foo() {} }`
|
||||
* ^^^^^^^^^
|
||||
* - `class A { ['foo']() {} }`
|
||||
* ^^^^^^^
|
||||
* - `class A { *['foo']() {} }`
|
||||
* ^^^^^^^^
|
||||
* - `class A { async ['foo']() {} }`
|
||||
* ^^^^^^^^^^^^^
|
||||
* - `class A { [foo]() {} }`
|
||||
* ^^^^^
|
||||
* - `class A { *[foo]() {} }`
|
||||
* ^^^^^^
|
||||
* - `class A { async [foo]() {} }`
|
||||
* ^^^^^^^^^^^
|
||||
* - `class A { get foo() {} }`
|
||||
* ^^^^^^^
|
||||
* - `class A { set foo(a) {} }`
|
||||
* ^^^^^^^
|
||||
* - `class A { static foo() {} }`
|
||||
* ^^^^^^^^^^
|
||||
* - `class A { static *foo() {} }`
|
||||
* ^^^^^^^^^^^
|
||||
* - `class A { static async foo() {} }`
|
||||
* ^^^^^^^^^^^^^^^^
|
||||
* - `class A { static get foo() {} }`
|
||||
* ^^^^^^^^^^^^^^
|
||||
* - `class A { static set foo(a) {} }`
|
||||
* ^^^^^^^^^^^^^^
|
||||
* - `class A { foo = function() {} }`
|
||||
* ^^^^^^^^^^^^^^
|
||||
* - `class A { static foo = function() {} }`
|
||||
* ^^^^^^^^^^^^^^^^^^^^^
|
||||
* - `class A { foo = (a, b) => {} }`
|
||||
* ^^^^^^
|
||||
* @param node The function node to get.
|
||||
* @param sourceCode The source code object to get tokens.
|
||||
* @returns The location of the function node for reporting.
|
||||
*/
|
||||
function getFunctionHeadLoc(node, sourceCode) {
|
||||
const parent = node.parent;
|
||||
let start;
|
||||
let end;
|
||||
if (parent.type === utils_1.AST_NODE_TYPES.MethodDefinition ||
|
||||
parent.type === utils_1.AST_NODE_TYPES.PropertyDefinition) {
|
||||
// the decorator's range is included within the member
|
||||
// however it's usually irrelevant to the member itself - so we don't want
|
||||
// to highlight it ever.
|
||||
if (parent.decorators.length > 0) {
|
||||
const lastDecorator = parent.decorators[parent.decorators.length - 1];
|
||||
const firstTokenAfterDecorator = utils_1.ESLintUtils.nullThrows(sourceCode.getTokenAfter(lastDecorator), utils_1.ESLintUtils.NullThrowsReasons.MissingToken('modifier or member name', 'class member'));
|
||||
start = firstTokenAfterDecorator.loc.start;
|
||||
}
|
||||
else {
|
||||
start = parent.loc.start;
|
||||
}
|
||||
end = getOpeningParenOfParams(node, sourceCode).loc.start;
|
||||
}
|
||||
else if (parent.type === utils_1.AST_NODE_TYPES.Property) {
|
||||
start = parent.loc.start;
|
||||
end = getOpeningParenOfParams(node, sourceCode).loc.start;
|
||||
}
|
||||
else if (node.type === utils_1.AST_NODE_TYPES.ArrowFunctionExpression) {
|
||||
const arrowToken = utils_1.ESLintUtils.nullThrows(sourceCode.getTokenBefore(node.body, astUtils_1.isArrowToken), utils_1.ESLintUtils.NullThrowsReasons.MissingToken('arrow token', 'arrow function'));
|
||||
start = arrowToken.loc.start;
|
||||
end = arrowToken.loc.end;
|
||||
}
|
||||
else {
|
||||
start = node.loc.start;
|
||||
end = getOpeningParenOfParams(node, sourceCode).loc.start;
|
||||
}
|
||||
return {
|
||||
end: { ...end },
|
||||
start: { ...start },
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
var _typeof = require("./typeof.js")["default"];
|
||||
function setFunctionName(e, t, n) {
|
||||
"symbol" == _typeof(t) && (t = (t = t.description) ? "[" + t + "]" : "");
|
||||
try {
|
||||
Object.defineProperty(e, "name", {
|
||||
configurable: !0,
|
||||
value: n ? n + " " + t : t
|
||||
});
|
||||
} catch (e) {}
|
||||
return e;
|
||||
}
|
||||
module.exports = setFunctionName, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
||||
@@ -0,0 +1,69 @@
|
||||
export {};
|
||||
|
||||
import * as undici from "undici-types";
|
||||
|
||||
type _CloseEvent = typeof globalThis extends { onmessage: any } ? {} : undici.CloseEvent;
|
||||
type _CloseEventInit = typeof globalThis extends { onmessage: any } ? {} : undici.CloseEventInit;
|
||||
type _ErrorEvent = typeof globalThis extends { onmessage: any } ? {} : undici.ErrorEvent;
|
||||
type _ErrorEventInit = typeof globalThis extends { onmessage: any } ? {} : undici.ErrorEventInit;
|
||||
type _EventSource = typeof globalThis extends { onmessage: any } ? {} : undici.EventSource;
|
||||
type _EventSourceInit = typeof globalThis extends { onmessage: any } ? {} : undici.EventSourceInit;
|
||||
type _FormData = typeof globalThis extends { onmessage: any } ? {} : undici.FormData;
|
||||
type _Headers = typeof globalThis extends { onmessage: any } ? {} : undici.Headers;
|
||||
type _MessageEvent = typeof globalThis extends { onmessage: any } ? {} : undici.MessageEvent;
|
||||
type _MessageEventInit = typeof globalThis extends { onmessage: any } ? {} : undici.MessageEventInit;
|
||||
type _Request = typeof globalThis extends { onmessage: any } ? {} : undici.Request;
|
||||
type _RequestInit = typeof globalThis extends { onmessage: any } ? {} : undici.RequestInit;
|
||||
type _Response = typeof globalThis extends { onmessage: any } ? {} : undici.Response;
|
||||
type _ResponseInit = typeof globalThis extends { onmessage: any } ? {} : undici.ResponseInit;
|
||||
type _WebSocket = typeof globalThis extends { onmessage: any } ? {} : undici.WebSocket;
|
||||
type _WebSocketInit = typeof globalThis extends { onmessage: any } ? {} : undici.WebSocketInit;
|
||||
|
||||
declare global {
|
||||
function fetch(
|
||||
input: string | URL | Request,
|
||||
init?: RequestInit,
|
||||
): Promise<Response>;
|
||||
|
||||
interface CloseEvent extends _CloseEvent {}
|
||||
var CloseEvent: typeof globalThis extends { onmessage: any; CloseEvent: infer T } ? T : typeof undici.CloseEvent;
|
||||
|
||||
interface CloseEventInit extends _CloseEventInit {}
|
||||
|
||||
interface ErrorEvent extends _ErrorEvent {}
|
||||
var ErrorEvent: typeof globalThis extends { onmessage: any; ErrorEvent: infer T } ? T : typeof undici.ErrorEvent;
|
||||
|
||||
interface ErrorEventInit extends _ErrorEventInit {}
|
||||
|
||||
interface EventSource extends _EventSource {}
|
||||
var EventSource: typeof globalThis extends { onmessage: any; EventSource: infer T } ? T : typeof undici.EventSource;
|
||||
|
||||
interface EventSourceInit extends _EventSourceInit {}
|
||||
|
||||
interface FormData extends _FormData {}
|
||||
var FormData: typeof globalThis extends { onmessage: any; FormData: infer T } ? T : typeof undici.FormData;
|
||||
|
||||
interface Headers extends _Headers {}
|
||||
var Headers: typeof globalThis extends { onmessage: any; Headers: infer T } ? T : typeof undici.Headers;
|
||||
|
||||
interface MessageEvent extends _MessageEvent {}
|
||||
var MessageEvent: typeof globalThis extends { onmessage: any; MessageEvent: infer T } ? T
|
||||
: typeof undici.MessageEvent;
|
||||
|
||||
interface MessageEventInit extends _MessageEventInit {}
|
||||
|
||||
interface Request extends _Request {}
|
||||
var Request: typeof globalThis extends { onmessage: any; Request: infer T } ? T : typeof undici.Request;
|
||||
|
||||
interface RequestInit extends _RequestInit {}
|
||||
|
||||
interface Response extends _Response {}
|
||||
var Response: typeof globalThis extends { onmessage: any; Response: infer T } ? T : typeof undici.Response;
|
||||
|
||||
interface ResponseInit extends _ResponseInit {}
|
||||
|
||||
interface WebSocket extends _WebSocket {}
|
||||
var WebSocket: typeof globalThis extends { onmessage: any; WebSocket: infer T } ? T : typeof undici.WebSocket;
|
||||
|
||||
interface WebSocketInit extends _WebSocketInit {}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import { FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder } from '@solana/codecs-core';
|
||||
import { NumberCodecConfig } from './common';
|
||||
/**
|
||||
* Returns an encoder for 32-bit unsigned integers (`u32`).
|
||||
*
|
||||
* This encoder serializes `u32` values using four bytes in little-endian format by default.
|
||||
* You may specify big-endian storage using the `endian` option.
|
||||
*
|
||||
* For more details, see {@link getU32Codec}.
|
||||
*
|
||||
* @param config - Optional settings for endianness.
|
||||
* @returns A `FixedSizeEncoder<bigint | number, 4>` for encoding `u32` values.
|
||||
*
|
||||
* @example
|
||||
* Encoding a `u32` value.
|
||||
* ```ts
|
||||
* const encoder = getU32Encoder();
|
||||
* const bytes = encoder.encode(42); // 0x2a000000
|
||||
* ```
|
||||
*
|
||||
* @see {@link getU32Codec}
|
||||
*/
|
||||
export declare const getU32Encoder: (config?: NumberCodecConfig) => FixedSizeEncoder<bigint | number, 4>;
|
||||
/**
|
||||
* Returns a decoder for 32-bit unsigned integers (`u32`).
|
||||
*
|
||||
* This decoder deserializes `u32` values from four bytes in little-endian format by default.
|
||||
* You may specify big-endian storage using the `endian` option.
|
||||
*
|
||||
* For more details, see {@link getU32Codec}.
|
||||
*
|
||||
* @param config - Optional settings for endianness.
|
||||
* @returns A `FixedSizeDecoder<number, 4>` for decoding `u32` values.
|
||||
*
|
||||
* @example
|
||||
* Decoding a `u32` value.
|
||||
* ```ts
|
||||
* const decoder = getU32Decoder();
|
||||
* const value = decoder.decode(new Uint8Array([0x2a, 0x00, 0x00, 0x00])); // 42
|
||||
* ```
|
||||
*
|
||||
* @see {@link getU32Codec}
|
||||
*/
|
||||
export declare const getU32Decoder: (config?: NumberCodecConfig) => FixedSizeDecoder<number, 4>;
|
||||
/**
|
||||
* Returns a codec for encoding and decoding 32-bit unsigned integers (`u32`).
|
||||
*
|
||||
* This codec serializes `u32` values using four bytes in little-endian format by default.
|
||||
* You may specify big-endian storage using the `endian` option.
|
||||
*
|
||||
* @param config - Optional settings for endianness.
|
||||
* @returns A `FixedSizeCodec<bigint | number, number, 4>` for encoding and decoding `u32` values.
|
||||
*
|
||||
* @example
|
||||
* Encoding and decoding a `u32` value.
|
||||
* ```ts
|
||||
* const codec = getU32Codec();
|
||||
* const bytes = codec.encode(42); // 0x2a000000 (little-endian)
|
||||
* const value = codec.decode(bytes); // 42
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* Storing values in big-endian format.
|
||||
* ```ts
|
||||
* const codec = getU32Codec({ endian: Endian.Big });
|
||||
* const bytes = codec.encode(42); // 0x0000002a
|
||||
* ```
|
||||
*
|
||||
* @remarks
|
||||
* This codec only supports values between `0` and `2^32 - 1`.
|
||||
* If you need a larger range, consider using {@link getU64Codec} or {@link getU128Codec}.
|
||||
* For signed integers, use {@link getI32Codec}.
|
||||
*
|
||||
* Separate {@link getU32Encoder} and {@link getU32Decoder} functions are available.
|
||||
*
|
||||
* ```ts
|
||||
* const bytes = getU32Encoder().encode(42);
|
||||
* const value = getU32Decoder().decode(bytes);
|
||||
* ```
|
||||
*
|
||||
* @see {@link getU32Encoder}
|
||||
* @see {@link getU32Decoder}
|
||||
*/
|
||||
export declare const getU32Codec: (config?: NumberCodecConfig) => FixedSizeCodec<bigint | number, number, 4>;
|
||||
//# sourceMappingURL=u32.d.ts.map
|
||||
@@ -0,0 +1,7 @@
|
||||
declare function setGlobalOrigin (origin: string | URL | undefined): void
|
||||
declare function getGlobalOrigin (): URL | undefined
|
||||
|
||||
export {
|
||||
setGlobalOrigin,
|
||||
getGlobalOrigin
|
||||
}
|
||||
@@ -0,0 +1,289 @@
|
||||
'use strict'
|
||||
|
||||
const { createRequire } = require('module')
|
||||
const { existsSync } = require('node:fs')
|
||||
const getCallers = require('./caller')
|
||||
const { join, isAbsolute, sep } = require('node:path')
|
||||
const { fileURLToPath } = require('node:url')
|
||||
const sleep = require('atomic-sleep')
|
||||
const onExit = require('on-exit-leak-free')
|
||||
const ThreadStream = require('thread-stream')
|
||||
|
||||
function setupOnExit (stream) {
|
||||
// This is leak free, it does not leave event handlers
|
||||
onExit.register(stream, autoEnd)
|
||||
onExit.registerBeforeExit(stream, flush)
|
||||
|
||||
stream.on('close', function () {
|
||||
onExit.unregister(stream)
|
||||
})
|
||||
}
|
||||
|
||||
// Check if preload flags exist in execArgv.
|
||||
// During preload phase (require.main undefined), we pass empty execArgv to prevent infinite worker spawning.
|
||||
// We don't try to filter and pass other flags because many (like --stack-trace-limit, --tls-cipher-list)
|
||||
// aren't valid for worker threads and would cause ERR_WORKER_INVALID_EXEC_ARGV.
|
||||
function hasPreloadFlags () {
|
||||
const execArgv = process.execArgv
|
||||
for (let i = 0; i < execArgv.length; i++) {
|
||||
const arg = execArgv[i]
|
||||
if (arg === '--import' || arg === '--require' || arg === '-r') {
|
||||
return true
|
||||
}
|
||||
if (arg.startsWith('--import=') || arg.startsWith('--require=') || arg.startsWith('-r=')) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
function sanitizeNodeOptions (nodeOptions) {
|
||||
const tokens = nodeOptions.match(/(?:[^\s"']+|"[^"]*"|'[^']*')+/g)
|
||||
if (!tokens) {
|
||||
return nodeOptions
|
||||
}
|
||||
|
||||
const sanitized = []
|
||||
let changed = false
|
||||
|
||||
for (let i = 0; i < tokens.length; i++) {
|
||||
const token = tokens[i]
|
||||
|
||||
if (token === '--require' || token === '-r' || token === '--import') {
|
||||
const next = tokens[i + 1]
|
||||
if (next && shouldDropPreload(next)) {
|
||||
changed = true
|
||||
i++
|
||||
continue
|
||||
}
|
||||
|
||||
sanitized.push(token)
|
||||
if (next) {
|
||||
sanitized.push(next)
|
||||
i++
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if (token.startsWith('--require=') || token.startsWith('-r=') || token.startsWith('--import=')) {
|
||||
const value = token.slice(token.indexOf('=') + 1)
|
||||
if (shouldDropPreload(value)) {
|
||||
changed = true
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
sanitized.push(token)
|
||||
}
|
||||
|
||||
return changed ? sanitized.join(' ') : nodeOptions
|
||||
}
|
||||
|
||||
function shouldDropPreload (value) {
|
||||
const unquoted = stripQuotes(value)
|
||||
if (!unquoted) {
|
||||
return false
|
||||
}
|
||||
|
||||
let path = unquoted
|
||||
if (path.startsWith('file://')) {
|
||||
try {
|
||||
path = fileURLToPath(path)
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return isAbsolute(path) && !existsSync(path)
|
||||
}
|
||||
|
||||
function stripQuotes (value) {
|
||||
const first = value[0]
|
||||
const last = value[value.length - 1]
|
||||
|
||||
if ((first === '"' && last === '"') || (first === "'" && last === "'")) {
|
||||
return value.slice(1, -1)
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
function buildStream (filename, workerData, workerOpts, sync, name) {
|
||||
// When pino is loaded during a preload phase (via --import or --require),
|
||||
// pass empty execArgv to prevent infinite spawning. Each worker would
|
||||
// otherwise re-run the preload, creating another transport.
|
||||
if (!workerOpts.execArgv && hasPreloadFlags() && require.main === undefined) {
|
||||
workerOpts = {
|
||||
...workerOpts,
|
||||
execArgv: []
|
||||
}
|
||||
}
|
||||
|
||||
if (!workerOpts.env && process.env.NODE_OPTIONS) {
|
||||
const nodeOptions = sanitizeNodeOptions(process.env.NODE_OPTIONS)
|
||||
if (nodeOptions !== process.env.NODE_OPTIONS) {
|
||||
workerOpts = {
|
||||
...workerOpts,
|
||||
env: {
|
||||
...process.env,
|
||||
NODE_OPTIONS: nodeOptions
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
workerOpts = { ...workerOpts, name }
|
||||
|
||||
const stream = new ThreadStream({
|
||||
filename,
|
||||
workerData,
|
||||
workerOpts,
|
||||
sync
|
||||
})
|
||||
|
||||
stream.on('ready', onReady)
|
||||
stream.on('close', function () {
|
||||
process.removeListener('exit', onExit)
|
||||
})
|
||||
|
||||
process.on('exit', onExit)
|
||||
|
||||
function onReady () {
|
||||
process.removeListener('exit', onExit)
|
||||
stream.unref()
|
||||
|
||||
if (workerOpts.autoEnd !== false) {
|
||||
setupOnExit(stream)
|
||||
}
|
||||
}
|
||||
|
||||
function onExit () {
|
||||
/* istanbul ignore next */
|
||||
if (stream.closed) {
|
||||
return
|
||||
}
|
||||
stream.flushSync()
|
||||
// Apparently there is a very sporadic race condition
|
||||
// that in certain OS would prevent the messages to be flushed
|
||||
// because the thread might not have been created still.
|
||||
// Unfortunately we need to sleep(100) in this case.
|
||||
sleep(100)
|
||||
stream.end()
|
||||
}
|
||||
|
||||
return stream
|
||||
}
|
||||
|
||||
function autoEnd (stream) {
|
||||
stream.ref()
|
||||
stream.flushSync()
|
||||
stream.end()
|
||||
stream.once('close', function () {
|
||||
stream.unref()
|
||||
})
|
||||
}
|
||||
|
||||
function flush (stream) {
|
||||
stream.flushSync()
|
||||
}
|
||||
|
||||
function transport (fullOptions) {
|
||||
const { pipeline, targets, levels, dedupe, worker = {}, caller = getCallers(), sync = false } = fullOptions
|
||||
|
||||
const options = {
|
||||
...fullOptions.options
|
||||
}
|
||||
|
||||
// Backwards compatibility
|
||||
const callers = typeof caller === 'string' ? [caller] : caller
|
||||
|
||||
// This will be eventually modified by bundlers
|
||||
const bundlerOverrides = (typeof globalThis === 'object' &&
|
||||
Object.prototype.hasOwnProperty.call(globalThis, '__bundlerPathsOverrides') &&
|
||||
globalThis.__bundlerPathsOverrides &&
|
||||
typeof globalThis.__bundlerPathsOverrides === 'object')
|
||||
? globalThis.__bundlerPathsOverrides
|
||||
: Object.create(null)
|
||||
|
||||
let target = fullOptions.target
|
||||
|
||||
if (target && targets) {
|
||||
throw new Error('only one of target or targets can be specified')
|
||||
}
|
||||
|
||||
if (targets) {
|
||||
target = bundlerOverrides['pino-worker'] || join(__dirname, 'worker.js')
|
||||
options.targets = targets.filter(dest => dest.target).map((dest) => {
|
||||
return {
|
||||
...dest,
|
||||
target: fixTarget(dest.target)
|
||||
}
|
||||
})
|
||||
options.pipelines = targets.filter(dest => dest.pipeline).map((dest) => {
|
||||
return dest.pipeline.map((t) => {
|
||||
return {
|
||||
...t,
|
||||
level: dest.level, // duplicate the pipeline `level` property defined in the upper level
|
||||
target: fixTarget(t.target)
|
||||
}
|
||||
})
|
||||
})
|
||||
} else if (pipeline) {
|
||||
target = bundlerOverrides['pino-worker'] || join(__dirname, 'worker.js')
|
||||
options.pipelines = [pipeline.map((dest) => {
|
||||
return {
|
||||
...dest,
|
||||
target: fixTarget(dest.target)
|
||||
}
|
||||
})]
|
||||
}
|
||||
|
||||
if (levels) {
|
||||
options.levels = levels
|
||||
}
|
||||
|
||||
if (dedupe) {
|
||||
options.dedupe = dedupe
|
||||
}
|
||||
|
||||
options.pinoWillSendConfig = true
|
||||
|
||||
const name = (targets || pipeline) ? 'pino.transport' : target
|
||||
return buildStream(fixTarget(target), options, worker, sync, name)
|
||||
|
||||
function fixTarget (origin) {
|
||||
origin = bundlerOverrides[origin] || origin
|
||||
|
||||
if (isAbsolute(origin) || origin.indexOf('file://') === 0) {
|
||||
return origin
|
||||
}
|
||||
|
||||
if (origin === 'pino/file') {
|
||||
return join(__dirname, '..', 'file.js')
|
||||
}
|
||||
|
||||
let fixTarget
|
||||
|
||||
for (const filePath of callers) {
|
||||
try {
|
||||
const context = filePath === 'node:repl'
|
||||
? process.cwd() + sep
|
||||
: filePath
|
||||
|
||||
fixTarget = createRequire(context).resolve(origin)
|
||||
break
|
||||
} catch (err) {
|
||||
// Silent catch
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if (!fixTarget) {
|
||||
throw new Error(`unable to determine transport target for "${origin}"`)
|
||||
}
|
||||
|
||||
return fixTarget
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = transport
|
||||
@@ -0,0 +1,375 @@
|
||||
/**
|
||||
* SHA2 hash function. A.k.a. sha256, sha384, sha512, sha512_224, sha512_256.
|
||||
* SHA256 is the fastest hash implementable in JS, even faster than Blake3.
|
||||
* Check out [RFC 4634](https://datatracker.ietf.org/doc/html/rfc4634) and
|
||||
* [FIPS 180-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf).
|
||||
* @module
|
||||
*/
|
||||
import { Chi, HashMD, Maj, SHA224_IV, SHA256_IV, SHA384_IV, SHA512_IV } from "./_md.js";
|
||||
import * as u64 from "./_u64.js";
|
||||
import { clean, createHasher, rotr } from "./utils.js";
|
||||
/**
|
||||
* Round constants:
|
||||
* First 32 bits of fractional parts of the cube roots of the first 64 primes 2..311)
|
||||
*/
|
||||
// prettier-ignore
|
||||
const SHA256_K = /* @__PURE__ */ Uint32Array.from([
|
||||
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
||||
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
||||
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
||||
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
||||
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
||||
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
||||
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
||||
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
||||
]);
|
||||
/** Reusable temporary buffer. "W" comes straight from spec. */
|
||||
const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
||||
export class SHA256 extends HashMD {
|
||||
constructor(outputLen = 32) {
|
||||
super(64, outputLen, 8, false);
|
||||
// We cannot use array here since array allows indexing by variable
|
||||
// which means optimizer/compiler cannot use registers.
|
||||
this.A = SHA256_IV[0] | 0;
|
||||
this.B = SHA256_IV[1] | 0;
|
||||
this.C = SHA256_IV[2] | 0;
|
||||
this.D = SHA256_IV[3] | 0;
|
||||
this.E = SHA256_IV[4] | 0;
|
||||
this.F = SHA256_IV[5] | 0;
|
||||
this.G = SHA256_IV[6] | 0;
|
||||
this.H = SHA256_IV[7] | 0;
|
||||
}
|
||||
get() {
|
||||
const { A, B, C, D, E, F, G, H } = this;
|
||||
return [A, B, C, D, E, F, G, H];
|
||||
}
|
||||
// prettier-ignore
|
||||
set(A, B, C, D, E, F, G, H) {
|
||||
this.A = A | 0;
|
||||
this.B = B | 0;
|
||||
this.C = C | 0;
|
||||
this.D = D | 0;
|
||||
this.E = E | 0;
|
||||
this.F = F | 0;
|
||||
this.G = G | 0;
|
||||
this.H = H | 0;
|
||||
}
|
||||
process(view, offset) {
|
||||
// Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array
|
||||
for (let i = 0; i < 16; i++, offset += 4)
|
||||
SHA256_W[i] = view.getUint32(offset, false);
|
||||
for (let i = 16; i < 64; i++) {
|
||||
const W15 = SHA256_W[i - 15];
|
||||
const W2 = SHA256_W[i - 2];
|
||||
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ (W15 >>> 3);
|
||||
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ (W2 >>> 10);
|
||||
SHA256_W[i] = (s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16]) | 0;
|
||||
}
|
||||
// Compression function main loop, 64 rounds
|
||||
let { A, B, C, D, E, F, G, H } = this;
|
||||
for (let i = 0; i < 64; i++) {
|
||||
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
||||
const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
|
||||
const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
|
||||
const T2 = (sigma0 + Maj(A, B, C)) | 0;
|
||||
H = G;
|
||||
G = F;
|
||||
F = E;
|
||||
E = (D + T1) | 0;
|
||||
D = C;
|
||||
C = B;
|
||||
B = A;
|
||||
A = (T1 + T2) | 0;
|
||||
}
|
||||
// Add the compressed chunk to the current hash value
|
||||
A = (A + this.A) | 0;
|
||||
B = (B + this.B) | 0;
|
||||
C = (C + this.C) | 0;
|
||||
D = (D + this.D) | 0;
|
||||
E = (E + this.E) | 0;
|
||||
F = (F + this.F) | 0;
|
||||
G = (G + this.G) | 0;
|
||||
H = (H + this.H) | 0;
|
||||
this.set(A, B, C, D, E, F, G, H);
|
||||
}
|
||||
roundClean() {
|
||||
clean(SHA256_W);
|
||||
}
|
||||
destroy() {
|
||||
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
||||
clean(this.buffer);
|
||||
}
|
||||
}
|
||||
export class SHA224 extends SHA256 {
|
||||
constructor() {
|
||||
super(28);
|
||||
this.A = SHA224_IV[0] | 0;
|
||||
this.B = SHA224_IV[1] | 0;
|
||||
this.C = SHA224_IV[2] | 0;
|
||||
this.D = SHA224_IV[3] | 0;
|
||||
this.E = SHA224_IV[4] | 0;
|
||||
this.F = SHA224_IV[5] | 0;
|
||||
this.G = SHA224_IV[6] | 0;
|
||||
this.H = SHA224_IV[7] | 0;
|
||||
}
|
||||
}
|
||||
// SHA2-512 is slower than sha256 in js because u64 operations are slow.
|
||||
// Round contants
|
||||
// First 32 bits of the fractional parts of the cube roots of the first 80 primes 2..409
|
||||
// prettier-ignore
|
||||
const K512 = /* @__PURE__ */ (() => u64.split([
|
||||
'0x428a2f98d728ae22', '0x7137449123ef65cd', '0xb5c0fbcfec4d3b2f', '0xe9b5dba58189dbbc',
|
||||
'0x3956c25bf348b538', '0x59f111f1b605d019', '0x923f82a4af194f9b', '0xab1c5ed5da6d8118',
|
||||
'0xd807aa98a3030242', '0x12835b0145706fbe', '0x243185be4ee4b28c', '0x550c7dc3d5ffb4e2',
|
||||
'0x72be5d74f27b896f', '0x80deb1fe3b1696b1', '0x9bdc06a725c71235', '0xc19bf174cf692694',
|
||||
'0xe49b69c19ef14ad2', '0xefbe4786384f25e3', '0x0fc19dc68b8cd5b5', '0x240ca1cc77ac9c65',
|
||||
'0x2de92c6f592b0275', '0x4a7484aa6ea6e483', '0x5cb0a9dcbd41fbd4', '0x76f988da831153b5',
|
||||
'0x983e5152ee66dfab', '0xa831c66d2db43210', '0xb00327c898fb213f', '0xbf597fc7beef0ee4',
|
||||
'0xc6e00bf33da88fc2', '0xd5a79147930aa725', '0x06ca6351e003826f', '0x142929670a0e6e70',
|
||||
'0x27b70a8546d22ffc', '0x2e1b21385c26c926', '0x4d2c6dfc5ac42aed', '0x53380d139d95b3df',
|
||||
'0x650a73548baf63de', '0x766a0abb3c77b2a8', '0x81c2c92e47edaee6', '0x92722c851482353b',
|
||||
'0xa2bfe8a14cf10364', '0xa81a664bbc423001', '0xc24b8b70d0f89791', '0xc76c51a30654be30',
|
||||
'0xd192e819d6ef5218', '0xd69906245565a910', '0xf40e35855771202a', '0x106aa07032bbd1b8',
|
||||
'0x19a4c116b8d2d0c8', '0x1e376c085141ab53', '0x2748774cdf8eeb99', '0x34b0bcb5e19b48a8',
|
||||
'0x391c0cb3c5c95a63', '0x4ed8aa4ae3418acb', '0x5b9cca4f7763e373', '0x682e6ff3d6b2b8a3',
|
||||
'0x748f82ee5defb2fc', '0x78a5636f43172f60', '0x84c87814a1f0ab72', '0x8cc702081a6439ec',
|
||||
'0x90befffa23631e28', '0xa4506cebde82bde9', '0xbef9a3f7b2c67915', '0xc67178f2e372532b',
|
||||
'0xca273eceea26619c', '0xd186b8c721c0c207', '0xeada7dd6cde0eb1e', '0xf57d4f7fee6ed178',
|
||||
'0x06f067aa72176fba', '0x0a637dc5a2c898a6', '0x113f9804bef90dae', '0x1b710b35131c471b',
|
||||
'0x28db77f523047d84', '0x32caab7b40c72493', '0x3c9ebe0a15c9bebc', '0x431d67c49c100d4c',
|
||||
'0x4cc5d4becb3e42b6', '0x597f299cfc657e2a', '0x5fcb6fab3ad6faec', '0x6c44198c4a475817'
|
||||
].map(n => BigInt(n))))();
|
||||
const SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
|
||||
const SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
|
||||
// Reusable temporary buffers
|
||||
const SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
|
||||
const SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
|
||||
export class SHA512 extends HashMD {
|
||||
constructor(outputLen = 64) {
|
||||
super(128, outputLen, 16, false);
|
||||
// We cannot use array here since array allows indexing by variable
|
||||
// which means optimizer/compiler cannot use registers.
|
||||
// h -- high 32 bits, l -- low 32 bits
|
||||
this.Ah = SHA512_IV[0] | 0;
|
||||
this.Al = SHA512_IV[1] | 0;
|
||||
this.Bh = SHA512_IV[2] | 0;
|
||||
this.Bl = SHA512_IV[3] | 0;
|
||||
this.Ch = SHA512_IV[4] | 0;
|
||||
this.Cl = SHA512_IV[5] | 0;
|
||||
this.Dh = SHA512_IV[6] | 0;
|
||||
this.Dl = SHA512_IV[7] | 0;
|
||||
this.Eh = SHA512_IV[8] | 0;
|
||||
this.El = SHA512_IV[9] | 0;
|
||||
this.Fh = SHA512_IV[10] | 0;
|
||||
this.Fl = SHA512_IV[11] | 0;
|
||||
this.Gh = SHA512_IV[12] | 0;
|
||||
this.Gl = SHA512_IV[13] | 0;
|
||||
this.Hh = SHA512_IV[14] | 0;
|
||||
this.Hl = SHA512_IV[15] | 0;
|
||||
}
|
||||
// prettier-ignore
|
||||
get() {
|
||||
const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
||||
return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
|
||||
}
|
||||
// prettier-ignore
|
||||
set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
|
||||
this.Ah = Ah | 0;
|
||||
this.Al = Al | 0;
|
||||
this.Bh = Bh | 0;
|
||||
this.Bl = Bl | 0;
|
||||
this.Ch = Ch | 0;
|
||||
this.Cl = Cl | 0;
|
||||
this.Dh = Dh | 0;
|
||||
this.Dl = Dl | 0;
|
||||
this.Eh = Eh | 0;
|
||||
this.El = El | 0;
|
||||
this.Fh = Fh | 0;
|
||||
this.Fl = Fl | 0;
|
||||
this.Gh = Gh | 0;
|
||||
this.Gl = Gl | 0;
|
||||
this.Hh = Hh | 0;
|
||||
this.Hl = Hl | 0;
|
||||
}
|
||||
process(view, offset) {
|
||||
// Extend the first 16 words into the remaining 64 words w[16..79] of the message schedule array
|
||||
for (let i = 0; i < 16; i++, offset += 4) {
|
||||
SHA512_W_H[i] = view.getUint32(offset);
|
||||
SHA512_W_L[i] = view.getUint32((offset += 4));
|
||||
}
|
||||
for (let i = 16; i < 80; i++) {
|
||||
// s0 := (w[i-15] rightrotate 1) xor (w[i-15] rightrotate 8) xor (w[i-15] rightshift 7)
|
||||
const W15h = SHA512_W_H[i - 15] | 0;
|
||||
const W15l = SHA512_W_L[i - 15] | 0;
|
||||
const s0h = u64.rotrSH(W15h, W15l, 1) ^ u64.rotrSH(W15h, W15l, 8) ^ u64.shrSH(W15h, W15l, 7);
|
||||
const s0l = u64.rotrSL(W15h, W15l, 1) ^ u64.rotrSL(W15h, W15l, 8) ^ u64.shrSL(W15h, W15l, 7);
|
||||
// s1 := (w[i-2] rightrotate 19) xor (w[i-2] rightrotate 61) xor (w[i-2] rightshift 6)
|
||||
const W2h = SHA512_W_H[i - 2] | 0;
|
||||
const W2l = SHA512_W_L[i - 2] | 0;
|
||||
const s1h = u64.rotrSH(W2h, W2l, 19) ^ u64.rotrBH(W2h, W2l, 61) ^ u64.shrSH(W2h, W2l, 6);
|
||||
const s1l = u64.rotrSL(W2h, W2l, 19) ^ u64.rotrBL(W2h, W2l, 61) ^ u64.shrSL(W2h, W2l, 6);
|
||||
// SHA256_W[i] = s0 + s1 + SHA256_W[i - 7] + SHA256_W[i - 16];
|
||||
const SUMl = u64.add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
|
||||
const SUMh = u64.add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
|
||||
SHA512_W_H[i] = SUMh | 0;
|
||||
SHA512_W_L[i] = SUMl | 0;
|
||||
}
|
||||
let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
||||
// Compression function main loop, 80 rounds
|
||||
for (let i = 0; i < 80; i++) {
|
||||
// S1 := (e rightrotate 14) xor (e rightrotate 18) xor (e rightrotate 41)
|
||||
const sigma1h = u64.rotrSH(Eh, El, 14) ^ u64.rotrSH(Eh, El, 18) ^ u64.rotrBH(Eh, El, 41);
|
||||
const sigma1l = u64.rotrSL(Eh, El, 14) ^ u64.rotrSL(Eh, El, 18) ^ u64.rotrBL(Eh, El, 41);
|
||||
//const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
|
||||
const CHIh = (Eh & Fh) ^ (~Eh & Gh);
|
||||
const CHIl = (El & Fl) ^ (~El & Gl);
|
||||
// T1 = H + sigma1 + Chi(E, F, G) + SHA512_K[i] + SHA512_W[i]
|
||||
// prettier-ignore
|
||||
const T1ll = u64.add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
|
||||
const T1h = u64.add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
|
||||
const T1l = T1ll | 0;
|
||||
// S0 := (a rightrotate 28) xor (a rightrotate 34) xor (a rightrotate 39)
|
||||
const sigma0h = u64.rotrSH(Ah, Al, 28) ^ u64.rotrBH(Ah, Al, 34) ^ u64.rotrBH(Ah, Al, 39);
|
||||
const sigma0l = u64.rotrSL(Ah, Al, 28) ^ u64.rotrBL(Ah, Al, 34) ^ u64.rotrBL(Ah, Al, 39);
|
||||
const MAJh = (Ah & Bh) ^ (Ah & Ch) ^ (Bh & Ch);
|
||||
const MAJl = (Al & Bl) ^ (Al & Cl) ^ (Bl & Cl);
|
||||
Hh = Gh | 0;
|
||||
Hl = Gl | 0;
|
||||
Gh = Fh | 0;
|
||||
Gl = Fl | 0;
|
||||
Fh = Eh | 0;
|
||||
Fl = El | 0;
|
||||
({ h: Eh, l: El } = u64.add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
|
||||
Dh = Ch | 0;
|
||||
Dl = Cl | 0;
|
||||
Ch = Bh | 0;
|
||||
Cl = Bl | 0;
|
||||
Bh = Ah | 0;
|
||||
Bl = Al | 0;
|
||||
const All = u64.add3L(T1l, sigma0l, MAJl);
|
||||
Ah = u64.add3H(All, T1h, sigma0h, MAJh);
|
||||
Al = All | 0;
|
||||
}
|
||||
// Add the compressed chunk to the current hash value
|
||||
({ h: Ah, l: Al } = u64.add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
|
||||
({ h: Bh, l: Bl } = u64.add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
|
||||
({ h: Ch, l: Cl } = u64.add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
|
||||
({ h: Dh, l: Dl } = u64.add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
|
||||
({ h: Eh, l: El } = u64.add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
|
||||
({ h: Fh, l: Fl } = u64.add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
|
||||
({ h: Gh, l: Gl } = u64.add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
|
||||
({ h: Hh, l: Hl } = u64.add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
|
||||
this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
|
||||
}
|
||||
roundClean() {
|
||||
clean(SHA512_W_H, SHA512_W_L);
|
||||
}
|
||||
destroy() {
|
||||
clean(this.buffer);
|
||||
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
export class SHA384 extends SHA512 {
|
||||
constructor() {
|
||||
super(48);
|
||||
this.Ah = SHA384_IV[0] | 0;
|
||||
this.Al = SHA384_IV[1] | 0;
|
||||
this.Bh = SHA384_IV[2] | 0;
|
||||
this.Bl = SHA384_IV[3] | 0;
|
||||
this.Ch = SHA384_IV[4] | 0;
|
||||
this.Cl = SHA384_IV[5] | 0;
|
||||
this.Dh = SHA384_IV[6] | 0;
|
||||
this.Dl = SHA384_IV[7] | 0;
|
||||
this.Eh = SHA384_IV[8] | 0;
|
||||
this.El = SHA384_IV[9] | 0;
|
||||
this.Fh = SHA384_IV[10] | 0;
|
||||
this.Fl = SHA384_IV[11] | 0;
|
||||
this.Gh = SHA384_IV[12] | 0;
|
||||
this.Gl = SHA384_IV[13] | 0;
|
||||
this.Hh = SHA384_IV[14] | 0;
|
||||
this.Hl = SHA384_IV[15] | 0;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Truncated SHA512/256 and SHA512/224.
|
||||
* SHA512_IV is XORed with 0xa5a5a5a5a5a5a5a5, then used as "intermediary" IV of SHA512/t.
|
||||
* Then t hashes string to produce result IV.
|
||||
* See `test/misc/sha2-gen-iv.js`.
|
||||
*/
|
||||
/** SHA512/224 IV */
|
||||
const T224_IV = /* @__PURE__ */ Uint32Array.from([
|
||||
0x8c3d37c8, 0x19544da2, 0x73e19966, 0x89dcd4d6, 0x1dfab7ae, 0x32ff9c82, 0x679dd514, 0x582f9fcf,
|
||||
0x0f6d2b69, 0x7bd44da8, 0x77e36f73, 0x04c48942, 0x3f9d85a8, 0x6a1d36c8, 0x1112e6ad, 0x91d692a1,
|
||||
]);
|
||||
/** SHA512/256 IV */
|
||||
const T256_IV = /* @__PURE__ */ Uint32Array.from([
|
||||
0x22312194, 0xfc2bf72c, 0x9f555fa3, 0xc84c64c2, 0x2393b86b, 0x6f53b151, 0x96387719, 0x5940eabd,
|
||||
0x96283ee2, 0xa88effe3, 0xbe5e1e25, 0x53863992, 0x2b0199fc, 0x2c85b8aa, 0x0eb72ddc, 0x81c52ca2,
|
||||
]);
|
||||
export class SHA512_224 extends SHA512 {
|
||||
constructor() {
|
||||
super(28);
|
||||
this.Ah = T224_IV[0] | 0;
|
||||
this.Al = T224_IV[1] | 0;
|
||||
this.Bh = T224_IV[2] | 0;
|
||||
this.Bl = T224_IV[3] | 0;
|
||||
this.Ch = T224_IV[4] | 0;
|
||||
this.Cl = T224_IV[5] | 0;
|
||||
this.Dh = T224_IV[6] | 0;
|
||||
this.Dl = T224_IV[7] | 0;
|
||||
this.Eh = T224_IV[8] | 0;
|
||||
this.El = T224_IV[9] | 0;
|
||||
this.Fh = T224_IV[10] | 0;
|
||||
this.Fl = T224_IV[11] | 0;
|
||||
this.Gh = T224_IV[12] | 0;
|
||||
this.Gl = T224_IV[13] | 0;
|
||||
this.Hh = T224_IV[14] | 0;
|
||||
this.Hl = T224_IV[15] | 0;
|
||||
}
|
||||
}
|
||||
export class SHA512_256 extends SHA512 {
|
||||
constructor() {
|
||||
super(32);
|
||||
this.Ah = T256_IV[0] | 0;
|
||||
this.Al = T256_IV[1] | 0;
|
||||
this.Bh = T256_IV[2] | 0;
|
||||
this.Bl = T256_IV[3] | 0;
|
||||
this.Ch = T256_IV[4] | 0;
|
||||
this.Cl = T256_IV[5] | 0;
|
||||
this.Dh = T256_IV[6] | 0;
|
||||
this.Dl = T256_IV[7] | 0;
|
||||
this.Eh = T256_IV[8] | 0;
|
||||
this.El = T256_IV[9] | 0;
|
||||
this.Fh = T256_IV[10] | 0;
|
||||
this.Fl = T256_IV[11] | 0;
|
||||
this.Gh = T256_IV[12] | 0;
|
||||
this.Gl = T256_IV[13] | 0;
|
||||
this.Hh = T256_IV[14] | 0;
|
||||
this.Hl = T256_IV[15] | 0;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* SHA2-256 hash function from RFC 4634.
|
||||
*
|
||||
* It is the fastest JS hash, even faster than Blake3.
|
||||
* To break sha256 using birthday attack, attackers need to try 2^128 hashes.
|
||||
* BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per 2025.
|
||||
*/
|
||||
export const sha256 = /* @__PURE__ */ createHasher(() => new SHA256());
|
||||
/** SHA2-224 hash function from RFC 4634 */
|
||||
export const sha224 = /* @__PURE__ */ createHasher(() => new SHA224());
|
||||
/** SHA2-512 hash function from RFC 4634. */
|
||||
export const sha512 = /* @__PURE__ */ createHasher(() => new SHA512());
|
||||
/** SHA2-384 hash function from RFC 4634. */
|
||||
export const sha384 = /* @__PURE__ */ createHasher(() => new SHA384());
|
||||
/**
|
||||
* SHA2-512/256 "truncated" hash function, with improved resistance to length extension attacks.
|
||||
* See the paper on [truncated SHA512](https://eprint.iacr.org/2010/548.pdf).
|
||||
*/
|
||||
export const sha512_256 = /* @__PURE__ */ createHasher(() => new SHA512_256());
|
||||
/**
|
||||
* SHA2-512/224 "truncated" hash function, with improved resistance to length extension attacks.
|
||||
* See the paper on [truncated SHA512](https://eprint.iacr.org/2010/548.pdf).
|
||||
*/
|
||||
export const sha512_224 = /* @__PURE__ */ createHasher(() => new SHA512_224());
|
||||
//# sourceMappingURL=sha2.js.map
|
||||
@@ -0,0 +1,75 @@
|
||||
'use strict';
|
||||
|
||||
const utils = require('../utils');
|
||||
|
||||
/**
|
||||
* Creates a Connect/Express compatible middleware bound to a Server
|
||||
* @class ServerMiddleware
|
||||
* @param {Server} server Server instance
|
||||
* @param {Object} [outerOptions] Specific options for the middleware
|
||||
* @return {Function}
|
||||
*/
|
||||
const Middleware = function(server, outerOptions) {
|
||||
return function(req, res, next) {
|
||||
const options = utils.merge(server.options, outerOptions || {});
|
||||
|
||||
// default options.end to true
|
||||
if(typeof(options.end) !== 'boolean') {
|
||||
options.end = true;
|
||||
}
|
||||
|
||||
// 405 method not allowed if not POST
|
||||
if(!utils.isMethod(req, 'POST')) {
|
||||
return error(405, { 'Allow': 'POST' });
|
||||
}
|
||||
|
||||
// 415 unsupported media type if Content-Type is not correct
|
||||
if(!utils.isContentType(req, 'application/json')) {
|
||||
return error(415);
|
||||
}
|
||||
|
||||
// body does not appear to be parsed, 500 server error
|
||||
if(!req.body || typeof(req.body) !== 'object') {
|
||||
return next(new Error('Request body must be parsed'));
|
||||
}
|
||||
|
||||
server.call(req.body, function(error, success) {
|
||||
const response = error || success;
|
||||
|
||||
utils.JSON.stringify(response, options, function(err, body) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
// empty response?
|
||||
if(body) {
|
||||
const headers = {
|
||||
'content-length': Buffer.byteLength(body, options.encoding),
|
||||
'content-type': 'application/json; charset=utf-8'
|
||||
};
|
||||
|
||||
res.writeHead(200, headers);
|
||||
res.write(body);
|
||||
} else {
|
||||
res.writeHead(204);
|
||||
}
|
||||
|
||||
// if end is false, next request instead of ending it
|
||||
if(options.end) {
|
||||
res.end();
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
// ends the request with an error code
|
||||
function error(code, headers) {
|
||||
res.writeHead(code, headers || {});
|
||||
res.end();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = Middleware;
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"buffer-reader.js","sourceRoot":"","sources":["../src/buffer-reader.ts"],"names":[],"mappings":";;;AAAA,MAAa,YAAY;IAMvB,YAAoB,SAAiB,CAAC;QAAlB,WAAM,GAAN,MAAM,CAAY;QAL9B,WAAM,GAAW,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAA;QAE9C,wCAAwC;QAChC,aAAQ,GAAmB,OAAO,CAAA;IAED,CAAC;IAEnC,SAAS,CAAC,MAAc,EAAE,MAAc;QAC7C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAEM,KAAK;QACV,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACnD,IAAI,CAAC,MAAM,IAAI,CAAC,CAAA;QAChB,OAAO,MAAM,CAAA;IACf,CAAC;IAEM,IAAI;QACT,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACvC,IAAI,CAAC,MAAM,EAAE,CAAA;QACb,OAAO,MAAM,CAAA;IACf,CAAC;IAEM,KAAK;QACV,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACnD,IAAI,CAAC,MAAM,IAAI,CAAC,CAAA;QAChB,OAAO,MAAM,CAAA;IACf,CAAC;IAEM,MAAM;QACX,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACpD,IAAI,CAAC,MAAM,IAAI,CAAC,CAAA;QAChB,OAAO,MAAM,CAAA;IACf,CAAC;IAEM,MAAM,CAAC,MAAc;QAC1B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,CAAA;QACrF,IAAI,CAAC,MAAM,IAAI,MAAM,CAAA;QACrB,OAAO,MAAM,CAAA;IACf,CAAC;IAEM,OAAO;QACZ,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAA;QACzB,IAAI,GAAG,GAAG,KAAK,CAAA;QACf,oCAAoC;QACpC,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAA,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,GAAG,CAAA;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC,CAAC,CAAA;IAC5D,CAAC;IAEM,KAAK,CAAC,MAAc;QACzB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,CAAA;QACnE,IAAI,CAAC,MAAM,IAAI,MAAM,CAAA;QACrB,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AAzDD,oCAyDC"}
|
||||
@@ -0,0 +1,8 @@
|
||||
function _defineAccessor(e, r, n, t) {
|
||||
var c = {
|
||||
configurable: !0,
|
||||
enumerable: !0
|
||||
};
|
||||
return c[e] = t, Object.defineProperty(r, n, c);
|
||||
}
|
||||
export { _defineAccessor as default };
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"main": "../../cjs/_ts_values.cjs",
|
||||
"module": "../../esm/_ts_values.js"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// Code generated by Herebyfile.mjs generate:enums from internal/checker/types.go. DO NOT EDIT.
|
||||
export var ElementFlags;
|
||||
(function (ElementFlags) {
|
||||
ElementFlags[ElementFlags["None"] = 0] = "None";
|
||||
ElementFlags[ElementFlags["Required"] = 1] = "Required";
|
||||
ElementFlags[ElementFlags["Optional"] = 2] = "Optional";
|
||||
ElementFlags[ElementFlags["Rest"] = 4] = "Rest";
|
||||
ElementFlags[ElementFlags["Variadic"] = 8] = "Variadic";
|
||||
ElementFlags[ElementFlags["Fixed"] = 3] = "Fixed";
|
||||
ElementFlags[ElementFlags["Variable"] = 12] = "Variable";
|
||||
ElementFlags[ElementFlags["NonRequired"] = 14] = "NonRequired";
|
||||
ElementFlags[ElementFlags["NonRest"] = 11] = "NonRest";
|
||||
})(ElementFlags || (ElementFlags = {}));
|
||||
//# sourceMappingURL=elementFlags.enum.js.map
|
||||
@@ -0,0 +1,16 @@
|
||||
import type { TSESTree } from '@typescript-eslint/utils';
|
||||
import type { InferMessageIdsTypeFromRule, InferOptionsTypeFromRule } from '../util';
|
||||
declare const baseRule: import("@typescript-eslint/utils/ts-eslint").RuleModule<"suggestComment" | "unexpected", [{
|
||||
allow?: string[];
|
||||
}], unknown, {
|
||||
FunctionDeclaration(node: TSESTree.FunctionDeclaration): void;
|
||||
FunctionExpression(node: TSESTree.FunctionExpression): void;
|
||||
}>;
|
||||
export type Options = InferOptionsTypeFromRule<typeof baseRule>;
|
||||
export type MessageIds = InferMessageIdsTypeFromRule<typeof baseRule>;
|
||||
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"suggestComment" | "unexpected", [{
|
||||
allow?: string[];
|
||||
}], import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
||||
name: string;
|
||||
};
|
||||
export default _default;
|
||||
@@ -0,0 +1,15 @@
|
||||
The ISC License
|
||||
|
||||
Copyright (c) Isaac Z. Schlueter and Contributors
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = function (it) {
|
||||
const { configName, importerName } = it;
|
||||
|
||||
return `
|
||||
ESLint couldn't find the config "${configName}" to extend from. Please check that the name of the config is correct.
|
||||
|
||||
The config "${configName}" was referenced from the config file in "${importerName}".
|
||||
|
||||
If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.
|
||||
`.trimStart();
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"uselessExport", [], import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
||||
name: string;
|
||||
};
|
||||
export default _default;
|
||||
@@ -0,0 +1,5 @@
|
||||
import assertClassBrand from "./assertClassBrand.js";
|
||||
function _classPrivateMethodGet(s, a, r) {
|
||||
return assertClassBrand(a, s), r;
|
||||
}
|
||||
export { _classPrivateMethodGet as default };
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"internalSymbolName.d.ts","sourceRoot":"","sources":["../../src/enums/internalSymbolName.ts"],"names":[],"mappings":"AACA,eAAO,IAAI,kBAAkB,EAAE,GAAG,CAAC"}
|
||||
@@ -0,0 +1,195 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const utils_1 = require("@typescript-eslint/utils");
|
||||
const util_1 = require("../util");
|
||||
const defaultMinimumDescriptionLength = 3;
|
||||
exports.default = (0, util_1.createRule)({
|
||||
name: 'ban-ts-comment',
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'Disallow `@ts-<directive>` comments or require descriptions after directives',
|
||||
recommended: {
|
||||
recommended: true,
|
||||
strict: [{ minimumDescriptionLength: 10 }],
|
||||
},
|
||||
},
|
||||
hasSuggestions: true,
|
||||
messages: {
|
||||
replaceTsIgnoreWithTsExpectError: 'Replace "@ts-ignore" with "@ts-expect-error".',
|
||||
tsDirectiveComment: 'Do not use "@ts-{{directive}}" because it alters compilation errors.',
|
||||
tsDirectiveCommentDescriptionNotMatchPattern: 'The description for the "@ts-{{directive}}" directive must match the {{format}} format.',
|
||||
tsDirectiveCommentRequiresDescription: 'Include a description after the "@ts-{{directive}}" directive to explain why the @ts-{{directive}} is necessary. The description must be {{minimumDescriptionLength}} characters or longer.',
|
||||
tsIgnoreInsteadOfExpectError: 'Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free.',
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
type: 'object',
|
||||
$defs: {
|
||||
directiveConfigSchema: {
|
||||
oneOf: [
|
||||
{
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
{
|
||||
type: 'string',
|
||||
enum: ['allow-with-description'],
|
||||
},
|
||||
{
|
||||
type: 'object',
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
descriptionFormat: { type: 'string' },
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
minimumDescriptionLength: {
|
||||
type: 'number',
|
||||
description: 'A minimum character length for descriptions when `allow-with-description` is enabled.',
|
||||
},
|
||||
'ts-check': {
|
||||
$ref: '#/items/0/$defs/directiveConfigSchema',
|
||||
description: 'Whether to allow ts-check directives, and with which restrictions.',
|
||||
},
|
||||
'ts-expect-error': {
|
||||
$ref: '#/items/0/$defs/directiveConfigSchema',
|
||||
description: 'Whether to allow ts-expect-error directives, and with which restrictions.',
|
||||
},
|
||||
'ts-ignore': {
|
||||
$ref: '#/items/0/$defs/directiveConfigSchema',
|
||||
description: 'Whether to allow ts-ignore directives, and with which restrictions.',
|
||||
},
|
||||
'ts-nocheck': {
|
||||
$ref: '#/items/0/$defs/directiveConfigSchema',
|
||||
description: 'Whether to allow ts-nocheck directives, and with which restrictions.',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
defaultOptions: [
|
||||
{
|
||||
minimumDescriptionLength: defaultMinimumDescriptionLength,
|
||||
'ts-check': false,
|
||||
'ts-expect-error': 'allow-with-description',
|
||||
'ts-ignore': true,
|
||||
'ts-nocheck': true,
|
||||
},
|
||||
],
|
||||
create(context, [options]) {
|
||||
// https://github.com/microsoft/TypeScript/blob/6f1ad5ad8bec5671f7e951a3524b62d82ec4be68/src/compiler/parser.ts#L10591
|
||||
const singleLinePragmaRegEx = /^\/\/\/?\s*@ts-(?<directive>check|nocheck)(?<description>.*)$/;
|
||||
/*
|
||||
The regex used are taken from the ones used in the official TypeScript repo -
|
||||
https://github.com/microsoft/TypeScript/blob/6f1ad5ad8bec5671f7e951a3524b62d82ec4be68/src/compiler/scanner.ts#L340-L348
|
||||
*/
|
||||
const commentDirectiveRegExSingleLine = /^\/*\s*@ts-(?<directive>expect-error|ignore)(?<description>.*)/;
|
||||
const commentDirectiveRegExMultiLine = /^\s*(?:\/|\*)*\s*@ts-(?<directive>expect-error|ignore)(?<description>.*)/;
|
||||
const descriptionFormats = new Map();
|
||||
for (const directive of [
|
||||
'ts-expect-error',
|
||||
'ts-ignore',
|
||||
'ts-nocheck',
|
||||
'ts-check',
|
||||
]) {
|
||||
const option = options[directive];
|
||||
if (typeof option === 'object' && option.descriptionFormat) {
|
||||
descriptionFormats.set(directive, new RegExp(option.descriptionFormat));
|
||||
}
|
||||
}
|
||||
function execDirectiveRegEx(regex, str) {
|
||||
const match = regex.exec(str);
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
const { description, directive } = (0, util_1.nullThrows)(match.groups, 'RegExp should contain groups');
|
||||
return {
|
||||
description: (0, util_1.nullThrows)(description, 'RegExp should contain "description" group'),
|
||||
directive: (0, util_1.nullThrows)(directive, 'RegExp should contain "directive" group'),
|
||||
};
|
||||
}
|
||||
function findDirectiveInComment(comment) {
|
||||
if (comment.type === utils_1.AST_TOKEN_TYPES.Line) {
|
||||
const matchedPragma = execDirectiveRegEx(singleLinePragmaRegEx, `//${comment.value}`);
|
||||
if (matchedPragma) {
|
||||
return matchedPragma;
|
||||
}
|
||||
return execDirectiveRegEx(commentDirectiveRegExSingleLine, comment.value);
|
||||
}
|
||||
const commentLines = comment.value.split(utils_1.ASTUtils.LINEBREAK_MATCHER);
|
||||
return execDirectiveRegEx(commentDirectiveRegExMultiLine, commentLines[commentLines.length - 1]);
|
||||
}
|
||||
return {
|
||||
Program(node) {
|
||||
const firstStatement = node.body.at(0);
|
||||
const comments = context.sourceCode.getAllComments();
|
||||
comments.forEach(comment => {
|
||||
const match = findDirectiveInComment(comment);
|
||||
if (!match) {
|
||||
return;
|
||||
}
|
||||
const { description, directive } = match;
|
||||
if (directive === 'nocheck' &&
|
||||
firstStatement &&
|
||||
firstStatement.loc.start.line <= comment.loc.start.line) {
|
||||
return;
|
||||
}
|
||||
const fullDirective = `ts-${directive}`;
|
||||
const option = options[fullDirective];
|
||||
if (option === true) {
|
||||
if (directive === 'ignore') {
|
||||
// Special case to suggest @ts-expect-error instead of @ts-ignore
|
||||
context.report({
|
||||
node: comment,
|
||||
messageId: 'tsIgnoreInsteadOfExpectError',
|
||||
suggest: [
|
||||
{
|
||||
messageId: 'replaceTsIgnoreWithTsExpectError',
|
||||
fix(fixer) {
|
||||
const commentText = comment.value.replace(/@ts-ignore/, '@ts-expect-error');
|
||||
return fixer.replaceText(comment, comment.type === utils_1.AST_TOKEN_TYPES.Line
|
||||
? `//${commentText}`
|
||||
: `/*${commentText}*/`);
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
else {
|
||||
context.report({
|
||||
node: comment,
|
||||
messageId: 'tsDirectiveComment',
|
||||
data: { directive },
|
||||
});
|
||||
}
|
||||
}
|
||||
if (option === 'allow-with-description' ||
|
||||
(typeof option === 'object' && option.descriptionFormat)) {
|
||||
const { minimumDescriptionLength } = options;
|
||||
const format = descriptionFormats.get(fullDirective);
|
||||
if ((0, util_1.getStringLength)(description.trim()) <
|
||||
(0, util_1.nullThrows)(minimumDescriptionLength, 'Expected minimumDescriptionLength to be set')) {
|
||||
context.report({
|
||||
node: comment,
|
||||
messageId: 'tsDirectiveCommentRequiresDescription',
|
||||
data: { directive, minimumDescriptionLength },
|
||||
});
|
||||
}
|
||||
else if (format && !format.test(description)) {
|
||||
context.report({
|
||||
node: comment,
|
||||
messageId: 'tsDirectiveCommentDescriptionNotMatchPattern',
|
||||
data: { directive, format: format.source },
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,223 @@
|
||||
/**
|
||||
* @fileoverview Translates CLI options into ESLint constructor options.
|
||||
* @author Nicholas C. Zakas
|
||||
* @author Francesco Trotta
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const { normalizeSeverityToString } = require("./severity");
|
||||
const { getShorthandName, normalizePackageName } = require("./naming");
|
||||
const { ModuleImporter } = require("@humanwhocodes/module-importer");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Types
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @typedef {import("../types").ESLint.Options} ESLintOptions */
|
||||
/** @typedef {import("../types").Linter.LintMessage} LintMessage */
|
||||
/** @typedef {import("../options").ParsedCLIOptions} ParsedCLIOptions */
|
||||
/** @typedef {import("../types").ESLint.Plugin} Plugin */
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Loads plugins with the specified names.
|
||||
* @param {{ "import": (name: string) => Promise<any> }} importer An object with an `import` method called once for each plugin.
|
||||
* @param {string[]} pluginNames The names of the plugins to be loaded, with or without the "eslint-plugin-" prefix.
|
||||
* @returns {Promise<Record<string, Plugin>>} A mapping of plugin short names to implementations.
|
||||
*/
|
||||
async function loadPlugins(importer, pluginNames) {
|
||||
const plugins = {};
|
||||
|
||||
await Promise.all(
|
||||
pluginNames.map(async pluginName => {
|
||||
const longName = normalizePackageName(pluginName, "eslint-plugin");
|
||||
const module = await importer.import(longName);
|
||||
|
||||
if (!("default" in module)) {
|
||||
throw new Error(
|
||||
`"${longName}" cannot be used with the \`--plugin\` option because its default module does not provide a \`default\` export`,
|
||||
);
|
||||
}
|
||||
|
||||
const shortName = getShorthandName(pluginName, "eslint-plugin");
|
||||
|
||||
plugins[shortName] = module.default;
|
||||
}),
|
||||
);
|
||||
|
||||
return plugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Predicate function for whether or not to apply fixes in quiet mode.
|
||||
* If a message is a warning, do not apply a fix.
|
||||
* @param {LintMessage} message The lint result.
|
||||
* @returns {boolean} `true` if the lint message is an error (and thus should be
|
||||
* autofixed), `false` otherwise.
|
||||
*/
|
||||
function quietFixPredicate(message) {
|
||||
return message.severity === 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Predicate function for whether or not to run a rule in quiet mode.
|
||||
* If a rule is set to warning, do not run it.
|
||||
* @param {{ ruleId: string; severity: number; }} rule The rule id and severity.
|
||||
* @returns {boolean} `true` if the lint rule should run, `false` otherwise.
|
||||
*/
|
||||
function quietRuleFilter(rule) {
|
||||
return rule.severity === 2;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Public Interface
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Translates the CLI options into the options expected by the ESLint constructor.
|
||||
* @param {ParsedCLIOptions} cliOptions The CLI options to translate.
|
||||
* @returns {Promise<ESLintOptions>} The options object for the ESLint constructor.
|
||||
*/
|
||||
async function translateOptions({
|
||||
cache,
|
||||
cacheFile,
|
||||
cacheLocation,
|
||||
cacheStrategy,
|
||||
concurrency,
|
||||
config,
|
||||
configLookup,
|
||||
errorOnUnmatchedPattern,
|
||||
ext,
|
||||
fix,
|
||||
fixDryRun,
|
||||
fixType,
|
||||
flag,
|
||||
global,
|
||||
ignore,
|
||||
ignorePattern,
|
||||
inlineConfig,
|
||||
parser,
|
||||
parserOptions,
|
||||
plugin,
|
||||
quiet,
|
||||
reportUnusedDisableDirectives,
|
||||
reportUnusedDisableDirectivesSeverity,
|
||||
reportUnusedInlineConfigs,
|
||||
rule,
|
||||
stats,
|
||||
warnIgnored,
|
||||
passOnNoPatterns,
|
||||
maxWarnings,
|
||||
}) {
|
||||
const importer = new ModuleImporter();
|
||||
|
||||
let overrideConfigFile =
|
||||
typeof config === "string" ? config : !configLookup;
|
||||
if (overrideConfigFile === false) {
|
||||
overrideConfigFile = void 0;
|
||||
}
|
||||
|
||||
const languageOptions = {};
|
||||
|
||||
if (global) {
|
||||
languageOptions.globals = global.reduce((obj, name) => {
|
||||
if (name.endsWith(":true")) {
|
||||
obj[name.slice(0, -5)] = "writable";
|
||||
} else {
|
||||
obj[name] = "readonly";
|
||||
}
|
||||
return obj;
|
||||
}, {});
|
||||
}
|
||||
|
||||
if (parserOptions) {
|
||||
languageOptions.parserOptions = parserOptions;
|
||||
}
|
||||
|
||||
if (parser) {
|
||||
languageOptions.parser = await importer.import(parser);
|
||||
}
|
||||
|
||||
const overrideConfig = [
|
||||
{
|
||||
...(Object.keys(languageOptions).length > 0
|
||||
? { languageOptions }
|
||||
: {}),
|
||||
rules: rule ? rule : {},
|
||||
},
|
||||
];
|
||||
|
||||
if (
|
||||
reportUnusedDisableDirectives ||
|
||||
reportUnusedDisableDirectivesSeverity !== void 0
|
||||
) {
|
||||
overrideConfig[0].linterOptions = {
|
||||
reportUnusedDisableDirectives: reportUnusedDisableDirectives
|
||||
? "error"
|
||||
: normalizeSeverityToString(
|
||||
reportUnusedDisableDirectivesSeverity,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
if (reportUnusedInlineConfigs !== void 0) {
|
||||
overrideConfig[0].linterOptions = {
|
||||
...overrideConfig[0].linterOptions,
|
||||
reportUnusedInlineConfigs: normalizeSeverityToString(
|
||||
reportUnusedInlineConfigs,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
if (plugin) {
|
||||
overrideConfig[0].plugins = await loadPlugins(importer, plugin);
|
||||
}
|
||||
|
||||
if (ext) {
|
||||
overrideConfig.push({
|
||||
files: ext.map(
|
||||
extension =>
|
||||
`**/*${extension.startsWith(".") ? "" : "."}${extension}`,
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* For performance reasons rules not marked as 'error' are filtered out in quiet mode. As maxWarnings
|
||||
* requires rules set to 'warn' to be run, we only filter out 'warn' rules if maxWarnings is not specified.
|
||||
*/
|
||||
const ruleFilter =
|
||||
quiet && maxWarnings === -1 ? quietRuleFilter : () => true;
|
||||
|
||||
const options = {
|
||||
allowInlineConfig: inlineConfig,
|
||||
cache,
|
||||
cacheLocation: cacheLocation || cacheFile,
|
||||
cacheStrategy,
|
||||
concurrency,
|
||||
errorOnUnmatchedPattern,
|
||||
fix: (fix || fixDryRun) && (quiet ? quietFixPredicate : true),
|
||||
fixTypes: fixType,
|
||||
flags: flag,
|
||||
ignore,
|
||||
ignorePatterns: ignorePattern,
|
||||
overrideConfig,
|
||||
overrideConfigFile,
|
||||
passOnNoPatterns,
|
||||
ruleFilter,
|
||||
stats,
|
||||
warnIgnored,
|
||||
};
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
module.exports = translateOptions;
|
||||
@@ -0,0 +1,133 @@
|
||||
// @ts-ignore TS6133
|
||||
import { expect, test } from "vitest";
|
||||
|
||||
import * as z from "zod/v3";
|
||||
|
||||
test("string coercion", () => {
|
||||
const schema = z.coerce.string();
|
||||
expect(schema.parse("sup")).toEqual("sup");
|
||||
expect(schema.parse("")).toEqual("");
|
||||
expect(schema.parse(12)).toEqual("12");
|
||||
expect(schema.parse(0)).toEqual("0");
|
||||
expect(schema.parse(-12)).toEqual("-12");
|
||||
expect(schema.parse(3.14)).toEqual("3.14");
|
||||
expect(schema.parse(BigInt(15))).toEqual("15");
|
||||
expect(schema.parse(Number.NaN)).toEqual("NaN");
|
||||
expect(schema.parse(Number.POSITIVE_INFINITY)).toEqual("Infinity");
|
||||
expect(schema.parse(Number.NEGATIVE_INFINITY)).toEqual("-Infinity");
|
||||
expect(schema.parse(true)).toEqual("true");
|
||||
expect(schema.parse(false)).toEqual("false");
|
||||
expect(schema.parse(null)).toEqual("null");
|
||||
expect(schema.parse(undefined)).toEqual("undefined");
|
||||
expect(schema.parse({ hello: "world!" })).toEqual("[object Object]");
|
||||
expect(schema.parse(["item", "another_item"])).toEqual("item,another_item");
|
||||
expect(schema.parse([])).toEqual("");
|
||||
expect(schema.parse(new Date("2022-01-01T00:00:00.000Z"))).toEqual(new Date("2022-01-01T00:00:00.000Z").toString());
|
||||
});
|
||||
|
||||
test("number coercion", () => {
|
||||
const schema = z.coerce.number();
|
||||
expect(schema.parse("12")).toEqual(12);
|
||||
expect(schema.parse("0")).toEqual(0);
|
||||
expect(schema.parse("-12")).toEqual(-12);
|
||||
expect(schema.parse("3.14")).toEqual(3.14);
|
||||
expect(schema.parse("")).toEqual(0);
|
||||
expect(() => schema.parse("NOT_A_NUMBER")).toThrow(); // z.ZodError
|
||||
expect(schema.parse(12)).toEqual(12);
|
||||
expect(schema.parse(0)).toEqual(0);
|
||||
expect(schema.parse(-12)).toEqual(-12);
|
||||
expect(schema.parse(3.14)).toEqual(3.14);
|
||||
expect(schema.parse(BigInt(15))).toEqual(15);
|
||||
expect(() => schema.parse(Number.NaN)).toThrow(); // z.ZodError
|
||||
expect(schema.parse(Number.POSITIVE_INFINITY)).toEqual(Number.POSITIVE_INFINITY);
|
||||
expect(schema.parse(Number.NEGATIVE_INFINITY)).toEqual(Number.NEGATIVE_INFINITY);
|
||||
expect(schema.parse(true)).toEqual(1);
|
||||
expect(schema.parse(false)).toEqual(0);
|
||||
expect(schema.parse(null)).toEqual(0);
|
||||
expect(() => schema.parse(undefined)).toThrow(); // z.ZodError
|
||||
expect(() => schema.parse({ hello: "world!" })).toThrow(); // z.ZodError
|
||||
expect(() => schema.parse(["item", "another_item"])).toThrow(); // z.ZodError
|
||||
expect(schema.parse([])).toEqual(0);
|
||||
expect(schema.parse(new Date(1670139203496))).toEqual(1670139203496);
|
||||
});
|
||||
|
||||
test("boolean coercion", () => {
|
||||
const schema = z.coerce.boolean();
|
||||
expect(schema.parse("true")).toEqual(true);
|
||||
expect(schema.parse("false")).toEqual(true);
|
||||
expect(schema.parse("0")).toEqual(true);
|
||||
expect(schema.parse("1")).toEqual(true);
|
||||
expect(schema.parse("")).toEqual(false);
|
||||
expect(schema.parse(1)).toEqual(true);
|
||||
expect(schema.parse(0)).toEqual(false);
|
||||
expect(schema.parse(-1)).toEqual(true);
|
||||
expect(schema.parse(3.14)).toEqual(true);
|
||||
expect(schema.parse(BigInt(15))).toEqual(true);
|
||||
expect(schema.parse(Number.NaN)).toEqual(false);
|
||||
expect(schema.parse(Number.POSITIVE_INFINITY)).toEqual(true);
|
||||
expect(schema.parse(Number.NEGATIVE_INFINITY)).toEqual(true);
|
||||
expect(schema.parse(true)).toEqual(true);
|
||||
expect(schema.parse(false)).toEqual(false);
|
||||
expect(schema.parse(null)).toEqual(false);
|
||||
expect(schema.parse(undefined)).toEqual(false);
|
||||
expect(schema.parse({ hello: "world!" })).toEqual(true);
|
||||
expect(schema.parse(["item", "another_item"])).toEqual(true);
|
||||
expect(schema.parse([])).toEqual(true);
|
||||
expect(schema.parse(new Date(1670139203496))).toEqual(true);
|
||||
});
|
||||
|
||||
test("bigint coercion", () => {
|
||||
const schema = z.coerce.bigint();
|
||||
expect(schema.parse("5")).toEqual(BigInt(5));
|
||||
expect(schema.parse("0")).toEqual(BigInt(0));
|
||||
expect(schema.parse("-5")).toEqual(BigInt(-5));
|
||||
expect(() => schema.parse("3.14")).toThrow(); // not a z.ZodError!
|
||||
expect(schema.parse("")).toEqual(BigInt(0));
|
||||
expect(() => schema.parse("NOT_A_NUMBER")).toThrow(); // not a z.ZodError!
|
||||
expect(schema.parse(5)).toEqual(BigInt(5));
|
||||
expect(schema.parse(0)).toEqual(BigInt(0));
|
||||
expect(schema.parse(-5)).toEqual(BigInt(-5));
|
||||
expect(() => schema.parse(3.14)).toThrow(); // not a z.ZodError!
|
||||
expect(schema.parse(BigInt(5))).toEqual(BigInt(5));
|
||||
expect(() => schema.parse(Number.NaN)).toThrow(); // not a z.ZodError!
|
||||
expect(() => schema.parse(Number.POSITIVE_INFINITY)).toThrow(); // not a z.ZodError!
|
||||
expect(() => schema.parse(Number.NEGATIVE_INFINITY)).toThrow(); // not a z.ZodError!
|
||||
expect(schema.parse(true)).toEqual(BigInt(1));
|
||||
expect(schema.parse(false)).toEqual(BigInt(0));
|
||||
expect(() => schema.parse(null)).toThrow(); // not a z.ZodError!
|
||||
expect(() => schema.parse(undefined)).toThrow(); // not a z.ZodError!
|
||||
expect(() => schema.parse({ hello: "world!" })).toThrow(); // not a z.ZodError!
|
||||
expect(() => schema.parse(["item", "another_item"])).toThrow(); // not a z.ZodError!
|
||||
expect(schema.parse([])).toEqual(BigInt(0));
|
||||
expect(schema.parse(new Date(1670139203496))).toEqual(BigInt(1670139203496));
|
||||
});
|
||||
|
||||
test("date coercion", () => {
|
||||
const schema = z.coerce.date();
|
||||
expect(schema.parse(new Date().toDateString())).toBeInstanceOf(Date);
|
||||
expect(schema.parse(new Date().toISOString())).toBeInstanceOf(Date);
|
||||
expect(schema.parse(new Date().toUTCString())).toBeInstanceOf(Date);
|
||||
expect(schema.parse("5")).toBeInstanceOf(Date);
|
||||
expect(schema.parse("2000-01-01")).toBeInstanceOf(Date);
|
||||
// expect(schema.parse("0")).toBeInstanceOf(Date);
|
||||
// expect(schema.parse("-5")).toBeInstanceOf(Date);
|
||||
// expect(schema.parse("3.14")).toBeInstanceOf(Date);
|
||||
expect(() => schema.parse("")).toThrow(); // z.ZodError
|
||||
expect(() => schema.parse("NOT_A_DATE")).toThrow(); // z.ZodError
|
||||
expect(schema.parse(5)).toBeInstanceOf(Date);
|
||||
expect(schema.parse(0)).toBeInstanceOf(Date);
|
||||
expect(schema.parse(-5)).toBeInstanceOf(Date);
|
||||
expect(schema.parse(3.14)).toBeInstanceOf(Date);
|
||||
expect(() => schema.parse(BigInt(5))).toThrow(); // not a z.ZodError!
|
||||
expect(() => schema.parse(Number.NaN)).toThrow(); // z.ZodError
|
||||
expect(() => schema.parse(Number.POSITIVE_INFINITY)).toThrow(); // z.ZodError
|
||||
expect(() => schema.parse(Number.NEGATIVE_INFINITY)).toThrow(); // z.ZodError
|
||||
expect(schema.parse(true)).toBeInstanceOf(Date);
|
||||
expect(schema.parse(false)).toBeInstanceOf(Date);
|
||||
expect(schema.parse(null)).toBeInstanceOf(Date);
|
||||
expect(() => schema.parse(undefined)).toThrow(); // z.ZodError
|
||||
expect(() => schema.parse({ hello: "world!" })).toThrow(); // z.ZodError
|
||||
expect(() => schema.parse(["item", "another_item"])).toThrow(); // z.ZodError
|
||||
expect(() => schema.parse([])).toThrow(); // z.ZodError
|
||||
expect(schema.parse(new Date())).toBeInstanceOf(Date);
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
'use strict'
|
||||
|
||||
const { test } = require('tap')
|
||||
const { fork } = require('child_process')
|
||||
const { join } = require('path')
|
||||
const { once } = require('events')
|
||||
const { register } = require('..')
|
||||
|
||||
const files = [
|
||||
'close.js',
|
||||
'beforeExit',
|
||||
'gc-not-close.js',
|
||||
'unregister.js'
|
||||
]
|
||||
|
||||
for (const file of files) {
|
||||
test(file, async ({ equal }) => {
|
||||
const child = fork(join(__dirname, 'fixtures', file), [], {
|
||||
execArgv: ['--expose-gc']
|
||||
})
|
||||
|
||||
const [code] = await once(child, 'close')
|
||||
|
||||
equal(code, 0)
|
||||
})
|
||||
}
|
||||
|
||||
test('undefined', async ({ throws }) => {
|
||||
throws(() => register(undefined))
|
||||
})
|
||||
Reference in New Issue
Block a user