badmfck-api-server 3.4.0 → 3.4.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.
@@ -95,7 +95,7 @@ async function Initializer(services) {
95
95
  exports.Initializer = Initializer;
96
96
  class APIService extends BaseService_1.BaseService {
97
97
  static nextLogID = 0;
98
- version = "3.4.0";
98
+ version = "3.4.1";
99
99
  options;
100
100
  monitor = null;
101
101
  started = new Date();
@@ -386,6 +386,8 @@ class MysqlAdapter {
386
386
  if (fields) {
387
387
  for (let i in fields) {
388
388
  const name = i;
389
+ if (name.startsWith("$__"))
390
+ continue;
389
391
  let queryField = fields[i];
390
392
  if (queryField === undefined)
391
393
  continue;
@@ -409,6 +411,8 @@ class MysqlAdapter {
409
411
  let insertFieldValues = [];
410
412
  for (let i in fields) {
411
413
  let f = fields[i];
414
+ if (f.name?.startsWith("$__"))
415
+ continue;
412
416
  if (f.ignoreInInsert)
413
417
  continue;
414
418
  insertFieldNames.push('`' + f.name + '`');
@@ -423,6 +427,8 @@ class MysqlAdapter {
423
427
  let oninsertValues = [];
424
428
  for (let i in fields) {
425
429
  let f = fields[i];
430
+ if (f.name?.startsWith("$__"))
431
+ continue;
426
432
  if (f.ignoreInInsert)
427
433
  continue;
428
434
  oninsertNames.push(f.name);
@@ -434,6 +440,8 @@ class MysqlAdapter {
434
440
  let onUpdate = [];
435
441
  for (let i in fields) {
436
442
  let f = fields[i];
443
+ if (f.name?.startsWith("$__"))
444
+ continue;
437
445
  if (f.ignoreInUpdate)
438
446
  continue;
439
447
  onUpdate.push('`' + f.name + '` = ' + f.__parsedValue);
@@ -444,6 +452,8 @@ class MysqlAdapter {
444
452
  let onDuplicate = [];
445
453
  for (let i in fields) {
446
454
  let f = fields[i];
455
+ if (f.name?.startsWith("$__"))
456
+ continue;
447
457
  if (!f.useInReplace)
448
458
  continue;
449
459
  onDuplicate.push('`' + f.name + f.__parsedValue);
@@ -126,6 +126,22 @@ class Validator {
126
126
  errors.push("wrong value for field '" + i + "', expected " + expected.join(", ") + " got: " + value);
127
127
  }
128
128
  }
129
+ if (structure['$__' + i + "_values"]) {
130
+ const values = structure['$__' + i + "_values"];
131
+ if (Array.isArray(values) && values.length) {
132
+ if (!values.includes(object[i])) {
133
+ let caseValue = null;
134
+ for (let i of values) {
135
+ const v = i.toLowerCase();
136
+ if (v === (object[i] + "").toLowerCase()) {
137
+ caseValue = object[i];
138
+ break;
139
+ }
140
+ }
141
+ errors.push("Wrong value for field '" + i + "'" + (caseValue ? ", check case for: " + caseValue : ""));
142
+ }
143
+ }
144
+ }
129
145
  if (typeof structure[i] === "string" && structure["$__" + i + "_regex"]) {
130
146
  const regex = structure["$__" + i + "_regex"];
131
147
  const reg = new RegExp(regex);
@@ -145,6 +161,12 @@ class Validator {
145
161
  }
146
162
  }
147
163
  if (typeof structure[i] === "number") {
164
+ if (typeof object[i] === "string") {
165
+ if (object[i].indexOf("."))
166
+ object[i] = parseFloat(object[i]);
167
+ else
168
+ object[i] = parseInt(object[i]);
169
+ }
148
170
  if (isNaN(object[i]))
149
171
  errors.push("wrong value for field '" + i + "', expected number got " + object[i]);
150
172
  if (structure[i] != 0) {
@@ -170,6 +192,16 @@ class Validator {
170
192
  if (object[i] > max)
171
193
  errors.push("value for field '" + i + "' is too big, expected less than " + max + " got: " + object[i]);
172
194
  }
195
+ if (typeof object[i] === "string" && structure["$__" + i + "_min"]) {
196
+ const min = structure["$__" + i + "_min"];
197
+ if (object[i].length < min)
198
+ errors.push("value length for field '" + i + "' is too small, expected more than " + min + " got: " + object[i].length);
199
+ }
200
+ if (typeof object[i] === "string" && structure["$__" + i + "_max"]) {
201
+ const max = structure["$__" + i + "_max"];
202
+ if (object[i].length > max)
203
+ errors.push("value length for field '" + i + "' is too big, expected less than " + max + " got: " + object[i].length);
204
+ }
173
205
  foundKeys.push(i);
174
206
  }
175
207
  if (errors.length > 0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "3.4.0",
3
+ "version": "3.4.1",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",