WIP: bootstrap and partial real Solana watcher implementation
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
import * as util from "../core/util.js";
|
||||
const error = () => {
|
||||
const Sizable = {
|
||||
string: { unit: "字元", verb: "擁有" },
|
||||
file: { unit: "位元組", verb: "擁有" },
|
||||
array: { unit: "項目", verb: "擁有" },
|
||||
set: { unit: "項目", verb: "擁有" },
|
||||
};
|
||||
function getSizing(origin) {
|
||||
return Sizable[origin] ?? null;
|
||||
}
|
||||
const FormatDictionary = {
|
||||
regex: "輸入",
|
||||
email: "郵件地址",
|
||||
url: "URL",
|
||||
emoji: "emoji",
|
||||
uuid: "UUID",
|
||||
uuidv4: "UUIDv4",
|
||||
uuidv6: "UUIDv6",
|
||||
nanoid: "nanoid",
|
||||
guid: "GUID",
|
||||
cuid: "cuid",
|
||||
cuid2: "cuid2",
|
||||
ulid: "ULID",
|
||||
xid: "XID",
|
||||
ksuid: "KSUID",
|
||||
datetime: "ISO 日期時間",
|
||||
date: "ISO 日期",
|
||||
time: "ISO 時間",
|
||||
duration: "ISO 期間",
|
||||
ipv4: "IPv4 位址",
|
||||
ipv6: "IPv6 位址",
|
||||
cidrv4: "IPv4 範圍",
|
||||
cidrv6: "IPv6 範圍",
|
||||
base64: "base64 編碼字串",
|
||||
base64url: "base64url 編碼字串",
|
||||
json_string: "JSON 字串",
|
||||
e164: "E.164 數值",
|
||||
jwt: "JWT",
|
||||
template_literal: "輸入",
|
||||
};
|
||||
const TypeDictionary = {
|
||||
nan: "NaN",
|
||||
};
|
||||
return (issue) => {
|
||||
switch (issue.code) {
|
||||
case "invalid_type": {
|
||||
const expected = TypeDictionary[issue.expected] ?? issue.expected;
|
||||
const receivedType = util.parsedType(issue.input);
|
||||
const received = TypeDictionary[receivedType] ?? receivedType;
|
||||
if (/^[A-Z]/.test(issue.expected)) {
|
||||
return `無效的輸入值:預期為 instanceof ${issue.expected},但收到 ${received}`;
|
||||
}
|
||||
return `無效的輸入值:預期為 ${expected},但收到 ${received}`;
|
||||
}
|
||||
case "invalid_value":
|
||||
if (issue.values.length === 1)
|
||||
return `無效的輸入值:預期為 ${util.stringifyPrimitive(issue.values[0])}`;
|
||||
return `無效的選項:預期為以下其中之一 ${util.joinValues(issue.values, "|")}`;
|
||||
case "too_big": {
|
||||
const adj = issue.inclusive ? "<=" : "<";
|
||||
const sizing = getSizing(issue.origin);
|
||||
if (sizing)
|
||||
return `數值過大:預期 ${issue.origin ?? "值"} 應為 ${adj}${issue.maximum.toString()} ${sizing.unit ?? "個元素"}`;
|
||||
return `數值過大:預期 ${issue.origin ?? "值"} 應為 ${adj}${issue.maximum.toString()}`;
|
||||
}
|
||||
case "too_small": {
|
||||
const adj = issue.inclusive ? ">=" : ">";
|
||||
const sizing = getSizing(issue.origin);
|
||||
if (sizing) {
|
||||
return `數值過小:預期 ${issue.origin} 應為 ${adj}${issue.minimum.toString()} ${sizing.unit}`;
|
||||
}
|
||||
return `數值過小:預期 ${issue.origin} 應為 ${adj}${issue.minimum.toString()}`;
|
||||
}
|
||||
case "invalid_format": {
|
||||
const _issue = issue;
|
||||
if (_issue.format === "starts_with") {
|
||||
return `無效的字串:必須以 "${_issue.prefix}" 開頭`;
|
||||
}
|
||||
if (_issue.format === "ends_with")
|
||||
return `無效的字串:必須以 "${_issue.suffix}" 結尾`;
|
||||
if (_issue.format === "includes")
|
||||
return `無效的字串:必須包含 "${_issue.includes}"`;
|
||||
if (_issue.format === "regex")
|
||||
return `無效的字串:必須符合格式 ${_issue.pattern}`;
|
||||
return `無效的 ${FormatDictionary[_issue.format] ?? issue.format}`;
|
||||
}
|
||||
case "not_multiple_of":
|
||||
return `無效的數字:必須為 ${issue.divisor} 的倍數`;
|
||||
case "unrecognized_keys":
|
||||
return `無法識別的鍵值${issue.keys.length > 1 ? "們" : ""}:${util.joinValues(issue.keys, "、")}`;
|
||||
case "invalid_key":
|
||||
return `${issue.origin} 中有無效的鍵值`;
|
||||
case "invalid_union":
|
||||
return "無效的輸入值";
|
||||
case "invalid_element":
|
||||
return `${issue.origin} 中有無效的值`;
|
||||
default:
|
||||
return `無效的輸入值`;
|
||||
}
|
||||
};
|
||||
};
|
||||
export default function () {
|
||||
return {
|
||||
localeError: error(),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
{
|
||||
"name": "@eslint-community/eslint-utils",
|
||||
"version": "4.10.1",
|
||||
"description": "Utilities for ESLint plugins.",
|
||||
"keywords": [
|
||||
"eslint"
|
||||
],
|
||||
"homepage": "https://github.com/eslint-community/eslint-utils#readme",
|
||||
"bugs": {
|
||||
"url": "https://github.com/eslint-community/eslint-utils/issues"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/eslint-community/eslint-utils"
|
||||
},
|
||||
"license": "MIT",
|
||||
"author": "Toru Nagashima",
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./index.mjs",
|
||||
"require": "./index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"main": "index",
|
||||
"module": "index.mjs",
|
||||
"files": [
|
||||
"index.*"
|
||||
],
|
||||
"scripts": {
|
||||
"prebuild": "npm run -s clean",
|
||||
"build": "npm run build:dts && npm run build:rollup",
|
||||
"build:dts": "tsc -p tsconfig.build.json",
|
||||
"build:rollup": "rollup -c",
|
||||
"clean": "rimraf .nyc_output coverage index.* dist",
|
||||
"coverage": "opener ./coverage/lcov-report/index.html",
|
||||
"docs:build": "vitepress build docs",
|
||||
"docs:watch": "vitepress dev docs",
|
||||
"format": "npm run -s format:prettier -- --write",
|
||||
"format:prettier": "prettier .",
|
||||
"format:check": "npm run -s format:prettier -- --check",
|
||||
"lint:eslint": "eslint .",
|
||||
"lint:format": "npm run -s format:check",
|
||||
"lint:installed-check": "installed-check -v -i installed-check -i npm-run-all2 -i knip -i rollup-plugin-dts",
|
||||
"lint:knip": "knip",
|
||||
"lint": "run-p lint:*",
|
||||
"test-coverage": "c8 mocha --reporter dot \"test/*.mjs\"",
|
||||
"test": "mocha --reporter dot \"test/*.mjs\"",
|
||||
"preversion": "npm run test-coverage && npm run -s build",
|
||||
"postversion": "git push && git push --tags",
|
||||
"prewatch": "npm run -s clean",
|
||||
"watch": "warun \"{src,test}/**/*.mjs\" -- npm run -s test:mocha"
|
||||
},
|
||||
"dependencies": {
|
||||
"eslint-visitor-keys": "^3.4.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint-community/eslint-plugin-eslint-comments": "^4.5.0",
|
||||
"@types/eslint": "^9.6.1",
|
||||
"@types/estree": "^1.0.8",
|
||||
"@types/node": "^20.19.43",
|
||||
"@typescript-eslint/parser": "^5.62.0",
|
||||
"@typescript-eslint/types": "^5.62.0",
|
||||
"c8": "^8.0.1",
|
||||
"dot-prop": "^7.2.0",
|
||||
"eslint": "^8.57.1",
|
||||
"eslint-config-prettier": "^10.1.8",
|
||||
"eslint-plugin-n": "^15.7.0",
|
||||
"eslint-plugin-prettier": "^4.2.5",
|
||||
"globals": "^13.24.0",
|
||||
"installed-check": "^8.0.1",
|
||||
"knip": "^5.80.2",
|
||||
"mocha": "^9.2.2",
|
||||
"npm-run-all2": "^6.2.6",
|
||||
"opener": "^1.5.2",
|
||||
"prettier": "2.8.8",
|
||||
"rimraf": "^3.0.2",
|
||||
"rollup": "^2.79.2",
|
||||
"rollup-plugin-dts": "^4.2.3",
|
||||
"rollup-plugin-sourcemaps": "^0.6.3",
|
||||
"semver": "^7.7.3",
|
||||
"typescript": "^4.9.5",
|
||||
"vitepress": "^1.6.4",
|
||||
"warun": "^1.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"eslint": "^6.0.0 || ^7.0.0 || >=8.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||
},
|
||||
"funding": "https://opencollective.com/eslint"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
| Suite | Browser | for + if | while + if | array join |
|
||||
| :--------- | :-------------------------------------- | ----------------: | ----------------: | ----------------: |
|
||||
| itar-long | Chrome 60.0.3112 (Windows 7 0.0.0) | *100.00% (±0.75%) | *99.20% (±0.98%) | 90.22% (±1.04%) |
|
||||
| itar-long | Chrome Mobile 55.0.2883 (Android 6.0.0) | *100.00% (±2.51%) | 98.56% (±2.31%) | 96.61% (±2.37%) |
|
||||
| itar-long | Edge 14.14393.0 (Windows 10 0.0.0) | 92.45% (±1.31%) | 83.30% (±1.72%) | *100.00% (±1.49%) |
|
||||
| itar-long | Firefox 54.0.0 (Windows 7 0.0.0) | *100.00% (±1.77%) | 97.53% (±1.90%) | 96.33% (±2.11%) |
|
||||
| itar-long | IE 10.0.0 (Windows 7 0.0.0) | 81.35% (±1.98%) | 75.32% (±1.89%) | *100.00% (±2.29%) |
|
||||
| itar-long | IE 11.0.0 (Windows 7 0.0.0) | 76.13% (±0.96%) | 70.16% (±1.13%) | *100.00% (±1.79%) |
|
||||
| itar-long | IE 9.0.0 (Windows 7 0.0.0) | 75.77% (±0.59%) | 71.20% (±0.55%) | *100.00% (±0.66%) |
|
||||
| itar-long | Mobile Safari 10.0.0 (iOS 10.3.0) | 97.10% (±0.61%) | 92.65% (±2.49%) | *100.00% (±1.17%) |
|
||||
| itar-long | Safari 10.0.1 (Mac OS X 10.12.1) | 94.36% (±1.37%) | 93.23% (±1.32%) | *100.00% (±1.28%) |
|
||||
| itar-short | Chrome 60.0.3112 (Windows 7 0.0.0) | *99.77% (±1.05%) | *100.00% (±0.80%) | 85.03% (±0.85%) |
|
||||
| itar-short | Chrome Mobile 55.0.2883 (Android 6.0.0) | *100.00% (±3.97%) | 95.54% (±2.84%) | 94.01% (±1.90%) |
|
||||
| itar-short | Edge 14.14393.0 (Windows 10 0.0.0) | *100.00% (±1.56%) | 96.83% (±1.49%) | *99.74% (±1.27%) |
|
||||
| itar-short | Firefox 54.0.0 (Windows 7 0.0.0) | 97.77% (±1.64%) | *100.00% (±1.38%) | 85.84% (±1.31%) |
|
||||
| itar-short | IE 10.0.0 (Windows 7 0.0.0) | 88.51% (±2.45%) | 79.82% (±1.94%) | *100.00% (±2.55%) |
|
||||
| itar-short | IE 11.0.0 (Windows 7 0.0.0) | 97.55% (±1.70%) | 92.95% (±1.44%) | *100.00% (±1.57%) |
|
||||
| itar-short | IE 9.0.0 (Windows 7 0.0.0) | 84.03% (±1.14%) | 80.27% (±1.07%) | *100.00% (±1.56%) |
|
||||
| itar-short | Mobile Safari 10.0.0 (iOS 10.3.0) | 88.94% (±2.82%) | *100.00% (±1.25%) | 99.56% (±2.31%) |
|
||||
| itar-short | Safari 10.0.1 (Mac OS X 10.12.1) | *100.00% (±1.54%) | 96.94% (±1.19%) | *99.75% (±1.36%) |
|
||||
@@ -0,0 +1,39 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Doc = void 0;
|
||||
class Doc {
|
||||
constructor(args = []) {
|
||||
this.content = [];
|
||||
this.indent = 0;
|
||||
if (this)
|
||||
this.args = args;
|
||||
}
|
||||
indented(fn) {
|
||||
this.indent += 1;
|
||||
fn(this);
|
||||
this.indent -= 1;
|
||||
}
|
||||
write(arg) {
|
||||
if (typeof arg === "function") {
|
||||
arg(this, { execution: "sync" });
|
||||
arg(this, { execution: "async" });
|
||||
return;
|
||||
}
|
||||
const content = arg;
|
||||
const lines = content.split("\n").filter((x) => x);
|
||||
const minIndent = Math.min(...lines.map((x) => x.length - x.trimStart().length));
|
||||
const dedented = lines.map((x) => x.slice(minIndent)).map((x) => " ".repeat(this.indent * 2) + x);
|
||||
for (const line of dedented) {
|
||||
this.content.push(line);
|
||||
}
|
||||
}
|
||||
compile() {
|
||||
const F = Function;
|
||||
const args = this?.args;
|
||||
const content = this?.content ?? [``];
|
||||
const lines = [...content.map((x) => ` ${x}`)];
|
||||
// console.log(lines.join("\n"));
|
||||
return new F(...args, lines.join("\n"));
|
||||
}
|
||||
}
|
||||
exports.Doc = Doc;
|
||||
@@ -0,0 +1,347 @@
|
||||
/**
|
||||
* @fileoverview A rule to suggest using template literals instead of string concatenation.
|
||||
* @author Toru Nagashima
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const astUtils = require("./utils/ast-utils");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Checks whether or not a given node is a concatenation.
|
||||
* @param {ASTNode} node A node to check.
|
||||
* @returns {boolean} `true` if the node is a concatenation.
|
||||
*/
|
||||
function isConcatenation(node) {
|
||||
return node.type === "BinaryExpression" && node.operator === "+";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the top binary expression node for concatenation in parents of a given node.
|
||||
* @param {ASTNode} node A node to get.
|
||||
* @returns {ASTNode} the top binary expression node in parents of a given node.
|
||||
*/
|
||||
function getTopConcatBinaryExpression(node) {
|
||||
let currentNode = node;
|
||||
|
||||
while (isConcatenation(currentNode.parent)) {
|
||||
currentNode = currentNode.parent;
|
||||
}
|
||||
return currentNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not a node contains a string literal with an octal or non-octal decimal escape sequence
|
||||
* @param {ASTNode} node A node to check
|
||||
* @returns {boolean} `true` if at least one string literal within the node contains
|
||||
* an octal or non-octal decimal escape sequence
|
||||
*/
|
||||
function hasOctalOrNonOctalDecimalEscapeSequence(node) {
|
||||
if (isConcatenation(node)) {
|
||||
return (
|
||||
hasOctalOrNonOctalDecimalEscapeSequence(node.left) ||
|
||||
hasOctalOrNonOctalDecimalEscapeSequence(node.right)
|
||||
);
|
||||
}
|
||||
|
||||
// No need to check TemplateLiterals – would throw parsing error
|
||||
if (node.type === "Literal" && typeof node.value === "string") {
|
||||
return astUtils.hasOctalOrNonOctalDecimalEscapeSequence(node.raw);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not a given binary expression has string literals.
|
||||
* @param {ASTNode} node A node to check.
|
||||
* @returns {boolean} `true` if the node has string literals.
|
||||
*/
|
||||
function hasStringLiteral(node) {
|
||||
if (isConcatenation(node)) {
|
||||
// `left` is deeper than `right` normally.
|
||||
return hasStringLiteral(node.right) || hasStringLiteral(node.left);
|
||||
}
|
||||
return astUtils.isStringLiteral(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not a given binary expression has non string literals.
|
||||
* @param {ASTNode} node A node to check.
|
||||
* @returns {boolean} `true` if the node has non string literals.
|
||||
*/
|
||||
function hasNonStringLiteral(node) {
|
||||
if (isConcatenation(node)) {
|
||||
// `left` is deeper than `right` normally.
|
||||
return (
|
||||
hasNonStringLiteral(node.right) || hasNonStringLiteral(node.left)
|
||||
);
|
||||
}
|
||||
return !astUtils.isStringLiteral(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a given node will start with a template curly expression (`${}`) when being converted to a template literal.
|
||||
* @param {ASTNode} node The node that will be fixed to a template literal
|
||||
* @returns {boolean} `true` if the node will start with a template curly.
|
||||
*/
|
||||
function startsWithTemplateCurly(node) {
|
||||
if (node.type === "BinaryExpression") {
|
||||
return startsWithTemplateCurly(node.left);
|
||||
}
|
||||
if (node.type === "TemplateLiteral") {
|
||||
return (
|
||||
node.expressions.length &&
|
||||
node.quasis.length &&
|
||||
node.quasis[0].range[0] === node.quasis[0].range[1]
|
||||
);
|
||||
}
|
||||
return node.type !== "Literal" || typeof node.value !== "string";
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a given node end with a template curly expression (`${}`) when being converted to a template literal.
|
||||
* @param {ASTNode} node The node that will be fixed to a template literal
|
||||
* @returns {boolean} `true` if the node will end with a template curly.
|
||||
*/
|
||||
function endsWithTemplateCurly(node) {
|
||||
if (node.type === "BinaryExpression") {
|
||||
return startsWithTemplateCurly(node.right);
|
||||
}
|
||||
if (node.type === "TemplateLiteral") {
|
||||
return (
|
||||
node.expressions.length &&
|
||||
node.quasis.length &&
|
||||
node.quasis.at(-1).range[0] === node.quasis.at(-1).range[1]
|
||||
);
|
||||
}
|
||||
return node.type !== "Literal" || typeof node.value !== "string";
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../types').Rule.RuleModule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "suggestion",
|
||||
|
||||
docs: {
|
||||
description:
|
||||
"Require template literals instead of string concatenation",
|
||||
recommended: false,
|
||||
frozen: true,
|
||||
url: "https://eslint.org/docs/latest/rules/prefer-template",
|
||||
},
|
||||
|
||||
schema: [],
|
||||
fixable: "code",
|
||||
|
||||
messages: {
|
||||
unexpectedStringConcatenation: "Unexpected string concatenation.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const sourceCode = context.sourceCode;
|
||||
let done = Object.create(null);
|
||||
|
||||
/**
|
||||
* Gets the non-token text between two nodes, ignoring any other tokens that appear between the two tokens.
|
||||
* @param {ASTNode} node1 The first node
|
||||
* @param {ASTNode} node2 The second node
|
||||
* @returns {string} The text between the nodes, excluding other tokens
|
||||
*/
|
||||
function getTextBetween(node1, node2) {
|
||||
const allTokens = [node1]
|
||||
.concat(sourceCode.getTokensBetween(node1, node2))
|
||||
.concat(node2);
|
||||
const sourceText = sourceCode.getText();
|
||||
|
||||
return allTokens
|
||||
.slice(0, -1)
|
||||
.reduce(
|
||||
(accumulator, token, index) =>
|
||||
accumulator +
|
||||
sourceText.slice(
|
||||
token.range[1],
|
||||
allTokens[index + 1].range[0],
|
||||
),
|
||||
"",
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a template literal form of the given node.
|
||||
* @param {ASTNode} currentNode A node that should be converted to a template literal
|
||||
* @param {string} textBeforeNode Text that should appear before the node
|
||||
* @param {string} textAfterNode Text that should appear after the node
|
||||
* @returns {string} A string form of this node, represented as a template literal
|
||||
*/
|
||||
function getTemplateLiteral(
|
||||
currentNode,
|
||||
textBeforeNode,
|
||||
textAfterNode,
|
||||
) {
|
||||
if (
|
||||
currentNode.type === "Literal" &&
|
||||
typeof currentNode.value === "string"
|
||||
) {
|
||||
/*
|
||||
* If the current node is a string literal, escape any instances of ${ or ` to prevent them from being interpreted
|
||||
* as a template placeholder. However, if the code already contains a backslash before the ${ or `
|
||||
* for some reason, don't add another backslash, because that would change the meaning of the code (it would cause
|
||||
* an actual backslash character to appear before the dollar sign).
|
||||
*/
|
||||
return `\`${currentNode.raw
|
||||
.slice(1, -1)
|
||||
.replace(/(?<!\\)\\*(\$\{|`)/gu, matched => {
|
||||
if (matched.lastIndexOf("\\") % 2) {
|
||||
return `\\${matched}`;
|
||||
}
|
||||
return matched;
|
||||
|
||||
// Unescape any quotes that appear in the original Literal that no longer need to be escaped.
|
||||
})
|
||||
.replace(
|
||||
new RegExp(`\\\\${currentNode.raw[0]}`, "gu"),
|
||||
currentNode.raw[0],
|
||||
)}\``;
|
||||
}
|
||||
|
||||
if (currentNode.type === "TemplateLiteral") {
|
||||
return sourceCode.getText(currentNode);
|
||||
}
|
||||
|
||||
if (isConcatenation(currentNode) && hasStringLiteral(currentNode)) {
|
||||
const plusSign = sourceCode.getFirstTokenBetween(
|
||||
currentNode.left,
|
||||
currentNode.right,
|
||||
token => token.value === "+",
|
||||
);
|
||||
const textBeforePlus = getTextBetween(
|
||||
currentNode.left,
|
||||
plusSign,
|
||||
);
|
||||
const textAfterPlus = getTextBetween(
|
||||
plusSign,
|
||||
currentNode.right,
|
||||
);
|
||||
const leftEndsWithCurly = endsWithTemplateCurly(
|
||||
currentNode.left,
|
||||
);
|
||||
const rightStartsWithCurly = startsWithTemplateCurly(
|
||||
currentNode.right,
|
||||
);
|
||||
|
||||
if (leftEndsWithCurly) {
|
||||
// If the left side of the expression ends with a template curly, add the extra text to the end of the curly bracket.
|
||||
// `foo${bar}` /* comment */ + 'baz' --> `foo${bar /* comment */ }${baz}`
|
||||
return (
|
||||
getTemplateLiteral(
|
||||
currentNode.left,
|
||||
textBeforeNode,
|
||||
textBeforePlus + textAfterPlus,
|
||||
).slice(0, -1) +
|
||||
getTemplateLiteral(
|
||||
currentNode.right,
|
||||
null,
|
||||
textAfterNode,
|
||||
).slice(1)
|
||||
);
|
||||
}
|
||||
if (rightStartsWithCurly) {
|
||||
// Otherwise, if the right side of the expression starts with a template curly, add the text there.
|
||||
// 'foo' /* comment */ + `${bar}baz` --> `foo${ /* comment */ bar}baz`
|
||||
return (
|
||||
getTemplateLiteral(
|
||||
currentNode.left,
|
||||
textBeforeNode,
|
||||
null,
|
||||
).slice(0, -1) +
|
||||
getTemplateLiteral(
|
||||
currentNode.right,
|
||||
textBeforePlus + textAfterPlus,
|
||||
textAfterNode,
|
||||
).slice(1)
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Otherwise, these nodes should not be combined into a template curly, since there is nowhere to put
|
||||
* the text between them.
|
||||
*/
|
||||
return `${getTemplateLiteral(currentNode.left, textBeforeNode, null)}${textBeforePlus}+${textAfterPlus}${getTemplateLiteral(currentNode.right, textAfterNode, null)}`;
|
||||
}
|
||||
|
||||
return `\`\${${textBeforeNode || ""}${sourceCode.getText(currentNode)}${textAfterNode || ""}}\``;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a fixer object that converts a non-string binary expression to a template literal
|
||||
* @param {SourceCodeFixer} fixer The fixer object
|
||||
* @param {ASTNode} node A node that should be converted to a template literal
|
||||
* @returns {Object} A fix for this binary expression
|
||||
*/
|
||||
function fixNonStringBinaryExpression(fixer, node) {
|
||||
const topBinaryExpr = getTopConcatBinaryExpression(node.parent);
|
||||
|
||||
if (hasOctalOrNonOctalDecimalEscapeSequence(topBinaryExpr)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return fixer.replaceText(
|
||||
topBinaryExpr,
|
||||
getTemplateLiteral(topBinaryExpr, null, null),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports if a given node is string concatenation with non string literals.
|
||||
* @param {ASTNode} node A node to check.
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkForStringConcat(node) {
|
||||
if (
|
||||
!astUtils.isStringLiteral(node) ||
|
||||
!isConcatenation(node.parent)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const topBinaryExpr = getTopConcatBinaryExpression(node.parent);
|
||||
|
||||
// Checks whether or not this node had been checked already.
|
||||
if (done[topBinaryExpr.range[0]]) {
|
||||
return;
|
||||
}
|
||||
done[topBinaryExpr.range[0]] = true;
|
||||
|
||||
if (hasNonStringLiteral(topBinaryExpr)) {
|
||||
context.report({
|
||||
node: topBinaryExpr,
|
||||
messageId: "unexpectedStringConcatenation",
|
||||
fix: fixer => fixNonStringBinaryExpression(fixer, node),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
Program() {
|
||||
done = Object.create(null);
|
||||
},
|
||||
|
||||
Literal: checkForStringConcat,
|
||||
TemplateLiteral: checkForStringConcat,
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
export declare enum ModuleResolutionKind {
|
||||
Unknown = 0,
|
||||
Classic = 1,
|
||||
Node10 = 2,
|
||||
Node16 = 3,
|
||||
NodeNext = 99,
|
||||
Bundler = 100
|
||||
}
|
||||
//# sourceMappingURL=moduleResolutionKind.enum.d.ts.map
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"root": true,
|
||||
|
||||
"extends": "@ljharb/eslint-config/node/0.4",
|
||||
|
||||
"rules": {
|
||||
"array-element-newline": 0,
|
||||
"complexity": 0,
|
||||
"func-style": [2, "declaration"],
|
||||
"max-lines-per-function": 0,
|
||||
"max-nested-callbacks": 1,
|
||||
"max-statements-per-line": 1,
|
||||
"max-statements": 0,
|
||||
"multiline-comment-style": 0,
|
||||
"no-continue": 1,
|
||||
"no-param-reassign": 1,
|
||||
"no-restricted-syntax": 1,
|
||||
"object-curly-newline": 0,
|
||||
},
|
||||
|
||||
"overrides": [
|
||||
{
|
||||
"files": "test/**",
|
||||
"rules": {
|
||||
"camelcase": 0,
|
||||
},
|
||||
},
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
import { FilterExpression, FilterExpressionKind, QueryFilterObject, TopLevelFilterExpression, and, code, exactRegex, exclude, exprInterpreter, filterVitePlugins, id, importerId, include, interpreter, interpreterImpl, makeIdFiltersToMatchWithQuery, moduleType, not, or, prefixRegex, queries, query } from "./filter/index.mjs";
|
||||
export { FilterExpression, FilterExpressionKind, QueryFilterObject, TopLevelFilterExpression, and, code, exactRegex, exclude, exprInterpreter, filterVitePlugins, id, importerId, include, interpreter, interpreterImpl, makeIdFiltersToMatchWithQuery, moduleType, not, or, prefixRegex, queries, query };
|
||||
@@ -0,0 +1,52 @@
|
||||
// Code generated by Herebyfile.mjs generate:enums from internal/checker/types.go. DO NOT EDIT.
|
||||
export var ObjectFlags;
|
||||
(function (ObjectFlags) {
|
||||
ObjectFlags[ObjectFlags["None"] = 0] = "None";
|
||||
ObjectFlags[ObjectFlags["Class"] = 1] = "Class";
|
||||
ObjectFlags[ObjectFlags["Interface"] = 2] = "Interface";
|
||||
ObjectFlags[ObjectFlags["Reference"] = 4] = "Reference";
|
||||
ObjectFlags[ObjectFlags["Tuple"] = 8] = "Tuple";
|
||||
ObjectFlags[ObjectFlags["Anonymous"] = 16] = "Anonymous";
|
||||
ObjectFlags[ObjectFlags["Mapped"] = 32] = "Mapped";
|
||||
ObjectFlags[ObjectFlags["Instantiated"] = 64] = "Instantiated";
|
||||
ObjectFlags[ObjectFlags["ObjectLiteral"] = 128] = "ObjectLiteral";
|
||||
ObjectFlags[ObjectFlags["EvolvingArray"] = 256] = "EvolvingArray";
|
||||
ObjectFlags[ObjectFlags["ObjectLiteralPatternWithComputedProperties"] = 512] = "ObjectLiteralPatternWithComputedProperties";
|
||||
ObjectFlags[ObjectFlags["ReverseMapped"] = 1024] = "ReverseMapped";
|
||||
ObjectFlags[ObjectFlags["JsxAttributes"] = 2048] = "JsxAttributes";
|
||||
ObjectFlags[ObjectFlags["JSLiteral"] = 4096] = "JSLiteral";
|
||||
ObjectFlags[ObjectFlags["FreshLiteral"] = 8192] = "FreshLiteral";
|
||||
ObjectFlags[ObjectFlags["ArrayLiteral"] = 16384] = "ArrayLiteral";
|
||||
ObjectFlags[ObjectFlags["PrimitiveUnion"] = 32768] = "PrimitiveUnion";
|
||||
ObjectFlags[ObjectFlags["ContainsWideningType"] = 65536] = "ContainsWideningType";
|
||||
ObjectFlags[ObjectFlags["ContainsObjectOrArrayLiteral"] = 131072] = "ContainsObjectOrArrayLiteral";
|
||||
ObjectFlags[ObjectFlags["NonInferrableType"] = 262144] = "NonInferrableType";
|
||||
ObjectFlags[ObjectFlags["CouldContainTypeVariablesComputed"] = 524288] = "CouldContainTypeVariablesComputed";
|
||||
ObjectFlags[ObjectFlags["CouldContainTypeVariables"] = 1048576] = "CouldContainTypeVariables";
|
||||
ObjectFlags[ObjectFlags["MembersResolved"] = 2097152] = "MembersResolved";
|
||||
ObjectFlags[ObjectFlags["ClassOrInterface"] = 3] = "ClassOrInterface";
|
||||
ObjectFlags[ObjectFlags["RequiresWidening"] = 196608] = "RequiresWidening";
|
||||
ObjectFlags[ObjectFlags["PropagatingFlags"] = 458752] = "PropagatingFlags";
|
||||
ObjectFlags[ObjectFlags["InstantiatedMapped"] = 96] = "InstantiatedMapped";
|
||||
ObjectFlags[ObjectFlags["InstantiationExpressionType"] = 16777216] = "InstantiationExpressionType";
|
||||
ObjectFlags[ObjectFlags["SingleSignatureType"] = 33554432] = "SingleSignatureType";
|
||||
ObjectFlags[ObjectFlags["ObjectTypeKindMask"] = 50332991] = "ObjectTypeKindMask";
|
||||
ObjectFlags[ObjectFlags["ContainsSpread"] = 4194304] = "ContainsSpread";
|
||||
ObjectFlags[ObjectFlags["ObjectRestType"] = 8388608] = "ObjectRestType";
|
||||
ObjectFlags[ObjectFlags["IsClassInstanceClone"] = 67108864] = "IsClassInstanceClone";
|
||||
ObjectFlags[ObjectFlags["IdenticalBaseTypeCalculated"] = 134217728] = "IdenticalBaseTypeCalculated";
|
||||
ObjectFlags[ObjectFlags["IdenticalBaseTypeExists"] = 268435456] = "IdenticalBaseTypeExists";
|
||||
ObjectFlags[ObjectFlags["UnresolvedMembers"] = 536870912] = "UnresolvedMembers";
|
||||
ObjectFlags[ObjectFlags["FromTypeNode"] = 1073741824] = "FromTypeNode";
|
||||
ObjectFlags[ObjectFlags["IsGenericTypeComputed"] = 4194304] = "IsGenericTypeComputed";
|
||||
ObjectFlags[ObjectFlags["IsGenericObjectType"] = 8388608] = "IsGenericObjectType";
|
||||
ObjectFlags[ObjectFlags["IsGenericIndexType"] = 16777216] = "IsGenericIndexType";
|
||||
ObjectFlags[ObjectFlags["IsGenericType"] = 25165824] = "IsGenericType";
|
||||
ObjectFlags[ObjectFlags["ContainsIntersections"] = 33554432] = "ContainsIntersections";
|
||||
ObjectFlags[ObjectFlags["IsUnknownLikeUnionComputed"] = 67108864] = "IsUnknownLikeUnionComputed";
|
||||
ObjectFlags[ObjectFlags["IsUnknownLikeUnion"] = 134217728] = "IsUnknownLikeUnion";
|
||||
ObjectFlags[ObjectFlags["IsNeverIntersectionComputed"] = 33554432] = "IsNeverIntersectionComputed";
|
||||
ObjectFlags[ObjectFlags["IsNeverIntersection"] = 67108864] = "IsNeverIntersection";
|
||||
ObjectFlags[ObjectFlags["IsConstrainedTypeVariable"] = 134217728] = "IsConstrainedTypeVariable";
|
||||
})(ObjectFlags || (ObjectFlags = {}));
|
||||
//# sourceMappingURL=objectFlags.enum.js.map
|
||||
@@ -0,0 +1,16 @@
|
||||
import type { TSESLint } from '@typescript-eslint/utils';
|
||||
import type { RuleListener } from '@typescript-eslint/utils/eslint-utils';
|
||||
type Prefer = 'no-type-imports' | 'type-imports';
|
||||
type FixStyle = 'inline-type-imports' | 'separate-type-imports';
|
||||
export type Options = [
|
||||
{
|
||||
disallowTypeAnnotations?: boolean;
|
||||
fixStyle?: FixStyle;
|
||||
prefer?: Prefer;
|
||||
}
|
||||
];
|
||||
export type MessageIds = 'avoidImportType' | 'noImportTypeAnnotations' | 'someImportsAreOnlyTypes' | 'typeOverValue';
|
||||
declare const _default: TSESLint.RuleModule<MessageIds, Options, import("../../rules").ESLintPluginDocs, RuleListener> & {
|
||||
name: string;
|
||||
};
|
||||
export default _default;
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025 pinojs contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,154 @@
|
||||
'use strict';
|
||||
|
||||
const EventEmitter = require('events');
|
||||
|
||||
const startObject = Ctr =>
|
||||
function () {
|
||||
if (this.done) {
|
||||
this.done = false;
|
||||
} else {
|
||||
this.stack.push(this.current, this.key);
|
||||
}
|
||||
this.current = new Ctr();
|
||||
this.key = null;
|
||||
};
|
||||
|
||||
class Assembler extends EventEmitter {
|
||||
static connectTo(stream, options) {
|
||||
return new Assembler(options).connectTo(stream);
|
||||
}
|
||||
|
||||
constructor(options) {
|
||||
super();
|
||||
this.stack = [];
|
||||
this.current = this.key = null;
|
||||
this.done = true;
|
||||
if (options) {
|
||||
this.reviver = typeof options.reviver == 'function' && options.reviver;
|
||||
if (this.reviver) {
|
||||
this.stringValue = this._saveValue = this._saveValueWithReviver;
|
||||
}
|
||||
if (options.numberAsString) {
|
||||
this.numberValue = this.stringValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
connectTo(stream) {
|
||||
stream.on('data', chunk => {
|
||||
if (this[chunk.name]) {
|
||||
this[chunk.name](chunk.value);
|
||||
if (this.done) this.emit('done', this);
|
||||
}
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
get depth() {
|
||||
return (this.stack.length >> 1) + (this.done ? 0 : 1);
|
||||
}
|
||||
|
||||
get path() {
|
||||
const path = [];
|
||||
for (let i = 0; i < this.stack.length; i += 2) {
|
||||
const key = this.stack[i + 1];
|
||||
path.push(key === null ? this.stack[i].length : key);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
dropToLevel(level) {
|
||||
if (level < this.depth) {
|
||||
if (level) {
|
||||
const index = (level - 1) << 1;
|
||||
this.current = this.stack[index];
|
||||
this.key = this.stack[index + 1];
|
||||
this.stack.splice(index);
|
||||
} else {
|
||||
this.stack = [];
|
||||
this.current = this.key = null;
|
||||
this.done = true;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
consume(chunk) {
|
||||
this[chunk.name] && this[chunk.name](chunk.value);
|
||||
return this;
|
||||
}
|
||||
|
||||
keyValue(value) {
|
||||
this.key = value;
|
||||
}
|
||||
|
||||
//stringValue() - aliased below to _saveValue()
|
||||
|
||||
numberValue(value) {
|
||||
this._saveValue(parseFloat(value));
|
||||
}
|
||||
nullValue() {
|
||||
this._saveValue(null);
|
||||
}
|
||||
trueValue() {
|
||||
this._saveValue(true);
|
||||
}
|
||||
falseValue() {
|
||||
this._saveValue(false);
|
||||
}
|
||||
|
||||
//startObject() - assigned below
|
||||
|
||||
endObject() {
|
||||
if (this.stack.length) {
|
||||
const value = this.current;
|
||||
this.key = this.stack.pop();
|
||||
this.current = this.stack.pop();
|
||||
this._saveValue(value);
|
||||
} else {
|
||||
this.done = true;
|
||||
}
|
||||
}
|
||||
|
||||
//startArray() - assigned below
|
||||
//endArray() - aliased below to endObject()
|
||||
|
||||
_saveValue(value) {
|
||||
if (this.done) {
|
||||
this.current = value;
|
||||
} else {
|
||||
if (this.current instanceof Array) {
|
||||
this.current.push(value);
|
||||
} else {
|
||||
this.current[this.key] = value;
|
||||
this.key = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
_saveValueWithReviver(value) {
|
||||
if (this.done) {
|
||||
this.current = this.reviver('', value);
|
||||
} else {
|
||||
if (this.current instanceof Array) {
|
||||
value = this.reviver('' + this.current.length, value);
|
||||
this.current.push(value);
|
||||
if (value === undefined) {
|
||||
delete this.current[this.current.length - 1];
|
||||
}
|
||||
} else {
|
||||
value = this.reviver(this.key, value);
|
||||
if (value !== undefined) {
|
||||
this.current[this.key] = value;
|
||||
}
|
||||
this.key = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Assembler.prototype.stringValue = Assembler.prototype._saveValue;
|
||||
Assembler.prototype.startObject = startObject(Object);
|
||||
Assembler.prototype.startArray = startObject(Array);
|
||||
Assembler.prototype.endArray = Assembler.prototype.endObject;
|
||||
|
||||
module.exports = Assembler;
|
||||
@@ -0,0 +1,115 @@
|
||||
const { test } = require('node:test')
|
||||
const { strict: assert } = require('node:assert')
|
||||
const slowRedact = require('../index.js')
|
||||
|
||||
test('selective cloning shares references for non-redacted paths', () => {
|
||||
const sharedObject = { unchanged: 'data' }
|
||||
const obj = {
|
||||
toRedact: 'secret',
|
||||
shared: sharedObject,
|
||||
nested: {
|
||||
toRedact: 'secret2',
|
||||
shared: sharedObject
|
||||
}
|
||||
}
|
||||
|
||||
const redact = slowRedact({
|
||||
paths: ['toRedact', 'nested.toRedact'],
|
||||
serialize: false
|
||||
})
|
||||
|
||||
const result = redact(obj)
|
||||
|
||||
// Redacted values should be different
|
||||
assert.strictEqual(result.toRedact, '[REDACTED]')
|
||||
assert.strictEqual(result.nested.toRedact, '[REDACTED]')
|
||||
|
||||
// Non-redacted references should be shared (same object reference)
|
||||
assert.strictEqual(result.shared, obj.shared)
|
||||
assert.strictEqual(result.nested.shared, obj.nested.shared)
|
||||
|
||||
// The shared object should be the exact same reference
|
||||
assert.strictEqual(result.shared, sharedObject)
|
||||
assert.strictEqual(result.nested.shared, sharedObject)
|
||||
})
|
||||
|
||||
test('selective cloning works with arrays', () => {
|
||||
const sharedItem = { unchanged: 'data' }
|
||||
const obj = {
|
||||
items: [
|
||||
{ secret: 'hidden1', shared: sharedItem },
|
||||
{ secret: 'hidden2', shared: sharedItem },
|
||||
sharedItem
|
||||
]
|
||||
}
|
||||
|
||||
const redact = slowRedact({
|
||||
paths: ['items.*.secret'],
|
||||
serialize: false
|
||||
})
|
||||
|
||||
const result = redact(obj)
|
||||
|
||||
// Secrets should be redacted
|
||||
assert.strictEqual(result.items[0].secret, '[REDACTED]')
|
||||
assert.strictEqual(result.items[1].secret, '[REDACTED]')
|
||||
|
||||
// Shared references should be preserved where possible
|
||||
// Note: array items with secrets will be cloned, but their shared properties should still reference the original
|
||||
assert.strictEqual(result.items[0].shared, sharedItem)
|
||||
assert.strictEqual(result.items[1].shared, sharedItem)
|
||||
|
||||
// The third item gets cloned due to wildcard, but should have the same content
|
||||
assert.deepStrictEqual(result.items[2], sharedItem)
|
||||
// Note: Due to wildcard '*', all array items are cloned, even if they don't need redaction
|
||||
// This is still a significant optimization for object properties that aren't in wildcard paths
|
||||
})
|
||||
|
||||
test('selective cloning with no paths returns original object', () => {
|
||||
const obj = { data: 'unchanged' }
|
||||
const redact = slowRedact({
|
||||
paths: [],
|
||||
serialize: false
|
||||
})
|
||||
|
||||
const result = redact(obj)
|
||||
|
||||
// Should return the exact same object reference
|
||||
assert.strictEqual(result, obj)
|
||||
})
|
||||
|
||||
test('selective cloning performance - large objects with minimal redaction', () => {
|
||||
// Create a large object with mostly shared data
|
||||
const sharedData = { large: 'data'.repeat(1000) }
|
||||
const obj = {
|
||||
secret: 'hidden',
|
||||
shared1: sharedData,
|
||||
shared2: sharedData,
|
||||
nested: {
|
||||
secret: 'hidden2',
|
||||
shared3: sharedData,
|
||||
deep: {
|
||||
shared4: sharedData,
|
||||
moreShared: sharedData
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const redact = slowRedact({
|
||||
paths: ['secret', 'nested.secret'],
|
||||
serialize: false
|
||||
})
|
||||
|
||||
const result = redact(obj)
|
||||
|
||||
// Verify redaction worked
|
||||
assert.strictEqual(result.secret, '[REDACTED]')
|
||||
assert.strictEqual(result.nested.secret, '[REDACTED]')
|
||||
|
||||
// Verify shared references are preserved
|
||||
assert.strictEqual(result.shared1, sharedData)
|
||||
assert.strictEqual(result.shared2, sharedData)
|
||||
assert.strictEqual(result.nested.shared3, sharedData)
|
||||
assert.strictEqual(result.nested.deep.shared4, sharedData)
|
||||
assert.strictEqual(result.nested.deep.moreShared, sharedData)
|
||||
})
|
||||
@@ -0,0 +1,85 @@
|
||||
{{# def.definitions }}
|
||||
{{# def.errors }}
|
||||
{{# def.setupKeyword }}
|
||||
|
||||
{{## def._validateRef:_v:
|
||||
{{? it.opts.passContext }}
|
||||
{{=_v}}.call(this,
|
||||
{{??}}
|
||||
{{=_v}}(
|
||||
{{?}}
|
||||
{{=$data}}, {{# def.dataPath }}{{# def.passParentData }}, rootData)
|
||||
#}}
|
||||
|
||||
{{ var $async, $refCode; }}
|
||||
{{? $schema == '#' || $schema == '#/' }}
|
||||
{{
|
||||
if (it.isRoot) {
|
||||
$async = it.async;
|
||||
$refCode = 'validate';
|
||||
} else {
|
||||
$async = it.root.schema.$async === true;
|
||||
$refCode = 'root.refVal[0]';
|
||||
}
|
||||
}}
|
||||
{{??}}
|
||||
{{ var $refVal = it.resolveRef(it.baseId, $schema, it.isRoot); }}
|
||||
{{? $refVal === undefined }}
|
||||
{{ var $message = it.MissingRefError.message(it.baseId, $schema); }}
|
||||
{{? it.opts.missingRefs == 'fail' }}
|
||||
{{ it.logger.error($message); }}
|
||||
{{# def.error:'$ref' }}
|
||||
{{? $breakOnError }} if (false) { {{?}}
|
||||
{{?? it.opts.missingRefs == 'ignore' }}
|
||||
{{ it.logger.warn($message); }}
|
||||
{{? $breakOnError }} if (true) { {{?}}
|
||||
{{??}}
|
||||
{{ throw new it.MissingRefError(it.baseId, $schema, $message); }}
|
||||
{{?}}
|
||||
{{?? $refVal.inline }}
|
||||
{{# def.setupNextLevel }}
|
||||
{{
|
||||
$it.schema = $refVal.schema;
|
||||
$it.schemaPath = '';
|
||||
$it.errSchemaPath = $schema;
|
||||
}}
|
||||
{{ var $code = it.validate($it).replace(/validate\.schema/g, $refVal.code); }}
|
||||
{{= $code }}
|
||||
{{? $breakOnError}}
|
||||
if ({{=$nextValid}}) {
|
||||
{{?}}
|
||||
{{??}}
|
||||
{{
|
||||
$async = $refVal.$async === true || (it.async && $refVal.$async !== false);
|
||||
$refCode = $refVal.code;
|
||||
}}
|
||||
{{?}}
|
||||
{{?}}
|
||||
|
||||
{{? $refCode }}
|
||||
{{# def.beginDefOut}}
|
||||
{{# def._validateRef:$refCode }}
|
||||
{{# def.storeDefOut:__callValidate }}
|
||||
|
||||
{{? $async }}
|
||||
{{ if (!it.async) throw new Error('async schema referenced by sync schema'); }}
|
||||
{{? $breakOnError }} var {{=$valid}}; {{?}}
|
||||
try {
|
||||
await {{=__callValidate}};
|
||||
{{? $breakOnError }} {{=$valid}} = true; {{?}}
|
||||
} catch (e) {
|
||||
if (!(e instanceof ValidationError)) throw e;
|
||||
if (vErrors === null) vErrors = e.errors;
|
||||
else vErrors = vErrors.concat(e.errors);
|
||||
errors = vErrors.length;
|
||||
{{? $breakOnError }} {{=$valid}} = false; {{?}}
|
||||
}
|
||||
{{? $breakOnError }} if ({{=$valid}}) { {{?}}
|
||||
{{??}}
|
||||
if (!{{=__callValidate}}) {
|
||||
if (vErrors === null) vErrors = {{=$refCode}}.errors;
|
||||
else vErrors = vErrors.concat({{=$refCode}}.errors);
|
||||
errors = vErrors.length;
|
||||
} {{? $breakOnError }} else { {{?}}
|
||||
{{?}}
|
||||
{{?}}
|
||||
@@ -0,0 +1,38 @@
|
||||
'use strict'
|
||||
|
||||
/* global SharedArrayBuffer, Atomics */
|
||||
|
||||
if (typeof SharedArrayBuffer !== 'undefined' && typeof Atomics !== 'undefined') {
|
||||
const nil = new Int32Array(new SharedArrayBuffer(4))
|
||||
|
||||
function sleep (ms) {
|
||||
// also filters out NaN, non-number types, including empty strings, but allows bigints
|
||||
const valid = ms > 0 && ms < Infinity
|
||||
if (valid === false) {
|
||||
if (typeof ms !== 'number' && typeof ms !== 'bigint') {
|
||||
throw TypeError('sleep: ms must be a number')
|
||||
}
|
||||
throw RangeError('sleep: ms must be a number that is greater than 0 but less than Infinity')
|
||||
}
|
||||
|
||||
Atomics.wait(nil, 0, 0, Number(ms))
|
||||
}
|
||||
module.exports = sleep
|
||||
} else {
|
||||
|
||||
function sleep (ms) {
|
||||
// also filters out NaN, non-number types, including empty strings, but allows bigints
|
||||
const valid = ms > 0 && ms < Infinity
|
||||
if (valid === false) {
|
||||
if (typeof ms !== 'number' && typeof ms !== 'bigint') {
|
||||
throw TypeError('sleep: ms must be a number')
|
||||
}
|
||||
throw RangeError('sleep: ms must be a number that is greater than 0 but less than Infinity')
|
||||
}
|
||||
const target = Date.now() + Number(ms)
|
||||
while (target > Date.now()){}
|
||||
}
|
||||
|
||||
module.exports = sleep
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import Benchmark from "benchmark";
|
||||
|
||||
import { z } from "zod/v3";
|
||||
|
||||
const emptySuite = new Benchmark.Suite("z.object: empty");
|
||||
const shortSuite = new Benchmark.Suite("z.object: short");
|
||||
const longSuite = new Benchmark.Suite("z.object: long");
|
||||
|
||||
const empty = z.object({});
|
||||
const short = z.object({
|
||||
string: z.string(),
|
||||
});
|
||||
const long = z.object({
|
||||
string: z.string(),
|
||||
number: z.number(),
|
||||
boolean: z.boolean(),
|
||||
});
|
||||
|
||||
emptySuite
|
||||
.add("valid", () => {
|
||||
empty.parse({});
|
||||
})
|
||||
.add("valid: extra keys", () => {
|
||||
empty.parse({ string: "string" });
|
||||
})
|
||||
.add("invalid: null", () => {
|
||||
try {
|
||||
empty.parse(null);
|
||||
} catch (_err) {}
|
||||
})
|
||||
.on("cycle", (e: Benchmark.Event) => {
|
||||
console.log(`${(emptySuite as any).name}: ${e.target}`);
|
||||
});
|
||||
|
||||
shortSuite
|
||||
.add("valid", () => {
|
||||
short.parse({ string: "string" });
|
||||
})
|
||||
.add("valid: extra keys", () => {
|
||||
short.parse({ string: "string", number: 42 });
|
||||
})
|
||||
.add("invalid: null", () => {
|
||||
try {
|
||||
short.parse(null);
|
||||
} catch (_err) {}
|
||||
})
|
||||
.on("cycle", (e: Benchmark.Event) => {
|
||||
console.log(`${(shortSuite as any).name}: ${e.target}`);
|
||||
});
|
||||
|
||||
longSuite
|
||||
.add("valid", () => {
|
||||
long.parse({ string: "string", number: 42, boolean: true });
|
||||
})
|
||||
.add("valid: extra keys", () => {
|
||||
long.parse({ string: "string", number: 42, boolean: true, list: [] });
|
||||
})
|
||||
.add("invalid: null", () => {
|
||||
try {
|
||||
long.parse(null);
|
||||
} catch (_err) {}
|
||||
})
|
||||
.on("cycle", (e: Benchmark.Event) => {
|
||||
console.log(`${(longSuite as any).name}: ${e.target}`);
|
||||
});
|
||||
|
||||
export default {
|
||||
suites: [emptySuite, shortSuite, longSuite],
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
Copyright © James Long and contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -0,0 +1,443 @@
|
||||
'use strict';
|
||||
|
||||
/** Highest positive signed 32-bit float value */
|
||||
const maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1
|
||||
|
||||
/** Bootstring parameters */
|
||||
const base = 36;
|
||||
const tMin = 1;
|
||||
const tMax = 26;
|
||||
const skew = 38;
|
||||
const damp = 700;
|
||||
const initialBias = 72;
|
||||
const initialN = 128; // 0x80
|
||||
const delimiter = '-'; // '\x2D'
|
||||
|
||||
/** Regular expressions */
|
||||
const regexPunycode = /^xn--/;
|
||||
const regexNonASCII = /[^\0-\x7F]/; // Note: U+007F DEL is excluded too.
|
||||
const regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
|
||||
|
||||
/** Error messages */
|
||||
const errors = {
|
||||
'overflow': 'Overflow: input needs wider integers to process',
|
||||
'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
|
||||
'invalid-input': 'Invalid input'
|
||||
};
|
||||
|
||||
/** Convenience shortcuts */
|
||||
const baseMinusTMin = base - tMin;
|
||||
const floor = Math.floor;
|
||||
const stringFromCharCode = String.fromCharCode;
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* A generic error utility function.
|
||||
* @private
|
||||
* @param {String} type The error type.
|
||||
* @returns {Error} Throws a `RangeError` with the applicable error message.
|
||||
*/
|
||||
function error(type) {
|
||||
throw new RangeError(errors[type]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A generic `Array#map` utility function.
|
||||
* @private
|
||||
* @param {Array} array The array to iterate over.
|
||||
* @param {Function} callback The function that gets called for every array
|
||||
* item.
|
||||
* @returns {Array} A new array of values returned by the callback function.
|
||||
*/
|
||||
function map(array, callback) {
|
||||
const result = [];
|
||||
let length = array.length;
|
||||
while (length--) {
|
||||
result[length] = callback(array[length]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple `Array#map`-like wrapper to work with domain name strings or email
|
||||
* addresses.
|
||||
* @private
|
||||
* @param {String} domain The domain name or email address.
|
||||
* @param {Function} callback The function that gets called for every
|
||||
* character.
|
||||
* @returns {String} A new string of characters returned by the callback
|
||||
* function.
|
||||
*/
|
||||
function mapDomain(domain, callback) {
|
||||
const parts = domain.split('@');
|
||||
let result = '';
|
||||
if (parts.length > 1) {
|
||||
// In email addresses, only the domain name should be punycoded. Leave
|
||||
// the local part (i.e. everything up to `@`) intact.
|
||||
result = parts[0] + '@';
|
||||
domain = parts[1];
|
||||
}
|
||||
// Avoid `split(regex)` for IE8 compatibility. See #17.
|
||||
domain = domain.replace(regexSeparators, '\x2E');
|
||||
const labels = domain.split('.');
|
||||
const encoded = map(labels, callback).join('.');
|
||||
return result + encoded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an array containing the numeric code points of each Unicode
|
||||
* character in the string. While JavaScript uses UCS-2 internally,
|
||||
* this function will convert a pair of surrogate halves (each of which
|
||||
* UCS-2 exposes as separate characters) into a single code point,
|
||||
* matching UTF-16.
|
||||
* @see `punycode.ucs2.encode`
|
||||
* @see <https://mathiasbynens.be/notes/javascript-encoding>
|
||||
* @memberOf punycode.ucs2
|
||||
* @name decode
|
||||
* @param {String} string The Unicode input string (UCS-2).
|
||||
* @returns {Array} The new array of code points.
|
||||
*/
|
||||
function ucs2decode(string) {
|
||||
const output = [];
|
||||
let counter = 0;
|
||||
const length = string.length;
|
||||
while (counter < length) {
|
||||
const value = string.charCodeAt(counter++);
|
||||
if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
|
||||
// It's a high surrogate, and there is a next character.
|
||||
const extra = string.charCodeAt(counter++);
|
||||
if ((extra & 0xFC00) == 0xDC00) { // Low surrogate.
|
||||
output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
|
||||
} else {
|
||||
// It's an unmatched surrogate; only append this code unit, in case the
|
||||
// next code unit is the high surrogate of a surrogate pair.
|
||||
output.push(value);
|
||||
counter--;
|
||||
}
|
||||
} else {
|
||||
output.push(value);
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string based on an array of numeric code points.
|
||||
* @see `punycode.ucs2.decode`
|
||||
* @memberOf punycode.ucs2
|
||||
* @name encode
|
||||
* @param {Array} codePoints The array of numeric code points.
|
||||
* @returns {String} The new Unicode string (UCS-2).
|
||||
*/
|
||||
const ucs2encode = codePoints => String.fromCodePoint(...codePoints);
|
||||
|
||||
/**
|
||||
* Converts a basic code point into a digit/integer.
|
||||
* @see `digitToBasic()`
|
||||
* @private
|
||||
* @param {Number} codePoint The basic numeric code point value.
|
||||
* @returns {Number} The numeric value of a basic code point (for use in
|
||||
* representing integers) in the range `0` to `base - 1`, or `base` if
|
||||
* the code point does not represent a value.
|
||||
*/
|
||||
const basicToDigit = function(codePoint) {
|
||||
if (codePoint >= 0x30 && codePoint < 0x3A) {
|
||||
return 26 + (codePoint - 0x30);
|
||||
}
|
||||
if (codePoint >= 0x41 && codePoint < 0x5B) {
|
||||
return codePoint - 0x41;
|
||||
}
|
||||
if (codePoint >= 0x61 && codePoint < 0x7B) {
|
||||
return codePoint - 0x61;
|
||||
}
|
||||
return base;
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a digit/integer into a basic code point.
|
||||
* @see `basicToDigit()`
|
||||
* @private
|
||||
* @param {Number} digit The numeric value of a basic code point.
|
||||
* @returns {Number} The basic code point whose value (when used for
|
||||
* representing integers) is `digit`, which needs to be in the range
|
||||
* `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
|
||||
* used; else, the lowercase form is used. The behavior is undefined
|
||||
* if `flag` is non-zero and `digit` has no uppercase form.
|
||||
*/
|
||||
const digitToBasic = function(digit, flag) {
|
||||
// 0..25 map to ASCII a..z or A..Z
|
||||
// 26..35 map to ASCII 0..9
|
||||
return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
|
||||
};
|
||||
|
||||
/**
|
||||
* Bias adaptation function as per section 3.4 of RFC 3492.
|
||||
* https://tools.ietf.org/html/rfc3492#section-3.4
|
||||
* @private
|
||||
*/
|
||||
const adapt = function(delta, numPoints, firstTime) {
|
||||
let k = 0;
|
||||
delta = firstTime ? floor(delta / damp) : delta >> 1;
|
||||
delta += floor(delta / numPoints);
|
||||
for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {
|
||||
delta = floor(delta / baseMinusTMin);
|
||||
}
|
||||
return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a Punycode string of ASCII-only symbols to a string of Unicode
|
||||
* symbols.
|
||||
* @memberOf punycode
|
||||
* @param {String} input The Punycode string of ASCII-only symbols.
|
||||
* @returns {String} The resulting string of Unicode symbols.
|
||||
*/
|
||||
const decode = function(input) {
|
||||
// Don't use UCS-2.
|
||||
const output = [];
|
||||
const inputLength = input.length;
|
||||
let i = 0;
|
||||
let n = initialN;
|
||||
let bias = initialBias;
|
||||
|
||||
// Handle the basic code points: let `basic` be the number of input code
|
||||
// points before the last delimiter, or `0` if there is none, then copy
|
||||
// the first basic code points to the output.
|
||||
|
||||
let basic = input.lastIndexOf(delimiter);
|
||||
if (basic < 0) {
|
||||
basic = 0;
|
||||
}
|
||||
|
||||
for (let j = 0; j < basic; ++j) {
|
||||
// if it's not a basic code point
|
||||
if (input.charCodeAt(j) >= 0x80) {
|
||||
error('not-basic');
|
||||
}
|
||||
output.push(input.charCodeAt(j));
|
||||
}
|
||||
|
||||
// Main decoding loop: start just after the last delimiter if any basic code
|
||||
// points were copied; start at the beginning otherwise.
|
||||
|
||||
for (let index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {
|
||||
|
||||
// `index` is the index of the next character to be consumed.
|
||||
// Decode a generalized variable-length integer into `delta`,
|
||||
// which gets added to `i`. The overflow checking is easier
|
||||
// if we increase `i` as we go, then subtract off its starting
|
||||
// value at the end to obtain `delta`.
|
||||
const oldi = i;
|
||||
for (let w = 1, k = base; /* no condition */; k += base) {
|
||||
|
||||
if (index >= inputLength) {
|
||||
error('invalid-input');
|
||||
}
|
||||
|
||||
const digit = basicToDigit(input.charCodeAt(index++));
|
||||
|
||||
if (digit >= base) {
|
||||
error('invalid-input');
|
||||
}
|
||||
if (digit > floor((maxInt - i) / w)) {
|
||||
error('overflow');
|
||||
}
|
||||
|
||||
i += digit * w;
|
||||
const t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
|
||||
|
||||
if (digit < t) {
|
||||
break;
|
||||
}
|
||||
|
||||
const baseMinusT = base - t;
|
||||
if (w > floor(maxInt / baseMinusT)) {
|
||||
error('overflow');
|
||||
}
|
||||
|
||||
w *= baseMinusT;
|
||||
|
||||
}
|
||||
|
||||
const out = output.length + 1;
|
||||
bias = adapt(i - oldi, out, oldi == 0);
|
||||
|
||||
// `i` was supposed to wrap around from `out` to `0`,
|
||||
// incrementing `n` each time, so we'll fix that now:
|
||||
if (floor(i / out) > maxInt - n) {
|
||||
error('overflow');
|
||||
}
|
||||
|
||||
n += floor(i / out);
|
||||
i %= out;
|
||||
|
||||
// Insert `n` at position `i` of the output.
|
||||
output.splice(i++, 0, n);
|
||||
|
||||
}
|
||||
|
||||
return String.fromCodePoint(...output);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a string of Unicode symbols (e.g. a domain name label) to a
|
||||
* Punycode string of ASCII-only symbols.
|
||||
* @memberOf punycode
|
||||
* @param {String} input The string of Unicode symbols.
|
||||
* @returns {String} The resulting Punycode string of ASCII-only symbols.
|
||||
*/
|
||||
const encode = function(input) {
|
||||
const output = [];
|
||||
|
||||
// Convert the input in UCS-2 to an array of Unicode code points.
|
||||
input = ucs2decode(input);
|
||||
|
||||
// Cache the length.
|
||||
const inputLength = input.length;
|
||||
|
||||
// Initialize the state.
|
||||
let n = initialN;
|
||||
let delta = 0;
|
||||
let bias = initialBias;
|
||||
|
||||
// Handle the basic code points.
|
||||
for (const currentValue of input) {
|
||||
if (currentValue < 0x80) {
|
||||
output.push(stringFromCharCode(currentValue));
|
||||
}
|
||||
}
|
||||
|
||||
const basicLength = output.length;
|
||||
let handledCPCount = basicLength;
|
||||
|
||||
// `handledCPCount` is the number of code points that have been handled;
|
||||
// `basicLength` is the number of basic code points.
|
||||
|
||||
// Finish the basic string with a delimiter unless it's empty.
|
||||
if (basicLength) {
|
||||
output.push(delimiter);
|
||||
}
|
||||
|
||||
// Main encoding loop:
|
||||
while (handledCPCount < inputLength) {
|
||||
|
||||
// All non-basic code points < n have been handled already. Find the next
|
||||
// larger one:
|
||||
let m = maxInt;
|
||||
for (const currentValue of input) {
|
||||
if (currentValue >= n && currentValue < m) {
|
||||
m = currentValue;
|
||||
}
|
||||
}
|
||||
|
||||
// Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
|
||||
// but guard against overflow.
|
||||
const handledCPCountPlusOne = handledCPCount + 1;
|
||||
if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
|
||||
error('overflow');
|
||||
}
|
||||
|
||||
delta += (m - n) * handledCPCountPlusOne;
|
||||
n = m;
|
||||
|
||||
for (const currentValue of input) {
|
||||
if (currentValue < n && ++delta > maxInt) {
|
||||
error('overflow');
|
||||
}
|
||||
if (currentValue === n) {
|
||||
// Represent delta as a generalized variable-length integer.
|
||||
let q = delta;
|
||||
for (let k = base; /* no condition */; k += base) {
|
||||
const t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
|
||||
if (q < t) {
|
||||
break;
|
||||
}
|
||||
const qMinusT = q - t;
|
||||
const baseMinusT = base - t;
|
||||
output.push(
|
||||
stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
|
||||
);
|
||||
q = floor(qMinusT / baseMinusT);
|
||||
}
|
||||
|
||||
output.push(stringFromCharCode(digitToBasic(q, 0)));
|
||||
bias = adapt(delta, handledCPCountPlusOne, handledCPCount === basicLength);
|
||||
delta = 0;
|
||||
++handledCPCount;
|
||||
}
|
||||
}
|
||||
|
||||
++delta;
|
||||
++n;
|
||||
|
||||
}
|
||||
return output.join('');
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a Punycode string representing a domain name or an email address
|
||||
* to Unicode. Only the Punycoded parts of the input will be converted, i.e.
|
||||
* it doesn't matter if you call it on a string that has already been
|
||||
* converted to Unicode.
|
||||
* @memberOf punycode
|
||||
* @param {String} input The Punycoded domain name or email address to
|
||||
* convert to Unicode.
|
||||
* @returns {String} The Unicode representation of the given Punycode
|
||||
* string.
|
||||
*/
|
||||
const toUnicode = function(input) {
|
||||
return mapDomain(input, function(string) {
|
||||
return regexPunycode.test(string)
|
||||
? decode(string.slice(4).toLowerCase())
|
||||
: string;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a Unicode string representing a domain name or an email address to
|
||||
* Punycode. Only the non-ASCII parts of the domain name will be converted,
|
||||
* i.e. it doesn't matter if you call it with a domain that's already in
|
||||
* ASCII.
|
||||
* @memberOf punycode
|
||||
* @param {String} input The domain name or email address to convert, as a
|
||||
* Unicode string.
|
||||
* @returns {String} The Punycode representation of the given domain name or
|
||||
* email address.
|
||||
*/
|
||||
const toASCII = function(input) {
|
||||
return mapDomain(input, function(string) {
|
||||
return regexNonASCII.test(string)
|
||||
? 'xn--' + encode(string)
|
||||
: string;
|
||||
});
|
||||
};
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/** Define the public API */
|
||||
const punycode = {
|
||||
/**
|
||||
* A string representing the current Punycode.js version number.
|
||||
* @memberOf punycode
|
||||
* @type String
|
||||
*/
|
||||
'version': '2.3.1',
|
||||
/**
|
||||
* An object of methods to convert from JavaScript's internal character
|
||||
* representation (UCS-2) to Unicode code points, and back.
|
||||
* @see <https://mathiasbynens.be/notes/javascript-encoding>
|
||||
* @memberOf punycode
|
||||
* @type Object
|
||||
*/
|
||||
'ucs2': {
|
||||
'decode': ucs2decode,
|
||||
'encode': ucs2encode
|
||||
},
|
||||
'decode': decode,
|
||||
'encode': encode,
|
||||
'toASCII': toASCII,
|
||||
'toUnicode': toUnicode
|
||||
};
|
||||
|
||||
module.exports = punycode;
|
||||
@@ -0,0 +1,35 @@
|
||||
const endpoint = {
|
||||
http: {
|
||||
devnet: 'http://api.devnet.solana.com',
|
||||
testnet: 'http://api.testnet.solana.com',
|
||||
'mainnet-beta': 'http://api.mainnet-beta.solana.com/',
|
||||
},
|
||||
https: {
|
||||
devnet: 'https://api.devnet.solana.com',
|
||||
testnet: 'https://api.testnet.solana.com',
|
||||
'mainnet-beta': 'https://api.mainnet-beta.solana.com/',
|
||||
},
|
||||
};
|
||||
|
||||
export type Cluster = 'devnet' | 'testnet' | 'mainnet-beta';
|
||||
|
||||
/**
|
||||
* Retrieves the RPC API URL for the specified cluster
|
||||
* @param {Cluster} [cluster="devnet"] - The cluster name of the RPC API URL to use. Possible options: 'devnet' | 'testnet' | 'mainnet-beta'
|
||||
* @param {boolean} [tls="http"] - Use TLS when connecting to cluster.
|
||||
*
|
||||
* @returns {string} URL string of the RPC endpoint
|
||||
*/
|
||||
export function clusterApiUrl(cluster?: Cluster, tls?: boolean): string {
|
||||
const key = tls === false ? 'http' : 'https';
|
||||
|
||||
if (!cluster) {
|
||||
return endpoint[key]['devnet'];
|
||||
}
|
||||
|
||||
const url = endpoint[key][cluster];
|
||||
if (!url) {
|
||||
throw new Error(`Unknown ${key} cluster: ${cluster}`);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,10 @@
|
||||
function _extends() {
|
||||
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
||||
for (var e = 1; e < arguments.length; e++) {
|
||||
var t = arguments[e];
|
||||
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
||||
}
|
||||
return n;
|
||||
}, _extends.apply(null, arguments);
|
||||
}
|
||||
export { _extends as default };
|
||||
@@ -0,0 +1,367 @@
|
||||
/// <reference path="../../typings/thenable.d.ts" preserve="true" />
|
||||
import { Message, RequestMessage, RequestType, RequestType0, RequestType1, RequestType2, RequestType3, RequestType4, RequestType5, RequestType6, RequestType7, RequestType8, RequestType9, ResponseMessage, ResponseError, NotificationMessage, NotificationType, NotificationType0, NotificationType1, NotificationType2, NotificationType3, NotificationType4, NotificationType5, NotificationType6, NotificationType7, NotificationType8, NotificationType9, _EM, ParameterStructures } from './messages';
|
||||
import type { Disposable } from './disposable';
|
||||
import { Event } from './events';
|
||||
import { CancellationToken, AbstractCancellationTokenSource } from './cancellation';
|
||||
import { MessageReader } from './messageReader';
|
||||
import { MessageWriter } from './messageWriter';
|
||||
export type ProgressToken = number | string;
|
||||
export declare namespace ProgressToken {
|
||||
function is(value: any): value is number | string;
|
||||
}
|
||||
interface ProgressParams<T> {
|
||||
/**
|
||||
* The progress token provided by the client or server.
|
||||
*/
|
||||
token: ProgressToken;
|
||||
/**
|
||||
* The progress data.
|
||||
*/
|
||||
value: T;
|
||||
}
|
||||
export declare class ProgressType<PR> {
|
||||
/**
|
||||
* Clients must not use these properties. They are here to ensure correct typing.
|
||||
* in TypeScript
|
||||
*/
|
||||
readonly __: [PR, _EM] | undefined;
|
||||
readonly _pr: PR | undefined;
|
||||
constructor();
|
||||
}
|
||||
export type RequestParam<P> = P extends null ? P | undefined : P;
|
||||
export type HandlerResult<R, E, _R = R extends null ? (R | undefined | void) : R> = _R | ResponseError<E> | Thenable<_R> | Thenable<ResponseError<E>> | Thenable<_R | ResponseError<E>>;
|
||||
export interface StarRequestHandler {
|
||||
(method: string, params: any[] | object | undefined, token: CancellationToken): HandlerResult<any, any>;
|
||||
}
|
||||
export interface GenericRequestHandler<R, E> {
|
||||
(...params: any[]): HandlerResult<R, E>;
|
||||
}
|
||||
export interface RequestHandler0<R, E> {
|
||||
(token: CancellationToken): HandlerResult<R, E>;
|
||||
}
|
||||
export interface RequestHandler<P, R, E> {
|
||||
(params: P, token: CancellationToken): HandlerResult<R, E>;
|
||||
}
|
||||
export interface RequestHandler1<P1, R, E> {
|
||||
(p1: P1, token: CancellationToken): HandlerResult<R, E>;
|
||||
}
|
||||
export interface RequestHandler2<P1, P2, R, E> {
|
||||
(p1: P1, p2: P2, token: CancellationToken): HandlerResult<R, E>;
|
||||
}
|
||||
export interface RequestHandler3<P1, P2, P3, R, E> {
|
||||
(p1: P1, p2: P2, p3: P3, token: CancellationToken): HandlerResult<R, E>;
|
||||
}
|
||||
export interface RequestHandler4<P1, P2, P3, P4, R, E> {
|
||||
(p1: P1, p2: P2, p3: P3, p4: P4, token: CancellationToken): HandlerResult<R, E>;
|
||||
}
|
||||
export interface RequestHandler5<P1, P2, P3, P4, P5, R, E> {
|
||||
(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, token: CancellationToken): HandlerResult<R, E>;
|
||||
}
|
||||
export interface RequestHandler6<P1, P2, P3, P4, P5, P6, R, E> {
|
||||
(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, token: CancellationToken): HandlerResult<R, E>;
|
||||
}
|
||||
export interface RequestHandler7<P1, P2, P3, P4, P5, P6, P7, R, E> {
|
||||
(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, token: CancellationToken): HandlerResult<R, E>;
|
||||
}
|
||||
export interface RequestHandler8<P1, P2, P3, P4, P5, P6, P7, P8, R, E> {
|
||||
(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, token: CancellationToken): HandlerResult<R, E>;
|
||||
}
|
||||
export interface RequestHandler9<P1, P2, P3, P4, P5, P6, P7, P8, P9, R, E> {
|
||||
(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, token: CancellationToken): HandlerResult<R, E>;
|
||||
}
|
||||
export type NotificationResult = void | Promise<void>;
|
||||
export interface StarNotificationHandler {
|
||||
(method: string, params: any[] | object | undefined): NotificationResult;
|
||||
}
|
||||
export interface GenericNotificationHandler {
|
||||
(...params: any[]): NotificationResult;
|
||||
}
|
||||
export interface NotificationHandler0 {
|
||||
(): NotificationResult;
|
||||
}
|
||||
export interface NotificationHandler<P> {
|
||||
(params: P): NotificationResult;
|
||||
}
|
||||
export interface NotificationHandler1<P1> {
|
||||
(p1: P1): NotificationResult;
|
||||
}
|
||||
export interface NotificationHandler2<P1, P2> {
|
||||
(p1: P1, p2: P2): NotificationResult;
|
||||
}
|
||||
export interface NotificationHandler3<P1, P2, P3> {
|
||||
(p1: P1, p2: P2, p3: P3): NotificationResult;
|
||||
}
|
||||
export interface NotificationHandler4<P1, P2, P3, P4> {
|
||||
(p1: P1, p2: P2, p3: P3, p4: P4): NotificationResult;
|
||||
}
|
||||
export interface NotificationHandler5<P1, P2, P3, P4, P5> {
|
||||
(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5): NotificationResult;
|
||||
}
|
||||
export interface NotificationHandler6<P1, P2, P3, P4, P5, P6> {
|
||||
(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6): NotificationResult;
|
||||
}
|
||||
export interface NotificationHandler7<P1, P2, P3, P4, P5, P6, P7> {
|
||||
(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7): NotificationResult;
|
||||
}
|
||||
export interface NotificationHandler8<P1, P2, P3, P4, P5, P6, P7, P8> {
|
||||
(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8): NotificationResult;
|
||||
}
|
||||
export interface NotificationHandler9<P1, P2, P3, P4, P5, P6, P7, P8, P9> {
|
||||
(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9): NotificationResult;
|
||||
}
|
||||
export interface Logger {
|
||||
error(message: string): void;
|
||||
warn(message: string): void;
|
||||
info(message: string): void;
|
||||
log(message: string): void;
|
||||
}
|
||||
export declare const NullLogger: Logger;
|
||||
export declare enum Trace {
|
||||
Off = 0,
|
||||
Messages = 1,
|
||||
Compact = 2,
|
||||
Verbose = 3
|
||||
}
|
||||
export declare namespace TraceValue {
|
||||
/**
|
||||
* Turn tracing off.
|
||||
*/
|
||||
const Off: 'off';
|
||||
/**
|
||||
* Trace messages only.
|
||||
*/
|
||||
const Messages: 'messages';
|
||||
/**
|
||||
* Compact message tracing.
|
||||
*/
|
||||
const Compact: 'compact';
|
||||
/**
|
||||
* Verbose message tracing.
|
||||
*/
|
||||
const Verbose: 'verbose';
|
||||
}
|
||||
export type TraceValue = 'off' | 'messages' | 'compact' | 'verbose';
|
||||
/**
|
||||
* @deprecated Use TraceValue instead
|
||||
*/
|
||||
export declare const TraceValues: typeof TraceValue;
|
||||
export type TraceValues = TraceValue;
|
||||
export declare namespace Trace {
|
||||
function fromString(value: string): Trace;
|
||||
function toString(value: Trace): TraceValue;
|
||||
}
|
||||
export declare enum TraceFormat {
|
||||
Text = "text",
|
||||
JSON = "json"
|
||||
}
|
||||
export declare namespace TraceFormat {
|
||||
function fromString(value: string): TraceFormat;
|
||||
}
|
||||
export interface TraceOptions {
|
||||
sendNotification?: boolean;
|
||||
traceFormat?: TraceFormat;
|
||||
}
|
||||
export interface SetTraceParams {
|
||||
value: TraceValue;
|
||||
}
|
||||
export declare namespace SetTraceNotification {
|
||||
const type: NotificationType<SetTraceParams>;
|
||||
}
|
||||
export interface LogTraceParams {
|
||||
message: string;
|
||||
verbose?: string;
|
||||
}
|
||||
export declare namespace LogTraceNotification {
|
||||
const type: NotificationType<LogTraceParams>;
|
||||
}
|
||||
export interface Tracer {
|
||||
log(dataObject: any): void;
|
||||
log(message: string, data?: string): void;
|
||||
}
|
||||
export declare enum ConnectionErrors {
|
||||
/**
|
||||
* The connection is closed.
|
||||
*/
|
||||
Closed = 1,
|
||||
/**
|
||||
* The connection got disposed.
|
||||
*/
|
||||
Disposed = 2,
|
||||
/**
|
||||
* The connection is already in listening mode.
|
||||
*/
|
||||
AlreadyListening = 3
|
||||
}
|
||||
export declare class ConnectionError extends Error {
|
||||
readonly code: ConnectionErrors;
|
||||
constructor(code: ConnectionErrors, message: string);
|
||||
}
|
||||
export type ConnectionStrategy = {
|
||||
cancelUndispatched?: (message: Message, next: (message: Message) => ResponseMessage | undefined) => ResponseMessage | undefined;
|
||||
};
|
||||
export declare namespace ConnectionStrategy {
|
||||
function is(value: any): value is ConnectionStrategy;
|
||||
}
|
||||
export type CancellationId = number | string;
|
||||
export interface IdCancellationReceiverStrategy {
|
||||
kind?: 'id';
|
||||
/**
|
||||
* Creates a CancellationTokenSource from a cancellation id.
|
||||
*
|
||||
* @param id The cancellation id.
|
||||
*/
|
||||
createCancellationTokenSource(id: CancellationId): AbstractCancellationTokenSource;
|
||||
/**
|
||||
* An optional method to dispose the strategy.
|
||||
*/
|
||||
dispose?(): void;
|
||||
}
|
||||
export declare namespace IdCancellationReceiverStrategy {
|
||||
function is(value: any): value is IdCancellationReceiverStrategy;
|
||||
}
|
||||
export interface RequestCancellationReceiverStrategy {
|
||||
kind: 'request';
|
||||
/**
|
||||
* Create a cancellation token source from a given request message.
|
||||
*
|
||||
* @param requestMessage The request message.
|
||||
*/
|
||||
createCancellationTokenSource(requestMessage: RequestMessage): AbstractCancellationTokenSource;
|
||||
/**
|
||||
* An optional method to dispose the strategy.
|
||||
*/
|
||||
dispose?(): void;
|
||||
}
|
||||
export declare namespace RequestCancellationReceiverStrategy {
|
||||
function is(value: any): value is RequestCancellationReceiverStrategy;
|
||||
}
|
||||
export type CancellationReceiverStrategy = IdCancellationReceiverStrategy | RequestCancellationReceiverStrategy;
|
||||
export declare namespace CancellationReceiverStrategy {
|
||||
const Message: CancellationReceiverStrategy;
|
||||
function is(value: any): value is CancellationReceiverStrategy;
|
||||
}
|
||||
export interface CancellationSenderStrategy {
|
||||
/**
|
||||
* Hook to enable cancellation for the given request.
|
||||
*
|
||||
* @param request The request to enable cancellation for.
|
||||
*/
|
||||
enableCancellation?(request: RequestMessage): void;
|
||||
/**
|
||||
* Send cancellation for the given cancellation id
|
||||
*
|
||||
* @param conn The connection used.
|
||||
* @param id The cancellation id.
|
||||
*/
|
||||
sendCancellation(conn: MessageConnection, id: CancellationId): Promise<void>;
|
||||
/**
|
||||
* Cleanup any cancellation state for the given cancellation id. After this
|
||||
* method has been call no cancellation will be sent anymore for the given id.
|
||||
*
|
||||
* @param id The cancellation id.
|
||||
*/
|
||||
cleanup(id: CancellationId): void;
|
||||
/**
|
||||
* An optional method to dispose the strategy.
|
||||
*/
|
||||
dispose?(): void;
|
||||
}
|
||||
export declare namespace CancellationSenderStrategy {
|
||||
const Message: CancellationSenderStrategy;
|
||||
function is(value: any): value is CancellationSenderStrategy;
|
||||
}
|
||||
export interface CancellationStrategy {
|
||||
receiver: CancellationReceiverStrategy | RequestCancellationReceiverStrategy;
|
||||
sender: CancellationSenderStrategy;
|
||||
}
|
||||
export declare namespace CancellationStrategy {
|
||||
const Message: CancellationStrategy;
|
||||
function is(value: any): value is CancellationStrategy;
|
||||
}
|
||||
export interface MessageStrategy {
|
||||
handleMessage(message: Message, next: (message: Message) => NotificationResult): NotificationResult;
|
||||
}
|
||||
export declare namespace MessageStrategy {
|
||||
function is(value: any): value is MessageStrategy;
|
||||
}
|
||||
/**
|
||||
* Connection options. A valid connection option must have at least a
|
||||
* `CancellationStrategy` or a `MessageStrategy` or a `ConnectionStrategy`.
|
||||
*/
|
||||
export interface ConnectionOptions {
|
||||
cancellationStrategy?: CancellationStrategy;
|
||||
connectionStrategy?: ConnectionStrategy;
|
||||
messageStrategy?: MessageStrategy;
|
||||
maxParallelism?: number;
|
||||
}
|
||||
export declare namespace ConnectionOptions {
|
||||
function is(value: any): value is ConnectionOptions;
|
||||
}
|
||||
export interface MessageConnection {
|
||||
sendRequest<R, E>(type: RequestType0<R, E>, token?: CancellationToken): Promise<R>;
|
||||
sendRequest<P, R, E>(type: RequestType<P, R, E>, params: NoInfer<RequestParam<P>>, token?: CancellationToken): Promise<R>;
|
||||
sendRequest<P1, R, E>(type: RequestType1<P1, R, E>, p1: NoInfer<RequestParam<P1>>, token?: CancellationToken): Promise<R>;
|
||||
sendRequest<P1, P2, R, E>(type: RequestType2<P1, P2, R, E>, p1: NoInfer<RequestParam<P1>>, p2: NoInfer<RequestParam<P2>>, token?: CancellationToken): Promise<R>;
|
||||
sendRequest<P1, P2, P3, R, E>(type: RequestType3<P1, P2, P3, R, E>, p1: NoInfer<RequestParam<P1>>, p2: NoInfer<RequestParam<P2>>, p3: NoInfer<RequestParam<P3>>, token?: CancellationToken): Promise<R>;
|
||||
sendRequest<P1, P2, P3, P4, R, E>(type: RequestType4<P1, P2, P3, P4, R, E>, p1: NoInfer<RequestParam<P1>>, p2: NoInfer<RequestParam<P2>>, p3: NoInfer<RequestParam<P3>>, p4: NoInfer<RequestParam<P4>>, token?: CancellationToken): Promise<R>;
|
||||
sendRequest<P1, P2, P3, P4, P5, R, E>(type: RequestType5<P1, P2, P3, P4, P5, R, E>, p1: NoInfer<RequestParam<P1>>, p2: NoInfer<RequestParam<P2>>, p3: NoInfer<RequestParam<P3>>, p4: NoInfer<RequestParam<P4>>, p5: NoInfer<RequestParam<P5>>, token?: CancellationToken): Promise<R>;
|
||||
sendRequest<P1, P2, P3, P4, P5, P6, R, E>(type: RequestType6<P1, P2, P3, P4, P5, P6, R, E>, p1: NoInfer<RequestParam<P1>>, p2: NoInfer<RequestParam<P2>>, p3: NoInfer<RequestParam<P3>>, p4: NoInfer<RequestParam<P4>>, p5: NoInfer<RequestParam<P5>>, p6: NoInfer<RequestParam<P6>>, token?: CancellationToken): Promise<R>;
|
||||
sendRequest<P1, P2, P3, P4, P5, P6, P7, R, E>(type: RequestType7<P1, P2, P3, P4, P5, P6, P7, R, E>, p1: NoInfer<RequestParam<P1>>, p2: NoInfer<RequestParam<P2>>, p3: NoInfer<RequestParam<P3>>, p4: NoInfer<RequestParam<P4>>, p5: NoInfer<RequestParam<P5>>, p6: NoInfer<RequestParam<P6>>, p7: NoInfer<RequestParam<P7>>, token?: CancellationToken): Promise<R>;
|
||||
sendRequest<P1, P2, P3, P4, P5, P6, P7, P8, R, E>(type: RequestType8<P1, P2, P3, P4, P5, P6, P7, P8, R, E>, p1: NoInfer<RequestParam<P1>>, p2: NoInfer<RequestParam<P2>>, p3: NoInfer<RequestParam<P3>>, p4: NoInfer<RequestParam<P4>>, p5: NoInfer<RequestParam<P5>>, p6: NoInfer<RequestParam<P6>>, p7: NoInfer<RequestParam<P7>>, p8: NoInfer<RequestParam<P8>>, token?: CancellationToken): Promise<R>;
|
||||
sendRequest<P1, P2, P3, P4, P5, P6, P7, P8, P9, R, E>(type: RequestType9<P1, P2, P3, P4, P5, P6, P7, P8, P9, R, E>, p1: NoInfer<RequestParam<P1>>, p2: NoInfer<RequestParam<P2>>, p3: NoInfer<RequestParam<P3>>, p4: NoInfer<RequestParam<P4>>, p5: NoInfer<RequestParam<P5>>, p6: NoInfer<RequestParam<P6>>, p7: NoInfer<RequestParam<P7>>, p8: NoInfer<RequestParam<P8>>, p9: NoInfer<RequestParam<P9>>, token?: CancellationToken): Promise<R>;
|
||||
sendRequest<R>(method: string, r0?: ParameterStructures | any, ...rest: any[]): Promise<R>;
|
||||
onRequest<R, E>(type: RequestType0<R, E>, handler: NoInfer<RequestHandler0<R, E>>): Disposable;
|
||||
onRequest<P, R, E>(type: RequestType<P, R, E>, handler: NoInfer<RequestHandler<P, R, E>>): Disposable;
|
||||
onRequest<P1, R, E>(type: RequestType1<P1, R, E>, handler: NoInfer<RequestHandler1<P1, R, E>>): Disposable;
|
||||
onRequest<P1, P2, R, E>(type: RequestType2<P1, P2, R, E>, handler: NoInfer<RequestHandler2<P1, P2, R, E>>): Disposable;
|
||||
onRequest<P1, P2, P3, R, E>(type: RequestType3<P1, P2, P3, R, E>, handler: NoInfer<RequestHandler3<P1, P2, P3, R, E>>): Disposable;
|
||||
onRequest<P1, P2, P3, P4, R, E>(type: RequestType4<P1, P2, P3, P4, R, E>, handler: NoInfer<RequestHandler4<P1, P2, P3, P4, R, E>>): Disposable;
|
||||
onRequest<P1, P2, P3, P4, P5, R, E>(type: RequestType5<P1, P2, P3, P4, P5, R, E>, handler: NoInfer<RequestHandler5<P1, P2, P3, P4, P5, R, E>>): Disposable;
|
||||
onRequest<P1, P2, P3, P4, P5, P6, R, E>(type: RequestType6<P1, P2, P3, P4, P5, P6, R, E>, handler: NoInfer<RequestHandler6<P1, P2, P3, P4, P5, P6, R, E>>): Disposable;
|
||||
onRequest<P1, P2, P3, P4, P5, P6, P7, R, E>(type: RequestType7<P1, P2, P3, P4, P5, P6, P7, R, E>, handler: NoInfer<RequestHandler7<P1, P2, P3, P4, P5, P6, P7, R, E>>): Disposable;
|
||||
onRequest<P1, P2, P3, P4, P5, P6, P7, P8, R, E>(type: RequestType8<P1, P2, P3, P4, P5, P6, P7, P8, R, E>, handler: NoInfer<RequestHandler8<P1, P2, P3, P4, P5, P6, P7, P8, R, E>>): Disposable;
|
||||
onRequest<P1, P2, P3, P4, P5, P6, P7, P8, P9, R, E>(type: RequestType9<P1, P2, P3, P4, P5, P6, P7, P8, P9, R, E>, handler: NoInfer<RequestHandler9<P1, P2, P3, P4, P5, P6, P7, P8, P9, R, E>>): Disposable;
|
||||
onRequest<R, E>(method: string, handler: GenericRequestHandler<R, E>): Disposable;
|
||||
onRequest(handler: StarRequestHandler): Disposable;
|
||||
hasPendingResponse(): boolean;
|
||||
sendNotification(type: NotificationType0): Promise<void>;
|
||||
sendNotification<P>(type: NotificationType<P>, params?: NoInfer<RequestParam<P>>): Promise<void>;
|
||||
sendNotification<P1>(type: NotificationType1<P1>, p1: NoInfer<RequestParam<P1>>): Promise<void>;
|
||||
sendNotification<P1, P2>(type: NotificationType2<P1, P2>, p1: NoInfer<RequestParam<P1>>, p2: NoInfer<RequestParam<P2>>): Promise<void>;
|
||||
sendNotification<P1, P2, P3>(type: NotificationType3<P1, P2, P3>, p1: NoInfer<RequestParam<P1>>, p2: NoInfer<RequestParam<P2>>, p3: NoInfer<RequestParam<P3>>): Promise<void>;
|
||||
sendNotification<P1, P2, P3, P4>(type: NotificationType4<P1, P2, P3, P4>, p1: NoInfer<RequestParam<P1>>, p2: NoInfer<RequestParam<P2>>, p3: NoInfer<RequestParam<P3>>, p4: NoInfer<RequestParam<P4>>): Promise<void>;
|
||||
sendNotification<P1, P2, P3, P4, P5>(type: NotificationType5<P1, P2, P3, P4, P5>, p1: NoInfer<RequestParam<P1>>, p2: NoInfer<RequestParam<P2>>, p3: NoInfer<RequestParam<P3>>, p4: NoInfer<RequestParam<P4>>, p5: NoInfer<RequestParam<P5>>): Promise<void>;
|
||||
sendNotification<P1, P2, P3, P4, P5, P6>(type: NotificationType6<P1, P2, P3, P4, P5, P6>, p1: NoInfer<RequestParam<P1>>, p2: NoInfer<RequestParam<P2>>, p3: NoInfer<RequestParam<P3>>, p4: NoInfer<RequestParam<P4>>, p5: NoInfer<RequestParam<P5>>, p6: NoInfer<RequestParam<P6>>): Promise<void>;
|
||||
sendNotification<P1, P2, P3, P4, P5, P6, P7>(type: NotificationType7<P1, P2, P3, P4, P5, P6, P7>, p1: NoInfer<RequestParam<P1>>, p2: NoInfer<RequestParam<P2>>, p3: NoInfer<RequestParam<P3>>, p4: NoInfer<RequestParam<P4>>, p5: NoInfer<RequestParam<P5>>, p6: NoInfer<RequestParam<P6>>, p7: NoInfer<RequestParam<P7>>): Promise<void>;
|
||||
sendNotification<P1, P2, P3, P4, P5, P6, P7, P8>(type: NotificationType8<P1, P2, P3, P4, P5, P6, P7, P8>, p1: NoInfer<RequestParam<P1>>, p2: NoInfer<RequestParam<P2>>, p3: NoInfer<RequestParam<P3>>, p4: NoInfer<RequestParam<P4>>, p5: NoInfer<RequestParam<P5>>, p6: NoInfer<RequestParam<P6>>, p7: NoInfer<RequestParam<P7>>, p8: NoInfer<RequestParam<P8>>): Promise<void>;
|
||||
sendNotification<P1, P2, P3, P4, P5, P6, P7, P8, P9>(type: NotificationType9<P1, P2, P3, P4, P5, P6, P7, P8, P9>, p1: NoInfer<RequestParam<P1>>, p2: NoInfer<RequestParam<P2>>, p3: NoInfer<RequestParam<P3>>, p4: NoInfer<RequestParam<P4>>, p5: NoInfer<RequestParam<P5>>, p6: NoInfer<RequestParam<P6>>, p7: NoInfer<RequestParam<P7>>, p8: NoInfer<RequestParam<P8>>, p9: NoInfer<RequestParam<P9>>): Promise<void>;
|
||||
sendNotification(method: string, r0?: ParameterStructures | any, ...rest: any[]): Promise<void>;
|
||||
onNotification(type: NotificationType0, handler: NotificationHandler0): Disposable;
|
||||
onNotification<P>(type: NotificationType<P>, handler: NoInfer<NotificationHandler<P>>): Disposable;
|
||||
onNotification<P1>(type: NotificationType1<P1>, handler: NoInfer<NotificationHandler1<P1>>): Disposable;
|
||||
onNotification<P1, P2>(type: NotificationType2<P1, P2>, handler: NoInfer<NotificationHandler2<P1, P2>>): Disposable;
|
||||
onNotification<P1, P2, P3>(type: NotificationType3<P1, P2, P3>, handler: NoInfer<NotificationHandler3<P1, P2, P3>>): Disposable;
|
||||
onNotification<P1, P2, P3, P4>(type: NotificationType4<P1, P2, P3, P4>, handler: NoInfer<NotificationHandler4<P1, P2, P3, P4>>): Disposable;
|
||||
onNotification<P1, P2, P3, P4, P5>(type: NotificationType5<P1, P2, P3, P4, P5>, handler: NoInfer<NotificationHandler5<P1, P2, P3, P4, P5>>): Disposable;
|
||||
onNotification<P1, P2, P3, P4, P5, P6>(type: NotificationType6<P1, P2, P3, P4, P5, P6>, handler: NoInfer<NotificationHandler6<P1, P2, P3, P4, P5, P6>>): Disposable;
|
||||
onNotification<P1, P2, P3, P4, P5, P6, P7>(type: NotificationType7<P1, P2, P3, P4, P5, P6, P7>, handler: NoInfer<NotificationHandler7<P1, P2, P3, P4, P5, P6, P7>>): Disposable;
|
||||
onNotification<P1, P2, P3, P4, P5, P6, P7, P8>(type: NotificationType8<P1, P2, P3, P4, P5, P6, P7, P8>, handler: NoInfer<NotificationHandler8<P1, P2, P3, P4, P5, P6, P7, P8>>): Disposable;
|
||||
onNotification<P1, P2, P3, P4, P5, P6, P7, P8, P9>(type: NotificationType9<P1, P2, P3, P4, P5, P6, P7, P8, P9>, handler: NoInfer<NotificationHandler9<P1, P2, P3, P4, P5, P6, P7, P8, P9>>): Disposable;
|
||||
onNotification(method: string, handler: GenericNotificationHandler): Disposable;
|
||||
onNotification(handler: StarNotificationHandler): Disposable;
|
||||
onUnhandledNotification: Event<NotificationMessage>;
|
||||
onProgress<P>(type: ProgressType<P>, token: string | number, handler: NoInfer<NotificationHandler<P>>): Disposable;
|
||||
sendProgress<P>(type: ProgressType<P>, token: string | number, value: NoInfer<RequestParam<P>>): Promise<void>;
|
||||
onUnhandledProgress: Event<ProgressParams<any>>;
|
||||
trace(value: Trace, tracer: Tracer, sendNotification?: boolean): Promise<void>;
|
||||
trace(value: Trace, tracer: Tracer, traceOptions?: TraceOptions): Promise<void>;
|
||||
onError: Event<[Error, Message | undefined, number | undefined]>;
|
||||
onClose: Event<void>;
|
||||
listen(): void;
|
||||
end(): void;
|
||||
onDispose: Event<void>;
|
||||
dispose(): void;
|
||||
inspect(): void;
|
||||
}
|
||||
export declare function createMessageConnection(messageReader: MessageReader, messageWriter: MessageWriter, _logger?: Logger, options?: ConnectionOptions): MessageConnection;
|
||||
export {};
|
||||
@@ -0,0 +1,414 @@
|
||||
'use strict'
|
||||
|
||||
const { test } = require('tap')
|
||||
const fs = require('fs')
|
||||
const proxyquire = require('proxyquire')
|
||||
const { file, runTests } = require('./helper')
|
||||
|
||||
const MAX_WRITE = 16 * 1024
|
||||
|
||||
runTests(buildTests)
|
||||
|
||||
function buildTests (test, sync) {
|
||||
// Reset the umask for testing
|
||||
process.umask(0o000)
|
||||
test('retry on EAGAIN', (t) => {
|
||||
t.plan(7)
|
||||
|
||||
const fakeFs = Object.create(fs)
|
||||
fakeFs.write = function (fd, buf, ...args) {
|
||||
t.pass('fake fs.write called')
|
||||
fakeFs.write = fs.write
|
||||
const err = new Error('EAGAIN')
|
||||
err.code = 'EAGAIN'
|
||||
process.nextTick(args.pop(), err)
|
||||
}
|
||||
const SonicBoom = proxyquire('../', {
|
||||
fs: fakeFs
|
||||
})
|
||||
|
||||
const dest = file()
|
||||
const fd = fs.openSync(dest, 'w')
|
||||
const stream = new SonicBoom({ fd, sync: false, minLength: 0 })
|
||||
|
||||
stream.on('ready', () => {
|
||||
t.pass('ready emitted')
|
||||
})
|
||||
|
||||
t.ok(stream.write('hello world\n'))
|
||||
t.ok(stream.write('something else\n'))
|
||||
|
||||
stream.end()
|
||||
|
||||
stream.on('finish', () => {
|
||||
fs.readFile(dest, 'utf8', (err, data) => {
|
||||
t.error(err)
|
||||
t.equal(data, 'hello world\nsomething else\n')
|
||||
})
|
||||
})
|
||||
stream.on('close', () => {
|
||||
t.pass('close emitted')
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
test('emit error on async EAGAIN', (t) => {
|
||||
t.plan(11)
|
||||
|
||||
const fakeFs = Object.create(fs)
|
||||
fakeFs.write = function (fd, buf, ...args) {
|
||||
t.pass('fake fs.write called')
|
||||
fakeFs.write = fs.write
|
||||
const err = new Error('EAGAIN')
|
||||
err.code = 'EAGAIN'
|
||||
process.nextTick(args[args.length - 1], err)
|
||||
}
|
||||
const SonicBoom = proxyquire('../', {
|
||||
fs: fakeFs
|
||||
})
|
||||
|
||||
const dest = file()
|
||||
const fd = fs.openSync(dest, 'w')
|
||||
const stream = new SonicBoom({
|
||||
fd,
|
||||
sync: false,
|
||||
minLength: 12,
|
||||
retryEAGAIN: (err, writeBufferLen, remainingBufferLen) => {
|
||||
t.equal(err.code, 'EAGAIN')
|
||||
t.equal(writeBufferLen, 12)
|
||||
t.equal(remainingBufferLen, 0)
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
stream.on('ready', () => {
|
||||
t.pass('ready emitted')
|
||||
})
|
||||
|
||||
stream.once('error', err => {
|
||||
t.equal(err.code, 'EAGAIN')
|
||||
t.ok(stream.write('something else\n'))
|
||||
})
|
||||
|
||||
t.ok(stream.write('hello world\n'))
|
||||
|
||||
stream.end()
|
||||
|
||||
stream.on('finish', () => {
|
||||
fs.readFile(dest, 'utf8', (err, data) => {
|
||||
t.error(err)
|
||||
t.equal(data, 'hello world\nsomething else\n')
|
||||
})
|
||||
})
|
||||
stream.on('close', () => {
|
||||
t.pass('close emitted')
|
||||
})
|
||||
})
|
||||
|
||||
test('retry on EAGAIN (sync)', (t) => {
|
||||
t.plan(7)
|
||||
|
||||
const fakeFs = Object.create(fs)
|
||||
fakeFs.writeSync = function (fd, buf, enc) {
|
||||
t.pass('fake fs.writeSync called')
|
||||
fakeFs.writeSync = fs.writeSync
|
||||
const err = new Error('EAGAIN')
|
||||
err.code = 'EAGAIN'
|
||||
throw err
|
||||
}
|
||||
const SonicBoom = proxyquire('../', {
|
||||
fs: fakeFs
|
||||
})
|
||||
|
||||
const dest = file()
|
||||
const fd = fs.openSync(dest, 'w')
|
||||
const stream = new SonicBoom({ fd, minLength: 0, sync: true })
|
||||
|
||||
stream.on('ready', () => {
|
||||
t.pass('ready emitted')
|
||||
})
|
||||
|
||||
t.ok(stream.write('hello world\n'))
|
||||
t.ok(stream.write('something else\n'))
|
||||
|
||||
stream.end()
|
||||
|
||||
stream.on('finish', () => {
|
||||
fs.readFile(dest, 'utf8', (err, data) => {
|
||||
t.error(err)
|
||||
t.equal(data, 'hello world\nsomething else\n')
|
||||
})
|
||||
})
|
||||
stream.on('close', () => {
|
||||
t.pass('close emitted')
|
||||
})
|
||||
})
|
||||
|
||||
test('emit error on EAGAIN (sync)', (t) => {
|
||||
t.plan(11)
|
||||
|
||||
const fakeFs = Object.create(fs)
|
||||
fakeFs.writeSync = function (fd, buf, enc) {
|
||||
t.pass('fake fs.writeSync called')
|
||||
fakeFs.writeSync = fs.writeSync
|
||||
const err = new Error('EAGAIN')
|
||||
err.code = 'EAGAIN'
|
||||
throw err
|
||||
}
|
||||
const SonicBoom = proxyquire('../', {
|
||||
fs: fakeFs
|
||||
})
|
||||
|
||||
const dest = file()
|
||||
const fd = fs.openSync(dest, 'w')
|
||||
const stream = new SonicBoom({
|
||||
fd,
|
||||
minLength: 0,
|
||||
sync: true,
|
||||
retryEAGAIN: (err, writeBufferLen, remainingBufferLen) => {
|
||||
t.equal(err.code, 'EAGAIN')
|
||||
t.equal(writeBufferLen, 12)
|
||||
t.equal(remainingBufferLen, 0)
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
stream.on('ready', () => {
|
||||
t.pass('ready emitted')
|
||||
})
|
||||
|
||||
stream.once('error', err => {
|
||||
t.equal(err.code, 'EAGAIN')
|
||||
t.ok(stream.write('something else\n'))
|
||||
})
|
||||
|
||||
t.ok(stream.write('hello world\n'))
|
||||
|
||||
stream.end()
|
||||
|
||||
stream.on('finish', () => {
|
||||
fs.readFile(dest, 'utf8', (err, data) => {
|
||||
t.error(err)
|
||||
t.equal(data, 'hello world\nsomething else\n')
|
||||
})
|
||||
})
|
||||
stream.on('close', () => {
|
||||
t.pass('close emitted')
|
||||
})
|
||||
})
|
||||
|
||||
test('retryEAGAIN receives remaining buffer on async if write fails', (t) => {
|
||||
t.plan(12)
|
||||
|
||||
const fakeFs = Object.create(fs)
|
||||
const SonicBoom = proxyquire('../', {
|
||||
fs: fakeFs
|
||||
})
|
||||
|
||||
const dest = file()
|
||||
const fd = fs.openSync(dest, 'w')
|
||||
const stream = new SonicBoom({
|
||||
fd,
|
||||
sync: false,
|
||||
minLength: 12,
|
||||
retryEAGAIN: (err, writeBufferLen, remainingBufferLen) => {
|
||||
t.equal(err.code, 'EAGAIN')
|
||||
t.equal(writeBufferLen, 12)
|
||||
t.equal(remainingBufferLen, 11)
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
stream.on('ready', () => {
|
||||
t.pass('ready emitted')
|
||||
})
|
||||
|
||||
stream.once('error', err => {
|
||||
t.equal(err.code, 'EAGAIN')
|
||||
t.ok(stream.write('done'))
|
||||
})
|
||||
|
||||
fakeFs.write = function (fd, buf, ...args) {
|
||||
t.pass('fake fs.write called')
|
||||
fakeFs.write = fs.write
|
||||
const err = new Error('EAGAIN')
|
||||
err.code = 'EAGAIN'
|
||||
t.ok(stream.write('sonic boom\n'))
|
||||
process.nextTick(args[args.length - 1], err)
|
||||
}
|
||||
|
||||
t.ok(stream.write('hello world\n'))
|
||||
|
||||
stream.end()
|
||||
|
||||
stream.on('finish', () => {
|
||||
fs.readFile(dest, 'utf8', (err, data) => {
|
||||
t.error(err)
|
||||
t.equal(data, 'hello world\nsonic boom\ndone')
|
||||
})
|
||||
})
|
||||
stream.on('close', () => {
|
||||
t.pass('close emitted')
|
||||
})
|
||||
})
|
||||
|
||||
test('retryEAGAIN receives remaining buffer if exceeds maxWrite', (t) => {
|
||||
t.plan(17)
|
||||
|
||||
const fakeFs = Object.create(fs)
|
||||
const SonicBoom = proxyquire('../', {
|
||||
fs: fakeFs
|
||||
})
|
||||
|
||||
const dest = file()
|
||||
const fd = fs.openSync(dest, 'w')
|
||||
const buf = Buffer.alloc(MAX_WRITE - 2).fill('x').toString() // 1 MB
|
||||
const stream = new SonicBoom({
|
||||
fd,
|
||||
sync: false,
|
||||
minLength: MAX_WRITE - 1,
|
||||
retryEAGAIN: (err, writeBufferLen, remainingBufferLen) => {
|
||||
t.equal(err.code, 'EAGAIN', 'retryEAGAIN received EAGAIN error')
|
||||
t.equal(writeBufferLen, buf.length, 'writeBufferLen === buf.length')
|
||||
t.equal(remainingBufferLen, 23, 'remainingBufferLen === 23')
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
stream.on('ready', () => {
|
||||
t.pass('ready emitted')
|
||||
})
|
||||
|
||||
fakeFs.write = function (fd, buf, ...args) {
|
||||
t.pass('fake fs.write called')
|
||||
const err = new Error('EAGAIN')
|
||||
err.code = 'EAGAIN'
|
||||
process.nextTick(args.pop(), err)
|
||||
}
|
||||
|
||||
fakeFs.writeSync = function (fd, buf, enc) {
|
||||
t.pass('fake fs.write called')
|
||||
const err = new Error('EAGAIN')
|
||||
err.code = 'EAGAIN'
|
||||
throw err
|
||||
}
|
||||
|
||||
t.ok(stream.write(buf), 'write buf')
|
||||
t.notOk(stream.write('hello world\nsonic boom\n'), 'write hello world sonic boom')
|
||||
|
||||
stream.once('error', err => {
|
||||
t.equal(err.code, 'EAGAIN', 'bubbled error should be EAGAIN')
|
||||
|
||||
try {
|
||||
stream.flushSync()
|
||||
} catch (err) {
|
||||
t.equal(err.code, 'EAGAIN', 'thrown error should be EAGAIN')
|
||||
fakeFs.write = fs.write
|
||||
fakeFs.writeSync = fs.writeSync
|
||||
stream.end()
|
||||
}
|
||||
})
|
||||
|
||||
stream.on('finish', () => {
|
||||
t.pass('finish emitted')
|
||||
fs.readFile(dest, 'utf8', (err, data) => {
|
||||
t.error(err)
|
||||
t.equal(data, `${buf}hello world\nsonic boom\n`, 'data on file should match written')
|
||||
})
|
||||
})
|
||||
stream.on('close', () => {
|
||||
t.pass('close emitted')
|
||||
})
|
||||
})
|
||||
|
||||
test('retry on EBUSY', (t) => {
|
||||
t.plan(7)
|
||||
|
||||
const fakeFs = Object.create(fs)
|
||||
fakeFs.write = function (fd, buf, ...args) {
|
||||
t.pass('fake fs.write called')
|
||||
fakeFs.write = fs.write
|
||||
const err = new Error('EBUSY')
|
||||
err.code = 'EBUSY'
|
||||
process.nextTick(args.pop(), err)
|
||||
}
|
||||
const SonicBoom = proxyquire('..', {
|
||||
fs: fakeFs
|
||||
})
|
||||
|
||||
const dest = file()
|
||||
const fd = fs.openSync(dest, 'w')
|
||||
const stream = new SonicBoom({ fd, sync: false, minLength: 0 })
|
||||
|
||||
stream.on('ready', () => {
|
||||
t.pass('ready emitted')
|
||||
})
|
||||
|
||||
t.ok(stream.write('hello world\n'))
|
||||
t.ok(stream.write('something else\n'))
|
||||
|
||||
stream.end()
|
||||
|
||||
stream.on('finish', () => {
|
||||
fs.readFile(dest, 'utf8', (err, data) => {
|
||||
t.error(err)
|
||||
t.equal(data, 'hello world\nsomething else\n')
|
||||
})
|
||||
})
|
||||
stream.on('close', () => {
|
||||
t.pass('close emitted')
|
||||
})
|
||||
})
|
||||
|
||||
test('emit error on async EBUSY', (t) => {
|
||||
t.plan(11)
|
||||
|
||||
const fakeFs = Object.create(fs)
|
||||
fakeFs.write = function (fd, buf, ...args) {
|
||||
t.pass('fake fs.write called')
|
||||
fakeFs.write = fs.write
|
||||
const err = new Error('EBUSY')
|
||||
err.code = 'EBUSY'
|
||||
process.nextTick(args.pop(), err)
|
||||
}
|
||||
const SonicBoom = proxyquire('..', {
|
||||
fs: fakeFs
|
||||
})
|
||||
|
||||
const dest = file()
|
||||
const fd = fs.openSync(dest, 'w')
|
||||
const stream = new SonicBoom({
|
||||
fd,
|
||||
sync: false,
|
||||
minLength: 12,
|
||||
retryEAGAIN: (err, writeBufferLen, remainingBufferLen) => {
|
||||
t.equal(err.code, 'EBUSY')
|
||||
t.equal(writeBufferLen, 12)
|
||||
t.equal(remainingBufferLen, 0)
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
stream.on('ready', () => {
|
||||
t.pass('ready emitted')
|
||||
})
|
||||
|
||||
stream.once('error', err => {
|
||||
t.equal(err.code, 'EBUSY')
|
||||
t.ok(stream.write('something else\n'))
|
||||
})
|
||||
|
||||
t.ok(stream.write('hello world\n'))
|
||||
|
||||
stream.end()
|
||||
|
||||
stream.on('finish', () => {
|
||||
fs.readFile(dest, 'utf8', (err, data) => {
|
||||
t.error(err)
|
||||
t.equal(data, 'hello world\nsomething else\n')
|
||||
})
|
||||
})
|
||||
stream.on('close', () => {
|
||||
t.pass('close emitted')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,2 @@
|
||||
export declare var NewLineKind: any;
|
||||
//# sourceMappingURL=newLineKind.d.ts.map
|
||||
@@ -0,0 +1,22 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Pooya Parsa <pooya@pi0.io>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
function _classApplyDescriptorDestructureSet(e, t) {
|
||||
if (t.set) return "__destrObj" in t || (t.__destrObj = {
|
||||
set value(r) {
|
||||
t.set.call(e, r);
|
||||
}
|
||||
}), t.__destrObj;
|
||||
if (!t.writable) throw new TypeError("attempted to set read only private field");
|
||||
return t;
|
||||
}
|
||||
module.exports = _classApplyDescriptorDestructureSet, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
||||
@@ -0,0 +1,16 @@
|
||||
import { type CurveFn } from './abstract/bls.ts';
|
||||
import { type IField } from './abstract/modular.ts';
|
||||
export declare const bls12_381_Fr: IField<bigint>;
|
||||
/**
|
||||
* bls12-381 pairing-friendly curve.
|
||||
* @example
|
||||
* import { bls12_381 as bls } from '@noble/curves/bls12-381';
|
||||
* // G1 keys, G2 signatures
|
||||
* const privateKey = '67d53f170b908cabb9eb326c3c337762d59289a8fec79f7bc9254b584b73265c';
|
||||
* const message = '64726e3da8';
|
||||
* const publicKey = bls.getPublicKey(privateKey);
|
||||
* const signature = bls.sign(message, privateKey);
|
||||
* const isValid = bls.verify(signature, message, publicKey);
|
||||
*/
|
||||
export declare const bls12_381: CurveFn;
|
||||
//# sourceMappingURL=bls12-381.d.ts.map
|
||||
Reference in New Issue
Block a user