db-crud-api 0.3.15 → 0.3.16

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/index.js CHANGED
@@ -5,16 +5,14 @@ import * as apiFactory from "./lib/api-factory.js";
5
5
 
6
6
  export default function(customSchema, config) {
7
7
  if (customSchema && customSchema.servers) {
8
- schema.servers = customSchema.servers;
8
+ apiFactory.setSchemaServers(customSchema.servers);
9
9
  }
10
10
  if (config) {
11
11
  if (config.log) {
12
- if (config.log.level) {
13
- if (typeof(config.log.level) === 'number') { schema.config.log.level = config.log.level }
14
- else if (typeof(config.log.level) === 'string' && Number.parseInt(config.log.level) != NaN) { schema.config.log.level = Number.parseInt(config.log.level) }
15
- }
16
- if (config.log.callback && typeof(config.log.callback) === 'function') { schema.config.log.callback = config.log.callback }
12
+ if (config.log.level) { apiFactory.setLogLevel(config.log.level) }
13
+ if (config.log.callback) { apiFactory.setLogCallback(config.log.callback) }
14
+ if (config.log.maxAsyncInstance) { apiFactory.setLogMaxAsyncInstances(config.log.maxAsyncInstance) }
17
15
  }
18
16
  }
19
17
  return apiFactory;
20
- }
18
+ }
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ import schema from "./schema.js";
3
4
  import * as dbOpe from "./db-operations.js"
4
5
  import apiFull from "./api-full.js"
5
6
  import apiRO from "./api-ro.js"
@@ -28,4 +29,22 @@ export function closeAllDbConnections() {
28
29
 
29
30
  export function testDbConnection() {
30
31
  return dbOpe.testConnection();
32
+ }
33
+
34
+ export function setLogLevel(level) {
35
+ if (typeof level === 'number') { schema.config.log.level = level }
36
+ else if (typeof level === 'string' && Number.parseInt(level) != NaN) { schema.config.log.level = Number.parseInt(level) }
37
+ }
38
+
39
+ export function setLogCallback(callback) {
40
+ if (typeof callback === 'function') { schema.config.log.callback = callback }
41
+ }
42
+
43
+ export function setLogMaxAsyncInstances(maxAsyncInstance) {
44
+ if (typeof maxAsyncInstance === 'number') { schema.config.log.maxAsyncInstance = maxAsyncInstance }
45
+ else if (typeof maxAsyncInstance === 'string' && Number.parseInt(maxAsyncInstance) != NaN) { schema.config.log.maxAsyncInstance = Number.parseInt(maxAsyncInstance) }
46
+ }
47
+
48
+ export function setSchemaServers(servers) {
49
+ schema.servers = servers;
31
50
  }
package/lib/log.js CHANGED
@@ -1,11 +1,20 @@
1
1
  'use strict';
2
2
 
3
3
  import schema from './schema.js';
4
+ let numberOfAsyncInstances = 0;
4
5
 
5
6
  export default function log(msg, level = 1) {
6
7
  if (schema.config.log.level >= level && schema.config.log.callback) {
7
- try {
8
- schema.config.log.callback({level: level, text: msg})
8
+ try {
9
+ const _param = {level: level, text: msg};
10
+ const _result = schema.config.log.callback(_param);
11
+ if (_result && typeof _result.then === 'function') {
12
+ // È una Promise (o un oggetto thenable)
13
+ if (numberOfAsyncInstances <= schema.config.log.maxAsyncInstance) {
14
+ numberOfAsyncInstances++;
15
+ _result.then((_param) => {}).catch(error => {}).finally(() => {numberOfAsyncInstances--;});
16
+ };
17
+ };
9
18
  }
10
19
  catch {}
11
20
  }
package/lib/schema.js CHANGED
@@ -4,7 +4,8 @@ export default {
4
4
  config: {
5
5
  log: {
6
6
  level: 0,
7
- callback: undefined
7
+ callback: undefined,
8
+ maxAsyncInstance: 50
8
9
  }
9
10
  }
10
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "db-crud-api",
3
- "version": "0.3.15",
3
+ "version": "0.3.16",
4
4
  "type": "module",
5
5
  "description": "CRUD api for database tables",
6
6
  "main": "index.js",