WIP: bootstrap and partial real Solana watcher implementation
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
import type { LibDefinition } from '../variable';
|
||||
export declare const decorators: LibDefinition;
|
||||
@@ -0,0 +1,159 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABILITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
|
||||
interface Map<K, V> {
|
||||
/**
|
||||
* Removes all elements from the Map.
|
||||
*/
|
||||
clear(): void;
|
||||
/**
|
||||
* @returns true if an element in the Map existed and has been removed, or false if the element does not exist.
|
||||
*/
|
||||
delete(key: K): boolean;
|
||||
/**
|
||||
* Executes a provided function once per each key/value pair in the Map, in insertion order.
|
||||
*/
|
||||
forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void;
|
||||
/**
|
||||
* Returns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.
|
||||
* @returns Returns the element associated with the specified key. If no element is associated with the specified key, undefined is returned.
|
||||
*/
|
||||
get(key: K): V | undefined;
|
||||
/**
|
||||
* @returns boolean indicating whether an element with the specified key exists or not.
|
||||
*/
|
||||
has(key: K): boolean;
|
||||
/**
|
||||
* Adds a new element with a specified key and value to the Map. If an element with the same key already exists, the element will be updated.
|
||||
*/
|
||||
set(key: K, value: V): this;
|
||||
/**
|
||||
* @returns the number of elements in the Map.
|
||||
*/
|
||||
readonly size: number;
|
||||
}
|
||||
|
||||
interface MapConstructor {
|
||||
new (): Map<any, any>;
|
||||
new <K, V>(entries?: readonly (readonly [K, V])[] | null): Map<K, V>;
|
||||
readonly prototype: Map<any, any>;
|
||||
}
|
||||
declare var Map: MapConstructor;
|
||||
|
||||
interface ReadonlyMap<K, V> {
|
||||
forEach(callbackfn: (value: V, key: K, map: ReadonlyMap<K, V>) => void, thisArg?: any): void;
|
||||
get(key: K): V | undefined;
|
||||
has(key: K): boolean;
|
||||
readonly size: number;
|
||||
}
|
||||
|
||||
interface WeakMap<K extends WeakKey, V> {
|
||||
/**
|
||||
* Removes the specified element from the WeakMap.
|
||||
* @returns true if the element was successfully removed, or false if it was not present.
|
||||
*/
|
||||
delete(key: K): boolean;
|
||||
/**
|
||||
* @returns a specified element.
|
||||
*/
|
||||
get(key: K): V | undefined;
|
||||
/**
|
||||
* @returns a boolean indicating whether an element with the specified key exists or not.
|
||||
*/
|
||||
has(key: K): boolean;
|
||||
/**
|
||||
* Adds a new element with a specified key and value.
|
||||
* @param key Must be an object or symbol.
|
||||
*/
|
||||
set(key: K, value: V): this;
|
||||
}
|
||||
|
||||
interface WeakMapConstructor {
|
||||
new <K extends WeakKey = WeakKey, V = any>(entries?: readonly (readonly [K, V])[] | null): WeakMap<K, V>;
|
||||
readonly prototype: WeakMap<WeakKey, any>;
|
||||
}
|
||||
declare var WeakMap: WeakMapConstructor;
|
||||
|
||||
interface Set<T> {
|
||||
/**
|
||||
* Appends a new element with a specified value to the end of the Set.
|
||||
*/
|
||||
add(value: T): this;
|
||||
/**
|
||||
* Removes all elements from the Set.
|
||||
*/
|
||||
clear(): void;
|
||||
/**
|
||||
* Removes a specified value from the Set.
|
||||
* @returns Returns true if an element in the Set existed and has been removed, or false if the element does not exist.
|
||||
*/
|
||||
delete(value: T): boolean;
|
||||
/**
|
||||
* Executes a provided function once per each value in the Set object, in insertion order.
|
||||
*/
|
||||
forEach(callbackfn: (value: T, value2: T, set: Set<T>) => void, thisArg?: any): void;
|
||||
/**
|
||||
* @returns a boolean indicating whether an element with the specified value exists in the Set or not.
|
||||
*/
|
||||
has(value: T): boolean;
|
||||
/**
|
||||
* @returns the number of (unique) elements in the Set.
|
||||
*/
|
||||
readonly size: number;
|
||||
}
|
||||
|
||||
interface SetConstructor {
|
||||
new <T = any>(values?: readonly T[] | null): Set<T>;
|
||||
readonly prototype: Set<any>;
|
||||
}
|
||||
declare var Set: SetConstructor;
|
||||
|
||||
interface ReadonlySet<T> {
|
||||
/**
|
||||
* Executes a provided function once per each value in the ReadonlySet object, in insertion order.
|
||||
*/
|
||||
forEach(callbackfn: (value: T, value2: T, set: ReadonlySet<T>) => void, thisArg?: any): void;
|
||||
/**
|
||||
* @returns a boolean indicating whether an element with the specified value exists in the Set or not.
|
||||
*/
|
||||
has(value: T): boolean;
|
||||
/**
|
||||
* @returns the number of (unique) elements in the Set.
|
||||
*/
|
||||
readonly size: number;
|
||||
}
|
||||
|
||||
interface WeakSet<T extends WeakKey> {
|
||||
/**
|
||||
* Appends a new value to the end of the WeakSet.
|
||||
*/
|
||||
add(value: T): this;
|
||||
/**
|
||||
* Removes the specified element from the WeakSet.
|
||||
* @returns Returns true if the element existed and has been removed, or false if the element does not exist.
|
||||
*/
|
||||
delete(value: T): boolean;
|
||||
/**
|
||||
* @returns a boolean indicating whether a value exists in the WeakSet or not.
|
||||
*/
|
||||
has(value: T): boolean;
|
||||
}
|
||||
|
||||
interface WeakSetConstructor {
|
||||
new <T extends WeakKey = WeakKey>(values?: readonly T[] | null): WeakSet<T>;
|
||||
readonly prototype: WeakSet<WeakKey>;
|
||||
}
|
||||
declare var WeakSet: WeakSetConstructor;
|
||||
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* @fileoverview Interpolate keys from an object into a string with {{ }} markers.
|
||||
* @author Jed Fox
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Public Interface
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns a global expression matching placeholders in messages.
|
||||
* @returns {RegExp} Global regular expression matching placeholders
|
||||
*/
|
||||
function getPlaceholderMatcher() {
|
||||
return /\{\{([^{}]+)\}\}/gu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces {{ placeholders }} in the message with the provided data.
|
||||
* Does not replace placeholders not available in the data.
|
||||
* @param {string} text Original message with potential placeholders
|
||||
* @param {Record<string, string>} data Map of placeholder name to its value
|
||||
* @returns {string} Message with replaced placeholders
|
||||
*/
|
||||
function interpolate(text, data) {
|
||||
if (!data) {
|
||||
return text;
|
||||
}
|
||||
|
||||
const matcher = getPlaceholderMatcher();
|
||||
|
||||
// Substitution content for any {{ }} markers.
|
||||
return text.replace(matcher, (fullMatch, termWithWhitespace) => {
|
||||
const term = termWithWhitespace.trim();
|
||||
|
||||
if (term in data) {
|
||||
return data[term];
|
||||
}
|
||||
|
||||
// Preserve old behavior: If parameter name not provided, don't replace it.
|
||||
return fullMatch;
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getPlaceholderMatcher,
|
||||
interpolate,
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Parser } from 'acorn'
|
||||
|
||||
declare const jsx: (options?: jsx.Options) => (BaseParser: typeof Parser) => typeof Parser;
|
||||
|
||||
declare namespace jsx {
|
||||
interface Options {
|
||||
allowNamespacedObjects?: boolean;
|
||||
allowNamespaces?: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
export = jsx;
|
||||
@@ -0,0 +1,59 @@
|
||||
import { expect, test } from "vitest";
|
||||
import * as z from "zod/v4";
|
||||
|
||||
test("safeExtend chaining preserves and overrides properties", () => {
|
||||
const schema1 = z.object({
|
||||
email: z.string(),
|
||||
});
|
||||
|
||||
const schema2 = schema1.safeExtend({
|
||||
email: schema1.shape.email.check(z.email()),
|
||||
});
|
||||
|
||||
const schema3 = schema2.safeExtend({
|
||||
email: schema2.shape.email.or(z.literal("")),
|
||||
});
|
||||
|
||||
schema3.parse({ email: "test@example.com" });
|
||||
});
|
||||
|
||||
test("extend with constructor field in shape", () => {
|
||||
const baseSchema = z.object({
|
||||
name: z.string(),
|
||||
});
|
||||
|
||||
const extendedSchema = baseSchema.extend({
|
||||
constructor: z.string(),
|
||||
age: z.number(),
|
||||
});
|
||||
|
||||
const result = extendedSchema.parse({
|
||||
name: "John",
|
||||
constructor: "Person",
|
||||
age: 30,
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
name: "John",
|
||||
constructor: "Person",
|
||||
age: 30,
|
||||
});
|
||||
|
||||
const testCases = [
|
||||
{ name: "Test", constructor: 123, age: 25 },
|
||||
{ name: "Test", constructor: null, age: 25 },
|
||||
{ name: "Test", constructor: true, age: 25 },
|
||||
{ name: "Test", constructor: {}, age: 25 },
|
||||
];
|
||||
|
||||
for (const testCase of testCases) {
|
||||
const anyConstructorSchema = baseSchema.extend({
|
||||
constructor: z.any(),
|
||||
age: z.number(),
|
||||
});
|
||||
|
||||
expect(() => anyConstructorSchema.parse(testCase)).not.toThrow();
|
||||
const parsed = anyConstructorSchema.parse(testCase);
|
||||
expect(parsed).toEqual(testCase);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,70 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const utils_1 = require("@typescript-eslint/utils");
|
||||
const util_1 = require("../util");
|
||||
function isEmptyExport(node) {
|
||||
return (node.type === utils_1.AST_NODE_TYPES.ExportNamedDeclaration &&
|
||||
node.specifiers.length === 0 &&
|
||||
!node.declaration);
|
||||
}
|
||||
const exportOrImportNodeTypes = new Set([
|
||||
utils_1.AST_NODE_TYPES.ExportAllDeclaration,
|
||||
utils_1.AST_NODE_TYPES.ExportDefaultDeclaration,
|
||||
utils_1.AST_NODE_TYPES.ExportNamedDeclaration,
|
||||
utils_1.AST_NODE_TYPES.ExportSpecifier,
|
||||
utils_1.AST_NODE_TYPES.ImportDeclaration,
|
||||
utils_1.AST_NODE_TYPES.TSExportAssignment,
|
||||
utils_1.AST_NODE_TYPES.TSImportEqualsDeclaration,
|
||||
]);
|
||||
exports.default = (0, util_1.createRule)({
|
||||
name: 'no-useless-empty-export',
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
docs: {
|
||||
description: "Disallow empty exports that don't change anything in a module file",
|
||||
},
|
||||
fixable: 'code',
|
||||
hasSuggestions: false,
|
||||
messages: {
|
||||
uselessExport: 'Empty export does nothing and can be removed.',
|
||||
},
|
||||
schema: [],
|
||||
},
|
||||
defaultOptions: [],
|
||||
create(context) {
|
||||
// In a definition file, export {} is necessary to make the module properly
|
||||
// encapsulated, even when there are other exports
|
||||
// https://github.com/typescript-eslint/typescript-eslint/issues/4975
|
||||
if ((0, util_1.isDefinitionFile)(context.filename)) {
|
||||
return {};
|
||||
}
|
||||
function checkNode(node) {
|
||||
if (!Array.isArray(node.body)) {
|
||||
return;
|
||||
}
|
||||
const emptyExports = [];
|
||||
let foundOtherExport = false;
|
||||
for (const statement of node.body) {
|
||||
if (isEmptyExport(statement)) {
|
||||
emptyExports.push(statement);
|
||||
}
|
||||
else if (exportOrImportNodeTypes.has(statement.type)) {
|
||||
foundOtherExport = true;
|
||||
}
|
||||
}
|
||||
if (foundOtherExport) {
|
||||
for (const emptyExport of emptyExports) {
|
||||
context.report({
|
||||
node: emptyExport,
|
||||
messageId: 'uselessExport',
|
||||
fix: fixer => fixer.remove(emptyExport),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
Program: checkNode,
|
||||
TSModuleDeclaration: checkNode,
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"outerExpressionKinds.enum.js","sourceRoot":"","sources":["../../src/enums/outerExpressionKinds.enum.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAE/F,MAAM,CAAN,IAAY,oBAcX;AAdD,WAAY,oBAAoB;IAC5B,6EAAoB,CAAA;IACpB,mFAAuB,CAAA;IACvB,yFAA0B,CAAA;IAC1B,6GAAoC,CAAA;IACpC,gHAAqC,CAAA;IACrC,0EAAkB,CAAA;IAClB,0GAAkC,CAAA;IAClC,+EAAoB,CAAA;IACpB,mEAAc,CAAA;IACd,4EAA2D,CAAA;IAC3D,8DAA2F,CAAA;IAC3F,yJAAqG,CAAA;IACrG,2GAA6D,CAAA;AACjE,CAAC,EAdW,oBAAoB,KAApB,oBAAoB,QAc/B"}
|
||||
@@ -0,0 +1,158 @@
|
||||
"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 tsutils = __importStar(require("ts-api-utils"));
|
||||
const ts_api_utils_1 = require("ts-api-utils");
|
||||
const ts = __importStar(require("typescript"));
|
||||
const util_1 = require("../util");
|
||||
const promiseUtils_1 = require("../util/promiseUtils");
|
||||
exports.default = (0, util_1.createRule)({
|
||||
name: 'only-throw-error',
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'Disallow throwing non-`Error` values as exceptions',
|
||||
extendsBaseRule: 'no-throw-literal',
|
||||
recommended: 'recommended',
|
||||
requiresTypeChecking: true,
|
||||
},
|
||||
messages: {
|
||||
object: 'Expected an error object to be thrown.',
|
||||
undef: 'Do not throw undefined.',
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
type: 'object',
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
allow: {
|
||||
...util_1.typeOrValueSpecifiersSchema,
|
||||
description: 'Type specifiers that can be thrown.',
|
||||
},
|
||||
allowRethrowing: {
|
||||
type: 'boolean',
|
||||
description: 'Whether to allow rethrowing caught values that are not `Error` objects.',
|
||||
},
|
||||
allowThrowingAny: {
|
||||
type: 'boolean',
|
||||
description: 'Whether to always allow throwing values typed as `any`.',
|
||||
},
|
||||
allowThrowingUnknown: {
|
||||
type: 'boolean',
|
||||
description: 'Whether to always allow throwing values typed as `unknown`.',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
defaultOptions: [
|
||||
{
|
||||
allow: [],
|
||||
allowRethrowing: true,
|
||||
allowThrowingAny: true,
|
||||
allowThrowingUnknown: true,
|
||||
},
|
||||
],
|
||||
create(context, [options]) {
|
||||
const services = (0, util_1.getParserServices)(context);
|
||||
const allow = options.allow;
|
||||
function isRethrownError(node) {
|
||||
if (node.type !== utils_1.AST_NODE_TYPES.Identifier) {
|
||||
return false;
|
||||
}
|
||||
const scope = context.sourceCode.getScope(node);
|
||||
const smVariable = (0, util_1.nullThrows)((0, util_1.findVariable)(scope, node), `Variable ${node.name} should exist in scope manager`);
|
||||
const variableDefinitions = smVariable.defs.filter(def => def.isVariableDefinition);
|
||||
if (variableDefinitions.length !== 1) {
|
||||
return false;
|
||||
}
|
||||
const def = smVariable.defs[0];
|
||||
// try { /* ... */ } catch (x) { throw x; }
|
||||
if (def.node.type === utils_1.AST_NODE_TYPES.CatchClause) {
|
||||
return true;
|
||||
}
|
||||
// promise.catch(x => { throw x; })
|
||||
// promise.then(onFulfilled, x => { throw x; })
|
||||
if (def.node.type === utils_1.AST_NODE_TYPES.ArrowFunctionExpression &&
|
||||
def.node.params.length >= 1 &&
|
||||
def.node.params[0] === def.name &&
|
||||
def.node.parent.type === utils_1.AST_NODE_TYPES.CallExpression) {
|
||||
const callExpression = def.node.parent;
|
||||
const parsedPromiseHandlingCall = (0, promiseUtils_1.parseCatchCall)(callExpression, context) ??
|
||||
(0, promiseUtils_1.parseThenCall)(callExpression, context);
|
||||
if (parsedPromiseHandlingCall != null) {
|
||||
const { object, onRejected } = parsedPromiseHandlingCall;
|
||||
if (onRejected === def.node) {
|
||||
const tsObjectNode = services.esTreeNodeToTSNodeMap.get(object);
|
||||
// make sure we're actually dealing with a promise
|
||||
if ((0, ts_api_utils_1.isThenableType)(services.program.getTypeChecker(), tsObjectNode)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function checkThrowArgument(node) {
|
||||
if (options.allowRethrowing && isRethrownError(node)) {
|
||||
return;
|
||||
}
|
||||
const type = services.getTypeAtLocation(node);
|
||||
if ((0, util_1.typeMatchesSomeSpecifier)(type, allow, services.program)) {
|
||||
return;
|
||||
}
|
||||
if (tsutils.isTypeFlagSet(type, ts.TypeFlags.Undefined)) {
|
||||
context.report({ node, messageId: 'undef' });
|
||||
return;
|
||||
}
|
||||
if (options.allowThrowingAny && (0, util_1.isTypeAnyType)(type)) {
|
||||
return;
|
||||
}
|
||||
if (options.allowThrowingUnknown && (0, util_1.isTypeUnknownType)(type)) {
|
||||
return;
|
||||
}
|
||||
if ((0, util_1.isErrorLike)(services.program, type)) {
|
||||
return;
|
||||
}
|
||||
context.report({ node, messageId: 'object' });
|
||||
}
|
||||
return {
|
||||
ThrowStatement(node) {
|
||||
checkThrowArgument(node.argument);
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
Binary file not shown.
@@ -0,0 +1,24 @@
|
||||
"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.es2024_full = void 0;
|
||||
const dom_1 = require("./dom");
|
||||
const dom_asynciterable_1 = require("./dom.asynciterable");
|
||||
const dom_iterable_1 = require("./dom.iterable");
|
||||
const es2024_1 = require("./es2024");
|
||||
const scripthost_1 = require("./scripthost");
|
||||
const webworker_importscripts_1 = require("./webworker.importscripts");
|
||||
exports.es2024_full = {
|
||||
libs: [
|
||||
es2024_1.es2024,
|
||||
dom_1.dom,
|
||||
webworker_importscripts_1.webworker_importscripts,
|
||||
scripthost_1.scripthost,
|
||||
dom_iterable_1.dom_iterable,
|
||||
dom_asynciterable_1.dom_asynciterable,
|
||||
],
|
||||
variables: [],
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"main": "../../cjs/_using_ctx.cjs",
|
||||
"module": "../../esm/_using_ctx.js"
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
# stream-json [![NPM version][npm-image]][npm-url]
|
||||
|
||||
[npm-image]: https://img.shields.io/npm/v/stream-json.svg
|
||||
[npm-url]: https://npmjs.org/package/stream-json
|
||||
|
||||
`stream-json` is a micro-library of node.js stream components with minimal dependencies for creating custom data processors oriented on processing huge JSON files while requiring a minimal memory footprint. It can parse JSON files far exceeding available memory. Even individual primitive data items (keys, strings, and numbers) can be streamed piece-wise. Streaming SAX-inspired event-based API is included as well.
|
||||
|
||||
Available components:
|
||||
|
||||
* Streaming JSON [Parser](https://github.com/uhop/stream-json/wiki/Parser).
|
||||
* It produces a SAX-like token stream.
|
||||
* Optionally it can pack keys, strings, and numbers (controlled separately).
|
||||
* The [main module](https://github.com/uhop/stream-json/wiki/Main-module) provides helpers to create a parser.
|
||||
* Filters to edit a token stream:
|
||||
* [Pick](https://github.com/uhop/stream-json/wiki/Pick) selects desired objects.
|
||||
* It can produces multiple top-level objects just like in [JSON Streaming](https://en.wikipedia.org/wiki/JSON_Streaming) protocol.
|
||||
* Don't forget to use [StreamValues](https://github.com/uhop/stream-json/wiki/StreamValues) when picking several subobjects!
|
||||
* [Replace](https://github.com/uhop/stream-json/wiki/Replace) substitutes objects with a replacement.
|
||||
* [Ignore](https://github.com/uhop/stream-json/wiki/Ignore) removes objects.
|
||||
* [Filter](https://github.com/uhop/stream-json/wiki/Filter) filters tokens maintaining stream's validity.
|
||||
* Streamers to produce a stream of JavaScript objects.
|
||||
* [StreamValues](https://github.com/uhop/stream-json/wiki/StreamValues) can handle a stream of JSON objects.
|
||||
* Useful to stream objects selected by `Pick`, or generated by other means.
|
||||
* It supports [JSON Streaming](https://en.wikipedia.org/wiki/JSON_Streaming) protocol, where individual values are separated semantically (like in `"{}[]"`), or with white spaces (like in `"true 1 null"`).
|
||||
* [StreamArray](https://github.com/uhop/stream-json/wiki/StreamArray) takes an array of objects and produces a stream of its components.
|
||||
* It streams array components individually taking care of assembling them automatically.
|
||||
* Created initially to deal with JSON files similar to [Django](https://www.djangoproject.com/)-produced database dumps.
|
||||
* Only one top-level array per stream is valid!
|
||||
* [StreamObject](https://github.com/uhop/stream-json/wiki/StreamObject) takes an object and produces a stream of its top-level properties.
|
||||
* Only one top-level object per stream is valid!
|
||||
* Essentials:
|
||||
* [Assembler](https://github.com/uhop/stream-json/wiki/Assembler) interprets a token stream creating JavaScript objects.
|
||||
* [Disassembler](https://github.com/uhop/stream-json/wiki/Disassembler) produces a token stream from JavaScript objects.
|
||||
* [Stringer](https://github.com/uhop/stream-json/wiki/Stringer) converts a token stream back into a JSON text stream.
|
||||
* [Emitter](https://github.com/uhop/stream-json/wiki/Emitter) reads a token stream and emits each token as an event.
|
||||
* It can greatly simplify data processing.
|
||||
* Utilities:
|
||||
* [emit()](https://github.com/uhop/stream-json/wiki/emit()) makes any stream component to emit tokens as events.
|
||||
* [withParser()](https://github.com/uhop/stream-json/wiki/withParser()) helps to create stream components with a parser.
|
||||
* [Batch](https://github.com/uhop/stream-json/wiki/Batch) batches items into arrays to simplify their processing.
|
||||
* [Verifier](https://github.com/uhop/stream-json/wiki/Verifier) reads a stream and verifies that it is a valid JSON.
|
||||
* [Utf8Stream](https://github.com/uhop/stream-json/wiki/Utf8Stream) sanitizes multibyte `utf8` text input.
|
||||
* Special helpers:
|
||||
* JSONL AKA [JSON Lines](http://jsonlines.org/) AKA [NDJSON](http://ndjson.org/):
|
||||
* [jsonl/Parser](https://github.com/uhop/stream-json/wiki/jsonl-Parser) parses a JSONL file producing objects similar to `StreamValues`.
|
||||
* Useful when we know that individual items can fit in memory.
|
||||
* Generally it is faster than the equivalent combination of `Parser({jsonStreaming: true})` + `StreamValues`.
|
||||
* [jsonl/Stringer](https://github.com/uhop/stream-json/wiki/jsonl-Stringer) produces a JSONL file from a stream of JavaScript objects.
|
||||
* Generally it is faster than the equivalent combination of `Disassembler` + `Stringer`.
|
||||
|
||||
All components are meant to be building blocks to create flexible custom data processing pipelines. They can be extended and/or combined with custom code. They can be used together with [stream-chain](https://www.npmjs.com/package/stream-chain) to simplify data processing.
|
||||
|
||||
This toolkit is distributed under New BSD license.
|
||||
|
||||
## Introduction
|
||||
|
||||
```js
|
||||
const {chain} = require('stream-chain');
|
||||
|
||||
const {parser} = require('stream-json');
|
||||
const {pick} = require('stream-json/filters/Pick');
|
||||
const {ignore} = require('stream-json/filters/Ignore');
|
||||
const {streamValues} = require('stream-json/streamers/StreamValues');
|
||||
|
||||
const fs = require('fs');
|
||||
const zlib = require('zlib');
|
||||
|
||||
const pipeline = chain([
|
||||
fs.createReadStream('sample.json.gz'),
|
||||
zlib.createGunzip(),
|
||||
parser(),
|
||||
pick({filter: 'data'}),
|
||||
ignore({filter: /\b_meta\b/i}),
|
||||
streamValues(),
|
||||
data => {
|
||||
const value = data.value;
|
||||
// keep data only for the accounting department
|
||||
return value && value.department === 'accounting' ? data : null;
|
||||
}
|
||||
]);
|
||||
|
||||
let counter = 0;
|
||||
pipeline.on('data', () => ++counter);
|
||||
pipeline.on('end', () =>
|
||||
console.log(`The accounting department has ${counter} employees.`));
|
||||
```
|
||||
|
||||
See the full documentation in [Wiki](https://github.com/uhop/stream-json/wiki).
|
||||
|
||||
Companion projects:
|
||||
|
||||
* [stream-csv-as-json](https://www.npmjs.com/package/stream-csv-as-json) streams huge CSV files in a format compatible with `stream-json`:
|
||||
rows as arrays of string values. If a header row is used, it can stream rows as objects with named fields.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
npm install --save stream-json
|
||||
# or: yarn add stream-json
|
||||
```
|
||||
|
||||
## Use
|
||||
|
||||
The whole library is organized as a set of small components, which can be combined to produce the most effective pipeline. All components are based on node.js
|
||||
[streams](http://nodejs.org/api/stream.html), and [events](http://nodejs.org/api/events.html). They implement all required standard APIs. It is easy to add your
|
||||
own components to solve your unique tasks.
|
||||
|
||||
The code of all components is compact and simple. Please take a look at their source code to see how things are implemented, so you can produce your own components
|
||||
in no time.
|
||||
|
||||
Obviously, if a bug is found, or a way to simplify existing components, or new generic components are created, which can be reused in a variety of projects,
|
||||
don't hesitate to open a ticket, and/or create a pull request.
|
||||
|
||||
## Release History
|
||||
|
||||
* 1.9.1 *fixed a race condition in disassembler implementation. Thx, [Noam Okman](https://github.com/noamokman).*
|
||||
* 1.9.0 *fixed a slight deviation from the JSON standard. Thx [Peter Burns](https://github.com/rictic).*
|
||||
* 1.8.0 *added an option to indicate/ignore JSONL errors. Thx, [AK](https://github.com/ak--47).*
|
||||
* 1.7.5 *fixed a stringer bug with ASCII control symbols. Thx, [Kraicheck](https://github.com/Kraicheck).*
|
||||
* 1.7.4 *updated dependency (`stream-chain`), bugfix: inconsistent object/array braces. Thx [Xiao Li](https://github.com/xli1000).*
|
||||
* 1.7.3 *added an assembler option to treat numbers as strings.*
|
||||
* 1.7.2 *added an error check for JSONL parsing. Thx [Marc-Andre Boily](https://github.com/maboily).*
|
||||
* 1.7.1 *minor bugfix and improved error reporting.*
|
||||
* 1.7.0 *added `utils/Utf8Stream` to sanitize `utf8` input, all parsers support it automatically. Thx [john30](https://github.com/john30) for the suggestion.*
|
||||
* 1.6.1 *the technical release, no need to upgrade.*
|
||||
* 1.6.0 *added `jsonl/Parser` and `jsonl/Stringer`.*
|
||||
|
||||
The rest can be consulted in the project's wiki [Release history](https://github.com/uhop/stream-json/wiki/Release-history).
|
||||
@@ -0,0 +1,187 @@
|
||||
/**
|
||||
* @fileoverview Rule to check for implicit global variables, functions and classes.
|
||||
* @author Joshua Peek
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const ASSIGNMENT_NODES = new Set([
|
||||
"AssignmentExpression",
|
||||
"ForInStatement",
|
||||
"ForOfStatement",
|
||||
]);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../types').Rule.RuleModule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "suggestion",
|
||||
|
||||
defaultOptions: [
|
||||
{
|
||||
lexicalBindings: false,
|
||||
},
|
||||
],
|
||||
|
||||
docs: {
|
||||
description: "Disallow declarations in the global scope",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/no-implicit-globals",
|
||||
},
|
||||
|
||||
schema: [
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
lexicalBindings: {
|
||||
type: "boolean",
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
|
||||
messages: {
|
||||
globalNonLexicalBinding:
|
||||
"Unexpected {{kind}} declaration in the global scope, wrap in an IIFE for a local variable, assign as global property for a global variable.",
|
||||
globalLexicalBinding:
|
||||
"Unexpected {{kind}} declaration in the global scope, wrap in a block or in an IIFE.",
|
||||
globalVariableLeak:
|
||||
"Global variable leak, declare the variable if it is intended to be local.",
|
||||
assignmentToReadonlyGlobal:
|
||||
"Unexpected assignment to read-only global variable.",
|
||||
redeclarationOfReadonlyGlobal:
|
||||
"Unexpected redeclaration of read-only global variable.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const [{ lexicalBindings: checkLexicalBindings }] = context.options;
|
||||
const sourceCode = context.sourceCode;
|
||||
|
||||
/**
|
||||
* Reports the node.
|
||||
* @param {ASTNode} node Node to report.
|
||||
* @param {string} messageId Id of the message to report.
|
||||
* @param {string|undefined} kind Declaration kind, can be 'var', 'const', 'let', function or class.
|
||||
* @returns {void}
|
||||
*/
|
||||
function report(node, messageId, kind) {
|
||||
context.report({
|
||||
node,
|
||||
messageId,
|
||||
data: {
|
||||
kind,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
Program(node) {
|
||||
const scope = sourceCode.getScope(node);
|
||||
|
||||
scope.variables.forEach(variable => {
|
||||
// Only ESLint global variables have the `writable` key.
|
||||
const isReadonlyEslintGlobalVariable =
|
||||
variable.writeable === false;
|
||||
const isWritableEslintGlobalVariable =
|
||||
variable.writeable === true;
|
||||
|
||||
if (isWritableEslintGlobalVariable) {
|
||||
// Everything is allowed with writable ESLint global variables.
|
||||
return;
|
||||
}
|
||||
|
||||
// Variables exported by "exported" block comments
|
||||
if (variable.eslintExported) {
|
||||
return;
|
||||
}
|
||||
|
||||
variable.defs.forEach(def => {
|
||||
const defNode = def.node;
|
||||
|
||||
if (
|
||||
def.type === "FunctionName" ||
|
||||
(def.type === "Variable" &&
|
||||
def.parent.kind === "var")
|
||||
) {
|
||||
if (isReadonlyEslintGlobalVariable) {
|
||||
report(
|
||||
defNode,
|
||||
"redeclarationOfReadonlyGlobal",
|
||||
);
|
||||
} else {
|
||||
report(
|
||||
defNode,
|
||||
"globalNonLexicalBinding",
|
||||
def.type === "FunctionName"
|
||||
? "function"
|
||||
: `'${def.parent.kind}'`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (checkLexicalBindings) {
|
||||
if (
|
||||
def.type === "ClassName" ||
|
||||
(def.type === "Variable" &&
|
||||
(def.parent.kind === "let" ||
|
||||
def.parent.kind === "const"))
|
||||
) {
|
||||
if (isReadonlyEslintGlobalVariable) {
|
||||
report(
|
||||
defNode,
|
||||
"redeclarationOfReadonlyGlobal",
|
||||
);
|
||||
} else {
|
||||
report(
|
||||
defNode,
|
||||
"globalLexicalBinding",
|
||||
def.type === "ClassName"
|
||||
? "class"
|
||||
: `'${def.parent.kind}'`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (
|
||||
isReadonlyEslintGlobalVariable &&
|
||||
variable.defs.length === 0
|
||||
) {
|
||||
variable.references.forEach(reference => {
|
||||
if (reference.isWrite() && !reference.isRead()) {
|
||||
let assignmentParent =
|
||||
reference.identifier.parent;
|
||||
|
||||
while (
|
||||
assignmentParent &&
|
||||
!ASSIGNMENT_NODES.has(assignmentParent.type)
|
||||
) {
|
||||
assignmentParent = assignmentParent.parent;
|
||||
}
|
||||
|
||||
report(
|
||||
assignmentParent ?? reference.identifier,
|
||||
"assignmentToReadonlyGlobal",
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Undeclared assigned variables.
|
||||
scope.implicit.variables.forEach(variable => {
|
||||
// def.node is an AssignmentExpression, ForInStatement or ForOfStatement.
|
||||
variable.defs.forEach(def => {
|
||||
report(def.node, "globalVariableLeak");
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,251 @@
|
||||
/**
|
||||
* Blake3 fast hash is Blake2 with reduced security (round count). Can also be used as MAC & KDF.
|
||||
*
|
||||
* It is advertised as "the fastest cryptographic hash". However, it isn't true in JS.
|
||||
* Why is this so slow? While it should be 6x faster than blake2b, perf diff is only 20%:
|
||||
*
|
||||
* * There is only 30% reduction in number of rounds from blake2s
|
||||
* * Speed-up comes from tree structure, which is parallelized using SIMD & threading.
|
||||
* These features are not present in JS, so we only get overhead from trees.
|
||||
* * Parallelization only happens on 1024-byte chunks: there is no benefit for small inputs.
|
||||
* * It is still possible to make it faster using: a) loop unrolling b) web workers c) wasm
|
||||
* @module
|
||||
*/
|
||||
import { SHA256_IV } from "./_md.js";
|
||||
import { fromBig } from "./_u64.js";
|
||||
import { BLAKE2, compress } from "./blake2.js";
|
||||
// prettier-ignore
|
||||
import { abytes, aexists, anumber, aoutput, clean, createXOFer, swap32IfBE, toBytes, u32, u8 } from "./utils.js";
|
||||
// Flag bitset
|
||||
const B3_Flags = {
|
||||
CHUNK_START: 0b1,
|
||||
CHUNK_END: 0b10,
|
||||
PARENT: 0b100,
|
||||
ROOT: 0b1000,
|
||||
KEYED_HASH: 0b10000,
|
||||
DERIVE_KEY_CONTEXT: 0b100000,
|
||||
DERIVE_KEY_MATERIAL: 0b1000000,
|
||||
};
|
||||
const B3_IV = SHA256_IV.slice();
|
||||
const B3_SIGMA = /* @__PURE__ */ (() => {
|
||||
const Id = Array.from({ length: 16 }, (_, i) => i);
|
||||
const permute = (arr) => [2, 6, 3, 10, 7, 0, 4, 13, 1, 11, 12, 5, 9, 14, 15, 8].map((i) => arr[i]);
|
||||
const res = [];
|
||||
for (let i = 0, v = Id; i < 7; i++, v = permute(v))
|
||||
res.push(...v);
|
||||
return Uint8Array.from(res);
|
||||
})();
|
||||
/** Blake3 hash. Can be used as MAC and KDF. */
|
||||
export class BLAKE3 extends BLAKE2 {
|
||||
constructor(opts = {}, flags = 0) {
|
||||
super(64, opts.dkLen === undefined ? 32 : opts.dkLen);
|
||||
this.chunkPos = 0; // Position of current block in chunk
|
||||
this.chunksDone = 0; // How many chunks we already have
|
||||
this.flags = 0 | 0;
|
||||
this.stack = [];
|
||||
// Output
|
||||
this.posOut = 0;
|
||||
this.bufferOut32 = new Uint32Array(16);
|
||||
this.chunkOut = 0; // index of output chunk
|
||||
this.enableXOF = true;
|
||||
const { key, context } = opts;
|
||||
const hasContext = context !== undefined;
|
||||
if (key !== undefined) {
|
||||
if (hasContext)
|
||||
throw new Error('Only "key" or "context" can be specified at same time');
|
||||
const k = toBytes(key).slice();
|
||||
abytes(k, 32);
|
||||
this.IV = u32(k);
|
||||
swap32IfBE(this.IV);
|
||||
this.flags = flags | B3_Flags.KEYED_HASH;
|
||||
}
|
||||
else if (hasContext) {
|
||||
const ctx = toBytes(context);
|
||||
const contextKey = new BLAKE3({ dkLen: 32 }, B3_Flags.DERIVE_KEY_CONTEXT)
|
||||
.update(ctx)
|
||||
.digest();
|
||||
this.IV = u32(contextKey);
|
||||
swap32IfBE(this.IV);
|
||||
this.flags = flags | B3_Flags.DERIVE_KEY_MATERIAL;
|
||||
}
|
||||
else {
|
||||
this.IV = B3_IV.slice();
|
||||
this.flags = flags;
|
||||
}
|
||||
this.state = this.IV.slice();
|
||||
this.bufferOut = u8(this.bufferOut32);
|
||||
}
|
||||
// Unused
|
||||
get() {
|
||||
return [];
|
||||
}
|
||||
set() { }
|
||||
b2Compress(counter, flags, buf, bufPos = 0) {
|
||||
const { state: s, pos } = this;
|
||||
const { h, l } = fromBig(BigInt(counter), true);
|
||||
// prettier-ignore
|
||||
const { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 } = compress(B3_SIGMA, bufPos, buf, 7, s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], B3_IV[0], B3_IV[1], B3_IV[2], B3_IV[3], h, l, pos, flags);
|
||||
s[0] = v0 ^ v8;
|
||||
s[1] = v1 ^ v9;
|
||||
s[2] = v2 ^ v10;
|
||||
s[3] = v3 ^ v11;
|
||||
s[4] = v4 ^ v12;
|
||||
s[5] = v5 ^ v13;
|
||||
s[6] = v6 ^ v14;
|
||||
s[7] = v7 ^ v15;
|
||||
}
|
||||
compress(buf, bufPos = 0, isLast = false) {
|
||||
// Compress last block
|
||||
let flags = this.flags;
|
||||
if (!this.chunkPos)
|
||||
flags |= B3_Flags.CHUNK_START;
|
||||
if (this.chunkPos === 15 || isLast)
|
||||
flags |= B3_Flags.CHUNK_END;
|
||||
if (!isLast)
|
||||
this.pos = this.blockLen;
|
||||
this.b2Compress(this.chunksDone, flags, buf, bufPos);
|
||||
this.chunkPos += 1;
|
||||
// If current block is last in chunk (16 blocks), then compress chunks
|
||||
if (this.chunkPos === 16 || isLast) {
|
||||
let chunk = this.state;
|
||||
this.state = this.IV.slice();
|
||||
// If not the last one, compress only when there are trailing zeros in chunk counter
|
||||
// chunks used as binary tree where current stack is path. Zero means current leaf is finished and can be compressed.
|
||||
// 1 (001) - leaf not finished (just push current chunk to stack)
|
||||
// 2 (010) - leaf finished at depth=1 (merge with last elm on stack and push back)
|
||||
// 3 (011) - last leaf not finished
|
||||
// 4 (100) - leafs finished at depth=1 and depth=2
|
||||
for (let last, chunks = this.chunksDone + 1; isLast || !(chunks & 1); chunks >>= 1) {
|
||||
if (!(last = this.stack.pop()))
|
||||
break;
|
||||
this.buffer32.set(last, 0);
|
||||
this.buffer32.set(chunk, 8);
|
||||
this.pos = this.blockLen;
|
||||
this.b2Compress(0, this.flags | B3_Flags.PARENT, this.buffer32, 0);
|
||||
chunk = this.state;
|
||||
this.state = this.IV.slice();
|
||||
}
|
||||
this.chunksDone++;
|
||||
this.chunkPos = 0;
|
||||
this.stack.push(chunk);
|
||||
}
|
||||
this.pos = 0;
|
||||
}
|
||||
_cloneInto(to) {
|
||||
to = super._cloneInto(to);
|
||||
const { IV, flags, state, chunkPos, posOut, chunkOut, stack, chunksDone } = this;
|
||||
to.state.set(state.slice());
|
||||
to.stack = stack.map((i) => Uint32Array.from(i));
|
||||
to.IV.set(IV);
|
||||
to.flags = flags;
|
||||
to.chunkPos = chunkPos;
|
||||
to.chunksDone = chunksDone;
|
||||
to.posOut = posOut;
|
||||
to.chunkOut = chunkOut;
|
||||
to.enableXOF = this.enableXOF;
|
||||
to.bufferOut32.set(this.bufferOut32);
|
||||
return to;
|
||||
}
|
||||
destroy() {
|
||||
this.destroyed = true;
|
||||
clean(this.state, this.buffer32, this.IV, this.bufferOut32);
|
||||
clean(...this.stack);
|
||||
}
|
||||
// Same as b2Compress, but doesn't modify state and returns 16 u32 array (instead of 8)
|
||||
b2CompressOut() {
|
||||
const { state: s, pos, flags, buffer32, bufferOut32: out32 } = this;
|
||||
const { h, l } = fromBig(BigInt(this.chunkOut++));
|
||||
swap32IfBE(buffer32);
|
||||
// prettier-ignore
|
||||
const { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 } = compress(B3_SIGMA, 0, buffer32, 7, s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], B3_IV[0], B3_IV[1], B3_IV[2], B3_IV[3], l, h, pos, flags);
|
||||
out32[0] = v0 ^ v8;
|
||||
out32[1] = v1 ^ v9;
|
||||
out32[2] = v2 ^ v10;
|
||||
out32[3] = v3 ^ v11;
|
||||
out32[4] = v4 ^ v12;
|
||||
out32[5] = v5 ^ v13;
|
||||
out32[6] = v6 ^ v14;
|
||||
out32[7] = v7 ^ v15;
|
||||
out32[8] = s[0] ^ v8;
|
||||
out32[9] = s[1] ^ v9;
|
||||
out32[10] = s[2] ^ v10;
|
||||
out32[11] = s[3] ^ v11;
|
||||
out32[12] = s[4] ^ v12;
|
||||
out32[13] = s[5] ^ v13;
|
||||
out32[14] = s[6] ^ v14;
|
||||
out32[15] = s[7] ^ v15;
|
||||
swap32IfBE(buffer32);
|
||||
swap32IfBE(out32);
|
||||
this.posOut = 0;
|
||||
}
|
||||
finish() {
|
||||
if (this.finished)
|
||||
return;
|
||||
this.finished = true;
|
||||
// Padding
|
||||
clean(this.buffer.subarray(this.pos));
|
||||
// Process last chunk
|
||||
let flags = this.flags | B3_Flags.ROOT;
|
||||
if (this.stack.length) {
|
||||
flags |= B3_Flags.PARENT;
|
||||
swap32IfBE(this.buffer32);
|
||||
this.compress(this.buffer32, 0, true);
|
||||
swap32IfBE(this.buffer32);
|
||||
this.chunksDone = 0;
|
||||
this.pos = this.blockLen;
|
||||
}
|
||||
else {
|
||||
flags |= (!this.chunkPos ? B3_Flags.CHUNK_START : 0) | B3_Flags.CHUNK_END;
|
||||
}
|
||||
this.flags = flags;
|
||||
this.b2CompressOut();
|
||||
}
|
||||
writeInto(out) {
|
||||
aexists(this, false);
|
||||
abytes(out);
|
||||
this.finish();
|
||||
const { blockLen, bufferOut } = this;
|
||||
for (let pos = 0, len = out.length; pos < len;) {
|
||||
if (this.posOut >= blockLen)
|
||||
this.b2CompressOut();
|
||||
const take = Math.min(blockLen - this.posOut, len - pos);
|
||||
out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
|
||||
this.posOut += take;
|
||||
pos += take;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
xofInto(out) {
|
||||
if (!this.enableXOF)
|
||||
throw new Error('XOF is not possible after digest call');
|
||||
return this.writeInto(out);
|
||||
}
|
||||
xof(bytes) {
|
||||
anumber(bytes);
|
||||
return this.xofInto(new Uint8Array(bytes));
|
||||
}
|
||||
digestInto(out) {
|
||||
aoutput(out, this);
|
||||
if (this.finished)
|
||||
throw new Error('digest() was already called');
|
||||
this.enableXOF = false;
|
||||
this.writeInto(out);
|
||||
this.destroy();
|
||||
return out;
|
||||
}
|
||||
digest() {
|
||||
return this.digestInto(new Uint8Array(this.outputLen));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* BLAKE3 hash function. Can be used as MAC and KDF.
|
||||
* @param msg - message that would be hashed
|
||||
* @param opts - `dkLen` for output length, `key` for MAC mode, `context` for KDF mode
|
||||
* @example
|
||||
* const data = new Uint8Array(32);
|
||||
* const hash = blake3(data);
|
||||
* const mac = blake3(data, { key: new Uint8Array(32) });
|
||||
* const kdf = blake3(data, { context: 'application name' });
|
||||
*/
|
||||
export const blake3 = /* @__PURE__ */ createXOFer((opts) => new BLAKE3(opts));
|
||||
//# sourceMappingURL=blake3.js.map
|
||||
@@ -0,0 +1,54 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const utils_1 = require("@typescript-eslint/utils");
|
||||
const util_1 = require("../util");
|
||||
exports.default = (0, util_1.createRule)({
|
||||
name: 'no-unsafe-declaration-merging',
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'Disallow unsafe declaration merging',
|
||||
recommended: 'recommended',
|
||||
requiresTypeChecking: false,
|
||||
},
|
||||
messages: {
|
||||
unsafeMerging: 'Unsafe declaration merging between classes and interfaces.',
|
||||
},
|
||||
schema: [],
|
||||
},
|
||||
defaultOptions: [],
|
||||
create(context) {
|
||||
function checkUnsafeDeclaration(scope, node, unsafeKind) {
|
||||
const variable = scope.set.get(node.name);
|
||||
if (!variable) {
|
||||
return;
|
||||
}
|
||||
const defs = variable.defs;
|
||||
if (defs.length <= 1) {
|
||||
return;
|
||||
}
|
||||
if (defs.some(def => def.node.type === unsafeKind)) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'unsafeMerging',
|
||||
});
|
||||
}
|
||||
}
|
||||
return {
|
||||
ClassDeclaration(node) {
|
||||
if (node.id) {
|
||||
// by default eslint returns the inner class scope for the ClassDeclaration node
|
||||
// but we want the outer scope within which merged variables will sit
|
||||
const currentScope = context.sourceCode.getScope(node).upper;
|
||||
if (currentScope == null) {
|
||||
return;
|
||||
}
|
||||
checkUnsafeDeclaration(currentScope, node.id, utils_1.AST_NODE_TYPES.TSInterfaceDeclaration);
|
||||
}
|
||||
},
|
||||
TSInterfaceDeclaration(node) {
|
||||
checkUnsafeDeclaration(context.sourceCode.getScope(node), node.id, utils_1.AST_NODE_TYPES.ClassDeclaration);
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"u128.d.ts","sourceRoot":"","sources":["../../src/u128.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,cAAc,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvG,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAG7C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,cAAc,GAAI,SAAQ,iBAAsB,KAAG,gBAAgB,CAAC,MAAM,GAAG,MAAM,EAAE,EAAE,CAa9F,CAAC;AAEP;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,cAAc,GAAI,SAAQ,iBAAsB,KAAG,gBAAgB,CAAC,MAAM,EAAE,EAAE,CAYrF,CAAC;AAEP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,eAAO,MAAM,YAAY,GAAI,SAAQ,iBAAsB,KAAG,cAAc,CAAC,MAAM,GAAG,MAAM,EAAE,MAAM,EAAE,EAAE,CACxC,CAAC"}
|
||||
@@ -0,0 +1,117 @@
|
||||
/*! *****************************************************************************
|
||||
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"/>
|
||||
|
||||
declare namespace Intl {
|
||||
/**
|
||||
* An object with some or all properties of the `Intl.Segmenter` constructor `options` parameter.
|
||||
*
|
||||
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter#parameters)
|
||||
*/
|
||||
interface SegmenterOptions {
|
||||
/** The locale matching algorithm to use. For information about this option, see [Intl page](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation). */
|
||||
localeMatcher?: "best fit" | "lookup" | undefined;
|
||||
/** The type of input to be split */
|
||||
granularity?: "grapheme" | "word" | "sentence" | undefined;
|
||||
}
|
||||
|
||||
interface Segmenter {
|
||||
/**
|
||||
* Returns `Segments` object containing the segments of the input string, using the segmenter's locale and granularity.
|
||||
*
|
||||
* @param input - The text to be segmented as a `string`.
|
||||
*
|
||||
* @returns A new iterable Segments object containing the segments of the input string, using the segmenter's locale and granularity.
|
||||
*/
|
||||
segment(input: string): Segments;
|
||||
resolvedOptions(): ResolvedSegmenterOptions;
|
||||
}
|
||||
|
||||
interface ResolvedSegmenterOptions {
|
||||
locale: string;
|
||||
granularity: "grapheme" | "word" | "sentence";
|
||||
}
|
||||
|
||||
interface Segments {
|
||||
/**
|
||||
* Returns an object describing the segment in the original string that includes the code unit at a specified index.
|
||||
*
|
||||
* @param codeUnitIndex - A number specifying the index of the code unit in the original input string. If the value is omitted, it defaults to `0`.
|
||||
*/
|
||||
containing(codeUnitIndex?: number): SegmentData;
|
||||
|
||||
/** Returns an iterator to iterate over the segments. */
|
||||
[Symbol.iterator](): IterableIterator<SegmentData>;
|
||||
}
|
||||
|
||||
interface SegmentData {
|
||||
/** A string containing the segment extracted from the original input string. */
|
||||
segment: string;
|
||||
/** The code unit index in the original input string at which the segment begins. */
|
||||
index: number;
|
||||
/** The complete input string that was segmented. */
|
||||
input: string;
|
||||
/**
|
||||
* A boolean value only if granularity is "word"; otherwise, undefined.
|
||||
* If granularity is "word", then isWordLike is true when the segment is word-like (i.e., consists of letters/numbers/ideographs/etc.); otherwise, false.
|
||||
*/
|
||||
isWordLike?: boolean;
|
||||
}
|
||||
|
||||
const Segmenter: {
|
||||
prototype: Segmenter;
|
||||
|
||||
/**
|
||||
* Creates a new `Intl.Segmenter` object.
|
||||
*
|
||||
* @param locales - A string with a [BCP 47 language tag](http://tools.ietf.org/html/rfc5646), or an array of such strings.
|
||||
* For the general form and interpretation of the `locales` argument,
|
||||
* see the [`Intl` page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).
|
||||
*
|
||||
* @param options - An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter#parameters)
|
||||
* with some or all options of `SegmenterOptions`.
|
||||
*
|
||||
* @returns [Intl.Segmenter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segments) object.
|
||||
*
|
||||
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter).
|
||||
*/
|
||||
new (locales?: LocalesArgument, options?: SegmenterOptions): Segmenter;
|
||||
|
||||
/**
|
||||
* Returns an array containing those of the provided locales that are supported without having to fall back to the runtime's default locale.
|
||||
*
|
||||
* @param locales - A string with a [BCP 47 language tag](http://tools.ietf.org/html/rfc5646), or an array of such strings.
|
||||
* For the general form and interpretation of the `locales` argument,
|
||||
* see the [`Intl` page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).
|
||||
*
|
||||
* @param options An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf#parameters).
|
||||
* with some or all possible options.
|
||||
*
|
||||
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf)
|
||||
*/
|
||||
supportedLocalesOf(locales: LocalesArgument, options?: Pick<SegmenterOptions, "localeMatcher">): UnicodeBCP47LocaleIdentifier[];
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a sorted array of the supported collation, calendar, currency, numbering system, timezones, and units by the implementation.
|
||||
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/supportedValuesOf)
|
||||
*
|
||||
* @param key A string indicating the category of values to return.
|
||||
* @returns A sorted array of the supported values.
|
||||
*/
|
||||
function supportedValuesOf(key: "calendar" | "collation" | "currency" | "numberingSystem" | "timeZone" | "unit"): string[];
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
'use strict'
|
||||
|
||||
const fs = require('fs')
|
||||
const { PassThrough, Writable, pipeline } = require('stream')
|
||||
const process = require('process')
|
||||
const { join } = require('path')
|
||||
|
||||
const defaults = {
|
||||
ext: '.txt',
|
||||
help: 'help'
|
||||
}
|
||||
|
||||
function isDirectory (path) {
|
||||
try {
|
||||
const stat = fs.lstatSync(path)
|
||||
return stat.isDirectory()
|
||||
} catch (err) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
function createDefaultStream () {
|
||||
return new Writable({
|
||||
write (chunk, encoding, callback) {
|
||||
process.stdout.write(chunk, callback)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function helpMe (opts) {
|
||||
opts = Object.assign({}, defaults, opts)
|
||||
|
||||
if (!opts.dir) {
|
||||
throw new Error('missing dir')
|
||||
}
|
||||
|
||||
if (!isDirectory(opts.dir)) {
|
||||
throw new Error(`${opts.dir} is not a directory`)
|
||||
}
|
||||
|
||||
return {
|
||||
createStream: createStream,
|
||||
toStdout: toStdout
|
||||
}
|
||||
|
||||
function createStream (args) {
|
||||
if (typeof args === 'string') {
|
||||
args = args.split(' ')
|
||||
} else if (!args || args.length === 0) {
|
||||
args = [opts.help]
|
||||
}
|
||||
|
||||
const out = new PassThrough()
|
||||
const re = new RegExp(
|
||||
args
|
||||
.map(function (arg) {
|
||||
return arg + '[a-zA-Z0-9]*'
|
||||
})
|
||||
.join('[ /]+')
|
||||
)
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
opts.dir = opts.dir.split('\\').join('/')
|
||||
}
|
||||
|
||||
fs.readdir(opts.dir, function (err, files) {
|
||||
if (err) return out.emit('error', err)
|
||||
|
||||
const regexp = new RegExp('.*' + opts.ext + '$')
|
||||
files = files
|
||||
.filter(function (file) {
|
||||
const matched = file.match(regexp)
|
||||
return !!matched
|
||||
})
|
||||
.map(function (relative) {
|
||||
return { file: join(opts.dir, relative), relative }
|
||||
})
|
||||
.filter(function (file) {
|
||||
return file.relative.match(re)
|
||||
})
|
||||
|
||||
if (files.length === 0) {
|
||||
return out.emit('error', new Error('no such help file'))
|
||||
} else if (files.length > 1) {
|
||||
const exactMatch = files.find(
|
||||
(file) => file.relative === `${args[0]}${opts.ext}`
|
||||
)
|
||||
if (!exactMatch) {
|
||||
out.write('There are ' + files.length + ' help pages ')
|
||||
out.write('that matches the given request, please disambiguate:\n')
|
||||
files.forEach(function (file) {
|
||||
out.write(' * ')
|
||||
out.write(file.relative.replace(opts.ext, ''))
|
||||
out.write('\n')
|
||||
})
|
||||
out.end()
|
||||
return
|
||||
}
|
||||
files = [exactMatch]
|
||||
}
|
||||
|
||||
pipeline(fs.createReadStream(files[0].file), out, () => {})
|
||||
})
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
function toStdout (args = [], opts) {
|
||||
opts = opts || {}
|
||||
const stream = opts.stream || createDefaultStream()
|
||||
const _onMissingHelp = opts.onMissingHelp || onMissingHelp
|
||||
return new Promise((resolve, reject) => {
|
||||
createStream(args)
|
||||
.on('error', (err) => {
|
||||
_onMissingHelp(err, args, stream).then(resolve, reject)
|
||||
})
|
||||
.pipe(stream)
|
||||
.on('close', resolve)
|
||||
.on('end', resolve)
|
||||
})
|
||||
}
|
||||
|
||||
function onMissingHelp (_, args, stream) {
|
||||
stream.write(`no such help file: ${args.join(' ')}.\n\n`)
|
||||
return toStdout([], { stream, async onMissingHelp () {} })
|
||||
}
|
||||
}
|
||||
|
||||
function help (opts, args) {
|
||||
return helpMe(opts).toStdout(args, opts)
|
||||
}
|
||||
|
||||
module.exports = helpMe
|
||||
module.exports.help = help
|
||||
@@ -0,0 +1,413 @@
|
||||
/* -*- Mode: js; js-indent-level: 2; -*- */
|
||||
/*
|
||||
* Copyright 2011 Mozilla Foundation and contributors
|
||||
* Licensed under the New BSD license. See LICENSE or:
|
||||
* http://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
|
||||
var SourceMapGenerator = require('./source-map-generator').SourceMapGenerator;
|
||||
var util = require('./util');
|
||||
|
||||
// Matches a Windows-style `\r\n` newline or a `\n` newline used by all other
|
||||
// operating systems these days (capturing the result).
|
||||
var REGEX_NEWLINE = /(\r?\n)/;
|
||||
|
||||
// Newline character code for charCodeAt() comparisons
|
||||
var NEWLINE_CODE = 10;
|
||||
|
||||
// Private symbol for identifying `SourceNode`s when multiple versions of
|
||||
// the source-map library are loaded. This MUST NOT CHANGE across
|
||||
// versions!
|
||||
var isSourceNode = "$$$isSourceNode$$$";
|
||||
|
||||
/**
|
||||
* SourceNodes provide a way to abstract over interpolating/concatenating
|
||||
* snippets of generated JavaScript source code while maintaining the line and
|
||||
* column information associated with the original source code.
|
||||
*
|
||||
* @param aLine The original line number.
|
||||
* @param aColumn The original column number.
|
||||
* @param aSource The original source's filename.
|
||||
* @param aChunks Optional. An array of strings which are snippets of
|
||||
* generated JS, or other SourceNodes.
|
||||
* @param aName The original identifier.
|
||||
*/
|
||||
function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
|
||||
this.children = [];
|
||||
this.sourceContents = {};
|
||||
this.line = aLine == null ? null : aLine;
|
||||
this.column = aColumn == null ? null : aColumn;
|
||||
this.source = aSource == null ? null : aSource;
|
||||
this.name = aName == null ? null : aName;
|
||||
this[isSourceNode] = true;
|
||||
if (aChunks != null) this.add(aChunks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a SourceNode from generated code and a SourceMapConsumer.
|
||||
*
|
||||
* @param aGeneratedCode The generated code
|
||||
* @param aSourceMapConsumer The SourceMap for the generated code
|
||||
* @param aRelativePath Optional. The path that relative sources in the
|
||||
* SourceMapConsumer should be relative to.
|
||||
*/
|
||||
SourceNode.fromStringWithSourceMap =
|
||||
function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) {
|
||||
// The SourceNode we want to fill with the generated code
|
||||
// and the SourceMap
|
||||
var node = new SourceNode();
|
||||
|
||||
// All even indices of this array are one line of the generated code,
|
||||
// while all odd indices are the newlines between two adjacent lines
|
||||
// (since `REGEX_NEWLINE` captures its match).
|
||||
// Processed fragments are accessed by calling `shiftNextLine`.
|
||||
var remainingLines = aGeneratedCode.split(REGEX_NEWLINE);
|
||||
var remainingLinesIndex = 0;
|
||||
var shiftNextLine = function() {
|
||||
var lineContents = getNextLine();
|
||||
// The last line of a file might not have a newline.
|
||||
var newLine = getNextLine() || "";
|
||||
return lineContents + newLine;
|
||||
|
||||
function getNextLine() {
|
||||
return remainingLinesIndex < remainingLines.length ?
|
||||
remainingLines[remainingLinesIndex++] : undefined;
|
||||
}
|
||||
};
|
||||
|
||||
// We need to remember the position of "remainingLines"
|
||||
var lastGeneratedLine = 1, lastGeneratedColumn = 0;
|
||||
|
||||
// The generate SourceNodes we need a code range.
|
||||
// To extract it current and last mapping is used.
|
||||
// Here we store the last mapping.
|
||||
var lastMapping = null;
|
||||
|
||||
aSourceMapConsumer.eachMapping(function (mapping) {
|
||||
if (lastMapping !== null) {
|
||||
// We add the code from "lastMapping" to "mapping":
|
||||
// First check if there is a new line in between.
|
||||
if (lastGeneratedLine < mapping.generatedLine) {
|
||||
// Associate first line with "lastMapping"
|
||||
addMappingWithCode(lastMapping, shiftNextLine());
|
||||
lastGeneratedLine++;
|
||||
lastGeneratedColumn = 0;
|
||||
// The remaining code is added without mapping
|
||||
} else {
|
||||
// There is no new line in between.
|
||||
// Associate the code between "lastGeneratedColumn" and
|
||||
// "mapping.generatedColumn" with "lastMapping"
|
||||
var nextLine = remainingLines[remainingLinesIndex] || '';
|
||||
var code = nextLine.substr(0, mapping.generatedColumn -
|
||||
lastGeneratedColumn);
|
||||
remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn -
|
||||
lastGeneratedColumn);
|
||||
lastGeneratedColumn = mapping.generatedColumn;
|
||||
addMappingWithCode(lastMapping, code);
|
||||
// No more remaining code, continue
|
||||
lastMapping = mapping;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// We add the generated code until the first mapping
|
||||
// to the SourceNode without any mapping.
|
||||
// Each line is added as separate string.
|
||||
while (lastGeneratedLine < mapping.generatedLine) {
|
||||
node.add(shiftNextLine());
|
||||
lastGeneratedLine++;
|
||||
}
|
||||
if (lastGeneratedColumn < mapping.generatedColumn) {
|
||||
var nextLine = remainingLines[remainingLinesIndex] || '';
|
||||
node.add(nextLine.substr(0, mapping.generatedColumn));
|
||||
remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn);
|
||||
lastGeneratedColumn = mapping.generatedColumn;
|
||||
}
|
||||
lastMapping = mapping;
|
||||
}, this);
|
||||
// We have processed all mappings.
|
||||
if (remainingLinesIndex < remainingLines.length) {
|
||||
if (lastMapping) {
|
||||
// Associate the remaining code in the current line with "lastMapping"
|
||||
addMappingWithCode(lastMapping, shiftNextLine());
|
||||
}
|
||||
// and add the remaining lines without any mapping
|
||||
node.add(remainingLines.splice(remainingLinesIndex).join(""));
|
||||
}
|
||||
|
||||
// Copy sourcesContent into SourceNode
|
||||
aSourceMapConsumer.sources.forEach(function (sourceFile) {
|
||||
var content = aSourceMapConsumer.sourceContentFor(sourceFile);
|
||||
if (content != null) {
|
||||
if (aRelativePath != null) {
|
||||
sourceFile = util.join(aRelativePath, sourceFile);
|
||||
}
|
||||
node.setSourceContent(sourceFile, content);
|
||||
}
|
||||
});
|
||||
|
||||
return node;
|
||||
|
||||
function addMappingWithCode(mapping, code) {
|
||||
if (mapping === null || mapping.source === undefined) {
|
||||
node.add(code);
|
||||
} else {
|
||||
var source = aRelativePath
|
||||
? util.join(aRelativePath, mapping.source)
|
||||
: mapping.source;
|
||||
node.add(new SourceNode(mapping.originalLine,
|
||||
mapping.originalColumn,
|
||||
source,
|
||||
code,
|
||||
mapping.name));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a chunk of generated JS to this source node.
|
||||
*
|
||||
* @param aChunk A string snippet of generated JS code, another instance of
|
||||
* SourceNode, or an array where each member is one of those things.
|
||||
*/
|
||||
SourceNode.prototype.add = function SourceNode_add(aChunk) {
|
||||
if (Array.isArray(aChunk)) {
|
||||
aChunk.forEach(function (chunk) {
|
||||
this.add(chunk);
|
||||
}, this);
|
||||
}
|
||||
else if (aChunk[isSourceNode] || typeof aChunk === "string") {
|
||||
if (aChunk) {
|
||||
this.children.push(aChunk);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new TypeError(
|
||||
"Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
|
||||
);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a chunk of generated JS to the beginning of this source node.
|
||||
*
|
||||
* @param aChunk A string snippet of generated JS code, another instance of
|
||||
* SourceNode, or an array where each member is one of those things.
|
||||
*/
|
||||
SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
|
||||
if (Array.isArray(aChunk)) {
|
||||
for (var i = aChunk.length-1; i >= 0; i--) {
|
||||
this.prepend(aChunk[i]);
|
||||
}
|
||||
}
|
||||
else if (aChunk[isSourceNode] || typeof aChunk === "string") {
|
||||
this.children.unshift(aChunk);
|
||||
}
|
||||
else {
|
||||
throw new TypeError(
|
||||
"Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
|
||||
);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Walk over the tree of JS snippets in this node and its children. The
|
||||
* walking function is called once for each snippet of JS and is passed that
|
||||
* snippet and the its original associated source's line/column location.
|
||||
*
|
||||
* @param aFn The traversal function.
|
||||
*/
|
||||
SourceNode.prototype.walk = function SourceNode_walk(aFn) {
|
||||
var chunk;
|
||||
for (var i = 0, len = this.children.length; i < len; i++) {
|
||||
chunk = this.children[i];
|
||||
if (chunk[isSourceNode]) {
|
||||
chunk.walk(aFn);
|
||||
}
|
||||
else {
|
||||
if (chunk !== '') {
|
||||
aFn(chunk, { source: this.source,
|
||||
line: this.line,
|
||||
column: this.column,
|
||||
name: this.name });
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
|
||||
* each of `this.children`.
|
||||
*
|
||||
* @param aSep The separator.
|
||||
*/
|
||||
SourceNode.prototype.join = function SourceNode_join(aSep) {
|
||||
var newChildren;
|
||||
var i;
|
||||
var len = this.children.length;
|
||||
if (len > 0) {
|
||||
newChildren = [];
|
||||
for (i = 0; i < len-1; i++) {
|
||||
newChildren.push(this.children[i]);
|
||||
newChildren.push(aSep);
|
||||
}
|
||||
newChildren.push(this.children[i]);
|
||||
this.children = newChildren;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Call String.prototype.replace on the very right-most source snippet. Useful
|
||||
* for trimming whitespace from the end of a source node, etc.
|
||||
*
|
||||
* @param aPattern The pattern to replace.
|
||||
* @param aReplacement The thing to replace the pattern with.
|
||||
*/
|
||||
SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
|
||||
var lastChild = this.children[this.children.length - 1];
|
||||
if (lastChild[isSourceNode]) {
|
||||
lastChild.replaceRight(aPattern, aReplacement);
|
||||
}
|
||||
else if (typeof lastChild === 'string') {
|
||||
this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
|
||||
}
|
||||
else {
|
||||
this.children.push(''.replace(aPattern, aReplacement));
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the source content for a source file. This will be added to the SourceMapGenerator
|
||||
* in the sourcesContent field.
|
||||
*
|
||||
* @param aSourceFile The filename of the source file
|
||||
* @param aSourceContent The content of the source file
|
||||
*/
|
||||
SourceNode.prototype.setSourceContent =
|
||||
function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
|
||||
this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
|
||||
};
|
||||
|
||||
/**
|
||||
* Walk over the tree of SourceNodes. The walking function is called for each
|
||||
* source file content and is passed the filename and source content.
|
||||
*
|
||||
* @param aFn The traversal function.
|
||||
*/
|
||||
SourceNode.prototype.walkSourceContents =
|
||||
function SourceNode_walkSourceContents(aFn) {
|
||||
for (var i = 0, len = this.children.length; i < len; i++) {
|
||||
if (this.children[i][isSourceNode]) {
|
||||
this.children[i].walkSourceContents(aFn);
|
||||
}
|
||||
}
|
||||
|
||||
var sources = Object.keys(this.sourceContents);
|
||||
for (var i = 0, len = sources.length; i < len; i++) {
|
||||
aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the string representation of this source node. Walks over the tree
|
||||
* and concatenates all the various snippets together to one string.
|
||||
*/
|
||||
SourceNode.prototype.toString = function SourceNode_toString() {
|
||||
var str = "";
|
||||
this.walk(function (chunk) {
|
||||
str += chunk;
|
||||
});
|
||||
return str;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the string representation of this source node along with a source
|
||||
* map.
|
||||
*/
|
||||
SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
|
||||
var generated = {
|
||||
code: "",
|
||||
line: 1,
|
||||
column: 0
|
||||
};
|
||||
var map = new SourceMapGenerator(aArgs);
|
||||
var sourceMappingActive = false;
|
||||
var lastOriginalSource = null;
|
||||
var lastOriginalLine = null;
|
||||
var lastOriginalColumn = null;
|
||||
var lastOriginalName = null;
|
||||
this.walk(function (chunk, original) {
|
||||
generated.code += chunk;
|
||||
if (original.source !== null
|
||||
&& original.line !== null
|
||||
&& original.column !== null) {
|
||||
if(lastOriginalSource !== original.source
|
||||
|| lastOriginalLine !== original.line
|
||||
|| lastOriginalColumn !== original.column
|
||||
|| lastOriginalName !== original.name) {
|
||||
map.addMapping({
|
||||
source: original.source,
|
||||
original: {
|
||||
line: original.line,
|
||||
column: original.column
|
||||
},
|
||||
generated: {
|
||||
line: generated.line,
|
||||
column: generated.column
|
||||
},
|
||||
name: original.name
|
||||
});
|
||||
}
|
||||
lastOriginalSource = original.source;
|
||||
lastOriginalLine = original.line;
|
||||
lastOriginalColumn = original.column;
|
||||
lastOriginalName = original.name;
|
||||
sourceMappingActive = true;
|
||||
} else if (sourceMappingActive) {
|
||||
map.addMapping({
|
||||
generated: {
|
||||
line: generated.line,
|
||||
column: generated.column
|
||||
}
|
||||
});
|
||||
lastOriginalSource = null;
|
||||
sourceMappingActive = false;
|
||||
}
|
||||
for (var idx = 0, length = chunk.length; idx < length; idx++) {
|
||||
if (chunk.charCodeAt(idx) === NEWLINE_CODE) {
|
||||
generated.line++;
|
||||
generated.column = 0;
|
||||
// Mappings end at eol
|
||||
if (idx + 1 === length) {
|
||||
lastOriginalSource = null;
|
||||
sourceMappingActive = false;
|
||||
} else if (sourceMappingActive) {
|
||||
map.addMapping({
|
||||
source: original.source,
|
||||
original: {
|
||||
line: original.line,
|
||||
column: original.column
|
||||
},
|
||||
generated: {
|
||||
line: generated.line,
|
||||
column: generated.column
|
||||
},
|
||||
name: original.name
|
||||
});
|
||||
}
|
||||
} else {
|
||||
generated.column++;
|
||||
}
|
||||
}
|
||||
});
|
||||
this.walkSourceContents(function (sourceFile, sourceContent) {
|
||||
map.setSourceContent(sourceFile, sourceContent);
|
||||
});
|
||||
|
||||
return { code: generated.code, map: map };
|
||||
};
|
||||
|
||||
exports.SourceNode = SourceNode;
|
||||
@@ -0,0 +1,135 @@
|
||||
/*! *****************************************************************************
|
||||
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="es2015.symbol" />
|
||||
/// <reference lib="es2015.symbol.wellknown" />
|
||||
|
||||
interface SharedArrayBuffer {
|
||||
/**
|
||||
* Read-only. The length of the ArrayBuffer (in bytes).
|
||||
*/
|
||||
readonly byteLength: number;
|
||||
|
||||
/**
|
||||
* Returns a section of an SharedArrayBuffer.
|
||||
*/
|
||||
slice(begin: number, end?: number): SharedArrayBuffer;
|
||||
readonly [Symbol.species]: SharedArrayBuffer;
|
||||
readonly [Symbol.toStringTag]: "SharedArrayBuffer";
|
||||
}
|
||||
|
||||
interface SharedArrayBufferConstructor {
|
||||
readonly prototype: SharedArrayBuffer;
|
||||
new (byteLength: number): SharedArrayBuffer;
|
||||
}
|
||||
declare var SharedArrayBuffer: SharedArrayBufferConstructor;
|
||||
|
||||
interface ArrayBufferTypes {
|
||||
SharedArrayBuffer: SharedArrayBuffer;
|
||||
}
|
||||
|
||||
interface Atomics {
|
||||
/**
|
||||
* Adds a value to the value at the given position in the array, returning the original value.
|
||||
* Until this atomic operation completes, any other read or write operation against the array
|
||||
* will block.
|
||||
*/
|
||||
add(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;
|
||||
|
||||
/**
|
||||
* Stores the bitwise AND of a value with the value at the given position in the array,
|
||||
* returning the original value. Until this atomic operation completes, any other read or
|
||||
* write operation against the array will block.
|
||||
*/
|
||||
and(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;
|
||||
|
||||
/**
|
||||
* Replaces the value at the given position in the array if the original value equals the given
|
||||
* expected value, returning the original value. Until this atomic operation completes, any
|
||||
* other read or write operation against the array will block.
|
||||
*/
|
||||
compareExchange(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, expectedValue: number, replacementValue: number): number;
|
||||
|
||||
/**
|
||||
* Replaces the value at the given position in the array, returning the original value. Until
|
||||
* this atomic operation completes, any other read or write operation against the array will
|
||||
* block.
|
||||
*/
|
||||
exchange(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;
|
||||
|
||||
/**
|
||||
* Returns a value indicating whether high-performance algorithms can use atomic operations
|
||||
* (`true`) or must use locks (`false`) for the given number of bytes-per-element of a typed
|
||||
* array.
|
||||
*/
|
||||
isLockFree(size: number): boolean;
|
||||
|
||||
/**
|
||||
* Returns the value at the given position in the array. Until this atomic operation completes,
|
||||
* any other read or write operation against the array will block.
|
||||
*/
|
||||
load(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number): number;
|
||||
|
||||
/**
|
||||
* Stores the bitwise OR of a value with the value at the given position in the array,
|
||||
* returning the original value. Until this atomic operation completes, any other read or write
|
||||
* operation against the array will block.
|
||||
*/
|
||||
or(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;
|
||||
|
||||
/**
|
||||
* Stores a value at the given position in the array, returning the new value. Until this
|
||||
* atomic operation completes, any other read or write operation against the array will block.
|
||||
*/
|
||||
store(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;
|
||||
|
||||
/**
|
||||
* Subtracts a value from the value at the given position in the array, returning the original
|
||||
* value. Until this atomic operation completes, any other read or write operation against the
|
||||
* array will block.
|
||||
*/
|
||||
sub(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;
|
||||
|
||||
/**
|
||||
* If the value at the given position in the array is equal to the provided value, the current
|
||||
* agent is put to sleep causing execution to suspend until the timeout expires (returning
|
||||
* `"timed-out"`) or until the agent is awoken (returning `"ok"`); otherwise, returns
|
||||
* `"not-equal"`.
|
||||
*/
|
||||
wait(typedArray: Int32Array, index: number, value: number, timeout?: number): "ok" | "not-equal" | "timed-out";
|
||||
|
||||
/**
|
||||
* Wakes up sleeping agents that are waiting on the given index of the array, returning the
|
||||
* number of agents that were awoken.
|
||||
* @param typedArray A shared Int32Array.
|
||||
* @param index The position in the typedArray to wake up on.
|
||||
* @param count The number of sleeping agents to notify. Defaults to +Infinity.
|
||||
*/
|
||||
notify(typedArray: Int32Array, index: number, count?: number): number;
|
||||
|
||||
/**
|
||||
* Stores the bitwise XOR of a value with the value at the given position in the array,
|
||||
* returning the original value. Until this atomic operation completes, any other read or write
|
||||
* operation against the array will block.
|
||||
*/
|
||||
xor(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;
|
||||
|
||||
readonly [Symbol.toStringTag]: "Atomics";
|
||||
}
|
||||
|
||||
declare var Atomics: Atomics;
|
||||
@@ -0,0 +1,31 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getBaseTypesOfClassMember = getBaseTypesOfClassMember;
|
||||
/**
|
||||
* Given a member of a class which extends another class or implements an interface,
|
||||
* yields the corresponding member type for each of the base class/interfaces.
|
||||
*/
|
||||
function* getBaseTypesOfClassMember(services, memberNode) {
|
||||
const memberTsNode = services.esTreeNodeToTSNodeMap.get(memberNode);
|
||||
if (memberTsNode.name == null) {
|
||||
return;
|
||||
}
|
||||
const checker = services.program.getTypeChecker();
|
||||
const memberSymbol = checker.getSymbolAtLocation(memberTsNode.name);
|
||||
if (memberSymbol == null) {
|
||||
return;
|
||||
}
|
||||
const classNode = memberTsNode.parent;
|
||||
for (const clauseNode of classNode.heritageClauses ?? []) {
|
||||
for (const baseTypeNode of clauseNode.types) {
|
||||
const baseType = checker.getTypeAtLocation(baseTypeNode);
|
||||
const baseMemberSymbol = checker.getPropertyOfType(baseType, memberSymbol.name);
|
||||
if (baseMemberSymbol == null) {
|
||||
continue;
|
||||
}
|
||||
const baseMemberType = checker.getTypeOfSymbolAtLocation(baseMemberSymbol, memberTsNode);
|
||||
const heritageToken = clauseNode.token;
|
||||
yield { baseMemberType, baseType, heritageToken };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*! *****************************************************************************
|
||||
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="es2020.bigint" />
|
||||
|
||||
interface Atomics {
|
||||
/**
|
||||
* A non-blocking, asynchronous version of wait which is usable on the main thread.
|
||||
* Waits asynchronously on a shared memory location and returns a Promise
|
||||
* @param typedArray A shared Int32Array or BigInt64Array.
|
||||
* @param index The position in the typedArray to wait on.
|
||||
* @param value The expected value to test.
|
||||
* @param [timeout] The expected value to test.
|
||||
*/
|
||||
waitAsync(typedArray: Int32Array, index: number, value: number, timeout?: number): { async: false; value: "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "timed-out">; };
|
||||
|
||||
/**
|
||||
* A non-blocking, asynchronous version of wait which is usable on the main thread.
|
||||
* Waits asynchronously on a shared memory location and returns a Promise
|
||||
* @param typedArray A shared Int32Array or BigInt64Array.
|
||||
* @param index The position in the typedArray to wait on.
|
||||
* @param value The expected value to test.
|
||||
* @param [timeout] The expected value to test.
|
||||
*/
|
||||
waitAsync(typedArray: BigInt64Array, index: number, value: bigint, timeout?: number): { async: false; value: "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "timed-out">; };
|
||||
}
|
||||
|
||||
interface SharedArrayBuffer {
|
||||
/**
|
||||
* Returns true if this SharedArrayBuffer can be grown.
|
||||
*
|
||||
* [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/growable)
|
||||
*/
|
||||
get growable(): boolean;
|
||||
|
||||
/**
|
||||
* If this SharedArrayBuffer is growable, returns the maximum byte length given during construction; returns the byte length if not.
|
||||
*
|
||||
* [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/maxByteLength)
|
||||
*/
|
||||
get maxByteLength(): number;
|
||||
|
||||
/**
|
||||
* Grows the SharedArrayBuffer to the specified size (in bytes).
|
||||
*
|
||||
* [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/grow)
|
||||
*/
|
||||
grow(newByteLength?: number): void;
|
||||
}
|
||||
|
||||
interface SharedArrayBufferConstructor {
|
||||
new (byteLength: number, options?: { maxByteLength?: number; }): SharedArrayBuffer;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "end-of-stream",
|
||||
"version": "1.4.5",
|
||||
"description": "Call a callback when a readable/writable/duplex stream has completed or failed.",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/mafintosh/end-of-stream.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"once": "^1.4.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test.js"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"keywords": [
|
||||
"stream",
|
||||
"streams",
|
||||
"callback",
|
||||
"finish",
|
||||
"close",
|
||||
"end",
|
||||
"wait"
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/mafintosh/end-of-stream/issues"
|
||||
},
|
||||
"homepage": "https://github.com/mafintosh/end-of-stream",
|
||||
"main": "index.js",
|
||||
"author": "Mathias Buus <mathiasbuus@gmail.com>",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"tape": "^4.11.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
function _classCheckPrivateStaticFieldDescriptor(t, e) {
|
||||
if (void 0 === t) throw new TypeError("attempted to " + e + " private static field before its declaration");
|
||||
}
|
||||
module.exports = _classCheckPrivateStaticFieldDescriptor, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
||||
Reference in New Issue
Block a user