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

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.
@@ -1258,13 +1258,7 @@ export class FormsAngular {
1258
1258
  let lookedUpFindQry = await this.doFindFuncPromise(req, resource);
1259
1259
  if (lookedUpFindQry) {
1260
1260
  // 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
- }
1261
+ lookedUpFindQry = this.prefixQuery(lookedUpFindQry, lookupField);
1268
1262
  if (allowNulls) {
1269
1263
  lookedUpFindQry = {
1270
1264
  $or: [
@@ -1293,6 +1287,28 @@ export class FormsAngular {
1293
1287
  }
1294
1288
  return retVal;
1295
1289
  }
1290
+ // Return a copy of query with every field path prefixed, so that it applies to a sub-document (such as the result of a
1291
+ // $lookup) rather than the document itself. The logical operators are followed into their clauses (prefixing them
1292
+ // would give a field path such as "b.$or", which silently matches nothing); any other top-level operator ($expr,
1293
+ // $text...) can't be made to apply to the sub-document like this, so is refused.
1294
+ prefixQuery(query, prefix) {
1295
+ const retVal = {};
1296
+ for (const prop of Object.keys(query)) {
1297
+ if (["$and", "$or", "$nor"].includes(prop)) {
1298
+ retVal[prop] = query[prop].map((clause) => this.prefixQuery(clause, prefix));
1299
+ }
1300
+ else if (prop === "$comment") {
1301
+ retVal[prop] = query[prop];
1302
+ }
1303
+ else if (prop.startsWith("$")) {
1304
+ throw new Error(`No support for a findFunc using ${prop} on a looked-up collection`);
1305
+ }
1306
+ else {
1307
+ retVal[`${prefix}.${prop}`] = query[prop];
1308
+ }
1309
+ }
1310
+ return retVal;
1311
+ }
1296
1312
  reportInternal(req, resource, schema, callback) {
1297
1313
  let runPipelineStr;
1298
1314
  let runPipelineObj;
@@ -1734,8 +1750,10 @@ export class FormsAngular {
1734
1750
  if (idArray.length > 0) {
1735
1751
  query = query.where("_id").in(idArray);
1736
1752
  }
1737
- if (findParam) {
1738
- query = query.find(findParam);
1753
+ if (findParam && Object.keys(findParam).length > 0) {
1754
+ // and, not find: find merges the conditions, so a key in findParam (which can come from the client)
1755
+ // would replace the same key in the findFunc's query rather than further restricting it
1756
+ query = query.and([findParam]);
1739
1757
  }
1740
1758
  query = query.select(that.generateProjection(hiddenFields, projectParam));
1741
1759
  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.353",
10
10
  "packageManager": "npm@10.2.4",
11
11
  "type": "module",
12
12
  "engines": {