badmfck-api-server 1.0.9 → 1.1.1

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.
@@ -1,5 +1,7 @@
1
1
  import { FieldInfo, MysqlError, Pool, PoolConnection } from "mysql";
2
2
  import { BaseService } from "./BaseService";
3
+ import { Req } from "badmfck-signal";
4
+ export declare const REQ_MYSQL_QUERY: Req<MySqlQuery | MySqlQuery[], MysqlResult[]>;
3
5
  export interface MysqlServiceOptions {
4
6
  connectionLimit: number;
5
7
  host: string;
@@ -3,11 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.MysqlService = void 0;
6
+ exports.MysqlService = exports.REQ_MYSQL_QUERY = void 0;
7
7
  const mysql_1 = __importDefault(require("mysql"));
8
8
  const BaseService_1 = require("./BaseService");
9
9
  const badmfck_signal_1 = require("badmfck-signal");
10
- const REQ_MYSQL_QUERY = new badmfck_signal_1.Req();
10
+ exports.REQ_MYSQL_QUERY = new badmfck_signal_1.Req();
11
11
  class MysqlService extends BaseService_1.BaseService {
12
12
  reconnectionTimeout = 1000 * 3;
13
13
  reconnecting = false;
@@ -25,7 +25,7 @@ class MysqlService extends BaseService_1.BaseService {
25
25
  if (this.options.onLog)
26
26
  this.options.onLog(2, "Mysql server not connected");
27
27
  }
28
- REQ_MYSQL_QUERY.listener = async (data) => {
28
+ exports.REQ_MYSQL_QUERY.listener = async (data) => {
29
29
  if (!Array.isArray(data))
30
30
  data = [data];
31
31
  const promises = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "1.0.9",
3
+ "version": "1.1.1",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -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;