WIP: bootstrap and partial real Solana watcher implementation
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
const parserBase = __importStar(require("@typescript-eslint/parser"));
|
||||
const all_1 = __importDefault(require("./configs/eslintrc/all"));
|
||||
const base_1 = __importDefault(require("./configs/eslintrc/base"));
|
||||
const disable_type_checked_1 = __importDefault(require("./configs/eslintrc/disable-type-checked"));
|
||||
const eslint_recommended_1 = __importDefault(require("./configs/eslintrc/eslint-recommended"));
|
||||
const recommended_1 = __importDefault(require("./configs/eslintrc/recommended"));
|
||||
const recommended_type_checked_1 = __importDefault(require("./configs/eslintrc/recommended-type-checked"));
|
||||
const recommended_type_checked_only_1 = __importDefault(require("./configs/eslintrc/recommended-type-checked-only"));
|
||||
const strict_1 = __importDefault(require("./configs/eslintrc/strict"));
|
||||
const strict_type_checked_1 = __importDefault(require("./configs/eslintrc/strict-type-checked"));
|
||||
const strict_type_checked_only_1 = __importDefault(require("./configs/eslintrc/strict-type-checked-only"));
|
||||
const stylistic_1 = __importDefault(require("./configs/eslintrc/stylistic"));
|
||||
const stylistic_type_checked_1 = __importDefault(require("./configs/eslintrc/stylistic-type-checked"));
|
||||
const stylistic_type_checked_only_1 = __importDefault(require("./configs/eslintrc/stylistic-type-checked-only"));
|
||||
const all_2 = __importDefault(require("./configs/flat/all"));
|
||||
const base_2 = __importDefault(require("./configs/flat/base"));
|
||||
const disable_type_checked_2 = __importDefault(require("./configs/flat/disable-type-checked"));
|
||||
const eslint_recommended_2 = __importDefault(require("./configs/flat/eslint-recommended"));
|
||||
const recommended_2 = __importDefault(require("./configs/flat/recommended"));
|
||||
const recommended_type_checked_2 = __importDefault(require("./configs/flat/recommended-type-checked"));
|
||||
const recommended_type_checked_only_2 = __importDefault(require("./configs/flat/recommended-type-checked-only"));
|
||||
const strict_2 = __importDefault(require("./configs/flat/strict"));
|
||||
const strict_type_checked_2 = __importDefault(require("./configs/flat/strict-type-checked"));
|
||||
const strict_type_checked_only_2 = __importDefault(require("./configs/flat/strict-type-checked-only"));
|
||||
const stylistic_2 = __importDefault(require("./configs/flat/stylistic"));
|
||||
const stylistic_type_checked_2 = __importDefault(require("./configs/flat/stylistic-type-checked"));
|
||||
const stylistic_type_checked_only_2 = __importDefault(require("./configs/flat/stylistic-type-checked-only"));
|
||||
const rules_1 = __importDefault(require("./rules"));
|
||||
const parser = {
|
||||
meta: parserBase.meta,
|
||||
parseForESLint: parserBase.parseForESLint,
|
||||
};
|
||||
// note - cannot migrate this to an import statement because it will make TSC copy the package.json to the dist folder
|
||||
const { name, version } = require('../package.json');
|
||||
const plugin = {
|
||||
// not fully initialized yet.
|
||||
// See https://eslint.org/docs/latest/extend/plugins#configs-in-plugins
|
||||
configs: {
|
||||
all: all_1.default,
|
||||
base: base_1.default,
|
||||
'disable-type-checked': disable_type_checked_1.default,
|
||||
'eslint-recommended': eslint_recommended_1.default,
|
||||
recommended: recommended_1.default,
|
||||
/** @deprecated - please use "recommended-type-checked" instead. */
|
||||
'recommended-requiring-type-checking': recommended_type_checked_1.default,
|
||||
'recommended-type-checked': recommended_type_checked_1.default,
|
||||
'recommended-type-checked-only': recommended_type_checked_only_1.default,
|
||||
strict: strict_1.default,
|
||||
'strict-type-checked': strict_type_checked_1.default,
|
||||
'strict-type-checked-only': strict_type_checked_only_1.default,
|
||||
stylistic: stylistic_1.default,
|
||||
'stylistic-type-checked': stylistic_type_checked_1.default,
|
||||
'stylistic-type-checked-only': stylistic_type_checked_only_1.default,
|
||||
},
|
||||
meta: {
|
||||
name,
|
||||
namespace: '@typescript-eslint',
|
||||
version,
|
||||
},
|
||||
rules: rules_1.default,
|
||||
};
|
||||
// @ts-expect-error -- upstream type incompatibility stuff
|
||||
const flatPlugin = plugin;
|
||||
// included due to https://github.com/eslint/eslint/issues/19513
|
||||
const flatConfigs = {
|
||||
'flat/all': (0, all_2.default)(flatPlugin, parser),
|
||||
'flat/base': (0, base_2.default)(flatPlugin, parser),
|
||||
'flat/disable-type-checked': (0, disable_type_checked_2.default)(flatPlugin, parser),
|
||||
'flat/eslint-recommended': (0, eslint_recommended_2.default)(flatPlugin, parser),
|
||||
'flat/recommended': (0, recommended_2.default)(flatPlugin, parser),
|
||||
'flat/recommended-type-checked': (0, recommended_type_checked_2.default)(flatPlugin, parser),
|
||||
'flat/recommended-type-checked-only': (0, recommended_type_checked_only_2.default)(flatPlugin, parser),
|
||||
'flat/strict': (0, strict_2.default)(flatPlugin, parser),
|
||||
'flat/strict-type-checked': (0, strict_type_checked_2.default)(flatPlugin, parser),
|
||||
'flat/strict-type-checked-only': (0, strict_type_checked_only_2.default)(flatPlugin, parser),
|
||||
'flat/stylistic': (0, stylistic_2.default)(flatPlugin, parser),
|
||||
'flat/stylistic-type-checked': (0, stylistic_type_checked_2.default)(flatPlugin, parser),
|
||||
'flat/stylistic-type-checked-only': (0, stylistic_type_checked_only_2.default)(flatPlugin, parser),
|
||||
};
|
||||
Object.assign(plugin.configs, flatConfigs);
|
||||
module.exports = {
|
||||
flatConfigs,
|
||||
parser,
|
||||
plugin,
|
||||
};
|
||||
@@ -0,0 +1,297 @@
|
||||
<h1 align="center">
|
||||
<br>
|
||||
<br>
|
||||
<img width="320" src="media/logo.svg" alt="Chalk">
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
</h1>
|
||||
|
||||
> Terminal string styling done right
|
||||
|
||||
[](https://codecov.io/gh/chalk/chalk)
|
||||
[](https://www.npmjs.com/package/chalk?activeTab=dependents)
|
||||
[](https://www.npmjs.com/package/chalk)
|
||||
|
||||

|
||||
|
||||
## Info
|
||||
|
||||
- [Why not switch to a smaller coloring package?](https://github.com/chalk/chalk?tab=readme-ov-file#why-not-switch-to-a-smaller-coloring-package)
|
||||
- See [yoctocolors](https://github.com/sindresorhus/yoctocolors) for a smaller alternative
|
||||
|
||||
## Highlights
|
||||
|
||||
- Expressive API
|
||||
- Highly performant
|
||||
- No dependencies
|
||||
- Ability to nest styles
|
||||
- [256/Truecolor color support](#256-and-truecolor-color-support)
|
||||
- Auto-detects color support
|
||||
- Doesn't extend `String.prototype`
|
||||
- Clean and focused
|
||||
- Actively maintained
|
||||
- [Used by ~115,000 packages](https://www.npmjs.com/browse/depended/chalk) as of July 4, 2024
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
npm install chalk
|
||||
```
|
||||
|
||||
**IMPORTANT:** Chalk 5 is ESM. If you want to use Chalk with TypeScript or a build tool, you will probably want to use Chalk 4 for now. [Read more.](https://github.com/chalk/chalk/releases/tag/v5.0.0)
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import chalk from 'chalk';
|
||||
|
||||
console.log(chalk.blue('Hello world!'));
|
||||
```
|
||||
|
||||
Chalk comes with an easy to use composable API where you just chain and nest the styles you want.
|
||||
|
||||
```js
|
||||
import chalk from 'chalk';
|
||||
|
||||
const log = console.log;
|
||||
|
||||
// Combine styled and normal strings
|
||||
log(chalk.blue('Hello') + ' World' + chalk.red('!'));
|
||||
|
||||
// Compose multiple styles using the chainable API
|
||||
log(chalk.blue.bgRed.bold('Hello world!'));
|
||||
|
||||
// Pass in multiple arguments
|
||||
log(chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz'));
|
||||
|
||||
// Nest styles
|
||||
log(chalk.red('Hello', chalk.underline.bgBlue('world') + '!'));
|
||||
|
||||
// Nest styles of the same type even (color, underline, background)
|
||||
log(chalk.green(
|
||||
'I am a green line ' +
|
||||
chalk.blue.underline.bold('with a blue substring') +
|
||||
' that becomes green again!'
|
||||
));
|
||||
|
||||
// ES2015 template literal
|
||||
log(`
|
||||
CPU: ${chalk.red('90%')}
|
||||
RAM: ${chalk.green('40%')}
|
||||
DISK: ${chalk.yellow('70%')}
|
||||
`);
|
||||
|
||||
// Use RGB colors in terminal emulators that support it.
|
||||
log(chalk.rgb(123, 45, 67).underline('Underlined reddish color'));
|
||||
log(chalk.hex('#DEADED').bold('Bold gray!'));
|
||||
```
|
||||
|
||||
Easily define your own themes:
|
||||
|
||||
```js
|
||||
import chalk from 'chalk';
|
||||
|
||||
const error = chalk.bold.red;
|
||||
const warning = chalk.hex('#FFA500'); // Orange color
|
||||
|
||||
console.log(error('Error!'));
|
||||
console.log(warning('Warning!'));
|
||||
```
|
||||
|
||||
Take advantage of console.log [string substitution](https://nodejs.org/docs/latest/api/console.html#console_console_log_data_args):
|
||||
|
||||
```js
|
||||
import chalk from 'chalk';
|
||||
|
||||
const name = 'Sindre';
|
||||
console.log(chalk.green('Hello %s'), name);
|
||||
//=> 'Hello Sindre'
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### chalk.`<style>[.<style>...](string, [string...])`
|
||||
|
||||
Example: `chalk.red.bold.underline('Hello', 'world');`
|
||||
|
||||
Chain [styles](#styles) and call the last one as a method with a string argument. Order doesn't matter, and later styles take precedent in case of a conflict. This simply means that `chalk.red.yellow.green` is equivalent to `chalk.green`.
|
||||
|
||||
Multiple arguments will be separated by space.
|
||||
|
||||
### chalk.level
|
||||
|
||||
Specifies the level of color support.
|
||||
|
||||
Color support is automatically detected, but you can override it by setting the `level` property. You should however only do this in your own code as it applies globally to all Chalk consumers.
|
||||
|
||||
If you need to change this in a reusable module, create a new instance:
|
||||
|
||||
```js
|
||||
import {Chalk} from 'chalk';
|
||||
|
||||
const customChalk = new Chalk({level: 0});
|
||||
```
|
||||
|
||||
| Level | Description |
|
||||
| :---: | :--- |
|
||||
| `0` | All colors disabled |
|
||||
| `1` | Basic color support (16 colors) |
|
||||
| `2` | 256 color support |
|
||||
| `3` | Truecolor support (16 million colors) |
|
||||
|
||||
### supportsColor
|
||||
|
||||
Detect whether the terminal [supports color](https://github.com/chalk/supports-color). Used internally and handled for you, but exposed for convenience.
|
||||
|
||||
Can be overridden by the user with the flags `--color` and `--no-color`. For situations where using `--color` is not possible, use the environment variable `FORCE_COLOR=1` (level 1), `FORCE_COLOR=2` (level 2), or `FORCE_COLOR=3` (level 3) to forcefully enable color, or `FORCE_COLOR=0` to forcefully disable. The use of `FORCE_COLOR` overrides all other color support checks.
|
||||
|
||||
Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively.
|
||||
|
||||
### chalkStderr and supportsColorStderr
|
||||
|
||||
`chalkStderr` contains a separate instance configured with color support detected for `stderr` stream instead of `stdout`. Override rules from `supportsColor` apply to this too. `supportsColorStderr` is exposed for convenience.
|
||||
|
||||
### modifierNames, foregroundColorNames, backgroundColorNames, and colorNames
|
||||
|
||||
All supported style strings are exposed as an array of strings for convenience. `colorNames` is the combination of `foregroundColorNames` and `backgroundColorNames`.
|
||||
|
||||
This can be useful if you wrap Chalk and need to validate input:
|
||||
|
||||
```js
|
||||
import {modifierNames, foregroundColorNames} from 'chalk';
|
||||
|
||||
console.log(modifierNames.includes('bold'));
|
||||
//=> true
|
||||
|
||||
console.log(foregroundColorNames.includes('pink'));
|
||||
//=> false
|
||||
```
|
||||
|
||||
## Styles
|
||||
|
||||
### Modifiers
|
||||
|
||||
- `reset` - Reset the current style.
|
||||
- `bold` - Make the text bold.
|
||||
- `dim` - Make the text have lower opacity.
|
||||
- `italic` - Make the text italic. *(Not widely supported)*
|
||||
- `underline` - Put a horizontal line below the text. *(Not widely supported)*
|
||||
- `overline` - Put a horizontal line above the text. *(Not widely supported)*
|
||||
- `inverse`- Invert background and foreground colors.
|
||||
- `hidden` - Print the text but make it invisible.
|
||||
- `strikethrough` - Puts a horizontal line through the center of the text. *(Not widely supported)*
|
||||
- `visible`- Print the text only when Chalk has a color level above zero. Can be useful for things that are purely cosmetic.
|
||||
|
||||
### Colors
|
||||
|
||||
- `black`
|
||||
- `red`
|
||||
- `green`
|
||||
- `yellow`
|
||||
- `blue`
|
||||
- `magenta`
|
||||
- `cyan`
|
||||
- `white`
|
||||
- `blackBright` (alias: `gray`, `grey`)
|
||||
- `redBright`
|
||||
- `greenBright`
|
||||
- `yellowBright`
|
||||
- `blueBright`
|
||||
- `magentaBright`
|
||||
- `cyanBright`
|
||||
- `whiteBright`
|
||||
|
||||
### Background colors
|
||||
|
||||
- `bgBlack`
|
||||
- `bgRed`
|
||||
- `bgGreen`
|
||||
- `bgYellow`
|
||||
- `bgBlue`
|
||||
- `bgMagenta`
|
||||
- `bgCyan`
|
||||
- `bgWhite`
|
||||
- `bgBlackBright` (alias: `bgGray`, `bgGrey`)
|
||||
- `bgRedBright`
|
||||
- `bgGreenBright`
|
||||
- `bgYellowBright`
|
||||
- `bgBlueBright`
|
||||
- `bgMagentaBright`
|
||||
- `bgCyanBright`
|
||||
- `bgWhiteBright`
|
||||
|
||||
## 256 and Truecolor color support
|
||||
|
||||
Chalk supports 256 colors and [Truecolor](https://github.com/termstandard/colors) (16 million colors) on supported terminal apps.
|
||||
|
||||
Colors are downsampled from 16 million RGB values to an ANSI color format that is supported by the terminal emulator (or by specifying `{level: n}` as a Chalk option). For example, Chalk configured to run at level 1 (basic color support) will downsample an RGB value of #FF0000 (red) to 31 (ANSI escape for red).
|
||||
|
||||
Examples:
|
||||
|
||||
- `chalk.hex('#DEADED').underline('Hello, world!')`
|
||||
- `chalk.rgb(15, 100, 204).inverse('Hello!')`
|
||||
|
||||
Background versions of these models are prefixed with `bg` and the first level of the module capitalized (e.g. `hex` for foreground colors and `bgHex` for background colors).
|
||||
|
||||
- `chalk.bgHex('#DEADED').underline('Hello, world!')`
|
||||
- `chalk.bgRgb(15, 100, 204).inverse('Hello!')`
|
||||
|
||||
The following color models can be used:
|
||||
|
||||
- [`rgb`](https://en.wikipedia.org/wiki/RGB_color_model) - Example: `chalk.rgb(255, 136, 0).bold('Orange!')`
|
||||
- [`hex`](https://en.wikipedia.org/wiki/Web_colors#Hex_triplet) - Example: `chalk.hex('#FF8800').bold('Orange!')`
|
||||
- [`ansi256`](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) - Example: `chalk.bgAnsi256(194)('Honeydew, more or less')`
|
||||
|
||||
## Browser support
|
||||
|
||||
Since Chrome 69, ANSI escape codes are natively supported in the developer console.
|
||||
|
||||
## Windows
|
||||
|
||||
If you're on Windows, do yourself a favor and use [Windows Terminal](https://github.com/microsoft/terminal) instead of `cmd.exe`.
|
||||
|
||||
## FAQ
|
||||
|
||||
### Why not switch to a smaller coloring package?
|
||||
|
||||
Chalk may be larger, but there is a reason for that. It offers a more user-friendly API, well-documented types, supports millions of colors, and covers edge cases that smaller alternatives miss. Chalk is mature, reliable, and built to last.
|
||||
|
||||
But beyond the technical aspects, there's something more critical: trust and long-term maintenance. I have been active in open source for over a decade, and I'm committed to keeping Chalk maintained. Smaller packages might seem appealing now, but there's no guarantee they will be around for the long term, or that they won't become malicious over time.
|
||||
|
||||
Chalk is also likely already in your dependency tree (since 100K+ packages depend on it), so switching won’t save space—in fact, it might increase it. npm deduplicates dependencies, so multiple Chalk instances turn into one, but adding another package alongside it will increase your overall size.
|
||||
|
||||
If the goal is to clean up the ecosystem, switching away from Chalk won’t even make a dent. The real problem lies with packages that have very deep dependency trees (for example, those including a lot of polyfills). Chalk has no dependencies. It's better to focus on impactful changes rather than minor optimizations.
|
||||
|
||||
If absolute package size is important to you, I also maintain [yoctocolors](https://github.com/sindresorhus/yoctocolors), one of the smallest color packages out there.
|
||||
|
||||
*\- [Sindre](https://github.com/sindresorhus)*
|
||||
|
||||
### But the smaller coloring package has benchmarks showing it is faster
|
||||
|
||||
[Micro-benchmarks are flawed](https://sindresorhus.com/blog/micro-benchmark-fallacy) because they measure performance in unrealistic, isolated scenarios, often giving a distorted view of real-world performance. Don't believe marketing fluff. All the coloring packages are more than fast enough.
|
||||
|
||||
## Related
|
||||
|
||||
- [chalk-template](https://github.com/chalk/chalk-template) - [Tagged template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates) support for this module
|
||||
- [chalk-cli](https://github.com/chalk/chalk-cli) - CLI for this module
|
||||
- [ansi-styles](https://github.com/chalk/ansi-styles) - ANSI escape codes for styling strings in the terminal
|
||||
- [supports-color](https://github.com/chalk/supports-color) - Detect whether a terminal supports color
|
||||
- [strip-ansi](https://github.com/chalk/strip-ansi) - Strip ANSI escape codes
|
||||
- [strip-ansi-stream](https://github.com/chalk/strip-ansi-stream) - Strip ANSI escape codes from a stream
|
||||
- [has-ansi](https://github.com/chalk/has-ansi) - Check if a string has ANSI escape codes
|
||||
- [ansi-regex](https://github.com/chalk/ansi-regex) - Regular expression for matching ANSI escape codes
|
||||
- [wrap-ansi](https://github.com/chalk/wrap-ansi) - Wordwrap a string with ANSI escape codes
|
||||
- [slice-ansi](https://github.com/chalk/slice-ansi) - Slice a string with ANSI escape codes
|
||||
- [color-convert](https://github.com/qix-/color-convert) - Converts colors between different models
|
||||
- [chalk-animation](https://github.com/bokub/chalk-animation) - Animate strings in the terminal
|
||||
- [gradient-string](https://github.com/bokub/gradient-string) - Apply color gradients to strings
|
||||
- [chalk-pipe](https://github.com/LitoMore/chalk-pipe) - Create chalk style schemes with simpler style strings
|
||||
- [terminal-link](https://github.com/sindresorhus/terminal-link) - Create clickable links in the terminal
|
||||
|
||||
*(Not accepting additional entries)*
|
||||
|
||||
## Maintainers
|
||||
|
||||
- [Sindre Sorhus](https://github.com/sindresorhus)
|
||||
- [Josh Junon](https://github.com/qix-)
|
||||
@@ -0,0 +1,17 @@
|
||||
import * as core from "../core/index.js";
|
||||
import * as schemas from "./schemas.js";
|
||||
export function string(params) {
|
||||
return core._coercedString(schemas.ZodString, params);
|
||||
}
|
||||
export function number(params) {
|
||||
return core._coercedNumber(schemas.ZodNumber, params);
|
||||
}
|
||||
export function boolean(params) {
|
||||
return core._coercedBoolean(schemas.ZodBoolean, params);
|
||||
}
|
||||
export function bigint(params) {
|
||||
return core._coercedBigint(schemas.ZodBigInt, params);
|
||||
}
|
||||
export function date(params) {
|
||||
return core._coercedDate(schemas.ZodDate, params);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference lib="es2017" />
|
||||
/// <reference lib="dom" />
|
||||
/// <reference lib="webworker.importscripts" />
|
||||
/// <reference lib="scripthost" />
|
||||
/// <reference lib="dom.iterable" />
|
||||
@@ -0,0 +1,413 @@
|
||||
/**
|
||||
* blake2b (64-bit) & blake2s (8 to 32-bit) hash functions.
|
||||
* b could have been faster, but there is no fast u64 in js, so s is 1.5x faster.
|
||||
* @module
|
||||
*/
|
||||
import { BSIGMA, G1s, G2s } from "./_blake.js";
|
||||
import { SHA256_IV } from "./_md.js";
|
||||
import * as u64 from "./_u64.js";
|
||||
// prettier-ignore
|
||||
import { abytes, aexists, anumber, aoutput, clean, createOptHasher, Hash, swap32IfBE, swap8IfBE, toBytes, u32 } from "./utils.js";
|
||||
// Same as SHA512_IV, but swapped endianness: LE instead of BE. iv[1] is iv[0], etc.
|
||||
const B2B_IV = /* @__PURE__ */ Uint32Array.from([
|
||||
0xf3bcc908, 0x6a09e667, 0x84caa73b, 0xbb67ae85, 0xfe94f82b, 0x3c6ef372, 0x5f1d36f1, 0xa54ff53a,
|
||||
0xade682d1, 0x510e527f, 0x2b3e6c1f, 0x9b05688c, 0xfb41bd6b, 0x1f83d9ab, 0x137e2179, 0x5be0cd19,
|
||||
]);
|
||||
// Temporary buffer
|
||||
const BBUF = /* @__PURE__ */ new Uint32Array(32);
|
||||
// Mixing function G splitted in two halfs
|
||||
function G1b(a, b, c, d, msg, x) {
|
||||
// NOTE: V is LE here
|
||||
const Xl = msg[x], Xh = msg[x + 1]; // prettier-ignore
|
||||
let Al = BBUF[2 * a], Ah = BBUF[2 * a + 1]; // prettier-ignore
|
||||
let Bl = BBUF[2 * b], Bh = BBUF[2 * b + 1]; // prettier-ignore
|
||||
let Cl = BBUF[2 * c], Ch = BBUF[2 * c + 1]; // prettier-ignore
|
||||
let Dl = BBUF[2 * d], Dh = BBUF[2 * d + 1]; // prettier-ignore
|
||||
// v[a] = (v[a] + v[b] + x) | 0;
|
||||
let ll = u64.add3L(Al, Bl, Xl);
|
||||
Ah = u64.add3H(ll, Ah, Bh, Xh);
|
||||
Al = ll | 0;
|
||||
// v[d] = rotr(v[d] ^ v[a], 32)
|
||||
({ Dh, Dl } = { Dh: Dh ^ Ah, Dl: Dl ^ Al });
|
||||
({ Dh, Dl } = { Dh: u64.rotr32H(Dh, Dl), Dl: u64.rotr32L(Dh, Dl) });
|
||||
// v[c] = (v[c] + v[d]) | 0;
|
||||
({ h: Ch, l: Cl } = u64.add(Ch, Cl, Dh, Dl));
|
||||
// v[b] = rotr(v[b] ^ v[c], 24)
|
||||
({ Bh, Bl } = { Bh: Bh ^ Ch, Bl: Bl ^ Cl });
|
||||
({ Bh, Bl } = { Bh: u64.rotrSH(Bh, Bl, 24), Bl: u64.rotrSL(Bh, Bl, 24) });
|
||||
(BBUF[2 * a] = Al), (BBUF[2 * a + 1] = Ah);
|
||||
(BBUF[2 * b] = Bl), (BBUF[2 * b + 1] = Bh);
|
||||
(BBUF[2 * c] = Cl), (BBUF[2 * c + 1] = Ch);
|
||||
(BBUF[2 * d] = Dl), (BBUF[2 * d + 1] = Dh);
|
||||
}
|
||||
function G2b(a, b, c, d, msg, x) {
|
||||
// NOTE: V is LE here
|
||||
const Xl = msg[x], Xh = msg[x + 1]; // prettier-ignore
|
||||
let Al = BBUF[2 * a], Ah = BBUF[2 * a + 1]; // prettier-ignore
|
||||
let Bl = BBUF[2 * b], Bh = BBUF[2 * b + 1]; // prettier-ignore
|
||||
let Cl = BBUF[2 * c], Ch = BBUF[2 * c + 1]; // prettier-ignore
|
||||
let Dl = BBUF[2 * d], Dh = BBUF[2 * d + 1]; // prettier-ignore
|
||||
// v[a] = (v[a] + v[b] + x) | 0;
|
||||
let ll = u64.add3L(Al, Bl, Xl);
|
||||
Ah = u64.add3H(ll, Ah, Bh, Xh);
|
||||
Al = ll | 0;
|
||||
// v[d] = rotr(v[d] ^ v[a], 16)
|
||||
({ Dh, Dl } = { Dh: Dh ^ Ah, Dl: Dl ^ Al });
|
||||
({ Dh, Dl } = { Dh: u64.rotrSH(Dh, Dl, 16), Dl: u64.rotrSL(Dh, Dl, 16) });
|
||||
// v[c] = (v[c] + v[d]) | 0;
|
||||
({ h: Ch, l: Cl } = u64.add(Ch, Cl, Dh, Dl));
|
||||
// v[b] = rotr(v[b] ^ v[c], 63)
|
||||
({ Bh, Bl } = { Bh: Bh ^ Ch, Bl: Bl ^ Cl });
|
||||
({ Bh, Bl } = { Bh: u64.rotrBH(Bh, Bl, 63), Bl: u64.rotrBL(Bh, Bl, 63) });
|
||||
(BBUF[2 * a] = Al), (BBUF[2 * a + 1] = Ah);
|
||||
(BBUF[2 * b] = Bl), (BBUF[2 * b + 1] = Bh);
|
||||
(BBUF[2 * c] = Cl), (BBUF[2 * c + 1] = Ch);
|
||||
(BBUF[2 * d] = Dl), (BBUF[2 * d + 1] = Dh);
|
||||
}
|
||||
function checkBlake2Opts(outputLen, opts = {}, keyLen, saltLen, persLen) {
|
||||
anumber(keyLen);
|
||||
if (outputLen < 0 || outputLen > keyLen)
|
||||
throw new Error('outputLen bigger than keyLen');
|
||||
const { key, salt, personalization } = opts;
|
||||
if (key !== undefined && (key.length < 1 || key.length > keyLen))
|
||||
throw new Error('key length must be undefined or 1..' + keyLen);
|
||||
if (salt !== undefined && salt.length !== saltLen)
|
||||
throw new Error('salt must be undefined or ' + saltLen);
|
||||
if (personalization !== undefined && personalization.length !== persLen)
|
||||
throw new Error('personalization must be undefined or ' + persLen);
|
||||
}
|
||||
/** Class, from which others are subclassed. */
|
||||
export class BLAKE2 extends Hash {
|
||||
constructor(blockLen, outputLen) {
|
||||
super();
|
||||
this.finished = false;
|
||||
this.destroyed = false;
|
||||
this.length = 0;
|
||||
this.pos = 0;
|
||||
anumber(blockLen);
|
||||
anumber(outputLen);
|
||||
this.blockLen = blockLen;
|
||||
this.outputLen = outputLen;
|
||||
this.buffer = new Uint8Array(blockLen);
|
||||
this.buffer32 = u32(this.buffer);
|
||||
}
|
||||
update(data) {
|
||||
aexists(this);
|
||||
data = toBytes(data);
|
||||
abytes(data);
|
||||
// Main difference with other hashes: there is flag for last block,
|
||||
// so we cannot process current block before we know that there
|
||||
// is the next one. This significantly complicates logic and reduces ability
|
||||
// to do zero-copy processing
|
||||
const { blockLen, buffer, buffer32 } = this;
|
||||
const len = data.length;
|
||||
const offset = data.byteOffset;
|
||||
const buf = data.buffer;
|
||||
for (let pos = 0; pos < len;) {
|
||||
// If buffer is full and we still have input (don't process last block, same as blake2s)
|
||||
if (this.pos === blockLen) {
|
||||
swap32IfBE(buffer32);
|
||||
this.compress(buffer32, 0, false);
|
||||
swap32IfBE(buffer32);
|
||||
this.pos = 0;
|
||||
}
|
||||
const take = Math.min(blockLen - this.pos, len - pos);
|
||||
const dataOffset = offset + pos;
|
||||
// full block && aligned to 4 bytes && not last in input
|
||||
if (take === blockLen && !(dataOffset % 4) && pos + take < len) {
|
||||
const data32 = new Uint32Array(buf, dataOffset, Math.floor((len - pos) / 4));
|
||||
swap32IfBE(data32);
|
||||
for (let pos32 = 0; pos + blockLen < len; pos32 += buffer32.length, pos += blockLen) {
|
||||
this.length += blockLen;
|
||||
this.compress(data32, pos32, false);
|
||||
}
|
||||
swap32IfBE(data32);
|
||||
continue;
|
||||
}
|
||||
buffer.set(data.subarray(pos, pos + take), this.pos);
|
||||
this.pos += take;
|
||||
this.length += take;
|
||||
pos += take;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
digestInto(out) {
|
||||
aexists(this);
|
||||
aoutput(out, this);
|
||||
const { pos, buffer32 } = this;
|
||||
this.finished = true;
|
||||
// Padding
|
||||
clean(this.buffer.subarray(pos));
|
||||
swap32IfBE(buffer32);
|
||||
this.compress(buffer32, 0, true);
|
||||
swap32IfBE(buffer32);
|
||||
const out32 = u32(out);
|
||||
this.get().forEach((v, i) => (out32[i] = swap8IfBE(v)));
|
||||
}
|
||||
digest() {
|
||||
const { buffer, outputLen } = this;
|
||||
this.digestInto(buffer);
|
||||
const res = buffer.slice(0, outputLen);
|
||||
this.destroy();
|
||||
return res;
|
||||
}
|
||||
_cloneInto(to) {
|
||||
const { buffer, length, finished, destroyed, outputLen, pos } = this;
|
||||
to || (to = new this.constructor({ dkLen: outputLen }));
|
||||
to.set(...this.get());
|
||||
to.buffer.set(buffer);
|
||||
to.destroyed = destroyed;
|
||||
to.finished = finished;
|
||||
to.length = length;
|
||||
to.pos = pos;
|
||||
// @ts-ignore
|
||||
to.outputLen = outputLen;
|
||||
return to;
|
||||
}
|
||||
clone() {
|
||||
return this._cloneInto();
|
||||
}
|
||||
}
|
||||
export class BLAKE2b extends BLAKE2 {
|
||||
constructor(opts = {}) {
|
||||
const olen = opts.dkLen === undefined ? 64 : opts.dkLen;
|
||||
super(128, olen);
|
||||
// Same as SHA-512, but LE
|
||||
this.v0l = B2B_IV[0] | 0;
|
||||
this.v0h = B2B_IV[1] | 0;
|
||||
this.v1l = B2B_IV[2] | 0;
|
||||
this.v1h = B2B_IV[3] | 0;
|
||||
this.v2l = B2B_IV[4] | 0;
|
||||
this.v2h = B2B_IV[5] | 0;
|
||||
this.v3l = B2B_IV[6] | 0;
|
||||
this.v3h = B2B_IV[7] | 0;
|
||||
this.v4l = B2B_IV[8] | 0;
|
||||
this.v4h = B2B_IV[9] | 0;
|
||||
this.v5l = B2B_IV[10] | 0;
|
||||
this.v5h = B2B_IV[11] | 0;
|
||||
this.v6l = B2B_IV[12] | 0;
|
||||
this.v6h = B2B_IV[13] | 0;
|
||||
this.v7l = B2B_IV[14] | 0;
|
||||
this.v7h = B2B_IV[15] | 0;
|
||||
checkBlake2Opts(olen, opts, 64, 16, 16);
|
||||
let { key, personalization, salt } = opts;
|
||||
let keyLength = 0;
|
||||
if (key !== undefined) {
|
||||
key = toBytes(key);
|
||||
keyLength = key.length;
|
||||
}
|
||||
this.v0l ^= this.outputLen | (keyLength << 8) | (0x01 << 16) | (0x01 << 24);
|
||||
if (salt !== undefined) {
|
||||
salt = toBytes(salt);
|
||||
const slt = u32(salt);
|
||||
this.v4l ^= swap8IfBE(slt[0]);
|
||||
this.v4h ^= swap8IfBE(slt[1]);
|
||||
this.v5l ^= swap8IfBE(slt[2]);
|
||||
this.v5h ^= swap8IfBE(slt[3]);
|
||||
}
|
||||
if (personalization !== undefined) {
|
||||
personalization = toBytes(personalization);
|
||||
const pers = u32(personalization);
|
||||
this.v6l ^= swap8IfBE(pers[0]);
|
||||
this.v6h ^= swap8IfBE(pers[1]);
|
||||
this.v7l ^= swap8IfBE(pers[2]);
|
||||
this.v7h ^= swap8IfBE(pers[3]);
|
||||
}
|
||||
if (key !== undefined) {
|
||||
// Pad to blockLen and update
|
||||
const tmp = new Uint8Array(this.blockLen);
|
||||
tmp.set(key);
|
||||
this.update(tmp);
|
||||
}
|
||||
}
|
||||
// prettier-ignore
|
||||
get() {
|
||||
let { v0l, v0h, v1l, v1h, v2l, v2h, v3l, v3h, v4l, v4h, v5l, v5h, v6l, v6h, v7l, v7h } = this;
|
||||
return [v0l, v0h, v1l, v1h, v2l, v2h, v3l, v3h, v4l, v4h, v5l, v5h, v6l, v6h, v7l, v7h];
|
||||
}
|
||||
// prettier-ignore
|
||||
set(v0l, v0h, v1l, v1h, v2l, v2h, v3l, v3h, v4l, v4h, v5l, v5h, v6l, v6h, v7l, v7h) {
|
||||
this.v0l = v0l | 0;
|
||||
this.v0h = v0h | 0;
|
||||
this.v1l = v1l | 0;
|
||||
this.v1h = v1h | 0;
|
||||
this.v2l = v2l | 0;
|
||||
this.v2h = v2h | 0;
|
||||
this.v3l = v3l | 0;
|
||||
this.v3h = v3h | 0;
|
||||
this.v4l = v4l | 0;
|
||||
this.v4h = v4h | 0;
|
||||
this.v5l = v5l | 0;
|
||||
this.v5h = v5h | 0;
|
||||
this.v6l = v6l | 0;
|
||||
this.v6h = v6h | 0;
|
||||
this.v7l = v7l | 0;
|
||||
this.v7h = v7h | 0;
|
||||
}
|
||||
compress(msg, offset, isLast) {
|
||||
this.get().forEach((v, i) => (BBUF[i] = v)); // First half from state.
|
||||
BBUF.set(B2B_IV, 16); // Second half from IV.
|
||||
let { h, l } = u64.fromBig(BigInt(this.length));
|
||||
BBUF[24] = B2B_IV[8] ^ l; // Low word of the offset.
|
||||
BBUF[25] = B2B_IV[9] ^ h; // High word.
|
||||
// Invert all bits for last block
|
||||
if (isLast) {
|
||||
BBUF[28] = ~BBUF[28];
|
||||
BBUF[29] = ~BBUF[29];
|
||||
}
|
||||
let j = 0;
|
||||
const s = BSIGMA;
|
||||
for (let i = 0; i < 12; i++) {
|
||||
G1b(0, 4, 8, 12, msg, offset + 2 * s[j++]);
|
||||
G2b(0, 4, 8, 12, msg, offset + 2 * s[j++]);
|
||||
G1b(1, 5, 9, 13, msg, offset + 2 * s[j++]);
|
||||
G2b(1, 5, 9, 13, msg, offset + 2 * s[j++]);
|
||||
G1b(2, 6, 10, 14, msg, offset + 2 * s[j++]);
|
||||
G2b(2, 6, 10, 14, msg, offset + 2 * s[j++]);
|
||||
G1b(3, 7, 11, 15, msg, offset + 2 * s[j++]);
|
||||
G2b(3, 7, 11, 15, msg, offset + 2 * s[j++]);
|
||||
G1b(0, 5, 10, 15, msg, offset + 2 * s[j++]);
|
||||
G2b(0, 5, 10, 15, msg, offset + 2 * s[j++]);
|
||||
G1b(1, 6, 11, 12, msg, offset + 2 * s[j++]);
|
||||
G2b(1, 6, 11, 12, msg, offset + 2 * s[j++]);
|
||||
G1b(2, 7, 8, 13, msg, offset + 2 * s[j++]);
|
||||
G2b(2, 7, 8, 13, msg, offset + 2 * s[j++]);
|
||||
G1b(3, 4, 9, 14, msg, offset + 2 * s[j++]);
|
||||
G2b(3, 4, 9, 14, msg, offset + 2 * s[j++]);
|
||||
}
|
||||
this.v0l ^= BBUF[0] ^ BBUF[16];
|
||||
this.v0h ^= BBUF[1] ^ BBUF[17];
|
||||
this.v1l ^= BBUF[2] ^ BBUF[18];
|
||||
this.v1h ^= BBUF[3] ^ BBUF[19];
|
||||
this.v2l ^= BBUF[4] ^ BBUF[20];
|
||||
this.v2h ^= BBUF[5] ^ BBUF[21];
|
||||
this.v3l ^= BBUF[6] ^ BBUF[22];
|
||||
this.v3h ^= BBUF[7] ^ BBUF[23];
|
||||
this.v4l ^= BBUF[8] ^ BBUF[24];
|
||||
this.v4h ^= BBUF[9] ^ BBUF[25];
|
||||
this.v5l ^= BBUF[10] ^ BBUF[26];
|
||||
this.v5h ^= BBUF[11] ^ BBUF[27];
|
||||
this.v6l ^= BBUF[12] ^ BBUF[28];
|
||||
this.v6h ^= BBUF[13] ^ BBUF[29];
|
||||
this.v7l ^= BBUF[14] ^ BBUF[30];
|
||||
this.v7h ^= BBUF[15] ^ BBUF[31];
|
||||
clean(BBUF);
|
||||
}
|
||||
destroy() {
|
||||
this.destroyed = true;
|
||||
clean(this.buffer32);
|
||||
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Blake2b hash function. 64-bit. 1.5x slower than blake2s in JS.
|
||||
* @param msg - message that would be hashed
|
||||
* @param opts - dkLen output length, key for MAC mode, salt, personalization
|
||||
*/
|
||||
export const blake2b = /* @__PURE__ */ createOptHasher((opts) => new BLAKE2b(opts));
|
||||
// prettier-ignore
|
||||
export function compress(s, offset, msg, rounds, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) {
|
||||
let j = 0;
|
||||
for (let i = 0; i < rounds; i++) {
|
||||
({ a: v0, b: v4, c: v8, d: v12 } = G1s(v0, v4, v8, v12, msg[offset + s[j++]]));
|
||||
({ a: v0, b: v4, c: v8, d: v12 } = G2s(v0, v4, v8, v12, msg[offset + s[j++]]));
|
||||
({ a: v1, b: v5, c: v9, d: v13 } = G1s(v1, v5, v9, v13, msg[offset + s[j++]]));
|
||||
({ a: v1, b: v5, c: v9, d: v13 } = G2s(v1, v5, v9, v13, msg[offset + s[j++]]));
|
||||
({ a: v2, b: v6, c: v10, d: v14 } = G1s(v2, v6, v10, v14, msg[offset + s[j++]]));
|
||||
({ a: v2, b: v6, c: v10, d: v14 } = G2s(v2, v6, v10, v14, msg[offset + s[j++]]));
|
||||
({ a: v3, b: v7, c: v11, d: v15 } = G1s(v3, v7, v11, v15, msg[offset + s[j++]]));
|
||||
({ a: v3, b: v7, c: v11, d: v15 } = G2s(v3, v7, v11, v15, msg[offset + s[j++]]));
|
||||
({ a: v0, b: v5, c: v10, d: v15 } = G1s(v0, v5, v10, v15, msg[offset + s[j++]]));
|
||||
({ a: v0, b: v5, c: v10, d: v15 } = G2s(v0, v5, v10, v15, msg[offset + s[j++]]));
|
||||
({ a: v1, b: v6, c: v11, d: v12 } = G1s(v1, v6, v11, v12, msg[offset + s[j++]]));
|
||||
({ a: v1, b: v6, c: v11, d: v12 } = G2s(v1, v6, v11, v12, msg[offset + s[j++]]));
|
||||
({ a: v2, b: v7, c: v8, d: v13 } = G1s(v2, v7, v8, v13, msg[offset + s[j++]]));
|
||||
({ a: v2, b: v7, c: v8, d: v13 } = G2s(v2, v7, v8, v13, msg[offset + s[j++]]));
|
||||
({ a: v3, b: v4, c: v9, d: v14 } = G1s(v3, v4, v9, v14, msg[offset + s[j++]]));
|
||||
({ a: v3, b: v4, c: v9, d: v14 } = G2s(v3, v4, v9, v14, msg[offset + s[j++]]));
|
||||
}
|
||||
return { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 };
|
||||
}
|
||||
const B2S_IV = SHA256_IV;
|
||||
export class BLAKE2s extends BLAKE2 {
|
||||
constructor(opts = {}) {
|
||||
const olen = opts.dkLen === undefined ? 32 : opts.dkLen;
|
||||
super(64, olen);
|
||||
// Internal state, same as SHA-256
|
||||
this.v0 = B2S_IV[0] | 0;
|
||||
this.v1 = B2S_IV[1] | 0;
|
||||
this.v2 = B2S_IV[2] | 0;
|
||||
this.v3 = B2S_IV[3] | 0;
|
||||
this.v4 = B2S_IV[4] | 0;
|
||||
this.v5 = B2S_IV[5] | 0;
|
||||
this.v6 = B2S_IV[6] | 0;
|
||||
this.v7 = B2S_IV[7] | 0;
|
||||
checkBlake2Opts(olen, opts, 32, 8, 8);
|
||||
let { key, personalization, salt } = opts;
|
||||
let keyLength = 0;
|
||||
if (key !== undefined) {
|
||||
key = toBytes(key);
|
||||
keyLength = key.length;
|
||||
}
|
||||
this.v0 ^= this.outputLen | (keyLength << 8) | (0x01 << 16) | (0x01 << 24);
|
||||
if (salt !== undefined) {
|
||||
salt = toBytes(salt);
|
||||
const slt = u32(salt);
|
||||
this.v4 ^= swap8IfBE(slt[0]);
|
||||
this.v5 ^= swap8IfBE(slt[1]);
|
||||
}
|
||||
if (personalization !== undefined) {
|
||||
personalization = toBytes(personalization);
|
||||
const pers = u32(personalization);
|
||||
this.v6 ^= swap8IfBE(pers[0]);
|
||||
this.v7 ^= swap8IfBE(pers[1]);
|
||||
}
|
||||
if (key !== undefined) {
|
||||
// Pad to blockLen and update
|
||||
abytes(key);
|
||||
const tmp = new Uint8Array(this.blockLen);
|
||||
tmp.set(key);
|
||||
this.update(tmp);
|
||||
}
|
||||
}
|
||||
get() {
|
||||
const { v0, v1, v2, v3, v4, v5, v6, v7 } = this;
|
||||
return [v0, v1, v2, v3, v4, v5, v6, v7];
|
||||
}
|
||||
// prettier-ignore
|
||||
set(v0, v1, v2, v3, v4, v5, v6, v7) {
|
||||
this.v0 = v0 | 0;
|
||||
this.v1 = v1 | 0;
|
||||
this.v2 = v2 | 0;
|
||||
this.v3 = v3 | 0;
|
||||
this.v4 = v4 | 0;
|
||||
this.v5 = v5 | 0;
|
||||
this.v6 = v6 | 0;
|
||||
this.v7 = v7 | 0;
|
||||
}
|
||||
compress(msg, offset, isLast) {
|
||||
const { h, l } = u64.fromBig(BigInt(this.length));
|
||||
// prettier-ignore
|
||||
const { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 } = compress(BSIGMA, offset, msg, 10, this.v0, this.v1, this.v2, this.v3, this.v4, this.v5, this.v6, this.v7, B2S_IV[0], B2S_IV[1], B2S_IV[2], B2S_IV[3], l ^ B2S_IV[4], h ^ B2S_IV[5], isLast ? ~B2S_IV[6] : B2S_IV[6], B2S_IV[7]);
|
||||
this.v0 ^= v0 ^ v8;
|
||||
this.v1 ^= v1 ^ v9;
|
||||
this.v2 ^= v2 ^ v10;
|
||||
this.v3 ^= v3 ^ v11;
|
||||
this.v4 ^= v4 ^ v12;
|
||||
this.v5 ^= v5 ^ v13;
|
||||
this.v6 ^= v6 ^ v14;
|
||||
this.v7 ^= v7 ^ v15;
|
||||
}
|
||||
destroy() {
|
||||
this.destroyed = true;
|
||||
clean(this.buffer32);
|
||||
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Blake2s hash function. Focuses on 8-bit to 32-bit platforms. 1.5x faster than blake2b in JS.
|
||||
* @param msg - message that would be hashed
|
||||
* @param opts - dkLen output length, key for MAC mode, salt, personalization
|
||||
*/
|
||||
export const blake2s = /* @__PURE__ */ createOptHasher((opts) => new BLAKE2s(opts));
|
||||
//# sourceMappingURL=blake2.js.map
|
||||
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
function _skip_first_generator_next(fn) {
|
||||
return function() {
|
||||
var it = fn.apply(this, arguments);
|
||||
it.next();
|
||||
|
||||
return it;
|
||||
};
|
||||
}
|
||||
exports._ = _skip_first_generator_next;
|
||||
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "natural-compare",
|
||||
"version": "1.4.0",
|
||||
"stability": 3,
|
||||
"author": "Lauri Rooden (https://github.com/litejs/natural-compare-lite)",
|
||||
"license": "MIT",
|
||||
"description": "Compare strings containing a mix of letters and numbers in the way a human being would in sort order.",
|
||||
"keywords": [
|
||||
"string",
|
||||
"natural",
|
||||
"order",
|
||||
"sort",
|
||||
"natsort",
|
||||
"natcmp",
|
||||
"compare",
|
||||
"alphanum",
|
||||
"litejs"
|
||||
],
|
||||
"main": "index.js",
|
||||
"readmeFilename": "README.md",
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "node node_modules/buildman/index.js --all",
|
||||
"test": "node tests/index.js"
|
||||
},
|
||||
"repository": "git://github.com/litejs/natural-compare-lite.git",
|
||||
"bugs": {
|
||||
"url": "https://github.com/litejs/natural-compare-lite/issues"
|
||||
},
|
||||
"devDependencies": {
|
||||
"buildman": "*",
|
||||
"testman": "*"
|
||||
},
|
||||
"buildman": {
|
||||
"dist/index-min.js": {
|
||||
"banner": "/*! litejs.com/MIT-LICENSE.txt */",
|
||||
"input": "index.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
const promisify = require('es6-promisify');
|
||||
const jayson = require('../../../');
|
||||
const promiseUtils = require('../utils');
|
||||
|
||||
/**
|
||||
* Constructor for a Jayson Promise Client Tls
|
||||
* @see Client
|
||||
* @class PromiseClientTls
|
||||
* @extends ClientTls
|
||||
* @return {PromiseClientTls}
|
||||
*/
|
||||
const PromiseClientTls = function(options) {
|
||||
if(!(this instanceof PromiseClientTls)) {
|
||||
return new PromiseClientTls(options);
|
||||
}
|
||||
jayson.Client.tls.apply(this, arguments);
|
||||
this.request = promiseUtils.wrapClientRequestMethod(this.request.bind(this));
|
||||
};
|
||||
require('util').inherits(PromiseClientTls, jayson.Client.tls);
|
||||
|
||||
module.exports = PromiseClientTls;
|
||||
@@ -0,0 +1 @@
|
||||
export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, _slugify as slugify, type $RefinementCtx as RefinementCtx, } from "../core/index.js";
|
||||
@@ -0,0 +1,518 @@
|
||||
'use strict';
|
||||
|
||||
const zlib = require('zlib');
|
||||
|
||||
const bufferUtil = require('./buffer-util');
|
||||
const Limiter = require('./limiter');
|
||||
const { kStatusCode, NOOP } = require('./constants');
|
||||
|
||||
const TRAILER = Buffer.from([0x00, 0x00, 0xff, 0xff]);
|
||||
const kPerMessageDeflate = Symbol('permessage-deflate');
|
||||
const kTotalLength = Symbol('total-length');
|
||||
const kCallback = Symbol('callback');
|
||||
const kBuffers = Symbol('buffers');
|
||||
const kError = Symbol('error');
|
||||
|
||||
//
|
||||
// We limit zlib concurrency, which prevents severe memory fragmentation
|
||||
// as documented in https://github.com/nodejs/node/issues/8871#issuecomment-250915913
|
||||
// and https://github.com/websockets/ws/issues/1202
|
||||
//
|
||||
// Intentionally global; it's the global thread pool that's an issue.
|
||||
//
|
||||
let zlibLimiter;
|
||||
|
||||
/**
|
||||
* permessage-deflate implementation.
|
||||
*/
|
||||
class PerMessageDeflate {
|
||||
/**
|
||||
* Creates a PerMessageDeflate instance.
|
||||
*
|
||||
* @param {Object} [options] Configuration options
|
||||
* @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
|
||||
* disabling of server context takeover
|
||||
* @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
|
||||
* acknowledge disabling of client context takeover
|
||||
* @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
|
||||
* use of a custom server window size
|
||||
* @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
|
||||
* for, or request, a custom client window size
|
||||
* @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
|
||||
* deflate
|
||||
* @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
|
||||
* inflate
|
||||
* @param {Number} [options.threshold=1024] Size (in bytes) below which
|
||||
* messages should not be compressed
|
||||
* @param {Number} [options.concurrencyLimit=10] The number of concurrent
|
||||
* calls to zlib
|
||||
* @param {Boolean} [isServer=false] Create the instance in either server or
|
||||
* client mode
|
||||
* @param {Number} [maxPayload=0] The maximum allowed message length
|
||||
*/
|
||||
constructor(options, isServer, maxPayload) {
|
||||
this._maxPayload = maxPayload | 0;
|
||||
this._options = options || {};
|
||||
this._threshold =
|
||||
this._options.threshold !== undefined ? this._options.threshold : 1024;
|
||||
this._isServer = !!isServer;
|
||||
this._deflate = null;
|
||||
this._inflate = null;
|
||||
|
||||
this.params = null;
|
||||
|
||||
if (!zlibLimiter) {
|
||||
const concurrency =
|
||||
this._options.concurrencyLimit !== undefined
|
||||
? this._options.concurrencyLimit
|
||||
: 10;
|
||||
zlibLimiter = new Limiter(concurrency);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {String}
|
||||
*/
|
||||
static get extensionName() {
|
||||
return 'permessage-deflate';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an extension negotiation offer.
|
||||
*
|
||||
* @return {Object} Extension parameters
|
||||
* @public
|
||||
*/
|
||||
offer() {
|
||||
const params = {};
|
||||
|
||||
if (this._options.serverNoContextTakeover) {
|
||||
params.server_no_context_takeover = true;
|
||||
}
|
||||
if (this._options.clientNoContextTakeover) {
|
||||
params.client_no_context_takeover = true;
|
||||
}
|
||||
if (this._options.serverMaxWindowBits) {
|
||||
params.server_max_window_bits = this._options.serverMaxWindowBits;
|
||||
}
|
||||
if (this._options.clientMaxWindowBits) {
|
||||
params.client_max_window_bits = this._options.clientMaxWindowBits;
|
||||
} else if (this._options.clientMaxWindowBits == null) {
|
||||
params.client_max_window_bits = true;
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept an extension negotiation offer/response.
|
||||
*
|
||||
* @param {Array} configurations The extension negotiation offers/reponse
|
||||
* @return {Object} Accepted configuration
|
||||
* @public
|
||||
*/
|
||||
accept(configurations) {
|
||||
configurations = this.normalizeParams(configurations);
|
||||
|
||||
this.params = this._isServer
|
||||
? this.acceptAsServer(configurations)
|
||||
: this.acceptAsClient(configurations);
|
||||
|
||||
return this.params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases all resources used by the extension.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
cleanup() {
|
||||
if (this._inflate) {
|
||||
this._inflate.close();
|
||||
this._inflate = null;
|
||||
}
|
||||
|
||||
if (this._deflate) {
|
||||
const callback = this._deflate[kCallback];
|
||||
|
||||
this._deflate.close();
|
||||
this._deflate = null;
|
||||
|
||||
if (callback) {
|
||||
callback(
|
||||
new Error(
|
||||
'The deflate stream was closed while data was being processed'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept an extension negotiation offer.
|
||||
*
|
||||
* @param {Array} offers The extension negotiation offers
|
||||
* @return {Object} Accepted configuration
|
||||
* @private
|
||||
*/
|
||||
acceptAsServer(offers) {
|
||||
const opts = this._options;
|
||||
const accepted = offers.find((params) => {
|
||||
if (
|
||||
(opts.serverNoContextTakeover === false &&
|
||||
params.server_no_context_takeover) ||
|
||||
(params.server_max_window_bits &&
|
||||
(opts.serverMaxWindowBits === false ||
|
||||
(typeof opts.serverMaxWindowBits === 'number' &&
|
||||
opts.serverMaxWindowBits > params.server_max_window_bits))) ||
|
||||
(typeof opts.clientMaxWindowBits === 'number' &&
|
||||
!params.client_max_window_bits)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
if (!accepted) {
|
||||
throw new Error('None of the extension offers can be accepted');
|
||||
}
|
||||
|
||||
if (opts.serverNoContextTakeover) {
|
||||
accepted.server_no_context_takeover = true;
|
||||
}
|
||||
if (opts.clientNoContextTakeover) {
|
||||
accepted.client_no_context_takeover = true;
|
||||
}
|
||||
if (typeof opts.serverMaxWindowBits === 'number') {
|
||||
accepted.server_max_window_bits = opts.serverMaxWindowBits;
|
||||
}
|
||||
if (typeof opts.clientMaxWindowBits === 'number') {
|
||||
accepted.client_max_window_bits = opts.clientMaxWindowBits;
|
||||
} else if (
|
||||
accepted.client_max_window_bits === true ||
|
||||
opts.clientMaxWindowBits === false
|
||||
) {
|
||||
delete accepted.client_max_window_bits;
|
||||
}
|
||||
|
||||
return accepted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept the extension negotiation response.
|
||||
*
|
||||
* @param {Array} response The extension negotiation response
|
||||
* @return {Object} Accepted configuration
|
||||
* @private
|
||||
*/
|
||||
acceptAsClient(response) {
|
||||
const params = response[0];
|
||||
|
||||
if (
|
||||
this._options.clientNoContextTakeover === false &&
|
||||
params.client_no_context_takeover
|
||||
) {
|
||||
throw new Error('Unexpected parameter "client_no_context_takeover"');
|
||||
}
|
||||
|
||||
if (!params.client_max_window_bits) {
|
||||
if (typeof this._options.clientMaxWindowBits === 'number') {
|
||||
params.client_max_window_bits = this._options.clientMaxWindowBits;
|
||||
}
|
||||
} else if (
|
||||
this._options.clientMaxWindowBits === false ||
|
||||
(typeof this._options.clientMaxWindowBits === 'number' &&
|
||||
params.client_max_window_bits > this._options.clientMaxWindowBits)
|
||||
) {
|
||||
throw new Error(
|
||||
'Unexpected or invalid parameter "client_max_window_bits"'
|
||||
);
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize parameters.
|
||||
*
|
||||
* @param {Array} configurations The extension negotiation offers/reponse
|
||||
* @return {Array} The offers/response with normalized parameters
|
||||
* @private
|
||||
*/
|
||||
normalizeParams(configurations) {
|
||||
configurations.forEach((params) => {
|
||||
Object.keys(params).forEach((key) => {
|
||||
let value = params[key];
|
||||
|
||||
if (value.length > 1) {
|
||||
throw new Error(`Parameter "${key}" must have only a single value`);
|
||||
}
|
||||
|
||||
value = value[0];
|
||||
|
||||
if (key === 'client_max_window_bits') {
|
||||
if (value !== true) {
|
||||
const num = +value;
|
||||
if (!Number.isInteger(num) || num < 8 || num > 15) {
|
||||
throw new TypeError(
|
||||
`Invalid value for parameter "${key}": ${value}`
|
||||
);
|
||||
}
|
||||
value = num;
|
||||
} else if (!this._isServer) {
|
||||
throw new TypeError(
|
||||
`Invalid value for parameter "${key}": ${value}`
|
||||
);
|
||||
}
|
||||
} else if (key === 'server_max_window_bits') {
|
||||
const num = +value;
|
||||
if (!Number.isInteger(num) || num < 8 || num > 15) {
|
||||
throw new TypeError(
|
||||
`Invalid value for parameter "${key}": ${value}`
|
||||
);
|
||||
}
|
||||
value = num;
|
||||
} else if (
|
||||
key === 'client_no_context_takeover' ||
|
||||
key === 'server_no_context_takeover'
|
||||
) {
|
||||
if (value !== true) {
|
||||
throw new TypeError(
|
||||
`Invalid value for parameter "${key}": ${value}`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
throw new Error(`Unknown parameter "${key}"`);
|
||||
}
|
||||
|
||||
params[key] = value;
|
||||
});
|
||||
});
|
||||
|
||||
return configurations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decompress data. Concurrency limited.
|
||||
*
|
||||
* @param {Buffer} data Compressed data
|
||||
* @param {Boolean} fin Specifies whether or not this is the last fragment
|
||||
* @param {Function} callback Callback
|
||||
* @public
|
||||
*/
|
||||
decompress(data, fin, callback) {
|
||||
zlibLimiter.add((done) => {
|
||||
this._decompress(data, fin, (err, result) => {
|
||||
done();
|
||||
callback(err, result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Compress data. Concurrency limited.
|
||||
*
|
||||
* @param {Buffer} data Data to compress
|
||||
* @param {Boolean} fin Specifies whether or not this is the last fragment
|
||||
* @param {Function} callback Callback
|
||||
* @public
|
||||
*/
|
||||
compress(data, fin, callback) {
|
||||
zlibLimiter.add((done) => {
|
||||
this._compress(data, fin, (err, result) => {
|
||||
done();
|
||||
callback(err, result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Decompress data.
|
||||
*
|
||||
* @param {Buffer} data Compressed data
|
||||
* @param {Boolean} fin Specifies whether or not this is the last fragment
|
||||
* @param {Function} callback Callback
|
||||
* @private
|
||||
*/
|
||||
_decompress(data, fin, callback) {
|
||||
const endpoint = this._isServer ? 'client' : 'server';
|
||||
|
||||
if (!this._inflate) {
|
||||
const key = `${endpoint}_max_window_bits`;
|
||||
const windowBits =
|
||||
typeof this.params[key] !== 'number'
|
||||
? zlib.Z_DEFAULT_WINDOWBITS
|
||||
: this.params[key];
|
||||
|
||||
this._inflate = zlib.createInflateRaw({
|
||||
...this._options.zlibInflateOptions,
|
||||
windowBits
|
||||
});
|
||||
this._inflate[kPerMessageDeflate] = this;
|
||||
this._inflate[kTotalLength] = 0;
|
||||
this._inflate[kBuffers] = [];
|
||||
this._inflate.on('error', inflateOnError);
|
||||
this._inflate.on('data', inflateOnData);
|
||||
}
|
||||
|
||||
this._inflate[kCallback] = callback;
|
||||
|
||||
this._inflate.write(data);
|
||||
if (fin) this._inflate.write(TRAILER);
|
||||
|
||||
this._inflate.flush(() => {
|
||||
const err = this._inflate[kError];
|
||||
|
||||
if (err) {
|
||||
this._inflate.close();
|
||||
this._inflate = null;
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
const data = bufferUtil.concat(
|
||||
this._inflate[kBuffers],
|
||||
this._inflate[kTotalLength]
|
||||
);
|
||||
|
||||
if (this._inflate._readableState.endEmitted) {
|
||||
this._inflate.close();
|
||||
this._inflate = null;
|
||||
} else {
|
||||
this._inflate[kTotalLength] = 0;
|
||||
this._inflate[kBuffers] = [];
|
||||
|
||||
if (fin && this.params[`${endpoint}_no_context_takeover`]) {
|
||||
this._inflate.reset();
|
||||
}
|
||||
}
|
||||
|
||||
callback(null, data);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Compress data.
|
||||
*
|
||||
* @param {Buffer} data Data to compress
|
||||
* @param {Boolean} fin Specifies whether or not this is the last fragment
|
||||
* @param {Function} callback Callback
|
||||
* @private
|
||||
*/
|
||||
_compress(data, fin, callback) {
|
||||
const endpoint = this._isServer ? 'server' : 'client';
|
||||
|
||||
if (!this._deflate) {
|
||||
const key = `${endpoint}_max_window_bits`;
|
||||
const windowBits =
|
||||
typeof this.params[key] !== 'number'
|
||||
? zlib.Z_DEFAULT_WINDOWBITS
|
||||
: this.params[key];
|
||||
|
||||
this._deflate = zlib.createDeflateRaw({
|
||||
...this._options.zlibDeflateOptions,
|
||||
windowBits
|
||||
});
|
||||
|
||||
this._deflate[kTotalLength] = 0;
|
||||
this._deflate[kBuffers] = [];
|
||||
|
||||
//
|
||||
// An `'error'` event is emitted, only on Node.js < 10.0.0, if the
|
||||
// `zlib.DeflateRaw` instance is closed while data is being processed.
|
||||
// This can happen if `PerMessageDeflate#cleanup()` is called at the wrong
|
||||
// time due to an abnormal WebSocket closure.
|
||||
//
|
||||
this._deflate.on('error', NOOP);
|
||||
this._deflate.on('data', deflateOnData);
|
||||
}
|
||||
|
||||
this._deflate[kCallback] = callback;
|
||||
|
||||
this._deflate.write(data);
|
||||
this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
|
||||
if (!this._deflate) {
|
||||
//
|
||||
// The deflate stream was closed while data was being processed.
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
let data = bufferUtil.concat(
|
||||
this._deflate[kBuffers],
|
||||
this._deflate[kTotalLength]
|
||||
);
|
||||
|
||||
if (fin) data = data.slice(0, data.length - 4);
|
||||
|
||||
//
|
||||
// Ensure that the callback will not be called again in
|
||||
// `PerMessageDeflate#cleanup()`.
|
||||
//
|
||||
this._deflate[kCallback] = null;
|
||||
|
||||
this._deflate[kTotalLength] = 0;
|
||||
this._deflate[kBuffers] = [];
|
||||
|
||||
if (fin && this.params[`${endpoint}_no_context_takeover`]) {
|
||||
this._deflate.reset();
|
||||
}
|
||||
|
||||
callback(null, data);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PerMessageDeflate;
|
||||
|
||||
/**
|
||||
* The listener of the `zlib.DeflateRaw` stream `'data'` event.
|
||||
*
|
||||
* @param {Buffer} chunk A chunk of data
|
||||
* @private
|
||||
*/
|
||||
function deflateOnData(chunk) {
|
||||
this[kBuffers].push(chunk);
|
||||
this[kTotalLength] += chunk.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* The listener of the `zlib.InflateRaw` stream `'data'` event.
|
||||
*
|
||||
* @param {Buffer} chunk A chunk of data
|
||||
* @private
|
||||
*/
|
||||
function inflateOnData(chunk) {
|
||||
this[kTotalLength] += chunk.length;
|
||||
|
||||
if (
|
||||
this[kPerMessageDeflate]._maxPayload < 1 ||
|
||||
this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload
|
||||
) {
|
||||
this[kBuffers].push(chunk);
|
||||
return;
|
||||
}
|
||||
|
||||
this[kError] = new RangeError('Max payload size exceeded');
|
||||
this[kError].code = 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH';
|
||||
this[kError][kStatusCode] = 1009;
|
||||
this.removeListener('data', inflateOnData);
|
||||
this.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* The listener of the `zlib.InflateRaw` stream `'error'` event.
|
||||
*
|
||||
* @param {Error} err The emitted error
|
||||
* @private
|
||||
*/
|
||||
function inflateOnError(err) {
|
||||
//
|
||||
// There is no need to call `Zlib#close()` as the handle is automatically
|
||||
// closed when an error is emitted.
|
||||
//
|
||||
this[kPerMessageDeflate]._inflate = null;
|
||||
err[kStatusCode] = 1007;
|
||||
this[kCallback](err);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { _ as default } from "../esm/_object_destructuring_empty.js";
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,145 @@
|
||||
/**
|
||||
* @fileoverview Rule to forbid control characters from regular expressions.
|
||||
* @author Nicholas C. Zakas
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const RegExpValidator = require("@eslint-community/regexpp").RegExpValidator;
|
||||
const collector = new (class {
|
||||
constructor() {
|
||||
this._source = "";
|
||||
this._controlChars = [];
|
||||
this._validator = new RegExpValidator(this);
|
||||
}
|
||||
|
||||
onPatternEnter() {
|
||||
/*
|
||||
* `RegExpValidator` may parse the pattern twice in one `validatePattern`.
|
||||
* So `this._controlChars` should be cleared here as well.
|
||||
*
|
||||
* For example, the `/(?<a>\x1f)/` regex will parse the pattern twice.
|
||||
* This is based on the content described in Annex B.
|
||||
* If the regex contains a `GroupName` and the `u` flag is not used, `ParseText` will be called twice.
|
||||
* See https://tc39.es/ecma262/2023/multipage/additional-ecmascript-features-for-web-browsers.html#sec-parsepattern-annexb
|
||||
*/
|
||||
this._controlChars = [];
|
||||
}
|
||||
|
||||
onCharacter(start, end, cp) {
|
||||
if (
|
||||
cp >= 0x00 &&
|
||||
cp <= 0x1f &&
|
||||
(this._source.codePointAt(start) === cp ||
|
||||
this._source.slice(start, end).startsWith("\\x") ||
|
||||
this._source.slice(start, end).startsWith("\\u"))
|
||||
) {
|
||||
this._controlChars.push(`\\x${`0${cp.toString(16)}`.slice(-2)}`);
|
||||
}
|
||||
}
|
||||
|
||||
collectControlChars(regexpStr, flags) {
|
||||
const uFlag = typeof flags === "string" && flags.includes("u");
|
||||
const vFlag = typeof flags === "string" && flags.includes("v");
|
||||
|
||||
this._controlChars = [];
|
||||
this._source = regexpStr;
|
||||
|
||||
try {
|
||||
this._validator.validatePattern(regexpStr, void 0, void 0, {
|
||||
unicode: uFlag,
|
||||
unicodeSets: vFlag,
|
||||
}); // Call onCharacter hook
|
||||
} catch {
|
||||
// Ignore syntax errors in RegExp.
|
||||
}
|
||||
return this._controlChars;
|
||||
}
|
||||
})();
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../types').Rule.RuleModule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "problem",
|
||||
|
||||
docs: {
|
||||
description: "Disallow control characters in regular expressions",
|
||||
recommended: true,
|
||||
url: "https://eslint.org/docs/latest/rules/no-control-regex",
|
||||
},
|
||||
|
||||
schema: [],
|
||||
|
||||
messages: {
|
||||
unexpected:
|
||||
"Unexpected control character(s) in regular expression: {{controlChars}}.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const sourceCode = context.sourceCode;
|
||||
|
||||
/**
|
||||
* Get the regex expression
|
||||
* @param {ASTNode} node `Literal` node to evaluate
|
||||
* @returns {{ pattern: string, flags: string | null } | null} Regex if found (the given node is either a regex literal
|
||||
* or a string literal that is the pattern argument of a RegExp constructor call). Otherwise `null`. If flags cannot be determined,
|
||||
* the `flags` property will be `null`.
|
||||
* @private
|
||||
*/
|
||||
function getRegExp(node) {
|
||||
if (node.regex) {
|
||||
return node.regex;
|
||||
}
|
||||
if (
|
||||
typeof node.value === "string" &&
|
||||
(node.parent.type === "NewExpression" ||
|
||||
node.parent.type === "CallExpression") &&
|
||||
node.parent.callee.type === "Identifier" &&
|
||||
node.parent.callee.name === "RegExp" &&
|
||||
sourceCode.isGlobalReference(node.parent.callee) &&
|
||||
node.parent.arguments[0] === node
|
||||
) {
|
||||
const pattern = node.value;
|
||||
const flags =
|
||||
node.parent.arguments.length > 1 &&
|
||||
node.parent.arguments[1].type === "Literal" &&
|
||||
typeof node.parent.arguments[1].value === "string"
|
||||
? node.parent.arguments[1].value
|
||||
: null;
|
||||
|
||||
return { pattern, flags };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
Literal(node) {
|
||||
const regExp = getRegExp(node);
|
||||
|
||||
if (regExp) {
|
||||
const { pattern, flags } = regExp;
|
||||
const controlCharacters = collector.collectControlChars(
|
||||
pattern,
|
||||
flags,
|
||||
);
|
||||
|
||||
if (controlCharacters.length > 0) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: "unexpected",
|
||||
data: {
|
||||
controlChars: controlCharacters.join(", "),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,8 @@
|
||||
var arrayWithHoles = require("./arrayWithHoles.js");
|
||||
var iterableToArrayLimit = require("./iterableToArrayLimit.js");
|
||||
var unsupportedIterableToArray = require("./unsupportedIterableToArray.js");
|
||||
var nonIterableRest = require("./nonIterableRest.js");
|
||||
function _slicedToArray(r, e) {
|
||||
return arrayWithHoles(r) || iterableToArrayLimit(r, e) || unsupportedIterableToArray(r, e) || nonIterableRest();
|
||||
}
|
||||
module.exports = _slicedToArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
||||
@@ -0,0 +1,41 @@
|
||||
// @ts-ignore TS6133
|
||||
import { expect, test } from "vitest";
|
||||
|
||||
import * as z from "zod/v3";
|
||||
|
||||
test("parse strict object with unknown keys", () => {
|
||||
expect(() =>
|
||||
z
|
||||
.object({ name: z.string() })
|
||||
.strict()
|
||||
.parse({ name: "bill", unknownKey: 12 } as any)
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
test("parse nonstrict object with unknown keys", () => {
|
||||
z.object({ name: z.string() }).nonstrict().parse({ name: "bill", unknownKey: 12 });
|
||||
});
|
||||
|
||||
test("invalid left side of intersection", () => {
|
||||
expect(() => z.intersection(z.string(), z.number()).parse(12 as any)).toThrow();
|
||||
});
|
||||
|
||||
test("invalid right side of intersection", () => {
|
||||
expect(() => z.intersection(z.string(), z.number()).parse("12" as any)).toThrow();
|
||||
});
|
||||
|
||||
test("parsing non-array in tuple schema", () => {
|
||||
expect(() => z.tuple([]).parse("12" as any)).toThrow();
|
||||
});
|
||||
|
||||
test("incorrect num elements in tuple", () => {
|
||||
expect(() => z.tuple([]).parse(["asdf"] as any)).toThrow();
|
||||
});
|
||||
|
||||
test("invalid enum value", () => {
|
||||
expect(() => z.enum(["Blue"]).parse("Red" as any)).toThrow();
|
||||
});
|
||||
|
||||
test("parsing unknown", () => {
|
||||
z.string().parse("Red" as unknown);
|
||||
});
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,47 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.hasOverloadSignatures = hasOverloadSignatures;
|
||||
const utils_1 = require("@typescript-eslint/utils");
|
||||
const misc_1 = require("./misc");
|
||||
/**
|
||||
* @return `true` if the function or method node has overload signatures.
|
||||
*/
|
||||
function hasOverloadSignatures(node, context) {
|
||||
// `export default function () {}`
|
||||
if (node.parent.type === utils_1.AST_NODE_TYPES.ExportDefaultDeclaration) {
|
||||
return node.parent.parent.body.some(member => {
|
||||
return (member.type === utils_1.AST_NODE_TYPES.ExportDefaultDeclaration &&
|
||||
member.declaration.type === utils_1.AST_NODE_TYPES.TSDeclareFunction);
|
||||
});
|
||||
}
|
||||
// `export function f() {}`
|
||||
if (node.parent.type === utils_1.AST_NODE_TYPES.ExportNamedDeclaration) {
|
||||
return node.parent.parent.body.some(member => {
|
||||
return (member.type === utils_1.AST_NODE_TYPES.ExportNamedDeclaration &&
|
||||
member.declaration?.type === utils_1.AST_NODE_TYPES.TSDeclareFunction &&
|
||||
getFunctionDeclarationName(member.declaration, context) ===
|
||||
getFunctionDeclarationName(node, context));
|
||||
});
|
||||
}
|
||||
// either:
|
||||
// - `function f() {}`
|
||||
// - `class T { foo() {} }`
|
||||
const nodeKey = getFunctionDeclarationName(node, context);
|
||||
return node.parent.body.some(member => {
|
||||
return ((member.type === utils_1.AST_NODE_TYPES.TSDeclareFunction ||
|
||||
(member.type === utils_1.AST_NODE_TYPES.MethodDefinition &&
|
||||
member.value.body == null)) &&
|
||||
nodeKey === getFunctionDeclarationName(member, context));
|
||||
});
|
||||
}
|
||||
function getFunctionDeclarationName(node, context) {
|
||||
if (node.type === utils_1.AST_NODE_TYPES.FunctionDeclaration ||
|
||||
node.type === utils_1.AST_NODE_TYPES.TSDeclareFunction) {
|
||||
// For a `FunctionDeclaration` or `TSDeclareFunction` this may be `null` if
|
||||
// and only if the parent is an `ExportDefaultDeclaration`.
|
||||
//
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
return node.id.name;
|
||||
}
|
||||
return (0, misc_1.getStaticMemberAccessValue)(node, context);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"main": "../../cjs/_interop_require_wildcard.cjs",
|
||||
"module": "../../esm/_interop_require_wildcard.js"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import Client from './client'
|
||||
|
||||
export default ClientStats
|
||||
|
||||
declare class ClientStats {
|
||||
constructor (pool: Client)
|
||||
/** If socket has open connection. */
|
||||
connected: boolean
|
||||
/** Number of open socket connections in this client that do not have an active request. */
|
||||
pending: number
|
||||
/** Number of currently active requests of this client. */
|
||||
running: number
|
||||
/** Number of active, pending, or queued requests of this client. */
|
||||
size: number
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
// make input suggestions work
|
||||
type StringQueryType = `?${keyof KnownAsTypeMap}` | (string & {})
|
||||
type BaseQueryType = StringQueryType | Record<string, string | number | boolean>
|
||||
|
||||
export interface ImportGlobOptions<
|
||||
Eager extends boolean,
|
||||
AsType extends string,
|
||||
QueryType extends BaseQueryType,
|
||||
> {
|
||||
/**
|
||||
* Import type for the import url.
|
||||
*
|
||||
* @deprecated Use `query` instead, e.g. `as: 'url'` -> `query: '?url', import: 'default'`
|
||||
*/
|
||||
as?: AsType
|
||||
/**
|
||||
* Import as static or dynamic
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
eager?: Eager
|
||||
/**
|
||||
* Import only the specific named export. Set to `default` to import the default export.
|
||||
*/
|
||||
import?: string
|
||||
/**
|
||||
* Custom queries
|
||||
*/
|
||||
query?: QueryType
|
||||
/**
|
||||
* Search files also inside `node_modules/` and hidden directories (e.g. `.git/`). This might have impact on performance.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
exhaustive?: boolean
|
||||
/**
|
||||
* Base path to resolve relative paths.
|
||||
*/
|
||||
base?: string
|
||||
/**
|
||||
* Whether the glob pattern matching should be case-sensitive. Defaults to `true`.
|
||||
*/
|
||||
caseSensitive?: boolean
|
||||
}
|
||||
|
||||
export type ImportGlobOptionsWithoutAs<
|
||||
Eager extends boolean,
|
||||
QueryType extends BaseQueryType,
|
||||
> = Omit<ImportGlobOptions<Eager, string, QueryType>, 'as'> & {
|
||||
as?: never
|
||||
}
|
||||
|
||||
export type GeneralImportGlobOptions = ImportGlobOptions<
|
||||
boolean,
|
||||
string,
|
||||
BaseQueryType
|
||||
>
|
||||
|
||||
/**
|
||||
* Declare Worker in case DOM is not added to the tsconfig lib causing
|
||||
* Worker interface is not defined. For developers with DOM lib added,
|
||||
* the Worker interface will be merged correctly.
|
||||
*/
|
||||
declare global {
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
||||
interface Worker {}
|
||||
}
|
||||
|
||||
export interface KnownAsTypeMap {
|
||||
raw: string
|
||||
url: string
|
||||
worker: Worker
|
||||
}
|
||||
|
||||
type KnownQueryTypeMap = {
|
||||
[K in keyof KnownAsTypeMap as `?${K}`]: KnownAsTypeMap[K]
|
||||
}
|
||||
|
||||
export interface ImportGlobFunction {
|
||||
/**
|
||||
* Import a list of files with a glob pattern.
|
||||
*
|
||||
* Overload 1A: No generic provided, infer the type from `eager` and `query`
|
||||
*/
|
||||
<
|
||||
Eager extends boolean,
|
||||
Query extends BaseQueryType,
|
||||
T = Query extends keyof KnownQueryTypeMap
|
||||
? KnownQueryTypeMap[Query]
|
||||
: unknown,
|
||||
>(
|
||||
glob: string | string[],
|
||||
options?: ImportGlobOptionsWithoutAs<Eager, Query>,
|
||||
): (Eager extends true ? true : false) extends true
|
||||
? Record<string, T>
|
||||
: Record<string, () => Promise<T>>
|
||||
/**
|
||||
* Import a list of files with a glob pattern.
|
||||
*
|
||||
* Overload 1B: No generic provided, infer the type from `eager` and `as`
|
||||
* (deprecated, use `query` instead)
|
||||
*/
|
||||
<
|
||||
Eager extends boolean,
|
||||
As extends string,
|
||||
T = As extends keyof KnownAsTypeMap ? KnownAsTypeMap[As] : unknown,
|
||||
>(
|
||||
glob: string | string[],
|
||||
options?: ImportGlobOptions<Eager, As, BaseQueryType>,
|
||||
): (Eager extends true ? true : false) extends true
|
||||
? Record<string, T>
|
||||
: Record<string, () => Promise<T>>
|
||||
/**
|
||||
* Import a list of files with a glob pattern.
|
||||
*
|
||||
* Overload 2: Module generic provided, infer the type from `eager: false`
|
||||
*/
|
||||
<M>(
|
||||
glob: string | string[],
|
||||
options?: ImportGlobOptions<false, string, BaseQueryType>,
|
||||
): Record<string, () => Promise<M>>
|
||||
/**
|
||||
* Import a list of files with a glob pattern.
|
||||
*
|
||||
* Overload 3: Module generic provided, infer the type from `eager: true`
|
||||
*/
|
||||
<M>(
|
||||
glob: string | string[],
|
||||
options: ImportGlobOptions<true, string, BaseQueryType>,
|
||||
): Record<string, M>
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.parserSeemsToBeTSESLint = parserSeemsToBeTSESLint;
|
||||
function parserSeemsToBeTSESLint(parser) {
|
||||
return !!parser && /(?:typescript-eslint|\.\.)[\w/\\]*parser/.test(parser);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
"use strict";var n=Object.defineProperty;var s=(e,t)=>n(e,"name",{value:t,configurable:!0});const i=s((e,t)=>{const r=e[0]-t[0];if(r===0){const o=e[1]-t[1];return o===0?e[2]>=t[2]:o>0}return r>0},"isVersionGreaterOrEqual"),u=process.versions.node.split(".").map(Number),a=s((e,t=u)=>{for(let r=0;r<e.length;r+=1){const o=e[r];if(r===e.length-1||t[0]===o[0])return i(t,o)}return!1},"isFeatureSupported"),l=[[18,19,0],[20,6,0]],m=[[22,22,3],[24,11,1],[25,1,0],[26,0,0]],c=[[18,19,0],[20,10,0],[21,0,0]],d=[[21,0,0]],p=[[20,11,0],[21,3,0]],f=[[20,11,0],[21,2,0]],R=[[20,19,0],[22,12,0],[23,0,0]];exports.esmLoadReadFile=p,exports.importAttributes=c,exports.importMetaPathProperties=f,exports.isFeatureSupported=a,exports.moduleRegister=l,exports.moduleRegisterHooksCjsReload=m,exports.requireEsm=R,exports.testRunnerGlob=d;
|
||||
@@ -0,0 +1 @@
|
||||
export * from './dist/helpers.js'
|
||||
@@ -0,0 +1,132 @@
|
||||
import * as util from "../core/util.js";
|
||||
const error = () => {
|
||||
const Sizable = {
|
||||
string: { unit: "caracteres", verb: "tener" },
|
||||
file: { unit: "bytes", verb: "tener" },
|
||||
array: { unit: "elementos", verb: "tener" },
|
||||
set: { unit: "elementos", verb: "tener" },
|
||||
};
|
||||
function getSizing(origin) {
|
||||
return Sizable[origin] ?? null;
|
||||
}
|
||||
const FormatDictionary = {
|
||||
regex: "entrada",
|
||||
email: "dirección de correo electrónico",
|
||||
url: "URL",
|
||||
emoji: "emoji",
|
||||
uuid: "UUID",
|
||||
uuidv4: "UUIDv4",
|
||||
uuidv6: "UUIDv6",
|
||||
nanoid: "nanoid",
|
||||
guid: "GUID",
|
||||
cuid: "cuid",
|
||||
cuid2: "cuid2",
|
||||
ulid: "ULID",
|
||||
xid: "XID",
|
||||
ksuid: "KSUID",
|
||||
datetime: "fecha y hora ISO",
|
||||
date: "fecha ISO",
|
||||
time: "hora ISO",
|
||||
duration: "duración ISO",
|
||||
ipv4: "dirección IPv4",
|
||||
ipv6: "dirección IPv6",
|
||||
cidrv4: "rango IPv4",
|
||||
cidrv6: "rango IPv6",
|
||||
base64: "cadena codificada en base64",
|
||||
base64url: "URL codificada en base64",
|
||||
json_string: "cadena JSON",
|
||||
e164: "número E.164",
|
||||
jwt: "JWT",
|
||||
template_literal: "entrada",
|
||||
};
|
||||
const TypeDictionary = {
|
||||
nan: "NaN",
|
||||
string: "texto",
|
||||
number: "número",
|
||||
boolean: "booleano",
|
||||
array: "arreglo",
|
||||
object: "objeto",
|
||||
set: "conjunto",
|
||||
file: "archivo",
|
||||
date: "fecha",
|
||||
bigint: "número grande",
|
||||
symbol: "símbolo",
|
||||
undefined: "indefinido",
|
||||
null: "nulo",
|
||||
function: "función",
|
||||
map: "mapa",
|
||||
record: "registro",
|
||||
tuple: "tupla",
|
||||
enum: "enumeración",
|
||||
union: "unión",
|
||||
literal: "literal",
|
||||
promise: "promesa",
|
||||
void: "vacío",
|
||||
never: "nunca",
|
||||
unknown: "desconocido",
|
||||
any: "cualquiera",
|
||||
};
|
||||
return (issue) => {
|
||||
switch (issue.code) {
|
||||
case "invalid_type": {
|
||||
const expected = TypeDictionary[issue.expected] ?? issue.expected;
|
||||
const receivedType = util.parsedType(issue.input);
|
||||
const received = TypeDictionary[receivedType] ?? receivedType;
|
||||
if (/^[A-Z]/.test(issue.expected)) {
|
||||
return `Entrada inválida: se esperaba instanceof ${issue.expected}, recibido ${received}`;
|
||||
}
|
||||
return `Entrada inválida: se esperaba ${expected}, recibido ${received}`;
|
||||
}
|
||||
case "invalid_value":
|
||||
if (issue.values.length === 1)
|
||||
return `Entrada inválida: se esperaba ${util.stringifyPrimitive(issue.values[0])}`;
|
||||
return `Opción inválida: se esperaba una de ${util.joinValues(issue.values, "|")}`;
|
||||
case "too_big": {
|
||||
const adj = issue.inclusive ? "<=" : "<";
|
||||
const sizing = getSizing(issue.origin);
|
||||
const origin = TypeDictionary[issue.origin] ?? issue.origin;
|
||||
if (sizing)
|
||||
return `Demasiado grande: se esperaba que ${origin ?? "valor"} tuviera ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elementos"}`;
|
||||
return `Demasiado grande: se esperaba que ${origin ?? "valor"} fuera ${adj}${issue.maximum.toString()}`;
|
||||
}
|
||||
case "too_small": {
|
||||
const adj = issue.inclusive ? ">=" : ">";
|
||||
const sizing = getSizing(issue.origin);
|
||||
const origin = TypeDictionary[issue.origin] ?? issue.origin;
|
||||
if (sizing) {
|
||||
return `Demasiado pequeño: se esperaba que ${origin} tuviera ${adj}${issue.minimum.toString()} ${sizing.unit}`;
|
||||
}
|
||||
return `Demasiado pequeño: se esperaba que ${origin} fuera ${adj}${issue.minimum.toString()}`;
|
||||
}
|
||||
case "invalid_format": {
|
||||
const _issue = issue;
|
||||
if (_issue.format === "starts_with")
|
||||
return `Cadena inválida: debe comenzar con "${_issue.prefix}"`;
|
||||
if (_issue.format === "ends_with")
|
||||
return `Cadena inválida: debe terminar en "${_issue.suffix}"`;
|
||||
if (_issue.format === "includes")
|
||||
return `Cadena inválida: debe incluir "${_issue.includes}"`;
|
||||
if (_issue.format === "regex")
|
||||
return `Cadena inválida: debe coincidir con el patrón ${_issue.pattern}`;
|
||||
return `Inválido ${FormatDictionary[_issue.format] ?? issue.format}`;
|
||||
}
|
||||
case "not_multiple_of":
|
||||
return `Número inválido: debe ser múltiplo de ${issue.divisor}`;
|
||||
case "unrecognized_keys":
|
||||
return `Llave${issue.keys.length > 1 ? "s" : ""} desconocida${issue.keys.length > 1 ? "s" : ""}: ${util.joinValues(issue.keys, ", ")}`;
|
||||
case "invalid_key":
|
||||
return `Llave inválida en ${TypeDictionary[issue.origin] ?? issue.origin}`;
|
||||
case "invalid_union":
|
||||
return "Entrada inválida";
|
||||
case "invalid_element":
|
||||
return `Valor inválido en ${TypeDictionary[issue.origin] ?? issue.origin}`;
|
||||
default:
|
||||
return `Entrada inválida`;
|
||||
}
|
||||
};
|
||||
};
|
||||
export default function () {
|
||||
return {
|
||||
localeError: error(),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
import { Hash, type CHashO, type Input } from './utils.ts';
|
||||
/** Blake1 options. Basically just "salt" */
|
||||
export type BlakeOpts = {
|
||||
salt?: Uint8Array;
|
||||
};
|
||||
declare abstract class BLAKE1<T extends BLAKE1<T>> extends Hash<T> {
|
||||
protected finished: boolean;
|
||||
protected length: number;
|
||||
protected pos: number;
|
||||
protected destroyed: boolean;
|
||||
protected buffer: Uint8Array;
|
||||
protected view: DataView;
|
||||
protected salt: Uint32Array;
|
||||
abstract compress(view: DataView, offset: number, withLength?: boolean): void;
|
||||
protected abstract get(): number[];
|
||||
protected abstract set(...args: number[]): void;
|
||||
readonly blockLen: number;
|
||||
readonly outputLen: number;
|
||||
private lengthFlag;
|
||||
private counterLen;
|
||||
protected constants: Uint32Array;
|
||||
constructor(blockLen: number, outputLen: number, lengthFlag: number, counterLen: number, saltLen: number, constants: Uint32Array, opts?: BlakeOpts);
|
||||
update(data: Input): this;
|
||||
destroy(): void;
|
||||
_cloneInto(to?: T): T;
|
||||
clone(): T;
|
||||
digestInto(out: Uint8Array): void;
|
||||
digest(): Uint8Array;
|
||||
}
|
||||
declare class Blake1_32 extends BLAKE1<Blake1_32> {
|
||||
private v0;
|
||||
private v1;
|
||||
private v2;
|
||||
private v3;
|
||||
private v4;
|
||||
private v5;
|
||||
private v6;
|
||||
private v7;
|
||||
constructor(outputLen: number, IV: Uint32Array, lengthFlag: number, opts?: BlakeOpts);
|
||||
protected get(): [number, number, number, number, number, number, number, number];
|
||||
protected set(v0: number, v1: number, v2: number, v3: number, v4: number, v5: number, v6: number, v7: number): void;
|
||||
destroy(): void;
|
||||
compress(view: DataView, offset: number, withLength?: boolean): void;
|
||||
}
|
||||
declare class Blake1_64 extends BLAKE1<Blake1_64> {
|
||||
private v0l;
|
||||
private v0h;
|
||||
private v1l;
|
||||
private v1h;
|
||||
private v2l;
|
||||
private v2h;
|
||||
private v3l;
|
||||
private v3h;
|
||||
private v4l;
|
||||
private v4h;
|
||||
private v5l;
|
||||
private v5h;
|
||||
private v6l;
|
||||
private v6h;
|
||||
private v7l;
|
||||
private v7h;
|
||||
constructor(outputLen: number, IV: Uint32Array, lengthFlag: number, opts?: BlakeOpts);
|
||||
protected get(): [
|
||||
number,
|
||||
number,
|
||||
number,
|
||||
number,
|
||||
number,
|
||||
number,
|
||||
number,
|
||||
number,
|
||||
number,
|
||||
number,
|
||||
number,
|
||||
number,
|
||||
number,
|
||||
number,
|
||||
number,
|
||||
number
|
||||
];
|
||||
protected set(v0l: number, v0h: number, v1l: number, v1h: number, v2l: number, v2h: number, v3l: number, v3h: number, v4l: number, v4h: number, v5l: number, v5h: number, v6l: number, v6h: number, v7l: number, v7h: number): void;
|
||||
destroy(): void;
|
||||
compress(view: DataView, offset: number, withLength?: boolean): void;
|
||||
}
|
||||
export declare class BLAKE224 extends Blake1_32 {
|
||||
constructor(opts?: BlakeOpts);
|
||||
}
|
||||
export declare class BLAKE256 extends Blake1_32 {
|
||||
constructor(opts?: BlakeOpts);
|
||||
}
|
||||
export declare class BLAKE384 extends Blake1_64 {
|
||||
constructor(opts?: BlakeOpts);
|
||||
}
|
||||
export declare class BLAKE512 extends Blake1_64 {
|
||||
constructor(opts?: BlakeOpts);
|
||||
}
|
||||
/** blake1-224 hash function */
|
||||
export declare const blake224: CHashO;
|
||||
/** blake1-256 hash function */
|
||||
export declare const blake256: CHashO;
|
||||
/** blake1-384 hash function */
|
||||
export declare const blake384: CHashO;
|
||||
/** blake1-512 hash function */
|
||||
export declare const blake512: CHashO;
|
||||
export {};
|
||||
//# sourceMappingURL=blake1.d.ts.map
|
||||
@@ -0,0 +1,5 @@
|
||||
var checkPrivateRedeclaration = require("./checkPrivateRedeclaration.js");
|
||||
function _classPrivateFieldInitSpec(e, t, a) {
|
||||
checkPrivateRedeclaration(e, t), t.set(e, a);
|
||||
}
|
||||
module.exports = _classPrivateFieldInitSpec, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
||||
@@ -0,0 +1,59 @@
|
||||
import { getSafeTimers } from '@vitest/utils/timers';
|
||||
|
||||
const NAME_WORKER_STATE = "__vitest_worker__";
|
||||
class EnvironmentTeardownError extends Error {
|
||||
name = "EnvironmentTeardownError";
|
||||
}
|
||||
function getWorkerState() {
|
||||
// @ts-expect-error untyped global
|
||||
const workerState = globalThis[NAME_WORKER_STATE];
|
||||
if (!workerState) throw new Error("Vitest failed to access its internal state.\n\nOne of the following is possible:\n- \"vitest\" is imported directly without running \"vitest\" command\n- \"vitest\" is imported inside \"globalSetup\" (to fix this, use \"setupFiles\" instead, because \"globalSetup\" runs in a different context)\n- \"vitest\" is imported inside Vite / Vitest config file\n- Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues\n");
|
||||
return workerState;
|
||||
}
|
||||
function getSafeWorkerState() {
|
||||
// @ts-expect-error untyped global
|
||||
return globalThis[NAME_WORKER_STATE];
|
||||
}
|
||||
function provideWorkerState(context, state) {
|
||||
Object.defineProperty(context, NAME_WORKER_STATE, {
|
||||
value: state,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
enumerable: false
|
||||
});
|
||||
return state;
|
||||
}
|
||||
function isChildProcess() {
|
||||
return typeof process !== "undefined" && !!process.send;
|
||||
}
|
||||
function resetModules(modules, resetMocks = false) {
|
||||
const skipPaths = [
|
||||
/\/vitest\/dist\//,
|
||||
/vitest-virtual-\w+\/dist/,
|
||||
/@vitest\/dist/,
|
||||
...!resetMocks ? [/^mock:/] : []
|
||||
];
|
||||
modules.idToModuleMap.forEach((node, path) => {
|
||||
if (skipPaths.some((re) => re.test(path))) return;
|
||||
node.promise = void 0;
|
||||
node.exports = void 0;
|
||||
node.evaluated = false;
|
||||
node.importers.clear();
|
||||
});
|
||||
}
|
||||
function waitNextTick() {
|
||||
const { setTimeout } = getSafeTimers();
|
||||
return new Promise((resolve) => setTimeout(resolve, 0));
|
||||
}
|
||||
async function waitForImportsToResolve() {
|
||||
await waitNextTick();
|
||||
const state = getWorkerState();
|
||||
const promises = [];
|
||||
const resolvingCount = state.resolvingModules.size;
|
||||
for (const [_, mod] of state.evaluatedModules.idToModuleMap) if (mod.promise && !mod.evaluated) promises.push(mod.promise);
|
||||
if (!promises.length && !resolvingCount) return;
|
||||
await Promise.allSettled(promises);
|
||||
await waitForImportsToResolve();
|
||||
}
|
||||
|
||||
export { EnvironmentTeardownError as E, getSafeWorkerState as a, getWorkerState as g, isChildProcess as i, provideWorkerState as p, resetModules as r, waitForImportsToResolve as w };
|
||||
@@ -0,0 +1,50 @@
|
||||
export declare enum ObjectFlags {
|
||||
None = 0,
|
||||
Class = 1,
|
||||
Interface = 2,
|
||||
Reference = 4,
|
||||
Tuple = 8,
|
||||
Anonymous = 16,
|
||||
Mapped = 32,
|
||||
Instantiated = 64,
|
||||
ObjectLiteral = 128,
|
||||
EvolvingArray = 256,
|
||||
ObjectLiteralPatternWithComputedProperties = 512,
|
||||
ReverseMapped = 1024,
|
||||
JsxAttributes = 2048,
|
||||
JSLiteral = 4096,
|
||||
FreshLiteral = 8192,
|
||||
ArrayLiteral = 16384,
|
||||
PrimitiveUnion = 32768,
|
||||
ContainsWideningType = 65536,
|
||||
ContainsObjectOrArrayLiteral = 131072,
|
||||
NonInferrableType = 262144,
|
||||
CouldContainTypeVariablesComputed = 524288,
|
||||
CouldContainTypeVariables = 1048576,
|
||||
MembersResolved = 2097152,
|
||||
ClassOrInterface = 3,
|
||||
RequiresWidening = 196608,
|
||||
PropagatingFlags = 458752,
|
||||
InstantiatedMapped = 96,
|
||||
InstantiationExpressionType = 16777216,
|
||||
SingleSignatureType = 33554432,
|
||||
ObjectTypeKindMask = 50332991,
|
||||
ContainsSpread = 4194304,
|
||||
ObjectRestType = 8388608,
|
||||
IsClassInstanceClone = 67108864,
|
||||
IdenticalBaseTypeCalculated = 134217728,
|
||||
IdenticalBaseTypeExists = 268435456,
|
||||
UnresolvedMembers = 536870912,
|
||||
FromTypeNode = 1073741824,
|
||||
IsGenericTypeComputed = 4194304,
|
||||
IsGenericObjectType = 8388608,
|
||||
IsGenericIndexType = 16777216,
|
||||
IsGenericType = 25165824,
|
||||
ContainsIntersections = 33554432,
|
||||
IsUnknownLikeUnionComputed = 67108864,
|
||||
IsUnknownLikeUnion = 134217728,
|
||||
IsNeverIntersectionComputed = 33554432,
|
||||
IsNeverIntersection = 67108864,
|
||||
IsConstrainedTypeVariable = 134217728
|
||||
}
|
||||
//# sourceMappingURL=objectFlags.enum.d.ts.map
|
||||
Reference in New Issue
Block a user