@xuda.io/xuda-dbs-plugin-xuda 1.0.188 → 1.0.190

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/server.js +184 -184
  3. package/studio.mjs +246 -196
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/xuda-dbs-plugin-xuda",
3
- "version": "1.0.188",
3
+ "version": "1.0.190",
4
4
  "description": "Xuda Database Socket for Xuda's proprietary structure powered by CouchDB",
5
5
  "scripts": {
6
6
  "pub": "npm version patch --force && npm publish --access public"
package/server.js CHANGED
@@ -266,190 +266,190 @@ const get_opt = function (e, table_obj) {
266
266
  }
267
267
  }
268
268
 
269
- if (e.filterModel) {
270
- debugger;
271
- for (const [key, val] of Object.entries(e.filterModel)) {
272
- var field_name = key;
273
- var condition = "$and";
274
- const make_selector = function (val) {
275
- var value = "";
276
- var operator = "";
277
- var value_to = "";
278
- var operator_to = "";
279
-
280
- if (val.filterType === "date") {
281
- var date = val.dateFrom.substr(0, 10);
282
- switch (val.type) {
283
- case "equals":
284
- operator = "$regex";
285
- value = `^${date}`;
286
- break;
287
-
288
- case "greaterThan":
289
- operator = "$gt";
290
- value = `${date}`;
291
- break;
292
-
293
- case "lessThan":
294
- operator = "$lt";
295
- value = `${date}`;
296
- break;
297
-
298
- case "blank":
299
- operator = "$eq";
300
- value = "";
301
- break;
302
-
303
- case "inRange":
304
- operator = "$gte";
305
- value = date;
306
- operator_to = "$lte";
307
- value_to = val.dateTo.substr(0, 10);
308
- break;
309
-
310
- case "notEqual":
311
- operator = "$regex";
312
- value = `^((?!${date}).)*$`;
313
- break;
314
-
315
- case "notBlank":
316
- operator = "$ne";
317
- value = "";
318
- break;
319
-
320
- default:
321
- operator = "$regex";
322
- value = `^${date}`;
323
- }
324
- }
325
-
326
- if (val.filterType === "string" || val.filterType === "text") {
327
- switch (val.type) {
328
- case "contains":
329
- operator = "$regex";
330
- value = `${val.filter}`;
331
- break;
332
-
333
- case "notContains":
334
- operator = "$regex";
335
- value = `^((?!${val.filter}).)*$`;
336
- break;
337
-
338
- case "equals":
339
- operator = "$eq";
340
- value = `${val.filter}`;
341
- break;
342
-
343
- case "notEqual":
344
- operator = "$ne";
345
- value = `${val.filter}`;
346
- break;
347
-
348
- case "startsWith":
349
- operator = "$regex";
350
- value = `^${val.filter}`;
351
- break;
352
-
353
- case "endsWith":
354
- operator = "$regex";
355
- value = `${val.filter}$`;
356
- break;
357
-
358
- case "blank":
359
- operator = "$eq";
360
- value = "";
361
- break;
362
-
363
- case "notBlank":
364
- operator = "$ne";
365
- value = "";
366
- break;
367
-
368
- default:
369
- value = "^" + val.filter;
370
- }
371
- }
372
-
373
- if (val.filterType === "number") {
374
- switch (val.type) {
375
- case "equals":
376
- operator = "$eq";
377
- value = val.filter;
378
- break;
379
-
380
- case "notEqual":
381
- operator = "$ne";
382
- value = val.filter;
383
- break;
384
-
385
- case "lessThanOrEqual":
386
- operator = "$lte";
387
- value = val.filter;
388
- break;
389
-
390
- case "greaterThanOrEqual":
391
- operator = "$gte";
392
- value = val.filter;
393
- break;
394
-
395
- case "lessThan":
396
- operator = "$lt";
397
- value = val.filter;
398
- break;
399
-
400
- case "greaterThan":
401
- operator = "$gt";
402
- value = val.filter;
403
- break;
404
-
405
- case "blank":
406
- operator = "$eq";
407
- value = 0;
408
- break;
409
-
410
- case "notBlank":
411
- operator = "$ne";
412
- value = 0;
413
- break;
414
-
415
- case "inRange":
416
- operator = "$gte";
417
- value = val.filter;
418
- operator_to = "$lte";
419
- value_to = val.filterTo;
420
- break;
421
-
422
- default:
423
- operator = "$eq";
424
- value = val.filter;
425
- }
426
- }
427
- if (!opt.selector[field_name]) {
428
- opt.selector[field_name] = {};
429
- }
430
- if (!opt.selector[field_name][condition]) {
431
- opt.selector[field_name][condition] = [];
432
- }
433
- opt.selector[field_name][condition].push({
434
- [operator]: value,
435
- });
436
-
437
- if (operator_to) {
438
- opt.selector[field_name][condition].push({
439
- [operator_to]: value_to,
440
- });
441
- }
442
- };
443
-
444
- if (!val.condition1) {
445
- make_selector(val);
446
- } else {
447
- condition = "$" + val.operator.toLowerCase();
448
- make_selector(val.condition1);
449
- make_selector(val.condition2);
450
- }
451
- }
452
- }
269
+ // if (e.filterModel) {
270
+ // debugger;
271
+ // for (const [key, val] of Object.entries(e.filterModel)) {
272
+ // var field_name = key;
273
+ // var condition = "$and";
274
+ // const make_selector = function (val) {
275
+ // var value = "";
276
+ // var operator = "";
277
+ // var value_to = "";
278
+ // var operator_to = "";
279
+
280
+ // if (val.filterType === "date") {
281
+ // var date = val.dateFrom.substr(0, 10);
282
+ // switch (val.type) {
283
+ // case "equals":
284
+ // operator = "$regex";
285
+ // value = `^${date}`;
286
+ // break;
287
+
288
+ // case "greaterThan":
289
+ // operator = "$gt";
290
+ // value = `${date}`;
291
+ // break;
292
+
293
+ // case "lessThan":
294
+ // operator = "$lt";
295
+ // value = `${date}`;
296
+ // break;
297
+
298
+ // case "blank":
299
+ // operator = "$eq";
300
+ // value = "";
301
+ // break;
302
+
303
+ // case "inRange":
304
+ // operator = "$gte";
305
+ // value = date;
306
+ // operator_to = "$lte";
307
+ // value_to = val.dateTo.substr(0, 10);
308
+ // break;
309
+
310
+ // case "notEqual":
311
+ // operator = "$regex";
312
+ // value = `^((?!${date}).)*$`;
313
+ // break;
314
+
315
+ // case "notBlank":
316
+ // operator = "$ne";
317
+ // value = "";
318
+ // break;
319
+
320
+ // default:
321
+ // operator = "$regex";
322
+ // value = `^${date}`;
323
+ // }
324
+ // }
325
+
326
+ // if (val.filterType === "string" || val.filterType === "text") {
327
+ // switch (val.type) {
328
+ // case "contains":
329
+ // operator = "$regex";
330
+ // value = `${val.filter}`;
331
+ // break;
332
+
333
+ // case "notContains":
334
+ // operator = "$regex";
335
+ // value = `^((?!${val.filter}).)*$`;
336
+ // break;
337
+
338
+ // case "equals":
339
+ // operator = "$eq";
340
+ // value = `${val.filter}`;
341
+ // break;
342
+
343
+ // case "notEqual":
344
+ // operator = "$ne";
345
+ // value = `${val.filter}`;
346
+ // break;
347
+
348
+ // case "startsWith":
349
+ // operator = "$regex";
350
+ // value = `^${val.filter}`;
351
+ // break;
352
+
353
+ // case "endsWith":
354
+ // operator = "$regex";
355
+ // value = `${val.filter}$`;
356
+ // break;
357
+
358
+ // case "blank":
359
+ // operator = "$eq";
360
+ // value = "";
361
+ // break;
362
+
363
+ // case "notBlank":
364
+ // operator = "$ne";
365
+ // value = "";
366
+ // break;
367
+
368
+ // default:
369
+ // value = "^" + val.filter;
370
+ // }
371
+ // }
372
+
373
+ // if (val.filterType === "number") {
374
+ // switch (val.type) {
375
+ // case "equals":
376
+ // operator = "$eq";
377
+ // value = val.filter;
378
+ // break;
379
+
380
+ // case "notEqual":
381
+ // operator = "$ne";
382
+ // value = val.filter;
383
+ // break;
384
+
385
+ // case "lessThanOrEqual":
386
+ // operator = "$lte";
387
+ // value = val.filter;
388
+ // break;
389
+
390
+ // case "greaterThanOrEqual":
391
+ // operator = "$gte";
392
+ // value = val.filter;
393
+ // break;
394
+
395
+ // case "lessThan":
396
+ // operator = "$lt";
397
+ // value = val.filter;
398
+ // break;
399
+
400
+ // case "greaterThan":
401
+ // operator = "$gt";
402
+ // value = val.filter;
403
+ // break;
404
+
405
+ // case "blank":
406
+ // operator = "$eq";
407
+ // value = 0;
408
+ // break;
409
+
410
+ // case "notBlank":
411
+ // operator = "$ne";
412
+ // value = 0;
413
+ // break;
414
+
415
+ // case "inRange":
416
+ // operator = "$gte";
417
+ // value = val.filter;
418
+ // operator_to = "$lte";
419
+ // value_to = val.filterTo;
420
+ // break;
421
+
422
+ // default:
423
+ // operator = "$eq";
424
+ // value = val.filter;
425
+ // }
426
+ // }
427
+ // if (!opt.selector[field_name]) {
428
+ // opt.selector[field_name] = {};
429
+ // }
430
+ // if (!opt.selector[field_name][condition]) {
431
+ // opt.selector[field_name][condition] = [];
432
+ // }
433
+ // opt.selector[field_name][condition].push({
434
+ // [operator]: value,
435
+ // });
436
+
437
+ // if (operator_to) {
438
+ // opt.selector[field_name][condition].push({
439
+ // [operator_to]: value_to,
440
+ // });
441
+ // }
442
+ // };
443
+
444
+ // if (!val.condition1) {
445
+ // make_selector(val);
446
+ // } else {
447
+ // condition = "$" + val.operator.toLowerCase();
448
+ // make_selector(val.condition1);
449
+ // make_selector(val.condition2);
450
+ // }
451
+ // }
452
+ // }
453
453
 
