first commit

This commit is contained in:
2024-01-19 11:09:11 +01:00
commit b18af7a943
29473 changed files with 4500547 additions and 0 deletions

12
node_modules/eventemitter-asyncresource/.taprc generated vendored Normal file
View File

@@ -0,0 +1,12 @@
check-coverage: true
color: true
coverage: true
coverage-report:
- html
- text
no-browser: true
test-env: TS_NODE_PROJECT=test/tsconfig.json
test-ignore: $.
test-regex: ((\/|^)(tests?|__tests?__)\/.*|\.(tests?|spec)|^\/?tests?)\.([mc]js|[jt]sx?)$
timeout: 30
ts: true

21
node_modules/eventemitter-asyncresource/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2020 Anna Henningsen
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.

25
node_modules/eventemitter-asyncresource/README.md generated vendored Normal file
View File

@@ -0,0 +1,25 @@
# eventemitter-asyncresource - AsyncResource integration for EventEmitter
Integrates [`EventEmitter`][] with [`AsyncResource`][] for `EventEmitter`s that
require manual async tracking.
```js
const { EventEmitterAsyncResource } = require('eventemitter-asyncresource');
// Async tracking tooling will identify this as 'Q'.
const ee = new EventEmitterAsyncResource({ name: 'Q' });
// 'foo' listeners will run in this EventEmitters async context.P
ee.emit('foo');
```
The `EventEmitterAsyncResource` class has the same methods and takes the same
options as `EventEmitter` and `AsyncResource` themselves.
It provides an `.asyncResource` property that allows accessing the async
resource in question, which in turn provides the original `EventEmitter` via
`.eventEmitter`, i.e. in the above example
`ee.asyncResource.eventEmitter === ee`.
[`EventEmitter`]: https://nodejs.org/api/events.html#events_class_eventemitter
[`AsyncResource`]: https://nodejs.org/api/async_hooks.html#async_hooks_class_asyncresource

View File

@@ -0,0 +1,4 @@
import mod from "./src/index.js";
export default mod;
export const EventEmitterAsyncResource = mod.EventEmitterAsyncResource;

View File

@@ -0,0 +1,30 @@
/// <reference types="node" />
import { EventEmitter } from 'events';
import { AsyncResource } from 'async_hooks';
declare const kEventEmitter: unique symbol;
declare const kAsyncResource: unique symbol;
declare type EventEmitterOptions = typeof EventEmitter extends {
new (options?: infer T): EventEmitter;
} ? T : never;
declare type AsyncResourceOptions = typeof AsyncResource extends {
new (name: string, options?: infer T): AsyncResource;
} ? T : never;
declare type Options = EventEmitterOptions & AsyncResourceOptions & {
name?: string;
};
declare class EventEmitterReferencingAsyncResource extends AsyncResource {
[kEventEmitter]: EventEmitter;
constructor(ee: EventEmitter, type: string, options?: AsyncResourceOptions);
get eventEmitter(): EventEmitter;
}
declare class EventEmitterAsyncResource extends EventEmitter {
[kAsyncResource]: EventEmitterReferencingAsyncResource;
constructor(options?: Options | string);
emit(event: string | symbol, ...args: any[]): boolean;
emitDestroy(): void;
asyncId(): number;
triggerAsyncId(): number;
get asyncResource(): EventEmitterReferencingAsyncResource;
static get EventEmitterAsyncResource(): typeof EventEmitterAsyncResource;
}
export = EventEmitterAsyncResource;

View File

