rename project, split up files, add argument inputs
This commit is contained in:
parent
dec6756b06
commit
191382b6d9
|
@ -1,188 +0,0 @@
|
|||
const jishoApi = require('unofficial-jisho-api');
|
||||
jisho = new jishoApi();
|
||||
fs = require('fs');
|
||||
const util = require('util');
|
||||
|
||||
/************************************************************************
|
||||
***************************** Data fetching *****************************
|
||||
************************************************************************/
|
||||
|
||||
async function fetchKanjiFromTxt(file) {
|
||||
const read = util.promisify(fs.readFile);
|
||||
const data = await read(file, 'utf8');
|
||||
return data.split('');
|
||||
}
|
||||
|
||||
async function delayedJishoCall(kanji, delay) {
|
||||
return new Promise((res, rej) => {
|
||||
setTimeout(() => {
|
||||
res(jisho.searchForKanji(kanji));
|
||||
}, delay);
|
||||
})
|
||||
}
|
||||
|
||||
/* Function to fetch jisho data for all kanjis in an array */
|
||||
async function fetchKanjiFromJisho(kanjiArray) {
|
||||
const promises = kanjiArray.map(async (kanji, i) => await delayedJishoCall(kanji, i*50));
|
||||
return await Promise.all(promises);
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
***************************** Kanji tables ******************************
|
||||
************************************************************************/
|
||||
|
||||
function kanjiTable(kanjiArray) {
|
||||
const xLength = 20;
|
||||
const yLength = Math.ceil(kanjiArray.length/xLength);
|
||||
const sideLength = Math.ceil(Math.sqrt(kanjiArray.length));
|
||||
|
||||
let tableString = '';
|
||||
for (let y_index = 0; y_index < yLength; y_index++) {
|
||||
|
||||
const lineArray = new Array;
|
||||
|
||||
for (let x_index = 0; x_index < xLength; x_index++) {
|
||||
const indexNumber = y_index * yLength + x_index;
|
||||
lineArray.push(kanjiArray[indexNumber] ? kanjiArray[indexNumber] : '');
|
||||
}
|
||||
|
||||
tableString += `${lineArray.join(' & ')} \\\\\n`
|
||||
}
|
||||
|
||||
return `\\begin{tabular}{ ${'c '.repeat(xLength)}}
|
||||
${tableString}\\end{tabular}`
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
**************************** Page Processing ****************************
|
||||
************************************************************************/
|
||||
|
||||
const yomiBrackets = ['\\textbf{\\textcolor{myGreen!80!black}{', '}}'];
|
||||
const yomiConnector = '、 ';
|
||||
const yomiDash = '—';
|
||||
|
||||
function convertKunyomi(res) {
|
||||
|
||||
if (res.kunyomi.length === 0) return '';
|
||||
|
||||
const kunyomi = JSON.stringify(res.kunyomi)
|
||||
.replace(/"|\[|\]/g, '')
|
||||
.replace(/\\/g, '\\\\')
|
||||
.replace(/%/g, '\\%')
|
||||
.replace(/&/g, '\\&')
|
||||
.split(',');
|
||||
|
||||
for (const i in kunyomi) {
|
||||
instance = kunyomi[i];
|
||||
|
||||
if (instance.includes('.') && instance.includes('-')) {
|
||||
|
||||
}
|
||||
else if (instance.includes('.')) {
|
||||
const words = instance.split('.');
|
||||
words[0] = yomiBrackets[0] + words[0] + yomiBrackets[1];
|
||||
kunyomi[i] = words.join('');
|
||||
}
|
||||
else if (instance.includes('-')) {
|
||||
const words = instance.split(/(?<=\-)/);
|
||||
if (words[0] == '-') { // ['-', 'word']
|
||||
words[0] = yomiDash;
|
||||
words[1] = yomiBrackets[0] + words[1] + yomiBrackets[1];
|
||||
} else { // ['Word-', '']
|
||||
words[1] = yomiDash;
|
||||
words[0] = words[0].slice(0, words[0].length-1);
|
||||
words[0] = yomiBrackets[0] + words[0] + yomiBrackets[1];
|
||||
}
|
||||
kunyomi[i] = words.join('');
|
||||
}
|
||||
else {
|
||||
kunyomi[i] = yomiBrackets[0] + instance + yomiBrackets[1];
|
||||
}
|
||||
}
|
||||
|
||||
return kunyomi.join(yomiConnector);
|
||||
}
|
||||
|
||||
function convertOnyomi(res) {
|
||||
return JSON.stringify(res.onyomi)
|
||||
.replace(/"|\[|\]/g, '')
|
||||
.replace(/\\/g, '\\\\')
|
||||
.replace(/%/g, '\\%')
|
||||
.replace(/,/g, yomiConnector)
|
||||
.replace(/&/g, '\\&');
|
||||
}
|
||||
|
||||
function convertMeaning(res) {
|
||||
return res.meaning
|
||||
.replace(/\\/g, '\\\\')
|
||||
.replace(/%/g, '\\%')
|
||||
.replace(/&/g, '\\&');
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
**************************** Main Functions *****************************
|
||||
************************************************************************/
|
||||
|
||||
/* Sort list of result array */
|
||||
const sortKanji = (kanjiData) => kanjiData.sort((a, b) => (a.strokeCount > b.strokeCount) ? 1 : -1);
|
||||
|
||||
/* Process result array into object with LaTeX strings */
|
||||
function getKanjiTexData(kanjiArray) {
|
||||
return kanjiArray.map(kanji => {
|
||||
|
||||
const meaning = convertMeaning(kanji);
|
||||
const kunyomi = convertKunyomi(kanji);
|
||||
const onyomi = convertOnyomi(kanji);
|
||||
|
||||
return {
|
||||
kanji: kanji.query,
|
||||
kanjiPageHeader: `\\kanjiPageHeader{${kanji.query}}{${kanji.taughtIn}}{${kanji.jlptLevel}}{${kanji.strokeCount}}{${kanji.radical.symbol}}`,
|
||||
kanjiMeaning: meaning ? `\\kanjiMeaning{${meaning}}` : '',
|
||||
kunyomi: kunyomi ? `\\kunyomi{${kunyomi}}` : '',
|
||||
onyomi: onyomi ? `\\onyomi{${onyomi}}` : '',
|
||||
kanjiRow: `\\kanjiRow{${kanji.query}}`
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/* Encapsulating main process in async function */
|
||||
async function main(jlptLevel) {
|
||||
|
||||
const kanjiArray = await fetchKanjiFromTxt(`../data/txt/${jlptLevel}.txt`);
|
||||
console.log(`Fetched txt for ${jlptLevel}`);
|
||||
|
||||
const results = await fetchKanjiFromJisho(kanjiArray);
|
||||
console.log(`Fetched data from Jisho for ${jlptLevel}`);
|
||||
|
||||
const sortedResults = sortKanji(results);
|
||||
const sortedKanji = sortedResults.map(result => result.query);
|
||||
const texData = getKanjiTexData(sortedResults);
|
||||
console.log(`Processed pages for ${jlptLevel}`);
|
||||
|
||||
const resultTable = kanjiTable(sortedKanji);
|
||||
console.log(`Processed table for ${jlptLevel}`);
|
||||
|
||||
let resultPage = '';
|
||||
for (kanji of texData) {
|
||||
resultPage+=`${kanji.kanjiPageHeader}
|
||||
${kanji.kanjiMeaning ? kanji.kanjiMeaning : ''}
|
||||
${kanji.kunyomi ? kanji.kunyomi : ''}
|
||||
${kanji.onyomi ? kanji.onyomi : ''}
|
||||
${kanji.kanjiRow}
|
||||
\\newpage\n`;
|
||||
}
|
||||
|
||||
fs.writeFile(`../data/tables/${jlptLevel}.tex`, resultTable, (err) => {if (err) console.error(err)});
|
||||
fs.writeFile(`../data/pages/${jlptLevel}.tex`, resultPage, (err) => {if (err) console.error(err)});
|
||||
}
|
||||
|
||||
async function loopMain() {
|
||||
await main('n5');
|
||||
await main('n4');
|
||||
await main('n3');
|
||||
await main('n2');
|
||||
await main('n1');
|
||||
}
|
||||
|
||||
loopMain();
|
|
@ -1,21 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) Microsoft Corporation.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE
|
|
@ -1,16 +0,0 @@
|
|||
# Installation
|
||||
> `npm install --save @types/node`
|
||||
|
||||
# Summary
|
||||
This package contains type definitions for Node.js (http://nodejs.org/).
|
||||
|
||||
# Details
|
||||
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node.
|
||||
|
||||
### Additional Details
|
||||
* Last updated: Sun, 26 Apr 2020 17:42:18 GMT
|
||||
* Dependencies: none
|
||||
* Global values: `Buffer`, `Symbol`, `__dirname`, `__filename`, `clearImmediate`, `clearInterval`, `clearTimeout`, `console`, `exports`, `global`, `module`, `process`, `queueMicrotask`, `require`, `setImmediate`, `setInterval`, `setTimeout`
|
||||
|
||||
# Credits
|
||||
These definitions were written by [Microsoft TypeScript](https://github.com/Microsoft), [DefinitelyTyped](https://github.com/DefinitelyTyped), [Alberto Schiabel](https://github.com/jkomyno), [Alexander T.](https://github.com/a-tarasyuk), [Alvis HT Tang](https://github.com/alvis), [Andrew Makarov](https://github.com/r3nya), [Benjamin Toueg](https://github.com/btoueg), [Bruno Scheufler](https://github.com/brunoscheufler), [Chigozirim C.](https://github.com/smac89), [Christian Vaagland Tellnes](https://github.com/tellnes), [David Junger](https://github.com/touffy), [Deividas Bakanas](https://github.com/DeividasBakanas), [Eugene Y. Q. Shen](https://github.com/eyqs), [Flarna](https://github.com/Flarna), [Hannes Magnusson](https://github.com/Hannes-Magnusson-CK), [Hoàng Văn Khải](https://github.com/KSXGitHub), [Huw](https://github.com/hoo29), [Kelvin Jin](https://github.com/kjin), [Klaus Meinhardt](https://github.com/ajafff), [Lishude](https://github.com/islishude), [Mariusz Wiktorczyk](https://github.com/mwiktorczyk), [Mohsen Azimi](https://github.com/mohsen1), [Nicolas Even](https://github.com/n-e), [Nicolas Voigt](https://github.com/octo-sniffle), [Nikita Galkin](https://github.com/galkin), [Parambir Singh](https://github.com/parambirs), [Sebastian Silbermann](https://github.com/eps1lon), [Simon Schick](https://github.com/SimonSchick), [Thomas den Hollander](https://github.com/ThomasdenH), [Wilco Bakker](https://github.com/WilcoBakker), [wwwy3y3](https://github.com/wwwy3y3), [Samuel Ainsworth](https://github.com/samuela), [Kyle Uehlein](https://github.com/kuehlein), [Jordi Oliveras Rovira](https://github.com/j-oliveras), [Thanik Bhongbhibhat](https://github.com/bhongy), [Marcin Kopacz](https://github.com/chyzwar), [Trivikram Kamat](https://github.com/trivikr), [Minh Son Nguyen](https://github.com/nguymin4), [Junxiao Shi](https://github.com/yoursunny), [Ilia Baryshnikov](https://github.com/qwelias), [ExE Boss](https://github.com/ExE-Boss), [Surasak Chaisurin](https://github.com/Ryan-Willpower), and [Piotr Błażejewicz](https://github.com/peterblazejewicz).
|
|
@ -1,57 +0,0 @@
|
|||
declare module "assert" {
|
||||
function assert(value: any, message?: string | Error): void;
|
||||
namespace assert {
|
||||
class AssertionError implements Error {
|
||||
name: string;
|
||||
message: string;
|
||||
actual: any;
|
||||
expected: any;
|
||||
operator: string;
|
||||
generatedMessage: boolean;
|
||||
code: 'ERR_ASSERTION';
|
||||
|
||||
constructor(options?: {
|
||||
message?: string; actual?: any; expected?: any;
|
||||
operator?: string; stackStartFn?: Function
|
||||
});
|
||||
}
|
||||
|
||||
type AssertPredicate = RegExp | (new() => object) | ((thrown: any) => boolean) | object | Error;
|
||||
|
||||
function fail(message?: string | Error): never;
|
||||
/** @deprecated since v10.0.0 - use fail([message]) or other assert functions instead. */
|
||||
function fail(actual: any, expected: any, message?: string | Error, operator?: string, stackStartFn?: Function): never;
|
||||
function ok(value: any, message?: string | Error): void;
|
||||
/** @deprecated since v9.9.0 - use strictEqual() instead. */
|
||||
function equal(actual: any, expected: any, message?: string | Error): void;
|
||||
/** @deprecated since v9.9.0 - use notStrictEqual() instead. */
|
||||
function notEqual(actual: any, expected: any, message?: string | Error): void;
|
||||
/** @deprecated since v9.9.0 - use deepStrictEqual() instead. */
|
||||
function deepEqual(actual: any, expected: any, message?: string | Error): void;
|
||||
/** @deprecated since v9.9.0 - use notDeepStrictEqual() instead. */
|
||||
function notDeepEqual(actual: any, expected: any, message?: string | Error): void;
|
||||
function strictEqual(actual: any, expected: any, message?: string | Error): void;
|
||||
function notStrictEqual(actual: any, expected: any, message?: string | Error): void;
|
||||
function deepStrictEqual(actual: any, expected: any, message?: string | Error): void;
|
||||
function notDeepStrictEqual(actual: any, expected: any, message?: string | Error): void;
|
||||
|
||||
function throws(block: () => any, message?: string | Error): void;
|
||||
function throws(block: () => any, error: AssertPredicate, message?: string | Error): void;
|
||||
function doesNotThrow(block: () => any, message?: string | Error): void;
|
||||
function doesNotThrow(block: () => any, error: RegExp | Function, message?: string | Error): void;
|
||||
|
||||
function ifError(value: any): void;
|
||||
|
||||
function rejects(block: (() => Promise<any>) | Promise<any>, message?: string | Error): Promise<void>;
|
||||
function rejects(block: (() => Promise<any>) | Promise<any>, error: AssertPredicate, message?: string | Error): Promise<void>;
|
||||
function doesNotReject(block: (() => Promise<any>) | Promise<any>, message?: string | Error): Promise<void>;
|
||||
function doesNotReject(block: (() => Promise<any>) | Promise<any>, error: RegExp | Function, message?: string | Error): Promise<void>;
|
||||
|
||||
function match(value: string, regExp: RegExp, message?: string | Error): void;
|
||||
function doesNotMatch(value: string, regExp: RegExp, message?: string | Error): void;
|
||||
|
||||
const strict: typeof assert;
|
||||
}
|
||||
|
||||
export = assert;
|
||||
}
|
|
@ -1,247 +0,0 @@
|
|||
/**
|
||||
* Async Hooks module: https://nodejs.org/api/async_hooks.html
|
||||
*/
|
||||
declare module "async_hooks" {
|
||||
/**
|
||||
* Returns the asyncId of the current execution context.
|
||||
*/
|
||||
function executionAsyncId(): number;
|
||||
|
||||
/**
|
||||
* The resource representing the current execution.
|
||||
* Useful to store data within the resource.
|
||||
*
|
||||
* Resource objects returned by `executionAsyncResource()` are most often internal
|
||||
* Node.js handle objects with undocumented APIs. Using any functions or properties
|
||||
* on the object is likely to crash your application and should be avoided.
|
||||
*
|
||||
* Using `executionAsyncResource()` in the top-level execution context will
|
||||
* return an empty object as there is no handle or request object to use,
|
||||
* but having an object representing the top-level can be helpful.
|
||||
*/
|
||||
function executionAsyncResource(): object;
|
||||
|
||||
/**
|
||||
* Returns the ID of the resource responsible for calling the callback that is currently being executed.
|
||||
*/
|
||||
function triggerAsyncId(): number;
|
||||
|
||||
interface HookCallbacks {
|
||||
/**
|
||||
* Called when a class is constructed that has the possibility to emit an asynchronous event.
|
||||
* @param asyncId a unique ID for the async resource
|
||||
* @param type the type of the async resource
|
||||
* @param triggerAsyncId the unique ID of the async resource in whose execution context this async resource was created
|
||||
* @param resource reference to the resource representing the async operation, needs to be released during destroy
|
||||
*/
|
||||
init?(asyncId: number, type: string, triggerAsyncId: number, resource: object): void;
|
||||
|
||||
/**
|
||||
* When an asynchronous operation is initiated or completes a callback is called to notify the user.
|
||||
* The before callback is called just before said callback is executed.
|
||||
* @param asyncId the unique identifier assigned to the resource about to execute the callback.
|
||||
*/
|
||||
before?(asyncId: number): void;
|
||||
|
||||
/**
|
||||
* Called immediately after the callback specified in before is completed.
|
||||
* @param asyncId the unique identifier assigned to the resource which has executed the callback.
|
||||
*/
|
||||
after?(asyncId: number): void;
|
||||
|
||||
/**
|
||||
* Called when a promise has resolve() called. This may not be in the same execution id
|
||||
* as the promise itself.
|
||||
* @param asyncId the unique id for the promise that was resolve()d.
|
||||
*/
|
||||
promiseResolve?(asyncId: number): void;
|
||||
|
||||
/**
|
||||
* Called after the resource corresponding to asyncId is destroyed
|
||||
* @param asyncId a unique ID for the async resource
|
||||
*/
|
||||
destroy?(asyncId: number): void;
|
||||
}
|
||||
|
||||
interface AsyncHook {
|
||||
/**
|
||||
* Enable the callbacks for a given AsyncHook instance. If no callbacks are provided enabling is a noop.
|
||||
*/
|
||||
enable(): this;
|
||||
|
||||
/**
|
||||
* Disable the callbacks for a given AsyncHook instance from the global pool of AsyncHook callbacks to be executed. Once a hook has been disabled it will not be called again until enabled.
|
||||
*/
|
||||
disable(): this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers functions to be called for different lifetime events of each async operation.
|
||||
* @param options the callbacks to register
|
||||
* @return an AsyncHooks instance used for disabling and enabling hooks
|
||||
*/
|
||||
function createHook(options: HookCallbacks): AsyncHook;
|
||||
|
||||
interface AsyncResourceOptions {
|
||||
/**
|
||||
* The ID of the execution context that created this async event.
|
||||
* Default: `executionAsyncId()`
|
||||
*/
|
||||
triggerAsyncId?: number;
|
||||
|
||||
/**
|
||||
* Disables automatic `emitDestroy` when the object is garbage collected.
|
||||
* This usually does not need to be set (even if `emitDestroy` is called
|
||||
* manually), unless the resource's `asyncId` is retrieved and the
|
||||
* sensitive API's `emitDestroy` is called with it.
|
||||
* Default: `false`
|
||||
*/
|
||||
requireManualDestroy?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* The class AsyncResource was designed to be extended by the embedder's async resources.
|
||||
* Using this users can easily trigger the lifetime events of their own resources.
|
||||
*/
|
||||
class AsyncResource {
|
||||
/**
|
||||
* AsyncResource() is meant to be extended. Instantiating a
|
||||
* new AsyncResource() also triggers init. If triggerAsyncId is omitted then
|
||||
* async_hook.executionAsyncId() is used.
|
||||
* @param type The type of async event.
|
||||
* @param triggerAsyncId The ID of the execution context that created
|
||||
* this async event (default: `executionAsyncId()`), or an
|
||||
* AsyncResourceOptions object (since 9.3)
|
||||
*/
|
||||
constructor(type: string, triggerAsyncId?: number|AsyncResourceOptions);
|
||||
|
||||
/**
|
||||
* Call the provided function with the provided arguments in the
|
||||
* execution context of the async resource. This will establish the
|
||||
* context, trigger the AsyncHooks before callbacks, call the function,
|
||||
* trigger the AsyncHooks after callbacks, and then restore the original
|
||||
* execution context.
|
||||
* @param fn The function to call in the execution context of this
|
||||
* async resource.
|
||||
* @param thisArg The receiver to be used for the function call.
|
||||
* @param args Optional arguments to pass to the function.
|
||||
*/
|
||||
runInAsyncScope<This, Result>(fn: (this: This, ...args: any[]) => Result, thisArg?: This, ...args: any[]): Result;
|
||||
|
||||
/**
|
||||
* Call AsyncHooks destroy callbacks.
|
||||
*/
|
||||
emitDestroy(): void;
|
||||
|
||||
/**
|
||||
* @return the unique ID assigned to this AsyncResource instance.
|
||||
*/
|
||||
asyncId(): number;
|
||||
|
||||
/**
|
||||
* @return the trigger ID for this AsyncResource instance.
|
||||
*/
|
||||
triggerAsyncId(): number;
|
||||
}
|
||||
|
||||
/**
|
||||
* When having multiple instances of `AsyncLocalStorage`, they are independent
|
||||
* from each other. It is safe to instantiate this class multiple times.
|
||||
*/
|
||||
class AsyncLocalStorage<T> {
|
||||
/**
|
||||
* This method disables the instance of `AsyncLocalStorage`. All subsequent calls
|
||||
* to `asyncLocalStorage.getStore()` will return `undefined` until
|
||||
* `asyncLocalStorage.run()` or `asyncLocalStorage.runSyncAndReturn()`
|
||||
* is called again.
|
||||
*
|
||||
* When calling `asyncLocalStorage.disable()`, all current contexts linked to the
|
||||
* instance will be exited.
|
||||
*
|
||||
* Calling `asyncLocalStorage.disable()` is required before the
|
||||
* `asyncLocalStorage` can be garbage collected. This does not apply to stores
|
||||
* provided by the `asyncLocalStorage`, as those objects are garbage collected
|
||||
* along with the corresponding async resources.
|
||||
*
|
||||
* This method is to be used when the `asyncLocalStorage` is not in use anymore
|
||||
* in the current process.
|
||||
*/
|
||||
disable(): void;
|
||||
|
||||
/**
|
||||
* This method returns the current store.
|
||||
* If this method is called outside of an asynchronous context initialized by
|
||||
* calling `asyncLocalStorage.run` or `asyncLocalStorage.runAndReturn`, it will
|
||||
* return `undefined`.
|
||||
*/
|
||||
getStore(): T | undefined;
|
||||
|
||||
/**
|
||||
* Calling `asyncLocalStorage.run(callback)` will create a new asynchronous
|
||||
* context.
|
||||
* Within the callback function and the asynchronous operations from the callback,
|
||||
* `asyncLocalStorage.getStore()` will return an instance of `Map` known as
|
||||
* "the store". This store will be persistent through the following
|
||||
* asynchronous calls.
|
||||
*
|
||||
* The callback will be ran asynchronously. Optionally, arguments can be passed
|
||||
* to the function. They will be passed to the callback function.
|
||||
*
|
||||
* If an error is thrown by the callback function, it will not be caught by
|
||||
* a `try/catch` block as the callback is ran in a new asynchronous resource.
|
||||
* Also, the stacktrace will be impacted by the asynchronous call.
|
||||
*/
|
||||
// TODO: Apply generic vararg once available
|
||||
run(store: T, callback: (...args: any[]) => void, ...args: any[]): void;
|
||||
|
||||
/**
|
||||
* Calling `asyncLocalStorage.exit(callback)` will create a new asynchronous
|
||||
* context.
|
||||
* Within the callback function and the asynchronous operations from the callback,
|
||||
* `asyncLocalStorage.getStore()` will return `undefined`.
|
||||
*
|
||||
* The callback will be ran asynchronously. Optionally, arguments can be passed
|
||||
* to the function. They will be passed to the callback function.
|
||||
*
|
||||
* If an error is thrown by the callback function, it will not be caught by
|
||||
* a `try/catch` block as the callback is ran in a new asynchronous resource.
|
||||
* Also, the stacktrace will be impacted by the asynchronous call.
|
||||
*/
|
||||
exit(callback: (...args: any[]) => void, ...args: any[]): void;
|
||||
|
||||
/**
|
||||
* This methods runs a function synchronously within a context and return its
|
||||
* return value. The store is not accessible outside of the callback function or
|
||||
* the asynchronous operations created within the callback.
|
||||
*
|
||||
* Optionally, arguments can be passed to the function. They will be passed to
|
||||
* the callback function.
|
||||
*
|
||||
* If the callback function throws an error, it will be thrown by
|
||||
* `runSyncAndReturn` too. The stacktrace will not be impacted by this call and
|
||||
* the context will be exited.
|
||||
*/
|
||||
runSyncAndReturn<R>(store: T, callback: (...args: any[]) => R, ...args: any[]): R;
|
||||
|
||||
/**
|
||||
* This methods runs a function synchronously outside of a context and return its
|
||||
* return value. The store is not accessible within the callback function or
|
||||
* the asynchronous operations created within the callback.
|
||||
*
|
||||
* Optionally, arguments can be passed to the function. They will be passed to
|
||||
* the callback function.
|
||||
*
|
||||
* If the callback function throws an error, it will be thrown by
|
||||
* `exitSyncAndReturn` too. The stacktrace will not be impacted by this call and
|
||||
* the context will be re-entered.
|
||||
*/
|
||||
exitSyncAndReturn<R>(callback: (...args: any[]) => R, ...args: any[]): R;
|
||||
|
||||
/**
|
||||
* Calling `asyncLocalStorage.enterWith(store)` will transition into the context
|
||||
* for the remainder of the current synchronous execution and will persist
|
||||
* through any following asynchronous calls.
|
||||
*/
|
||||
enterWith(store: T): void;
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
// base definnitions for all NodeJS modules that are not specific to any version of TypeScript
|
||||
/// <reference path="globals.d.ts" />
|
||||
/// <reference path="async_hooks.d.ts" />
|
||||
/// <reference path="buffer.d.ts" />
|
||||
/// <reference path="child_process.d.ts" />
|
||||
/// <reference path="cluster.d.ts" />
|
||||
/// <reference path="console.d.ts" />
|
||||
/// <reference path="constants.d.ts" />
|
||||
/// <reference path="crypto.d.ts" />
|
||||
/// <reference path="dgram.d.ts" />
|
||||
/// <reference path="dns.d.ts" />
|
||||
/// <reference path="domain.d.ts" />
|
||||
/// <reference path="events.d.ts" />
|
||||
/// <reference path="fs.d.ts" />
|
||||
/// <reference path="http.d.ts" />
|
||||
/// <reference path="http2.d.ts" />
|
||||
/// <reference path="https.d.ts" />
|
||||
/// <reference path="inspector.d.ts" />
|
||||
/// <reference path="module.d.ts" />
|
||||
/// <reference path="net.d.ts" />
|
||||
/// <reference path="os.d.ts" />
|
||||
/// <reference path="path.d.ts" />
|
||||
/// <reference path="perf_hooks.d.ts" />
|
||||
/// <reference path="process.d.ts" />
|
||||
/// <reference path="punycode.d.ts" />
|
||||
/// <reference path="querystring.d.ts" />
|
||||
/// <reference path="readline.d.ts" />
|
||||
/// <reference path="repl.d.ts" />
|
||||
/// <reference path="stream.d.ts" />
|
||||
/// <reference path="string_decoder.d.ts" />
|
||||
/// <reference path="timers.d.ts" />
|
||||
/// <reference path="tls.d.ts" />
|
||||
/// <reference path="trace_events.d.ts" />
|
||||
/// <reference path="tty.d.ts" />
|
||||
/// <reference path="url.d.ts" />
|
||||
/// <reference path="util.d.ts" />
|
||||
/// <reference path="v8.d.ts" />
|
||||
/// <reference path="vm.d.ts" />
|
||||
/// <reference path="worker_threads.d.ts" />
|
||||
/// <reference path="zlib.d.ts" />
|
|
@ -1,22 +0,0 @@
|
|||
declare module "buffer" {
|
||||
export const INSPECT_MAX_BYTES: number;
|
||||
export const kMaxLength: number;
|
||||
export const kStringMaxLength: number;
|
||||
export const constants: {
|
||||
MAX_LENGTH: number;
|
||||
MAX_STRING_LENGTH: number;
|
||||
};
|
||||
const BuffType: typeof Buffer;
|
||||
|
||||
export type TranscodeEncoding = "ascii" | "utf8" | "utf16le" | "ucs2" | "latin1" | "binary";
|
||||
|
||||
export function transcode(source: Uint8Array, fromEnc: TranscodeEncoding, toEnc: TranscodeEncoding): Buffer;
|
||||
|
||||
export const SlowBuffer: {
|
||||
/** @deprecated since v6.0.0, use Buffer.allocUnsafeSlow() */
|
||||
new(size: number): Buffer;
|
||||
prototype: Buffer;
|
||||
};
|
||||
|
||||
export { BuffType as Buffer };
|
||||
}
|
|
@ -1,495 +0,0 @@
|
|||
declare module "child_process" {
|
||||
import * as events from "events";
|
||||
import * as net from "net";
|
||||
import { Writable, Readable, Stream, Pipe } from "stream";
|
||||
|
||||
type Serializable = string | object | number | boolean;
|
||||
type SendHandle = net.Socket | net.Server;
|
||||
|
||||
interface ChildProcess extends events.EventEmitter {
|
||||
stdin: Writable | null;
|
||||
stdout: Readable | null;
|
||||
stderr: Readable | null;
|
||||
readonly channel?: Pipe | null;
|
||||
readonly stdio: [
|
||||
Writable | null, // stdin
|
||||
Readable | null, // stdout
|
||||
Readable | null, // stderr
|
||||
Readable | Writable | null | undefined, // extra
|
||||
Readable | Writable | null | undefined // extra
|
||||
];
|
||||
readonly killed: boolean;
|
||||
readonly pid: number;
|
||||
readonly connected: boolean;
|
||||
kill(signal?: NodeJS.Signals | number): boolean;
|
||||
send(message: Serializable, callback?: (error: Error | null) => void): boolean;
|
||||
send(message: Serializable, sendHandle?: SendHandle, callback?: (error: Error | null) => void): boolean;
|
||||
send(message: Serializable, sendHandle?: SendHandle, options?: MessageOptions, callback?: (error: Error | null) => void): boolean;
|
||||
disconnect(): void;
|
||||
unref(): void;
|
||||
ref(): void;
|
||||
|
||||
/**
|
||||
* events.EventEmitter
|
||||
* 1. close
|
||||
* 2. disconnect
|
||||
* 3. error
|
||||
* 4. exit
|
||||
* 5. message
|
||||
*/
|
||||
|
||||
addListener(event: string, listener: (...args: any[]) => void): this;
|
||||
addListener(event: "close", listener: (code: number, signal: NodeJS.Signals) => void): this;
|
||||
addListener(event: "disconnect", listener: () => void): this;
|
||||
addListener(event: "error", listener: (err: Error) => void): this;
|
||||
addListener(event: "exit", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
|
||||
addListener(event: "message", listener: (message: Serializable, sendHandle: SendHandle) => void): this;
|
||||
|
||||
emit(event: string | symbol, ...args: any[]): boolean;
|
||||
emit(event: "close", code: number, signal: NodeJS.Signals): boolean;
|
||||
emit(event: "disconnect"): boolean;
|
||||
emit(event: "error", err: Error): boolean;
|
||||
emit(event: "exit", code: number | null, signal: NodeJS.Signals | null): boolean;
|
||||
emit(event: "message", message: Serializable, sendHandle: SendHandle): boolean;
|
||||
|
||||
on(event: string, listener: (...args: any[]) => void): this;
|
||||
on(event: "close", listener: (code: number, signal: NodeJS.Signals) => void): this;
|
||||
on(event: "disconnect", listener: () => void): this;
|
||||
on(event: "error", listener: (err: Error) => void): this;
|
||||
on(event: "exit", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
|
||||
on(event: "message", listener: (message: Serializable, sendHandle: SendHandle) => void): this;
|
||||
|
||||
once(event: string, listener: (...args: any[]) => void): this;
|
||||
once(event: "close", listener: (code: number, signal: NodeJS.Signals) => void): this;
|
||||
once(event: "disconnect", listener: () => void): this;
|
||||
once(event: "error", listener: (err: Error) => void): this;
|
||||
once(event: "exit", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
|
||||
once(event: "message", listener: (message: Serializable, sendHandle: SendHandle) => void): this;
|
||||
|
||||
prependListener(event: string, listener: (...args: any[]) => void): this;
|
||||
prependListener(event: "close", listener: (code: number, signal: NodeJS.Signals) => void): this;
|
||||
prependListener(event: "disconnect", listener: () => void): this;
|
||||
prependListener(event: "error", listener: (err: Error) => void): this;
|
||||
prependListener(event: "exit", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
|
||||
prependListener(event: "message", listener: (message: Serializable, sendHandle: SendHandle) => void): this;
|
||||
|
||||
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
||||
prependOnceListener(event: "close", listener: (code: number, signal: NodeJS.Signals) => void): this;
|
||||
prependOnceListener(event: "disconnect", listener: () => void): this;
|
||||
prependOnceListener(event: "error", listener: (err: Error) => void): this;
|
||||
prependOnceListener(event: "exit", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
|
||||
prependOnceListener(event: "message", listener: (message: Serializable, sendHandle: SendHandle) => void): this;
|
||||
}
|
||||
|
||||
// return this object when stdio option is undefined or not specified
|
||||
interface ChildProcessWithoutNullStreams extends ChildProcess {
|
||||
stdin: Writable;
|
||||
stdout: Readable;
|
||||
stderr: Readable;
|
||||
readonly stdio: [
|
||||
Writable, // stdin
|
||||
Readable, // stdout
|
||||
Readable, // stderr
|
||||
Readable | Writable | null | undefined, // extra, no modification
|
||||
Readable | Writable | null | undefined // extra, no modification
|
||||
];
|
||||
}
|
||||
|
||||
// return this object when stdio option is a tuple of 3
|
||||
interface ChildProcessByStdio<
|
||||
I extends null | Writable,
|
||||
O extends null | Readable,
|
||||
E extends null | Readable,
|
||||
> extends ChildProcess {
|
||||
stdin: I;
|
||||
stdout: O;
|
||||
stderr: E;
|
||||
readonly stdio: [
|
||||
I,
|
||||
O,
|
||||
E,
|
||||
Readable | Writable | null | undefined, // extra, no modification
|
||||
Readable | Writable | null | undefined // extra, no modification
|
||||
];
|
||||
}
|
||||
|
||||
interface MessageOptions {
|
||||
keepOpen?: boolean;
|
||||
}
|
||||
|
||||
type StdioOptions = "pipe" | "ignore" | "inherit" | Array<("pipe" | "ipc" | "ignore" | "inherit" | Stream | number | null | undefined)>;
|
||||
|
||||
type SerializationType = 'json' | 'advanced';
|
||||
|
||||
interface MessagingOptions {
|
||||
/**
|
||||
* Specify the kind of serialization used for sending messages between processes.
|
||||
* @default 'json'
|
||||
*/
|
||||
serialization?: SerializationType;
|
||||
}
|
||||
|
||||
interface ProcessEnvOptions {
|
||||
uid?: number;
|
||||
gid?: number;
|
||||
cwd?: string;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
}
|
||||
|
||||
interface CommonOptions extends ProcessEnvOptions {
|
||||
/**
|
||||
* @default true
|
||||
*/
|
||||
windowsHide?: boolean;
|
||||
/**
|
||||
* @default 0
|
||||
*/
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
interface CommonSpawnOptions extends CommonOptions, MessagingOptions {
|
||||
argv0?: string;
|
||||
stdio?: StdioOptions;
|
||||
shell?: boolean | string;
|
||||
windowsVerbatimArguments?: boolean;
|
||||
}
|
||||
|
||||
interface SpawnOptions extends CommonSpawnOptions {
|
||||
detached?: boolean;
|
||||
}
|
||||
|
||||
interface SpawnOptionsWithoutStdio extends SpawnOptions {
|
||||
stdio?: 'pipe' | Array<null | undefined | 'pipe'>;
|
||||
}
|
||||
|
||||
type StdioNull = 'inherit' | 'ignore' | Stream;
|
||||
type StdioPipe = undefined | null | 'pipe';
|
||||
|
||||
interface SpawnOptionsWithStdioTuple<
|
||||
Stdin extends StdioNull | StdioPipe,
|
||||
Stdout extends StdioNull | StdioPipe,
|
||||
Stderr extends StdioNull | StdioPipe,
|
||||
> extends SpawnOptions {
|
||||
stdio: [Stdin, Stdout, Stderr];
|
||||
}
|
||||
|
||||
// overloads of spawn without 'args'
|
||||
function spawn(command: string, options?: SpawnOptionsWithoutStdio): ChildProcessWithoutNullStreams;
|
||||
|
||||
function spawn(
|
||||
command: string,
|
||||
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>,
|
||||
): ChildProcessByStdio<Writable, Readable, Readable>;
|
||||
function spawn(
|
||||
command: string,
|
||||
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>,
|
||||
): ChildProcessByStdio<Writable, Readable, null>;
|
||||
function spawn(
|
||||
command: string,
|
||||
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,
|
||||
): ChildProcessByStdio<Writable, null, Readable>;
|
||||
function spawn(
|
||||
command: string,
|
||||
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,
|
||||
): ChildProcessByStdio<null, Readable, Readable>;
|
||||
function spawn(
|
||||
command: string,
|
||||
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,
|
||||
): ChildProcessByStdio<Writable, null, null>;
|
||||
function spawn(
|
||||
command: string,
|
||||
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,
|
||||
): ChildProcessByStdio<null, Readable, null>;
|
||||
function spawn(
|
||||
command: string,
|
||||
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,
|
||||
): ChildProcessByStdio<null, null, Readable>;
|
||||
function spawn(
|
||||
command: string,
|
||||
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,
|
||||
): ChildProcessByStdio<null, null, null>;
|
||||
|
||||
function spawn(command: string, options: SpawnOptions): ChildProcess;
|
||||
|
||||
// overloads of spawn with 'args'
|
||||
function spawn(command: string, args?: ReadonlyArray<string>, options?: SpawnOptionsWithoutStdio): ChildProcessWithoutNullStreams;
|
||||
|
||||
function spawn(
|
||||
command: string,
|
||||
args: ReadonlyArray<string>,
|
||||
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>,
|
||||
): ChildProcessByStdio<Writable, Readable, Readable>;
|
||||
function spawn(
|
||||
command: string,
|
||||
args: ReadonlyArray<string>,
|
||||
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>,
|
||||
): ChildProcessByStdio<Writable, Readable, null>;
|
||||
function spawn(
|
||||
command: string,
|
||||
args: ReadonlyArray<string>,
|
||||
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,
|
||||
): ChildProcessByStdio<Writable, null, Readable>;
|
||||
function spawn(
|
||||
command: string,
|
||||
args: ReadonlyArray<string>,
|
||||
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,
|
||||
): ChildProcessByStdio<null, Readable, Readable>;
|
||||
function spawn(
|
||||
command: string,
|
||||
args: ReadonlyArray<string>,
|
||||
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,
|
||||
): ChildProcessByStdio<Writable, null, null>;
|
||||
function spawn(
|
||||
command: string,
|
||||
args: ReadonlyArray<string>,
|
||||
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,
|
||||
): ChildProcessByStdio<null, Readable, null>;
|
||||
function spawn(
|
||||
command: string,
|
||||
args: ReadonlyArray<string>,
|
||||
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,
|
||||
): ChildProcessByStdio<null, null, Readable>;
|
||||
function spawn(
|
||||
command: string,
|
||||
args: ReadonlyArray<string>,
|
||||
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,
|
||||
): ChildProcessByStdio<null, null, null>;
|
||||
|
||||
function spawn(command: string, args: ReadonlyArray<string>, options: SpawnOptions): ChildProcess;
|
||||
|
||||
interface ExecOptions extends CommonOptions {
|
||||
shell?: string;
|
||||
maxBuffer?: number;
|
||||
killSignal?: NodeJS.Signals | number;
|
||||
}
|
||||
|
||||
interface ExecOptionsWithStringEncoding extends ExecOptions {
|
||||
encoding: BufferEncoding;
|
||||
}
|
||||
|
||||
interface ExecOptionsWithBufferEncoding extends ExecOptions {
|
||||
encoding: string | null; // specify `null`.
|
||||
}
|
||||
|
||||
interface ExecException extends Error {
|
||||
cmd?: string;
|
||||
killed?: boolean;
|
||||
code?: number;
|
||||
signal?: NodeJS.Signals;
|
||||
}
|
||||
|
||||
// no `options` definitely means stdout/stderr are `string`.
|
||||
function exec(command: string, callback?: (error: ExecException | null, stdout: string, stderr: string) => void): ChildProcess;
|
||||
|
||||
// `options` with `"buffer"` or `null` for `encoding` means stdout/stderr are definitely `Buffer`.
|
||||
function exec(command: string, options: { encoding: "buffer" | null } & ExecOptions, callback?: (error: ExecException | null, stdout: Buffer, stderr: Buffer) => void): ChildProcess;
|
||||
|
||||
// `options` with well known `encoding` means stdout/stderr are definitely `string`.
|
||||
function exec(command: string, options: { encoding: BufferEncoding } & ExecOptions, callback?: (error: ExecException | null, stdout: string, stderr: string) => void): ChildProcess;
|
||||
|
||||
// `options` with an `encoding` whose type is `string` means stdout/stderr could either be `Buffer` or `string`.
|
||||
// There is no guarantee the `encoding` is unknown as `string` is a superset of `BufferEncoding`.
|
||||
function exec(command: string, options: { encoding: string } & ExecOptions, callback?: (error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void): ChildProcess;
|
||||
|
||||
// `options` without an `encoding` means stdout/stderr are definitely `string`.
|
||||
function exec(command: string, options: ExecOptions, callback?: (error: ExecException | null, stdout: string, stderr: string) => void): ChildProcess;
|
||||
|
||||
// fallback if nothing else matches. Worst case is always `string | Buffer`.
|
||||
function exec(
|
||||
command: string,
|
||||
options: ({ encoding?: string | null } & ExecOptions) | undefined | null,
|
||||
callback?: (error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void,
|
||||
): ChildProcess;
|
||||
|
||||
interface PromiseWithChild<T> extends Promise<T> {
|
||||
child: ChildProcess;
|
||||
}
|
||||
|
||||
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
||||
namespace exec {
|
||||
function __promisify__(command: string): PromiseWithChild<{ stdout: string, stderr: string }>;
|
||||
function __promisify__(command: string, options: { encoding: "buffer" | null } & ExecOptions): PromiseWithChild<{ stdout: Buffer, stderr: Buffer }>;
|
||||
function __promisify__(command: string, options: { encoding: BufferEncoding } & ExecOptions): PromiseWithChild<{ stdout: string, stderr: string }>;
|
||||
function __promisify__(command: string, options: ExecOptions): PromiseWithChild<{ stdout: string, stderr: string }>;
|
||||
function __promisify__(command: string, options?: ({ encoding?: string | null } & ExecOptions) | null): PromiseWithChild<{ stdout: string | Buffer, stderr: string | Buffer }>;
|
||||
}
|
||||
|
||||
interface ExecFileOptions extends CommonOptions {
|
||||
maxBuffer?: number;
|
||||
killSignal?: NodeJS.Signals | number;
|
||||
windowsVerbatimArguments?: boolean;
|
||||
shell?: boolean | string;
|
||||
}
|
||||
interface ExecFileOptionsWithStringEncoding extends ExecFileOptions {
|
||||
encoding: BufferEncoding;
|
||||
}
|
||||
interface ExecFileOptionsWithBufferEncoding extends ExecFileOptions {
|
||||
encoding: 'buffer' | null;
|
||||
}
|
||||
interface ExecFileOptionsWithOtherEncoding extends ExecFileOptions {
|
||||
encoding: string;
|
||||
}
|
||||
|
||||
function execFile(file: string): ChildProcess;
|
||||
function execFile(file: string, options: ({ encoding?: string | null } & ExecFileOptions) | undefined | null): ChildProcess;
|
||||
function execFile(file: string, args?: ReadonlyArray<string> | null): ChildProcess;
|
||||
function execFile(file: string, args: ReadonlyArray<string> | undefined | null, options: ({ encoding?: string | null } & ExecFileOptions) | undefined | null): ChildProcess;
|
||||
|
||||
// no `options` definitely means stdout/stderr are `string`.
|
||||
function execFile(file: string, callback: (error: ExecException | null, stdout: string, stderr: string) => void): ChildProcess;
|
||||
function execFile(file: string, args: ReadonlyArray<string> | undefined | null, callback: (error: ExecException | null, stdout: string, stderr: string) => void): ChildProcess;
|
||||
|
||||
// `options` with `"buffer"` or `null` for `encoding` means stdout/stderr are definitely `Buffer`.
|
||||
function execFile(file: string, options: ExecFileOptionsWithBufferEncoding, callback: (error: ExecException | null, stdout: Buffer, stderr: Buffer) => void): ChildProcess;
|
||||
function execFile(
|
||||
file: string,
|
||||
args: ReadonlyArray<string> | undefined | null,
|
||||
options: ExecFileOptionsWithBufferEncoding,
|
||||
callback: (error: ExecException | null, stdout: Buffer, stderr: Buffer) => void,
|
||||
): ChildProcess;
|
||||
|
||||
// `options` with well known `encoding` means stdout/stderr are definitely `string`.
|
||||
function execFile(file: string, options: ExecFileOptionsWithStringEncoding, callback: (error: ExecException | null, stdout: string, stderr: string) => void): ChildProcess;
|
||||
function execFile(
|
||||
file: string,
|
||||
args: ReadonlyArray<string> | undefined | null,
|
||||
options: ExecFileOptionsWithStringEncoding,
|
||||
callback: (error: ExecException | null, stdout: string, stderr: string) => void,
|
||||
): ChildProcess;
|
||||
|
||||
// `options` with an `encoding` whose type is `string` means stdout/stderr could either be `Buffer` or `string`.
|
||||
// There is no guarantee the `encoding` is unknown as `string` is a superset of `BufferEncoding`.
|
||||
function execFile(
|
||||
file: string,
|
||||
options: ExecFileOptionsWithOtherEncoding,
|
||||
callback: (error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void,
|
||||
): ChildProcess;
|
||||
function execFile(
|
||||
file: string,
|
||||
args: ReadonlyArray<string> | undefined | null,
|
||||
options: ExecFileOptionsWithOtherEncoding,
|
||||
callback: (error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void,
|
||||
): ChildProcess;
|
||||
|
||||
// `options` without an `encoding` means stdout/stderr are definitely `string`.
|
||||
function execFile(file: string, options: ExecFileOptions, callback: (error: ExecException | null, stdout: string, stderr: string) => void): ChildProcess;
|
||||
function execFile(
|
||||
file: string,
|
||||
args: ReadonlyArray<string> | undefined | null,
|
||||
options: ExecFileOptions,
|
||||
callback: (error: ExecException | null, stdout: string, stderr: string) => void
|
||||
): ChildProcess;
|
||||
|
||||
// fallback if nothing else matches. Worst case is always `string | Buffer`.
|
||||
function execFile(
|
||||
file: string,
|
||||
options: ({ encoding?: string | null } & ExecFileOptions) | undefined | null,
|
||||
callback: ((error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void) | undefined | null,
|
||||
): ChildProcess;
|
||||
function execFile(
|
||||
file: string,
|
||||
args: ReadonlyArray<string> | undefined | null,
|
||||
options: ({ encoding?: string | null } & ExecFileOptions) | undefined | null,
|
||||
callback: ((error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void) | undefined | null,
|
||||
): ChildProcess;
|
||||
|
||||
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
||||
namespace execFile {
|
||||
function __promisify__(file: string): PromiseWithChild<{ stdout: string, stderr: string }>;
|
||||
function __promisify__(file: string, args: string[] | undefined | null): PromiseWithChild<{ stdout: string, stderr: string }>;
|
||||
function __promisify__(file: string, options: ExecFileOptionsWithBufferEncoding): PromiseWithChild<{ stdout: Buffer, stderr: Buffer }>;
|
||||
function __promisify__(file: string, args: string[] | undefined | null, options: ExecFileOptionsWithBufferEncoding): PromiseWithChild<{ stdout: Buffer, stderr: Buffer }>;
|
||||
function __promisify__(file: string, options: ExecFileOptionsWithStringEncoding): PromiseWithChild<{ stdout: string, stderr: string }>;
|
||||
function __promisify__(file: string, args: string[] | undefined | null, options: ExecFileOptionsWithStringEncoding): PromiseWithChild<{ stdout: string, stderr: string }>;
|
||||
function __promisify__(file: string, options: ExecFileOptionsWithOtherEncoding): PromiseWithChild<{ stdout: string | Buffer, stderr: string | Buffer }>;
|
||||
function __promisify__(file: string, args: string[] | undefined | null, options: ExecFileOptionsWithOtherEncoding): PromiseWithChild<{ stdout: string | Buffer, stderr: string | Buffer }>;
|
||||
function __promisify__(file: string, options: ExecFileOptions): PromiseWithChild<{ stdout: string, stderr: string }>;
|
||||
function __promisify__(file: string, args: string[] | undefined | null, options: ExecFileOptions): PromiseWithChild<{ stdout: string, stderr: string }>;
|
||||
function __promisify__(file: string, options: ({ encoding?: string | null } & ExecFileOptions) | undefined | null): PromiseWithChild<{ stdout: string | Buffer, stderr: string | Buffer }>;
|
||||
function __promisify__(
|
||||
file: string,
|
||||
args: string[] | undefined | null,
|
||||
options: ({ encoding?: string | null } & ExecFileOptions) | undefined | null,
|
||||
): PromiseWithChild<{ stdout: string | Buffer, stderr: string | Buffer }>;
|
||||
}
|
||||
|
||||
interface ForkOptions extends ProcessEnvOptions, MessagingOptions {
|
||||
execPath?: string;
|
||||
execArgv?: string[];
|
||||
silent?: boolean;
|
||||
stdio?: StdioOptions;
|
||||
detached?: boolean;
|
||||
windowsVerbatimArguments?: boolean;
|
||||
}
|
||||
function fork(modulePath: string, args?: ReadonlyArray<string>, options?: ForkOptions): ChildProcess;
|
||||
|
||||
interface SpawnSyncOptions extends CommonSpawnOptions {
|
||||
input?: string | NodeJS.ArrayBufferView;
|
||||
killSignal?: NodeJS.Signals | number;
|
||||
maxBuffer?: number;
|
||||
encoding?: string;
|
||||
}
|
||||
interface SpawnSyncOptionsWithStringEncoding extends SpawnSyncOptions {
|
||||
encoding: BufferEncoding;
|
||||
}
|
||||
interface SpawnSyncOptionsWithBufferEncoding extends SpawnSyncOptions {
|
||||
encoding: string; // specify `null`.
|
||||
}
|
||||
interface SpawnSyncReturns<T> {
|
||||
pid: number;
|
||||
output: string[];
|
||||
stdout: T;
|
||||
stderr: T;
|
||||
status: number | null;
|
||||
signal: NodeJS.Signals | null;
|
||||
error?: Error;
|
||||
}
|
||||
function spawnSync(command: string): SpawnSyncReturns<Buffer>;
|
||||
function spawnSync(command: string, options?: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns<string>;
|
||||
function spawnSync(command: string, options?: SpawnSyncOptionsWithBufferEncoding): SpawnSyncReturns<Buffer>;
|
||||
function spawnSync(command: string, options?: SpawnSyncOptions): SpawnSyncReturns<Buffer>;
|
||||
function spawnSync(command: string, args?: ReadonlyArray<string>, options?: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns<string>;
|
||||
function spawnSync(command: string, args?: ReadonlyArray<string>, options?: SpawnSyncOptionsWithBufferEncoding): SpawnSyncReturns<Buffer>;
|
||||
function spawnSync(command: string, args?: ReadonlyArray<string>, options?: SpawnSyncOptions): SpawnSyncReturns<Buffer>;
|
||||
|
||||
interface ExecSyncOptions extends CommonOptions {
|
||||
input?: string | Uint8Array;
|
||||
stdio?: StdioOptions;
|
||||
shell?: string;
|
||||
killSignal?: NodeJS.Signals | number;
|
||||
maxBuffer?: number;
|
||||
encoding?: string;
|
||||
}
|
||||
interface ExecSyncOptionsWithStringEncoding extends ExecSyncOptions {
|
||||
encoding: BufferEncoding;
|
||||
}
|
||||
interface ExecSyncOptionsWithBufferEncoding extends ExecSyncOptions {
|
||||
encoding: string; // specify `null`.
|
||||
}
|
||||
function execSync(command: string): Buffer;
|
||||
function execSync(command: string, options?: ExecSyncOptionsWithStringEncoding): string;
|
||||
function execSync(command: string, options?: ExecSyncOptionsWithBufferEncoding): Buffer;
|
||||
function execSync(command: string, options?: ExecSyncOptions): Buffer;
|
||||
|
||||
interface ExecFileSyncOptions extends CommonOptions {
|
||||
input?: string | NodeJS.ArrayBufferView;
|
||||
stdio?: StdioOptions;
|
||||
killSignal?: NodeJS.Signals | number;
|
||||
maxBuffer?: number;
|
||||
encoding?: string;
|
||||
shell?: boolean | string;
|
||||
}
|
||||
interface ExecFileSyncOptionsWithStringEncoding extends ExecFileSyncOptions {
|
||||
encoding: BufferEncoding;
|
||||
}
|
||||
interface ExecFileSyncOptionsWithBufferEncoding extends ExecFileSyncOptions {
|
||||
encoding: string; // specify `null`.
|
||||
}
|
||||
function execFileSync(command: string): Buffer;
|
||||
function execFileSync(command: string, options?: ExecFileSyncOptionsWithStringEncoding): string;
|
||||
function execFileSync(command: string, options?: ExecFileSyncOptionsWithBufferEncoding): Buffer;
|
||||
function execFileSync(command: string, options?: ExecFileSyncOptions): Buffer;
|
||||
function execFileSync(command: string, args?: ReadonlyArray<string>, options?: ExecFileSyncOptionsWithStringEncoding): string;
|
||||
function execFileSync(command: string, args?: ReadonlyArray<string>, options?: ExecFileSyncOptionsWithBufferEncoding): Buffer;
|
||||
function execFileSync(command: string, args?: ReadonlyArray<string>, options?: ExecFileSyncOptions): Buffer;
|
||||
}
|
|
@ -1,262 +0,0 @@
|
|||
declare module "cluster" {
|
||||
import * as child from "child_process";
|
||||
import * as events from "events";
|
||||
import * as net from "net";
|
||||
|
||||
// interfaces
|
||||
interface ClusterSettings {
|
||||
execArgv?: string[]; // default: process.execArgv
|
||||
exec?: string;
|
||||
args?: string[];
|
||||
silent?: boolean;
|
||||
stdio?: any[];
|
||||
uid?: number;
|
||||
gid?: number;
|
||||
inspectPort?: number | (() => number);
|
||||
}
|
||||
|
||||
interface Address {
|
||||
address: string;
|
||||
port: number;
|
||||
addressType: number | "udp4" | "udp6"; // 4, 6, -1, "udp4", "udp6"
|
||||
}
|
||||
|
||||
class Worker extends events.EventEmitter {
|
||||
id: number;
|
||||
process: child.ChildProcess;
|
||||
send(message: child.Serializable, sendHandle?: child.SendHandle, callback?: (error: Error | null) => void): boolean;
|
||||
kill(signal?: string): void;
|
||||
destroy(signal?: string): void;
|
||||
disconnect(): void;
|
||||
isConnected(): boolean;
|
||||
isDead(): boolean;
|
||||
exitedAfterDisconnect: boolean;
|
||||
|
||||
/**
|
||||
* events.EventEmitter
|
||||
* 1. disconnect
|
||||
* 2. error
|
||||
* 3. exit
|
||||
* 4. listening
|
||||
* 5. message
|
||||
* 6. online
|
||||
*/
|
||||
addListener(event: string, listener: (...args: any[]) => void): this;
|
||||
addListener(event: "disconnect", listener: () => void): this;
|
||||
addListener(event: "error", listener: (error: Error) => void): this;
|
||||
addListener(event: "exit", listener: (code: number, signal: string) => void): this;
|
||||
addListener(event: "listening", listener: (address: Address) => void): this;
|
||||
addListener(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
||||
addListener(event: "online", listener: () => void): this;
|
||||
|
||||
emit(event: string | symbol, ...args: any[]): boolean;
|
||||
emit(event: "disconnect"): boolean;
|
||||
emit(event: "error", error: Error): boolean;
|
||||
emit(event: "exit", code: number, signal: string): boolean;
|
||||
emit(event: "listening", address: Address): boolean;
|
||||
emit(event: "message", message: any, handle: net.Socket | net.Server): boolean;
|
||||
emit(event: "online"): boolean;
|
||||
|
||||
on(event: string, listener: (...args: any[]) => void): this;
|
||||
on(event: "disconnect", listener: () => void): this;
|
||||
on(event: "error", listener: (error: Error) => void): this;
|
||||
on(event: "exit", listener: (code: number, signal: string) => void): this;
|
||||
on(event: "listening", listener: (address: Address) => void): this;
|
||||
on(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
||||
on(event: "online", listener: () => void): this;
|
||||
|
||||
once(event: string, listener: (...args: any[]) => void): this;
|
||||
once(event: "disconnect", listener: () => void): this;
|
||||
once(event: "error", listener: (error: Error) => void): this;
|
||||
once(event: "exit", listener: (code: number, signal: string) => void): this;
|
||||
once(event: "listening", listener: (address: Address) => void): this;
|
||||
once(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
||||
once(event: "online", listener: () => void): this;
|
||||
|
||||
prependListener(event: string, listener: (...args: any[]) => void): this;
|
||||
prependListener(event: "disconnect", listener: () => void): this;
|
||||
prependListener(event: "error", listener: (error: Error) => void): this;
|
||||
prependListener(event: "exit", listener: (code: number, signal: string) => void): this;
|
||||
prependListener(event: "listening", listener: (address: Address) => void): this;
|
||||
prependListener(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
||||
prependListener(event: "online", listener: () => void): this;
|
||||
|
||||
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
||||
prependOnceListener(event: "disconnect", listener: () => void): this;
|
||||
prependOnceListener(event: "error", listener: (error: Error) => void): this;
|
||||
prependOnceListener(event: "exit", listener: (code: number, signal: string) => void): this;
|
||||
prependOnceListener(event: "listening", listener: (address: Address) => void): this;
|
||||
prependOnceListener(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
||||
prependOnceListener(event: "online", listener: () => void): this;
|
||||
}
|
||||
|
||||
interface Cluster extends events.EventEmitter {
|
||||
Worker: Worker;
|
||||
disconnect(callback?: () => void): void;
|
||||
fork(env?: any): Worker;
|
||||
isMaster: boolean;
|
||||
isWorker: boolean;
|
||||
schedulingPolicy: number;
|
||||
settings: ClusterSettings;
|
||||
setupMaster(settings?: ClusterSettings): void;
|
||||
worker?: Worker;
|
||||
workers?: NodeJS.Dict<Worker>;
|
||||
|
||||
readonly SCHED_NONE: number;
|
||||
readonly SCHED_RR: number;
|
||||
|
||||
/**
|
||||
* events.EventEmitter
|
||||
* 1. disconnect
|
||||
* 2. exit
|
||||
* 3. fork
|
||||
* 4. listening
|
||||
* 5. message
|
||||
* 6. online
|
||||
* 7. setup
|
||||
*/
|
||||
addListener(event: string, listener: (...args: any[]) => void): this;
|
||||
addListener(event: "disconnect", listener: (worker: Worker) => void): this;
|
||||
addListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this;
|
||||
addListener(event: "fork", listener: (worker: Worker) => void): this;
|
||||
addListener(event: "listening", listener: (worker: Worker, address: Address) => void): this;
|
||||
addListener(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
||||
addListener(event: "online", listener: (worker: Worker) => void): this;
|
||||
addListener(event: "setup", listener: (settings: ClusterSettings) => void): this;
|
||||
|
||||
emit(event: string | symbol, ...args: any[]): boolean;
|
||||
emit(event: "disconnect", worker: Worker): boolean;
|
||||
emit(event: "exit", worker: Worker, code: number, signal: string): boolean;
|
||||
emit(event: "fork", worker: Worker): boolean;
|
||||
emit(event: "listening", worker: Worker, address: Address): boolean;
|
||||
emit(event: "message", worker: Worker, message: any, handle: net.Socket | net.Server): boolean;
|
||||
emit(event: "online", worker: Worker): boolean;
|
||||
emit(event: "setup", settings: ClusterSettings): boolean;
|
||||
|
||||
on(event: string, listener: (...args: any[]) => void): this;
|
||||
on(event: "disconnect", listener: (worker: Worker) => void): this;
|
||||
on(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this;
|
||||
on(event: "fork", listener: (worker: Worker) => void): this;
|
||||
on(event: "listening", listener: (worker: Worker, address: Address) => void): this;
|
||||
on(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
||||
on(event: "online", listener: (worker: Worker) => void): this;
|
||||
on(event: "setup", listener: (settings: ClusterSettings) => void): this;
|
||||
|
||||
once(event: string, listener: (...args: any[]) => void): this;
|
||||
once(event: "disconnect", listener: (worker: Worker) => void): this;
|
||||
once(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this;
|
||||
once(event: "fork", listener: (worker: Worker) => void): this;
|
||||
once(event: "listening", listener: (worker: Worker, address: Address) => void): this;
|
||||
once(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
||||
once(event: "online", listener: (worker: Worker) => void): this;
|
||||
once(event: "setup", listener: (settings: ClusterSettings) => void): this;
|
||||
|
||||
prependListener(event: string, listener: (...args: any[]) => void): this;
|
||||
prependListener(event: "disconnect", listener: (worker: Worker) => void): this;
|
||||
prependListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this;
|
||||
prependListener(event: "fork", listener: (worker: Worker) => void): this;
|
||||
prependListener(event: "listening", listener: (worker: Worker, address: Address) => void): this;
|
||||
prependListener(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
||||
prependListener(event: "online", listener: (worker: Worker) => void): this;
|
||||
prependListener(event: "setup", listener: (settings: ClusterSettings) => void): this;
|
||||
|
||||
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
||||
prependOnceListener(event: "disconnect", listener: (worker: Worker) => void): this;
|
||||
prependOnceListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this;
|
||||
prependOnceListener(event: "fork", listener: (worker: Worker) => void): this;
|
||||
prependOnceListener(event: "listening", listener: (worker: Worker, address: Address) => void): this;
|
||||
// the handle is a net.Socket or net.Server object, or undefined.
|
||||
prependOnceListener(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): this;
|
||||
prependOnceListener(event: "online", listener: (worker: Worker) => void): this;
|
||||
prependOnceListener(event: "setup", listener: (settings: ClusterSettings) => void): this;
|
||||
}
|
||||
|
||||
const SCHED_NONE: number;
|
||||
const SCHED_RR: number;
|
||||
|
||||
function disconnect(callback?: () => void): void;
|
||||
function fork(env?: any): Worker;
|
||||
const isMaster: boolean;
|
||||
const isWorker: boolean;
|
||||
let schedulingPolicy: number;
|
||||
const settings: ClusterSettings;
|
||||
function setupMaster(settings?: ClusterSettings): void;
|
||||
const worker: Worker;
|
||||
const workers: NodeJS.Dict<Worker>;
|
||||
|
||||
/**
|
||||