@nocobase/plugin-multi-app-manager 2.1.0-alpha.1 → 2.1.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -661
- package/README.md +79 -10
- package/dist/client/Migrate.d.ts +10 -0
- package/dist/client/e9551d3b66931c0a.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/externalVersion.js +7 -7
- package/dist/locale/en-US.json +3 -2
- package/dist/locale/zh-CN.json +3 -2
- package/dist/node_modules/p-queue/dist/index.d.ts +101 -0
- package/dist/node_modules/p-queue/dist/index.js +1 -0
- package/dist/node_modules/p-queue/dist/lower-bound.d.ts +1 -0
- package/dist/node_modules/p-queue/dist/lower-bound.js +21 -0
- package/dist/node_modules/p-queue/dist/options.d.ts +64 -0
- package/dist/node_modules/p-queue/dist/options.js +2 -0
- package/dist/node_modules/p-queue/dist/priority-queue.d.ts +12 -0
- package/dist/node_modules/p-queue/dist/priority-queue.js +32 -0
- package/dist/node_modules/p-queue/dist/queue.d.ts +7 -0
- package/dist/node_modules/p-queue/dist/queue.js +2 -0
- package/dist/node_modules/p-queue/license +9 -0
- package/dist/node_modules/p-queue/node_modules/eventemitter3/index.d.ts +134 -0
- package/dist/node_modules/p-queue/node_modules/eventemitter3/index.js +336 -0
- package/dist/node_modules/p-queue/node_modules/eventemitter3/package.json +56 -0
- package/dist/node_modules/p-queue/node_modules/eventemitter3/umd/eventemitter3.js +340 -0
- package/dist/node_modules/p-queue/node_modules/eventemitter3/umd/eventemitter3.min.js +1 -0
- package/dist/node_modules/p-queue/package.json +1 -0
- package/dist/server/adapters/legacy-adapter.d.ts +43 -0
- package/dist/server/adapters/legacy-adapter.js +207 -0
- package/dist/server/server.d.ts +4 -6
- package/dist/server/server.js +38 -191
- package/package.json +3 -3
- package/dist/client/db3a142b120d6553.js +0 -10
- package/dist/node_modules/mariadb/LICENSE +0 -502
- package/dist/node_modules/mariadb/callback.js +0 -41
- package/dist/node_modules/mariadb/lib/cmd/batch-bulk.js +0 -278
- package/dist/node_modules/mariadb/lib/cmd/batch-rewrite.js +0 -372
- package/dist/node_modules/mariadb/lib/cmd/change-user.js +0 -149
- package/dist/node_modules/mariadb/lib/cmd/class/ok-packet.js +0 -17
- package/dist/node_modules/mariadb/lib/cmd/column-definition.js +0 -102
- package/dist/node_modules/mariadb/lib/cmd/command.js +0 -168
- package/dist/node_modules/mariadb/lib/cmd/common-binary-cmd.js +0 -327
- package/dist/node_modules/mariadb/lib/cmd/common-text-cmd.js +0 -427
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/caching-sha2-password-auth.js +0 -168
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/clear-password-auth.js +0 -23
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/ed25519-password-auth.js +0 -761
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/native-password-auth.js +0 -55
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/pam-password-auth.js +0 -58
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/plugin-auth.js +0 -19
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/sha256-password-auth.js +0 -142
- package/dist/node_modules/mariadb/lib/cmd/handshake/client-capabilities.js +0 -74
- package/dist/node_modules/mariadb/lib/cmd/handshake/client-handshake-response.js +0 -126
- package/dist/node_modules/mariadb/lib/cmd/handshake/handshake.js +0 -292
- package/dist/node_modules/mariadb/lib/cmd/handshake/initial-handshake.js +0 -74
- package/dist/node_modules/mariadb/lib/cmd/handshake/ssl-request.js +0 -29
- package/dist/node_modules/mariadb/lib/cmd/ping.js +0 -52
- package/dist/node_modules/mariadb/lib/cmd/query.js +0 -255
- package/dist/node_modules/mariadb/lib/cmd/quit.js +0 -28
- package/dist/node_modules/mariadb/lib/cmd/reset.js +0 -54
- package/dist/node_modules/mariadb/lib/cmd/resultset.js +0 -607
- package/dist/node_modules/mariadb/lib/cmd/stream.js +0 -45
- package/dist/node_modules/mariadb/lib/config/connection-options.js +0 -258
- package/dist/node_modules/mariadb/lib/config/pool-cluster-options.js +0 -19
- package/dist/node_modules/mariadb/lib/config/pool-options.js +0 -47
- package/dist/node_modules/mariadb/lib/connection-callback.js +0 -160
- package/dist/node_modules/mariadb/lib/connection.js +0 -1460
- package/dist/node_modules/mariadb/lib/const/capabilities.js +0 -64
- package/dist/node_modules/mariadb/lib/const/collations.js +0 -473
- package/dist/node_modules/mariadb/lib/const/connection_status.js +0 -13
- package/dist/node_modules/mariadb/lib/const/error-code.js +0 -1282
- package/dist/node_modules/mariadb/lib/const/field-detail.js +0 -35
- package/dist/node_modules/mariadb/lib/const/field-type.js +0 -71
- package/dist/node_modules/mariadb/lib/const/server-status.js +0 -30
- package/dist/node_modules/mariadb/lib/const/state-change.js +0 -12
- package/dist/node_modules/mariadb/lib/filtered-pool-cluster.js +0 -81
- package/dist/node_modules/mariadb/lib/io/bulk-packet.js +0 -590
- package/dist/node_modules/mariadb/lib/io/compression-input-stream.js +0 -141
- package/dist/node_modules/mariadb/lib/io/compression-output-stream.js +0 -171
- package/dist/node_modules/mariadb/lib/io/packet-input-stream.js +0 -193
- package/dist/node_modules/mariadb/lib/io/packet-node-encoded.js +0 -36
- package/dist/node_modules/mariadb/lib/io/packet-node-iconv.js +0 -37
- package/dist/node_modules/mariadb/lib/io/packet-output-stream.js +0 -502
- package/dist/node_modules/mariadb/lib/io/packet.js +0 -515
- package/dist/node_modules/mariadb/lib/io/rewrite-packet.js +0 -481
- package/dist/node_modules/mariadb/lib/misc/connection-information.js +0 -96
- package/dist/node_modules/mariadb/lib/misc/errors.js +0 -123
- package/dist/node_modules/mariadb/lib/misc/parse.js +0 -1033
- package/dist/node_modules/mariadb/lib/misc/utils.js +0 -298
- package/dist/node_modules/mariadb/lib/pool-base.js +0 -611
- package/dist/node_modules/mariadb/lib/pool-callback.js +0 -202
- package/dist/node_modules/mariadb/lib/pool-cluster-callback.js +0 -66
- package/dist/node_modules/mariadb/lib/pool-cluster.js +0 -407
- package/dist/node_modules/mariadb/lib/pool-promise.js +0 -108
- package/dist/node_modules/mariadb/node_modules/@types/node/assert/strict.d.ts +0 -8
- package/dist/node_modules/mariadb/node_modules/@types/node/assert.d.ts +0 -912
- package/dist/node_modules/mariadb/node_modules/@types/node/async_hooks.d.ts +0 -501
- package/dist/node_modules/mariadb/node_modules/@types/node/buffer.d.ts +0 -2232
- package/dist/node_modules/mariadb/node_modules/@types/node/child_process.d.ts +0 -1366
- package/dist/node_modules/mariadb/node_modules/@types/node/cluster.d.ts +0 -414
- package/dist/node_modules/mariadb/node_modules/@types/node/console.d.ts +0 -412
- package/dist/node_modules/mariadb/node_modules/@types/node/constants.d.ts +0 -18
- package/dist/node_modules/mariadb/node_modules/@types/node/crypto.d.ts +0 -3338
- package/dist/node_modules/mariadb/node_modules/@types/node/dgram.d.ts +0 -545
- package/dist/node_modules/mariadb/node_modules/@types/node/diagnostics_channel.d.ts +0 -152
- package/dist/node_modules/mariadb/node_modules/@types/node/dns/promises.d.ts +0 -370
- package/dist/node_modules/mariadb/node_modules/@types/node/dns.d.ts +0 -659
- package/dist/node_modules/mariadb/node_modules/@types/node/domain.d.ts +0 -169
- package/dist/node_modules/mariadb/node_modules/@types/node/events.d.ts +0 -651
- package/dist/node_modules/mariadb/node_modules/@types/node/fs/promises.d.ts +0 -1091
- package/dist/node_modules/mariadb/node_modules/@types/node/fs.d.ts +0 -3869
- package/dist/node_modules/mariadb/node_modules/@types/node/globals.d.ts +0 -294
- package/dist/node_modules/mariadb/node_modules/@types/node/globals.global.d.ts +0 -1
- package/dist/node_modules/mariadb/node_modules/@types/node/http.d.ts +0 -1396
- package/dist/node_modules/mariadb/node_modules/@types/node/http2.d.ts +0 -2101
- package/dist/node_modules/mariadb/node_modules/@types/node/https.d.ts +0 -391
- package/dist/node_modules/mariadb/node_modules/@types/node/index.d.ts +0 -129
- package/dist/node_modules/mariadb/node_modules/@types/node/inspector.d.ts +0 -2744
- package/dist/node_modules/mariadb/node_modules/@types/node/module.d.ts +0 -114
- package/dist/node_modules/mariadb/node_modules/@types/node/net.d.ts +0 -791
- package/dist/node_modules/mariadb/node_modules/@types/node/os.d.ts +0 -455
- package/dist/node_modules/mariadb/node_modules/@types/node/package.json +0 -220
- package/dist/node_modules/mariadb/node_modules/@types/node/path.d.ts +0 -180
- package/dist/node_modules/mariadb/node_modules/@types/node/perf_hooks.d.ts +0 -557
- package/dist/node_modules/mariadb/node_modules/@types/node/process.d.ts +0 -1481
- package/dist/node_modules/mariadb/node_modules/@types/node/punycode.d.ts +0 -117
- package/dist/node_modules/mariadb/node_modules/@types/node/querystring.d.ts +0 -131
- package/dist/node_modules/mariadb/node_modules/@types/node/readline.d.ts +0 -650
- package/dist/node_modules/mariadb/node_modules/@types/node/repl.d.ts +0 -424
- package/dist/node_modules/mariadb/node_modules/@types/node/stream/consumers.d.ts +0 -24
- package/dist/node_modules/mariadb/node_modules/@types/node/stream/promises.d.ts +0 -42
- package/dist/node_modules/mariadb/node_modules/@types/node/stream/web.d.ts +0 -330
- package/dist/node_modules/mariadb/node_modules/@types/node/stream.d.ts +0 -1249
- package/dist/node_modules/mariadb/node_modules/@types/node/string_decoder.d.ts +0 -67
- package/dist/node_modules/mariadb/node_modules/@types/node/timers/promises.d.ts +0 -68
- package/dist/node_modules/mariadb/node_modules/@types/node/timers.d.ts +0 -94
- package/dist/node_modules/mariadb/node_modules/@types/node/tls.d.ts +0 -1020
- package/dist/node_modules/mariadb/node_modules/@types/node/trace_events.d.ts +0 -161
- package/dist/node_modules/mariadb/node_modules/@types/node/tty.d.ts +0 -204
- package/dist/node_modules/mariadb/node_modules/@types/node/url.d.ts +0 -891
- package/dist/node_modules/mariadb/node_modules/@types/node/util.d.ts +0 -1594
- package/dist/node_modules/mariadb/node_modules/@types/node/v8.d.ts +0 -378
- package/dist/node_modules/mariadb/node_modules/@types/node/vm.d.ts +0 -507
- package/dist/node_modules/mariadb/node_modules/@types/node/wasi.d.ts +0 -158
- package/dist/node_modules/mariadb/node_modules/@types/node/worker_threads.d.ts +0 -649
- package/dist/node_modules/mariadb/node_modules/@types/node/zlib.d.ts +0 -517
- package/dist/node_modules/mariadb/package.json +0 -1
- package/dist/node_modules/mariadb/promise.js +0 -34
- package/dist/node_modules/mariadb/types/index.d.ts +0 -870
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Queue, RunFunction } from './queue';
|
|
2
|
+
import { QueueAddOptions } from './options';
|
|
3
|
+
export interface PriorityQueueOptions extends QueueAddOptions {
|
|
4
|
+
priority?: number;
|
|
5
|
+
}
|
|
6
|
+
export default class PriorityQueue implements Queue<RunFunction, PriorityQueueOptions> {
|
|
7
|
+
private readonly _queue;
|
|
8
|
+
enqueue(run: RunFunction, options?: Partial<PriorityQueueOptions>): void;
|
|
9
|
+
dequeue(): RunFunction | undefined;
|
|
10
|
+
filter(options: Readonly<Partial<PriorityQueueOptions>>): RunFunction[];
|
|
11
|
+
get size(): number;
|
|
12
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const lower_bound_1 = require("./lower-bound");
|
|
4
|
+
class PriorityQueue {
|
|
5
|
+
constructor() {
|
|
6
|
+
this._queue = [];
|
|
7
|
+
}
|
|
8
|
+
enqueue(run, options) {
|
|
9
|
+
options = Object.assign({ priority: 0 }, options);
|
|
10
|
+
const element = {
|
|
11
|
+
priority: options.priority,
|
|
12
|
+
run
|
|
13
|
+
};
|
|
14
|
+
if (this.size && this._queue[this.size - 1].priority >= options.priority) {
|
|
15
|
+
this._queue.push(element);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const index = lower_bound_1.default(this._queue, element, (a, b) => b.priority - a.priority);
|
|
19
|
+
this._queue.splice(index, 0, element);
|
|
20
|
+
}
|
|
21
|
+
dequeue() {
|
|
22
|
+
const item = this._queue.shift();
|
|
23
|
+
return item === null || item === void 0 ? void 0 : item.run;
|
|
24
|
+
}
|
|
25
|
+
filter(options) {
|
|
26
|
+
return this._queue.filter((element) => element.priority === options.priority).map((element) => element.run);
|
|
27
|
+
}
|
|
28
|
+
get size() {
|
|
29
|
+
return this._queue.length;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.default = PriorityQueue;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare type RunFunction = () => Promise<unknown>;
|
|
2
|
+
export interface Queue<Element, Options> {
|
|
3
|
+
size: number;
|
|
4
|
+
filter: (options: Partial<Options>) => Element[];
|
|
5
|
+
dequeue: () => Element | undefined;
|
|
6
|
+
enqueue: (run: Element, options?: Partial<Options>) => void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
4
|
+
|
|
5
|
+
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:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
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.
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal `EventEmitter` interface that is molded against the Node.js
|
|
3
|
+
* `EventEmitter` interface.
|
|
4
|
+
*/
|
|
5
|
+
declare class EventEmitter<
|
|
6
|
+
EventTypes extends EventEmitter.ValidEventTypes = string | symbol,
|
|
7
|
+
Context extends any = any
|
|
8
|
+
> {
|
|
9
|
+
static prefixed: string | boolean;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Return an array listing the events for which the emitter has registered
|
|
13
|
+
* listeners.
|
|
14
|
+
*/
|
|
15
|
+
eventNames(): Array<EventEmitter.EventNames<EventTypes>>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Return the listeners registered for a given event.
|
|
19
|
+
*/
|
|
20
|
+
listeners<T extends EventEmitter.EventNames<EventTypes>>(
|
|
21
|
+
event: T
|
|
22
|
+
): Array<EventEmitter.EventListener<EventTypes, T>>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Return the number of listeners listening to a given event.
|
|
26
|
+
*/
|
|
27
|
+
listenerCount(event: EventEmitter.EventNames<EventTypes>): number;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Calls each of the listeners registered for a given event.
|
|
31
|
+
*/
|
|
32
|
+
emit<T extends EventEmitter.EventNames<EventTypes>>(
|
|
33
|
+
event: T,
|
|
34
|
+
...args: EventEmitter.EventArgs<EventTypes, T>
|
|
35
|
+
): boolean;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Add a listener for a given event.
|
|
39
|
+
*/
|
|
40
|
+
on<T extends EventEmitter.EventNames<EventTypes>>(
|
|
41
|
+
event: T,
|
|
42
|
+
fn: EventEmitter.EventListener<EventTypes, T>,
|
|
43
|
+
context?: Context
|
|
44
|
+
): this;
|
|
45
|
+
addListener<T extends EventEmitter.EventNames<EventTypes>>(
|
|
46
|
+
event: T,
|
|
47
|
+
fn: EventEmitter.EventListener<EventTypes, T>,
|
|
48
|
+
context?: Context
|
|
49
|
+
): this;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Add a one-time listener for a given event.
|
|
53
|
+
*/
|
|
54
|
+
once<T extends EventEmitter.EventNames<EventTypes>>(
|
|
55
|
+
event: T,
|
|
56
|
+
fn: EventEmitter.EventListener<EventTypes, T>,
|
|
57
|
+
context?: Context
|
|
58
|
+
): this;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Remove the listeners of a given event.
|
|
62
|
+
*/
|
|
63
|
+
removeListener<T extends EventEmitter.EventNames<EventTypes>>(
|
|
64
|
+
event: T,
|
|
65
|
+
fn?: EventEmitter.EventListener<EventTypes, T>,
|
|
66
|
+
context?: Context,
|
|
67
|
+
once?: boolean
|
|
68
|
+
): this;
|
|
69
|
+
off<T extends EventEmitter.EventNames<EventTypes>>(
|
|
70
|
+
event: T,
|
|
71
|
+
fn?: EventEmitter.EventListener<EventTypes, T>,
|
|
72
|
+
context?: Context,
|
|
73
|
+
once?: boolean
|
|
74
|
+
): this;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Remove all listeners, or those of the specified event.
|
|
78
|
+
*/
|
|
79
|
+
removeAllListeners(event?: EventEmitter.EventNames<EventTypes>): this;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
declare namespace EventEmitter {
|
|
83
|
+
export interface ListenerFn<Args extends any[] = any[]> {
|
|
84
|
+
(...args: Args): void;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface EventEmitterStatic {
|
|
88
|
+
new <
|
|
89
|
+
EventTypes extends ValidEventTypes = string | symbol,
|
|
90
|
+
Context = any
|
|
91
|
+
>(): EventEmitter<EventTypes, Context>;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* `object` should be in either of the following forms:
|
|
96
|
+
* ```
|
|
97
|
+
* interface EventTypes {
|
|
98
|
+
* 'event-with-parameters': any[]
|
|
99
|
+
* 'event-with-example-handler': (...args: any[]) => void
|
|
100
|
+
* }
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export type ValidEventTypes = string | symbol | object;
|
|
104
|
+
|
|
105
|
+
export type EventNames<T extends ValidEventTypes> = T extends string | symbol
|
|
106
|
+
? T
|
|
107
|
+
: keyof T;
|
|
108
|
+
|
|
109
|
+
export type ArgumentMap<T extends object> = {
|
|
110
|
+
[K in keyof T]: T[K] extends (...args: any[]) => void
|
|
111
|
+
? Parameters<T[K]>
|
|
112
|
+
: T[K] extends any[]
|
|
113
|
+
? T[K]
|
|
114
|
+
: any[];
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export type EventListener<
|
|
118
|
+
T extends ValidEventTypes,
|
|
119
|
+
K extends EventNames<T>
|
|
120
|
+
> = T extends string | symbol
|
|
121
|
+
? (...args: any[]) => void
|
|
122
|
+
: (
|
|
123
|
+
...args: ArgumentMap<Exclude<T, string | symbol>>[Extract<K, keyof T>]
|
|
124
|
+
) => void;
|
|
125
|
+
|
|
126
|
+
export type EventArgs<
|
|
127
|
+
T extends ValidEventTypes,
|
|
128
|
+
K extends EventNames<T>
|
|
129
|
+
> = Parameters<EventListener<T, K>>;
|
|
130
|
+
|
|
131
|
+
export const EventEmitter: EventEmitterStatic;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export = EventEmitter;
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var has = Object.prototype.hasOwnProperty
|
|
4
|
+
, prefix = '~';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Constructor to create a storage for our `EE` objects.
|
|
8
|
+
* An `Events` instance is a plain object whose properties are event names.
|
|
9
|
+
*
|
|
10
|
+
* @constructor
|
|
11
|
+
* @private
|
|
12
|
+
*/
|
|
13
|
+
function Events() {}
|
|
14
|
+
|
|
15
|
+
//
|
|
16
|
+
// We try to not inherit from `Object.prototype`. In some engines creating an
|
|
17
|
+
// instance in this way is faster than calling `Object.create(null)` directly.
|
|
18
|
+
// If `Object.create(null)` is not supported we prefix the event names with a
|
|
19
|
+
// character to make sure that the built-in object properties are not
|
|
20
|
+
// overridden or used as an attack vector.
|
|
21
|
+
//
|
|
22
|
+
if (Object.create) {
|
|
23
|
+
Events.prototype = Object.create(null);
|
|
24
|
+
|
|
25
|
+
//
|
|
26
|
+
// This hack is needed because the `__proto__` property is still inherited in
|
|
27
|
+
// some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
|
|
28
|
+
//
|
|
29
|
+
if (!new Events().__proto__) prefix = false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Representation of a single event listener.
|
|
34
|
+
*
|
|
35
|
+
* @param {Function} fn The listener function.
|
|
36
|
+
* @param {*} context The context to invoke the listener with.
|
|
37
|
+
* @param {Boolean} [once=false] Specify if the listener is a one-time listener.
|
|
38
|
+
* @constructor
|
|
39
|
+
* @private
|
|
40
|
+
*/
|
|
41
|
+
function EE(fn, context, once) {
|
|
42
|
+
this.fn = fn;
|
|
43
|
+
this.context = context;
|
|
44
|
+
this.once = once || false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Add a listener for a given event.
|
|
49
|
+
*
|
|
50
|
+
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
51
|
+
* @param {(String|Symbol)} event The event name.
|
|
52
|
+
* @param {Function} fn The listener function.
|
|
53
|
+
* @param {*} context The context to invoke the listener with.
|
|
54
|
+
* @param {Boolean} once Specify if the listener is a one-time listener.
|
|
55
|
+
* @returns {EventEmitter}
|
|
56
|
+
* @private
|
|
57
|
+
*/
|
|
58
|
+
function addListener(emitter, event, fn, context, once) {
|
|
59
|
+
if (typeof fn !== 'function') {
|
|
60
|
+
throw new TypeError('The listener must be a function');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
var listener = new EE(fn, context || emitter, once)
|
|
64
|
+
, evt = prefix ? prefix + event : event;
|
|
65
|
+
|
|
66
|
+
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
|
|
67
|
+
else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
|
|
68
|
+
else emitter._events[evt] = [emitter._events[evt], listener];
|
|
69
|
+
|
|
70
|
+
return emitter;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Clear event by name.
|
|
75
|
+
*
|
|
76
|
+
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
77
|
+
* @param {(String|Symbol)} evt The Event name.
|
|
78
|
+
* @private
|
|
79
|
+
*/
|
|
80
|
+
function clearEvent(emitter, evt) {
|
|
81
|
+
if (--emitter._eventsCount === 0) emitter._events = new Events();
|
|
82
|
+
else delete emitter._events[evt];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Minimal `EventEmitter` interface that is molded against the Node.js
|
|
87
|
+
* `EventEmitter` interface.
|
|
88
|
+
*
|
|
89
|
+
* @constructor
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
92
|
+
function EventEmitter() {
|
|
93
|
+
this._events = new Events();
|
|
94
|
+
this._eventsCount = 0;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Return an array listing the events for which the emitter has registered
|
|
99
|
+
* listeners.
|
|
100
|
+
*
|
|
101
|
+
* @returns {Array}
|
|
102
|
+
* @public
|
|
103
|
+
*/
|
|
104
|
+
EventEmitter.prototype.eventNames = function eventNames() {
|
|
105
|
+
var names = []
|
|
106
|
+
, events
|
|
107
|
+
, name;
|
|
108
|
+
|
|
109
|
+
if (this._eventsCount === 0) return names;
|
|
110
|
+
|
|
111
|
+
for (name in (events = this._events)) {
|
|
112
|
+
if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (Object.getOwnPropertySymbols) {
|
|
116
|
+
return names.concat(Object.getOwnPropertySymbols(events));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return names;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Return the listeners registered for a given event.
|
|
124
|
+
*
|
|
125
|
+
* @param {(String|Symbol)} event The event name.
|
|
126
|
+
* @returns {Array} The registered listeners.
|
|
127
|
+
* @public
|
|
128
|
+
*/
|
|
129
|
+
EventEmitter.prototype.listeners = function listeners(event) {
|
|
130
|
+
var evt = prefix ? prefix + event : event
|
|
131
|
+
, handlers = this._events[evt];
|
|
132
|
+
|
|
133
|
+
if (!handlers) return [];
|
|
134
|
+
if (handlers.fn) return [handlers.fn];
|
|
135
|
+
|
|
136
|
+
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
|
|
137
|
+
ee[i] = handlers[i].fn;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return ee;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Return the number of listeners listening to a given event.
|
|
145
|
+
*
|
|
146
|
+
* @param {(String|Symbol)} event The event name.
|
|
147
|
+
* @returns {Number} The number of listeners.
|
|
148
|
+
* @public
|
|
149
|
+
*/
|
|
150
|
+
EventEmitter.prototype.listenerCount = function listenerCount(event) {
|
|
151
|
+
var evt = prefix ? prefix + event : event
|
|
152
|
+
, listeners = this._events[evt];
|
|
153
|
+
|
|
154
|
+
if (!listeners) return 0;
|
|
155
|
+
if (listeners.fn) return 1;
|
|
156
|
+
return listeners.length;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Calls each of the listeners registered for a given event.
|
|
161
|
+
*
|
|
162
|
+
* @param {(String|Symbol)} event The event name.
|
|
163
|
+
* @returns {Boolean} `true` if the event had listeners, else `false`.
|
|
164
|
+
* @public
|
|
165
|
+
*/
|
|
166
|
+
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
167
|
+
var evt = prefix ? prefix + event : event;
|
|
168
|
+
|
|
169
|
+
if (!this._events[evt]) return false;
|
|
170
|
+
|
|
171
|
+
var listeners = this._events[evt]
|
|
172
|
+
, len = arguments.length
|
|
173
|
+
, args
|
|
174
|
+
, i;
|
|
175
|
+
|
|
176
|
+
if (listeners.fn) {
|
|
177
|
+
if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
|
|
178
|
+
|
|
179
|
+
switch (len) {
|
|
180
|
+
case 1: return listeners.fn.call(listeners.context), true;
|
|
181
|
+
case 2: return listeners.fn.call(listeners.context, a1), true;
|
|
182
|
+
case 3: return listeners.fn.call(listeners.context, a1, a2), true;
|
|
183
|
+
case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
|
184
|
+
case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
|
185
|
+
case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
for (i = 1, args = new Array(len -1); i < len; i++) {
|
|
189
|
+
args[i - 1] = arguments[i];
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
listeners.fn.apply(listeners.context, args);
|
|
193
|
+
} else {
|
|
194
|
+
var length = listeners.length
|
|
195
|
+
, j;
|
|
196
|
+
|
|
197
|
+
for (i = 0; i < length; i++) {
|
|
198
|
+
if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
|
|
199
|
+
|
|
200
|
+
switch (len) {
|
|
201
|
+
case 1: listeners[i].fn.call(listeners[i].context); break;
|
|
202
|
+
case 2: listeners[i].fn.call(listeners[i].context, a1); break;
|
|
203
|
+
case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
|
|
204
|
+
case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
|
|
205
|
+
default:
|
|
206
|
+
if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {
|
|
207
|
+
args[j - 1] = arguments[j];
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
listeners[i].fn.apply(listeners[i].context, args);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return true;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Add a listener for a given event.
|
|
220
|
+
*
|
|
221
|
+
* @param {(String|Symbol)} event The event name.
|
|
222
|
+
* @param {Function} fn The listener function.
|
|
223
|
+
* @param {*} [context=this] The context to invoke the listener with.
|
|
224
|
+
* @returns {EventEmitter} `this`.
|
|
225
|
+
* @public
|
|
226
|
+
*/
|
|
227
|
+
EventEmitter.prototype.on = function on(event, fn, context) {
|
|
228
|
+
return addListener(this, event, fn, context, false);
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Add a one-time listener for a given event.
|
|
233
|
+
*
|
|
234
|
+
* @param {(String|Symbol)} event The event name.
|
|
235
|
+
* @param {Function} fn The listener function.
|
|
236
|
+
* @param {*} [context=this] The context to invoke the listener with.
|
|
237
|
+
* @returns {EventEmitter} `this`.
|
|
238
|
+
* @public
|
|
239
|
+
*/
|
|
240
|
+
EventEmitter.prototype.once = function once(event, fn, context) {
|
|
241
|
+
return addListener(this, event, fn, context, true);
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Remove the listeners of a given event.
|
|
246
|
+
*
|
|
247
|
+
* @param {(String|Symbol)} event The event name.
|
|
248
|
+
* @param {Function} fn Only remove the listeners that match this function.
|
|
249
|
+
* @param {*} context Only remove the listeners that have this context.
|
|
250
|
+
* @param {Boolean} once Only remove one-time listeners.
|
|
251
|
+
* @returns {EventEmitter} `this`.
|
|
252
|
+
* @public
|
|
253
|
+
*/
|
|
254
|
+
EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
|
|
255
|
+
var evt = prefix ? prefix + event : event;
|
|
256
|
+
|
|
257
|
+
if (!this._events[evt]) return this;
|
|
258
|
+
if (!fn) {
|
|
259
|
+
clearEvent(this, evt);
|
|
260
|
+
return this;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
var listeners = this._events[evt];
|
|
264
|
+
|
|
265
|
+
if (listeners.fn) {
|
|
266
|
+
if (
|
|
267
|
+
listeners.fn === fn &&
|
|
268
|
+
(!once || listeners.once) &&
|
|
269
|
+
(!context || listeners.context === context)
|
|
270
|
+
) {
|
|
271
|
+
clearEvent(this, evt);
|
|
272
|
+
}
|
|
273
|
+
} else {
|
|
274
|
+
for (var i = 0, events = [], length = listeners.length; i < length; i++) {
|
|
275
|
+
if (
|
|
276
|
+
listeners[i].fn !== fn ||
|
|
277
|
+
(once && !listeners[i].once) ||
|
|
278
|
+
(context && listeners[i].context !== context)
|
|
279
|
+
) {
|
|
280
|
+
events.push(listeners[i]);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
//
|
|
285
|
+
// Reset the array, or remove it completely if we have no more listeners.
|
|
286
|
+
//
|
|
287
|
+
if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
|
|
288
|
+
else clearEvent(this, evt);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return this;
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Remove all listeners, or those of the specified event.
|
|
296
|
+
*
|
|
297
|
+
* @param {(String|Symbol)} [event] The event name.
|
|
298
|
+
* @returns {EventEmitter} `this`.
|
|
299
|
+
* @public
|
|
300
|
+
*/
|
|
301
|
+
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
302
|
+
var evt;
|
|
303
|
+
|
|
304
|
+
if (event) {
|
|
305
|
+
evt = prefix ? prefix + event : event;
|
|
306
|
+
if (this._events[evt]) clearEvent(this, evt);
|
|
307
|
+
} else {
|
|
308
|
+
this._events = new Events();
|
|
309
|
+
this._eventsCount = 0;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return this;
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
//
|
|
316
|
+
// Alias methods names because people roll like that.
|
|
317
|
+
//
|
|
318
|
+
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
319
|
+
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
|
|
320
|
+
|
|
321
|
+
//
|
|
322
|
+
// Expose the prefix.
|
|
323
|
+
//
|
|
324
|
+
EventEmitter.prefixed = prefix;
|
|
325
|
+
|
|
326
|
+
//
|
|
327
|
+
// Allow `EventEmitter` to be imported as module namespace.
|
|
328
|
+
//
|
|
329
|
+
EventEmitter.EventEmitter = EventEmitter;
|
|
330
|
+
|
|
331
|
+
//
|
|
332
|
+
// Expose the module.
|
|
333
|
+
//
|
|
334
|
+
if ('undefined' !== typeof module) {
|
|
335
|
+
module.exports = EventEmitter;
|
|
336
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "eventemitter3",
|
|
3
|
+
"version": "4.0.7",
|
|
4
|
+
"description": "EventEmitter3 focuses on performance while maintaining a Node.js AND browser compatible interface.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"typings": "index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"browserify": "rm -rf umd && mkdir umd && browserify index.js -s EventEmitter3 -o umd/eventemitter3.js",
|
|
9
|
+
"minify": "uglifyjs umd/eventemitter3.js --source-map -cm -o umd/eventemitter3.min.js",
|
|
10
|
+
"benchmark": "find benchmarks/run -name '*.js' -exec benchmarks/start.sh {} \\;",
|
|
11
|
+
"test": "nyc --reporter=html --reporter=text mocha test/test.js",
|
|
12
|
+
"prepublishOnly": "npm run browserify && npm run minify",
|
|
13
|
+
"test-browser": "node test/browser.js"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"index.js",
|
|
17
|
+
"index.d.ts",
|
|
18
|
+
"umd"
|
|
19
|
+
],
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git://github.com/primus/eventemitter3.git"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"EventEmitter",
|
|
26
|
+
"EventEmitter2",
|
|
27
|
+
"EventEmitter3",
|
|
28
|
+
"Events",
|
|
29
|
+
"addEventListener",
|
|
30
|
+
"addListener",
|
|
31
|
+
"emit",
|
|
32
|
+
"emits",
|
|
33
|
+
"emitter",
|
|
34
|
+
"event",
|
|
35
|
+
"once",
|
|
36
|
+
"pub/sub",
|
|
37
|
+
"publish",
|
|
38
|
+
"reactor",
|
|
39
|
+
"subscribe"
|
|
40
|
+
],
|
|
41
|
+
"author": "Arnout Kazemier",
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/primus/eventemitter3/issues"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"assume": "^2.2.0",
|
|
48
|
+
"browserify": "^16.5.0",
|
|
49
|
+
"mocha": "^8.0.1",
|
|
50
|
+
"nyc": "^15.1.0",
|
|
51
|
+
"pre-commit": "^1.2.0",
|
|
52
|
+
"sauce-browsers": "^2.0.0",
|
|
53
|
+
"sauce-test": "^1.3.3",
|
|
54
|
+
"uglify-js": "^3.9.0"
|
|
55
|
+
}
|
|
56
|
+
}
|