@@ -0,0 +1,47 @@
"use strict";
const events_1 = require("events");
const async_hooks_1 = require("async_hooks");
const kEventEmitter = Symbol('kEventEmitter');
const kAsyncResource = Symbol('kAsyncResource');
class EventEmitterReferencingAsyncResource extends async_hooks_1.AsyncResource {
constructor(ee, type, options) {
super(type, options);
this[kEventEmitter] = ee;
}
get eventEmitter() {
return this[kEventEmitter];
}
}
class EventEmitterAsyncResource extends events_1.EventEmitter {
constructor(options) {
let name;
if (typeof options === 'string') {
name = options;
options = undefined;
}
else {
name = (options === null || options === void 0 ? void 0 : options.name) || new.target.name;
}
super(options);
this[kAsyncResource] =
new EventEmitterReferencingAsyncResource(this, name, options);
}
emit(event, ...args) {
return this.asyncResource.runInAsyncScope(super.emit, this, event, ...args);
}
emitDestroy() {
this.asyncResource.emitDestroy();
}
asyncId() {
return this.asyncResource.asyncId();
}
triggerAsyncId() {
return this.asyncResource.triggerAsyncId();
}
get asyncResource() {
return this[kAsyncResource];
}
static get EventEmitterAsyncResource() { return EventEmitterAsyncResource; }
}
module.exports = EventEmitterAsyncResource;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,mCAAsC;AACtC,6CAA4C;AAE5C,MAAM,aAAa,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAC9C,MAAM,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAchD,MAAM,oCAAqC,SAAQ,2BAAa;IAG9D,YAAa,EAAgB,EAAE,IAAY,EAAE,OAA8B;QACzE,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACrB,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC;IAC3B,CAAC;IAED,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,aAAa,CAAC,CAAC;IAC7B,CAAC;CACF;AAED,MAAM,yBAA0B,SAAQ,qBAAY;IAGlD,YAAa,OAA0B;QACrC,IAAI,IAAI,CAAC;QACT,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YAC/B,IAAI,GAAG,OAAO,CAAC;YACf,OAAO,GAAG,SAAS,CAAC;SACrB;aAAM;YACL,IAAI,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,KAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;SACzC;QACD,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,cAAc,CAAC;YAClB,IAAI,oCAAoC,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAClE,CAAC;IAED,IAAI,CAAE,KAAsB,EAAE,GAAG,IAAW;QAC1C,OAAO,IAAI,CAAC,aAAa,CAAC,eAAe,CACvC,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC;IACtC,CAAC;IAED,WAAW;QACT,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC;IACnC,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC;IACtC,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,aAAa,CAAC,cAAc,EAAE,CAAC;IAC7C,CAAC;IAED,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,cAAc,CAAC,CAAC;IAC9B,CAAC;IAED,MAAM,KAAK,yBAAyB,KAAM,OAAO,yBAAyB,CAAC,CAAC,CAAC;CAC9E;AAED,iBAAS,yBAAyB,CAAC"}

56
node_modules/eventemitter-asyncresource/package.json generated vendored Normal file
View File

@@ -0,0 +1,56 @@
{
"name": "eventemitter-asyncresource",
"version": "1.0.0",
"description": "AsyncResource integration for EventEmitter",
"main": "./dist/src/index.js",
"exports": {
"import": "./dist/esm-wrapper.mjs",
"require": "./dist/src/index.js"
},
"types": "./dist/src/index.d.ts",
"scripts": {
"build": "tsc && gen-esm-wrapper . dist/esm-wrapper.mjs",
"lint": "standardx \"**/*.{ts,mjs,js,cjs}\" | snazzy",
"test": "npm run lint && npm run build && npm run test-only",
"test-only": "tap",
"prepack": "npm run build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/addaleax/eventemitter-asyncresource"
},
"keywords": [
"EventEmitter",
"AsyncResource",
"async_hooks",
"events"
],
"author": "Anna Henningsen <anna@addaleax.net>",
"license": "MIT",
"devDependencies": {
"@types/node": "^13.13.5",
"@typescript-eslint/eslint-plugin": "^2.28.0",
"@typescript-eslint/parser": "^2.28.0",
"gen-esm-wrapper": "^1.0.0",
"snazzy": "^8.0.0",
"standardx": "^5.0.0",
"tap": "^14.10.7",
"typescript": "^3.8.3"
},
"eslintConfig": {
"rules": {
"semi": [
"error",
"always"
],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error"
}
},
"standardx": {
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint/eslint-plugin"
]
}
}

View File

@@ -0,0 +1 @@
declare module 'hdr-histogram-percentiles-obj';

73
node_modules/eventemitter-asyncresource/src/index.ts generated vendored Normal file
View File

@@ -0,0 +1,73 @@
import { EventEmitter } from 'events';
import { AsyncResource } from 'async_hooks';
const kEventEmitter = Symbol('kEventEmitter');
const kAsyncResource = Symbol('kAsyncResource');
type EventEmitterOptions = typeof EventEmitter extends {
new (options?: infer T) : EventEmitter;
} ? T : never;
type AsyncResourceOptions = typeof AsyncResource extends {
new (name : string, options?: infer T) : AsyncResource;
} ? T : never;
type Options = EventEmitterOptions & AsyncResourceOptions & {
name?: string;
};
class EventEmitterReferencingAsyncResource extends AsyncResource {
[kEventEmitter] : EventEmitter;
constructor (ee: EventEmitter, type: string, options?: AsyncResourceOptions) {
super(type, options);
this[kEventEmitter] = ee;
}
get eventEmitter () : EventEmitter {
return this[kEventEmitter];
}
}
class EventEmitterAsyncResource extends EventEmitter {
[kAsyncResource] : EventEmitterReferencingAsyncResource;
constructor (options?: Options | string) {
let name;
if (typeof options === 'string') {
name = options;
options = undefined;
} else {
name = options?.name || new.target.name;
}
super(options);
this[kAsyncResource] =
new EventEmitterReferencingAsyncResource(this, name, options);
}
emit (event: string | symbol, ...args: any[]) : boolean {
return this.asyncResource.runInAsyncScope(
super.emit, this, event, ...args);
}
emitDestroy () : void {
this.asyncResource.emitDestroy();
}
asyncId () : number {
return this.asyncResource.asyncId();
}
triggerAsyncId () : number {
return this.asyncResource.triggerAsyncId();
}
get asyncResource () : EventEmitterReferencingAsyncResource {
return this[kAsyncResource];
}
static get EventEmitterAsyncResource () { return EventEmitterAsyncResource; }
}
export = EventEmitterAsyncResource;

