badmfck-api-server 1.4.4 → 1.4.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,10 +21,10 @@ function getDefaultOptions() {
21
21
  endpoints: [],
22
22
  jsonLimit: "10mb",
23
23
  onNetworkLog: function (log) {
24
- (0, LogService_1.logInfo)("${ApiService.js}", log);
24
+ (0, LogService_1.logInfo)("${APIService.js}", log);
25
25
  },
26
26
  onError: function (err) {
27
- (0, LogService_1.logError)("${ApiService.js}", err);
27
+ (0, LogService_1.logError)("${APIService.js}", err);
28
28
  },
29
29
  isProductionEnvironment: false
30
30
  };
@@ -43,7 +43,7 @@ async function Initializer(services) {
43
43
  exports.Initializer = Initializer;
44
44
  class APIService extends BaseService_1.BaseService {
45
45
  static nextLogID = 0;
46
- version = "1.4.4";
46
+ version = "1.4.6";
47
47
  options;
48
48
  netLog = [];
49
49
  constructor(options) {
@@ -177,7 +177,7 @@ class APIService extends BaseService_1.BaseService {
177
177
  }, tme, req.path);
178
178
  });
179
179
  app.listen(this.options.port, () => {
180
- (0, LogService_1.logCrit)('API Service started at: ' + this.options.port + ", with base endpoint:" + this.options.baseEndPoint + ", ver.: " + this.version);
180
+ (0, LogService_1.logCrit)('${APIService.js}', 'API Service started at: ' + this.options.port + ", with base endpoint:" + this.options.baseEndPoint + ", ver.: " + this.version);
181
181
  });
182
182
  }
