@xuda.io/xuda-dbs-plugin-xuda 1.0.191 → 1.0.192

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 +44 -0
  3. package/studio.mjs +7 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/xuda-dbs-plugin-xuda",
3
- "version": "1.0.191",
3
+ "version": "1.0.192",
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
@@ -490,6 +490,50 @@ const get_opt = function (e, table_obj) {
490
490
 
491
491
  var selector_new = {};
492
492
 
493
+ function replaceKeysInQuery(query) {
494
+ const keys_to_replace = table_obj.tableFields.map((e) => {
495
+ return e.id;
496
+ });
497
+
498
+ // Helper function to recursively process the query object
499
+ function recursiveReplace(obj) {
500
+ if (typeof obj === "object" && obj !== null) {
501
+ // Create a new object to store the modified query
502
+ let newObj = Array.isArray(obj) ? [] : {};
503
+
504
+ // Traverse through the object
505
+ for (let key in obj) {
506
+ if (obj.hasOwnProperty(key)) {
507
+ // If the key is in the keys_to_replace array, replace it
508
+ let newKey = keys_to_replace.includes(key)
509
+ ? `udfData.data.${key}`
510
+ : key;
511
+
512
+ // Recursively process nested objects
513
+ newObj[newKey] = recursiveReplace(obj[key]);
514
+ }
515
+ }
516
+
517
+ return newObj;
518
+ } else {
519
+ // If it's not an object or array, return the value as is
520
+ return obj;
521
+ }
522
+ }
523
+
524
+ // Start the recursive replacement
525
+ return recursiveReplace(query);
526
+ }
527
+
528
+ if (e.filterModelMongo) {
529
+ selector_new["$and"] = [replaceKeysInQuery(e.filterModelMongo)];
530
+ }
531
+ if (e.filterModelUserMongo) {
532
+ if (!selector_new["$and"]) {
533
+ selector_new["$and"] = [];
534
+ }
535
+ selector_new["$and"] = [replaceKeysInQuery(e.filterModelUserMongo)];
536
+ }
493
537
  for (const [key, val] of Object.entries(opt.selector)) {
494
538
  selector_new["udfData.data." + key] = val;
495
539
  }
package/studio.mjs CHANGED
@@ -509,13 +509,13 @@ const get_opt = function (e, table_obj) {
509
509
 
510
510
  var selector_new = {};
511
511
 
512
- for (const [key, val] of Object.entries(opt.selector)) {
513
- if (key.substring(0, 1) === "$") {
514
- selector_new[key] = val;
515
- continue;
516
- }
517
- selector_new["udfData.data." + key] = val;
518
- }
512
+ // for (const [key, val] of Object.entries(opt.selector)) {
513
+ // if (key.substring(0, 1) === "$") {
514
+ // selector_new[key] = val;
515
+ // continue;
516
+ // }
517
+ // selector_new["udfData.data." + key] = val;
518
+ // }
519
519
 
520
520
  // if (e.viewDbQuery) {
521
521
  // for (const [key, val] of Object.entries(table_obj.tableFields)) {