forms-angular 0.12.0-beta.352 → 0.12.0-beta.354

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.
@@ -551,13 +551,15 @@ export class FormsAngular {
551
551
  function recordMatches(resultObject, aDoc, item) {
552
552
  const before = calcAddHits(resultObject);
553
553
  const charsBefore = matchedChars(resultObject);
554
+ // A resource can opt out of the exact match bonus, so its exact matches never jump above resources of greater importance
555
+ const exactBonus = item.resource.options.searchExactBonus !== false;
554
556
  resultObject.matched = resultObject.matched || [];
555
557
  if (item.combined) {
556
558
  if (multiMatchPossible) {
557
559
  resultObject.matched = searchStrings.map((word, i) => i);
558
560
  }
559
561
  else {
560
- resultObject.exact = true;
562
+ resultObject.exact = exactBonus;
561
563
  }
562
564
  }
563
565
  else {
@@ -584,7 +586,7 @@ export class FormsAngular {
584
586
  }
585
587
  }
586
588
  else if (fieldValue === searchFor) {
587
- resultObject.exact = true;
589
+ resultObject.exact = exactBonus;
588
590
  }
589
591
  }
590
592
  }
@@ -1258,13 +1260,7 @@ export class FormsAngular {
1258
1260
  let lookedUpFindQry = await this.doFindFuncPromise(req, resource);
1259
1261
  if (lookedUpFindQry) {
1260
1262
  // Now we need to put the lookup base into the criteria
1261
- for (const prop in lookedUpFindQry) {
1262
- if (lookedUpFindQry.hasOwnProperty(prop)) {
1263
- lookedUpFindQry[`${lookupField}.${prop}`] =
1264
- lookedUpFindQry[prop];
1265
- delete lookedUpFindQry[prop];
1266
- }
1267
- }
1263
+ lookedUpFindQry = this.prefixQuery(lookedUpFindQry, lookupField);
1268
1264
  if (allowNulls) {
1269
1265
  lookedUpFindQry = {
1270
1266
  $or: [
@@ -1293,6 +1289,28 @@ export class FormsAngular {
1293
1289
  }
1294
1290
  return retVal;
1295
1291
  }
1292
+ // Return a copy of query with every field path prefixed, so that it applies to a sub-document (such as the result of a
1293
+ // $lookup) rather than the document itself. The logical operators are followed into their clauses (prefixing them
1294
+ // would give a field path such as "b.$or", which silently matches nothing); any other top-level operator ($expr,
1295
+ // $text...) can't be made to apply to the sub-document like this, so is refused.
1296
+ prefixQuery(query, prefix) {
1297
+ const retVal = {};
1298
+ for (const prop of Object.keys(query)) {
1299
+ if (["$and", "$or", "$nor"].includes(prop)) {
1300
+ retVal[prop] = query[prop].map((clause) => this.prefixQuery(clause, prefix));
1301
+ }
1302
+ else if (prop === "$comment") {
1303
+ retVal[prop] = query[prop];
1304
+ }
1305
+ else if (prop.startsWith("$")) {
1306
+ throw new Error(`No support for a findFunc using ${prop} on a looked-up collection`);
1307
+ }
1308
+ else {
1309
+ retVal[`${prefix}.${prop}`] = query[prop];
1310
+ }
1311
+ }
1312
+ return retVal;
1313
+ }
1296
1314
  reportInternal(req, resource, schema, callback) {
1297
1315
  let runPipelineStr;
1298
1316
  let runPipelineObj;
@@ -1734,8 +1752,10 @@ export class FormsAngular {
1734
1752
  if (idArray.length > 0) {
1735
1753
  query = query.where("_id").in(idArray);
1736
1754
  }
1737
- if (findParam) {
1738
- query = query.find(findParam);
1755
+ if (findParam && Object.keys(findParam).length > 0) {
1756
+ // and, not find: find merges the conditions, so a key in findParam (which can come from the client)
1757
+ // would replace the same key in the findFunc's query rather than further restricting it
1758
+ query = query.and([findParam]);
1739
1759
  }
1740
1760
  query = query.select(that.generateProjection(hiddenFields, projectParam));
1741
1761
  if (limit) {
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  },
7
7
  "description": "A form builder that sits on top of Angular.js, Twitter Bootstrap, jQuery UI, Angular-UI, Express and Mongoose. Opinionated or what?",
8
8
  "homepage": "http://forms-angular.org",
9
- "version": "0.12.0-beta.352",
9
+ "version": "0.12.0-beta.354",
10
10
  "packageManager": "npm@10.2.4",
11
11
  "type": "module",
12
12
  "engines": {