WIP: bootstrap and partial real Solana watcher implementation
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
/// <reference types="../types/index.d.ts" />
|
||||
|
||||
// (c) 2020-present Andrea Giammarchi
|
||||
|
||||
const {parse: $parse, stringify: $stringify} = JSON;
|
||||
const {keys} = Object;
|
||||
|
||||
const Primitive = String; // it could be Number
|
||||
const primitive = 'string'; // it could be 'number'
|
||||
|
||||
const ignore = {};
|
||||
const object = 'object';
|
||||
|
||||
const noop = (_, value) => value;
|
||||
|
||||
const primitives = value => (
|
||||
value instanceof Primitive ? Primitive(value) : value
|
||||
);
|
||||
|
||||
const Primitives = (_, value) => (
|
||||
typeof value === primitive ? new Primitive(value) : value
|
||||
);
|
||||
|
||||
const resolver = (input, lazy, parsed, $) => output => {
|
||||
for (let ke = keys(output), {length} = ke, y = 0; y < length; y++) {
|
||||
const k = ke[y];
|
||||
const value = output[k];
|
||||
if (value instanceof Primitive) {
|
||||
const tmp = input[+value];
|
||||
if (typeof tmp === object && !parsed.has(tmp)) {
|
||||
parsed.add(tmp);
|
||||
output[k] = ignore;
|
||||
lazy.push({ o: output, k, r: tmp });
|
||||
}
|
||||
else
|
||||
output[k] = $.call(output, k, tmp);
|
||||
}
|
||||
else if (output[k] !== ignore)
|
||||
output[k] = $.call(output, k, value);
|
||||
}
|
||||
return output;
|
||||
};
|
||||
|
||||
const set = (known, input, value) => {
|
||||
const index = Primitive(input.push(value) - 1);
|
||||
known.set(value, index);
|
||||
return index;
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a specialized flatted string into a JS value.
|
||||
* @param {string} text
|
||||
* @param {(this: any, key: string, value: any) => any} [reviver]
|
||||
* @returns {any}
|
||||
*/
|
||||
export const parse = (text, reviver) => {
|
||||
const input = $parse(text, Primitives).map(primitives);
|
||||
const $ = reviver || noop;
|
||||
|
||||
let value = input[0];
|
||||
|
||||
if (typeof value === object && value) {
|
||||
const lazy = [];
|
||||
const revive = resolver(input, lazy, new Set, $);
|
||||
value = revive(value);
|
||||
|
||||
let i = 0;
|
||||
while (i < lazy.length) {
|
||||
// it could be a lazy.shift() but that's costly
|
||||
const {o, k, r} = lazy[i++];
|
||||
o[k] = $.call(o, k, revive(r));
|
||||
}
|
||||
}
|
||||
|
||||
return $.call({'': value}, '', value);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a JS value into a specialized flatted string.
|
||||
* @param {any} value
|
||||
* @param {((this: any, key: string, value: any) => any) | (string | number)[] | null | undefined} [replacer]
|
||||
* @param {string | number | undefined} [space]
|
||||
* @returns {string}
|
||||
*/
|
||||
export const stringify = (value, replacer, space) => {
|
||||
const $ = replacer && typeof replacer === object ?
|
||||
(k, v) => (k === '' || -1 < replacer.indexOf(k) ? v : void 0) :
|
||||
(replacer || noop);
|
||||
const known = new Map;
|
||||
const input = [];
|
||||
const output = [];
|
||||
let i = +set(known, input, $.call({'': value}, '', value));
|
||||
let firstRun = !i;
|
||||
while (i < input.length) {
|
||||
firstRun = true;
|
||||
output[i] = $stringify(input[i++], replace, space);
|
||||
}
|
||||
return '[' + output.join(',') + ']';
|
||||
function replace(key, value) {
|
||||
if (firstRun) {
|
||||
firstRun = !firstRun;
|
||||
return value;
|
||||
}
|
||||
const after = $.call(this, key, value);
|
||||
switch (typeof after) {
|
||||
case object:
|
||||
if (after === null) return after;
|
||||
case primitive:
|
||||
return known.get(after) || set(known, input, after);
|
||||
}
|
||||
return after;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a generic value into a JSON serializable object without losing recursion.
|
||||
* @param {any} value
|
||||
* @returns {any}
|
||||
*/
|
||||
export const toJSON = value => $parse(stringify(value));
|
||||
|
||||
/**
|
||||
* Converts a previously serialized object with recursion into a recursive one.
|
||||
* @param {any} value
|
||||
* @returns {any}
|
||||
*/
|
||||
export const fromJSON = value => parse($stringify(value));
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"all": true,
|
||||
"check-coverage": false,
|
||||
"reporter": ["text-summary", "text", "html", "json"],
|
||||
"lines": 86,
|
||||
"statements": 85.93,
|
||||
"functions": 82.43,
|
||||
"branches": 76.06,
|
||||
"exclude": [
|
||||
"coverage",
|
||||
"example",
|
||||
"test"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
/// <reference types="node" />
|
||||
import * as nativeFs from "fs";
|
||||
import picomatch from "picomatch";
|
||||
|
||||
//#region src/api/aborter.d.ts
|
||||
/**
|
||||
* AbortController is not supported on Node 14 so we use this until we can drop
|
||||
* support for Node 14.
|
||||
*/
|
||||
declare class Aborter {
|
||||
aborted: boolean;
|
||||
abort(): void;
|
||||
}
|
||||
//#endregion
|
||||
//#region src/api/queue.d.ts
|
||||
type OnQueueEmptyCallback = (error: Error | null, output: WalkerState) => void;
|
||||
/**
|
||||
* This is a custom stateless queue to track concurrent async fs calls.
|
||||
* It increments a counter whenever a call is queued and decrements it
|
||||
* as soon as it completes. When the counter hits 0, it calls onQueueEmpty.
|
||||
*/
|
||||
declare class Queue {
|
||||
private onQueueEmpty?;
|
||||
count: number;
|
||||
constructor(onQueueEmpty?: OnQueueEmptyCallback | undefined);
|
||||
enqueue(): number;
|
||||
dequeue(error: Error | null, output: WalkerState): void;
|
||||
}
|
||||
//#endregion
|
||||
//#region src/types.d.ts
|
||||
type Counts = {
|
||||
files: number;
|
||||
directories: number;
|
||||
/**
|
||||
* @deprecated use `directories` instead. Will be removed in v7.0.
|
||||
*/
|
||||
dirs: number;
|
||||
};
|
||||
type Group = {
|
||||
directory: string;
|
||||
files: string[];
|
||||
/**
|
||||
* @deprecated use `directory` instead. Will be removed in v7.0.
|
||||
*/
|
||||
dir: string;
|
||||
};
|
||||
type GroupOutput = Group[];
|
||||
type OnlyCountsOutput = Counts;
|
||||
type PathsOutput = string[];
|
||||
type Output = OnlyCountsOutput | PathsOutput | GroupOutput;
|
||||
type FSLike = {
|
||||
readdir: typeof nativeFs.readdir;
|
||||
readdirSync: typeof nativeFs.readdirSync;
|
||||
realpath: typeof nativeFs.realpath;
|
||||
realpathSync: typeof nativeFs.realpathSync;
|
||||
stat: typeof nativeFs.stat;
|
||||
statSync: typeof nativeFs.statSync;
|
||||
};
|
||||
type WalkerState = {
|
||||
root: string;
|
||||
paths: string[];
|
||||
groups: Group[];
|
||||
counts: Counts;
|
||||
options: Options;
|
||||
queue: Queue;
|
||||
controller: Aborter;
|
||||
fs: FSLike;
|
||||
symlinks: Map<string, string>;
|
||||
visited: string[];
|
||||
};
|
||||
type ResultCallback<TOutput extends Output> = (error: Error | null, output: TOutput) => void;
|
||||
type FilterPredicate = (path: string, isDirectory: boolean) => boolean;
|
||||
type ExcludePredicate = (dirName: string, dirPath: string) => boolean;
|
||||
type PathSeparator = "/" | "\\";
|
||||
type Options<TGlobFunction = unknown> = {
|
||||
includeBasePath?: boolean;
|
||||
includeDirs?: boolean;
|
||||
normalizePath?: boolean;
|
||||
maxDepth: number;
|
||||
maxFiles?: number;
|
||||
resolvePaths?: boolean;
|
||||
suppressErrors: boolean;
|
||||
group?: boolean;
|
||||
onlyCounts?: boolean;
|
||||
filters: FilterPredicate[];
|
||||
resolveSymlinks?: boolean;
|
||||
useRealPaths?: boolean;
|
||||
excludeFiles?: boolean;
|
||||
excludeSymlinks?: boolean;
|
||||
exclude?: ExcludePredicate;
|
||||
relativePaths?: boolean;
|
||||
pathSeparator: PathSeparator;
|
||||
signal?: AbortSignal;
|
||||
globFunction?: TGlobFunction;
|
||||
fs?: FSLike;
|
||||
};
|
||||
type GlobMatcher = (test: string) => boolean;
|
||||
type GlobFunction = (glob: string | string[], ...params: unknown[]) => GlobMatcher;
|
||||
type GlobParams<T> = T extends ((globs: string | string[], ...params: infer TParams extends unknown[]) => GlobMatcher) ? TParams : [];
|
||||
//#endregion
|
||||
//#region src/builder/api-builder.d.ts
|
||||
declare class APIBuilder<TReturnType extends Output> {
|
||||
private readonly root;
|
||||
private readonly options;
|
||||
constructor(root: string, options: Options);
|
||||
withPromise(): Promise<TReturnType>;
|
||||
withCallback(cb: ResultCallback<TReturnType>): void;
|
||||
sync(): TReturnType;
|
||||
}
|
||||
//#endregion
|
||||
//#region src/builder/index.d.ts
|
||||
declare class Builder<TReturnType extends Output = PathsOutput, TGlobFunction = typeof picomatch> {
|
||||
private readonly globCache;
|
||||
private options;
|
||||
private globFunction?;
|
||||
constructor(options?: Partial<Options<TGlobFunction>>);
|
||||
group(): Builder<GroupOutput, TGlobFunction>;
|
||||
withPathSeparator(separator: "/" | "\\"): this;
|
||||
withBasePath(): this;
|
||||
withRelativePaths(): this;
|
||||
withDirs(): this;
|
||||
withMaxDepth(depth: number): this;
|
||||
withMaxFiles(limit: number): this;
|
||||
withFullPaths(): this;
|
||||
withErrors(): this;
|
||||
withSymlinks({
|
||||
resolvePaths
|
||||
}?: {
|
||||
resolvePaths?: boolean | undefined;
|
||||
}): this;
|
||||
withAbortSignal(signal: AbortSignal): this;
|
||||
normalize(): this;
|
||||
filter(predicate: FilterPredicate): this;
|
||||
onlyDirs(): this;
|
||||
exclude(predicate: ExcludePredicate): this;
|
||||
onlyCounts(): Builder<OnlyCountsOutput, TGlobFunction>;
|
||||
crawl(root?: string): APIBuilder<TReturnType>;
|
||||
withGlobFunction<TFunc>(fn: TFunc): Builder<TReturnType, TFunc>;
|
||||
/**
|
||||
* @deprecated Pass options using the constructor instead:
|
||||
* ```ts
|
||||
* new fdir(options).crawl("/path/to/root");
|
||||
* ```
|
||||
* This method will be removed in v7.0
|
||||
*/
|
||||
crawlWithOptions(root: string, options: Partial<Options<TGlobFunction>>): APIBuilder<TReturnType>;
|
||||
glob(...patterns: string[]): Builder<TReturnType, TGlobFunction>;
|
||||
globWithOptions(patterns: string[]): Builder<TReturnType, TGlobFunction>;
|
||||
globWithOptions(patterns: string[], ...options: GlobParams<TGlobFunction>): Builder<TReturnType, TGlobFunction>;
|
||||
}
|
||||
//#endregion
|
||||
//#region src/index.d.ts
|
||||
type Fdir = typeof Builder;
|
||||
//#endregion
|
||||
export { Counts, ExcludePredicate, FSLike, Fdir, FilterPredicate, GlobFunction, GlobMatcher, GlobParams, Group, GroupOutput, OnlyCountsOutput, Options, Output, PathSeparator, PathsOutput, ResultCallback, WalkerState, Builder as fdir };
|
||||
@@ -0,0 +1,255 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.readonlynessOptionsDefaults = exports.readonlynessOptionsSchema = void 0;
|
||||
exports.isTypeReadonly = isTypeReadonly;
|
||||
const utils_1 = require("@typescript-eslint/utils");
|
||||
const tsutils = __importStar(require("ts-api-utils"));
|
||||
const ts = __importStar(require("typescript"));
|
||||
const propertyTypes_1 = require("./propertyTypes");
|
||||
const TypeOrValueSpecifier_1 = require("./TypeOrValueSpecifier");
|
||||
var Readonlyness;
|
||||
(function (Readonlyness) {
|
||||
/** the type cannot be handled by the function */
|
||||
Readonlyness[Readonlyness["UnknownType"] = 1] = "UnknownType";
|
||||
/** the type is mutable */
|
||||
Readonlyness[Readonlyness["Mutable"] = 2] = "Mutable";
|
||||
/** the type is readonly */
|
||||
Readonlyness[Readonlyness["Readonly"] = 3] = "Readonly";
|
||||
})(Readonlyness || (Readonlyness = {}));
|
||||
exports.readonlynessOptionsSchema = {
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
allow: TypeOrValueSpecifier_1.typeOrValueSpecifiersSchema,
|
||||
treatMethodsAsReadonly: {
|
||||
type: 'boolean',
|
||||
},
|
||||
},
|
||||
type: 'object',
|
||||
};
|
||||
exports.readonlynessOptionsDefaults = {
|
||||
allow: [],
|
||||
treatMethodsAsReadonly: false,
|
||||
};
|
||||
function hasSymbol(node) {
|
||||
return Object.hasOwn(node, 'symbol');
|
||||
}
|
||||
function isTypeReadonlyArrayOrTuple(program, type, options, seenTypes) {
|
||||
const checker = program.getTypeChecker();
|
||||
function checkTypeArguments(arrayType) {
|
||||
const typeArguments = checker.getTypeArguments(arrayType);
|
||||
// this shouldn't happen in reality as:
|
||||
// - tuples require at least 1 type argument
|
||||
// - ReadonlyArray requires at least 1 type argument
|
||||
/* istanbul ignore if */ if (typeArguments.length === 0) {
|
||||
return Readonlyness.Readonly;
|
||||
}
|
||||
// validate the element types are also readonly
|
||||
if (typeArguments.some(typeArg => isTypeReadonlyRecurser(program, typeArg, options, seenTypes) ===
|
||||
Readonlyness.Mutable)) {
|
||||
return Readonlyness.Mutable;
|
||||
}
|
||||
return Readonlyness.Readonly;
|
||||
}
|
||||
if (checker.isArrayType(type)) {
|
||||
const symbol = utils_1.ESLintUtils.nullThrows(type.getSymbol(), utils_1.ESLintUtils.NullThrowsReasons.MissingToken('symbol', 'array type'));
|
||||
const escapedName = symbol.getEscapedName();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
||||
if (escapedName === 'Array') {
|
||||
return Readonlyness.Mutable;
|
||||
}
|
||||
return checkTypeArguments(type);
|
||||
}
|
||||
if (checker.isTupleType(type)) {
|
||||
if (!type.target.readonly) {
|
||||
return Readonlyness.Mutable;
|
||||
}
|
||||
return checkTypeArguments(type);
|
||||
}
|
||||
return Readonlyness.UnknownType;
|
||||
}
|
||||
function isTypeReadonlyObject(program, type, options, seenTypes) {
|
||||
const checker = program.getTypeChecker();
|
||||
function checkIndexSignature(kind) {
|
||||
const indexInfo = checker.getIndexInfoOfType(type, kind);
|
||||
if (indexInfo) {
|
||||
if (!indexInfo.isReadonly) {
|
||||
return Readonlyness.Mutable;
|
||||
}
|
||||
if (indexInfo.type === type || seenTypes.has(indexInfo.type)) {
|
||||
return Readonlyness.Readonly;
|
||||
}
|
||||
return isTypeReadonlyRecurser(program, indexInfo.type, options, seenTypes);
|
||||
}
|
||||
return Readonlyness.UnknownType;
|
||||
}
|
||||
const properties = type.getProperties();
|
||||
if (properties.length) {
|
||||
// ensure the properties are marked as readonly
|
||||
for (const property of properties) {
|
||||
if (options.treatMethodsAsReadonly) {
|
||||
if (property.valueDeclaration != null &&
|
||||
hasSymbol(property.valueDeclaration) &&
|
||||
tsutils.isSymbolFlagSet(property.valueDeclaration.symbol, ts.SymbolFlags.Method)) {
|
||||
continue;
|
||||
}
|
||||
const declarations = property.getDeclarations();
|
||||
const lastDeclaration = declarations != null && declarations.length > 0
|
||||
? declarations[declarations.length - 1]
|
||||
: undefined;
|
||||
if (lastDeclaration != null &&
|
||||
hasSymbol(lastDeclaration) &&
|
||||
tsutils.isSymbolFlagSet(lastDeclaration.symbol, ts.SymbolFlags.Method)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (tsutils.isPropertyReadonlyInType(type, property.getEscapedName(), checker)) {
|
||||
continue;
|
||||
}
|
||||
const name = ts.getNameOfDeclaration(property.valueDeclaration);
|
||||
if (name && ts.isPrivateIdentifier(name)) {
|
||||
continue;
|
||||
}
|
||||
return Readonlyness.Mutable;
|
||||
}
|
||||
// all properties were readonly
|
||||
// now ensure that all of the values are readonly also.
|
||||
// do this after checking property readonly-ness as a perf optimization,
|
||||
// as we might be able to bail out early due to a mutable property before
|
||||
// doing this deep, potentially expensive check.
|
||||
for (const property of properties) {
|
||||
const propertyType = utils_1.ESLintUtils.nullThrows((0, propertyTypes_1.getTypeOfPropertyOfType)(checker, type, property), utils_1.ESLintUtils.NullThrowsReasons.MissingToken(`property "${property.name}"`, 'type'));
|
||||
// handle recursive types.
|
||||
// we only need this simple check, because a mutable recursive type will break via the above prop readonly check
|
||||
if (seenTypes.has(propertyType)) {
|
||||
continue;
|
||||
}
|
||||
if (isTypeReadonlyRecurser(program, propertyType, options, seenTypes) ===
|
||||
Readonlyness.Mutable) {
|
||||
return Readonlyness.Mutable;
|
||||
}
|
||||
}
|
||||
}
|
||||
const isStringIndexSigReadonly = checkIndexSignature(ts.IndexKind.String);
|
||||
if (isStringIndexSigReadonly === Readonlyness.Mutable) {
|
||||
return isStringIndexSigReadonly;
|
||||
}
|
||||
const isNumberIndexSigReadonly = checkIndexSignature(ts.IndexKind.Number);
|
||||
if (isNumberIndexSigReadonly === Readonlyness.Mutable) {
|
||||
return isNumberIndexSigReadonly;
|
||||
}
|
||||
return Readonlyness.Readonly;
|
||||
}
|
||||
// a helper function to ensure the seenTypes map is always passed down, except by the external caller
|
||||
function isTypeReadonlyRecurser(program, type, options, seenTypes) {
|
||||
const checker = program.getTypeChecker();
|
||||
seenTypes.add(type);
|
||||
// If the type has an alias symbol, check it against the allow list first
|
||||
if (type.aliasSymbol && options.allow) {
|
||||
const aliasSymbol = type.aliasSymbol;
|
||||
const aliasMatches = options.allow.some(specifier => {
|
||||
const specifierName = typeof specifier === 'string' ? specifier : specifier.name;
|
||||
const names = Array.isArray(specifierName)
|
||||
? specifierName
|
||||
: [specifierName];
|
||||
return names.includes(aliasSymbol.getName());
|
||||
});
|
||||
if (aliasMatches) {
|
||||
return Readonlyness.Readonly;
|
||||
}
|
||||
}
|
||||
if ((0, TypeOrValueSpecifier_1.typeMatchesSomeSpecifier)(type, options.allow, program)) {
|
||||
return Readonlyness.Readonly;
|
||||
}
|
||||
if (tsutils.isUnionType(type)) {
|
||||
// all types in the union must be readonly
|
||||
const result = tsutils
|
||||
.unionConstituents(type)
|
||||
.every(t => seenTypes.has(t) ||
|
||||
isTypeReadonlyRecurser(program, t, options, seenTypes) ===
|
||||
Readonlyness.Readonly);
|
||||
const readonlyness = result ? Readonlyness.Readonly : Readonlyness.Mutable;
|
||||
return readonlyness;
|
||||
}
|
||||
if (tsutils.isIntersectionType(type)) {
|
||||
// Special case for handling arrays/tuples (as readonly arrays/tuples always have mutable methods).
|
||||
if (type.types.some(t => checker.isArrayType(t) || checker.isTupleType(t))) {
|
||||
const allReadonlyParts = type.types.every(t => seenTypes.has(t) ||
|
||||
isTypeReadonlyRecurser(program, t, options, seenTypes) ===
|
||||
Readonlyness.Readonly);
|
||||
return allReadonlyParts ? Readonlyness.Readonly : Readonlyness.Mutable;
|
||||
}
|
||||
// Normal case.
|
||||
const isReadonlyObject = isTypeReadonlyObject(program, type, options, seenTypes);
|
||||
if (isReadonlyObject !== Readonlyness.UnknownType) {
|
||||
return isReadonlyObject;
|
||||
}
|
||||
}
|
||||
if (tsutils.isConditionalType(type)) {
|
||||
const result = [type.root.node.trueType, type.root.node.falseType]
|
||||
.map(checker.getTypeFromTypeNode)
|
||||
.every(t => seenTypes.has(t) ||
|
||||
isTypeReadonlyRecurser(program, t, options, seenTypes) ===
|
||||
Readonlyness.Readonly);
|
||||
const readonlyness = result ? Readonlyness.Readonly : Readonlyness.Mutable;
|
||||
return readonlyness;
|
||||
}
|
||||
// all non-object, non-intersection types are readonly.
|
||||
// this should only be primitive types
|
||||
if (!tsutils.isObjectType(type)) {
|
||||
return Readonlyness.Readonly;
|
||||
}
|
||||
// pure function types are readonly
|
||||
if (type.getCallSignatures().length > 0 &&
|
||||
type.getProperties().length === 0) {
|
||||
return Readonlyness.Readonly;
|
||||
}
|
||||
const isReadonlyArray = isTypeReadonlyArrayOrTuple(program, type, options, seenTypes);
|
||||
if (isReadonlyArray !== Readonlyness.UnknownType) {
|
||||
return isReadonlyArray;
|
||||
}
|
||||
const isReadonlyObject = isTypeReadonlyObject(program, type, options, seenTypes);
|
||||
/* istanbul ignore else */ if (isReadonlyObject !== Readonlyness.UnknownType) {
|
||||
return isReadonlyObject;
|
||||
}
|
||||
throw new Error('Unhandled type');
|
||||
}
|
||||
/**
|
||||
* Checks if the given type is readonly
|
||||
*/
|
||||
function isTypeReadonly(program, type, options = exports.readonlynessOptionsDefaults) {
|
||||
return (isTypeReadonlyRecurser(program, type, options, new Set()) ===
|
||||
Readonlyness.Readonly);
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = default_1;
|
||||
const util = __importStar(require("../core/util.cjs"));
|
||||
const error = () => {
|
||||
const Sizable = {
|
||||
string: { unit: "字符", verb: "包含" },
|
||||
file: { unit: "字节", verb: "包含" },
|
||||
array: { unit: "项", verb: "包含" },
|
||||
set: { unit: "项", verb: "包含" },
|
||||
};
|
||||
function getSizing(origin) {
|
||||
return Sizable[origin] ?? null;
|
||||
}
|
||||
const FormatDictionary = {
|
||||
regex: "输入",
|
||||
email: "电子邮件",
|
||||
url: "URL",
|
||||
emoji: "表情符号",
|
||||
uuid: "UUID",
|
||||
uuidv4: "UUIDv4",
|
||||
uuidv6: "UUIDv6",
|
||||
nanoid: "nanoid",
|
||||
guid: "GUID",
|
||||
cuid: "cuid",
|
||||
cuid2: "cuid2",
|
||||
ulid: "ULID",
|
||||
xid: "XID",
|
||||
ksuid: "KSUID",
|
||||
datetime: "ISO日期时间",
|
||||
date: "ISO日期",
|
||||
time: "ISO时间",
|
||||
duration: "ISO时长",
|
||||
ipv4: "IPv4地址",
|
||||
ipv6: "IPv6地址",
|
||||
cidrv4: "IPv4网段",
|
||||
cidrv6: "IPv6网段",
|
||||
base64: "base64编码字符串",
|
||||
base64url: "base64url编码字符串",
|
||||
json_string: "JSON字符串",
|
||||
e164: "E.164号码",
|
||||
jwt: "JWT",
|
||||
template_literal: "输入",
|
||||
};
|
||||
const TypeDictionary = {
|
||||
nan: "NaN",
|
||||
number: "数字",
|
||||
array: "数组",
|
||||
null: "空值(null)",
|
||||
};
|
||||
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 `出现未知的键(key): ${util.joinValues(issue.keys, ", ")}`;
|
||||
case "invalid_key":
|
||||
return `${issue.origin} 中的键(key)无效`;
|
||||
case "invalid_union":
|
||||
return "无效输入";
|
||||
case "invalid_element":
|
||||
return `${issue.origin} 中包含无效值(value)`;
|
||||
default:
|
||||
return `无效输入`;
|
||||
}
|
||||
};
|
||||
};
|
||||
function default_1() {
|
||||
return {
|
||||
localeError: error(),
|
||||
};
|
||||
}
|
||||
module.exports = exports.default;
|
||||
@@ -0,0 +1,5 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
||||
|
||||
script: "npm test"
|
||||
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
// THIS CODE WAS AUTOMATICALLY GENERATED
|
||||
// DO NOT EDIT THIS CODE BY HAND
|
||||
// RUN THE FOLLOWING COMMAND FROM THE WORKSPACE ROOT TO REGENERATE:
|
||||
// npx nx generate-lib repo
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.es2015_proxy = void 0;
|
||||
const base_config_1 = require("./base-config");
|
||||
exports.es2015_proxy = {
|
||||
libs: [],
|
||||
variables: [
|
||||
['ProxyHandler', base_config_1.TYPE],
|
||||
['ProxyConstructor', base_config_1.TYPE],
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,307 @@
|
||||
/**
|
||||
* @fileoverview Rule to check empty newline after "var" statement
|
||||
* @author Gopal Venkatesan
|
||||
* @deprecated in ESLint v4.0.0
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const astUtils = require("./utils/ast-utils");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../types').Rule.RuleModule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "layout",
|
||||
|
||||
docs: {
|
||||
description:
|
||||
"Require or disallow an empty line after variable declarations",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/newline-after-var",
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
enum: ["never", "always"],
|
||||
},
|
||||
],
|
||||
fixable: "whitespace",
|
||||
messages: {
|
||||
expected: "Expected blank line after variable declarations.",
|
||||
unexpected: "Unexpected blank line after variable declarations.",
|
||||
},
|
||||
|
||||
deprecated: {
|
||||
message: "The rule was replaced with a more general rule.",
|
||||
url: "https://eslint.org/blog/2017/06/eslint-v4.0.0-released/",
|
||||
deprecatedSince: "4.0.0",
|
||||
availableUntil: "11.0.0",
|
||||
replacedBy: [
|
||||
{
|
||||
message: "The new rule moved to a plugin.",
|
||||
url: "https://eslint.org/docs/latest/rules/padding-line-between-statements#examples",
|
||||
plugin: {
|
||||
name: "@stylistic/eslint-plugin",
|
||||
url: "https://eslint.style",
|
||||
},
|
||||
rule: {
|
||||
name: "padding-line-between-statements",
|
||||
url: "https://eslint.style/rules/padding-line-between-statements",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const sourceCode = context.sourceCode;
|
||||
|
||||
// Default `mode` to "always".
|
||||
const mode = context.options[0] === "never" ? "never" : "always";
|
||||
|
||||
// Cache starting and ending line numbers of comments for faster lookup
|
||||
const commentEndLine = sourceCode
|
||||
.getAllComments()
|
||||
.reduce((result, token) => {
|
||||
result[token.loc.start.line] = token.loc.end.line;
|
||||
return result;
|
||||
}, {});
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Gets a token from the given node to compare line to the next statement.
|
||||
*
|
||||
* In general, the token is the last token of the node. However, the token is the second last token if the following conditions satisfy.
|
||||
*
|
||||
* - The last token is semicolon.
|
||||
* - The semicolon is on a different line from the previous token of the semicolon.
|
||||
*
|
||||
* This behavior would address semicolon-less style code. e.g.:
|
||||
*
|
||||
* var foo = 1
|
||||
*
|
||||
* ;(a || b).doSomething()
|
||||
* @param {ASTNode} node The node to get.
|
||||
* @returns {Token} The token to compare line to the next statement.
|
||||
*/
|
||||
function getLastToken(node) {
|
||||
const lastToken = sourceCode.getLastToken(node);
|
||||
|
||||
if (lastToken.type === "Punctuator" && lastToken.value === ";") {
|
||||
const prevToken = sourceCode.getTokenBefore(lastToken);
|
||||
|
||||
if (prevToken.loc.end.line !== lastToken.loc.start.line) {
|
||||
return prevToken;
|
||||
}
|
||||
}
|
||||
|
||||
return lastToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if provided keyword is a variable declaration
|
||||
* @private
|
||||
* @param {string} keyword keyword to test
|
||||
* @returns {boolean} True if `keyword` is a type of var
|
||||
*/
|
||||
function isVar(keyword) {
|
||||
return (
|
||||
keyword === "var" || keyword === "let" || keyword === "const"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if provided keyword is a variant of for specifiers
|
||||
* @private
|
||||
* @param {string} keyword keyword to test
|
||||
* @returns {boolean} True if `keyword` is a variant of for specifier
|
||||
*/
|
||||
function isForTypeSpecifier(keyword) {
|
||||
return (
|
||||
keyword === "ForStatement" ||
|
||||
keyword === "ForInStatement" ||
|
||||
keyword === "ForOfStatement"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if provided keyword is an export specifiers
|
||||
* @private
|
||||
* @param {string} nodeType nodeType to test
|
||||
* @returns {boolean} True if `nodeType` is an export specifier
|
||||
*/
|
||||
function isExportSpecifier(nodeType) {
|
||||
return (
|
||||
nodeType === "ExportNamedDeclaration" ||
|
||||
nodeType === "ExportSpecifier" ||
|
||||
nodeType === "ExportDefaultDeclaration" ||
|
||||
nodeType === "ExportAllDeclaration"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if provided node is the last of their parent block.
|
||||
* @private
|
||||
* @param {ASTNode} node node to test
|
||||
* @returns {boolean} True if `node` is last of their parent block.
|
||||
*/
|
||||
function isLastNode(node) {
|
||||
const token = sourceCode.getTokenAfter(node);
|
||||
|
||||
return (
|
||||
!token || (token.type === "Punctuator" && token.value === "}")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the last line of a group of consecutive comments
|
||||
* @param {number} commentStartLine The starting line of the group
|
||||
* @returns {number} The number of the last comment line of the group
|
||||
*/
|
||||
function getLastCommentLineOfBlock(commentStartLine) {
|
||||
const currentCommentEnd = commentEndLine[commentStartLine];
|
||||
|
||||
return commentEndLine[currentCommentEnd + 1]
|
||||
? getLastCommentLineOfBlock(currentCommentEnd + 1)
|
||||
: currentCommentEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a token starts more than one line after a comment ends
|
||||
* @param {token} token The token being checked
|
||||
* @param {integer} commentStartLine The line number on which the comment starts
|
||||
* @returns {boolean} True if `token` does not start immediately after a comment
|
||||
*/
|
||||
function hasBlankLineAfterComment(token, commentStartLine) {
|
||||
return (
|
||||
token.loc.start.line >
|
||||
getLastCommentLineOfBlock(commentStartLine) + 1
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that a blank line exists after a variable declaration when mode is
|
||||
* set to "always", or checks that there is no blank line when mode is set
|
||||
* to "never"
|
||||
* @private
|
||||
* @param {ASTNode} node `VariableDeclaration` node to test
|
||||
* @returns {void}
|
||||
*/
|
||||
function checkForBlankLine(node) {
|
||||
/*
|
||||
* lastToken is the last token on the node's line. It will usually also be the last token of the node, but it will
|
||||
* sometimes be second-last if there is a semicolon on a different line.
|
||||
*/
|
||||
const lastToken = getLastToken(node),
|
||||
/*
|
||||
* If lastToken is the last token of the node, nextToken should be the token after the node. Otherwise, nextToken
|
||||
* is the last token of the node.
|
||||
*/
|
||||
nextToken =
|
||||
lastToken === sourceCode.getLastToken(node)
|
||||
? sourceCode.getTokenAfter(node)
|
||||
: sourceCode.getLastToken(node),
|
||||
nextLineNum = lastToken.loc.end.line + 1;
|
||||
|
||||
// Ignore if there is no following statement
|
||||
if (!nextToken) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ignore if parent of node is a for variant
|
||||
if (isForTypeSpecifier(node.parent.type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ignore if parent of node is an export specifier
|
||||
if (isExportSpecifier(node.parent.type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Some coding styles use multiple `var` statements, so do nothing if
|
||||
* the next token is a `var` statement.
|
||||
*/
|
||||
if (nextToken.type === "Keyword" && isVar(nextToken.value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ignore if it is last statement in a block
|
||||
if (isLastNode(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Next statement is not a `var`...
|
||||
const noNextLineToken = nextToken.loc.start.line > nextLineNum;
|
||||
const hasNextLineComment =
|
||||
typeof commentEndLine[nextLineNum] !== "undefined";
|
||||
|
||||
if (mode === "never" && noNextLineToken && !hasNextLineComment) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: "unexpected",
|
||||
fix(fixer) {
|
||||
const linesBetween = sourceCode
|
||||
.getText()
|
||||
.slice(lastToken.range[1], nextToken.range[0])
|
||||
.split(astUtils.LINEBREAK_MATCHER);
|
||||
|
||||
return fixer.replaceTextRange(
|
||||
[lastToken.range[1], nextToken.range[0]],
|
||||
`${linesBetween.slice(0, -1).join("")}\n${linesBetween.at(-1)}`,
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Token on the next line, or comment without blank line
|
||||
if (
|
||||
mode === "always" &&
|
||||
(!noNextLineToken ||
|
||||
(hasNextLineComment &&
|
||||
!hasBlankLineAfterComment(nextToken, nextLineNum)))
|
||||
) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: "expected",
|
||||
fix(fixer) {
|
||||
if (
|
||||
(noNextLineToken
|
||||
? getLastCommentLineOfBlock(nextLineNum)
|
||||
: lastToken.loc.end.line) ===
|
||||
nextToken.loc.start.line
|
||||
) {
|
||||
return fixer.insertTextBefore(nextToken, "\n\n");
|
||||
}
|
||||
|
||||
return fixer.insertTextBeforeRange(
|
||||
[
|
||||
nextToken.range[0] - nextToken.loc.start.column,
|
||||
nextToken.range[1],
|
||||
],
|
||||
"\n",
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Public
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
return {
|
||||
VariableDeclaration: checkForBlankLine,
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"reg": {
|
||||
"name": "reg",
|
||||
"browser": "IE 11.0.0 (Windows 7 0.0.0)",
|
||||
"suite": "escape-long",
|
||||
"hz": 376419.7269868499,
|
||||
"success": true,
|
||||
"fastest": false,
|
||||
"rme": 0.02384499571699006,
|
||||
"rhz": 0.5037035677866308,
|
||||
"sampleSize": 169
|
||||
},
|
||||
"fn if": {
|
||||
"name": "fn if",
|
||||
"browser": "IE 11.0.0 (Windows 7 0.0.0)",
|
||||
"suite": "escape-long",
|
||||
"hz": 135765.75434799597,
|
||||
"success": true,
|
||||
"fastest": false,
|
||||
"rme": 0.014645250447295578,
|
||||
"rhz": 0.18167404613923935,
|
||||
"sampleSize": 172
|
||||
},
|
||||
"fn if reverse": {
|
||||
"name": "fn if reverse",
|
||||
"browser": "IE 11.0.0 (Windows 7 0.0.0)",
|
||||
"suite": "escape-long",
|
||||
"hz": 71111.50057399167,
|
||||
"success": true,
|
||||
"fastest": false,
|
||||
"rme": 0.03988751428801817,
|
||||
"rhz": 0.09515738411614111,
|
||||
"sampleSize": 169
|
||||
},
|
||||
"escape31": {
|
||||
"name": "escape31",
|
||||
"browser": "IE 11.0.0 (Windows 7 0.0.0)",
|
||||
"suite": "escape-long",
|
||||
"hz": 139727.09470691156,
|
||||
"success": true,
|
||||
"fastest": false,
|
||||
"rme": 0.019847762101041267,
|
||||
"rhz": 0.18697488753768354,
|
||||
"sampleSize": 161
|
||||
},
|
||||
"native": {
|
||||
"name": "native",
|
||||
"browser": "IE 11.0.0 (Windows 7 0.0.0)",
|
||||
"suite": "escape-long",
|
||||
"hz": 747304.0714023721,
|
||||
"success": true,
|
||||
"fastest": true,
|
||||
"rme": 0.01350595023982867,
|
||||
"rhz": 1,
|
||||
"sampleSize": 167
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABLITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference no-default-lib="true"/>
|
||||
|
||||
/// <reference lib="es2016" />
|
||||
/// <reference lib="es2017.object" />
|
||||
/// <reference lib="es2017.sharedmemory" />
|
||||
/// <reference lib="es2017.string" />
|
||||
/// <reference lib="es2017.intl" />
|
||||
/// <reference lib="es2017.typedarrays" />
|
||||
/// <reference lib="es2017.date" />
|
||||
@@ -0,0 +1,135 @@
|
||||
# Redaction
|
||||
|
||||
> Redaction is not supported in the browser [#670](https://github.com/pinojs/pino/issues/670)
|
||||
|
||||
To redact sensitive information, supply paths to keys that hold sensitive data
|
||||
using the `redact` option. Note that paths that contain hyphens need to use
|
||||
brackets to access the hyphenated property:
|
||||
|
||||
```js
|
||||
const logger = require('.')({
|
||||
redact: ['key', 'path.to.key', 'stuff.thats[*].secret', 'path["with-hyphen"]']
|
||||
})
|
||||
|
||||
logger.info({
|
||||
key: 'will be redacted',
|
||||
path: {
|
||||
to: {key: 'sensitive', another: 'thing'}
|
||||
},
|
||||
stuff: {
|
||||
thats: [
|
||||
{secret: 'will be redacted', logme: 'will be logged'},
|
||||
{secret: 'as will this', logme: 'as will this'}
|
||||
]
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
This will output:
|
||||
|
||||
```JSON
|
||||
{"level":30,"time":1527777350011,"pid":3186,"hostname":"Davids-MacBook-Pro-3.local","key":"[Redacted]","path":{"to":{"key":"[Redacted]","another":"thing"}},"stuff":{"thats":[{"secret":"[Redacted]","logme":"will be logged"},{"secret":"[Redacted]","logme":"as will this"}]}}
|
||||
```
|
||||
|
||||
The `redact` option can take an array (as shown in the above example) or
|
||||
an object. This allows control over *how* information is redacted.
|
||||
|
||||
For instance, setting the censor:
|
||||
|
||||
```js
|
||||
const logger = require('.')({
|
||||
redact: {
|
||||
paths: ['key', 'path.to.key', 'stuff.thats[*].secret'],
|
||||
censor: '**GDPR COMPLIANT**'
|
||||
}
|
||||
})
|
||||
|
||||
logger.info({
|
||||
key: 'will be redacted',
|
||||
path: {
|
||||
to: {key: 'sensitive', another: 'thing'}
|
||||
},
|
||||
stuff: {
|
||||
thats: [
|
||||
{secret: 'will be redacted', logme: 'will be logged'},
|
||||
{secret: 'as will this', logme: 'as will this'}
|
||||
]
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
This will output:
|
||||
|
||||
```JSON
|
||||
{"level":30,"time":1527778563934,"pid":3847,"hostname":"Davids-MacBook-Pro-3.local","key":"**GDPR COMPLIANT**","path":{"to":{"key":"**GDPR COMPLIANT**","another":"thing"}},"stuff":{"thats":[{"secret":"**GDPR COMPLIANT**","logme":"will be logged"},{"secret":"**GDPR COMPLIANT**","logme":"as will this"}]}}
|
||||
```
|
||||
|
||||
The `redact.remove` option also allows for the key and value to be removed from output:
|
||||
|
||||
```js
|
||||
const logger = require('.')({
|
||||
redact: {
|
||||
paths: ['key', 'path.to.key', 'stuff.thats[*].secret'],
|
||||
remove: true
|
||||
}
|
||||
})
|
||||
|
||||
logger.info({
|
||||
key: 'will be redacted',
|
||||
path: {
|
||||
to: {key: 'sensitive', another: 'thing'}
|
||||
},
|
||||
stuff: {
|
||||
thats: [
|
||||
{secret: 'will be redacted', logme: 'will be logged'},
|
||||
{secret: 'as will this', logme: 'as will this'}
|
||||
]
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
This will output
|
||||
|
||||
```JSON
|
||||
{"level":30,"time":1527782356751,"pid":5758,"hostname":"Davids-MacBook-Pro-3.local","path":{"to":{"another":"thing"}},"stuff":{"thats":[{"logme":"will be logged"},{"logme":"as will this"}]}}
|
||||
```
|
||||
|
||||
See [pino options in API](/docs/api.md#redact-array-object) for `redact` API details.
|
||||
|
||||
<a name="paths"></a>
|
||||
## Path Syntax
|
||||
|
||||
The syntax for paths supplied to the `redact` option conform to the syntax in path lookups
|
||||
in standard ECMAScript, with two additions:
|
||||
|
||||
* paths may start with bracket notation
|
||||
* paths may contain the asterisk `*` to denote a wildcard
|
||||
* paths are **case sensitive**
|
||||
|
||||
By way of example, the following are all valid paths:
|
||||
|
||||
* `a.b.c`
|
||||
* `a["b-c"].d`
|
||||
* `["a-b"].c`
|
||||
* `a.b.*`
|
||||
* `a[*].b`
|
||||
|
||||
## Overhead
|
||||
|
||||
Pino's redaction functionality is built on top of [`fast-redact`](https://github.com/davidmarkclements/fast-redact)
|
||||
which adds about 2% overhead to `JSON.stringify` when using paths without wildcards.
|
||||
|
||||
When used with pino logger with a single redacted path, any overhead is within noise -
|
||||
a way to deterministically measure its effect has not been found. This is because it is not a bottleneck.
|
||||
|
||||
However, wildcard redaction does carry a non-trivial cost relative to explicitly declaring the keys
|
||||
(50% in a case where four keys are redacted across two objects). See
|
||||
the [`fast-redact` benchmarks](https://github.com/davidmarkclements/fast-redact#benchmarks) for details.
|
||||
|
||||
## Safety
|
||||
|
||||
The `redact` option is intended as an initialization time configuration option.
|
||||
Path strings must not originate from user input.
|
||||
The `fast-redact` module uses a VM context to syntax check the paths, user input
|
||||
should never be combined with such an approach. See the [`fast-redact` Caveat](https://github.com/davidmarkclements/fast-redact#caveat)
|
||||
and the [`fast-redact` Approach](https://github.com/davidmarkclements/fast-redact#approach) for in-depth information.
|
||||
@@ -0,0 +1,33 @@
|
||||
import type { TSESLint } from '@typescript-eslint/utils';
|
||||
export type Options = [
|
||||
{
|
||||
/**
|
||||
* If `true`, allow `default` cases on switch statements with exhaustive
|
||||
* cases.
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
allowDefaultCaseForExhaustiveSwitch?: boolean;
|
||||
/**
|
||||
* If `true`, require a `default` clause for switches on non-union types.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
requireDefaultForNonUnion?: boolean;
|
||||
/**
|
||||
* Regular expression for a comment that can indicate an intentionally omitted default case.
|
||||
*/
|
||||
defaultCaseCommentPattern?: string;
|
||||
/**
|
||||
* If `true`, the `default` clause is used to determine whether the switch statement is exhaustive for union types.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
considerDefaultExhaustiveForUnions?: boolean;
|
||||
}
|
||||
];
|
||||
export type MessageIds = 'addMissingCases' | 'dangerousDefaultCase' | 'switchIsNotExhaustive';
|
||||
declare const _default: TSESLint.RuleModule<MessageIds, Options, import("../../rules").ESLintPluginDocs, TSESLint.RuleListener> & {
|
||||
name: string;
|
||||
};
|
||||
export default _default;
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,84 @@
|
||||
{
|
||||
"name": "@solana/errors",
|
||||
"version": "2.3.0",
|
||||
"description": "Throw, identify, and decode Solana JavaScript errors",
|
||||
"exports": {
|
||||
"edge-light": {
|
||||
"import": "./dist/index.node.mjs",
|
||||
"require": "./dist/index.node.cjs"
|
||||
},
|
||||
"workerd": {
|
||||
"import": "./dist/index.node.mjs",
|
||||
"require": "./dist/index.node.cjs"
|
||||
},
|
||||
"browser": {
|
||||
"import": "./dist/index.browser.mjs",
|
||||
"require": "./dist/index.browser.cjs"
|
||||
},
|
||||
"node": {
|
||||
"import": "./dist/index.node.mjs",
|
||||
"require": "./dist/index.node.cjs"
|
||||
},
|
||||
"react-native": "./dist/index.native.mjs",
|
||||
"types": "./dist/types/index.d.ts"
|
||||
},
|
||||
"browser": {
|
||||
"./dist/index.node.cjs": "./dist/index.browser.cjs",
|
||||
"./dist/index.node.mjs": "./dist/index.browser.mjs"
|
||||
},
|
||||
"main": "./dist/index.node.cjs",
|
||||
"module": "./dist/index.node.mjs",
|
||||
"react-native": "./dist/index.native.mjs",
|
||||
"types": "./dist/types/index.d.ts",
|
||||
"type": "commonjs",
|
||||
"files": [
|
||||
"./dist/"
|
||||
],
|
||||
"sideEffects": false,
|
||||
"keywords": [
|
||||
"blockchain",
|
||||
"solana",
|
||||
"web3"
|
||||
],
|
||||
"bin": "./bin/cli.mjs",
|
||||
"author": "Solana Labs Maintainers <maintainers@solanalabs.com>",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/anza-xyz/kit"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/anza-xyz/kit/issues"
|
||||
},
|
||||
"browserslist": [
|
||||
"supports bigint and not dead",
|
||||
"maintained node versions"
|
||||
],
|
||||
"dependencies": {
|
||||
"chalk": "^5.4.1",
|
||||
"commander": "^14.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=5.3.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.18.0"
|
||||
},
|
||||
"scripts": {
|
||||
"compile:docs": "typedoc",
|
||||
"compile:js": "tsup --config build-scripts/tsup.config.package.ts && tsup src/cli.ts --define.__NODEJS__ true --format esm --treeshake",
|
||||
"compile:typedefs": "tsc -p ./tsconfig.declarations.json",
|
||||
"dev": "jest -c ../../node_modules/@solana/test-config/jest-dev.config.ts --rootDir . --watch",
|
||||
"publish-impl": "npm view $npm_package_name@$npm_package_version > /dev/null 2>&1 || (pnpm publish --tag ${PUBLISH_TAG:-canary} --access public --no-git-checks && (([ \"$PUBLISH_TAG\" != \"canary\" ] && pnpm dist-tag add $npm_package_name@$npm_package_version latest) || true))",
|
||||
"publish-packages": "pnpm prepublishOnly && pnpm publish-impl",
|
||||
"style:fix": "pnpm eslint --fix src && pnpm prettier --log-level warn --ignore-unknown --write ./*",
|
||||
"test:lint": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-lint.config.ts --rootDir . --silent",
|
||||
"test:prettier": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-prettier.config.ts --rootDir . --silent",
|
||||
"test:treeshakability:browser": "agadoo dist/index.browser.mjs",
|
||||
"test:treeshakability:native": "agadoo dist/index.native.mjs",
|
||||
"test:treeshakability:node": "agadoo dist/index.node.mjs",
|
||||
"test:typecheck": "tsc --noEmit",
|
||||
"test:unit:browser": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-unit.config.browser.ts --rootDir . --silent",
|
||||
"test:unit:node": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-unit.config.node.ts --rootDir . --silent"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
# shebang-command [](https://travis-ci.org/kevva/shebang-command)
|
||||
|
||||
> Get the command from a shebang
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install shebang-command
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const shebangCommand = require('shebang-command');
|
||||
|
||||
shebangCommand('#!/usr/bin/env node');
|
||||
//=> 'node'
|
||||
|
||||
shebangCommand('#!/bin/bash');
|
||||
//=> 'bash'
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### shebangCommand(string)
|
||||
|
||||
#### string
|
||||
|
||||
Type: `string`
|
||||
|
||||
String containing a shebang.
|
||||
@@ -0,0 +1,60 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isPossiblyTruthy = exports.isPossiblyFalsy = void 0;
|
||||
const tsutils = __importStar(require("ts-api-utils"));
|
||||
const ts = __importStar(require("typescript"));
|
||||
const getValueOfLiteralType_1 = require("./getValueOfLiteralType");
|
||||
// Truthiness utilities
|
||||
const isTruthyLiteral = (type) => tsutils.isTrueLiteralType(type) ||
|
||||
(type.isLiteral() && !!(0, getValueOfLiteralType_1.getValueOfLiteralType)(type));
|
||||
const isPossiblyFalsy = (type) => tsutils
|
||||
.unionConstituents(type)
|
||||
// Intersections like `string & {}` can also be possibly falsy,
|
||||
// requiring us to look into the intersection.
|
||||
.flatMap(type => tsutils.intersectionConstituents(type))
|
||||
// PossiblyFalsy flag includes literal values, so exclude ones that
|
||||
// are definitely truthy
|
||||
.filter(t => !isTruthyLiteral(t))
|
||||
.some(type => tsutils.isTypeFlagSet(type, ts.TypeFlags.PossiblyFalsy));
|
||||
exports.isPossiblyFalsy = isPossiblyFalsy;
|
||||
const isPossiblyTruthy = (type) => tsutils
|
||||
.unionConstituents(type)
|
||||
.map(type => tsutils.intersectionConstituents(type))
|
||||
.some(intersectionParts =>
|
||||
// It is possible to define intersections that are always falsy,
|
||||
// like `"" & { __brand: string }`.
|
||||
intersectionParts.every(type => !tsutils.isFalsyType(type)));
|
||||
exports.isPossiblyTruthy = isPossiblyTruthy;
|
||||
@@ -0,0 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
const neostandard = require('neostandard')
|
||||
|
||||
module.exports = neostandard({
|
||||
ignores: neostandard.resolveIgnoresFromGitignore(),
|
||||
})
|
||||
@@ -0,0 +1,48 @@
|
||||
# estree-walker
|
||||
|
||||
Simple utility for walking an [ESTree](https://github.com/estree/estree)-compliant AST, such as one generated by [acorn](https://github.com/marijnh/acorn).
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
npm i estree-walker
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
var walk = require('estree-walker').walk;
|
||||
var acorn = require('acorn');
|
||||
|
||||
ast = acorn.parse(sourceCode, options); // https://github.com/acornjs/acorn
|
||||
|
||||
walk(ast, {
|
||||
enter(node, parent, prop, index) {
|
||||
// some code happens
|
||||
},
|
||||
leave(node, parent, prop, index) {
|
||||
// some code happens
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Inside the `enter` function, calling `this.skip()` will prevent the node's children being walked, or the `leave` function (which is optional) being called.
|
||||
|
||||
Call `this.replace(new_node)` in either `enter` or `leave` to replace the current node with a new one.
|
||||
|
||||
Call `this.remove()` in either `enter` or `leave` to remove the current node.
|
||||
|
||||
## Why not use estraverse?
|
||||
|
||||
The ESTree spec is evolving to accommodate ES6/7. I've had a couple of experiences where [estraverse](https://github.com/estools/estraverse) was unable to handle an AST generated by recent versions of acorn, because it hard-codes visitor keys.
|
||||
|
||||
estree-walker, by contrast, simply enumerates a node's properties to find child nodes (and child lists of nodes), and is therefore resistant to spec changes. It's also much smaller. (The performance, if you're wondering, is basically identical.)
|
||||
|
||||
None of which should be taken as criticism of estraverse, which has more features and has been battle-tested in many more situations, and for which I'm very grateful.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
@@ -0,0 +1,247 @@
|
||||
"use strict";
|
||||
// THIS CODE WAS AUTOMATICALLY GENERATED
|
||||
// DO NOT EDIT THIS CODE BY HAND
|
||||
// RUN THE FOLLOWING COMMAND FROM THE WORKSPACE ROOT TO REGENERATE:
|
||||
// npx nx generate-lib repo
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.lib = void 0;
|
||||
const decorators_1 = require("./decorators");
|
||||
const decorators_legacy_1 = require("./decorators.legacy");
|
||||
const dom_1 = require("./dom");
|
||||
const dom_asynciterable_1 = require("./dom.asynciterable");
|
||||
const dom_iterable_1 = require("./dom.iterable");
|
||||
const es5_1 = require("./es5");
|
||||
const es6_1 = require("./es6");
|
||||
const es7_1 = require("./es7");
|
||||
const es2015_1 = require("./es2015");
|
||||
const es2015_collection_1 = require("./es2015.collection");
|
||||
const es2015_core_1 = require("./es2015.core");
|
||||
const es2015_generator_1 = require("./es2015.generator");
|
||||
const es2015_iterable_1 = require("./es2015.iterable");
|
||||
const es2015_promise_1 = require("./es2015.promise");
|
||||
const es2015_proxy_1 = require("./es2015.proxy");
|
||||
const es2015_reflect_1 = require("./es2015.reflect");
|
||||
const es2015_symbol_1 = require("./es2015.symbol");
|
||||
const es2015_symbol_wellknown_1 = require("./es2015.symbol.wellknown");
|
||||
const es2016_1 = require("./es2016");
|
||||
const es2016_array_include_1 = require("./es2016.array.include");
|
||||
const es2016_full_1 = require("./es2016.full");
|
||||
const es2016_intl_1 = require("./es2016.intl");
|
||||
const es2017_1 = require("./es2017");
|
||||
const es2017_arraybuffer_1 = require("./es2017.arraybuffer");
|
||||
const es2017_date_1 = require("./es2017.date");
|
||||
const es2017_full_1 = require("./es2017.full");
|
||||
const es2017_intl_1 = require("./es2017.intl");
|
||||
const es2017_object_1 = require("./es2017.object");
|
||||
const es2017_sharedmemory_1 = require("./es2017.sharedmemory");
|
||||
const es2017_string_1 = require("./es2017.string");
|
||||
const es2017_typedarrays_1 = require("./es2017.typedarrays");
|
||||
const es2018_1 = require("./es2018");
|
||||
const es2018_asyncgenerator_1 = require("./es2018.asyncgenerator");
|
||||
const es2018_asynciterable_1 = require("./es2018.asynciterable");
|
||||
const es2018_full_1 = require("./es2018.full");
|
||||
const es2018_intl_1 = require("./es2018.intl");
|
||||
const es2018_promise_1 = require("./es2018.promise");
|
||||
const es2018_regexp_1 = require("./es2018.regexp");
|
||||
const es2019_1 = require("./es2019");
|
||||
const es2019_array_1 = require("./es2019.array");
|
||||
const es2019_full_1 = require("./es2019.full");
|
||||
const es2019_intl_1 = require("./es2019.intl");
|
||||
const es2019_object_1 = require("./es2019.object");
|
||||
const es2019_string_1 = require("./es2019.string");
|
||||
const es2019_symbol_1 = require("./es2019.symbol");
|
||||
const es2020_1 = require("./es2020");
|
||||
const es2020_bigint_1 = require("./es2020.bigint");
|
||||
const es2020_date_1 = require("./es2020.date");
|
||||
const es2020_full_1 = require("./es2020.full");
|
||||
const es2020_intl_1 = require("./es2020.intl");
|
||||
const es2020_number_1 = require("./es2020.number");
|
||||
const es2020_promise_1 = require("./es2020.promise");
|
||||
const es2020_sharedmemory_1 = require("./es2020.sharedmemory");
|
||||
const es2020_string_1 = require("./es2020.string");
|
||||
const es2020_symbol_wellknown_1 = require("./es2020.symbol.wellknown");
|
||||
const es2021_1 = require("./es2021");
|
||||
const es2021_full_1 = require("./es2021.full");
|
||||
const es2021_intl_1 = require("./es2021.intl");
|
||||
const es2021_promise_1 = require("./es2021.promise");
|
||||
const es2021_string_1 = require("./es2021.string");
|
||||
const es2021_weakref_1 = require("./es2021.weakref");
|
||||
const es2022_1 = require("./es2022");
|
||||
const es2022_array_1 = require("./es2022.array");
|
||||
const es2022_error_1 = require("./es2022.error");
|
||||
const es2022_full_1 = require("./es2022.full");
|
||||
const es2022_intl_1 = require("./es2022.intl");
|
||||
const es2022_object_1 = require("./es2022.object");
|
||||
const es2022_regexp_1 = require("./es2022.regexp");
|
||||
const es2022_string_1 = require("./es2022.string");
|
||||
const es2023_1 = require("./es2023");
|
||||
const es2023_array_1 = require("./es2023.array");
|
||||
const es2023_collection_1 = require("./es2023.collection");
|
||||
const es2023_full_1 = require("./es2023.full");
|
||||
const es2023_intl_1 = require("./es2023.intl");
|
||||
const es2024_1 = require("./es2024");
|
||||
const es2024_arraybuffer_1 = require("./es2024.arraybuffer");
|
||||
const es2024_collection_1 = require("./es2024.collection");
|
||||
const es2024_full_1 = require("./es2024.full");
|
||||
const es2024_object_1 = require("./es2024.object");
|
||||
const es2024_promise_1 = require("./es2024.promise");
|
||||
const es2024_regexp_1 = require("./es2024.regexp");
|
||||
const es2024_sharedmemory_1 = require("./es2024.sharedmemory");
|
||||
const es2024_string_1 = require("./es2024.string");
|
||||
const es2025_1 = require("./es2025");
|
||||
const es2025_collection_1 = require("./es2025.collection");
|
||||
const es2025_float16_1 = require("./es2025.float16");
|
||||
const es2025_full_1 = require("./es2025.full");
|
||||
const es2025_intl_1 = require("./es2025.intl");
|
||||
const es2025_iterator_1 = require("./es2025.iterator");
|
||||
const es2025_promise_1 = require("./es2025.promise");
|
||||
const es2025_regexp_1 = require("./es2025.regexp");
|
||||
const esnext_1 = require("./esnext");
|
||||
const esnext_array_1 = require("./esnext.array");
|
||||
const esnext_asynciterable_1 = require("./esnext.asynciterable");
|
||||
const esnext_bigint_1 = require("./esnext.bigint");
|
||||
const esnext_collection_1 = require("./esnext.collection");
|
||||
const esnext_date_1 = require("./esnext.date");
|
||||
const esnext_decorators_1 = require("./esnext.decorators");
|
||||
const esnext_disposable_1 = require("./esnext.disposable");
|
||||
const esnext_error_1 = require("./esnext.error");
|
||||
const esnext_float16_1 = require("./esnext.float16");
|
||||
const esnext_full_1 = require("./esnext.full");
|
||||
const esnext_intl_1 = require("./esnext.intl");
|
||||
const esnext_iterator_1 = require("./esnext.iterator");
|
||||
const esnext_object_1 = require("./esnext.object");
|
||||
const esnext_promise_1 = require("./esnext.promise");
|
||||
const esnext_regexp_1 = require("./esnext.regexp");
|
||||
const esnext_sharedmemory_1 = require("./esnext.sharedmemory");
|
||||
const esnext_string_1 = require("./esnext.string");
|
||||
const esnext_symbol_1 = require("./esnext.symbol");
|
||||
const esnext_temporal_1 = require("./esnext.temporal");
|
||||
const esnext_typedarrays_1 = require("./esnext.typedarrays");
|
||||
const esnext_weakref_1 = require("./esnext.weakref");
|
||||
const lib_1 = require("./lib");
|
||||
const scripthost_1 = require("./scripthost");
|
||||
const webworker_1 = require("./webworker");
|
||||
const webworker_asynciterable_1 = require("./webworker.asynciterable");
|
||||
const webworker_importscripts_1 = require("./webworker.importscripts");
|
||||
const webworker_iterable_1 = require("./webworker.iterable");
|
||||
exports.lib = new Map([
|
||||
['es5', es5_1.es5],
|
||||
['es6', es6_1.es6],
|
||||
['es2015', es2015_1.es2015],
|
||||
['es7', es7_1.es7],
|
||||
['es2016', es2016_1.es2016],
|
||||
['es2017', es2017_1.es2017],
|
||||
['es2018', es2018_1.es2018],
|
||||
['es2019', es2019_1.es2019],
|
||||
['es2020', es2020_1.es2020],
|
||||
['es2021', es2021_1.es2021],
|
||||
['es2022', es2022_1.es2022],
|
||||
['es2023', es2023_1.es2023],
|
||||
['es2024', es2024_1.es2024],
|
||||
['es2025', es2025_1.es2025],
|
||||
['esnext', esnext_1.esnext],
|
||||
['dom', dom_1.dom],
|
||||
['dom.iterable', dom_iterable_1.dom_iterable],
|
||||
['dom.asynciterable', dom_asynciterable_1.dom_asynciterable],
|
||||
['webworker', webworker_1.webworker],
|
||||
['webworker.importscripts', webworker_importscripts_1.webworker_importscripts],
|
||||
['webworker.iterable', webworker_iterable_1.webworker_iterable],
|
||||
['webworker.asynciterable', webworker_asynciterable_1.webworker_asynciterable],
|
||||
['scripthost', scripthost_1.scripthost],
|
||||
['es2015.core', es2015_core_1.es2015_core],
|
||||
['es2015.collection', es2015_collection_1.es2015_collection],
|
||||
['es2015.generator', es2015_generator_1.es2015_generator],
|
||||
['es2015.iterable', es2015_iterable_1.es2015_iterable],
|
||||
['es2015.promise', es2015_promise_1.es2015_promise],
|
||||
['es2015.proxy', es2015_proxy_1.es2015_proxy],
|
||||
['es2015.reflect', es2015_reflect_1.es2015_reflect],
|
||||
['es2015.symbol', es2015_symbol_1.es2015_symbol],
|
||||
['es2015.symbol.wellknown', es2015_symbol_wellknown_1.es2015_symbol_wellknown],
|
||||
['es2016.array.include', es2016_array_include_1.es2016_array_include],
|
||||
['es2016.intl', es2016_intl_1.es2016_intl],
|
||||
['es2017.arraybuffer', es2017_arraybuffer_1.es2017_arraybuffer],
|
||||
['es2017.date', es2017_date_1.es2017_date],
|
||||
['es2017.object', es2017_object_1.es2017_object],
|
||||
['es2017.sharedmemory', es2017_sharedmemory_1.es2017_sharedmemory],
|
||||
['es2017.string', es2017_string_1.es2017_string],
|
||||
['es2017.intl', es2017_intl_1.es2017_intl],
|
||||
['es2017.typedarrays', es2017_typedarrays_1.es2017_typedarrays],
|
||||
['es2018.asyncgenerator', es2018_asyncgenerator_1.es2018_asyncgenerator],
|
||||
['es2018.asynciterable', es2018_asynciterable_1.es2018_asynciterable],
|
||||
['es2018.intl', es2018_intl_1.es2018_intl],
|
||||
['es2018.promise', es2018_promise_1.es2018_promise],
|
||||
['es2018.regexp', es2018_regexp_1.es2018_regexp],
|
||||
['es2019.array', es2019_array_1.es2019_array],
|
||||
['es2019.object', es2019_object_1.es2019_object],
|
||||
['es2019.string', es2019_string_1.es2019_string],
|
||||
['es2019.symbol', es2019_symbol_1.es2019_symbol],
|
||||
['es2019.intl', es2019_intl_1.es2019_intl],
|
||||
['es2020.bigint', es2020_bigint_1.es2020_bigint],
|
||||
['es2020.date', es2020_date_1.es2020_date],
|
||||
['es2020.promise', es2020_promise_1.es2020_promise],
|
||||
['es2020.sharedmemory', es2020_sharedmemory_1.es2020_sharedmemory],
|
||||
['es2020.string', es2020_string_1.es2020_string],
|
||||
['es2020.symbol.wellknown', es2020_symbol_wellknown_1.es2020_symbol_wellknown],
|
||||
['es2020.intl', es2020_intl_1.es2020_intl],
|
||||
['es2020.number', es2020_number_1.es2020_number],
|
||||
['es2021.promise', es2021_promise_1.es2021_promise],
|
||||
['es2021.string', es2021_string_1.es2021_string],
|
||||
['es2021.weakref', es2021_weakref_1.es2021_weakref],
|
||||
['es2021.intl', es2021_intl_1.es2021_intl],
|
||||
['es2022.array', es2022_array_1.es2022_array],
|
||||
['es2022.error', es2022_error_1.es2022_error],
|
||||
['es2022.intl', es2022_intl_1.es2022_intl],
|
||||
['es2022.object', es2022_object_1.es2022_object],
|
||||
['es2022.string', es2022_string_1.es2022_string],
|
||||
['es2022.regexp', es2022_regexp_1.es2022_regexp],
|
||||
['es2023.array', es2023_array_1.es2023_array],
|
||||
['es2023.collection', es2023_collection_1.es2023_collection],
|
||||
['es2023.intl', es2023_intl_1.es2023_intl],
|
||||
['es2024.arraybuffer', es2024_arraybuffer_1.es2024_arraybuffer],
|
||||
['es2024.collection', es2024_collection_1.es2024_collection],
|
||||
['es2024.object', es2024_object_1.es2024_object],
|
||||
['es2024.promise', es2024_promise_1.es2024_promise],
|
||||
['es2024.regexp', es2024_regexp_1.es2024_regexp],
|
||||
['es2024.sharedmemory', es2024_sharedmemory_1.es2024_sharedmemory],
|
||||
['es2024.string', es2024_string_1.es2024_string],
|
||||
['es2025.collection', es2025_collection_1.es2025_collection],
|
||||
['es2025.float16', es2025_float16_1.es2025_float16],
|
||||
['es2025.intl', es2025_intl_1.es2025_intl],
|
||||
['es2025.iterator', es2025_iterator_1.es2025_iterator],
|
||||
['es2025.promise', es2025_promise_1.es2025_promise],
|
||||
['es2025.regexp', es2025_regexp_1.es2025_regexp],
|
||||
['esnext.asynciterable', esnext_asynciterable_1.esnext_asynciterable],
|
||||
['esnext.symbol', esnext_symbol_1.esnext_symbol],
|
||||
['esnext.bigint', esnext_bigint_1.esnext_bigint],
|
||||
['esnext.weakref', esnext_weakref_1.esnext_weakref],
|
||||
['esnext.object', esnext_object_1.esnext_object],
|
||||
['esnext.regexp', esnext_regexp_1.esnext_regexp],
|
||||
['esnext.string', esnext_string_1.esnext_string],
|
||||
['esnext.float16', esnext_float16_1.esnext_float16],
|
||||
['esnext.iterator', esnext_iterator_1.esnext_iterator],
|
||||
['esnext.promise', esnext_promise_1.esnext_promise],
|
||||
['esnext.array', esnext_array_1.esnext_array],
|
||||
['esnext.collection', esnext_collection_1.esnext_collection],
|
||||
['esnext.date', esnext_date_1.esnext_date],
|
||||
['esnext.decorators', esnext_decorators_1.esnext_decorators],
|
||||
['esnext.disposable', esnext_disposable_1.esnext_disposable],
|
||||
['esnext.error', esnext_error_1.esnext_error],
|
||||
['esnext.intl', esnext_intl_1.esnext_intl],
|
||||
['esnext.sharedmemory', esnext_sharedmemory_1.esnext_sharedmemory],
|
||||
['esnext.temporal', esnext_temporal_1.esnext_temporal],
|
||||
['esnext.typedarrays', esnext_typedarrays_1.esnext_typedarrays],
|
||||
['decorators', decorators_1.decorators],
|
||||
['decorators.legacy', decorators_legacy_1.decorators_legacy],
|
||||
['es2016.full', es2016_full_1.es2016_full],
|
||||
['es2017.full', es2017_full_1.es2017_full],
|
||||
['es2018.full', es2018_full_1.es2018_full],
|
||||
['es2019.full', es2019_full_1.es2019_full],
|
||||
['es2020.full', es2020_full_1.es2020_full],
|
||||
['es2021.full', es2021_full_1.es2021_full],
|
||||
['es2022.full', es2022_full_1.es2022_full],
|
||||
['es2023.full', es2023_full_1.es2023_full],
|
||||
['es2024.full', es2024_full_1.es2024_full],
|
||||
['es2025.full', es2025_full_1.es2025_full],
|
||||
['esnext.full', esnext_full_1.esnext_full],
|
||||
['lib', lib_1.lib],
|
||||
]);
|
||||
@@ -0,0 +1,176 @@
|
||||
/**
|
||||
* @fileoverview A collection of methods for processing Espree's options.
|
||||
* @author Kai Cataldo
|
||||
*/
|
||||
|
||||
/**
|
||||
* @import { EcmaVersion, Options } from "../espree.js";
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const SUPPORTED_VERSIONS = /** @type {const} */ ([
|
||||
3,
|
||||
5,
|
||||
6, // 2015
|
||||
7, // 2016
|
||||
8, // 2017
|
||||
9, // 2018
|
||||
10, // 2019
|
||||
11, // 2020
|
||||
12, // 2021
|
||||
13, // 2022
|
||||
14, // 2023
|
||||
15, // 2024
|
||||
16, // 2025
|
||||
17, // 2026
|
||||
]);
|
||||
|
||||
/**
|
||||
* @typedef {typeof SUPPORTED_VERSIONS[number]} NormalizedEcmaVersion
|
||||
*/
|
||||
|
||||
const LATEST_ECMA_VERSION =
|
||||
/* eslint-disable jsdoc/valid-types -- Bug */
|
||||
/** @type {typeof SUPPORTED_VERSIONS extends readonly [...unknown[], infer L] ? L : never} */ (
|
||||
SUPPORTED_VERSIONS.at(-1)
|
||||
/* eslint-enable jsdoc/valid-types -- Bug */
|
||||
);
|
||||
|
||||
/**
|
||||
* Get the latest ECMAScript version supported by Espree.
|
||||
* @returns {typeof LATEST_ECMA_VERSION} The latest ECMAScript version.
|
||||
*/
|
||||
export function getLatestEcmaVersion() {
|
||||
return LATEST_ECMA_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of ECMAScript versions supported by Espree.
|
||||
* @returns {[...typeof SUPPORTED_VERSIONS]} An array containing the supported ECMAScript versions.
|
||||
*/
|
||||
export function getSupportedEcmaVersions() {
|
||||
return [...SUPPORTED_VERSIONS];
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize ECMAScript version from the initial config
|
||||
* @param {EcmaVersion} ecmaVersion ECMAScript version from the initial config
|
||||
* @throws {Error} throws an error if the ecmaVersion is invalid.
|
||||
* @returns {NormalizedEcmaVersion} normalized ECMAScript version
|
||||
*/
|
||||
function normalizeEcmaVersion(ecmaVersion = 5) {
|
||||
let version =
|
||||
ecmaVersion === "latest" ? getLatestEcmaVersion() : ecmaVersion;
|
||||
|
||||
if (typeof version !== "number") {
|
||||
throw new Error(
|
||||
`ecmaVersion must be a number or "latest". Received value of type ${typeof ecmaVersion} instead.`,
|
||||
);
|
||||
}
|
||||
|
||||
// Calculate ECMAScript edition number from official year version starting with
|
||||
// ES2015, which corresponds with ES6 (or a difference of 2009).
|
||||
if (version >= 2015) {
|
||||
version -= 2009;
|
||||
}
|
||||
|
||||
if (
|
||||
!SUPPORTED_VERSIONS.includes(
|
||||
/** @type {NormalizedEcmaVersion} */
|
||||
(version),
|
||||
)
|
||||
) {
|
||||
throw new Error("Invalid ecmaVersion.");
|
||||
}
|
||||
|
||||
return /** @type {NormalizedEcmaVersion} */ (version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize sourceType from the initial config
|
||||
* @param {string} sourceType to normalize
|
||||
* @throws {Error} throw an error if sourceType is invalid
|
||||
* @returns {"script"|"module"|"commonjs"} normalized sourceType
|
||||
*/
|
||||
function normalizeSourceType(sourceType = "script") {
|
||||
if (
|
||||
sourceType === "script" ||
|
||||
sourceType === "module" ||
|
||||
sourceType === "commonjs"
|
||||
) {
|
||||
return sourceType;
|
||||
}
|
||||
|
||||
throw new Error("Invalid sourceType.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
* ecmaVersion: NormalizedEcmaVersion,
|
||||
* sourceType: "script"|"module"|"commonjs",
|
||||
* range?: boolean,
|
||||
* loc?: boolean,
|
||||
* allowReserved: boolean | "never",
|
||||
* ecmaFeatures?: {
|
||||
* jsx?: boolean,
|
||||
* globalReturn?: boolean,
|
||||
* impliedStrict?: boolean
|
||||
* },
|
||||
* ranges: boolean,
|
||||
* locations: boolean,
|
||||
* allowReturnOutsideFunction: boolean,
|
||||
* tokens?: boolean,
|
||||
* comment?: boolean
|
||||
* }} NormalizedParserOptions
|
||||
*/
|
||||
|
||||
/**
|
||||
* Normalize parserOptions
|
||||
* @param {Options} options the parser options to normalize
|
||||
* @throws {Error} throw an error if found invalid option.
|
||||
* @returns {NormalizedParserOptions} normalized options
|
||||
*/
|
||||
export function normalizeOptions(options) {
|
||||
const ecmaVersion = normalizeEcmaVersion(options.ecmaVersion);
|
||||
const sourceType = normalizeSourceType(options.sourceType);
|
||||
const ranges = options.range === true;
|
||||
const locations = options.loc === true;
|
||||
|
||||
if (ecmaVersion !== 3 && options.allowReserved) {
|
||||
// a value of `false` is intentionally allowed here, so a shared config can overwrite it when needed
|
||||
throw new Error(
|
||||
"`allowReserved` is only supported when ecmaVersion is 3",
|
||||
);
|
||||
}
|
||||
if (
|
||||
typeof options.allowReserved !== "undefined" &&
|
||||
typeof options.allowReserved !== "boolean"
|
||||
) {
|
||||
throw new Error(
|
||||
"`allowReserved`, when present, must be `true` or `false`",
|
||||
);
|
||||
}
|
||||
const allowReserved =
|
||||
ecmaVersion === 3 ? options.allowReserved || "never" : false;
|
||||
const ecmaFeatures = options.ecmaFeatures || {};
|
||||
const allowReturnOutsideFunction =
|
||||
options.sourceType === "commonjs" || Boolean(ecmaFeatures.globalReturn);
|
||||
|
||||
if (sourceType === "module" && ecmaVersion < 6) {
|
||||
throw new Error(
|
||||
"sourceType 'module' is not supported when ecmaVersion < 2015. Consider adding `{ ecmaVersion: 2015 }` to the parser options.",
|
||||
);
|
||||
}
|
||||
|
||||
return Object.assign({}, options, {
|
||||
ecmaVersion,
|
||||
sourceType,
|
||||
ranges,
|
||||
locations,
|
||||
allowReserved,
|
||||
allowReturnOutsideFunction,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Internal Merkle-Damgard hash utils.
|
||||
* @module
|
||||
*/
|
||||
import { type Input, Hash } from './utils.ts';
|
||||
/** Polyfill for Safari 14. https://caniuse.com/mdn-javascript_builtins_dataview_setbiguint64 */
|
||||
export declare function setBigUint64(view: DataView, byteOffset: number, value: bigint, isLE: boolean): void;
|
||||
/** Choice: a ? b : c */
|
||||
export declare function Chi(a: number, b: number, c: number): number;
|
||||
/** Majority function, true if any two inputs is true. */
|
||||
export declare function Maj(a: number, b: number, c: number): number;
|
||||
/**
|
||||
* Merkle-Damgard hash construction base class.
|
||||
* Could be used to create MD5, RIPEMD, SHA1, SHA2.
|
||||
*/
|
||||
export declare abstract class HashMD<T extends HashMD<T>> extends Hash<T> {
|
||||
protected abstract process(buf: DataView, offset: number): void;
|
||||
protected abstract get(): number[];
|
||||
protected abstract set(...args: number[]): void;
|
||||
abstract destroy(): void;
|
||||
protected abstract roundClean(): void;
|
||||
readonly blockLen: number;
|
||||
readonly outputLen: number;
|
||||
readonly padOffset: number;
|
||||
readonly isLE: boolean;
|
||||
protected buffer: Uint8Array;
|
||||
protected view: DataView;
|
||||
protected finished: boolean;
|
||||
protected length: number;
|
||||
protected pos: number;
|
||||
protected destroyed: boolean;
|
||||
constructor(blockLen: number, outputLen: number, padOffset: number, isLE: boolean);
|
||||
update(data: Input): this;
|
||||
digestInto(out: Uint8Array): void;
|
||||
digest(): Uint8Array;
|
||||
_cloneInto(to?: T): T;
|
||||
clone(): T;
|
||||
}
|
||||
/**
|
||||
* Initial SHA-2 state: fractional parts of square roots of first 16 primes 2..53.
|
||||
* Check out `test/misc/sha2-gen-iv.js` for recomputation guide.
|
||||
*/
|
||||
/** Initial SHA256 state. Bits 0..32 of frac part of sqrt of primes 2..19 */
|
||||
export declare const SHA256_IV: Uint32Array;
|
||||
/** Initial SHA224 state. Bits 32..64 of frac part of sqrt of primes 23..53 */
|
||||
export declare const SHA224_IV: Uint32Array;
|
||||
/** Initial SHA384 state. Bits 0..64 of frac part of sqrt of primes 23..53 */
|
||||
export declare const SHA384_IV: Uint32Array;
|
||||
/** Initial SHA512 state. Bits 0..64 of frac part of sqrt of primes 2..19 */
|
||||
export declare const SHA512_IV: Uint32Array;
|
||||
//# sourceMappingURL=_md.d.ts.map
|
||||
@@ -0,0 +1,142 @@
|
||||
/**
|
||||
* SHA3 (keccak) addons.
|
||||
*
|
||||
* * Full [NIST SP 800-185](https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-185.pdf):
|
||||
* cSHAKE, KMAC, TupleHash, ParallelHash + XOF variants
|
||||
* * Reduced-round Keccak [(draft)](https://datatracker.ietf.org/doc/draft-irtf-cfrg-kangarootwelve/):
|
||||
* * 🦘 K12 aka KangarooTwelve
|
||||
* * M14 aka MarsupilamiFourteen
|
||||
* * TurboSHAKE
|
||||
* * KeccakPRG: Pseudo-random generator based on Keccak [(pdf)](https://keccak.team/files/CSF-0.1.pdf)
|
||||
* @module
|
||||
*/
|
||||
import { Keccak, type ShakeOpts } from './sha3.ts';
|
||||
import { type CHashO, type CHashXO, Hash, type HashXOF, type Input } from './utils.ts';
|
||||
export type cShakeOpts = ShakeOpts & {
|
||||
personalization?: Input;
|
||||
NISTfn?: Input;
|
||||
};
|
||||
export type ICShake = {
|
||||
(msg: Input, opts?: cShakeOpts): Uint8Array;
|
||||
outputLen: number;
|
||||
blockLen: number;
|
||||
create(opts: cShakeOpts): HashXOF<Keccak>;
|
||||
};
|
||||
export type ITupleHash = {
|
||||
(messages: Input[], opts?: cShakeOpts): Uint8Array;
|
||||
create(opts?: cShakeOpts): TupleHash;
|
||||
};
|
||||
export type IParHash = {
|
||||
(message: Input, opts?: ParallelOpts): Uint8Array;
|
||||
create(opts?: ParallelOpts): ParallelHash;
|
||||
};
|
||||
export declare const cshake128: ICShake;
|
||||
export declare const cshake256: ICShake;
|
||||
export declare class KMAC extends Keccak implements HashXOF<KMAC> {
|
||||
constructor(blockLen: number, outputLen: number, enableXOF: boolean, key: Input, opts?: cShakeOpts);
|
||||
protected finish(): void;
|
||||
_cloneInto(to?: KMAC): KMAC;
|
||||
clone(): KMAC;
|
||||
}
|
||||
export declare const kmac128: {
|
||||
(key: Input, message: Input, opts?: cShakeOpts): Uint8Array;
|
||||
create(key: Input, opts?: cShakeOpts): KMAC;
|
||||
};
|
||||
export declare const kmac256: {
|
||||
(key: Input, message: Input, opts?: cShakeOpts): Uint8Array;
|
||||
create(key: Input, opts?: cShakeOpts): KMAC;
|
||||
};
|
||||
export declare const kmac128xof: {
|
||||
(key: Input, message: Input, opts?: cShakeOpts): Uint8Array;
|
||||
create(key: Input, opts?: cShakeOpts): KMAC;
|
||||
};
|
||||
export declare const kmac256xof: {
|
||||
(key: Input, message: Input, opts?: cShakeOpts): Uint8Array;
|
||||
create(key: Input, opts?: cShakeOpts): KMAC;
|
||||
};
|
||||
export declare class TupleHash extends Keccak implements HashXOF<TupleHash> {
|
||||
constructor(blockLen: number, outputLen: number, enableXOF: boolean, opts?: cShakeOpts);
|
||||
protected finish(): void;
|
||||
_cloneInto(to?: TupleHash): TupleHash;
|
||||
clone(): TupleHash;
|
||||
}
|
||||
/** 128-bit TupleHASH. */
|
||||
export declare const tuplehash128: ITupleHash;
|
||||
/** 256-bit TupleHASH. */
|
||||
export declare const tuplehash256: ITupleHash;
|
||||
/** 128-bit TupleHASH XOF. */
|
||||
export declare const tuplehash128xof: ITupleHash;
|
||||
/** 256-bit TupleHASH XOF. */
|
||||
export declare const tuplehash256xof: ITupleHash;
|
||||
type ParallelOpts = cShakeOpts & {
|
||||
blockLen?: number;
|
||||
};
|
||||
export declare class ParallelHash extends Keccak implements HashXOF<ParallelHash> {
|
||||
private leafHash?;
|
||||
protected leafCons: () => Hash<Keccak>;
|
||||
private chunkPos;
|
||||
private chunksDone;
|
||||
private chunkLen;
|
||||
constructor(blockLen: number, outputLen: number, leafCons: () => Hash<Keccak>, enableXOF: boolean, opts?: ParallelOpts);
|
||||
protected finish(): void;
|
||||
_cloneInto(to?: ParallelHash): ParallelHash;
|
||||
destroy(): void;
|
||||
clone(): ParallelHash;
|
||||
}
|
||||
/** 128-bit ParallelHash. In JS, it is not parallel. */
|
||||
export declare const parallelhash128: IParHash;
|
||||
/** 256-bit ParallelHash. In JS, it is not parallel. */
|
||||
export declare const parallelhash256: IParHash;
|
||||
/** 128-bit ParallelHash XOF. In JS, it is not parallel. */
|
||||
export declare const parallelhash128xof: IParHash;
|
||||
/** 256-bit ParallelHash. In JS, it is not parallel. */
|
||||
export declare const parallelhash256xof: IParHash;
|
||||
export type TurboshakeOpts = ShakeOpts & {
|
||||
D?: number;
|
||||
};
|
||||
/** TurboSHAKE 128-bit: reduced 12-round keccak. */
|
||||
export declare const turboshake128: CHashXO;
|
||||
/** TurboSHAKE 256-bit: reduced 12-round keccak. */
|
||||
export declare const turboshake256: CHashXO;
|
||||
export type KangarooOpts = {
|
||||
dkLen?: number;
|
||||
personalization?: Input;
|
||||
};
|
||||
export declare class KangarooTwelve extends Keccak implements HashXOF<KangarooTwelve> {
|
||||
readonly chunkLen = 8192;
|
||||
private leafHash?;
|
||||
protected leafLen: number;
|
||||
private personalization;
|
||||
private chunkPos;
|
||||
private chunksDone;
|
||||
constructor(blockLen: number, leafLen: number, outputLen: number, rounds: number, opts: KangarooOpts);
|
||||
update(data: Input): this;
|
||||
protected finish(): void;
|
||||
destroy(): void;
|
||||
_cloneInto(to?: KangarooTwelve): KangarooTwelve;
|
||||
clone(): KangarooTwelve;
|
||||
}
|
||||
/** KangarooTwelve: reduced 12-round keccak. */
|
||||
export declare const k12: CHashO;
|
||||
/** MarsupilamiFourteen: reduced 14-round keccak. */
|
||||
export declare const m14: CHashO;
|
||||
/**
|
||||
* More at https://github.com/XKCP/XKCP/tree/master/lib/high/Keccak/PRG.
|
||||
*/
|
||||
export declare class KeccakPRG extends Keccak {
|
||||
protected rate: number;
|
||||
constructor(capacity: number);
|
||||
keccak(): void;
|
||||
update(data: Input): this;
|
||||
feed(data: Input): this;
|
||||
protected finish(): void;
|
||||
digestInto(_out: Uint8Array): Uint8Array;
|
||||
fetch(bytes: number): Uint8Array;
|
||||
forget(): void;
|
||||
_cloneInto(to?: KeccakPRG): KeccakPRG;
|
||||
clone(): KeccakPRG;
|
||||
}
|
||||
/** KeccakPRG: Pseudo-random generator based on Keccak. https://keccak.team/files/CSF-0.1.pdf */
|
||||
export declare const keccakprg: (capacity?: number) => KeccakPRG;
|
||||
export {};
|
||||
//# sourceMappingURL=sha3-addons.d.ts.map
|
||||
@@ -0,0 +1,115 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const utils_1 = require("@typescript-eslint/utils");
|
||||
const util = __importStar(require("../util"));
|
||||
exports.default = util.createRule({
|
||||
name: 'no-require-imports',
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'Disallow invocation of `require()`',
|
||||
recommended: 'recommended',
|
||||
},
|
||||
messages: {
|
||||
noRequireImports: 'A `require()` style import is forbidden.',
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
type: 'object',
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
allow: {
|
||||
type: 'array',
|
||||
description: 'Patterns of import paths to allow requiring from.',
|
||||
items: { type: 'string' },
|
||||
},
|
||||
allowAsImport: {
|
||||
type: 'boolean',
|
||||
description: 'Allows `require` statements in import declarations.',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
defaultOptions: [{ allow: [], allowAsImport: false }],
|
||||
create(context, options) {
|
||||
const allowAsImport = options[0].allowAsImport;
|
||||
const allowPatterns = options[0].allow?.map(pattern => new RegExp(pattern, 'u'));
|
||||
function isImportPathAllowed(importPath) {
|
||||
return allowPatterns?.some(pattern => importPath.match(pattern));
|
||||
}
|
||||
function isStringOrTemplateLiteral(node) {
|
||||
return ((node.type === utils_1.AST_NODE_TYPES.Literal &&
|
||||
typeof node.value === 'string') ||
|
||||
node.type === utils_1.AST_NODE_TYPES.TemplateLiteral);
|
||||
}
|
||||
return {
|
||||
'CallExpression[callee.name="require"]'(node) {
|
||||
if (node.arguments[0] && isStringOrTemplateLiteral(node.arguments[0])) {
|
||||
const argValue = util.getStaticStringValue(node.arguments[0]);
|
||||
if (typeof argValue === 'string' && isImportPathAllowed(argValue)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
const variable = utils_1.ASTUtils.findVariable(context.sourceCode.getScope(node), 'require');
|
||||
// ignore non-global require usage as it's something user-land custom instead
|
||||
// of the commonjs standard
|
||||
if (!variable?.identifiers.length) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'noRequireImports',
|
||||
});
|
||||
}
|
||||
},
|
||||
TSExternalModuleReference(node) {
|
||||
if (isStringOrTemplateLiteral(node.expression)) {
|
||||
const argValue = util.getStaticStringValue(node.expression);
|
||||
if (typeof argValue === 'string' && isImportPathAllowed(argValue)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (allowAsImport &&
|
||||
node.parent.type === utils_1.AST_NODE_TYPES.TSImportEqualsDeclaration) {
|
||||
return;
|
||||
}
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'noRequireImports',
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"jubjub.js","sourceRoot":"","sources":["../src/jubjub.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAEtF,wEAAwE;AACxE,MAAM,CAAC,MAAM,MAAM,GAAmB,OAAO,CAAC;AAC9C,sFAAsF;AACtF,MAAM,CAAC,MAAM,aAAa,GAAgC,oBAAoB,CAAC;AAC/E,kFAAkF;AAClF,MAAM,CAAC,MAAM,SAAS,GAA4B,gBAAgB,CAAC"}
|
||||
Reference in New Issue
Block a user