WIP: bootstrap and partial real Solana watcher implementation
This commit is contained in:
@@ -0,0 +1,165 @@
|
||||
"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 tsutils = __importStar(require("ts-api-utils"));
|
||||
const ts = __importStar(require("typescript"));
|
||||
const util_1 = require("../util");
|
||||
exports.default = (0, util_1.createRule)({
|
||||
name: 'no-unsafe-type-assertion',
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'Disallow type assertions that narrow a type',
|
||||
requiresTypeChecking: true,
|
||||
},
|
||||
messages: {
|
||||
unsafeOfAnyTypeAssertion: 'Unsafe assertion from {{type}} detected: consider using type guards or a safer assertion.',
|
||||
unsafeToAnyTypeAssertion: 'Unsafe assertion to {{type}} detected: consider using a more specific type to ensure safety.',
|
||||
unsafeToUnconstrainedTypeAssertion: "Unsafe type assertion: '{{type}}' could be instantiated with an arbitrary type which could be unrelated to the original type.",
|
||||
unsafeTypeAssertion: "Unsafe type assertion: type '{{type}}' is more narrow than the original type.",
|
||||
unsafeTypeAssertionAssignableToConstraint: "Unsafe type assertion: the original type is assignable to the constraint of type '{{type}}', but '{{type}}' could be instantiated with a different subtype of its constraint.",
|
||||
},
|
||||
schema: [],
|
||||
},
|
||||
defaultOptions: [],
|
||||
create(context) {
|
||||
const services = (0, util_1.getParserServices)(context);
|
||||
const checker = services.program.getTypeChecker();
|
||||
function getAnyTypeName(type) {
|
||||
return tsutils.isIntrinsicErrorType(type) ? 'error typed' : '`any`';
|
||||
}
|
||||
function isObjectLiteralType(type) {
|
||||
return (tsutils.isObjectType(type) &&
|
||||
tsutils.isObjectFlagSet(type, ts.ObjectFlags.ObjectLiteral));
|
||||
}
|
||||
function checkExpression(node) {
|
||||
const expressionType = services.getTypeAtLocation(node.expression);
|
||||
const assertedType = services.getTypeAtLocation(node.typeAnnotation);
|
||||
if (expressionType === assertedType) {
|
||||
return;
|
||||
}
|
||||
// handle cases when asserting unknown ==> any.
|
||||
if ((0, util_1.isTypeAnyType)(assertedType) && (0, util_1.isTypeUnknownType)(expressionType)) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'unsafeToAnyTypeAssertion',
|
||||
data: {
|
||||
type: '`any`',
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
const unsafeExpressionAny = (0, util_1.isUnsafeAssignment)(expressionType, assertedType, checker, node.expression);
|
||||
if (unsafeExpressionAny) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'unsafeOfAnyTypeAssertion',
|
||||
data: {
|
||||
type: getAnyTypeName(unsafeExpressionAny.sender),
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
const unsafeAssertedAny = (0, util_1.isUnsafeAssignment)(assertedType, expressionType, checker, node.typeAnnotation);
|
||||
if (unsafeAssertedAny) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'unsafeToAnyTypeAssertion',
|
||||
data: {
|
||||
type: getAnyTypeName(unsafeAssertedAny.sender),
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
// Use the widened type in case of an object literal so `isTypeAssignableTo()`
|
||||
// won't fail on excess property check.
|
||||
const expressionWidenedType = isObjectLiteralType(expressionType)
|
||||
? checker.getWidenedType(expressionType)
|
||||
: expressionType;
|
||||
let isAssertionSafe;
|
||||
try {
|
||||
isAssertionSafe = checker.isTypeAssignableTo(expressionWidenedType, assertedType);
|
||||
}
|
||||
catch {
|
||||
// workaround for https://github.com/microsoft/TypeScript/issues/62933
|
||||
return;
|
||||
}
|
||||
if (isAssertionSafe) {
|
||||
return;
|
||||
}
|
||||
// Produce a more specific error message when targeting a type parameter
|
||||
if (tsutils.isTypeParameter(assertedType)) {
|
||||
const assertedTypeConstraint = checker.getBaseConstraintOfType(assertedType);
|
||||
if (!assertedTypeConstraint) {
|
||||
// asserting to an unconstrained type parameter is unsafe
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'unsafeToUnconstrainedTypeAssertion',
|
||||
data: {
|
||||
type: checker.typeToString(assertedType),
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
// special case message if the original type is assignable to the
|
||||
// constraint of the target type parameter
|
||||
const isAssignableToConstraint = checker.isTypeAssignableTo(expressionWidenedType, assertedTypeConstraint);
|
||||
if (isAssignableToConstraint) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'unsafeTypeAssertionAssignableToConstraint',
|
||||
data: {
|
||||
type: checker.typeToString(assertedType),
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
// General error message
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'unsafeTypeAssertion',
|
||||
data: {
|
||||
type: checker.typeToString(assertedType),
|
||||
},
|
||||
});
|
||||
}
|
||||
return {
|
||||
'TSAsExpression, TSTypeAssertion'(node) {
|
||||
checkExpression(node);
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
// Code generated by Herebyfile.mjs generate:enums from internal/lsp/lsproto/lsp_generated.go. DO NOT EDIT.
|
||||
export var CompletionItemKind;
|
||||
(function (CompletionItemKind) {
|
||||
CompletionItemKind[CompletionItemKind["Text"] = 1] = "Text";
|
||||
CompletionItemKind[CompletionItemKind["Method"] = 2] = "Method";
|
||||
CompletionItemKind[CompletionItemKind["Function"] = 3] = "Function";
|
||||
CompletionItemKind[CompletionItemKind["Constructor"] = 4] = "Constructor";
|
||||
CompletionItemKind[CompletionItemKind["Field"] = 5] = "Field";
|
||||
CompletionItemKind[CompletionItemKind["Variable"] = 6] = "Variable";
|
||||
CompletionItemKind[CompletionItemKind["Class"] = 7] = "Class";
|
||||
CompletionItemKind[CompletionItemKind["Interface"] = 8] = "Interface";
|
||||
CompletionItemKind[CompletionItemKind["Module"] = 9] = "Module";
|
||||
CompletionItemKind[CompletionItemKind["Property"] = 10] = "Property";
|
||||
CompletionItemKind[CompletionItemKind["Unit"] = 11] = "Unit";
|
||||
CompletionItemKind[CompletionItemKind["Value"] = 12] = "Value";
|
||||
CompletionItemKind[CompletionItemKind["Enum"] = 13] = "Enum";
|
||||
CompletionItemKind[CompletionItemKind["Keyword"] = 14] = "Keyword";
|
||||
CompletionItemKind[CompletionItemKind["Snippet"] = 15] = "Snippet";
|
||||
CompletionItemKind[CompletionItemKind["Color"] = 16] = "Color";
|
||||
CompletionItemKind[CompletionItemKind["File"] = 17] = "File";
|
||||
CompletionItemKind[CompletionItemKind["Reference"] = 18] = "Reference";
|
||||
CompletionItemKind[CompletionItemKind["Folder"] = 19] = "Folder";
|
||||
CompletionItemKind[CompletionItemKind["EnumMember"] = 20] = "EnumMember";
|
||||
CompletionItemKind[CompletionItemKind["Constant"] = 21] = "Constant";
|
||||
CompletionItemKind[CompletionItemKind["Struct"] = 22] = "Struct";
|
||||
CompletionItemKind[CompletionItemKind["Event"] = 23] = "Event";
|
||||
CompletionItemKind[CompletionItemKind["Operator"] = 24] = "Operator";
|
||||
CompletionItemKind[CompletionItemKind["TypeParameter"] = 25] = "TypeParameter";
|
||||
})(CompletionItemKind || (CompletionItemKind = {}));
|
||||
//# sourceMappingURL=completionItemKind.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"outerExpressionKinds.enum.d.ts","sourceRoot":"","sources":["../../src/enums/outerExpressionKinds.enum.ts"],"names":[],"mappings":"AAEA,oBAAY,oBAAoB;IAC5B,WAAW,IAAS;IACpB,cAAc,IAAS;IACvB,iBAAiB,IAAS;IAC1B,2BAA2B,IAAS;IACpC,4BAA4B,KAAS;IACrC,SAAS,KAAS;IAClB,yBAAyB,KAAS;IAClC,WAAW,MAAS;IACpB,KAAK,MAAS;IACd,UAAU,KAAiD;IAC3D,GAAG,KAAwF;IAC3F,iDAAiD,IAAoD;IACrG,yBAAyB,MAAoC;CAChE"}
|
||||
@@ -0,0 +1,56 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.walkStatements = walkStatements;
|
||||
const utils_1 = require("@typescript-eslint/utils");
|
||||
/**
|
||||
* Yields all statement nodes in a block, including nested blocks.
|
||||
*
|
||||
* You can use it to find all return statements in a function body.
|
||||
*/
|
||||
function* walkStatements(body) {
|
||||
for (const statement of body) {
|
||||
switch (statement.type) {
|
||||
case utils_1.AST_NODE_TYPES.BlockStatement: {
|
||||
yield* walkStatements(statement.body);
|
||||
continue;
|
||||
}
|
||||
case utils_1.AST_NODE_TYPES.SwitchStatement: {
|
||||
for (const switchCase of statement.cases) {
|
||||
yield* walkStatements(switchCase.consequent);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
case utils_1.AST_NODE_TYPES.IfStatement: {
|
||||
yield* walkStatements([statement.consequent]);
|
||||
if (statement.alternate) {
|
||||
yield* walkStatements([statement.alternate]);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
case utils_1.AST_NODE_TYPES.WhileStatement:
|
||||
case utils_1.AST_NODE_TYPES.DoWhileStatement:
|
||||
case utils_1.AST_NODE_TYPES.ForStatement:
|
||||
case utils_1.AST_NODE_TYPES.ForInStatement:
|
||||
case utils_1.AST_NODE_TYPES.ForOfStatement:
|
||||
case utils_1.AST_NODE_TYPES.WithStatement:
|
||||
case utils_1.AST_NODE_TYPES.LabeledStatement: {
|
||||
yield* walkStatements([statement.body]);
|
||||
continue;
|
||||
}
|
||||
case utils_1.AST_NODE_TYPES.TryStatement: {
|
||||
yield* walkStatements([statement.block]);
|
||||
if (statement.handler) {
|
||||
yield* walkStatements([statement.handler.body]);
|
||||
}
|
||||
if (statement.finalizer) {
|
||||
yield* walkStatements([statement.finalizer]);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
default: {
|
||||
yield statement;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
'use strict'
|
||||
|
||||
/* eslint no-prototype-builtins: 0 */
|
||||
|
||||
const { EventEmitter } = require('node:events')
|
||||
const {
|
||||
lsCacheSym,
|
||||
levelValSym,
|
||||
setLevelSym,
|
||||
getLevelSym,
|
||||
chindingsSym,
|
||||
mixinSym,
|
||||
asJsonSym,
|
||||
writeSym,
|
||||
mixinMergeStrategySym,
|
||||
timeSym,
|
||||
timeSliceIndexSym,
|
||||
streamSym,
|
||||
serializersSym,
|
||||
formattersSym,
|
||||
errorKeySym,
|
||||
messageKeySym,
|
||||
useOnlyCustomLevelsSym,
|
||||
needsMetadataGsym,
|
||||
redactFmtSym,
|
||||
stringifySym,
|
||||
formatOptsSym,
|
||||
stringifiersSym,
|
||||
msgPrefixSym,
|
||||
hooksSym
|
||||
} = require('./symbols')
|
||||
const {
|
||||
getLevel,
|
||||
setLevel,
|
||||
isLevelEnabled,
|
||||
mappings,
|
||||
initialLsCache,
|
||||
genLsCache,
|
||||
assertNoLevelCollisions
|
||||
} = require('./levels')
|
||||
const {
|
||||
asChindings,
|
||||
asJson,
|
||||
buildFormatters,
|
||||
stringify,
|
||||
noop
|
||||
} = require('./tools')
|
||||
const {
|
||||
version
|
||||
} = require('./meta')
|
||||
const redaction = require('./redaction')
|
||||
|
||||
// note: use of class is satirical
|
||||
// https://github.com/pinojs/pino/pull/433#pullrequestreview-127703127
|
||||
const constructor = class Pino {}
|
||||
const prototype = {
|
||||
constructor,
|
||||
child,
|
||||
bindings,
|
||||
setBindings,
|
||||
flush,
|
||||
isLevelEnabled,
|
||||
version,
|
||||
get level () { return this[getLevelSym]() },
|
||||
set level (lvl) { this[setLevelSym](lvl) },
|
||||
get levelVal () { return this[levelValSym] },
|
||||
set levelVal (n) { throw Error('levelVal is read-only') },
|
||||
get msgPrefix () { return this[msgPrefixSym] },
|
||||
get [Symbol.toStringTag] () { return 'Pino' },
|
||||
[lsCacheSym]: initialLsCache,
|
||||
[writeSym]: write,
|
||||
[asJsonSym]: asJson,
|
||||
[getLevelSym]: getLevel,
|
||||
[setLevelSym]: setLevel
|
||||
}
|
||||
|
||||
Object.setPrototypeOf(prototype, EventEmitter.prototype)
|
||||
|
||||
// exporting and consuming the prototype object using factory pattern fixes scoping issues with getters when serializing
|
||||
module.exports = function () {
|
||||
return Object.create(prototype)
|
||||
}
|
||||
|
||||
const resetChildingsFormatter = bindings => bindings
|
||||
function child (bindings, options) {
|
||||
if (!bindings) {
|
||||
throw Error('missing bindings for child Pino')
|
||||
}
|
||||
const serializers = this[serializersSym]
|
||||
const formatters = this[formattersSym]
|
||||
const instance = Object.create(this)
|
||||
|
||||
// If an `options` object was not supplied, we can improve
|
||||
// the performance of child creation by skipping
|
||||
// the checks for set options and simply return
|
||||
// a baseline instance.
|
||||
if (options == null) {
|
||||
if (instance[formattersSym].bindings !== resetChildingsFormatter) {
|
||||
instance[formattersSym] = buildFormatters(
|
||||
formatters.level,
|
||||
resetChildingsFormatter,
|
||||
formatters.log
|
||||
)
|
||||
}
|
||||
|
||||
instance[chindingsSym] = asChindings(instance, bindings)
|
||||
|
||||
if (this.onChild !== noop) {
|
||||
this.onChild(instance)
|
||||
}
|
||||
|
||||
return instance
|
||||
}
|
||||
|
||||
if (options.hasOwnProperty('serializers') === true) {
|
||||
instance[serializersSym] = Object.create(null)
|
||||
|
||||
for (const k in serializers) {
|
||||
instance[serializersSym][k] = serializers[k]
|
||||
}
|
||||
const parentSymbols = Object.getOwnPropertySymbols(serializers)
|
||||
/* eslint no-var: off */
|
||||
for (var i = 0; i < parentSymbols.length; i++) {
|
||||
const ks = parentSymbols[i]
|
||||
instance[serializersSym][ks] = serializers[ks]
|
||||
}
|
||||
|
||||
for (const bk in options.serializers) {
|
||||
instance[serializersSym][bk] = options.serializers[bk]
|
||||
}
|
||||
const bindingsSymbols = Object.getOwnPropertySymbols(options.serializers)
|
||||
for (var bi = 0; bi < bindingsSymbols.length; bi++) {
|
||||
const bks = bindingsSymbols[bi]
|
||||
instance[serializersSym][bks] = options.serializers[bks]
|
||||
}
|
||||
} else instance[serializersSym] = serializers
|
||||
if (options.hasOwnProperty('formatters')) {
|
||||
const { level, bindings: chindings, log } = options.formatters
|
||||
instance[formattersSym] = buildFormatters(
|
||||
level || formatters.level,
|
||||
chindings || resetChildingsFormatter,
|
||||
log || formatters.log
|
||||
)
|
||||
} else {
|
||||
instance[formattersSym] = buildFormatters(
|
||||
formatters.level,
|
||||
resetChildingsFormatter,
|
||||
formatters.log
|
||||
)
|
||||
}
|
||||
if (options.hasOwnProperty('customLevels') === true) {
|
||||
assertNoLevelCollisions(this.levels, options.customLevels)
|
||||
instance.levels = mappings(options.customLevels, instance[useOnlyCustomLevelsSym])
|
||||
genLsCache(instance)
|
||||
}
|
||||
|
||||
// redact must place before asChindings and only replace if exist
|
||||
if ((typeof options.redact === 'object' && options.redact !== null) || Array.isArray(options.redact)) {
|
||||
instance.redact = options.redact // replace redact directly
|
||||
const stringifiers = redaction(instance.redact, stringify)
|
||||
const formatOpts = { stringify: stringifiers[redactFmtSym] }
|
||||
instance[stringifySym] = stringify
|
||||
instance[stringifiersSym] = stringifiers
|
||||
instance[formatOptsSym] = formatOpts
|
||||
}
|
||||
|
||||
if (typeof options.msgPrefix === 'string') {
|
||||
instance[msgPrefixSym] = (this[msgPrefixSym] || '') + options.msgPrefix
|
||||
}
|
||||
|
||||
instance[chindingsSym] = asChindings(instance, bindings)
|
||||
if ((options.level !== undefined && options.level !== this.level) || options.hasOwnProperty('customLevels')) {
|
||||
const childLevel = options.level || this.level
|
||||
instance[setLevelSym](childLevel)
|
||||
}
|
||||
this.onChild(instance)
|
||||
return instance
|
||||
}
|
||||
|
||||
function bindings () {
|
||||
const chindings = this[chindingsSym]
|
||||
const chindingsJson = `{${chindings.substr(1)}}` // at least contains ,"pid":7068,"hostname":"myMac"
|
||||
const bindingsFromJson = JSON.parse(chindingsJson)
|
||||
delete bindingsFromJson.pid
|
||||
delete bindingsFromJson.hostname
|
||||
return bindingsFromJson
|
||||
}
|
||||
|
||||
function setBindings (newBindings) {
|
||||
const chindings = asChindings(this, newBindings)
|
||||
this[chindingsSym] = chindings
|
||||
}
|
||||
|
||||
/**
|
||||
* Default strategy for creating `mergeObject` from arguments and the result from `mixin()`.
|
||||
* Fields from `mergeObject` have higher priority in this strategy.
|
||||
*
|
||||
* @param {Object} mergeObject The object a user has supplied to the logging function.
|
||||
* @param {Object} mixinObject The result of the `mixin` method.
|
||||
* @return {Object}
|
||||
*/
|
||||
function defaultMixinMergeStrategy (mergeObject, mixinObject) {
|
||||
return Object.assign(mixinObject, mergeObject)
|
||||
}
|
||||
|
||||
function write (_obj, msg, num) {
|
||||
const t = this[timeSym]()
|
||||
const mixin = this[mixinSym]
|
||||
const errorKey = this[errorKeySym]
|
||||
const messageKey = this[messageKeySym]
|
||||
const mixinMergeStrategy = this[mixinMergeStrategySym] || defaultMixinMergeStrategy
|
||||
let obj
|
||||
const streamWriteHook = this[hooksSym].streamWrite
|
||||
|
||||
if (_obj === undefined || _obj === null) {
|
||||
obj = {}
|
||||
} else if (_obj instanceof Error) {
|
||||
obj = { [errorKey]: _obj }
|
||||
if (msg === undefined) {
|
||||
msg = _obj.message
|
||||
}
|
||||
} else {
|
||||
obj = _obj
|
||||
if (msg === undefined && _obj[messageKey] === undefined && _obj[errorKey]) {
|
||||
msg = _obj[errorKey].message
|
||||
}
|
||||
}
|
||||
|
||||
if (mixin) {
|
||||
obj = mixinMergeStrategy(obj, mixin(obj, num, this))
|
||||
}
|
||||
|
||||
const s = this[asJsonSym](obj, msg, num, t)
|
||||
|
||||
const stream = this[streamSym]
|
||||
if (stream[needsMetadataGsym] === true) {
|
||||
stream.lastLevel = num
|
||||
stream.lastObj = obj
|
||||
stream.lastMsg = msg
|
||||
stream.lastTime = t.slice(this[timeSliceIndexSym])
|
||||
stream.lastLogger = this // for child loggers
|
||||
}
|
||||
stream.write(streamWriteHook ? streamWriteHook(s) : s)
|
||||
}
|
||||
|
||||
function flush (cb) {
|
||||
if (cb != null && typeof cb !== 'function') {
|
||||
throw Error('callback must be a function')
|
||||
}
|
||||
|
||||
const stream = this[streamSym]
|
||||
|
||||
if (typeof stream.flush === 'function') {
|
||||
stream.flush(cb || noop)
|
||||
} else if (cb) cb()
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = testFile => {
|
||||
// Ignore coverage on files that do not have a direct corollary.
|
||||
if (testFile.startsWith('test/')) return false
|
||||
|
||||
// Indicate the matching name, sans '.test.js', should be checked for coverage.
|
||||
return testFile.replace(/\.test\.js$/, '.js')
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
'use strict'
|
||||
|
||||
const pino = require('../..')
|
||||
const transport = pino.transport({
|
||||
target: 'pino/file',
|
||||
options: { destination: '1' }
|
||||
})
|
||||
const logger = pino(transport)
|
||||
logger.info('Hello')
|
||||
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"name": "file-entry-cache",
|
||||
"version": "8.0.0",
|
||||
"description": "Super simple cache for file metadata, useful for process that work o a given series of files and that only need to repeat the job on the changed ones since the previous run of the process",
|
||||
"repository": "jaredwray/file-entry-cache",
|
||||
"license": "MIT",
|
||||
"author": {
|
||||
"name": "Jared Wray",
|
||||
"url": "https://jaredwray.com"
|
||||
},
|
||||
"main": "cache.js",
|
||||
"files": [
|
||||
"cache.js"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=16.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"eslint": "eslint --cache --cache-location=node_modules/.cache/ 'cache.js' 'test/**/*.js' 'perf.js'",
|
||||
"autofix": "npm run eslint -- --fix",
|
||||
"clean": "rimraf ./node_modules ./package-lock.json ./yarn.lock",
|
||||
"test": "npm run eslint --silent && c8 mocha -R spec test/specs",
|
||||
"test:ci": "npm run eslint --silent && c8 --reporter=lcov mocha -R spec test/specs",
|
||||
"perf": "node perf.js"
|
||||
},
|
||||
"prepush": [
|
||||
"npm run eslint --silent"
|
||||
],
|
||||
"precommit": [
|
||||
"npm run eslint --silent"
|
||||
],
|
||||
"keywords": [
|
||||
"file cache",
|
||||
"task cache files",
|
||||
"file cache",
|
||||
"key par",
|
||||
"key value",
|
||||
"cache"
|
||||
],
|
||||
"devDependencies": {
|
||||
"c8": "^8.0.1",
|
||||
"chai": "^4.3.10",
|
||||
"eslint": "^8.56.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-plugin-mocha": "^10.2.0",
|
||||
"eslint-plugin-prettier": "^5.0.1",
|
||||
"glob-expand": "^0.2.1",
|
||||
"mocha": "^10.2.0",
|
||||
"prettier": "^3.1.1",
|
||||
"rimraf": "^5.0.5",
|
||||
"write": "^2.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"flat-cache": "^4.0.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"lib": [ "es2015", "dom" ],
|
||||
"module": "commonjs",
|
||||
"noEmit": true,
|
||||
"strict": true,
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"exclude": [
|
||||
"./test/types/*.test-d.ts",
|
||||
"./*.d.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* HMAC: RFC2104 message authentication code.
|
||||
* @module
|
||||
*/
|
||||
import { Hash, type CHash, type Input } from './utils.ts';
|
||||
export declare class HMAC<T extends Hash<T>> extends Hash<HMAC<T>> {
|
||||
oHash: T;
|
||||
iHash: T;
|
||||
blockLen: number;
|
||||
outputLen: number;
|
||||
private finished;
|
||||
private destroyed;
|
||||
constructor(hash: CHash, _key: Input);
|
||||
update(buf: Input): this;
|
||||
digestInto(out: Uint8Array): void;
|
||||
digest(): Uint8Array;
|
||||
_cloneInto(to?: HMAC<T>): HMAC<T>;
|
||||
clone(): HMAC<T>;
|
||||
destroy(): void;
|
||||
}
|
||||
/**
|
||||
* HMAC: RFC2104 message authentication code.
|
||||
* @param hash - function that would be used e.g. sha256
|
||||
* @param key - message key
|
||||
* @param message - message data
|
||||
* @example
|
||||
* import { hmac } from '@noble/hashes/hmac';
|
||||
* import { sha256 } from '@noble/hashes/sha2';
|
||||
* const mac1 = hmac(sha256, 'key', 'message');
|
||||
*/
|
||||
export declare const hmac: {
|
||||
(hash: CHash, key: Input, message: Input): Uint8Array;
|
||||
create(hash: CHash, key: Input): HMAC<any>;
|
||||
};
|
||||
//# sourceMappingURL=hmac.d.ts.map
|
||||
@@ -0,0 +1,22 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
/// <reference lib="es2018" />
|
||||
/// <reference lib="es2019.array" />
|
||||
/// <reference lib="es2019.object" />
|
||||
/// <reference lib="es2019.string" />
|
||||
/// <reference lib="es2019.symbol" />
|
||||
/// <reference lib="es2019.intl" />
|
||||
@@ -0,0 +1,2 @@
|
||||
import type { LibDefinition } from '../variable';
|
||||
export declare const esnext_date: LibDefinition;
|
||||
@@ -0,0 +1,2 @@
|
||||
import type { LibDefinition } from '../variable';
|
||||
export declare const es2017_sharedmemory: LibDefinition;
|
||||
@@ -0,0 +1,6 @@
|
||||
import { Printer } from "../index.js";
|
||||
|
||||
export declare const printers: {
|
||||
estree: Printer;
|
||||
"estree-json": Printer;
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export default false
|
||||
@@ -0,0 +1 @@
|
||||
import"../../get-pipe-path-_tAJyU_v.mjs";import{r as n}from"../../register-C9AniqUt.mjs";import{t as w}from"../../require-CywAB2e6.mjs";import"module";import"node:path";import"../../temporary-directory-BDDVQOvU.mjs";import"node:os";import"node:module";import"node:url";import"node:fs";import"fs";import"os";import"path";import"../../index-DQtFPMc2.mjs";import"esbuild";import"node:crypto";import"../../node-features-JeyyvQz6.mjs";import"../../client-D_mPDF5S.mjs";import"node:net";import"node:util";import"../../index-gbaejti9.mjs";export{n as register,w as require};
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,395 @@
|
||||
/**
|
||||
* Utilities for hex, bytes, CSPRNG.
|
||||
* @module
|
||||
*/
|
||||
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
||||
|
||||
// We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.
|
||||
// node.js versions earlier than v19 don't declare it in global scope.
|
||||
// For node.js, package.json#exports field mapping rewrites import
|
||||
// from `crypto` to `cryptoNode`, which imports native module.
|
||||
// Makes the utils un-importable in browsers without a bundler.
|
||||
// Once node.js 18 is deprecated (2025-04-30), we can just drop the import.
|
||||
import { crypto } from '@noble/hashes/crypto';
|
||||
|
||||
/** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */
|
||||
export function isBytes(a: unknown): a is Uint8Array {
|
||||
return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');
|
||||
}
|
||||
|
||||
/** Asserts something is positive integer. */
|
||||
export function anumber(n: number): void {
|
||||
if (!Number.isSafeInteger(n) || n < 0) throw new Error('positive integer expected, got ' + n);
|
||||
}
|
||||
|
||||
/** Asserts something is Uint8Array. */
|
||||
export function abytes(b: Uint8Array | undefined, ...lengths: number[]): void {
|
||||
if (!isBytes(b)) throw new Error('Uint8Array expected');
|
||||
if (lengths.length > 0 && !lengths.includes(b.length))
|
||||
throw new Error('Uint8Array expected of length ' + lengths + ', got length=' + b.length);
|
||||
}
|
||||
|
||||
/** Asserts something is hash */
|
||||
export function ahash(h: IHash): void {
|
||||
if (typeof h !== 'function' || typeof h.create !== 'function')
|
||||
throw new Error('Hash should be wrapped by utils.createHasher');
|
||||
anumber(h.outputLen);
|
||||
anumber(h.blockLen);
|
||||
}
|
||||
|
||||
/** Asserts a hash instance has not been destroyed / finished */
|
||||
export function aexists(instance: any, checkFinished = true): void {
|
||||
if (instance.destroyed) throw new Error('Hash instance has been destroyed');
|
||||
if (checkFinished && instance.finished) throw new Error('Hash#digest() has already been called');
|
||||
}
|
||||
|
||||
/** Asserts output is properly-sized byte array */
|
||||
export function aoutput(out: any, instance: any): void {
|
||||
abytes(out);
|
||||
const min = instance.outputLen;
|
||||
if (out.length < min) {
|
||||
throw new Error('digestInto() expects output buffer of length at least ' + min);
|
||||
}
|
||||
}
|
||||
|
||||
/** Generic type encompassing 8/16/32-byte arrays - but not 64-byte. */
|
||||
// prettier-ignore
|
||||
export type TypedArray = Int8Array | Uint8ClampedArray | Uint8Array |
|
||||
Uint16Array | Int16Array | Uint32Array | Int32Array;
|
||||
|
||||
/** Cast u8 / u16 / u32 to u8. */
|
||||
export function u8(arr: TypedArray): Uint8Array {
|
||||
return new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
|
||||
}
|
||||
|
||||
/** Cast u8 / u16 / u32 to u32. */
|
||||
export function u32(arr: TypedArray): Uint32Array {
|
||||
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
||||
}
|
||||
|
||||
/** Zeroize a byte array. Warning: JS provides no guarantees. */
|
||||
export function clean(...arrays: TypedArray[]): void {
|
||||
for (let i = 0; i < arrays.length; i++) {
|
||||
arrays[i].fill(0);
|
||||
}
|
||||
}
|
||||
|
||||
/** Create DataView of an array for easy byte-level manipulation. */
|
||||
export function createView(arr: TypedArray): DataView {
|
||||
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
||||
}
|
||||
|
||||
/** The rotate right (circular right shift) operation for uint32 */
|
||||
export function rotr(word: number, shift: number): number {
|
||||
return (word << (32 - shift)) | (word >>> shift);
|
||||
}
|
||||
|
||||
/** The rotate left (circular left shift) operation for uint32 */
|
||||
export function rotl(word: number, shift: number): number {
|
||||
return (word << shift) | ((word >>> (32 - shift)) >>> 0);
|
||||
}
|
||||
|
||||
/** Is current platform little-endian? Most are. Big-Endian platform: IBM */
|
||||
export const isLE: boolean = /* @__PURE__ */ (() =>
|
||||
new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44)();
|
||||
|
||||
/** The byte swap operation for uint32 */
|
||||
export function byteSwap(word: number): number {
|
||||
return (
|
||||
((word << 24) & 0xff000000) |
|
||||
((word << 8) & 0xff0000) |
|
||||
((word >>> 8) & 0xff00) |
|
||||
((word >>> 24) & 0xff)
|
||||
);
|
||||
}
|
||||
/** Conditionally byte swap if on a big-endian platform */
|
||||
export const swap8IfBE: (n: number) => number = isLE
|
||||
? (n: number) => n
|
||||
: (n: number) => byteSwap(n);
|
||||
|
||||
/** @deprecated */
|
||||
export const byteSwapIfBE: typeof swap8IfBE = swap8IfBE;
|
||||
/** In place byte swap for Uint32Array */
|
||||
export function byteSwap32(arr: Uint32Array): Uint32Array {
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
arr[i] = byteSwap(arr[i]);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
export const swap32IfBE: (u: Uint32Array) => Uint32Array = isLE
|
||||
? (u: Uint32Array) => u
|
||||
: byteSwap32;
|
||||
|
||||
// Built-in hex conversion https://caniuse.com/mdn-javascript_builtins_uint8array_fromhex
|
||||
const hasHexBuiltin: boolean = /* @__PURE__ */ (() =>
|
||||
// @ts-ignore
|
||||
typeof Uint8Array.from([]).toHex === 'function' && typeof Uint8Array.fromHex === 'function')();
|
||||
|
||||
// Array where index 0xf0 (240) is mapped to string 'f0'
|
||||
const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) =>
|
||||
i.toString(16).padStart(2, '0')
|
||||
);
|
||||
|
||||
/**
|
||||
* Convert byte array to hex string. Uses built-in function, when available.
|
||||
* @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'
|
||||
*/
|
||||
export function bytesToHex(bytes: Uint8Array): string {
|
||||
abytes(bytes);
|
||||
// @ts-ignore
|
||||
if (hasHexBuiltin) return bytes.toHex();
|
||||
// pre-caching improves the speed 6x
|
||||
let hex = '';
|
||||
for (let i = 0; i < bytes.length; i++) {
|
||||
hex += hexes[bytes[i]];
|
||||
}
|
||||
return hex;
|
||||
}
|
||||
|
||||
// We use optimized technique to convert hex string to byte array
|
||||
const asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 } as const;
|
||||
function asciiToBase16(ch: number): number | undefined {
|
||||
if (ch >= asciis._0 && ch <= asciis._9) return ch - asciis._0; // '2' => 50-48
|
||||
if (ch >= asciis.A && ch <= asciis.F) return ch - (asciis.A - 10); // 'B' => 66-(65-10)
|
||||
if (ch >= asciis.a && ch <= asciis.f) return ch - (asciis.a - 10); // 'b' => 98-(97-10)
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert hex string to byte array. Uses built-in function, when available.
|
||||
* @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])
|
||||
*/
|
||||
export function hexToBytes(hex: string): Uint8Array {
|
||||
if (typeof hex !== 'string') throw new Error('hex string expected, got ' + typeof hex);
|
||||
// @ts-ignore
|
||||
if (hasHexBuiltin) return Uint8Array.fromHex(hex);
|
||||
const hl = hex.length;
|
||||
const al = hl / 2;
|
||||
if (hl % 2) throw new Error('hex string expected, got unpadded hex of length ' + hl);
|
||||
const array = new Uint8Array(al);
|
||||
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
||||
const n1 = asciiToBase16(hex.charCodeAt(hi));
|
||||
const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
|
||||
if (n1 === undefined || n2 === undefined) {
|
||||
const char = hex[hi] + hex[hi + 1];
|
||||
throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
||||
}
|
||||
array[ai] = n1 * 16 + n2; // multiply first octet, e.g. 'a3' => 10*16+3 => 160 + 3 => 163
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* There is no setImmediate in browser and setTimeout is slow.
|
||||
* Call of async fn will return Promise, which will be fullfiled only on
|
||||
* next scheduler queue processing step and this is exactly what we need.
|
||||
*/
|
||||
export const nextTick = async (): Promise<void> => {};
|
||||
|
||||
/** Returns control to thread each 'tick' ms to avoid blocking. */
|
||||
export async function asyncLoop(
|
||||
iters: number,
|
||||
tick: number,
|
||||
cb: (i: number) => void
|
||||
): Promise<void> {
|
||||
let ts = Date.now();
|
||||
for (let i = 0; i < iters; i++) {
|
||||
cb(i);
|
||||
// Date.now() is not monotonic, so in case if clock goes backwards we return return control too
|
||||
const diff = Date.now() - ts;
|
||||
if (diff >= 0 && diff < tick) continue;
|
||||
await nextTick();
|
||||
ts += diff;
|
||||
}
|
||||
}
|
||||
|
||||
// Global symbols, but ts doesn't see them: https://github.com/microsoft/TypeScript/issues/31535
|
||||
declare const TextEncoder: any;
|
||||
declare const TextDecoder: any;
|
||||
|
||||
/**
|
||||
* Converts string to bytes using UTF8 encoding.
|
||||
* @example utf8ToBytes('abc') // Uint8Array.from([97, 98, 99])
|
||||
*/
|
||||
export function utf8ToBytes(str: string): Uint8Array {
|
||||
if (typeof str !== 'string') throw new Error('string expected');
|
||||
return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts bytes to string using UTF8 encoding.
|
||||
* @example bytesToUtf8(Uint8Array.from([97, 98, 99])) // 'abc'
|
||||
*/
|
||||
export function bytesToUtf8(bytes: Uint8Array): string {
|
||||
return new TextDecoder().decode(bytes);
|
||||
}
|
||||
|
||||
/** Accepted input of hash functions. Strings are converted to byte arrays. */
|
||||
export type Input = string | Uint8Array;
|
||||
/**
|
||||
* Normalizes (non-hex) string or Uint8Array to Uint8Array.
|
||||
* Warning: when Uint8Array is passed, it would NOT get copied.
|
||||
* Keep in mind for future mutable operations.
|
||||
*/
|
||||
export function toBytes(data: Input): Uint8Array {
|
||||
if (typeof data === 'string') data = utf8ToBytes(data);
|
||||
abytes(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
/** KDFs can accept string or Uint8Array for user convenience. */
|
||||
export type KDFInput = string | Uint8Array;
|
||||
/**
|
||||
* Helper for KDFs: consumes uint8array or string.
|
||||
* When string is passed, does utf8 decoding, using TextDecoder.
|
||||
*/
|
||||
export function kdfInputToBytes(data: KDFInput): Uint8Array {
|
||||
if (typeof data === 'string') data = utf8ToBytes(data);
|
||||
abytes(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
/** Copies several Uint8Arrays into one. */
|
||||
export function concatBytes(...arrays: Uint8Array[]): Uint8Array {
|
||||
let sum = 0;
|
||||
for (let i = 0; i < arrays.length; i++) {
|
||||
const a = arrays[i];
|
||||
abytes(a);
|
||||
sum += a.length;
|
||||
}
|
||||
const res = new Uint8Array(sum);
|
||||
for (let i = 0, pad = 0; i < arrays.length; i++) {
|
||||
const a = arrays[i];
|
||||
res.set(a, pad);
|
||||
pad += a.length;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
type EmptyObj = {};
|
||||
export function checkOpts<T1 extends EmptyObj, T2 extends EmptyObj>(
|
||||
defaults: T1,
|
||||
opts?: T2
|
||||
): T1 & T2 {
|
||||
if (opts !== undefined && {}.toString.call(opts) !== '[object Object]')
|
||||
throw new Error('options should be object or undefined');
|
||||
const merged = Object.assign(defaults, opts);
|
||||
return merged as T1 & T2;
|
||||
}
|
||||
|
||||
/** Hash interface. */
|
||||
export type IHash = {
|
||||
(data: Uint8Array): Uint8Array;
|
||||
blockLen: number;
|
||||
outputLen: number;
|
||||
create: any;
|
||||
};
|
||||
|
||||
/** For runtime check if class implements interface */
|
||||
export abstract class Hash<T extends Hash<T>> {
|
||||
abstract blockLen: number; // Bytes per block
|
||||
abstract outputLen: number; // Bytes in output
|
||||
abstract update(buf: Input): this;
|
||||
// Writes digest into buf
|
||||
abstract digestInto(buf: Uint8Array): void;
|
||||
abstract digest(): Uint8Array;
|
||||
/**
|
||||
* Resets internal state. Makes Hash instance unusable.
|
||||
* Reset is impossible for keyed hashes if key is consumed into state. If digest is not consumed
|
||||
* by user, they will need to manually call `destroy()` when zeroing is necessary.
|
||||
*/
|
||||
abstract destroy(): void;
|
||||
/**
|
||||
* Clones hash instance. Unsafe: doesn't check whether `to` is valid. Can be used as `clone()`
|
||||
* when no options are passed.
|
||||
* Reasons to use `_cloneInto` instead of clone: 1) performance 2) reuse instance => all internal
|
||||
* buffers are overwritten => causes buffer overwrite which is used for digest in some cases.
|
||||
* There are no guarantees for clean-up because it's impossible in JS.
|
||||
*/
|
||||
abstract _cloneInto(to?: T): T;
|
||||
// Safe version that clones internal state
|
||||
abstract clone(): T;
|
||||
}
|
||||
|
||||
/**
|
||||
* XOF: streaming API to read digest in chunks.
|
||||
* Same as 'squeeze' in keccak/k12 and 'seek' in blake3, but more generic name.
|
||||
* When hash used in XOF mode it is up to user to call '.destroy' afterwards, since we cannot
|
||||
* destroy state, next call can require more bytes.
|
||||
*/
|
||||
export type HashXOF<T extends Hash<T>> = Hash<T> & {
|
||||
xof(bytes: number): Uint8Array; // Read 'bytes' bytes from digest stream
|
||||
xofInto(buf: Uint8Array): Uint8Array; // read buf.length bytes from digest stream into buf
|
||||
};
|
||||
|
||||
/** Hash function */
|
||||
export type CHash = ReturnType<typeof createHasher>;
|
||||
/** Hash function with output */
|
||||
export type CHashO = ReturnType<typeof createOptHasher>;
|
||||
/** XOF with output */
|
||||
export type CHashXO = ReturnType<typeof createXOFer>;
|
||||
|
||||
/** Wraps hash function, creating an interface on top of it */
|
||||
export function createHasher<T extends Hash<T>>(
|
||||
hashCons: () => Hash<T>
|
||||
): {
|
||||
(msg: Input): Uint8Array;
|
||||
outputLen: number;
|
||||
blockLen: number;
|
||||
create(): Hash<T>;
|
||||
} {
|
||||
const hashC = (msg: Input): Uint8Array => hashCons().update(toBytes(msg)).digest();
|
||||
const tmp = hashCons();
|
||||
hashC.outputLen = tmp.outputLen;
|
||||
hashC.blockLen = tmp.blockLen;
|
||||
hashC.create = () => hashCons();
|
||||
return hashC;
|
||||
}
|
||||
|
||||
export function createOptHasher<H extends Hash<H>, T extends Object>(
|
||||
hashCons: (opts?: T) => Hash<H>
|
||||
): {
|
||||
(msg: Input, opts?: T): Uint8Array;
|
||||
outputLen: number;
|
||||
blockLen: number;
|
||||
create(opts?: T): Hash<H>;
|
||||
} {
|
||||
const hashC = (msg: Input, opts?: T): Uint8Array => hashCons(opts).update(toBytes(msg)).digest();
|
||||
const tmp = hashCons({} as T);
|
||||
hashC.outputLen = tmp.outputLen;
|
||||
hashC.blockLen = tmp.blockLen;
|
||||
hashC.create = (opts?: T) => hashCons(opts);
|
||||
return hashC;
|
||||
}
|
||||
|
||||
export function createXOFer<H extends HashXOF<H>, T extends Object>(
|
||||
hashCons: (opts?: T) => HashXOF<H>
|
||||
): {
|
||||
(msg: Input, opts?: T): Uint8Array;
|
||||
outputLen: number;
|
||||
blockLen: number;
|
||||
create(opts?: T): HashXOF<H>;
|
||||
} {
|
||||
const hashC = (msg: Input, opts?: T): Uint8Array => hashCons(opts).update(toBytes(msg)).digest();
|
||||
const tmp = hashCons({} as T);
|
||||
hashC.outputLen = tmp.outputLen;
|
||||
hashC.blockLen = tmp.blockLen;
|
||||
hashC.create = (opts?: T) => hashCons(opts);
|
||||
return hashC;
|
||||
}
|
||||
export const wrapConstructor: typeof createHasher = createHasher;
|
||||
export const wrapConstructorWithOpts: typeof createOptHasher = createOptHasher;
|
||||
export const wrapXOFConstructorWithOpts: typeof createXOFer = createXOFer;
|
||||
|
||||
/** Cryptographically secure PRNG. Uses internal OS-level `crypto.getRandomValues`. */
|
||||
export function randomBytes(bytesLength = 32): Uint8Array {
|
||||
if (crypto && typeof crypto.getRandomValues === 'function') {
|
||||
return crypto.getRandomValues(new Uint8Array(bytesLength));
|
||||
}
|
||||
// Legacy Node.js compatibility
|
||||
if (crypto && typeof crypto.randomBytes === 'function') {
|
||||
return Uint8Array.from(crypto.randomBytes(bytesLength));
|
||||
}
|
||||
throw new Error('crypto.getRandomValues must be defined');
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
import type { LibDefinition } from '../variable';
|
||||
export declare const es2022_string: LibDefinition;
|
||||
@@ -0,0 +1,84 @@
|
||||
import * as BufferLayout from '@solana/buffer-layout';
|
||||
|
||||
import assert from '../../utils/assert';
|
||||
import * as Layout from '../../layout';
|
||||
import {PublicKey} from '../../publickey';
|
||||
import {u64} from '../../utils/bigint';
|
||||
import {decodeData} from '../../account-data';
|
||||
|
||||
export type AddressLookupTableState = {
|
||||
deactivationSlot: bigint;
|
||||
lastExtendedSlot: number;
|
||||
lastExtendedSlotStartIndex: number;
|
||||
authority?: PublicKey;
|
||||
addresses: Array<PublicKey>;
|
||||
};
|
||||
|
||||
export type AddressLookupTableAccountArgs = {
|
||||
key: PublicKey;
|
||||
state: AddressLookupTableState;
|
||||
};
|
||||
|
||||
/// The serialized size of lookup table metadata
|
||||
const LOOKUP_TABLE_META_SIZE = 56;
|
||||
|
||||
export class AddressLookupTableAccount {
|
||||
key: PublicKey;
|
||||
state: AddressLookupTableState;
|
||||
|
||||
constructor(args: AddressLookupTableAccountArgs) {
|
||||
this.key = args.key;
|
||||
this.state = args.state;
|
||||
}
|
||||
|
||||
isActive(): boolean {
|
||||
const U64_MAX = BigInt('0xffffffffffffffff');
|
||||
return this.state.deactivationSlot === U64_MAX;
|
||||
}
|
||||
|
||||
static deserialize(accountData: Uint8Array): AddressLookupTableState {
|
||||
const meta = decodeData(LookupTableMetaLayout, accountData);
|
||||
|
||||
const serializedAddressesLen = accountData.length - LOOKUP_TABLE_META_SIZE;
|
||||
assert(serializedAddressesLen >= 0, 'lookup table is invalid');
|
||||
assert(serializedAddressesLen % 32 === 0, 'lookup table is invalid');
|
||||
|
||||
const numSerializedAddresses = serializedAddressesLen / 32;
|
||||
const {addresses} = BufferLayout.struct<{addresses: Array<Uint8Array>}>([
|
||||
BufferLayout.seq(Layout.publicKey(), numSerializedAddresses, 'addresses'),
|
||||
]).decode(accountData.slice(LOOKUP_TABLE_META_SIZE));
|
||||
|
||||
return {
|
||||
deactivationSlot: meta.deactivationSlot,
|
||||
lastExtendedSlot: meta.lastExtendedSlot,
|
||||
lastExtendedSlotStartIndex: meta.lastExtendedStartIndex,
|
||||
authority:
|
||||
meta.authority.length !== 0
|
||||
? new PublicKey(meta.authority[0])
|
||||
: undefined,
|
||||
addresses: addresses.map(address => new PublicKey(address)),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const LookupTableMetaLayout = {
|
||||
index: 1,
|
||||
layout: BufferLayout.struct<{
|
||||
typeIndex: number;
|
||||
deactivationSlot: bigint;
|
||||
lastExtendedSlot: number;
|
||||
lastExtendedStartIndex: number;
|
||||
authority: Array<Uint8Array>;
|
||||
}>([
|
||||
BufferLayout.u32('typeIndex'),
|
||||
u64('deactivationSlot'),
|
||||
BufferLayout.nu64('lastExtendedSlot'),
|
||||
BufferLayout.u8('lastExtendedStartIndex'),
|
||||
BufferLayout.u8(), // option
|
||||
BufferLayout.seq(
|
||||
Layout.publicKey(),
|
||||
BufferLayout.offset(BufferLayout.u8(), -1),
|
||||
'authority',
|
||||
),
|
||||
]),
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
import { n as __toESM, t as require_binding } from "./shared/binding-Zhafd14U.mjs";
|
||||
import { c as PluginContextData, n as bindingifyPlugin } from "./shared/bindingify-input-options-C-Zsy1EG.mjs";
|
||||
import { parentPort, workerData } from "node:worker_threads";
|
||||
//#region src/parallel-plugin-worker.ts
|
||||
var import_binding = /* @__PURE__ */ __toESM(require_binding(), 1);
|
||||
const { registryId, pluginInfos, threadNumber } = workerData;
|
||||
(async () => {
|
||||
try {
|
||||
const plugins = await Promise.all(pluginInfos.map(async (pluginInfo) => {
|
||||
const definePluginImpl = (await import(pluginInfo.fileUrl)).default;
|
||||
const plugin = await definePluginImpl(pluginInfo.options, { threadNumber });
|
||||
return {
|
||||
index: pluginInfo.index,
|
||||
plugin: bindingifyPlugin(plugin, {}, {}, new PluginContextData(() => {}, {}, [], []), [], () => {}, "info", false, void 0)
|
||||
};
|
||||
}));
|
||||
(0, import_binding.registerPlugins)(registryId, plugins);
|
||||
parentPort.postMessage({ type: "success" });
|
||||
} catch (error) {
|
||||
parentPort.postMessage({
|
||||
type: "error",
|
||||
error
|
||||
});
|
||||
} finally {
|
||||
parentPort.unref();
|
||||
}
|
||||
})();
|
||||
//#endregion
|
||||
export {};
|
||||
@@ -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 () {
|
||||
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 tsutils = __importStar(require("ts-api-utils"));
|
||||
const util_1 = require("../util");
|
||||
exports.default = (0, util_1.createRule)({
|
||||
name: 'no-unsafe-call',
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'Disallow calling a value with type `any`',
|
||||
recommended: 'recommended',
|
||||
requiresTypeChecking: true,
|
||||
},
|
||||
messages: {
|
||||
errorCall: 'Unsafe call of a type that could not be resolved.',
|
||||
errorCallThis: 'Unsafe call of a `this` type that could not be resolved.',
|
||||
errorNew: 'Unsafe construction of a type that could not be resolved.',
|
||||
errorTemplateTag: 'Unsafe use of a template tag whose type could not be resolved.',
|
||||
unsafeCall: 'Unsafe call of {{type}} typed value.',
|
||||
unsafeCallThis: [
|
||||
'Unsafe call of {{type}} typed value. `this` is typed as {{type}}.',
|
||||
'You can try to fix this by turning on the `noImplicitThis` compiler option, or adding a `this` parameter to the function.',
|
||||
].join('\n'),
|
||||
unsafeNew: 'Unsafe construction of {{type}} typed value.',
|
||||
unsafeTemplateTag: 'Unsafe use of {{type}} typed template tag.',
|
||||
},
|
||||
schema: [],
|
||||
},
|
||||
defaultOptions: [],
|
||||
create(context) {
|
||||
const services = (0, util_1.getParserServices)(context);
|
||||
const compilerOptions = services.program.getCompilerOptions();
|
||||
const isNoImplicitThis = tsutils.isStrictCompilerOptionEnabled(compilerOptions, 'noImplicitThis');
|
||||
function checkCall(node, reportingNode, unsafeMessageId, errorMessageId) {
|
||||
const type = (0, util_1.getConstrainedTypeAtLocation)(services, node);
|
||||
if ((0, util_1.isTypeAnyType)(type)) {
|
||||
if (!isNoImplicitThis) {
|
||||
// `this()` or `this.foo()` or `this.foo[bar]()`
|
||||
const thisExpression = (0, util_1.getThisExpression)(node);
|
||||
if (thisExpression &&
|
||||
(0, util_1.isTypeAnyType)((0, util_1.getConstrainedTypeAtLocation)(services, thisExpression))) {
|
||||
unsafeMessageId = 'unsafeCallThis';
|
||||
errorMessageId = 'errorCallThis';
|
||||
}
|
||||
}
|
||||
const isErrorType = tsutils.isIntrinsicErrorType(type);
|
||||
context.report({
|
||||
node: reportingNode,
|
||||
messageId: isErrorType ? errorMessageId : unsafeMessageId,
|
||||
data: {
|
||||
type: 'an `any`',
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
if ((0, util_1.isBuiltinSymbolLike)(services.program, type, 'Function')) {
|
||||
// this also matches subtypes of `Function`, like `interface Foo extends Function {}`.
|
||||
//
|
||||
// For weird TS reasons that I don't understand, these are
|
||||
//
|
||||
// safe to construct if:
|
||||
// - they have at least one call signature _that is not void-returning_,
|
||||
// - OR they have at least one construct signature.
|
||||
//
|
||||
// safe to call (including as template) if:
|
||||
// - they have at least one call signature
|
||||
// - OR they have at least one construct signature.
|
||||
const constructSignatures = type.getConstructSignatures();
|
||||
if (constructSignatures.length > 0) {
|
||||
return;
|
||||
}
|
||||
const callSignatures = type.getCallSignatures();
|
||||
if (unsafeMessageId === 'unsafeNew') {
|
||||
if (callSignatures.some(signature => !tsutils.isIntrinsicVoidType(signature.getReturnType()))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (callSignatures.length > 0) {
|
||||
return;
|
||||
}
|
||||
context.report({
|
||||
node: reportingNode,
|
||||
messageId: unsafeMessageId,
|
||||
data: {
|
||||
type: 'a `Function`',
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
return {
|
||||
'CallExpression > *.callee'(node) {
|
||||
checkCall(node, node, 'unsafeCall', 'errorCall');
|
||||
},
|
||||
NewExpression(node) {
|
||||
checkCall(node.callee, node, 'unsafeNew', 'errorNew');
|
||||
},
|
||||
'TaggedTemplateExpression > *.tag'(node) {
|
||||
checkCall(node, node, 'unsafeTemplateTag', 'errorTemplateTag');
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,5 @@
|
||||
import assertClassBrand from "./assertClassBrand.js";
|
||||
function _classPrivateGetter(s, r, a) {
|
||||
return a(assertClassBrand(s, r));
|
||||
}
|
||||
export { _classPrivateGetter as default };
|
||||
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.VisitorBase = exports.Visitor = void 0;
|
||||
const PatternVisitor_1 = require("./PatternVisitor");
|
||||
const VisitorBase_1 = require("./VisitorBase");
|
||||
class Visitor extends VisitorBase_1.VisitorBase {
|
||||
#options;
|
||||
constructor(optionsOrVisitor) {
|
||||
super(optionsOrVisitor instanceof Visitor
|
||||
? optionsOrVisitor.#options
|
||||
: optionsOrVisitor);
|
||||
this.#options =
|
||||
optionsOrVisitor instanceof Visitor
|
||||
? optionsOrVisitor.#options
|
||||
: optionsOrVisitor;
|
||||
}
|
||||
visitPattern(node, callback, options = { processRightHandNodes: false }) {
|
||||
// Call the callback at left hand identifier nodes, and Collect right hand nodes.
|
||||
const visitor = new PatternVisitor_1.PatternVisitor(this.#options, node, callback);
|
||||
visitor.visit(node);
|
||||
// Process the right hand nodes recursively.
|
||||
if (options.processRightHandNodes) {
|
||||
visitor.rightHandNodes.forEach(this.visit, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.Visitor = Visitor;
|
||||
var VisitorBase_2 = require("./VisitorBase");
|
||||
Object.defineProperty(exports, "VisitorBase", { enumerable: true, get: function () { return VisitorBase_2.VisitorBase; } });
|
||||
@@ -0,0 +1,21 @@
|
||||
name: CI Tests
|
||||
|
||||
on:
|
||||
- pull_request
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [10.x, 12.x, 13.x]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- run: npm i && npm test
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Blake2b hash function. Focuses on 64-bit platforms, but in JS speed different from Blake2s is negligible.
|
||||
* @module
|
||||
* @deprecated
|
||||
*/
|
||||
import { BLAKE2b as B2B, blake2b as b2b } from './blake2.ts';
|
||||
/** @deprecated Use import from `noble/hashes/blake2` module */
|
||||
export declare const BLAKE2b: typeof B2B;
|
||||
/** @deprecated Use import from `noble/hashes/blake2` module */
|
||||
export declare const blake2b: typeof b2b;
|
||||
//# sourceMappingURL=blake2b.d.ts.map
|
||||
@@ -0,0 +1,35 @@
|
||||
import { VitestModuleEvaluator } from './module-evaluator.js';
|
||||
import { V as VITEST_VM_CONTEXT_SYMBOL, s as startVitestModuleRunner, a as VitestModuleRunner } from './chunks/startVitestModuleRunner.DB-7oCpn.js';
|
||||
import { g as getWorkerState } from './chunks/utils.BX5Fg8C4.js';
|
||||
export { e as builtinEnvironments, p as populateGlobal } from './chunks/index.DC7d2Pf8.js';
|
||||
export { VitestNodeSnapshotEnvironment as VitestSnapshotEnvironment } from './chunks/node.COQbm6gK.js';
|
||||
import 'node:module';
|
||||
import 'node:url';
|
||||
import 'node:vm';
|
||||
import 'vite/module-runner';
|
||||
import './chunks/traces.DT5aQ62U.js';
|
||||
import 'node:fs';
|
||||
import '@vitest/utils/helpers';
|
||||
import './chunks/modules.BJuCwlRJ.js';
|
||||
import 'pathe';
|
||||
import './path.js';
|
||||
import 'node:path';
|
||||
import '@vitest/mocker';
|
||||
import '@vitest/mocker/redirect';
|
||||
import '@vitest/utils/timers';
|
||||
import 'node:console';
|
||||
import '@vitest/snapshot/environment';
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
const __INTERNAL = {
|
||||
VitestModuleEvaluator,
|
||||
VitestModuleRunner,
|
||||
startVitestModuleRunner,
|
||||
VITEST_VM_CONTEXT_SYMBOL,
|
||||
getWorkerState
|
||||
};
|
||||
// #endregion
|
||||
|
||||
export { __INTERNAL };
|
||||
Reference in New Issue
Block a user