454
454
  if (e.total_fields_info) {
455
455
  fields = [];
package/studio.mjs CHANGED
@@ -295,191 +295,191 @@ const get_opt = function (e, table_obj) {
295
295
  }
296
296
  }
297
297
 
298
- if (e.filterModel && JSON.parse(e.filterModel)) {
299
- debugger;
300
- for (const [key, val] of Object.entries(JSON.parse(e.filterModel))) {
301
- var field_name = "udfData.data." + key;
302
- var condition = "$and";
303
- const make_selector = function (val) {
304
- var value = "";
305
- var operator = "";
306
- var value_to = "";
307
- var operator_to = "";
308
-
309
- if (val.filterType === "date") {
310
- var date = val.dateFrom.substr(0, 10);
311
- switch (val.type) {
312
- case "equals":
313
- operator = "$regex";
314
- value = `^${date}`;
315
- break;
316
-
317
- case "greaterThan":
318
- operator = "$gt";
319
- value = `${date}`;
320
- break;
321
-
322
- case "lessThan":
323
- operator = "$lt";
324
- value = `${date}`;
325
- break;
326
-
327
- case "blank":
328
- operator = "$eq";
329
- value = "";
330
- break;
331
-
332
- case "inRange":
333
- operator = "$gte";
334
- value = date;
335
- operator_to = "$lte";
336
- value_to = val.dateTo.substr(0, 10);
337
- break;
338
-
339
- case "notEqual":
340
- operator = "$regex";
341
- value = `^((?!${date}).)*$`;
342
- break;
343
-
344
- case "notBlank":
345
- operator = "$ne";
346
- value = "";
347
- break;
348
-
349
- default:
350
- operator = "$regex";
351
- value = `^${date}`;
352
- }
353
- }
354
-
355
- if (val.filterType === "string" || val.filterType === "text") {
356
- switch (val.type) {
357
- case "contains":
358
- operator = "$regex";
359
- value = `${val.filter}`;
360
- break;
361
-
362
- case "notContains":
363
- operator = "$regex";
364
- value = `^((?!${val.filter}).)*$`;
365
- break;
366
-
367
- case "equals":
368
- operator = "$eq";
369
- value = `${val.filter}`;
370
- break;
371
-
372
- case "notEqual":
373
- operator = "$ne";
374
- value = `${val.filter}`;
375
- break;
376
-
377
- case "startsWith":
378
- operator = "$regex";
379
- value = `^${val.filter}`;
380
- break;
381
-
382
- case "endsWith":
383
- operator = "$regex";
384
- value = `${val.filter}$`;
385
- break;
386
-
387
- case "blank":
388
- operator = "$eq";
389
- value = "";
390
- break;
391
-
392
- case "notBlank":
393
- operator = "$ne";
394
- value = "";
395
- break;
396
-
397
- default:
398
- value = "^" + val.filter;
399
- }
400
- }
401
-
402
- if (val.filterType === "number") {
403
- switch (val.type) {
404
- case "equals":
405
- operator = "$eq";
406
- value = val.filter;
407
- break;
408
-
409
- case "notEqual":
410
- operator = "$ne";
411
- value = val.filter;
412
- break;
413
-
414
- case "lessThanOrEqual":
415
- operator = "$lte";
416
- value = val.filter;
417
- break;
418
-
419
- case "greaterThanOrEqual":
420
- operator = "$gte";
421
- value = val.filter;
422
- break;
423
-
424
- case "lessThan":
425
- operator = "$lt";
426
- value = val.filter;
427
- break;
428
-
429
- case "greaterThan":
430
- operator = "$gt";
431
- value = val.filter;
432
- break;
433
-
434
- case "blank":
435
- operator = "$eq";
436
- value = 0;
437
- break;
438
-
439
- case "notBlank":
440
- operator = "$ne";
441
- value = 0;
442
- break;
443
-
444
- case "inRange":
445
- operator = "$gte";
446
- value = val.filter;
447
- operator_to = "$lte";
448
- value_to = val.filterTo;
449
- break;
450
-
451
- default:
452
- operator = "$eq";
453
- value = val.filter;
454
- }
455
- }
456
- if (!opt.selector[condition]) {
457
- opt.selector[condition] = [];
458
- }
459
- // if (!opt.selector[condition][field_name]) {
460
- // opt.selector[condition][field_name] = [];
461
- // }
462
- opt.selector[condition].push({ [field_name]: { [operator]: value } });
463
-
464
- if (operator_to) {
465
- opt.selector[condition].push({
466
- [field_name]: { [operator_to]: value_to },
467
- });
468
- // opt.selector[condition][field_name].push({
469
- // [operator_to]: value_to,
470
- // });
471
- }
472
- };
473
-
474
- if (!val.condition1) {
475
- make_selector(val);
476
- } else {
477
- condition = "$" + val.operator.toLowerCase();
478
- make_selector(val.condition1);
479
- make_selector(val.condition2);
480
- }
481
- }
482
- }
298
+ // if (e.filterModel && JSON.parse(e.filterModel)) {
299
+ // debugger;
300
+ // for (const [key, val] of Object.entries(JSON.parse(e.filterModel))) {
301
+ // var field_name = "udfData.data." + key;
302
+ // var condition = "$and";
303
+ // const make_selector = function (val) {
304
+ // var value = "";
305
+ // var operator = "";
306
+ // var value_to = "";
307
+ // var operator_to = "";
308
+
309
+ // if (val.filterType === "date") {
310
+ // var date = val.dateFrom.substr(0, 10);
311
+ // switch (val.type) {
312
+ // case "equals":
313
+ // operator = "$regex";
314
+ // value = `^${date}`;
315
+ // break;
316
+
317
+ // case "greaterThan":
318
+ // operator = "$gt";
319
+ // value = `${date}`;
320
+ // break;
321
+
322
+ // case "lessThan":
323
+ // operator = "$lt";
324
+ // value = `${date}`;
325
+ // break;
326
+
327
+ // case "blank":
328
+ // operator = "$eq";
329
+ // value = "";
330
+ // break;
331
+
332
+ // case "inRange":
333
+ // operator = "$gte";
334
+ // value = date;
335
+ // operator_to = "$lte";
336
+ // value_to = val.dateTo.substr(0, 10);
337
+ // break;
338
+
339
+ // case "notEqual":
340
+ // operator = "$regex";
341
+ // value = `^((?!${date}).)*$`;
342
+ // break;
343
+
344
+ // case "notBlank":
345
+ // operator = "$ne";
346
+ // value = "";
347
+ // break;
348
+
349
+ // default:
350
+ // operator = "$regex";
351
+ // value = `^${date}`;
352
+ // }
353
+ // }
354
+
355
+ // if (val.filterType === "string" || val.filterType === "text") {
356
+ // switch (val.type) {
357
+ // case "contains":
358
+ // operator = "$regex";
359
+ // value = `${val.filter}`;
360
+ // break;
361
+
362
+ // case "notContains":
363
+ // operator = "$regex";
364
+ // value = `^((?!${val.filter}).)*$`;
365
+ // break;
366
+
367
+ // case "equals":
368
+ // operator = "$eq";
369
+ // value = `${val.filter}`;
370
+ // break;
371
+
372
+ // case "notEqual":
373
+ // operator = "$ne";
374
+ // value = `${val.filter}`;
375
+ // break;
376
+
377
+ // case "startsWith":
378
+ // operator = "$regex";
379
+ // value = `^${val.filter}`;
380
+ // break;
381
+
382
+ // case "endsWith":
383
+ // operator = "$regex";
384
+ // value = `${val.filter}$`;
385
+ // break;
386
+
387
+ // case "blank":
388
+ // operator = "$eq";
389
+ // value = "";
390
+ // break;
391
+
392
+ // case "notBlank":
393
+ // operator = "$ne";
394
+ // value = "";
395
+ // break;
396
+
397
+ // default:
398
+ // value = "^" + val.filter;
399
+ // }
400
+ // }
401
+
402
+ // if (val.filterType === "number") {
403
+ // switch (val.type) {
404
+ // case "equals":
405
+ // operator = "$eq";
406
+ // value = val.filter;
407
+ // break;
408
+
409
+ // case "notEqual":
410
+ // operator = "$ne";
411
+ // value = val.filter;
412
+ // break;
413
+
414
+ // case "lessThanOrEqual":
415
+ // operator = "$lte";
416
+ // value = val.filter;
417
+ // break;
418
+
419
+ // case "greaterThanOrEqual":
420
+ // operator = "$gte";
421
+ // value = val.filter;
422
+ // break;
423
+
424
+ // case "lessThan":
425
+ // operator = "$lt";
426
+ // value = val.filter;
427
+ // break;
428
+
429
+ // case "greaterThan":
430
+ // operator = "$gt";
431
+ // value = val.filter;
432
+ // break;
433
+
434
+ // case "blank":
435
+ // operator = "$eq";
436
+ // value = 0;
437
+ // break;
438
+
439
+ // case "notBlank":
440
+ // operator = "$ne";
441
+ // value = 0;
442
+ // break;
443
+
444
+ // case "inRange":
445
+ // operator = "$gte";
446
+ // value = val.filter;
447
+ // operator_to = "$lte";
448
+ // value_to = val.filterTo;
449
+ // break;
450
+
451
+ // default:
452
+ // operator = "$eq";
453
+ // value = val.filter;
454
+ // }
455
+ // }
456
+ // if (!opt.selector[condition]) {
457
+ // opt.selector[condition] = [];
458
+ // }
459
+ // // if (!opt.selector[condition][field_name]) {
460
+ // // opt.selector[condition][field_name] = [];
461
+ // // }
462
+ // opt.selector[condition].push({ [field_name]: { [operator]: value } });
463
+
464
+ // if (operator_to) {
465
+ // opt.selector[condition].push({
466
+ // [field_name]: { [operator_to]: value_to },
467
+ // });
468
+ // // opt.selector[condition][field_name].push({
469
+ // // [operator_to]: value_to,
470
+ // // });
471
+ // }
472
+ // };
473
+
474
+ // if (!val.condition1) {
475
+ // make_selector(val);
476
+ // } else {
477
+ // condition = "$" + val.operator.toLowerCase();
478
+ // make_selector(val.condition1);
479
+ // make_selector(val.condition2);
480
+ // }
481
+ // }
482
+ // }
483
483
 