119
node_modules/eventemitter-asyncresource/test/test.ts generated vendored Normal file
View File

@@ -0,0 +1,119 @@
import EventEmitterAsyncResource from '..';
import { createHook, executionAsyncId, executionAsyncResource } from 'async_hooks';
import { test } from 'tap';
import { promisify } from 'util';
const tick = promisify(setImmediate);
interface InitAsyncEvent {
name : 'init',
type : string,
triggerAsyncId : number,
resource: object
}
interface OtherAsyncEvent {
name : 'before' | 'after' | 'destroy'
}
type AsyncEvent = InitAsyncEvent | OtherAsyncEvent;
function makeHook (trackedTypes : string[]) {
const eventMap = new Map<number, AsyncEvent[]>();
function log (asyncId : number, name : 'before' | 'after' | 'destroy') {
const entry = eventMap.get(asyncId);
if (entry !== undefined) entry.push({ name });
}
const hook = createHook({
init (asyncId, type, triggerAsyncId, resource) {
if (trackedTypes.includes(type)) {
eventMap.set(asyncId, [
{ name: 'init', type, triggerAsyncId, resource }
]);
}
},
before (asyncId) { log(asyncId, 'before'); },
after (asyncId) { log(asyncId, 'after'); },
destroy (asyncId) { log(asyncId, 'destroy'); }
}).enable();
return {
done () {
hook.disable();
return new Set(eventMap.values());
},
ids () {
return new Set(eventMap.keys());
}
};
}
test('tracks emit() calls correctly using async_hooks', async ({ is, isDeep }) => {
const tracer = makeHook(['Foo']);
class Foo extends EventEmitterAsyncResource {}
const origExecutionAsyncId = executionAsyncId();
const foo = new Foo();
let called = false;
foo.on('someEvent', () => {
if (typeof executionAsyncResource === 'function') { // Node.js 12+ only
is(executionAsyncResource(), foo.asyncResource);
}
called = true;
});
foo.emit('someEvent');
is(called, true);
isDeep([foo.asyncId()], [...tracer.ids()]);
is(foo.triggerAsyncId(), origExecutionAsyncId);
is(foo.asyncResource.eventEmitter, foo);
foo.emitDestroy();
await tick();
isDeep(tracer.done(), new Set<AsyncEvent[]>([
[
{ name: 'init', type: 'Foo', triggerAsyncId: origExecutionAsyncId, resource: foo.asyncResource },
{ name: 'before' },
{ name: 'after' },
{ name: 'destroy' }
]
]));
});
test('can explicitly specify name as positional arg', async ({ isDeep }) => {
const tracer = makeHook(['ResourceName']);
const origExecutionAsyncId = executionAsyncId();
class Foo extends EventEmitterAsyncResource {}
const foo = new Foo('ResourceName');
isDeep(tracer.done(), new Set<AsyncEvent[]>([
[
{ name: 'init', type: 'ResourceName', triggerAsyncId: origExecutionAsyncId, resource: foo.asyncResource }
]
]));
});
test('can explicitly specify name as option', async ({ isDeep }) => {
const tracer = makeHook(['ResourceName']);
const origExecutionAsyncId = executionAsyncId();
class Foo extends EventEmitterAsyncResource {}
const foo = new Foo({ name: 'ResourceName' });
isDeep(tracer.done(), new Set<AsyncEvent[]>([
[
{ name: 'init', type: 'ResourceName', triggerAsyncId: origExecutionAsyncId, resource: foo.asyncResource }
]
]));
});
test('is provided as export on itself', async ({ is }) => {
is(EventEmitterAsyncResource.EventEmitterAsyncResource, EventEmitterAsyncResource);
});

View File

@@ -0,0 +1,10 @@
{
"extends": "../tsconfig",
"compilerOptions": {
"strict": false,
"noImplicitAny": false
},
"include": [
"./**/*.ts"
]
}

24
node_modules/eventemitter-asyncresource/tsconfig.json generated vendored Normal file
View File

@@ -0,0 +1,24 @@
{
"compilerOptions": {
"target": "es2018",
"module": "commonjs",
"moduleResolution": "node",
"lib": ["es2018"],
"outDir": "dist",
"rootDir": ".",
"declaration": true,
"sourceMap": true,
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"esModuleInterop": true,
"resolveJsonModule": true, /* Include modules imported with '.json' extension */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
},
"include": ["src"],
}