WIP: bootstrap and partial real Solana watcher implementation
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
import type * as errors from "../core/errors.js";
|
||||
import uk from "./uk.js";
|
||||
|
||||
/** @deprecated Use `uk` instead. */
|
||||
export default function (): { localeError: errors.$ZodErrorMap } {
|
||||
return uk();
|
||||
}
|
||||
@@ -0,0 +1,224 @@
|
||||
/**
|
||||
* @fileoverview Specify the maximum number of statements allowed per line.
|
||||
* @author Kenneth Williams
|
||||
* @deprecated in ESLint v8.53.0
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const astUtils = require("./utils/ast-utils");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../types').Rule.RuleModule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
deprecated: {
|
||||
message: "Formatting rules are being moved out of ESLint core.",
|
||||
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
||||
deprecatedSince: "8.53.0",
|
||||
availableUntil: "11.0.0",
|
||||
replacedBy: [
|
||||
{
|
||||
message:
|
||||
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
||||
url: "https://eslint.style/guide/migration",
|
||||
plugin: {
|
||||
name: "@stylistic/eslint-plugin",
|
||||
url: "https://eslint.style",
|
||||
},
|
||||
rule: {
|
||||
name: "max-statements-per-line",
|
||||
url: "https://eslint.style/rules/max-statements-per-line",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
type: "layout",
|
||||
|
||||
docs: {
|
||||
description:
|
||||
"Enforce a maximum number of statements allowed per line",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/max-statements-per-line",
|
||||
},
|
||||
|
||||
schema: [
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
max: {
|
||||
type: "integer",
|
||||
minimum: 1,
|
||||
default: 1,
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
messages: {
|
||||
exceed: "This line has {{numberOfStatementsOnThisLine}} {{statements}}. Maximum allowed is {{maxStatementsPerLine}}.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const sourceCode = context.sourceCode,
|
||||
options = context.options[0] || {},
|
||||
maxStatementsPerLine =
|
||||
typeof options.max !== "undefined" ? options.max : 1;
|
||||
|
||||
let lastStatementLine = 0,
|
||||
numberOfStatementsOnThisLine = 0,
|
||||
firstExtraStatement;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
const SINGLE_CHILD_ALLOWED =
|
||||
/^(?:(?:DoWhile|For|ForIn|ForOf|If|Labeled|While)Statement|Export(?:Default|Named)Declaration)$/u;
|
||||
|
||||
/**
|
||||
* Reports with the first extra statement, and clears it.
|
||||
* @returns {void}
|
||||
*/
|
||||
function reportFirstExtraStatementAndClear() {
|
||||
if (firstExtraStatement) {
|
||||
context.report({
|
||||
node: firstExtraStatement,
|
||||
messageId: "exceed",
|
||||
data: {
|
||||
numberOfStatementsOnThisLine,
|
||||
maxStatementsPerLine,
|
||||
statements:
|
||||
numberOfStatementsOnThisLine === 1
|
||||
? "statement"
|
||||
: "statements",
|
||||
},
|
||||
});
|
||||
}
|
||||
firstExtraStatement = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the actual last token of a given node.
|
||||
* @param {ASTNode} node A node to get. This is a node except EmptyStatement.
|
||||
* @returns {Token} The actual last token.
|
||||
*/
|
||||
function getActualLastToken(node) {
|
||||
return sourceCode.getLastToken(node, astUtils.isNotSemicolonToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* Addresses a given node.
|
||||
* It updates the state of this rule, then reports the node if the node violated this rule.
|
||||
* @param {ASTNode} node A node to check.
|
||||
* @returns {void}
|
||||
*/
|
||||
function enterStatement(node) {
|
||||
const line = node.loc.start.line;
|
||||
|
||||
/*
|
||||
* Skip to allow non-block statements if this is direct child of control statements.
|
||||
* `if (a) foo();` is counted as 1.
|
||||
* But `if (a) foo(); else foo();` should be counted as 2.
|
||||
*/
|
||||
if (
|
||||
SINGLE_CHILD_ALLOWED.test(node.parent.type) &&
|
||||
node.parent.alternate !== node
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update state.
|
||||
if (line === lastStatementLine) {
|
||||
numberOfStatementsOnThisLine += 1;
|
||||
} else {
|
||||
reportFirstExtraStatementAndClear();
|
||||
numberOfStatementsOnThisLine = 1;
|
||||
lastStatementLine = line;
|
||||
}
|
||||
|
||||
// Reports if the node violated this rule.
|
||||
if (numberOfStatementsOnThisLine === maxStatementsPerLine + 1) {
|
||||
firstExtraStatement = firstExtraStatement || node;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the state of this rule with the end line of leaving node to check with the next statement.
|
||||
* @param {ASTNode} node A node to check.
|
||||
* @returns {void}
|
||||
*/
|
||||
function leaveStatement(node) {
|
||||
const line = getActualLastToken(node).loc.end.line;
|
||||
|
||||
// Update state.
|
||||
if (line !== lastStatementLine) {
|
||||
reportFirstExtraStatementAndClear();
|
||||
numberOfStatementsOnThisLine = 1;
|
||||
lastStatementLine = line;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Public API
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
return {
|
||||
BreakStatement: enterStatement,
|
||||
ClassDeclaration: enterStatement,
|
||||
ContinueStatement: enterStatement,
|
||||
DebuggerStatement: enterStatement,
|
||||
DoWhileStatement: enterStatement,
|
||||
ExpressionStatement: enterStatement,
|
||||
ForInStatement: enterStatement,
|
||||
ForOfStatement: enterStatement,
|
||||
ForStatement: enterStatement,
|
||||
FunctionDeclaration: enterStatement,
|
||||
IfStatement: enterStatement,
|
||||
ImportDeclaration: enterStatement,
|
||||
LabeledStatement: enterStatement,
|
||||
ReturnStatement: enterStatement,
|
||||
SwitchStatement: enterStatement,
|
||||
ThrowStatement: enterStatement,
|
||||
TryStatement: enterStatement,
|
||||
VariableDeclaration: enterStatement,
|
||||
WhileStatement: enterStatement,
|
||||
WithStatement: enterStatement,
|
||||
ExportNamedDeclaration: enterStatement,
|
||||
ExportDefaultDeclaration: enterStatement,
|
||||
ExportAllDeclaration: enterStatement,
|
||||
|
||||
"BreakStatement:exit": leaveStatement,
|
||||
"ClassDeclaration:exit": leaveStatement,
|
||||
"ContinueStatement:exit": leaveStatement,
|
||||
"DebuggerStatement:exit": leaveStatement,
|
||||
"DoWhileStatement:exit": leaveStatement,
|
||||
"ExpressionStatement:exit": leaveStatement,
|
||||
"ForInStatement:exit": leaveStatement,
|
||||
"ForOfStatement:exit": leaveStatement,
|
||||
"ForStatement:exit": leaveStatement,
|
||||
"FunctionDeclaration:exit": leaveStatement,
|
||||
"IfStatement:exit": leaveStatement,
|
||||
"ImportDeclaration:exit": leaveStatement,
|
||||
"LabeledStatement:exit": leaveStatement,
|
||||
"ReturnStatement:exit": leaveStatement,
|
||||
"SwitchStatement:exit": leaveStatement,
|
||||
"ThrowStatement:exit": leaveStatement,
|
||||
"TryStatement:exit": leaveStatement,
|
||||
"VariableDeclaration:exit": leaveStatement,
|
||||
"WhileStatement:exit": leaveStatement,
|
||||
"WithStatement:exit": leaveStatement,
|
||||
"ExportNamedDeclaration:exit": leaveStatement,
|
||||
"ExportDefaultDeclaration:exit": leaveStatement,
|
||||
"ExportAllDeclaration:exit": leaveStatement,
|
||||
"Program:exit": reportFirstExtraStatementAndClear,
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
import * as ts from 'typescript';
|
||||
/**
|
||||
* Retrieve only the Enum literals from a type. for example:
|
||||
* - 123 --> []
|
||||
* - {} --> []
|
||||
* - Fruit.Apple --> [Fruit.Apple]
|
||||
* - Fruit.Apple | Vegetable.Lettuce --> [Fruit.Apple, Vegetable.Lettuce]
|
||||
* - Fruit.Apple | Vegetable.Lettuce | 123 --> [Fruit.Apple, Vegetable.Lettuce]
|
||||
* - T extends Fruit --> [Fruit]
|
||||
*/
|
||||
export declare function getEnumLiterals(type: ts.Type): ts.LiteralType[];
|
||||
/**
|
||||
* A type can have 0 or more enum types. For example:
|
||||
* - 123 --> []
|
||||
* - {} --> []
|
||||
* - Fruit.Apple --> [Fruit]
|
||||
* - Fruit.Apple | Vegetable.Lettuce --> [Fruit, Vegetable]
|
||||
* - Fruit.Apple | Vegetable.Lettuce | 123 --> [Fruit, Vegetable]
|
||||
* - T extends Fruit --> [Fruit]
|
||||
*/
|
||||
export declare function getEnumTypes(typeChecker: ts.TypeChecker, type: ts.Type): ts.Type[];
|
||||
/**
|
||||
* Returns the enum key that matches the given literal node, or null if none
|
||||
* match. For example:
|
||||
* ```ts
|
||||
* enum Fruit {
|
||||
* Apple = 'apple',
|
||||
* Banana = 'banana',
|
||||
* }
|
||||
*
|
||||
* getEnumKeyForLiteral([Fruit.Apple, Fruit.Banana], 'apple') --> 'Fruit.Apple'
|
||||
* getEnumKeyForLiteral([Fruit.Apple, Fruit.Banana], 'banana') --> 'Fruit.Banana'
|
||||
* getEnumKeyForLiteral([Fruit.Apple, Fruit.Banana], 'cherry') --> null
|
||||
* ```
|
||||
*/
|
||||
export declare function getEnumKeyForLiteral(enumLiterals: ts.LiteralType[], literal: unknown): string | null;
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,310 @@
|
||||
// Type definitions for commander 2.11
|
||||
// Project: https://github.com/visionmedia/commander.js
|
||||
// Definitions by: Alan Agius <https://github.com/alan-agius4>, Marcelo Dezem <https://github.com/mdezem>, vvakame <https://github.com/vvakame>, Jules Randolph <https://github.com/sveinburne>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare namespace local {
|
||||
|
||||
class Option {
|
||||
flags: string;
|
||||
required: boolean;
|
||||
optional: boolean;
|
||||
bool: boolean;
|
||||
short?: string;
|
||||
long: string;
|
||||
description: string;
|
||||
|
||||
/**
|
||||
* Initialize a new `Option` with the given `flags` and `description`.
|
||||
*
|
||||
* @param {string} flags
|
||||
* @param {string} [description]
|
||||
*/
|
||||
constructor(flags: string, description?: string);
|
||||
}
|
||||
|
||||
class Command extends NodeJS.EventEmitter {
|
||||
[key: string]: any;
|
||||
|
||||
args: string[];
|
||||
|
||||
/**
|
||||
* Initialize a new `Command`.
|
||||
*
|
||||
* @param {string} [name]
|
||||
*/
|
||||
constructor(name?: string);
|
||||
|
||||
/**
|
||||
* Set the program version to `str`.
|
||||
*
|
||||
* This method auto-registers the "-V, --version" flag
|
||||
* which will print the version number when passed.
|
||||
*
|
||||
* @param {string} str
|
||||
* @param {string} [flags]
|
||||
* @returns {Command} for chaining
|
||||
*/
|
||||
version(str: string, flags?: string): Command;
|
||||
|
||||
/**
|
||||
* Add command `name`.
|
||||
*
|
||||
* The `.action()` callback is invoked when the
|
||||
* command `name` is specified via __ARGV__,
|
||||
* and the remaining arguments are applied to the
|
||||
* function for access.
|
||||
*
|
||||
* When the `name` is "*" an un-matched command
|
||||
* will be passed as the first arg, followed by
|
||||
* the rest of __ARGV__ remaining.
|
||||
*
|
||||
* @example
|
||||
* program
|
||||
* .version('0.0.1')
|
||||
* .option('-C, --chdir <path>', 'change the working directory')
|
||||
* .option('-c, --config <path>', 'set config path. defaults to ./deploy.conf')
|
||||
* .option('-T, --no-tests', 'ignore test hook')
|
||||
*
|
||||
* program
|
||||
* .command('setup')
|
||||
* .description('run remote setup commands')
|
||||
* .action(function() {
|
||||
* console.log('setup');
|
||||
* });
|
||||
*
|
||||
* program
|
||||
* .command('exec <cmd>')
|
||||
* .description('run the given remote command')
|
||||
* .action(function(cmd) {
|
||||
* console.log('exec "%s"', cmd);
|
||||
* });
|
||||
*
|
||||
* program
|
||||
* .command('teardown <dir> [otherDirs...]')
|
||||
* .description('run teardown commands')
|
||||
* .action(function(dir, otherDirs) {
|
||||
* console.log('dir "%s"', dir);
|
||||
* if (otherDirs) {
|
||||
* otherDirs.forEach(function (oDir) {
|
||||
* console.log('dir "%s"', oDir);
|
||||
* });
|
||||
* }
|
||||
* });
|
||||
*
|
||||
* program
|
||||
* .command('*')
|
||||
* .description('deploy the given env')
|
||||
* .action(function(env) {
|
||||
* console.log('deploying "%s"', env);
|
||||
* });
|
||||
*
|
||||
* program.parse(process.argv);
|
||||
*
|
||||
* @param {string} name
|
||||
* @param {string} [desc] for git-style sub-commands
|
||||
* @param {CommandOptions} [opts] command options
|
||||
* @returns {Command} the new command
|
||||
*/
|
||||
command(name: string, desc?: string, opts?: commander.CommandOptions): Command;
|
||||
|
||||
/**
|
||||
* Define argument syntax for the top-level command.
|
||||
*
|
||||
* @param {string} desc
|
||||
* @returns {Command} for chaining
|
||||
*/
|
||||
arguments(desc: string): Command;
|
||||
|
||||
/**
|
||||
* Parse expected `args`.
|
||||
*
|
||||
* For example `["[type]"]` becomes `[{ required: false, name: 'type' }]`.
|
||||
*
|
||||
* @param {string[]} args
|
||||
* @returns {Command} for chaining
|
||||
*/
|
||||
parseExpectedArgs(args: string[]): Command;
|
||||
|
||||
/**
|
||||
* Register callback `fn` for the command.
|
||||
*
|
||||
* @example
|
||||
* program
|
||||
* .command('help')
|
||||
* .description('display verbose help')
|
||||
* .action(function() {
|
||||
* // output help here
|
||||
* });
|
||||
*
|
||||
* @param {(...args: any[]) => void} fn
|
||||
* @returns {Command} for chaining
|
||||
*/
|
||||
action(fn: (...args: any[]) => void): Command;
|
||||
|
||||
/**
|
||||
* Define option with `flags`, `description` and optional
|
||||
* coercion `fn`.
|
||||
*
|
||||
* The `flags` string should contain both the short and long flags,
|
||||
* separated by comma, a pipe or space. The following are all valid
|
||||
* all will output this way when `--help` is used.
|
||||
*
|
||||
* "-p, --pepper"
|
||||
* "-p|--pepper"
|
||||
* "-p --pepper"
|
||||
*
|
||||
* @example
|
||||
* // simple boolean defaulting to false
|
||||
* program.option('-p, --pepper', 'add pepper');
|
||||
*
|
||||
* --pepper
|
||||
* program.pepper
|
||||
* // => Boolean
|
||||
*
|
||||
* // simple boolean defaulting to true
|
||||
* program.option('-C, --no-cheese', 'remove cheese');
|
||||
*
|
||||
* program.cheese
|
||||
* // => true
|
||||
*
|
||||
* --no-cheese
|
||||
* program.cheese
|
||||
* // => false
|
||||
*
|
||||
* // required argument
|
||||
* program.option('-C, --chdir <path>', 'change the working directory');
|
||||
*
|
||||
* --chdir /tmp
|
||||
* program.chdir
|
||||
* // => "/tmp"
|
||||
*
|
||||
* // optional argument
|
||||
* program.option('-c, --cheese [type]', 'add cheese [marble]');
|
||||
*
|
||||
* @param {string} flags
|
||||
* @param {string} [description]
|
||||
* @param {((arg1: any, arg2: any) => void) | RegExp} [fn] function or default
|
||||
* @param {*} [defaultValue]
|
||||
* @returns {Command} for chaining
|
||||
*/
|
||||
option(flags: string, description?: string, fn?: ((arg1: any, arg2: any) => void) | RegExp, defaultValue?: any): Command;
|
||||
option(flags: string, description?: string, defaultValue?: any): Command;
|
||||
|
||||
/**
|
||||
* Allow unknown options on the command line.
|
||||
*
|
||||
* @param {boolean} [arg] if `true` or omitted, no error will be thrown for unknown options.
|
||||
* @returns {Command} for chaining
|
||||
*/
|
||||
allowUnknownOption(arg?: boolean): Command;
|
||||
|
||||
/**
|
||||
* Parse `argv`, settings options and invoking commands when defined.
|
||||
*
|
||||
* @param {string[]} argv
|
||||
* @returns {Command} for chaining
|
||||
*/
|
||||
parse(argv: string[]): Command;
|
||||
|
||||
/**
|
||||
* Parse options from `argv` returning `argv` void of these options.
|
||||
*
|
||||
* @param {string[]} argv
|
||||
* @returns {ParseOptionsResult}
|
||||
*/
|
||||
parseOptions(argv: string[]): commander.ParseOptionsResult;
|
||||
|
||||
/**
|
||||
* Return an object containing options as key-value pairs
|
||||
*
|
||||
* @returns {{[key: string]: any}}
|
||||
*/
|
||||
opts(): { [key: string]: any };
|
||||
|
||||
/**
|
||||
* Set the description to `str`.
|
||||
*
|
||||
* @param {string} str
|
||||
* @param {{[argName: string]: string}} argsDescription
|
||||
* @return {(Command | string)}
|
||||
*/
|
||||
description(str: string, argsDescription?: {[argName: string]: string}): Command;
|
||||
description(): string;
|
||||
|
||||
/**
|
||||
* Set an alias for the command.
|
||||
*
|
||||
* @param {string} alias
|
||||
* @return {(Command | string)}
|
||||
*/
|
||||
alias(alias: string): Command;
|
||||
alias(): string;
|
||||
|
||||
/**
|
||||
* Set or get the command usage.
|
||||
*
|
||||
* @param {string} str
|
||||
* @return {(Command | string)}
|
||||
*/
|
||||
usage(str: string): Command;
|
||||
usage(): string;
|
||||
|
||||
/**
|
||||
* Set the name of the command.
|
||||
*
|
||||
* @param {string} str
|
||||
* @return {Command}
|
||||
*/
|
||||
name(str: string): Command;
|
||||
|
||||
/**
|
||||
* Get the name of the command.
|
||||
*
|
||||
* @return {string}
|
||||
*/
|
||||
name(): string;
|
||||
|
||||
/**
|
||||
* Output help information for this command.
|
||||
*
|
||||
* @param {(str: string) => string} [cb]
|
||||
*/
|
||||
outputHelp(cb?: (str: string) => string): void;
|
||||
|
||||
/** Output help information and exit.
|
||||
*
|
||||
* @param {(str: string) => string} [cb]
|
||||
*/
|
||||
help(cb?: (str: string) => string): never;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
declare namespace commander {
|
||||
|
||||
type Command = local.Command
|
||||
|
||||
type Option = local.Option
|
||||
|
||||
interface CommandOptions {
|
||||
noHelp?: boolean;
|
||||
isDefault?: boolean;
|
||||
}
|
||||
|
||||
interface ParseOptionsResult {
|
||||
args: string[];
|
||||
unknown: string[];
|
||||
}
|
||||
|
||||
interface CommanderStatic extends Command {
|
||||
Command: typeof local.Command;
|
||||
Option: typeof local.Option;
|
||||
CommandOptions: CommandOptions;
|
||||
ParseOptionsResult: ParseOptionsResult;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
declare const commander: commander.CommanderStatic;
|
||||
export = commander;
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"add-codec-sentinel.d.ts","sourceRoot":"","sources":["../../src/add-codec-sentinel.ts"],"names":[],"mappings":"AAOA,OAAO,EACH,KAAK,EAGL,OAAO,EACP,OAAO,EACP,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAEhB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACtB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EACpC,OAAO,EAAE,gBAAgB,CAAC,KAAK,CAAC,EAChC,QAAQ,EAAE,kBAAkB,GAC7B,gBAAgB,CAAC,KAAK,CAAC,CAAC;AAC3B,wBAAgB,kBAAkB,CAAC,KAAK,EACpC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,EACvB,QAAQ,EAAE,kBAAkB,GAC7B,mBAAmB,CAAC,KAAK,CAAC,CAAC;AAkC9B;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAClC,OAAO,EAAE,gBAAgB,CAAC,GAAG,CAAC,EAC9B,QAAQ,EAAE,kBAAkB,GAC7B,gBAAgB,CAAC,GAAG,CAAC,CAAC;AACzB,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,kBAAkB,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;AA+BvH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,GAAG,SAAS,KAAK,EACrD,KAAK,EAAE,cAAc,CAAC,KAAK,EAAE,GAAG,CAAC,EACjC,QAAQ,EAAE,kBAAkB,GAC7B,cAAc,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAC9B,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,GAAG,SAAS,KAAK,EACrD,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,EACxB,QAAQ,EAAE,kBAAkB,GAC7B,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC"}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
interface String {
|
||||
/**
|
||||
* Pads the current string with a given string (repeated and/or truncated, if needed) so that the resulting string has a given length.
|
||||
* The padding is applied from the start of the current string.
|
||||
*
|
||||
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart)
|
||||
*
|
||||
* @param targetLength The length of the resulting string once the current `str` has been padded.
|
||||
* If the value is less than or equal to `str.length`, then `str` is returned as-is.
|
||||
*
|
||||
* @param padString The string to pad the current `str` with.
|
||||
* If `padString` is too long to stay within `targetLength`, it will be truncated from the end.
|
||||
* The default value is the space character (U+0020).
|
||||
*/
|
||||
padStart(targetLength: number, padString?: string): string;
|
||||
|
||||
/**
|
||||
* Pads the current string with a given string (repeated and/or truncated, if needed) so that the resulting string has a given length.
|
||||
* The padding is applied from the end of the current string.
|
||||
*
|
||||
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd)
|
||||
*
|
||||
* @param targetLength The length of the resulting string once the current `str` has been padded.
|
||||
* If the value is less than or equal to `str.length`, then `str` is returned as-is.
|
||||
*
|
||||
* @param padString The string to pad the current `str` with.
|
||||
* If `padString` is too long to stay within `targetLength`, it will be truncated from the end.
|
||||
* The default value is the space character (U+0020).
|
||||
*/
|
||||
padEnd(targetLength: number, padString?: string): string;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"p256.d.ts","sourceRoot":"","sources":["src/p256.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,sEAAsE;AACtE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAe,IAAI,IAAI,KAAK,EAAE,MAAM,WAAW,CAAC;AACvD,sEAAsE;AACtE,eAAO,MAAM,IAAI,EAAE,OAAO,KAAa,CAAC;AACxC,sEAAsE;AACtE,eAAO,MAAM,SAAS,EAAE,OAAO,KAAa,CAAC;AAC7C,6EAA6E;AAC7E,eAAO,MAAM,WAAW,EAAE,SAAS,CAAC,MAAM,CAAqD,CAAC;AAChG,6EAA6E;AAC7E,eAAO,MAAM,aAAa,EAAE,SAAS,CAAC,MAAM,CAAuD,CAAC"}
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"hmac.d.ts","sourceRoot":"","sources":["src/hmac.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAiC,IAAI,EAAW,KAAK,KAAK,EAAE,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAElG,qBAAa,IAAI,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,CAAC,CAAE,SAAQ,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACxD,KAAK,EAAE,CAAC,CAAC;IACT,KAAK,EAAE,CAAC,CAAC;IACT,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,SAAS,CAAS;gBAEd,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK;IAsBpC,MAAM,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI;IAKxB,UAAU,CAAC,GAAG,EAAE,UAAU,GAAG,IAAI;IASjC,MAAM,IAAI,UAAU;IAKpB,UAAU,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IAajC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC;IAGhB,OAAO,IAAI,IAAI;CAKhB;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,IAAI,EAAE;IACjB,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,GAAG,UAAU,CAAC;IACtD,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;CAEM,CAAC"}
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"eskdf.d.ts","sourceRoot":"","sources":["src/eskdf.ts"],"names":[],"mappings":"AAiBA,wBAAgB,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CAEjE;AAGD,wBAAgB,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CAEjE;AAiBD;;GAEG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,CAY7E;AAED,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;AAgCjC,KAAK,UAAU,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AACxC,KAAK,OAAO,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AACnC,KAAK,OAAO,GAAG,SAAS,GAAG,UAAU,GAAG,OAAO,CAAC;AAwChD,MAAM,WAAW,KAAK;IACpB;;;;;;;;OAQG;IACH,cAAc,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,UAAU,CAAC;IAC1F;;OAEG;IACH,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;GASG;AACH,wBAAsB,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAuB9E"}
|
||||
@@ -0,0 +1,513 @@
|
||||
import bs58 from 'bs58';
|
||||
import * as BufferLayout from '@solana/buffer-layout';
|
||||
|
||||
import * as Layout from '../layout';
|
||||
import {Blockhash} from '../blockhash';
|
||||
import {
|
||||
MessageHeader,
|
||||
MessageAddressTableLookup,
|
||||
MessageCompiledInstruction,
|
||||
} from './index';
|
||||
import {PublicKey, PUBLIC_KEY_LENGTH} from '../publickey';
|
||||
import * as shortvec from '../utils/shortvec-encoding';
|
||||
import assert from '../utils/assert';
|
||||
import {PACKET_DATA_SIZE, VERSION_PREFIX_MASK} from '../transaction/constants';
|
||||
import {TransactionInstruction} from '../transaction';
|
||||
import {AddressLookupTableAccount} from '../programs';
|
||||
import {CompiledKeys} from './compiled-keys';
|
||||
import {AccountKeysFromLookups, MessageAccountKeys} from './account-keys';
|
||||
import {guardedShift, guardedSplice} from '../utils/guarded-array-utils';
|
||||
|
||||
/**
|
||||
* Message constructor arguments
|
||||
*/
|
||||
export type MessageV0Args = {
|
||||
/** The message header, identifying signed and read-only `accountKeys` */
|
||||
header: MessageHeader;
|
||||
/** The static account keys used by this transaction */
|
||||
staticAccountKeys: PublicKey[];
|
||||
/** The hash of a recent ledger block */
|
||||
recentBlockhash: Blockhash;
|
||||
/** Instructions that will be executed in sequence and committed in one atomic transaction if all succeed. */
|
||||
compiledInstructions: MessageCompiledInstruction[];
|
||||
/** Instructions that will be executed in sequence and committed in one atomic transaction if all succeed. */
|
||||
addressTableLookups: MessageAddressTableLookup[];
|
||||
};
|
||||
|
||||
export type CompileV0Args = {
|
||||
payerKey: PublicKey;
|
||||
instructions: Array<TransactionInstruction>;
|
||||
recentBlockhash: Blockhash;
|
||||
addressLookupTableAccounts?: Array<AddressLookupTableAccount>;
|
||||
};
|
||||
|
||||
export type GetAccountKeysArgs =
|
||||
| {
|
||||
accountKeysFromLookups?: AccountKeysFromLookups | null;
|
||||
}
|
||||
| {
|
||||
addressLookupTableAccounts?: AddressLookupTableAccount[] | null;
|
||||
};
|
||||
|
||||
export class MessageV0 {
|
||||
header: MessageHeader;
|
||||
staticAccountKeys: Array<PublicKey>;
|
||||
recentBlockhash: Blockhash;
|
||||
compiledInstructions: Array<MessageCompiledInstruction>;
|
||||
addressTableLookups: Array<MessageAddressTableLookup>;
|
||||
|
||||
constructor(args: MessageV0Args) {
|
||||
this.header = args.header;
|
||||
this.staticAccountKeys = args.staticAccountKeys;
|
||||
this.recentBlockhash = args.recentBlockhash;
|
||||
this.compiledInstructions = args.compiledInstructions;
|
||||
this.addressTableLookups = args.addressTableLookups;
|
||||
}
|
||||
|
||||
get version(): 0 {
|
||||
return 0;
|
||||
}
|
||||
|
||||
get numAccountKeysFromLookups(): number {
|
||||
let count = 0;
|
||||
for (const lookup of this.addressTableLookups) {
|
||||
count += lookup.readonlyIndexes.length + lookup.writableIndexes.length;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
getAccountKeys(args?: GetAccountKeysArgs): MessageAccountKeys {
|
||||
let accountKeysFromLookups: AccountKeysFromLookups | undefined;
|
||||
if (
|
||||
args &&
|
||||
'accountKeysFromLookups' in args &&
|
||||
args.accountKeysFromLookups
|
||||
) {
|
||||
if (
|
||||
this.numAccountKeysFromLookups !=
|
||||
args.accountKeysFromLookups.writable.length +
|
||||
args.accountKeysFromLookups.readonly.length
|
||||
) {
|
||||
throw new Error(
|
||||
'Failed to get account keys because of a mismatch in the number of account keys from lookups',
|
||||
);
|
||||
}
|
||||
accountKeysFromLookups = args.accountKeysFromLookups;
|
||||
} else if (
|
||||
args &&
|
||||
'addressLookupTableAccounts' in args &&
|
||||
args.addressLookupTableAccounts
|
||||
) {
|
||||
accountKeysFromLookups = this.resolveAddressTableLookups(
|
||||
args.addressLookupTableAccounts,
|
||||
);
|
||||
} else if (this.addressTableLookups.length > 0) {
|
||||
throw new Error(
|
||||
'Failed to get account keys because address table lookups were not resolved',
|
||||
);
|
||||
}
|
||||
return new MessageAccountKeys(
|
||||
this.staticAccountKeys,
|
||||
accountKeysFromLookups,
|
||||
);
|
||||
}
|
||||
|
||||
isAccountSigner(index: number): boolean {
|
||||
return index < this.header.numRequiredSignatures;
|
||||
}
|
||||
|
||||
isAccountWritable(index: number): boolean {
|
||||
const numSignedAccounts = this.header.numRequiredSignatures;
|
||||
const numStaticAccountKeys = this.staticAccountKeys.length;
|
||||
if (index >= numStaticAccountKeys) {
|
||||
const lookupAccountKeysIndex = index - numStaticAccountKeys;
|
||||
const numWritableLookupAccountKeys = this.addressTableLookups.reduce(
|
||||
(count, lookup) => count + lookup.writableIndexes.length,
|
||||
0,
|
||||
);
|
||||
return lookupAccountKeysIndex < numWritableLookupAccountKeys;
|
||||
} else if (index >= this.header.numRequiredSignatures) {
|
||||
const unsignedAccountIndex = index - numSignedAccounts;
|
||||
const numUnsignedAccounts = numStaticAccountKeys - numSignedAccounts;
|
||||
const numWritableUnsignedAccounts =
|
||||
numUnsignedAccounts - this.header.numReadonlyUnsignedAccounts;
|
||||
return unsignedAccountIndex < numWritableUnsignedAccounts;
|
||||
} else {
|
||||
const numWritableSignedAccounts =
|
||||
numSignedAccounts - this.header.numReadonlySignedAccounts;
|
||||
return index < numWritableSignedAccounts;
|
||||
}
|
||||
}
|
||||
|
||||
resolveAddressTableLookups(
|
||||
addressLookupTableAccounts: AddressLookupTableAccount[],
|
||||
): AccountKeysFromLookups {
|
||||
const accountKeysFromLookups: AccountKeysFromLookups = {
|
||||
writable: [],
|
||||
readonly: [],
|
||||
};
|
||||
|
||||
for (const tableLookup of this.addressTableLookups) {
|
||||
const tableAccount = addressLookupTableAccounts.find(account =>
|
||||
account.key.equals(tableLookup.accountKey),
|
||||
);
|
||||
if (!tableAccount) {
|
||||
throw new Error(
|
||||
`Failed to find address lookup table account for table key ${tableLookup.accountKey.toBase58()}`,
|
||||
);
|
||||
}
|
||||
|
||||
for (const index of tableLookup.writableIndexes) {
|
||||
if (index < tableAccount.state.addresses.length) {
|
||||
accountKeysFromLookups.writable.push(
|
||||
tableAccount.state.addresses[index],
|
||||
);
|
||||
} else {
|
||||
throw new Error(
|
||||
`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (const index of tableLookup.readonlyIndexes) {
|
||||
if (index < tableAccount.state.addresses.length) {
|
||||
accountKeysFromLookups.readonly.push(
|
||||
tableAccount.state.addresses[index],
|
||||
);
|
||||
} else {
|
||||
throw new Error(
|
||||
`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return accountKeysFromLookups;
|
||||
}
|
||||
|
||||
static compile(args: CompileV0Args): MessageV0 {
|
||||
const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
|
||||
|
||||
const addressTableLookups = new Array<MessageAddressTableLookup>();
|
||||
const accountKeysFromLookups: AccountKeysFromLookups = {
|
||||
writable: new Array(),
|
||||
readonly: new Array(),
|
||||
};
|
||||
const lookupTableAccounts = args.addressLookupTableAccounts || [];
|
||||
for (const lookupTable of lookupTableAccounts) {
|
||||
const extractResult = compiledKeys.extractTableLookup(lookupTable);
|
||||
if (extractResult !== undefined) {
|
||||
const [addressTableLookup, {writable, readonly}] = extractResult;
|
||||
addressTableLookups.push(addressTableLookup);
|
||||
accountKeysFromLookups.writable.push(...writable);
|
||||
accountKeysFromLookups.readonly.push(...readonly);
|
||||
}
|
||||
}
|
||||
|
||||
const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
|
||||
const accountKeys = new MessageAccountKeys(
|
||||
staticAccountKeys,
|
||||
accountKeysFromLookups,
|
||||
);
|
||||
const compiledInstructions = accountKeys.compileInstructions(
|
||||
args.instructions,
|
||||
);
|
||||
return new MessageV0({
|
||||
header,
|
||||
staticAccountKeys,
|
||||
recentBlockhash: args.recentBlockhash,
|
||||
compiledInstructions,
|
||||
addressTableLookups,
|
||||
});
|
||||
}
|
||||
|
||||
serialize(): Uint8Array {
|
||||
const encodedStaticAccountKeysLength = Array<number>();
|
||||
shortvec.encodeLength(
|
||||
encodedStaticAccountKeysLength,
|
||||
this.staticAccountKeys.length,
|
||||
);
|
||||
|
||||
const serializedInstructions = this.serializeInstructions();
|
||||
const encodedInstructionsLength = Array<number>();
|
||||
shortvec.encodeLength(
|
||||
encodedInstructionsLength,
|
||||
this.compiledInstructions.length,
|
||||
);
|
||||
|
||||
const serializedAddressTableLookups = this.serializeAddressTableLookups();
|
||||
const encodedAddressTableLookupsLength = Array<number>();
|
||||
shortvec.encodeLength(
|
||||
encodedAddressTableLookupsLength,
|
||||
this.addressTableLookups.length,
|
||||
);
|
||||
|
||||
const messageLayout = BufferLayout.struct<{
|
||||
prefix: number;
|
||||
header: MessageHeader;
|
||||
staticAccountKeysLength: Uint8Array;
|
||||
staticAccountKeys: Array<Uint8Array>;
|
||||
recentBlockhash: Uint8Array;
|
||||
instructionsLength: Uint8Array;
|
||||
serializedInstructions: Uint8Array;
|
||||
addressTableLookupsLength: Uint8Array;
|
||||
serializedAddressTableLookups: Uint8Array;
|
||||
}>([
|
||||
BufferLayout.u8('prefix'),
|
||||
BufferLayout.struct<MessageHeader>(
|
||||
[
|
||||
BufferLayout.u8('numRequiredSignatures'),
|
||||
BufferLayout.u8('numReadonlySignedAccounts'),
|
||||
BufferLayout.u8('numReadonlyUnsignedAccounts'),
|
||||
],
|
||||
'header',
|
||||
),
|
||||
BufferLayout.blob(
|
||||
encodedStaticAccountKeysLength.length,
|
||||
'staticAccountKeysLength',
|
||||
),
|
||||
BufferLayout.seq(
|
||||
Layout.publicKey(),
|
||||
this.staticAccountKeys.length,
|
||||
'staticAccountKeys',
|
||||
),
|
||||
Layout.publicKey('recentBlockhash'),
|
||||
BufferLayout.blob(encodedInstructionsLength.length, 'instructionsLength'),
|
||||
BufferLayout.blob(
|
||||
serializedInstructions.length,
|
||||
'serializedInstructions',
|
||||
),
|
||||
BufferLayout.blob(
|
||||
encodedAddressTableLookupsLength.length,
|
||||
'addressTableLookupsLength',
|
||||
),
|
||||
BufferLayout.blob(
|
||||
serializedAddressTableLookups.length,
|
||||
'serializedAddressTableLookups',
|
||||
),
|
||||
]);
|
||||
|
||||
const serializedMessage = new Uint8Array(PACKET_DATA_SIZE);
|
||||
const MESSAGE_VERSION_0_PREFIX = 1 << 7;
|
||||
const serializedMessageLength = messageLayout.encode(
|
||||
{
|
||||
prefix: MESSAGE_VERSION_0_PREFIX,
|
||||
header: this.header,
|
||||
staticAccountKeysLength: new Uint8Array(encodedStaticAccountKeysLength),
|
||||
staticAccountKeys: this.staticAccountKeys.map(key => key.toBytes()),
|
||||
recentBlockhash: bs58.decode(this.recentBlockhash),
|
||||
instructionsLength: new Uint8Array(encodedInstructionsLength),
|
||||
serializedInstructions,
|
||||
addressTableLookupsLength: new Uint8Array(
|
||||
encodedAddressTableLookupsLength,
|
||||
),
|
||||
serializedAddressTableLookups,
|
||||
},
|
||||
serializedMessage,
|
||||
);
|
||||
return serializedMessage.slice(0, serializedMessageLength);
|
||||
}
|
||||
|
||||
private serializeInstructions(): Uint8Array {
|
||||
let serializedLength = 0;
|
||||
const serializedInstructions = new Uint8Array(PACKET_DATA_SIZE);
|
||||
for (const instruction of this.compiledInstructions) {
|
||||
const encodedAccountKeyIndexesLength = Array<number>();
|
||||
shortvec.encodeLength(
|
||||
encodedAccountKeyIndexesLength,
|
||||
instruction.accountKeyIndexes.length,
|
||||
);
|
||||
|
||||
const encodedDataLength = Array<number>();
|
||||
shortvec.encodeLength(encodedDataLength, instruction.data.length);
|
||||
|
||||
const instructionLayout = BufferLayout.struct<{
|
||||
programIdIndex: number;
|
||||
encodedAccountKeyIndexesLength: Uint8Array;
|
||||
accountKeyIndexes: number[];
|
||||
encodedDataLength: Uint8Array;
|
||||
data: Uint8Array;
|
||||
}>([
|
||||
BufferLayout.u8('programIdIndex'),
|
||||
BufferLayout.blob(
|
||||
encodedAccountKeyIndexesLength.length,
|
||||
'encodedAccountKeyIndexesLength',
|
||||
),
|
||||
BufferLayout.seq(
|
||||
BufferLayout.u8(),
|
||||
instruction.accountKeyIndexes.length,
|
||||
'accountKeyIndexes',
|
||||
),
|
||||
BufferLayout.blob(encodedDataLength.length, 'encodedDataLength'),
|
||||
BufferLayout.blob(instruction.data.length, 'data'),
|
||||
]);
|
||||
|
||||
serializedLength += instructionLayout.encode(
|
||||
{
|
||||
programIdIndex: instruction.programIdIndex,
|
||||
encodedAccountKeyIndexesLength: new Uint8Array(
|
||||
encodedAccountKeyIndexesLength,
|
||||
),
|
||||
accountKeyIndexes: instruction.accountKeyIndexes,
|
||||
encodedDataLength: new Uint8Array(encodedDataLength),
|
||||
data: instruction.data,
|
||||
},
|
||||
serializedInstructions,
|
||||
serializedLength,
|
||||
);
|
||||
}
|
||||
|
||||
return serializedInstructions.slice(0, serializedLength);
|
||||
}
|
||||
|
||||
private serializeAddressTableLookups(): Uint8Array {
|
||||
let serializedLength = 0;
|
||||
const serializedAddressTableLookups = new Uint8Array(PACKET_DATA_SIZE);
|
||||
for (const lookup of this.addressTableLookups) {
|
||||
const encodedWritableIndexesLength = Array<number>();
|
||||
shortvec.encodeLength(
|
||||
encodedWritableIndexesLength,
|
||||
lookup.writableIndexes.length,
|
||||
);
|
||||
|
||||
const encodedReadonlyIndexesLength = Array<number>();
|
||||
shortvec.encodeLength(
|
||||
encodedReadonlyIndexesLength,
|
||||
lookup.readonlyIndexes.length,
|
||||
);
|
||||
|
||||
const addressTableLookupLayout = BufferLayout.struct<{
|
||||
accountKey: Uint8Array;
|
||||
encodedWritableIndexesLength: Uint8Array;
|
||||
writableIndexes: number[];
|
||||
encodedReadonlyIndexesLength: Uint8Array;
|
||||
readonlyIndexes: number[];
|
||||
}>([
|
||||
Layout.publicKey('accountKey'),
|
||||
BufferLayout.blob(
|
||||
encodedWritableIndexesLength.length,
|
||||
'encodedWritableIndexesLength',
|
||||
),
|
||||
BufferLayout.seq(
|
||||
BufferLayout.u8(),
|
||||
lookup.writableIndexes.length,
|
||||
'writableIndexes',
|
||||
),
|
||||
BufferLayout.blob(
|
||||
encodedReadonlyIndexesLength.length,
|
||||
'encodedReadonlyIndexesLength',
|
||||
),
|
||||
BufferLayout.seq(
|
||||
BufferLayout.u8(),
|
||||
lookup.readonlyIndexes.length,
|
||||
'readonlyIndexes',
|
||||
),
|
||||
]);
|
||||
|
||||
serializedLength += addressTableLookupLayout.encode(
|
||||
{
|
||||
accountKey: lookup.accountKey.toBytes(),
|
||||
encodedWritableIndexesLength: new Uint8Array(
|
||||
encodedWritableIndexesLength,
|
||||
),
|
||||
writableIndexes: lookup.writableIndexes,
|
||||
encodedReadonlyIndexesLength: new Uint8Array(
|
||||
encodedReadonlyIndexesLength,
|
||||
),
|
||||
readonlyIndexes: lookup.readonlyIndexes,
|
||||
},
|
||||
serializedAddressTableLookups,
|
||||
serializedLength,
|
||||
);
|
||||
}
|
||||
|
||||
return serializedAddressTableLookups.slice(0, serializedLength);
|
||||
}
|
||||
|
||||
static deserialize(serializedMessage: Uint8Array): MessageV0 {
|
||||
let byteArray = [...serializedMessage];
|
||||
|
||||
const prefix = guardedShift(byteArray);
|
||||
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
||||
assert(
|
||||
prefix !== maskedPrefix,
|
||||
`Expected versioned message but received legacy message`,
|
||||
);
|
||||
|
||||
const version = maskedPrefix;
|
||||
assert(
|
||||
version === 0,
|
||||
`Expected versioned message with version 0 but found version ${version}`,
|
||||
);
|
||||
|
||||
const header: MessageHeader = {
|
||||
numRequiredSignatures: guardedShift(byteArray),
|
||||
numReadonlySignedAccounts: guardedShift(byteArray),
|
||||
numReadonlyUnsignedAccounts: guardedShift(byteArray),
|
||||
};
|
||||
|
||||
const staticAccountKeys = [];
|
||||
const staticAccountKeysLength = shortvec.decodeLength(byteArray);
|
||||
for (let i = 0; i < staticAccountKeysLength; i++) {
|
||||
staticAccountKeys.push(
|
||||
new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)),
|
||||
);
|
||||
}
|
||||
|
||||
const recentBlockhash = bs58.encode(
|
||||
guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH),
|
||||
);
|
||||
|
||||
const instructionCount = shortvec.decodeLength(byteArray);
|
||||
const compiledInstructions: MessageCompiledInstruction[] = [];
|
||||
for (let i = 0; i < instructionCount; i++) {
|
||||
const programIdIndex = guardedShift(byteArray);
|
||||
const accountKeyIndexesLength = shortvec.decodeLength(byteArray);
|
||||
const accountKeyIndexes = guardedSplice(
|
||||
byteArray,
|
||||
0,
|
||||
accountKeyIndexesLength,
|
||||
);
|
||||
const dataLength = shortvec.decodeLength(byteArray);
|
||||
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
||||
compiledInstructions.push({
|
||||
programIdIndex,
|
||||
accountKeyIndexes,
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
const addressTableLookupsCount = shortvec.decodeLength(byteArray);
|
||||
const addressTableLookups: MessageAddressTableLookup[] = [];
|
||||
for (let i = 0; i < addressTableLookupsCount; i++) {
|
||||
const accountKey = new PublicKey(
|
||||
guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH),
|
||||
);
|
||||
const writableIndexesLength = shortvec.decodeLength(byteArray);
|
||||
const writableIndexes = guardedSplice(
|
||||
byteArray,
|
||||
0,
|
||||
writableIndexesLength,
|
||||
);
|
||||
const readonlyIndexesLength = shortvec.decodeLength(byteArray);
|
||||
const readonlyIndexes = guardedSplice(
|
||||
byteArray,
|
||||
0,
|
||||
readonlyIndexesLength,
|
||||
);
|
||||
addressTableLookups.push({
|
||||
accountKey,
|
||||
writableIndexes,
|
||||
readonlyIndexes,
|
||||
});
|
||||
}
|
||||
|
||||
return new MessageV0({
|
||||
header,
|
||||
staticAccountKeys,
|
||||
recentBlockhash,
|
||||
compiledInstructions,
|
||||
addressTableLookups,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export declare var ModifierFlags: any;
|
||||
//# sourceMappingURL=modifierFlags.d.ts.map
|
||||
@@ -0,0 +1,119 @@
|
||||
let len = 0;
|
||||
let vertxNext;
|
||||
let customSchedulerFn;
|
||||
|
||||
export var asap = function asap(callback, arg) {
|
||||
queue[len] = callback;
|
||||
queue[len + 1] = arg;
|
||||
len += 2;
|
||||
if (len === 2) {
|
||||
// If len is 2, that means that we need to schedule an async flush.
|
||||
// If additional callbacks are queued before the queue is flushed, they
|
||||
// will be processed by this flush that we are scheduling.
|
||||
if (customSchedulerFn) {
|
||||
customSchedulerFn(flush);
|
||||
} else {
|
||||
scheduleFlush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function setScheduler(scheduleFn) {
|
||||
customSchedulerFn = scheduleFn;
|
||||
}
|
||||
|
||||
export function setAsap(asapFn) {
|
||||
asap = asapFn;
|
||||
}
|
||||
|
||||
const browserWindow = (typeof window !== 'undefined') ? window : undefined;
|
||||
const browserGlobal = browserWindow || {};
|
||||
const BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
|
||||
const isNode = typeof self === 'undefined' && typeof process !== 'undefined' && {}.toString.call(process) === '[object process]';
|
||||
|
||||
// test for web worker but not in IE10
|
||||
const isWorker = typeof Uint8ClampedArray !== 'undefined' &&
|
||||
typeof importScripts !== 'undefined' &&
|
||||
typeof MessageChannel !== 'undefined';
|
||||
|
||||
// node
|
||||
function useNextTick() {
|
||||
// node version 0.10.x displays a deprecation warning when nextTick is used recursively
|
||||
// see https://github.com/cujojs/when/issues/410 for details
|
||||
return () => process.nextTick(flush);
|
||||
}
|
||||
|
||||
// vertx
|
||||
function useVertxTimer() {
|
||||
if (typeof vertxNext !== 'undefined') {
|
||||
return function() {
|
||||
vertxNext(flush);
|
||||
};
|
||||
}
|
||||
|
||||
return useSetTimeout();
|
||||
}
|
||||
|
||||
function useMutationObserver() {
|
||||
let iterations = 0;
|
||||
const observer = new BrowserMutationObserver(flush);
|
||||
const node = document.createTextNode('');
|
||||
observer.observe(node, { characterData: true });
|
||||
|
||||
return () => {
|
||||
node.data = (iterations = ++iterations % 2);
|
||||
};
|
||||
}
|
||||
|
||||
// web worker
|
||||
function useMessageChannel() {
|
||||
const channel = new MessageChannel();
|
||||
channel.port1.onmessage = flush;
|
||||
return () => channel.port2.postMessage(0);
|
||||
}
|
||||
|
||||
function useSetTimeout() {
|
||||
// Store setTimeout reference so es6-promise will be unaffected by
|
||||
// other code modifying setTimeout (like sinon.useFakeTimers())
|
||||
const globalSetTimeout = setTimeout;
|
||||
return () => globalSetTimeout(flush, 1);
|
||||
}
|
||||
|
||||
const queue = new Array(1000);
|
||||
function flush() {
|
||||
for (let i = 0; i < len; i+=2) {
|
||||
let callback = queue[i];
|
||||
let arg = queue[i+1];
|
||||
|
||||
callback(arg);
|
||||
|
||||
queue[i] = undefined;
|
||||
queue[i+1] = undefined;
|
||||
}
|
||||
|
||||
len = 0;
|
||||
}
|
||||
|
||||
function attemptVertx() {
|
||||
try {
|
||||
const vertx = Function('return this')().require('vertx');
|
||||
vertxNext = vertx.runOnLoop || vertx.runOnContext;
|
||||
return useVertxTimer();
|
||||
} catch(e) {
|
||||
return useSetTimeout();
|
||||
}
|
||||
}
|
||||
|
||||
let scheduleFlush;
|
||||
// Decide what async method to use to triggering processing of queued callbacks:
|
||||
if (isNode) {
|
||||
scheduleFlush = useNextTick();
|
||||
} else if (BrowserMutationObserver) {
|
||||
scheduleFlush = useMutationObserver();
|
||||
} else if (isWorker) {
|
||||
scheduleFlush = useMessageChannel();
|
||||
} else if (browserWindow === undefined && typeof require === 'function') {
|
||||
scheduleFlush = attemptVertx();
|
||||
} else {
|
||||
scheduleFlush = useSetTimeout();
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = string => {
|
||||
if (typeof string !== 'string') {
|
||||
throw new TypeError('Expected a string');
|
||||
}
|
||||
|
||||
// Escape characters with special meaning either inside or outside character sets.
|
||||
// Use a simple backslash escape when it’s always valid, and a \unnnn escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar.
|
||||
return string
|
||||
.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')
|
||||
.replace(/-/g, '\\x2d');
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(r="undefined"!=typeof globalThis?globalThis:r||self).uuidv5=e()}(this,(function(){"use strict";var r=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function e(e){return"string"==typeof e&&r.test(e)}for(var t=[],n=0;n<256;++n)t.push((n+256).toString(16).substr(1));function a(r,e,t,n){switch(r){case 0:return e&t^~e&n;case 1:return e^t^n;case 2:return e&t^e&n^t&n;case 3:return e^t^n}}function o(r,e){return r<<e|r>>>32-e}return function(r,n,a){function o(r,o,i,f){if("string"==typeof r&&(r=function(r){r=unescape(encodeURIComponent(r));for(var e=[],t=0;t<r.length;++t)e.push(r.charCodeAt(t));return e}(r)),"string"==typeof o&&(o=function(r){if(!e(r))throw TypeError("Invalid UUID");var t,n=new Uint8Array(16);return n[0]=(t=parseInt(r.slice(0,8),16))>>>24,n[1]=t>>>16&255,n[2]=t>>>8&255,n[3]=255&t,n[4]=(t=parseInt(r.slice(9,13),16))>>>8,n[5]=255&t,n[6]=(t=parseInt(r.slice(14,18),16))>>>8,n[7]=255&t,n[8]=(t=parseInt(r.slice(19,23),16))>>>8,n[9]=255&t,n[10]=(t=parseInt(r.slice(24,36),16))/1099511627776&255,n[11]=t/4294967296&255,n[12]=t>>>24&255,n[13]=t>>>16&255,n[14]=t>>>8&255,n[15]=255&t,n}(o)),16!==o.length)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");var s=new Uint8Array(16+r.length);if(s.set(o),s.set(r,o.length),(s=a(s))[6]=15&s[6]|n,s[8]=63&s[8]|128,i){f=f||0;for(var u=0;u<16;++u)i[f+u]=s[u];return i}return function(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,a=(t[r[n+0]]+t[r[n+1]]+t[r[n+2]]+t[r[n+3]]+"-"+t[r[n+4]]+t[r[n+5]]+"-"+t[r[n+6]]+t[r[n+7]]+"-"+t[r[n+8]]+t[r[n+9]]+"-"+t[r[n+10]]+t[r[n+11]]+t[r[n+12]]+t[r[n+13]]+t[r[n+14]]+t[r[n+15]]).toLowerCase();if(!e(a))throw TypeError("Stringified UUID is invalid");return a}(s)}try{o.name=r}catch(r){}return o.DNS="6ba7b810-9dad-11d1-80b4-00c04fd430c8",o.URL="6ba7b811-9dad-11d1-80b4-00c04fd430c8",o}("v5",80,(function(r){var e=[1518500249,1859775393,2400959708,3395469782],t=[1732584193,4023233417,2562383102,271733878,3285377520];if("string"==typeof r){var n=unescape(encodeURIComponent(r));r=[];for(var i=0;i<n.length;++i)r.push(n.charCodeAt(i))}else Array.isArray(r)||(r=Array.prototype.slice.call(r));r.push(128);for(var f=r.length/4+2,s=Math.ceil(f/16),u=new Array(s),c=0;c<s;++c){for(var l=new Uint32Array(16),p=0;p<16;++p)l[p]=r[64*c+4*p]<<24|r[64*c+4*p+1]<<16|r[64*c+4*p+2]<<8|r[64*c+4*p+3];u[c]=l}u[s-1][14]=8*(r.length-1)/Math.pow(2,32),u[s-1][14]=Math.floor(u[s-1][14]),u[s-1][15]=8*(r.length-1)&4294967295;for(var d=0;d<s;++d){for(var h=new Uint32Array(80),v=0;v<16;++v)h[v]=u[d][v];for(var y=16;y<80;++y)h[y]=o(h[y-3]^h[y-8]^h[y-14]^h[y-16],1);for(var g=t[0],b=t[1],w=t[2],U=t[3],A=t[4],I=0;I<80;++I){var m=Math.floor(I/20),C=o(g,5)+a(m,b,w,U)+A+e[m]+h[I]>>>0;A=U,U=w,w=o(b,30)>>>0,b=g,g=C}t[0]=t[0]+g>>>0,t[1]=t[1]+b>>>0,t[2]=t[2]+w>>>0,t[3]=t[3]+U>>>0,t[4]=t[4]+A>>>0}return[t[0]>>24&255,t[0]>>16&255,t[0]>>8&255,255&t[0],t[1]>>24&255,t[1]>>16&255,t[1]>>8&255,255&t[1],t[2]>>24&255,t[2]>>16&255,t[2]>>8&255,255&t[2],t[3]>>24&255,t[3]>>16&255,t[3]>>8&255,255&t[3],t[4]>>24&255,t[4]>>16&255,t[4]>>8&255,255&t[4]]}))}));
|
||||
@@ -0,0 +1,82 @@
|
||||
'use strict'
|
||||
|
||||
const bench = require('fastbench')
|
||||
const pino = require('../')
|
||||
const bunyan = require('bunyan')
|
||||
const bole = require('bole')('bench')
|
||||
const winston = require('winston')
|
||||
const fs = require('node:fs')
|
||||
const dest = fs.createWriteStream('/dev/null')
|
||||
const loglevel = require('./utils/wrap-log-level')(dest)
|
||||
const plogNodeStream = pino(dest)
|
||||
delete require.cache[require.resolve('../')]
|
||||
const plogDest = require('../')(pino.destination('/dev/null'))
|
||||
delete require.cache[require.resolve('../')]
|
||||
const plogMinLength = require('../')(pino.destination({ dest: '/dev/null', sync: false, minLength: 4096 }))
|
||||
const blog = bunyan.createLogger({
|
||||
name: 'myapp',
|
||||
streams: [{
|
||||
level: 'trace',
|
||||
stream: dest
|
||||
}]
|
||||
})
|
||||
require('bole').output({
|
||||
level: 'info',
|
||||
stream: dest
|
||||
}).setFastTime(true)
|
||||
const chill = winston.createLogger({
|
||||
transports: [
|
||||
new winston.transports.Stream({
|
||||
stream: fs.createWriteStream('/dev/null')
|
||||
})
|
||||
]
|
||||
})
|
||||
|
||||
const max = 10
|
||||
|
||||
const run = bench([
|
||||
function benchBunyanObj (cb) {
|
||||
for (var i = 0; i < max; i++) {
|
||||
blog.info({ hello: 'world' })
|
||||
}
|
||||
setImmediate(cb)
|
||||
},
|
||||
function benchWinstonObj (cb) {
|
||||
for (var i = 0; i < max; i++) {
|
||||
chill.info({ hello: 'world' })
|
||||
}
|
||||
setImmediate(cb)
|
||||
},
|
||||
function benchBoleObj (cb) {
|
||||
for (var i = 0; i < max; i++) {
|
||||
bole.info({ hello: 'world' })
|
||||
}
|
||||
setImmediate(cb)
|
||||
},
|
||||
function benchLogLevelObject (cb) {
|
||||
for (var i = 0; i < max; i++) {
|
||||
loglevel.info({ hello: 'world' })
|
||||
}
|
||||
setImmediate(cb)
|
||||
},
|
||||
function benchPinoObj (cb) {
|
||||
for (var i = 0; i < max; i++) {
|
||||
plogDest.info({ hello: 'world' })
|
||||
}
|
||||
setImmediate(cb)
|
||||
},
|
||||
function benchPinoMinLengthObj (cb) {
|
||||
for (var i = 0; i < max; i++) {
|
||||
plogMinLength.info({ hello: 'world' })
|
||||
}
|
||||
setImmediate(cb)
|
||||
},
|
||||
function benchPinoNodeStreamObj (cb) {
|
||||
for (var i = 0; i < max; i++) {
|
||||
plogNodeStream.info({ hello: 'world' })
|
||||
}
|
||||
setImmediate(cb)
|
||||
}
|
||||
], 10000)
|
||||
|
||||
run(run)
|
||||
@@ -0,0 +1,24 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
interface ObjectConstructor {
|
||||
/**
|
||||
* Determines whether an object has a property with the specified name.
|
||||
* @param o An object.
|
||||
* @param v A property name.
|
||||
*/
|
||||
hasOwn(o: object, v: PropertyKey): boolean;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
if [[ -n $TRAVIS_TAG && $TRAVIS_JOB_NUMBER =~ ".3" ]]; then
|
||||
echo "About to publish $TRAVIS_TAG to ajv-dist..."
|
||||
|
||||
git config user.email "$GIT_USER_EMAIL"
|
||||
git config user.name "$GIT_USER_NAME"
|
||||
|
||||
git clone https://${GITHUB_TOKEN}@github.com/ajv-validator/ajv-dist.git ../ajv-dist
|
||||
|
||||
rm -rf ../ajv-dist/dist
|
||||
mkdir ../ajv-dist/dist
|
||||
cp ./dist/ajv.* ../ajv-dist/dist
|
||||
cat bower.json | sed 's/"name": "ajv"/"name": "ajv-dist"/' > ../ajv-dist/bower.json
|
||||
cd ../ajv-dist
|
||||
|
||||
if [[ `git status --porcelain` ]]; then
|
||||
echo "Changes detected. Updating master branch..."
|
||||
git add -A
|
||||
git commit -m "updated by travis build #$TRAVIS_BUILD_NUMBER"
|
||||
git push --quiet origin master > /dev/null 2>&1
|
||||
fi
|
||||
|
||||
echo "Publishing tag..."
|
||||
|
||||
git tag $TRAVIS_TAG
|
||||
git push --tags > /dev/null 2>&1
|
||||
|
||||
echo "Done"
|
||||
fi
|
||||
@@ -0,0 +1,13 @@
|
||||
export {};
|
||||
|
||||
import { URL } from "node:url";
|
||||
|
||||
declare global {
|
||||
interface ImportMeta {
|
||||
dirname: string;
|
||||
filename: string;
|
||||
main: boolean;
|
||||
url: string;
|
||||
resolve(specifier: string, parent?: string | URL): string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.zhCN = exports.vi = exports.uz = exports.ur = exports.uk = exports.ua = exports.tr = exports.th = exports.ta = exports.sv = exports.sl = exports.ru = exports.ro = exports.pt = exports.pl = exports.ps = exports.ota = exports.no = exports.nl = exports.ms = exports.mk = exports.lt = exports.ko = exports.km = exports.kh = exports.ka = exports.ja = exports.it = exports.is = exports.id = exports.hy = exports.hu = exports.hr = exports.he = exports.frCA = exports.fr = exports.fi = exports.fa = exports.es = exports.eo = exports.en = exports.el = exports.de = exports.da = exports.cs = exports.ca = exports.bg = exports.be = exports.az = exports.ar = void 0;
|
||||
exports.yo = exports.zhTW = void 0;
|
||||
var ar_js_1 = require("./ar.cjs");
|
||||
Object.defineProperty(exports, "ar", { enumerable: true, get: function () { return __importDefault(ar_js_1).default; } });
|
||||
var az_js_1 = require("./az.cjs");
|
||||
Object.defineProperty(exports, "az", { enumerable: true, get: function () { return __importDefault(az_js_1).default; } });
|
||||
var be_js_1 = require("./be.cjs");
|
||||
Object.defineProperty(exports, "be", { enumerable: true, get: function () { return __importDefault(be_js_1).default; } });
|
||||
var bg_js_1 = require("./bg.cjs");
|
||||
Object.defineProperty(exports, "bg", { enumerable: true, get: function () { return __importDefault(bg_js_1).default; } });
|
||||
var ca_js_1 = require("./ca.cjs");
|
||||
Object.defineProperty(exports, "ca", { enumerable: true, get: function () { return __importDefault(ca_js_1).default; } });
|
||||
var cs_js_1 = require("./cs.cjs");
|
||||
Object.defineProperty(exports, "cs", { enumerable: true, get: function () { return __importDefault(cs_js_1).default; } });
|
||||
var da_js_1 = require("./da.cjs");
|
||||
Object.defineProperty(exports, "da", { enumerable: true, get: function () { return __importDefault(da_js_1).default; } });
|
||||
var de_js_1 = require("./de.cjs");
|
||||
Object.defineProperty(exports, "de", { enumerable: true, get: function () { return __importDefault(de_js_1).default; } });
|
||||
var el_js_1 = require("./el.cjs");
|
||||
Object.defineProperty(exports, "el", { enumerable: true, get: function () { return __importDefault(el_js_1).default; } });
|
||||
var en_js_1 = require("./en.cjs");
|
||||
Object.defineProperty(exports, "en", { enumerable: true, get: function () { return __importDefault(en_js_1).default; } });
|
||||
var eo_js_1 = require("./eo.cjs");
|
||||
Object.defineProperty(exports, "eo", { enumerable: true, get: function () { return __importDefault(eo_js_1).default; } });
|
||||
var es_js_1 = require("./es.cjs");
|
||||
Object.defineProperty(exports, "es", { enumerable: true, get: function () { return __importDefault(es_js_1).default; } });
|
||||
var fa_js_1 = require("./fa.cjs");
|
||||
Object.defineProperty(exports, "fa", { enumerable: true, get: function () { return __importDefault(fa_js_1).default; } });
|
||||
var fi_js_1 = require("./fi.cjs");
|
||||
Object.defineProperty(exports, "fi", { enumerable: true, get: function () { return __importDefault(fi_js_1).default; } });
|
||||
var fr_js_1 = require("./fr.cjs");
|
||||
Object.defineProperty(exports, "fr", { enumerable: true, get: function () { return __importDefault(fr_js_1).default; } });
|
||||
var fr_CA_js_1 = require("./fr-CA.cjs");
|
||||
Object.defineProperty(exports, "frCA", { enumerable: true, get: function () { return __importDefault(fr_CA_js_1).default; } });
|
||||
var he_js_1 = require("./he.cjs");
|
||||
Object.defineProperty(exports, "he", { enumerable: true, get: function () { return __importDefault(he_js_1).default; } });
|
||||
var hr_js_1 = require("./hr.cjs");
|
||||
Object.defineProperty(exports, "hr", { enumerable: true, get: function () { return __importDefault(hr_js_1).default; } });
|
||||
var hu_js_1 = require("./hu.cjs");
|
||||
Object.defineProperty(exports, "hu", { enumerable: true, get: function () { return __importDefault(hu_js_1).default; } });
|
||||
var hy_js_1 = require("./hy.cjs");
|
||||
Object.defineProperty(exports, "hy", { enumerable: true, get: function () { return __importDefault(hy_js_1).default; } });
|
||||
var id_js_1 = require("./id.cjs");
|
||||
Object.defineProperty(exports, "id", { enumerable: true, get: function () { return __importDefault(id_js_1).default; } });
|
||||
var is_js_1 = require("./is.cjs");
|
||||
Object.defineProperty(exports, "is", { enumerable: true, get: function () { return __importDefault(is_js_1).default; } });
|
||||
var it_js_1 = require("./it.cjs");
|
||||
Object.defineProperty(exports, "it", { enumerable: true, get: function () { return __importDefault(it_js_1).default; } });
|
||||
var ja_js_1 = require("./ja.cjs");
|
||||
Object.defineProperty(exports, "ja", { enumerable: true, get: function () { return __importDefault(ja_js_1).default; } });
|
||||
var ka_js_1 = require("./ka.cjs");
|
||||
Object.defineProperty(exports, "ka", { enumerable: true, get: function () { return __importDefault(ka_js_1).default; } });
|
||||
var kh_js_1 = require("./kh.cjs");
|
||||
Object.defineProperty(exports, "kh", { enumerable: true, get: function () { return __importDefault(kh_js_1).default; } });
|
||||
var km_js_1 = require("./km.cjs");
|
||||
Object.defineProperty(exports, "km", { enumerable: true, get: function () { return __importDefault(km_js_1).default; } });
|
||||
var ko_js_1 = require("./ko.cjs");
|
||||
Object.defineProperty(exports, "ko", { enumerable: true, get: function () { return __importDefault(ko_js_1).default; } });
|
||||
var lt_js_1 = require("./lt.cjs");
|
||||
Object.defineProperty(exports, "lt", { enumerable: true, get: function () { return __importDefault(lt_js_1).default; } });
|
||||
var mk_js_1 = require("./mk.cjs");
|
||||
Object.defineProperty(exports, "mk", { enumerable: true, get: function () { return __importDefault(mk_js_1).default; } });
|
||||
var ms_js_1 = require("./ms.cjs");
|
||||
Object.defineProperty(exports, "ms", { enumerable: true, get: function () { return __importDefault(ms_js_1).default; } });
|
||||
var nl_js_1 = require("./nl.cjs");
|
||||
Object.defineProperty(exports, "nl", { enumerable: true, get: function () { return __importDefault(nl_js_1).default; } });
|
||||
var no_js_1 = require("./no.cjs");
|
||||
Object.defineProperty(exports, "no", { enumerable: true, get: function () { return __importDefault(no_js_1).default; } });
|
||||
var ota_js_1 = require("./ota.cjs");
|
||||
Object.defineProperty(exports, "ota", { enumerable: true, get: function () { return __importDefault(ota_js_1).default; } });
|
||||
var ps_js_1 = require("./ps.cjs");
|
||||
Object.defineProperty(exports, "ps", { enumerable: true, get: function () { return __importDefault(ps_js_1).default; } });
|
||||
var pl_js_1 = require("./pl.cjs");
|
||||
Object.defineProperty(exports, "pl", { enumerable: true, get: function () { return __importDefault(pl_js_1).default; } });
|
||||
var pt_js_1 = require("./pt.cjs");
|
||||
Object.defineProperty(exports, "pt", { enumerable: true, get: function () { return __importDefault(pt_js_1).default; } });
|
||||
var ro_js_1 = require("./ro.cjs");
|
||||
Object.defineProperty(exports, "ro", { enumerable: true, get: function () { return __importDefault(ro_js_1).default; } });
|
||||
var ru_js_1 = require("./ru.cjs");
|
||||
Object.defineProperty(exports, "ru", { enumerable: true, get: function () { return __importDefault(ru_js_1).default; } });
|
||||
var sl_js_1 = require("./sl.cjs");
|
||||
Object.defineProperty(exports, "sl", { enumerable: true, get: function () { return __importDefault(sl_js_1).default; } });
|
||||
var sv_js_1 = require("./sv.cjs");
|
||||
Object.defineProperty(exports, "sv", { enumerable: true, get: function () { return __importDefault(sv_js_1).default; } });
|
||||
var ta_js_1 = require("./ta.cjs");
|
||||
Object.defineProperty(exports, "ta", { enumerable: true, get: function () { return __importDefault(ta_js_1).default; } });
|
||||
var th_js_1 = require("./th.cjs");
|
||||
Object.defineProperty(exports, "th", { enumerable: true, get: function () { return __importDefault(th_js_1).default; } });
|
||||
var tr_js_1 = require("./tr.cjs");
|
||||
Object.defineProperty(exports, "tr", { enumerable: true, get: function () { return __importDefault(tr_js_1).default; } });
|
||||
var ua_js_1 = require("./ua.cjs");
|
||||
Object.defineProperty(exports, "ua", { enumerable: true, get: function () { return __importDefault(ua_js_1).default; } });
|
||||
var uk_js_1 = require("./uk.cjs");
|
||||
Object.defineProperty(exports, "uk", { enumerable: true, get: function () { return __importDefault(uk_js_1).default; } });
|
||||
var ur_js_1 = require("./ur.cjs");
|
||||
Object.defineProperty(exports, "ur", { enumerable: true, get: function () { return __importDefault(ur_js_1).default; } });
|
||||
var uz_js_1 = require("./uz.cjs");
|
||||
Object.defineProperty(exports, "uz", { enumerable: true, get: function () { return __importDefault(uz_js_1).default; } });
|
||||
var vi_js_1 = require("./vi.cjs");
|
||||
Object.defineProperty(exports, "vi", { enumerable: true, get: function () { return __importDefault(vi_js_1).default; } });
|
||||
var zh_CN_js_1 = require("./zh-CN.cjs");
|
||||
Object.defineProperty(exports, "zhCN", { enumerable: true, get: function () { return __importDefault(zh_CN_js_1).default; } });
|
||||
var zh_TW_js_1 = require("./zh-TW.cjs");
|
||||
Object.defineProperty(exports, "zhTW", { enumerable: true, get: function () { return __importDefault(zh_TW_js_1).default; } });
|
||||
var yo_js_1 = require("./yo.cjs");
|
||||
Object.defineProperty(exports, "yo", { enumerable: true, get: function () { return __importDefault(yo_js_1).default; } });
|
||||
@@ -0,0 +1,466 @@
|
||||
declare module "node:buffer" {
|
||||
type ImplicitArrayBuffer<T extends WithImplicitCoercion<ArrayBufferLike>> = T extends
|
||||
{ valueOf(): infer V extends ArrayBufferLike } ? V : T;
|
||||
global {
|
||||
interface BufferConstructor {
|
||||
// see buffer.d.ts for implementation shared with all TypeScript versions
|
||||
|
||||
/**
|
||||
* Allocates a new buffer containing the given {str}.
|
||||
*
|
||||
* @param str String to store in buffer.
|
||||
* @param encoding encoding to use, optional. Default is 'utf8'
|
||||
* @deprecated since v10.0.0 - Use `Buffer.from(string[, encoding])` instead.
|
||||
*/
|
||||
new(str: string, encoding?: BufferEncoding): Buffer<ArrayBuffer>;
|
||||
/**
|
||||
* Allocates a new buffer of {size} octets.
|
||||
*
|
||||
* @param size count of octets to allocate.
|
||||
* @deprecated since v10.0.0 - Use `Buffer.alloc()` instead (also see `Buffer.allocUnsafe()`).
|
||||
*/
|
||||
new(size: number): Buffer<ArrayBuffer>;
|
||||
/**
|
||||
* Allocates a new buffer containing the given {array} of octets.
|
||||
*
|
||||
* @param array The octets to store.
|
||||
* @deprecated since v10.0.0 - Use `Buffer.from(array)` instead.
|
||||
*/
|
||||
new(array: ArrayLike<number>): Buffer<ArrayBuffer>;
|
||||
/**
|
||||
* Produces a Buffer backed by the same allocated memory as
|
||||
* the given {ArrayBuffer}/{SharedArrayBuffer}.
|
||||
*
|
||||
* @param arrayBuffer The ArrayBuffer with which to share memory.
|
||||
* @deprecated since v10.0.0 - Use `Buffer.from(arrayBuffer[, byteOffset[, length]])` instead.
|
||||
*/
|
||||
new<TArrayBuffer extends ArrayBufferLike = ArrayBuffer>(arrayBuffer: TArrayBuffer): Buffer<TArrayBuffer>;
|
||||
/**
|
||||
* Allocates a new `Buffer` using an `array` of bytes in the range `0` – `255`.
|
||||
* Array entries outside that range will be truncated to fit into it.
|
||||
*
|
||||
* ```js
|
||||
* import { Buffer } from 'node:buffer';
|
||||
*
|
||||
* // Creates a new Buffer containing the UTF-8 bytes of the string 'buffer'.
|
||||
* const buf = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
|
||||
* ```
|
||||
*
|
||||
* If `array` is an `Array`-like object (that is, one with a `length` property of
|
||||
* type `number`), it is treated as if it is an array, unless it is a `Buffer` or
|
||||
* a `Uint8Array`. This means all other `TypedArray` variants get treated as an
|
||||
* `Array`. To create a `Buffer` from the bytes backing a `TypedArray`, use
|
||||
* `Buffer.copyBytesFrom()`.
|
||||
*
|
||||
* A `TypeError` will be thrown if `array` is not an `Array` or another type
|
||||
* appropriate for `Buffer.from()` variants.
|
||||
*
|
||||
* `Buffer.from(array)` and `Buffer.from(string)` may also use the internal
|
||||
* `Buffer` pool like `Buffer.allocUnsafe()` does.
|
||||
* @since v5.10.0
|
||||
*/
|
||||
from(array: WithImplicitCoercion<ArrayLike<number>>): Buffer<ArrayBuffer>;
|
||||
/**
|
||||
* This creates a view of the `ArrayBuffer` without copying the underlying
|
||||
* memory. For example, when passed a reference to the `.buffer` property of a
|
||||
* `TypedArray` instance, the newly created `Buffer` will share the same
|
||||
* allocated memory as the `TypedArray`'s underlying `ArrayBuffer`.
|
||||
*
|
||||
* ```js
|
||||
* import { Buffer } from 'node:buffer';
|
||||
*
|
||||
* const arr = new Uint16Array(2);
|
||||
*
|
||||
* arr[0] = 5000;
|
||||
* arr[1] = 4000;
|
||||
*
|
||||
* // Shares memory with `arr`.
|
||||
* const buf = Buffer.from(arr.buffer);
|
||||
*
|
||||
* console.log(buf);
|
||||
* // Prints: <Buffer 88 13 a0 0f>
|
||||
*
|
||||
* // Changing the original Uint16Array changes the Buffer also.
|
||||
* arr[1] = 6000;
|
||||
*
|
||||
* console.log(buf);
|
||||
* // Prints: <Buffer 88 13 70 17>
|
||||
* ```
|
||||
*
|
||||
* The optional `byteOffset` and `length` arguments specify a memory range within
|
||||
* the `arrayBuffer` that will be shared by the `Buffer`.
|
||||
*
|
||||
* ```js
|
||||
* import { Buffer } from 'node:buffer';
|
||||
*
|
||||
* const ab = new ArrayBuffer(10);
|
||||
* const buf = Buffer.from(ab, 0, 2);
|
||||
*
|
||||
* console.log(buf.length);
|
||||
* // Prints: 2
|
||||
* ```
|
||||
*
|
||||
* A `TypeError` will be thrown if `arrayBuffer` is not an `ArrayBuffer` or a
|
||||
* `SharedArrayBuffer` or another type appropriate for `Buffer.from()`
|
||||
* variants.
|
||||
*
|
||||
* It is important to remember that a backing `ArrayBuffer` can cover a range
|
||||
* of memory that extends beyond the bounds of a `TypedArray` view. A new
|
||||
* `Buffer` created using the `buffer` property of a `TypedArray` may extend
|
||||
* beyond the range of the `TypedArray`:
|
||||
*
|
||||
* ```js
|
||||
* import { Buffer } from 'node:buffer';
|
||||
*
|
||||
* const arrA = Uint8Array.from([0x63, 0x64, 0x65, 0x66]); // 4 elements
|
||||
* const arrB = new Uint8Array(arrA.buffer, 1, 2); // 2 elements
|
||||
* console.log(arrA.buffer === arrB.buffer); // true
|
||||
*
|
||||
* const buf = Buffer.from(arrB.buffer);
|
||||
* console.log(buf);
|
||||
* // Prints: <Buffer 63 64 65 66>
|
||||
* ```
|
||||
* @since v5.10.0
|
||||
* @param arrayBuffer An `ArrayBuffer`, `SharedArrayBuffer`, for example the
|
||||
* `.buffer` property of a `TypedArray`.
|
||||
* @param byteOffset Index of first byte to expose. **Default:** `0`.
|
||||
* @param length Number of bytes to expose. **Default:**
|
||||
* `arrayBuffer.byteLength - byteOffset`.
|
||||
*/
|
||||
from<TArrayBuffer extends WithImplicitCoercion<ArrayBufferLike>>(
|
||||
arrayBuffer: TArrayBuffer,
|
||||
byteOffset?: number,
|
||||
length?: number,
|
||||
): Buffer<ImplicitArrayBuffer<TArrayBuffer>>;
|
||||
/**
|
||||
* Creates a new `Buffer` containing `string`. The `encoding` parameter identifies
|
||||
* the character encoding to be used when converting `string` into bytes.
|
||||
*
|
||||
* ```js
|
||||
* import { Buffer } from 'node:buffer';
|
||||
*
|
||||
* const buf1 = Buffer.from('this is a tést');
|
||||
* const buf2 = Buffer.from('7468697320697320612074c3a97374', 'hex');
|
||||
*
|
||||
* console.log(buf1.toString());
|
||||
* // Prints: this is a tést
|
||||
* console.log(buf2.toString());
|
||||
* // Prints: this is a tést
|
||||
* console.log(buf1.toString('latin1'));
|
||||
* // Prints: this is a tést
|
||||
* ```
|
||||
*
|
||||
* A `TypeError` will be thrown if `string` is not a string or another type
|
||||
* appropriate for `Buffer.from()` variants.
|
||||
*
|
||||
* `Buffer.from(string)` may also use the internal `Buffer` pool like
|
||||
* `Buffer.allocUnsafe()` does.
|
||||
* @since v5.10.0
|
||||
* @param string A string to encode.
|
||||
* @param encoding The encoding of `string`. **Default:** `'utf8'`.
|
||||
*/
|
||||
from(string: WithImplicitCoercion<string>, encoding?: BufferEncoding): Buffer<ArrayBuffer>;
|
||||
from(arrayOrString: WithImplicitCoercion<ArrayLike<number> | string>): Buffer<ArrayBuffer>;
|
||||
/**
|
||||
* Creates a new Buffer using the passed {data}
|
||||
* @param values to create a new Buffer
|
||||
*/
|
||||
of(...items: number[]): Buffer<ArrayBuffer>;
|
||||
/**
|
||||
* Returns a new `Buffer` which is the result of concatenating all the `Buffer` instances in the `list` together.
|
||||
*
|
||||
* If the list has no items, or if the `totalLength` is 0, then a new zero-length `Buffer` is returned.
|
||||
*
|
||||
* If `totalLength` is not provided, it is calculated from the `Buffer` instances
|
||||
* in `list` by adding their lengths.
|
||||
*
|
||||
* If `totalLength` is provided, it must be an unsigned integer. If the
|
||||
* combined length of the `Buffer`s in `list` exceeds `totalLength`, the result is
|
||||
* truncated to `totalLength`. If the combined length of the `Buffer`s in `list` is
|
||||
* less than `totalLength`, the remaining space is filled with zeros.
|
||||
*
|
||||
* ```js
|
||||
* import { Buffer } from 'node:buffer';
|
||||
*
|
||||
* // Create a single `Buffer` from a list of three `Buffer` instances.
|
||||
*
|
||||
* const buf1 = Buffer.alloc(10);
|
||||
* const buf2 = Buffer.alloc(14);
|
||||
* const buf3 = Buffer.alloc(18);
|
||||
* const totalLength = buf1.length + buf2.length + buf3.length;
|
||||
*
|
||||
* console.log(totalLength);
|
||||
* // Prints: 42
|
||||
*
|
||||
* const bufA = Buffer.concat([buf1, buf2, buf3], totalLength);
|
||||
*
|
||||
* console.log(bufA);
|
||||
* // Prints: <Buffer 00 00 00 00 ...>
|
||||
* console.log(bufA.length);
|
||||
* // Prints: 42
|
||||
* ```
|
||||
*
|
||||
* `Buffer.concat()` may also use the internal `Buffer` pool like `Buffer.allocUnsafe()` does.
|
||||
* @since v0.7.11
|
||||
* @param list List of `Buffer` or {@link Uint8Array} instances to concatenate.
|
||||
* @param totalLength Total length of the `Buffer` instances in `list` when concatenated.
|
||||
*/
|
||||
concat(list: readonly Uint8Array[], totalLength?: number): Buffer<ArrayBuffer>;
|
||||
/**
|
||||
* Copies the underlying memory of `view` into a new `Buffer`.
|
||||
*
|
||||
* ```js
|
||||
* const u16 = new Uint16Array([0, 0xffff]);
|
||||
* const buf = Buffer.copyBytesFrom(u16, 1, 1);
|
||||
* u16[1] = 0;
|
||||
* console.log(buf.length); // 2
|
||||
* console.log(buf[0]); // 255
|
||||
* console.log(buf[1]); // 255
|
||||
* ```
|
||||
* @since v19.8.0
|
||||
* @param view The {TypedArray} to copy.
|
||||
* @param [offset=0] The starting offset within `view`.
|
||||
* @param [length=view.length - offset] The number of elements from `view` to copy.
|
||||
*/
|
||||
copyBytesFrom(view: NodeJS.TypedArray, offset?: number, length?: number): Buffer<ArrayBuffer>;
|
||||
/**
|
||||
* Allocates a new `Buffer` of `size` bytes. If `fill` is `undefined`, the`Buffer` will be zero-filled.
|
||||
*
|
||||
* ```js
|
||||
* import { Buffer } from 'node:buffer';
|
||||
*
|
||||
* const buf = Buffer.alloc(5);
|
||||
*
|
||||
* console.log(buf);
|
||||
* // Prints: <Buffer 00 00 00 00 00>
|
||||
* ```
|
||||
*
|
||||
* If `size` is larger than {@link constants.MAX_LENGTH} or smaller than 0, `ERR_OUT_OF_RANGE` is thrown.
|
||||
*
|
||||
* If `fill` is specified, the allocated `Buffer` will be initialized by calling `buf.fill(fill)`.
|
||||
*
|
||||
* ```js
|
||||
* import { Buffer } from 'node:buffer';
|
||||
*
|
||||
* const buf = Buffer.alloc(5, 'a');
|
||||
*
|
||||
* console.log(buf);
|
||||
* // Prints: <Buffer 61 61 61 61 61>
|
||||
* ```
|
||||
*
|
||||
* If both `fill` and `encoding` are specified, the allocated `Buffer` will be
|
||||
* initialized by calling `buf.fill(fill, encoding)`.
|
||||
*
|
||||
* ```js
|
||||
* import { Buffer } from 'node:buffer';
|
||||
*
|
||||
* const buf = Buffer.alloc(11, 'aGVsbG8gd29ybGQ=', 'base64');
|
||||
*
|
||||
* console.log(buf);
|
||||
* // Prints: <Buffer 68 65 6c 6c 6f 20 77 6f 72 6c 64>
|
||||
* ```
|
||||
*
|
||||
* Calling `Buffer.alloc()` can be measurably slower than the alternative `Buffer.allocUnsafe()` but ensures that the newly created `Buffer` instance
|
||||
* contents will never contain sensitive data from previous allocations, including
|
||||
* data that might not have been allocated for `Buffer`s.
|
||||
*
|
||||
* A `TypeError` will be thrown if `size` is not a number.
|
||||
* @since v5.10.0
|
||||
* @param size The desired length of the new `Buffer`.
|
||||
* @param [fill=0] A value to pre-fill the new `Buffer` with.
|
||||
* @param [encoding='utf8'] If `fill` is a string, this is its encoding.
|
||||
*/
|
||||
alloc(size: number, fill?: string | Uint8Array | number, encoding?: BufferEncoding): Buffer<ArrayBuffer>;
|
||||
/**
|
||||
* Allocates a new `Buffer` of `size` bytes. If `size` is larger than {@link constants.MAX_LENGTH} or smaller than 0, `ERR_OUT_OF_RANGE` is thrown.
|
||||
*
|
||||
* The underlying memory for `Buffer` instances created in this way is _not_
|
||||
* _initialized_. The contents of the newly created `Buffer` are unknown and _may contain sensitive data_. Use `Buffer.alloc()` instead to initialize`Buffer` instances with zeroes.
|
||||
*
|
||||
* ```js
|
||||
* import { Buffer } from 'node:buffer';
|
||||
*
|
||||
* const buf = Buffer.allocUnsafe(10);
|
||||
*
|
||||
* console.log(buf);
|
||||
* // Prints (contents may vary): <Buffer a0 8b 28 3f 01 00 00 00 50 32>
|
||||
*
|
||||
* buf.fill(0);
|
||||
*
|
||||
* console.log(buf);
|
||||
* // Prints: <Buffer 00 00 00 00 00 00 00 00 00 00>
|
||||
* ```
|
||||
*
|
||||
* A `TypeError` will be thrown if `size` is not a number.
|
||||
*
|
||||
* The `Buffer` module pre-allocates an internal `Buffer` instance of
|
||||
* size `Buffer.poolSize` that is used as a pool for the fast allocation of new `Buffer` instances created using `Buffer.allocUnsafe()`, `Buffer.from(array)`,
|
||||
* and `Buffer.concat()` only when `size` is less than `Buffer.poolSize >>> 1` (floor of `Buffer.poolSize` divided by two).
|
||||
*
|
||||
* Use of this pre-allocated internal memory pool is a key difference between
|
||||
* calling `Buffer.alloc(size, fill)` vs. `Buffer.allocUnsafe(size).fill(fill)`.
|
||||
* Specifically, `Buffer.alloc(size, fill)` will _never_ use the internal `Buffer`pool, while `Buffer.allocUnsafe(size).fill(fill)`_will_ use the internal`Buffer` pool if `size` is less
|
||||
* than or equal to half `Buffer.poolSize`. The
|
||||
* difference is subtle but can be important when an application requires the
|
||||
* additional performance that `Buffer.allocUnsafe()` provides.
|
||||
* @since v5.10.0
|
||||
* @param size The desired length of the new `Buffer`.
|
||||
*/
|
||||
allocUnsafe(size: number): Buffer<ArrayBuffer>;
|
||||
/**
|
||||
* Allocates a new `Buffer` of `size` bytes. If `size` is larger than {@link constants.MAX_LENGTH} or smaller than 0, `ERR_OUT_OF_RANGE` is thrown. A zero-length `Buffer` is created if
|
||||
* `size` is 0.
|
||||
*
|
||||
* The underlying memory for `Buffer` instances created in this way is _not_
|
||||
* _initialized_. The contents of the newly created `Buffer` are unknown and _may contain sensitive data_. Use `buf.fill(0)` to initialize
|
||||
* such `Buffer` instances with zeroes.
|
||||
*
|
||||
* When using `Buffer.allocUnsafe()` to allocate new `Buffer` instances,
|
||||
* allocations under 4 KiB are sliced from a single pre-allocated `Buffer`. This
|
||||
* allows applications to avoid the garbage collection overhead of creating many
|
||||
* individually allocated `Buffer` instances. This approach improves both
|
||||
* performance and memory usage by eliminating the need to track and clean up as
|
||||
* many individual `ArrayBuffer` objects.
|
||||
*
|
||||
* However, in the case where a developer may need to retain a small chunk of
|
||||
* memory from a pool for an indeterminate amount of time, it may be appropriate
|
||||
* to create an un-pooled `Buffer` instance using `Buffer.allocUnsafeSlow()` and
|
||||
* then copying out the relevant bits.
|
||||
*
|
||||
* ```js
|
||||
* import { Buffer } from 'node:buffer';
|
||||
*
|
||||
* // Need to keep around a few small chunks of memory.
|
||||
* const store = [];
|
||||
*
|
||||
* socket.on('readable', () => {
|
||||
* let data;
|
||||
* while (null !== (data = readable.read())) {
|
||||
* // Allocate for retained data.
|
||||
* const sb = Buffer.allocUnsafeSlow(10);
|
||||
*
|
||||
* // Copy the data into the new allocation.
|
||||
* data.copy(sb, 0, 0, 10);
|
||||
*
|
||||
* store.push(sb);
|
||||
* }
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* A `TypeError` will be thrown if `size` is not a number.
|
||||
* @since v5.12.0
|
||||
* @param size The desired length of the new `Buffer`.
|
||||
*/
|
||||
allocUnsafeSlow(size: number): Buffer<ArrayBuffer>;
|
||||
}
|
||||
interface Buffer<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike> extends Uint8Array<TArrayBuffer> {
|
||||
// see buffer.d.ts for implementation shared with all TypeScript versions
|
||||
|
||||
/**
|
||||
* Returns a new `Buffer` that references the same memory as the original, but
|
||||
* offset and cropped by the `start` and `end` indices.
|
||||
*
|
||||
* This method is not compatible with the `Uint8Array.prototype.slice()`,
|
||||
* which is a superclass of `Buffer`. To copy the slice, use`Uint8Array.prototype.slice()`.
|
||||
*
|
||||
* ```js
|
||||
* import { Buffer } from 'node:buffer';
|
||||
*
|
||||
* const buf = Buffer.from('buffer');
|
||||
*
|
||||
* const copiedBuf = Uint8Array.prototype.slice.call(buf);
|
||||
* copiedBuf[0]++;
|
||||
* console.log(copiedBuf.toString());
|
||||
* // Prints: cuffer
|
||||
*
|
||||
* console.log(buf.toString());
|
||||
* // Prints: buffer
|
||||
*
|
||||
* // With buf.slice(), the original buffer is modified.
|
||||
* const notReallyCopiedBuf = buf.slice();
|
||||
* notReallyCopiedBuf[0]++;
|
||||
* console.log(notReallyCopiedBuf.toString());
|
||||
* // Prints: cuffer
|
||||
* console.log(buf.toString());
|
||||
* // Also prints: cuffer (!)
|
||||
* ```
|
||||
* @since v0.3.0
|
||||
* @deprecated Use `subarray` instead.
|
||||
* @param [start=0] Where the new `Buffer` will start.
|
||||
* @param [end=buf.length] Where the new `Buffer` will end (not inclusive).
|
||||
*/
|
||||
slice(start?: number, end?: number): Buffer<ArrayBuffer>;
|
||||
/**
|
||||
* Returns a new `Buffer` that references the same memory as the original, but
|
||||
* offset and cropped by the `start` and `end` indices.
|
||||
*
|
||||
* Specifying `end` greater than `buf.length` will return the same result as
|
||||
* that of `end` equal to `buf.length`.
|
||||
*
|
||||
* This method is inherited from [`TypedArray.prototype.subarray()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray).
|
||||
*
|
||||
* Modifying the new `Buffer` slice will modify the memory in the original `Buffer`because the allocated memory of the two objects overlap.
|
||||
*
|
||||
* ```js
|
||||
* import { Buffer } from 'node:buffer';
|
||||
*
|
||||
* // Create a `Buffer` with the ASCII alphabet, take a slice, and modify one byte
|
||||
* // from the original `Buffer`.
|
||||
*
|
||||
* const buf1 = Buffer.allocUnsafe(26);
|
||||
*
|
||||
* for (let i = 0; i < 26; i++) {
|
||||
* // 97 is the decimal ASCII value for 'a'.
|
||||
* buf1[i] = i + 97;
|
||||
* }
|
||||
*
|
||||
* const buf2 = buf1.subarray(0, 3);
|
||||
*
|
||||
* console.log(buf2.toString('ascii', 0, buf2.length));
|
||||
* // Prints: abc
|
||||
*
|
||||
* buf1[0] = 33;
|
||||
*
|
||||
* console.log(buf2.toString('ascii', 0, buf2.length));
|
||||
* // Prints: !bc
|
||||
* ```
|
||||
*
|
||||
* Specifying negative indexes causes the slice to be generated relative to the
|
||||
* end of `buf` rather than the beginning.
|
||||
*
|
||||
* ```js
|
||||
* import { Buffer } from 'node:buffer';
|
||||
*
|
||||
* const buf = Buffer.from('buffer');
|
||||
*
|
||||
* console.log(buf.subarray(-6, -1).toString());
|
||||
* // Prints: buffe
|
||||
* // (Equivalent to buf.subarray(0, 5).)
|
||||
*
|
||||
* console.log(buf.subarray(-6, -2).toString());
|
||||
* // Prints: buff
|
||||
* // (Equivalent to buf.subarray(0, 4).)
|
||||
*
|
||||
* console.log(buf.subarray(-5, -2).toString());
|
||||
* // Prints: uff
|
||||
* // (Equivalent to buf.subarray(1, 4).)
|
||||
* ```
|
||||
* @since v3.0.0
|
||||
* @param [start=0] Where the new `Buffer` will start.
|
||||
* @param [end=buf.length] Where the new `Buffer` will end (not inclusive).
|
||||
*/
|
||||
subarray(start?: number, end?: number): Buffer<TArrayBuffer>;
|
||||
}
|
||||
// TODO: remove globals in future version
|
||||
/**
|
||||
* @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports
|
||||
* TypeScript versions earlier than 5.7.
|
||||
*/
|
||||
type NonSharedBuffer = Buffer<ArrayBuffer>;
|
||||
/**
|
||||
* @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports
|
||||
* TypeScript versions earlier than 5.7.
|
||||
*/
|
||||
type AllowSharedBuffer = Buffer<ArrayBufferLike>;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
/**
|
||||
* @fileoverview A rule to ensure whitespace before blocks.
|
||||
* @author Mathias Schreck <https://github.com/lo1tuma>
|
||||
* @deprecated in ESLint v8.53.0
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const astUtils = require("./utils/ast-utils");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Checks whether the given node represents the body of a function.
|
||||
* @param {ASTNode} node the node to check.
|
||||
* @returns {boolean} `true` if the node is function body.
|
||||
*/
|
||||
function isFunctionBody(node) {
|
||||
const parent = node.parent;
|
||||
|
||||
return (
|
||||
node.type === "BlockStatement" &&
|
||||
astUtils.isFunction(parent) &&
|
||||
parent.body === node
|
||||
);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../types').Rule.RuleModule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
deprecated: {
|
||||
message: "Formatting rules are being moved out of ESLint core.",
|
||||
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
||||
deprecatedSince: "8.53.0",
|
||||
availableUntil: "11.0.0",
|
||||
replacedBy: [
|
||||
{
|
||||
message:
|
||||
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
||||
url: "https://eslint.style/guide/migration",
|
||||
plugin: {
|
||||
name: "@stylistic/eslint-plugin",
|
||||
url: "https://eslint.style",
|
||||
},
|
||||
rule: {
|
||||
name: "space-before-blocks",
|
||||
url: "https://eslint.style/rules/space-before-blocks",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
type: "layout",
|
||||
|
||||
docs: {
|
||||
description: "Enforce consistent spacing before blocks",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/space-before-blocks",
|
||||
},
|
||||
|
||||
fixable: "whitespace",
|
||||
|
||||
schema: [
|
||||
{
|
||||
oneOf: [
|
||||
{
|
||||
enum: ["always", "never"],
|
||||
},
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
keywords: {
|
||||
enum: ["always", "never", "off"],
|
||||
},
|
||||
functions: {
|
||||
enum: ["always", "never", "off"],
|
||||
},
|
||||
classes: {
|
||||
enum: ["always", "never", "off"],
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
messages: {
|
||||
unexpectedSpace: "Unexpected space before opening brace.",
|
||||
missingSpace: "Missing space before opening brace.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const config = context.options[0],
|
||||
sourceCode = context.sourceCode;
|
||||
let alwaysFunctions = true,
|
||||
alwaysKeywords = true,
|
||||
alwaysClasses = true,
|
||||
neverFunctions = false,
|
||||
neverKeywords = false,
|
||||
neverClasses = false;
|
||||
|
||||
if (typeof config === "object") {
|
||||
alwaysFunctions = config.functions === "always";
|
||||
alwaysKeywords = config.keywords === "always";
|
||||
alwaysClasses = config.classes === "always";
|
||||
neverFunctions = config.functions === "never";
|
||||
neverKeywords = config.keywords === "never";
|
||||
neverClasses = config.classes === "never";
|
||||
} else if (config === "never") {
|
||||
alwaysFunctions = false;
|
||||
alwaysKeywords = false;
|
||||
alwaysClasses = false;
|
||||
neverFunctions = true;
|
||||
neverKeywords = true;
|
||||
neverClasses = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the spacing before the given block is already controlled by another rule:
|
||||
* - `arrow-spacing` checks spaces after `=>`.
|
||||
* - `keyword-spacing` checks spaces after keywords in certain contexts.
|
||||
* - `switch-colon-spacing` checks spaces after `:` of switch cases.
|
||||
* @param {Token} precedingToken first token before the block.
|
||||
* @param {ASTNode|Token} node `BlockStatement` node or `{` token of a `SwitchStatement` node.
|
||||
* @returns {boolean} `true` if requiring or disallowing spaces before the given block could produce conflicts with other rules.
|
||||
*/
|
||||
function isConflicted(precedingToken, node) {
|
||||
return (
|
||||
astUtils.isArrowToken(precedingToken) ||
|
||||
(astUtils.isKeywordToken(precedingToken) &&
|
||||
!isFunctionBody(node)) ||
|
||||
(astUtils.isColonToken(precedingToken) &&
|
||||
node.parent &&
|
||||
node.parent.type === "SwitchCase" &&
|
||||
precedingToken ===
|
||||
astUtils.getSwitchCaseColonToken(
|
||||
node.parent,
|
||||
sourceCode,
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the given BlockStatement node has a preceding space if it doesn’t start on a new line.
|
||||
* @param {ASTNode|Token} node The AST node of a BlockStatement.
|
||||
* @returns {void} undefined.
|
||||
*/
|
||||
function checkPrecedingSpace(node) {
|
||||
const precedingToken = sourceCode.getTokenBefore(node);
|
||||
|
||||
if (
|
||||
precedingToken &&
|
||||
!isConflicted(precedingToken, node) &&
|
||||
astUtils.isTokenOnSameLine(precedingToken, node)
|
||||
) {
|
||||
const hasSpace = sourceCode.isSpaceBetween(
|
||||
precedingToken,
|
||||
node,
|
||||
);
|
||||
let requireSpace;
|
||||
let requireNoSpace;
|
||||
|
||||
if (isFunctionBody(node)) {
|
||||
requireSpace = alwaysFunctions;
|
||||
requireNoSpace = neverFunctions;
|
||||
} else if (node.type === "ClassBody") {
|
||||
requireSpace = alwaysClasses;
|
||||
requireNoSpace = neverClasses;
|
||||
} else {
|
||||
requireSpace = alwaysKeywords;
|
||||
requireNoSpace = neverKeywords;
|
||||
}
|
||||
|
||||
if (requireSpace && !hasSpace) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: "missingSpace",
|
||||
fix(fixer) {
|
||||
return fixer.insertTextBefore(node, " ");
|
||||
},
|
||||
});
|
||||
} else if (requireNoSpace && hasSpace) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: "unexpectedSpace",
|
||||
fix(fixer) {
|
||||
return fixer.removeRange([
|
||||
precedingToken.range[1],
|
||||
node.range[0],
|
||||
]);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the CaseBlock of an given SwitchStatement node has a preceding space.
|
||||
* @param {ASTNode} node The node of a SwitchStatement.
|
||||
* @returns {void} undefined.
|
||||
*/
|
||||
function checkSpaceBeforeCaseBlock(node) {
|
||||
const cases = node.cases;
|
||||
let openingBrace;
|
||||
|
||||
if (cases.length > 0) {
|
||||
openingBrace = sourceCode.getTokenBefore(cases[0]);
|
||||
} else {
|
||||
openingBrace = sourceCode.getLastToken(node, 1);
|
||||
}
|
||||
|
||||
checkPrecedingSpace(openingBrace);
|
||||
}
|
||||
|
||||
return {
|
||||
BlockStatement: checkPrecedingSpace,
|
||||
ClassBody: checkPrecedingSpace,
|
||||
SwitchStatement: checkSpaceBeforeCaseBlock,
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
# Installation
|
||||
> `npm install --save @types/json-schema`
|
||||
|
||||
# Summary
|
||||
This package contains type definitions for json-schema (https://github.com/kriszyp/json-schema).
|
||||
|
||||
# Details
|
||||
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/json-schema.
|
||||
|
||||
### Additional Details
|
||||
* Last updated: Tue, 07 Nov 2023 03:09:37 GMT
|
||||
* Dependencies: none
|
||||
|
||||
# Credits
|
||||
These definitions were written by [Boris Cherny](https://github.com/bcherny), [Lucian Buzzo](https://github.com/lucianbuzzo), [Roland Groza](https://github.com/rolandjitsu), and [Jason Kwok](https://github.com/JasonHK).
|
||||
@@ -0,0 +1,9 @@
|
||||
import http from "./http";
|
||||
const handler = {
|
||||
scheme: "https",
|
||||
domainHost: http.domainHost,
|
||||
parse: http.parse,
|
||||
serialize: http.serialize
|
||||
};
|
||||
export default handler;
|
||||
//# sourceMappingURL=https.js.map
|
||||
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var code = require('./code');
|
||||
|
||||
function isStrictModeReservedWordES6(id) {
|
||||
switch (id) {
|
||||
case 'implements':
|
||||
case 'interface':
|
||||
case 'package':
|
||||
case 'private':
|
||||
case 'protected':
|
||||
case 'public':
|
||||
case 'static':
|
||||
case 'let':
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function isKeywordES5(id, strict) {
|
||||
// yield should not be treated as keyword under non-strict mode.
|
||||
if (!strict && id === 'yield') {
|
||||
return false;
|
||||
}
|
||||
return isKeywordES6(id, strict);
|
||||
}
|
||||
|
||||
function isKeywordES6(id, strict) {
|
||||
if (strict && isStrictModeReservedWordES6(id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (id.length) {
|
||||
case 2:
|
||||
return (id === 'if') || (id === 'in') || (id === 'do');
|
||||
case 3:
|
||||
return (id === 'var') || (id === 'for') || (id === 'new') || (id === 'try');
|
||||
case 4:
|
||||
return (id === 'this') || (id === 'else') || (id === 'case') ||
|
||||
(id === 'void') || (id === 'with') || (id === 'enum');
|
||||
case 5:
|
||||
return (id === 'while') || (id === 'break') || (id === 'catch') ||
|
||||
(id === 'throw') || (id === 'const') || (id === 'yield') ||
|
||||
(id === 'class') || (id === 'super');
|
||||
case 6:
|
||||
return (id === 'return') || (id === 'typeof') || (id === 'delete') ||
|
||||
(id === 'switch') || (id === 'export') || (id === 'import');
|
||||
case 7:
|
||||
return (id === 'default') || (id === 'finally') || (id === 'extends');
|
||||
case 8:
|
||||
return (id === 'function') || (id === 'continue') || (id === 'debugger');
|
||||
case 10:
|
||||
return (id === 'instanceof');
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function isReservedWordES5(id, strict) {
|
||||
return id === 'null' || id === 'true' || id === 'false' || isKeywordES5(id, strict);
|
||||
}
|
||||
|
||||
function isReservedWordES6(id, strict) {
|
||||
return id === 'null' || id === 'true' || id === 'false' || isKeywordES6(id, strict);
|
||||
}
|
||||
|
||||
function isRestrictedWord(id) {
|
||||
return id === 'eval' || id === 'arguments';
|
||||
}
|
||||
|
||||
function isIdentifierNameES5(id) {
|
||||
var i, iz, ch;
|
||||
|
||||
if (id.length === 0) { return false; }
|
||||
|
||||
ch = id.charCodeAt(0);
|
||||
if (!code.isIdentifierStartES5(ch)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (i = 1, iz = id.length; i < iz; ++i) {
|
||||
ch = id.charCodeAt(i);
|
||||
if (!code.isIdentifierPartES5(ch)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function decodeUtf16(lead, trail) {
|
||||
return (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000;
|
||||
}
|
||||
|
||||
function isIdentifierNameES6(id) {
|
||||
var i, iz, ch, lowCh, check;
|
||||
|
||||
if (id.length === 0) { return false; }
|
||||
|
||||
check = code.isIdentifierStartES6;
|
||||
for (i = 0, iz = id.length; i < iz; ++i) {
|
||||
ch = id.charCodeAt(i);
|
||||
if (0xD800 <= ch && ch <= 0xDBFF) {
|
||||
++i;
|
||||
if (i >= iz) { return false; }
|
||||
lowCh = id.charCodeAt(i);
|
||||
if (!(0xDC00 <= lowCh && lowCh <= 0xDFFF)) {
|
||||
return false;
|
||||
}
|
||||
ch = decodeUtf16(ch, lowCh);
|
||||
}
|
||||
if (!check(ch)) {
|
||||
return false;
|
||||
}
|
||||
check = code.isIdentifierPartES6;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function isIdentifierES5(id, strict) {
|
||||
return isIdentifierNameES5(id) && !isReservedWordES5(id, strict);
|
||||
}
|
||||
|
||||
function isIdentifierES6(id, strict) {
|
||||
return isIdentifierNameES6(id) && !isReservedWordES6(id, strict);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
isKeywordES5: isKeywordES5,
|
||||
isKeywordES6: isKeywordES6,
|
||||
isReservedWordES5: isReservedWordES5,
|
||||
isReservedWordES6: isReservedWordES6,
|
||||
isRestrictedWord: isRestrictedWord,
|
||||
isIdentifierNameES5: isIdentifierNameES5,
|
||||
isIdentifierNameES6: isIdentifierNameES6,
|
||||
isIdentifierES5: isIdentifierES5,
|
||||
isIdentifierES6: isIdentifierES6
|
||||
};
|
||||
}());
|
||||
/* vim: set sw=4 ts=4 et tw=80 : */
|
||||
@@ -0,0 +1,485 @@
|
||||
'use strict';
|
||||
|
||||
const {Writable} = require('stream');
|
||||
const {StringDecoder} = require('string_decoder');
|
||||
|
||||
const patterns = {
|
||||
value1: /^(?:[\"\{\[\]\-\d]|true\b|false\b|null\b|\s{1,256})/,
|
||||
string: /^(?:[^\x00-\x1f\"\\]{1,256}|\\[bfnrt\"\\\/]|\\u[\da-fA-F]{4}|\")/,
|
||||
key1: /^(?:[\"\}]|\s{1,256})/,
|
||||
colon: /^(?:\:|\s{1,256})/,
|
||||
comma: /^(?:[\,\]\}]|\s{1,256})/,
|
||||
ws: /^\s{1,256}/,
|
||||
numberStart: /^\d/,
|
||||
numberDigit: /^\d{0,256}/,
|
||||
numberFraction: /^[\.eE]/,
|
||||
numberExponent: /^[eE]/,
|
||||
numberExpSign: /^[-+]/
|
||||
};
|
||||
const MAX_PATTERN_SIZE = 16;
|
||||
|
||||
let noSticky = true;
|
||||
try {
|
||||
new RegExp('.', 'y');
|
||||
noSticky = false;
|
||||
} catch (e) {
|
||||
// suppress
|
||||
}
|
||||
|
||||
!noSticky &&
|
||||
Object.keys(patterns).forEach(key => {
|
||||
let src = patterns[key].source.slice(1); // lop off ^
|
||||
if (src.slice(0, 3) === '(?:' && src.slice(-1) === ')') {
|
||||
src = src.slice(3, -1);
|
||||
}
|
||||
patterns[key] = new RegExp(src, 'y');
|
||||
});
|
||||
|
||||
patterns.numberFracStart = patterns.numberExpStart = patterns.numberStart;
|
||||
patterns.numberFracDigit = patterns.numberExpDigit = patterns.numberDigit;
|
||||
|
||||
const eol = /[\u000A\u2028\u2029]|\u000D\u000A|\u000D/g;
|
||||
|
||||
const expected = {object: 'objectStop', array: 'arrayStop', '': 'done'};
|
||||
|
||||
class Verifier extends Writable {
|
||||
static make(options) {
|
||||
return new Verifier(options);
|
||||
}
|
||||
|
||||
constructor(options) {
|
||||
super(Object.assign({}, options, {objectMode: false}));
|
||||
|
||||
if (options) {
|
||||
this._jsonStreaming = options.jsonStreaming;
|
||||
}
|
||||
|
||||
this._buffer = '';
|
||||
this._done = false;
|
||||
this._expect = this._jsonStreaming ? 'done' : 'value';
|
||||
this._stack = [];
|
||||
this._parent = '';
|
||||
|
||||
this._line = this._pos = 1;
|
||||
this._offset = 0;
|
||||
}
|
||||
|
||||
_write(chunk, encoding, callback) {
|
||||
if (typeof chunk == 'string') {
|
||||
this._write = this._writeString;
|
||||
} else {
|
||||
this._stringDecoder = new StringDecoder();
|
||||
this._write = this._writeBuffer;
|
||||
}
|
||||
this._write(chunk, encoding, callback);
|
||||
}
|
||||
|
||||
_writeBuffer(chunk, _, callback) {
|
||||
this._buffer += this._stringDecoder.write(chunk);
|
||||
this._processBuffer(callback);
|
||||
}
|
||||
|
||||
_writeString(chunk, _, callback) {
|
||||
this._buffer += chunk.toString();
|
||||
this._processBuffer(callback);
|
||||
}
|
||||
|
||||
_final(callback) {
|
||||
if (this._stringDecoder) {
|
||||
this._buffer += this._stringDecoder.end();
|
||||
}
|
||||
this._done = true;
|
||||
this._processBuffer(callback);
|
||||
}
|
||||
|
||||
_makeError(msg) {
|
||||
const error = new Error('ERROR at ' + this._offset + ' (' + this._line + ', ' + this._pos + '): ' + msg);
|
||||
error.line = this._line;
|
||||
error.pos = this._pos;
|
||||
error.offset = this._offset;
|
||||
return error;
|
||||
}
|
||||
|
||||
_updatePos(value) {
|
||||
let len = value.length;
|
||||
this._offset += len;
|
||||
value.replace(eol, (match, offset) => {
|
||||
len = value.length - match.length - offset;
|
||||
++this._line;
|
||||
this._pos = 1;
|
||||
return '';
|
||||
});
|
||||
this._pos += len;
|
||||
}
|
||||
|
||||
_processBuffer(callback) {
|
||||
let match,
|
||||
value,
|
||||
index = 0;
|
||||
main: for (;;) {
|
||||
switch (this._expect) {
|
||||
case 'value1':
|
||||
case 'value':
|
||||
patterns.value1.lastIndex = index;
|
||||
match = patterns.value1.exec(this._buffer);
|
||||
if (!match) {
|
||||
if (this._done || index + MAX_PATTERN_SIZE < this._buffer.length) {
|
||||
if (index < this._buffer.length) return callback(this._makeError('Verifier cannot parse input: expected a value'));
|
||||
return callback(this._makeError('Verifier has expected a value'));
|
||||
}
|
||||
break main; // wait for more input
|
||||
}
|
||||
value = match[0];
|
||||
switch (value) {
|
||||
case '"':
|
||||
this._expect = 'string';
|
||||
break;
|
||||
case '{':
|
||||
this._stack.push(this._parent);
|
||||
this._parent = 'object';
|
||||
this._expect = 'key1';
|
||||
break;
|
||||
case '[':
|
||||
this._stack.push(this._parent);
|
||||
this._parent = 'array';
|
||||
this._expect = 'value1';
|
||||
break;
|
||||
case ']':
|
||||
if (this._expect !== 'value1') return callback(this._makeError("Verifier cannot parse input: unexpected token ']'"));
|
||||
this._parent = this._stack.pop();
|
||||
this._expect = expected[this._parent];
|
||||
break;
|
||||
case '-':
|
||||
this._expect = 'numberStart';
|
||||
break;
|
||||
case '0':
|
||||
this._expect = 'numberFraction';
|
||||
break;
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
this._expect = 'numberDigit';
|
||||
break;
|
||||
case 'true':
|
||||
case 'false':
|
||||
case 'null':
|
||||
if (this._buffer.length - index === value.length && !this._done) break main; // wait for more input
|
||||
this._expect = expected[this._parent];
|
||||
break;
|
||||
// default: // ws
|
||||
}
|
||||
this._updatePos(value);
|
||||
if (noSticky) {
|
||||
this._buffer = this._buffer.slice(value.length);
|
||||
} else {
|
||||
index += value.length;
|
||||
}
|
||||
break;
|
||||
case 'keyVal':
|
||||
case 'string':
|
||||
patterns.string.lastIndex = index;
|
||||
match = patterns.string.exec(this._buffer);
|
||||
if (!match) {
|
||||
if (index < this._buffer.length && (this._done || this._buffer.length - index >= 6))
|
||||
return callback(this._makeError('Verifier cannot parse input: escaped characters'));
|
||||
if (this._done) return callback(this._makeError('Verifier has expected a string value'));
|
||||
break main; // wait for more input
|
||||
}
|
||||
value = match[0];
|
||||
if (value === '"') {
|
||||
if (this._expect === 'keyVal') {
|
||||
this._expect = 'colon';
|
||||
} else {
|
||||
this._expect = expected[this._parent];
|
||||
}
|
||||
}
|
||||
this._updatePos(value);
|
||||
if (noSticky) {
|
||||
this._buffer = this._buffer.slice(value.length);
|
||||
} else {
|
||||
index += value.length;
|
||||
}
|
||||
break;
|
||||
case 'key1':
|
||||
case 'key':
|
||||
patterns.key1.lastIndex = index;
|
||||
match = patterns.key1.exec(this._buffer);
|
||||
if (!match) {
|
||||
if (index < this._buffer.length || this._done) return callback(this._makeError('Verifier cannot parse input: expected an object key'));
|
||||
break main; // wait for more input
|
||||
}
|
||||
value = match[0];
|
||||
if (value === '"') {
|
||||
this._expect = 'keyVal';
|
||||
} else if (value === '}') {
|
||||
if (this._expect !== 'key1') return callback(this._makeError("Verifier cannot parse input: unexpected token '}'"));
|
||||
this._parent = this._stack.pop();
|
||||
this._expect = expected[this._parent];
|
||||
}
|
||||
this._updatePos(value);
|
||||
if (noSticky) {
|
||||
this._buffer = this._buffer.slice(value.length);
|
||||
} else {
|
||||
index += value.length;
|
||||
}
|
||||
break;
|
||||
case 'colon':
|
||||
patterns.colon.lastIndex = index;
|
||||
match = patterns.colon.exec(this._buffer);
|
||||
if (!match) {
|
||||
if (index < this._buffer.length || this._done) return callback(this._makeError("Verifier cannot parse input: expected ':'"));
|
||||
break main; // wait for more input
|
||||
}
|
||||
value = match[0];
|
||||
value === ':' && (this._expect = 'value');
|
||||
this._updatePos(value);
|
||||
if (noSticky) {
|
||||
this._buffer = this._buffer.slice(value.length);
|
||||
} else {
|
||||
index += value.length;
|
||||
}
|
||||
break;
|
||||
case 'arrayStop':
|
||||
case 'objectStop':
|
||||
patterns.comma.lastIndex = index;
|
||||
match = patterns.comma.exec(this._buffer);
|
||||
if (!match) {
|
||||
if (index < this._buffer.length || this._done) return callback(this._makeError("Verifier cannot parse input: expected ','"));
|
||||
break main; // wait for more input
|
||||
}
|
||||
value = match[0];
|
||||
if (value === ',') {
|
||||
this._expect = this._expect === 'arrayStop' ? 'value' : 'key';
|
||||
} else if (value === '}' || value === ']') {
|
||||
if (value === '}' ? this._expect === 'arrayStop' : this._expect !== 'arrayStop') {
|
||||
return callback(this._makeError("Verifier cannot parse input: expected '" + (this._expect === 'arrayStop' ? ']' : '}') + "'"));
|
||||
}
|
||||
this._parent = this._stack.pop();
|
||||
this._expect = expected[this._parent];
|
||||
}
|
||||
this._updatePos(value);
|
||||
if (noSticky) {
|
||||
this._buffer = this._buffer.slice(value.length);
|
||||
} else {
|
||||
index += value.length;
|
||||
}
|
||||
break;
|
||||
// number chunks
|
||||
case 'numberStart': // [0-9]
|
||||
patterns.numberStart.lastIndex = index;
|
||||
match = patterns.numberStart.exec(this._buffer);
|
||||
if (!match) {
|
||||
if (index < this._buffer.length || this._done) return callback(this._makeError('Verifier cannot parse input: expected a starting digit'));
|
||||
break main; // wait for more input
|
||||
}
|
||||
value = match[0];
|
||||
this._expect = value === '0' ? 'numberFraction' : 'numberDigit';
|
||||
this._updatePos(value);
|
||||
if (noSticky) {
|
||||
this._buffer = this._buffer.slice(value.length);
|
||||
} else {
|
||||
index += value.length;
|
||||
}
|
||||
break;
|
||||
case 'numberDigit': // [0-9]*
|
||||
patterns.numberDigit.lastIndex = index;
|
||||
match = patterns.numberDigit.exec(this._buffer);
|
||||
if (!match) {
|
||||
if (index < this._buffer.length || this._done) return callback(this._makeError('Verifier cannot parse input: expected a digit'));
|
||||
break main; // wait for more input
|
||||
}
|
||||
value = match[0];
|
||||
if (value) {
|
||||
this._updatePos(value);
|
||||
if (noSticky) {
|
||||
this._buffer = this._buffer.slice(value.length);
|
||||
} else {
|
||||
index += value.length;
|
||||
}
|
||||
} else {
|
||||
if (index < this._buffer.length) {
|
||||
this._expect = 'numberFraction';
|
||||
break;
|
||||
}
|
||||
if (this._done) {
|
||||
this._expect = expected[this._parent];
|
||||
break;
|
||||
}
|
||||
break main; // wait for more input
|
||||
}
|
||||
break;
|
||||
case 'numberFraction': // [\.eE]?
|
||||
patterns.numberFraction.lastIndex = index;
|
||||
match = patterns.numberFraction.exec(this._buffer);
|
||||
if (!match) {
|
||||
if (index < this._buffer.length || this._done) {
|
||||
this._expect = expected[this._parent];
|
||||
break;
|
||||
}
|
||||
break main; // wait for more input
|
||||
}
|
||||
value = match[0];
|
||||
this._expect = value === '.' ? 'numberFracStart' : 'numberExpSign';
|
||||
this._updatePos(value);
|
||||
if (noSticky) {
|
||||
this._buffer = this._buffer.slice(value.length);
|
||||
} else {
|
||||
index += value.length;
|
||||
}
|
||||
break;
|
||||
case 'numberFracStart': // [0-9]
|
||||
patterns.numberFracStart.lastIndex = index;
|
||||
match = patterns.numberFracStart.exec(this._buffer);
|
||||
if (!match) {
|
||||
if (index < this._buffer.length || this._done)
|
||||
return callback(this._makeError('Verifier cannot parse input: expected a fractional part of a number'));
|
||||
break main; // wait for more input
|
||||
}
|
||||
value = match[0];
|
||||
this._expect = 'numberFracDigit';
|
||||
this._updatePos(value);
|
||||
if (noSticky) {
|
||||
this._buffer = this._buffer.slice(value.length);
|
||||
} else {
|
||||
index += value.length;
|
||||
}
|
||||
break;
|
||||
case 'numberFracDigit': // [0-9]*
|
||||
patterns.numberFracDigit.lastIndex = index;
|
||||
match = patterns.numberFracDigit.exec(this._buffer);
|
||||
value = match[0];
|
||||
if (value) {
|
||||
this._updatePos(value);
|
||||
if (noSticky) {
|
||||
this._buffer = this._buffer.slice(value.length);
|
||||
} else {
|
||||
index += value.length;
|
||||
}
|
||||
} else {
|
||||
if (index < this._buffer.length) {
|
||||
this._expect = 'numberExponent';
|
||||
break;
|
||||
}
|
||||
if (this._done) {
|
||||
this._expect = expected[this._parent];
|
||||
break;
|
||||
}
|
||||
break main; // wait for more input
|
||||
}
|
||||
break;
|
||||
case 'numberExponent': // [eE]?
|
||||
patterns.numberExponent.lastIndex = index;
|
||||
match = patterns.numberExponent.exec(this._buffer);
|
||||
if (!match) {
|
||||
if (index < this._buffer.length) {
|
||||
this._expect = expected[this._parent];
|
||||
break;
|
||||
}
|
||||
if (this._done) {
|
||||
this._expect = 'done';
|
||||
break;
|
||||
}
|
||||
break main; // wait for more input
|
||||
}
|
||||
value = match[0];
|
||||
this._expect = 'numberExpSign';
|
||||
this._updatePos(value);
|
||||
if (noSticky) {
|
||||
this._buffer = this._buffer.slice(value.length);
|
||||
} else {
|
||||
index += value.length;
|
||||
}
|
||||
break;
|
||||
case 'numberExpSign': // [-+]?
|
||||
patterns.numberExpSign.lastIndex = index;
|
||||
match = patterns.numberExpSign.exec(this._buffer);
|
||||
if (!match) {
|
||||
if (index < this._buffer.length) {
|
||||
this._expect = 'numberExpStart';
|
||||
break;
|
||||
}
|
||||
if (this._done) return callback(this._makeError('Verifier has expected an exponent value of a number'));
|
||||
break main; // wait for more input
|
||||
}
|
||||
value = match[0];
|
||||
this._expect = 'numberExpStart';
|
||||
this._updatePos(value);
|
||||
if (noSticky) {
|
||||
this._buffer = this._buffer.slice(value.length);
|
||||
} else {
|
||||
index += value.length;
|
||||
}
|
||||
break;
|
||||
case 'numberExpStart': // [0-9]
|
||||
patterns.numberExpStart.lastIndex = index;
|
||||
match = patterns.numberExpStart.exec(this._buffer);
|
||||
if (!match) {
|
||||
if (index < this._buffer.length || this._done)
|
||||
return callback(this._makeError('Verifier cannot parse input: expected an exponent part of a number'));
|
||||
break main; // wait for more input
|
||||
}
|
||||
value = match[0];
|
||||
this._expect = 'numberExpDigit';
|
||||
this._updatePos(value);
|
||||
if (noSticky) {
|
||||
this._buffer = this._buffer.slice(value.length);
|
||||
} else {
|
||||
index += value.length;
|
||||
}
|
||||
break;
|
||||
case 'numberExpDigit': // [0-9]*
|
||||
patterns.numberExpDigit.lastIndex = index;
|
||||
match = patterns.numberExpDigit.exec(this._buffer);
|
||||
value = match[0];
|
||||
if (value) {
|
||||
this._updatePos(value);
|
||||
if (noSticky) {
|
||||
this._buffer = this._buffer.slice(value.length);
|
||||
} else {
|
||||
index += value.length;
|
||||
}
|
||||
} else {
|
||||
if (index < this._buffer.length || this._done) {
|
||||
this._expect = expected[this._parent];
|
||||
break;
|
||||
}
|
||||
break main; // wait for more input
|
||||
}
|
||||
break;
|
||||
case 'done':
|
||||
patterns.ws.lastIndex = index;
|
||||
match = patterns.ws.exec(this._buffer);
|
||||
if (!match) {
|
||||
if (index < this._buffer.length) {
|
||||
if (this._jsonStreaming) {
|
||||
this._expect = 'value';
|
||||
break;
|
||||
}
|
||||
return callback(this._makeError('Verifier cannot parse input: unexpected characters'));
|
||||
}
|
||||
break main; // wait for more input
|
||||
}
|
||||
value = match[0];
|
||||
this._updatePos(value);
|
||||
if (noSticky) {
|
||||
this._buffer = this._buffer.slice(value.length);
|
||||
} else {
|
||||
index += value.length;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
!noSticky && (this._buffer = this._buffer.slice(index));
|
||||
callback(null);
|
||||
}
|
||||
}
|
||||
Verifier.verifier = Verifier.make;
|
||||
Verifier.make.Constructor = Verifier;
|
||||
|
||||
module.exports = Verifier;
|
||||
@@ -0,0 +1,91 @@
|
||||
'use strict';
|
||||
|
||||
const tls = require('tls');
|
||||
const utils = require('../utils');
|
||||
const Client = require('../client');
|
||||
|
||||
/**
|
||||
* Constructor for a Jayson TLS-encrypted TCP Client
|
||||
* @class ClientTls
|
||||
* @constructor
|
||||
* @extends Client
|
||||
* @param {Object|String} [options] Object goes into options for tls.connect, String goes into options.path. String option argument is NOT recommended.
|
||||
* @return {ClientTls}
|
||||
*/
|
||||
const ClientTls = function(options) {
|
||||
if(typeof(options) === 'string') {
|
||||
options = {path: options};
|
||||
}
|
||||
|
||||
if(!(this instanceof ClientTls)) {
|
||||
return new ClientTls(options);
|
||||
}
|
||||
Client.call(this, options);
|
||||
|
||||
const defaults = utils.merge(this.options, {
|
||||
encoding: 'utf8'
|
||||
});
|
||||
|
||||
this.options = utils.merge(defaults, options || {});
|
||||
};
|
||||
require('util').inherits(ClientTls, Client);
|
||||
|
||||
module.exports = ClientTls;
|
||||
|
||||
ClientTls.prototype._request = function(request, callback) {
|
||||
const self = this;
|
||||
|
||||
// copies options so object can be modified in this context
|
||||
const options = utils.merge({}, this.options);
|
||||
|
||||
utils.JSON.stringify(request, options, function(err, body) {
|
||||
if(err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
let handled = false;
|
||||
|
||||
const conn = tls.connect(options, function() {
|
||||
|
||||
conn.setEncoding(options.encoding);
|
||||
|
||||
// wont get anything for notifications, just end here
|
||||
if(utils.Request.isNotification(request)) {
|
||||
|
||||
handled = true;
|
||||
conn.end(body + '\n');
|
||||
callback();
|
||||
|
||||
} else {
|
||||
|
||||
utils.parseStream(conn, options, function(err, response) {
|
||||
handled = true;
|
||||
conn.end();
|
||||
if(err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
callback(null, response);
|
||||
});
|
||||
|
||||
conn.write(body + '\n');
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
self.emit('tcp socket', conn);
|
||||
|
||||
conn.on('error', function(err) {
|
||||
self.emit('tcp error', err);
|
||||
callback(err);
|
||||
});
|
||||
|
||||
conn.on('end', function() {
|
||||
if(!handled) {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
{{# def.definitions }}
|
||||
{{# def.errors }}
|
||||
{{# def.setupKeyword }}
|
||||
{{# def.$data }}
|
||||
|
||||
{{# def.numberKeyword }}
|
||||
|
||||
var division{{=$lvl}};
|
||||
if ({{?$isData}}
|
||||
{{=$schemaValue}} !== undefined && (
|
||||
typeof {{=$schemaValue}} != 'number' ||
|
||||
{{?}}
|
||||
(division{{=$lvl}} = {{=$data}} / {{=$schemaValue}},
|
||||
{{? it.opts.multipleOfPrecision }}
|
||||
Math.abs(Math.round(division{{=$lvl}}) - division{{=$lvl}}) > 1e-{{=it.opts.multipleOfPrecision}}
|
||||
{{??}}
|
||||
division{{=$lvl}} !== parseInt(division{{=$lvl}})
|
||||
{{?}}
|
||||
)
|
||||
{{?$isData}} ) {{?}} ) {
|
||||
{{# def.error:'multipleOf' }}
|
||||
} {{? $breakOnError }} else { {{?}}
|
||||
@@ -0,0 +1,54 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.NullThrowsReasons = exports.nullThrows = exports.isObjectNotArray = exports.getParserServices = exports.deepMerge = exports.applyDefault = void 0;
|
||||
const utils_1 = require("@typescript-eslint/utils");
|
||||
__exportStar(require("./astUtils"), exports);
|
||||
__exportStar(require("./baseTypeUtils"), exports);
|
||||
__exportStar(require("./collectUnusedVariables"), exports);
|
||||
__exportStar(require("./createRule"), exports);
|
||||
__exportStar(require("./getBaseTypesOfClassMember"), exports);
|
||||
__exportStar(require("./getFixOrSuggest"), exports);
|
||||
__exportStar(require("./getFunctionHeadLoc"), exports);
|
||||
__exportStar(require("./getOperatorPrecedence"), exports);
|
||||
__exportStar(require("./getStaticStringValue"), exports);
|
||||
__exportStar(require("./getStringLength"), exports);
|
||||
__exportStar(require("./getTextWithParentheses"), exports);
|
||||
__exportStar(require("./getThisExpression"), exports);
|
||||
__exportStar(require("./getWrappingFixer"), exports);
|
||||
__exportStar(require("./hasOverloadSignatures"), exports);
|
||||
__exportStar(require("./isArrayMethodCallWithPredicate"), exports);
|
||||
__exportStar(require("./isAssignee"), exports);
|
||||
__exportStar(require("./isConditionalTest"), exports);
|
||||
__exportStar(require("./isNodeEqual"), exports);
|
||||
__exportStar(require("./isNullLiteral"), exports);
|
||||
__exportStar(require("./isStartOfExpressionStatement"), exports);
|
||||
__exportStar(require("./isUndefinedIdentifier"), exports);
|
||||
__exportStar(require("./misc"), exports);
|
||||
__exportStar(require("./needsPrecedingSemiColon"), exports);
|
||||
__exportStar(require("./objectIterators"), exports);
|
||||
__exportStar(require("./needsToBeAwaited"), exports);
|
||||
__exportStar(require("./scopeUtils"), exports);
|
||||
__exportStar(require("./types"), exports);
|
||||
__exportStar(require("./getConstraintInfo"), exports);
|
||||
__exportStar(require("./getValueOfLiteralType"), exports);
|
||||
__exportStar(require("./isHigherPrecedenceThanAwait"), exports);
|
||||
__exportStar(require("./skipChainExpression"), exports);
|
||||
__exportStar(require("./truthinessUtils"), exports);
|
||||
__exportStar(require("./walkStatements"), exports);
|
||||
// this is done for convenience - saves migrating all of the old rules
|
||||
__exportStar(require("@typescript-eslint/type-utils"), exports);
|
||||
({ applyDefault: exports.applyDefault, deepMerge: exports.deepMerge, getParserServices: exports.getParserServices, isObjectNotArray: exports.isObjectNotArray, nullThrows: exports.nullThrows, NullThrowsReasons: exports.NullThrowsReasons } = utils_1.ESLintUtils);
|
||||
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.referenceContainsTypePredicate = referenceContainsTypePredicate;
|
||||
const utils_1 = require("@typescript-eslint/utils");
|
||||
/**
|
||||
* Recursively checks whether a given reference is used in a type predicate (e.g., `arg is string`)
|
||||
*/
|
||||
function referenceContainsTypePredicate(node) {
|
||||
switch (node.type) {
|
||||
case utils_1.AST_NODE_TYPES.TSTypePredicate:
|
||||
return true;
|
||||
case utils_1.AST_NODE_TYPES.TSQualifiedName:
|
||||
case utils_1.AST_NODE_TYPES.Identifier:
|
||||
return referenceContainsTypePredicate(node.parent);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,422 @@
|
||||
/**
|
||||
* @fileoverview Rule to flag unnecessary double negation in Boolean contexts
|
||||
* @author Brandon Mills
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const astUtils = require("./utils/ast-utils");
|
||||
const eslintUtils = require("@eslint-community/eslint-utils");
|
||||
|
||||
const precedence = astUtils.getPrecedence;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../types').Rule.RuleModule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "suggestion",
|
||||
|
||||
defaultOptions: [{}],
|
||||
|
||||
docs: {
|
||||
description: "Disallow unnecessary boolean casts",
|
||||
recommended: true,
|
||||
frozen: true,
|
||||
url: "https://eslint.org/docs/latest/rules/no-extra-boolean-cast",
|
||||
},
|
||||
|
||||
schema: [
|
||||
{
|
||||
anyOf: [
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
enforceForInnerExpressions: {
|
||||
type: "boolean",
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
|
||||
// deprecated
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
enforceForLogicalOperands: {
|
||||
type: "boolean",
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
fixable: "code",
|
||||
|
||||
messages: {
|
||||
unexpectedCall: "Redundant Boolean call.",
|
||||
unexpectedNegation: "Redundant double negation.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const sourceCode = context.sourceCode;
|
||||
const [{ enforceForLogicalOperands, enforceForInnerExpressions }] =
|
||||
context.options;
|
||||
|
||||
// Node types which have a test which will coerce values to booleans.
|
||||
const BOOLEAN_NODE_TYPES = new Set([
|
||||
"IfStatement",
|
||||
"DoWhileStatement",
|
||||
"WhileStatement",
|
||||
"ConditionalExpression",
|
||||
"ForStatement",
|
||||
]);
|
||||
|
||||
/**
|
||||
* Check if a node is a Boolean function or constructor.
|
||||
* @param {ASTNode} node the node
|
||||
* @returns {boolean} If the node is Boolean function or constructor
|
||||
*/
|
||||
function isBooleanFunctionOrConstructorCall(node) {
|
||||
// Boolean(<bool>) and new Boolean(<bool>)
|
||||
return (
|
||||
(node.type === "CallExpression" ||
|
||||
node.type === "NewExpression") &&
|
||||
node.callee.type === "Identifier" &&
|
||||
node.callee.name === "Boolean" &&
|
||||
sourceCode.isGlobalReference(node.callee)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a node is in a context where its value would be coerced to a boolean at runtime.
|
||||
* @param {ASTNode} node The node
|
||||
* @returns {boolean} If it is in a boolean context
|
||||
*/
|
||||
function isInBooleanContext(node) {
|
||||
return (
|
||||
(isBooleanFunctionOrConstructorCall(node.parent) &&
|
||||
node === node.parent.arguments[0]) ||
|
||||
(BOOLEAN_NODE_TYPES.has(node.parent.type) &&
|
||||
node === node.parent.test) ||
|
||||
// !<bool>
|
||||
(node.parent.type === "UnaryExpression" &&
|
||||
node.parent.operator === "!")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the node is a context that should report an error
|
||||
* Acts recursively if it is in a logical context
|
||||
* @param {ASTNode} node the node
|
||||
* @returns {boolean} If the node is in one of the flagged contexts
|
||||
*/
|
||||
function isInFlaggedContext(node) {
|
||||
if (node.parent.type === "ChainExpression") {
|
||||
return isInFlaggedContext(node.parent);
|
||||
}
|
||||
|
||||
/*
|
||||
* legacy behavior - enforceForLogicalOperands will only recurse on
|
||||
* logical expressions, not on other contexts.
|
||||
* enforceForInnerExpressions will recurse on logical expressions
|
||||
* as well as the other recursive syntaxes.
|
||||
*/
|
||||
|
||||
if (enforceForLogicalOperands || enforceForInnerExpressions) {
|
||||
if (node.parent.type === "LogicalExpression") {
|
||||
if (
|
||||
node.parent.operator === "||" ||
|
||||
node.parent.operator === "&&"
|
||||
) {
|
||||
return isInFlaggedContext(node.parent);
|
||||
}
|
||||
|
||||
// Check the right hand side of a `??` operator.
|
||||
if (
|
||||
enforceForInnerExpressions &&
|
||||
node.parent.operator === "??" &&
|
||||
node.parent.right === node
|
||||
) {
|
||||
return isInFlaggedContext(node.parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (enforceForInnerExpressions) {
|
||||
if (
|
||||
node.parent.type === "ConditionalExpression" &&
|
||||
(node.parent.consequent === node ||
|
||||
node.parent.alternate === node)
|
||||
) {
|
||||
return isInFlaggedContext(node.parent);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check last expression only in a sequence, i.e. if ((1, 2, Boolean(3))) {}, since
|
||||
* the others don't affect the result of the expression.
|
||||
*/
|
||||
if (
|
||||
node.parent.type === "SequenceExpression" &&
|
||||
node.parent.expressions.at(-1) === node
|
||||
) {
|
||||
return isInFlaggedContext(node.parent);
|
||||
}
|
||||
}
|
||||
|
||||
return isInBooleanContext(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a node has comments inside.
|
||||
* @param {ASTNode} node The node to check.
|
||||
* @returns {boolean} `true` if it has comments inside.
|
||||
*/
|
||||
function hasCommentsInside(node) {
|
||||
return Boolean(sourceCode.getCommentsInside(node).length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given node is wrapped in grouping parentheses. Parentheses for constructs such as if() don't count.
|
||||
* @param {ASTNode} node The node to check.
|
||||
* @returns {boolean} `true` if the node is parenthesized.
|
||||
* @private
|
||||
*/
|
||||
function isParenthesized(node) {
|
||||
return eslintUtils.isParenthesized(1, node, sourceCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the given node needs to be parenthesized when replacing the previous node.
|
||||
* It assumes that `previousNode` is the node to be reported by this rule, so it has a limited list
|
||||
* of possible parent node types. By the same assumption, the node's role in a particular parent is already known.
|
||||
* @param {ASTNode} previousNode Previous node.
|
||||
* @param {ASTNode} node The node to check.
|
||||
* @throws {Error} (Unreachable.)
|
||||
* @returns {boolean} `true` if the node needs to be parenthesized.
|
||||
*/
|
||||
function needsParens(previousNode, node) {
|
||||
if (previousNode.parent.type === "ChainExpression") {
|
||||
return needsParens(previousNode.parent, node);
|
||||
}
|
||||
|
||||
if (isParenthesized(previousNode)) {
|
||||
// parentheses around the previous node will stay, so there is no need for an additional pair
|
||||
return false;
|
||||
}
|
||||
|
||||
// parent of the previous node will become parent of the replacement node
|
||||
const parent = previousNode.parent;
|
||||
|
||||
switch (parent.type) {
|
||||
case "CallExpression":
|
||||
case "NewExpression":
|
||||
return node.type === "SequenceExpression";
|
||||
case "IfStatement":
|
||||
case "DoWhileStatement":
|
||||
case "WhileStatement":
|
||||
case "ForStatement":
|
||||
case "SequenceExpression":
|
||||
return false;
|
||||
case "ConditionalExpression":
|
||||
if (previousNode === parent.test) {
|
||||
return precedence(node) <= precedence(parent);
|
||||
}
|
||||
if (
|
||||
previousNode === parent.consequent ||
|
||||
previousNode === parent.alternate
|
||||
) {
|
||||
return (
|
||||
precedence(node) <
|
||||
precedence({ type: "AssignmentExpression" })
|
||||
);
|
||||
}
|
||||
|
||||
/* c8 ignore next */
|
||||
throw new Error(
|
||||
"Ternary child must be test, consequent, or alternate.",
|
||||
);
|
||||
case "UnaryExpression":
|
||||
return precedence(node) < precedence(parent);
|
||||
case "LogicalExpression":
|
||||
if (
|
||||
astUtils.isMixedLogicalAndCoalesceExpressions(
|
||||
node,
|
||||
parent,
|
||||
)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
if (previousNode === parent.left) {
|
||||
return precedence(node) < precedence(parent);
|
||||
}
|
||||
return precedence(node) <= precedence(parent);
|
||||
|
||||
/* c8 ignore next */
|
||||
default:
|
||||
throw new Error(`Unexpected parent type: ${parent.type}`);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
UnaryExpression(node) {
|
||||
const parent = node.parent;
|
||||
|
||||
// Exit early if it's guaranteed not to match
|
||||
if (
|
||||
node.operator !== "!" ||
|
||||
parent.type !== "UnaryExpression" ||
|
||||
parent.operator !== "!"
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isInFlaggedContext(parent)) {
|
||||
context.report({
|
||||
node: parent,
|
||||
messageId: "unexpectedNegation",
|
||||
fix(fixer) {
|
||||
if (hasCommentsInside(parent)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (needsParens(parent, node.argument)) {
|
||||
return fixer.replaceText(
|
||||
parent,
|
||||
`(${sourceCode.getText(node.argument)})`,
|
||||
);
|
||||
}
|
||||
|
||||
let prefix = "";
|
||||
const tokenBefore =
|
||||
sourceCode.getTokenBefore(parent);
|
||||
const firstReplacementToken =
|
||||
sourceCode.getFirstToken(node.argument);
|
||||
|
||||
if (
|
||||
tokenBefore &&
|
||||
tokenBefore.range[1] === parent.range[0] &&
|
||||
!astUtils.canTokensBeAdjacent(
|
||||
tokenBefore,
|
||||
firstReplacementToken,
|
||||
)
|
||||
) {
|
||||
prefix = " ";
|
||||
}
|
||||
|
||||
return fixer.replaceText(
|
||||
parent,
|
||||
prefix + sourceCode.getText(node.argument),
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
CallExpression(node) {
|
||||
if (
|
||||
node.callee.type !== "Identifier" ||
|
||||
node.callee.name !== "Boolean" ||
|
||||
!sourceCode.isGlobalReference(node.callee)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isInFlaggedContext(node)) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: "unexpectedCall",
|
||||
fix(fixer) {
|
||||
const parent = node.parent;
|
||||
|
||||
if (node.arguments.length === 0) {
|
||||
if (
|
||||
parent.type === "UnaryExpression" &&
|
||||
parent.operator === "!"
|
||||
) {
|
||||
/*
|
||||
* !Boolean() -> true
|
||||
*/
|
||||
|
||||
if (hasCommentsInside(parent)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const replacement = "true";
|
||||
let prefix = "";
|
||||
const tokenBefore =
|
||||
sourceCode.getTokenBefore(parent);
|
||||
|
||||
if (
|
||||
tokenBefore &&
|
||||
tokenBefore.range[1] ===
|
||||
parent.range[0] &&
|
||||
!astUtils.canTokensBeAdjacent(
|
||||
tokenBefore,
|
||||
replacement,
|
||||
)
|
||||
) {
|
||||
prefix = " ";
|
||||
}
|
||||
|
||||
return fixer.replaceText(
|
||||
parent,
|
||||
prefix + replacement,
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Boolean() -> false
|
||||
*/
|
||||
|
||||
if (hasCommentsInside(node)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return fixer.replaceText(node, "false");
|
||||
}
|
||||
|
||||
if (node.arguments.length === 1) {
|
||||
const argument = node.arguments[0];
|
||||
|
||||
if (
|
||||
argument.type === "SpreadElement" ||
|
||||
hasCommentsInside(node)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* Boolean(expression) -> expression
|
||||
*/
|
||||
|
||||
if (needsParens(node, argument)) {
|
||||
return fixer.replaceText(
|
||||
node,
|
||||
`(${sourceCode.getText(argument)})`,
|
||||
);
|
||||
}
|
||||
|
||||
return fixer.replaceText(
|
||||
node,
|
||||
sourceCode.getText(argument),
|
||||
);
|
||||
}
|
||||
|
||||
// two or more arguments
|
||||
return null;
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* @fileoverview Rule to flag use of certain node types
|
||||
* @author Burak Yigit Kaya
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../types').Rule.RuleModule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "suggestion",
|
||||
|
||||
docs: {
|
||||
description: "Disallow specified syntax",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/no-restricted-syntax",
|
||||
},
|
||||
|
||||
schema: {
|
||||
type: "array",
|
||||
items: {
|
||||
oneOf: [
|
||||
{
|
||||
type: "string",
|
||||
},
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
selector: { type: "string" },
|
||||
message: { type: "string" },
|
||||
},
|
||||
required: ["selector"],
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
uniqueItems: true,
|
||||
minItems: 0,
|
||||
},
|
||||
|
||||
defaultOptions: [],
|
||||
|
||||
messages: {
|
||||
// eslint-disable-next-line eslint-plugin/report-message-format -- Custom message might not end in a period
|
||||
restrictedSyntax: "{{message}}",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
return context.options.reduce((result, selectorOrObject) => {
|
||||
const isStringFormat = typeof selectorOrObject === "string";
|
||||
const hasCustomMessage =
|
||||
!isStringFormat && Boolean(selectorOrObject.message);
|
||||
|
||||
const selector = isStringFormat
|
||||
? selectorOrObject
|
||||
: selectorOrObject.selector;
|
||||
const message = hasCustomMessage
|
||||
? selectorOrObject.message
|
||||
: `Using '${selector}' is not allowed.`;
|
||||
|
||||
return Object.assign(result, {
|
||||
[selector](node) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: "restrictedSyntax",
|
||||
data: { message },
|
||||
});
|
||||
},
|
||||
});
|
||||
}, {});
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user