183
183
  sendResponse(res, data, requestTime, endpoint, log) {
@@ -42,11 +42,11 @@ class BaseEndpoint {
42
42
  }
43
43
  async init() {
44
44
  if (!this.endpoints) {
45
- (0, LogService_1.logInfo)("No endpoints registered for " + this.endpoint);
45
+ (0, LogService_1.logCrit)("${BaseEndpoint.js}", "No endpoints registered for " + this.endpoint);
46
46
  return;
47
47
  }
48
48
  for (let i of this.endpoints)
49
- (0, LogService_1.logInfo)("endpoint: " + i.endpoint + " initalized, ignoreInterceptor: " + (i.ignoreInterceptor ?? "false"));
49
+ (0, LogService_1.logInfo)("${BaseEndpoint.js}", "endpoint: " + i.endpoint + " initalized, ignoreInterceptor: " + (i.ignoreInterceptor ?? "false"));
50
50
  }
51
51
  ;
52
52
  async execute(req) {
@@ -56,6 +56,7 @@ class BaseEndpoint {
56
56
  return i.handler(req);
57
57
  }
58
58
  }
59
+ (0, LogService_1.logWarn)("${BaseEndpoint.js}", "Unhandled entrypoint: " + this.endpoint);
59
60
  return {
60
61
  error: DefaultErrors_1.default.NOT_IMPLEMENTED,
61
62
  data: null
@@ -19,6 +19,7 @@ export interface ILogServiceOptions {
19
19
  output?: (data?: any) => void;
20
20
  stackSize: number;
21
21
  level: LOG_LEVEL;
22
+ textLimit: number;
22
23
  watchFor?: string[];
23
24
  }
24
25
  export declare const getDefaultLogOptions: () => ILogServiceOptions;
@@ -35,6 +36,7 @@ export declare const S_LOG_CHANGE_LEVEL: Signal<LOG_LEVEL>;
35
36
  export declare const S_LOG_FLUSH: Signal<void>;
36
37
  export declare const S_LOG_ADD_SERVICE_TO_WATCH: Signal<string>;
37
38
  export declare const S_LOG_REMOVE_SERVICE_FROM_WATCH: Signal<string>;
39
+ export declare const S_LOG_SET_TEXT_LIMIT: Signal<number>;
38
40
  export declare const REQ_LOG: Req<{
39
41
  lastID: number;
40
42
  } | null | undefined, ILogItem[]>;
@@ -43,13 +45,14 @@ export declare const REQ_LOG_UNIQUE_SERVICES: Req<void, {
43
45
  count: number;
44
46
  }[]>;
45
47
  export declare class LogService extends BaseService {
46
- epoch: number;
48
+ static nextID: number;
47
49
  log: ILogItem[];
48
50
  options: ILogServiceOptions;
49
51
  level: LOG_LEVEL;
50
52
  uniqueServices: Map<string, number>;
51
53
  constructor(opt?: ILogServiceOptions);
52
54
  init(): Promise<void>;
55
+ checkTextLimit(): void;
53
56
  createDate(d?: Date): string;
54
57
  leadZero(num: number): string;
55
58
  createText(data: any): string;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.LogService = exports.REQ_LOG_UNIQUE_SERVICES = exports.REQ_LOG = exports.S_LOG_REMOVE_SERVICE_FROM_WATCH = exports.S_LOG_ADD_SERVICE_TO_WATCH = exports.S_LOG_FLUSH = exports.S_LOG_CHANGE_LEVEL = exports.S_LOG_CREATED = exports.S_LOG = exports.logError = exports.logCrit = exports.logWarn = exports.logInfo = exports.getDefaultLogOptions = exports.LOG_LEVEL = void 0;
26
+ exports.LogService = exports.REQ_LOG_UNIQUE_SERVICES = exports.REQ_LOG = exports.S_LOG_SET_TEXT_LIMIT = exports.S_LOG_REMOVE_SERVICE_FROM_WATCH = exports.S_LOG_ADD_SERVICE_TO_WATCH = exports.S_LOG_FLUSH = exports.S_LOG_CHANGE_LEVEL = exports.S_LOG_CREATED = exports.S_LOG = exports.logError = exports.logCrit = exports.logWarn = exports.logInfo = exports.getDefaultLogOptions = exports.LOG_LEVEL = void 0;
27
27
  const badmfck_signal_1 = __importStar(require("badmfck-signal"));
28
28
  const BaseService_1 = require("./BaseService");
29
29
  var LOG_LEVEL;
@@ -37,6 +37,7 @@ var LOG_LEVEL;
37
37
  const getDefaultLogOptions = () => {
38
38
  return {
39
39
  stackSize: 1000,
40
+ textLimit: 1024,
40
41
  level: LOG_LEVEL.ALL
41
42
  };
42
43
  };
@@ -55,10 +56,11 @@ exports.S_LOG_CHANGE_LEVEL = new badmfck_signal_1.default();
55
56
  exports.S_LOG_FLUSH = new badmfck_signal_1.default();
56
57
  exports.S_LOG_ADD_SERVICE_TO_WATCH = new badmfck_signal_1.default();
57
58
  exports.S_LOG_REMOVE_SERVICE_FROM_WATCH = new badmfck_signal_1.default();
59
+ exports.S_LOG_SET_TEXT_LIMIT = new badmfck_signal_1.default();
58
60
  exports.REQ_LOG = new badmfck_signal_1.Req();
59
61
  exports.REQ_LOG_UNIQUE_SERVICES = new badmfck_signal_1.Req();
60
62
  class LogService extends BaseService_1.BaseService {
61
- epoch = 1699476234961;
63
+ static nextID = 0;
62
64
  log = [];
63
65
  options;
64
66
  level = LOG_LEVEL.ALL;
@@ -69,6 +71,7 @@ class LogService extends BaseService_1.BaseService {
69
71
  opt = (0, exports.getDefaultLogOptions)();
70
72
  this.options = opt;
71
73
  this.level = opt.level;
74
+ this.checkTextLimit();
72
75
  }
73
76
  async init() {
74
77
  exports.REQ_LOG_UNIQUE_SERVICES.listener = async () => {
@@ -85,6 +88,10 @@ class LogService extends BaseService_1.BaseService {
85
88
  else
86
89
  return [...this.log];
87
90
  };
91
+ exports.S_LOG_SET_TEXT_LIMIT.subscribe(l => {
92
+ this.options.textLimit = l;
93
+ this.checkTextLimit();
94
+ });
88
95
  exports.S_LOG_ADD_SERVICE_TO_WATCH.subscribe(service => {
89
96
  if (!this.options.watchFor)
90
97
  this.options.watchFor = [];
@@ -140,7 +147,7 @@ class LogService extends BaseService_1.BaseService {
140
147
  const d = new Date();
141
148
  const logitem = {
142
149
  level: log.level,
143
- id: ((+new Date()) - this.epoch),
150
+ id: LogService.nextID++,
144
151
  text: text,
145
152
  time: d.getTime(),
146
153
  date: this.createDate(d),
@@ -158,6 +165,10 @@ class LogService extends BaseService_1.BaseService {
158
165
  });
159
166
  super.init();
160
167
  }
168
+ checkTextLimit() {
169
+ if (this.options.textLimit > 1024 * 4)
170
+ this.options.textLimit = 1024 * 4;
171
+ }
161
172
  createDate(d) {
162
173
  if (!d)
163
174
  d = new Date();
@@ -202,8 +213,8 @@ class LogService extends BaseService_1.BaseService {
202
213
  else {
203
214
  res = data + "";
204
215
  }
205
- if (res.length > 1024)
206
- res = res.substring(0, 1024) + "... (total: " + res.length + ")";
216
+ if (res.length > this.options.textLimit)
217
+ res = res.substring(0, this.options.textLimit) + "... (total: " + res.length + ")";
207
218
  return res;
208
219
  }
209
220
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "1.4.4",
3
+ "version": "1.4.6",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",