484
484
  if (e.total_fields_info) {
485
485
  fields = [];
@@ -517,22 +517,72 @@ const get_opt = function (e, table_obj) {
517
517
  selector_new["udfData.data." + key] = val;
518
518
  }
519
519
 
520
- if (e.viewDbQuery) {
521
- for (const [key, val] of Object.entries(table_obj.tableFields)) {
522
- if (e.viewDbQuery.includes(val.id)) {
523
- const replacer = new RegExp(val.id, "g");
524
- e.viewDbQuery = e.viewDbQuery.replace(
525
- replacer,
526
- "udfData.data." + val.data.field_id
527
- );
520
+ // if (e.viewDbQuery) {
521
+ // for (const [key, val] of Object.entries(table_obj.tableFields)) {
522
+ // if (e.viewDbQuery.includes(val.id)) {
523
+ // const replacer = new RegExp(val.id, "g");
524
+ // e.viewDbQuery = e.viewDbQuery.replace(
525
+ // replacer,
526
+ // "udfData.data." + val.data.field_id
527
+ // );
528
+ // }
529
+ // }
530
+
531
+ // let viewDbQuery = JSON.parse(e.viewDbQuery.replace(/\\/g, ""));
532
+
533
+ // for (const [key, val] of Object.entries(viewDbQuery)) {
534
+ // selector_new[key] = val;
535
+ // }
536
+ // }
537
+
538
+ function replaceKeysInQuery(query) {
539
+ const keys_to_replace = table_obj.tableFields.map((e) => {
540
+ return e.id;
541
+ });
542
+
543
+ // Helper function to recursively process the query object
544
+ function recursiveReplace(obj) {
545
+ if (typeof obj === "object" && obj !== null) {
546
+ // Create a new object to store the modified query
547
+ let newObj = Array.isArray(obj) ? [] : {};
548
+
549
+ // Traverse through the object
550
+ for (let key in obj) {
551
+ if (obj.hasOwnProperty(key)) {
552
+ // If the key is in the keys_to_replace array, replace it
553
+ let newKey = keys_to_replace.includes(key)
554
+ ? `udfData.data.${key}`
555
+ : key;
556
+
557
+ // Recursively process nested objects
558
+ newObj[newKey] = recursiveReplace(obj[key]);
559
+ }
560
+ }
561
+
562
+ return newObj;
563
+ } else {
564
+ // If it's not an object or array, return the value as is
565
+ return obj;
528
566
  }
529
567
  }
530
568
 
531
- let viewDbQuery = JSON.parse(e.viewDbQuery.replace(/\\/g, ""));
569
+ // Start the recursive replacement
570
+ return recursiveReplace(query);
571
+ }
532
572
 
533
- for (const [key, val] of Object.entries(viewDbQuery)) {
534
- selector_new[key] = val;
573
+ if (e.filterModelMongo) {
574
+ selector_new["$and"] = [replaceKeysInQuery(e.filterModelMongo)];
575
+ }
576
+ if (e.filterModelUserMongo) {
577
+ if (!selector_new["$and"]) {
578
+ selector_new["$and"] = [];
535
579
  }
580
+ selector_new["$and"] = [replaceKeysInQuery(e.filterModelUserMongo)];
581
+
582
+ // selector_new["$and"] = {
583
+ // ...selector_new["$and"],
584
+ // ...replaceKeysInQuery(e.filterModelUserMongo),
585
+ // };
536
586
  }
537
587
 
538
588
  opt.selector = selector_new;