forms-angular 0.12.0-beta.312 → 0.12.0-beta.313

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.
@@ -1099,18 +1099,40 @@ class FormsAngular {
1099
1099
  case "$graphLookup":
1100
1100
  let needFindFunc = true;
1101
1101
  if (keys[0] === "$lookup") {
1102
- // For now at least, we only support simple $lookups with a single join field equality
1103
1102
  let lookupProps = Object.keys(stage.$lookup);
1104
- if (lookupProps.length !== 4 ||
1105
- lookupProps.indexOf("from") === -1 ||
1106
- lookupProps.indexOf("localField") === -1 ||
1107
- lookupProps.indexOf("foreignField") === -1 ||
1108
- lookupProps.indexOf("as") === -1) {
1109
- throw new Error("No support for $lookup that isn't Equality Match with a Single Join Condition");
1103
+ // First deal with simple $lookups with a single join field equality
1104
+ if (lookupProps.length === 4 &&
1105
+ lookupProps.includes("from") &&
1106
+ lookupProps.includes("localField") &&
1107
+ lookupProps.includes("foreignField") &&
1108
+ lookupProps.includes("as")) {
1109
+ // If we are doing a lookup using an _id (so not fishing) we don't need to do the findFunc (see tkt #12399)
1110
+ if (stage.$lookup.foreignField === "_id") {
1111
+ needFindFunc = false;
1112
+ }
1110
1113
  }
1111
- // If we are doing a lookup using an _id (so not fishing) we don't need to do the findFunc (see tkt #12399)
1112
- if (stage.$lookup.foreignField === "_id") {
1113
- needFindFunc = false;
1114
+ else if (lookupProps.length === 4 &&
1115
+ lookupProps.includes("from") &&
1116
+ lookupProps.includes("let") &&
1117
+ lookupProps.includes("pipeline") &&
1118
+ lookupProps.includes("as")) {
1119
+ // can't think of a way to exploit this (if you add a findFunc) but it is the responsibility of the user
1120
+ // to ensure that the pipeline returns fields used by the findFunc
1121
+ console.log(`In some scenarios $lookups that use pipelines may not provide all the fields used by the 'findFunc' of a collection.
1122
+ If you get no results returned this might be the explanation.`);
1123
+ /* Sanitise the pipeline we are doing a lookup with, removing hidden fields from that collection */
1124
+ const lookupCollectionName = stage.$lookup.from;
1125
+ const lookupResource = that.getResourceFromCollection(lookupCollectionName);
1126
+ let lookupHiddenLookupFields = {};
1127
+ if (lookupResource) {
1128
+ if (lookupResource.options?.hide?.length > 0) {
1129
+ lookupHiddenLookupFields = this.generateHiddenFields(lookupResource, false);
1130
+ }
1131
+ }
1132
+ stage.$lookup.pipeline = await that.sanitisePipeline(stage.$lookup.pipeline, lookupHiddenLookupFields, findFuncQry, req);
1133
+ }
1134
+ else {
1135
+ throw new Error(`No support for $lookup of with properties ${lookupProps.join(', ')}`);
1114
1136
  }
1115
1137
  }
1116
1138
  // hide any hiddenfields in the lookup collection
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "Mark Chapman <support@forms-angular.org>",
4
4
  "description": "A form builder that sits on top of Angular.js, Twitter Bootstrap, jQuery UI, Angular-UI, Express and Mongoose. Opinionated or what?",
5
5
  "homepage": "http://forms-angular.org",
6
- "version": "0.12.0-beta.312",
6
+ "version": "0.12.0-beta.313",
7
7
  "engines": {
8
8
  "node": ">=8.x",
9
9
  "npm": ">=5.x"