@xuda.io/xuda-dbs-plugin-xuda 1.0.196 → 1.0.198

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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/server.js +34 -0
  3. package/studio.mjs +44 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/xuda-dbs-plugin-xuda",
3
- "version": "1.0.196",
3
+ "version": "1.0.198",
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
@@ -525,6 +525,40 @@ const get_opt = function (e, table_obj) {
525
525
  return recursiveReplace(query);
526
526
  }
527
527
 
528
+ function replaceRegexOptions(query) {
529
+ // Helper function to recursively process the query object
530
+ function recursiveReplace(obj) {
531
+ if (typeof obj === "object" && obj !== null) {
532
+ // Create a new object to store the modified query
533
+ let newObj = Array.isArray(obj) ? [] : {};
534
+
535
+ // Traverse through the object
536
+ for (let key in obj) {
537
+ if (obj.hasOwnProperty(key)) {
538
+ if (key === "$regex") {
539
+ newObj[key] = obj.$options
540
+ ? `(?${obj.$options})${obj[key]}`
541
+ : obj[key];
542
+ return newObj;
543
+ }
544
+
545
+ // Recursively process nested objects
546
+
547
+ newObj[key] = recursiveReplace(obj[key]);
548
+ }
549
+ }
550
+
551
+ return newObj;
552
+ } else {
553
+ // If it's not an object or array, return the value as is
554
+ return obj;
555
+ }
556
+ }
557
+
558
+ // Start the recursive replacement
559
+ return recursiveReplace(query);
560
+ }
561
+
528
562
  if (e.filterModelMongo) {
529
563
  selector_new["$and"] = [replaceKeysInQuery(JSON.parse(e.filterModelMongo))];
530
564
  }
package/studio.mjs CHANGED
@@ -570,21 +570,58 @@ const get_opt = function (e, table_obj) {
570
570
  return recursiveReplace(query);
571
571
  }
572
572
 
573
+ function replaceRegexOptions(query) {
574
+ // Helper function to recursively process the query object
575
+ function recursiveReplace(obj) {
576
+ if (typeof obj === "object" && obj !== null) {
577
+ // Create a new object to store the modified query
578
+ let newObj = Array.isArray(obj) ? [] : {};
579
+
580
+ // Traverse through the object
581
+ for (let key in obj) {
582
+ if (obj.hasOwnProperty(key)) {
583
+ // If the key is in the keys_to_replace array, replace it
584
+ // let newKey = keys_to_replace.includes(key)
585
+ // ? `udfData.data.${key}`
586
+ // : key;
587
+
588
+ if (key === "$regex") {
589
+ newObj[key] = RegExp(obj[key], obj.$options);
590
+ return newObj;
591
+ }
592
+
593
+ // Recursively process nested objects
594
+ // if (key !== "$options") {
595
+ newObj[key] = recursiveReplace(obj[key]);
596
+ // }
597
+ }
598
+ }
599
+
600
+ return newObj;
601
+ } else {
602
+ // If it's not an object or array, return the value as is
603
+ return obj;
604
+ }
605
+ }
606
+
607
+ // Start the recursive replacement
608
+ return recursiveReplace(query);
609
+ }
610
+
573
611
  if (e.filterModelMongo) {
574
- selector_new["$and"] = [replaceKeysInQuery(JSON.parse(e.filterModelMongo))];
612
+ selector_new["$and"] = [
613
+ replaceRegexOptions(replaceKeysInQuery(JSON.parse(e.filterModelMongo))),
614
+ ];
575
615
  }
576
616
  if (e.filterModelUserMongo) {
577
617
  if (!selector_new["$and"]) {
578
618
  selector_new["$and"] = [];
579
619
  }
580
620
  selector_new["$and"].push(
581
- replaceKeysInQuery(JSON.parse(e.filterModelUserMongo))
621
+ replaceRegexOptions(
622
+ replaceKeysInQuery(JSON.parse(e.filterModelUserMongo))
623
+ )
582
624
  );
583
-
584
- // selector_new["$and"] = {
585
- // ...selector_new["$and"],
586
- // ...replaceKeysInQuery(e.filterModelUserMongo),
587
- // };
588
625
  }
589
626
 
590
627
  opt.selector = selector_new;