badmfck-api-server 1.0.7 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -51,8 +51,8 @@ class APIService extends BaseService_1.BaseService {
51
51
  this.options = options ?? getDefaultOptions();
52
52
  }
53
53
  async init() {
54
- exports.REQ_HTTP_LOG.listener = (ignore, cb) => { cb(this.netLog); };
55
- exports.REQ_CREATE_NET_LOG.listener = (ignore, cb) => {
54
+ exports.REQ_HTTP_LOG.listener = async (ignore) => this.netLog;
55
+ exports.REQ_CREATE_NET_LOG.listener = async (ignore) => {
56
56
  const log = {
57
57
  created: +new Date(),
58
58
  time: 0,
@@ -64,7 +64,7 @@ class APIService extends BaseService_1.BaseService {
64
64
  this.netLog.push(log);
65
65
  if (this.netLog.length > 1000)
66
66
  this.netLog.shift();
67
- cb(log);
67
+ return log;
68
68
  };
69
69
  const app = (0, express_1.default)();
70
70
  if (this.options.isProductionEnvironment)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "1.0.7",
3
+ "version": "1.1.0",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,7 +20,7 @@
20
20
  "dependencies": {
21
21
  "@types/mysql": "^2.15.21",
22
22
  "axios": "^1.4.0",
23
- "badmfck-signal": "^1.0.1",
23
+ "badmfck-signal": "^1.2.6",
24
24
  "cors": "^2.8.5",
25
25
  "express": "^4.18.2",
26
26
  "mysql": "^2.18.1"
@@ -1,28 +0,0 @@
1
- declare class Signal<T> {
2
- static nextID: number;
3
- private busy;
4
- private tempAdd;
5
- private tempRem;
6
- private tempInvoke;
7
- private callbacks;
8
- private tempClear;
9
- constructor(name?: string);
10
- add(callback: (data: T) => void, id?: string): string;
11
- clear(): void;
12
- remove(callback?: (data: T) => void, id?: string): string | undefined;
13
- invoke(data: T): void;
14
- }
15
- export declare class SignalHandler {
16
- static nextID: number;
17
- private id;
18
- private signals;
19
- constructor();
20
- add<T>(signal: Signal<T>, cb: (data: T) => void): void;
21
- clear(): void;
22
- }
23
- export declare class SyncSignal<T, K> {
24
- private worker?;
25
- request(data: T): Promise<K>;
26
- set listener(_listener: (request: T, response: (data: K) => void) => void);
27
- }
28
- export default Signal;
@@ -1,140 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SyncSignal = exports.SignalHandler = void 0;
4
- class Signal {
5
- static nextID = 0;
6
- busy = false;
7
- tempAdd = [];
8
- tempRem = [];
9
- tempInvoke = [];
10
- callbacks = [];
11
- tempClear = false;
12
- constructor(name) { }
13
- add(callback, id) {
14
- if (!id)
15
- id = "" + (Signal.nextID++);
16
- if (this.busy) {
17
- for (let i of this.tempAdd) {
18
- if (i.cb === callback)
19
- return i.id;
20
- }
21
- this.tempAdd.push({ cb: callback, id: id });
22
- return id;
23
- }
24
- for (let i of this.callbacks) {
25
- if (i.cb === callback)
26
- return i.id;
27
- }
28
- this.callbacks.push({ cb: callback, id: id });
29
- return id;
30
- }
31
- clear() {
32
- if (this.busy) {
33
- this.tempClear = true;
34
- return;
35
- }
36
- this.callbacks = [];
37
- }
38
- remove(callback, id) {
39
- if (!callback && !id)
40
- return;
41
- if (this.busy) {
42
- for (let i of this.tempRem) {
43
- if (callback) {
44
- if (i.cb === callback)
45
- return;
46
- }
47
- if (id) {
48
- if (i.id === id)
49
- return;
50
- }
51
- }
52
- this.tempRem.push({ cb: callback, id: id });
53
- return id;
54
- }
55
- for (let i = 0; i < this.callbacks.length; i++) {
56
- const itm = this.callbacks[i];
57
- let remove = false;
58
- if (callback)
59
- remove = itm.cb === callback;
60
- if (id)
61
- remove = remove || itm.id === id;
62
- if (remove) {
63
- this.callbacks.splice(i, 1);
64
- i--;
65
- }
66
- }
67
- }
68
- invoke(data) {
69
- if (this.busy) {
70
- this.tempInvoke.push({ data: data });
71
- return;
72
- }
73
- this.busy = true;
74
- for (let i of this.callbacks) {
75
- if (i && i.cb && typeof i.cb === "function") {
76
- i.cb(data);
77
- }
78
- }
79
- this.busy = false;
80
- for (let i of this.tempAdd) {
81
- this.add(i.cb, i.id);
82
- }
83
- this.tempAdd = [];
84
- for (let i of this.tempRem) {
85
- this.remove(i.cb, i.id);
86
- }
87
- this.tempRem = [];
88
- for (let i of this.tempInvoke) {
89
- this.invoke(i.data);
90
- }
91
- if (this.tempClear)
92
- this.clear();
93
- }
94
- }
95
- class SignalHandler {
96
- static nextID = 0;
97
- id;
98
- signals = [];
99
- constructor() {
100
- this.id = SignalHandler.nextID++;
101
- }
102
- add(signal, cb) {
103
- let added = false;
104
- for (let i of this.signals) {
105
- if (i === signal) {
106
- added = true;
107
- break;
108
- }
109
- }
110
- if (!added)
111
- this.signals.push(signal);
112
- signal.add(cb, "signaller_" + this.id);
113
- }
114
- clear() {
115
- for (let i of this.signals)
116
- i.remove(undefined, "signaller_" + this.id);
117
- this.signals = [];
118
- }
119
- }
120
- exports.SignalHandler = SignalHandler;
121
- class SyncSignal {
122
- worker;
123
- request(data) {
124
- const executor = (resolve, reject) => {
125
- if (!this.worker) {
126
- console.error("No worker registered in SyncSignal");
127
- reject("No worker registered in SyncSignal");
128
- return;
129
- }
130
- this.worker(data, resolve);
131
- };
132
- const promise = new Promise(executor);
133
- return promise;
134
- }
135
- set listener(_listener) {
136
- this.worker = _listener;
137
- }
138
- }
139
- exports.SyncSignal = SyncSignal;
140
- exports.default = Signal;