forms-angular 0.12.0-beta.369 → 0.12.0-beta.370

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.
@@ -1069,13 +1069,17 @@ export class FormsAngular {
1069
1069
  for (let pipelineSection = 0; pipelineSection < runPipeline.length; pipelineSection++) {
1070
1070
  let sectionType = Object.keys(runPipeline[pipelineSection])[0];
1071
1071
  if (["$match", "$group", "$project"].includes(sectionType)) {
1072
- this.hackVariables(runPipeline[pipelineSection][sectionType]);
1072
+ // In a $group or $project, _id is not a field being compared, so leave its dates alone
1073
+ this.hackVariables(runPipeline[pipelineSection][sectionType], sectionType === "$match");
1073
1074
  }
1074
1075
  }
1075
1076
  }
1076
- hackVariables(obj) {
1077
+ hackVariables(obj, idDates = true, inIdCriteria = false) {
1077
1078
  // Replace variables that cannot be serialised / deserialised. Bit of a hack, but needs must...
1078
- // Anything formatted 1800-01-01T00:00:00.000Z or 1800-01-01T00:00:00.000+0000 is converted to a Date
1079
+ // Anything formatted 1800-01-01T00:00:00.000Z or 1800-01-01T00:00:00.000+0000 is converted to a Date, except
1080
+ // in a range on _id ({_id: {$gte: "2025-01-01T00:00:00.000Z"}}), where it becomes the first ObjectId of that
1081
+ // time, so that a date (a report's date parameter, say) can select documents by when they were created using
1082
+ // the _id index
1079
1083
  // Only handles the cases I need for now
1080
1084
  // TODO: handle arrays etc
1081
1085
  for (const prop in obj) {
@@ -1083,7 +1087,11 @@ export class FormsAngular {
1083
1087
  if (typeof obj[prop] === "string") {
1084
1088
  const dateTest = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(.\d{3})?)(Z|[+ -]\d{2}:?\d{2})$/.exec(obj[prop]);
1085
1089
  if (dateTest) {
1086
- obj[prop] = new Date(dateTest[1] + "Z");
1090
+ const date = new Date(dateTest[1] + "Z");
1091
+ obj[prop] =
1092
+ inIdCriteria && ["$gt", "$gte", "$lt", "$lte"].includes(prop)
1093
+ ? Types.ObjectId.createFromTime(Math.floor(date.valueOf() / 1000))
1094
+ : date;
1087
1095
  }
1088
1096
  else if (prop !== "$regex") {
1089
1097
  const objectIdTest = /^([0-9a-fA-F]{24})$/.exec(obj[prop]);
@@ -1093,7 +1101,7 @@ export class FormsAngular {
1093
1101
  }
1094
1102
  }
1095
1103
  else if (_.isObject(obj[prop])) {
1096
- this.hackVariables(obj[prop]);
1104
+ this.hackVariables(obj[prop], idDates, idDates && prop === "_id");
1097
1105
  }
1098
1106
  }
1099
1107
  }
@@ -1182,6 +1190,9 @@ export class FormsAngular {
1182
1190
  case "$lookup":
1183
1191
  case "$graphLookup":
1184
1192
  let needFindFunc = true;
1193
+ // Set when the findFunc is applied inside the $lookup's own pipeline. Applying it again after the $unwind
1194
+ // would be redundant, and wrong if that pipeline projects away the fields the findFunc selects on.
1195
+ let restrictedInPipeline = false;
1185
1196
  const collectionName = stage[keys[0]].from;
1186
1197
  const lookupField = stage[keys[0]].as;
1187
1198
  if (typeof collectionName !== "string" || typeof lookupField !== "string" || (collectionName + lookupField).indexOf("$") !== -1) {
@@ -1201,6 +1212,7 @@ export class FormsAngular {
1201
1212
  }
1202
1213
  else if (lookupProps.length === 5 && lookupProps.includes("pipeline")) {
1203
1214
  stage.$lookup.pipeline = await sanitiseJoinedPipeline(stage.$lookup.pipeline, resource);
1215
+ restrictedInPipeline = true;
1204
1216
  }
1205
1217
  else {
1206
1218
  throw new Error("Unsupported $lookup format");
@@ -1212,6 +1224,7 @@ export class FormsAngular {
1212
1224
  lookupProps.includes("pipeline") &&
1213
1225
  lookupProps.includes("as")) {
1214
1226
  stage.$lookup.pipeline = await sanitiseJoinedPipeline(stage.$lookup.pipeline, resource);
1227
+ restrictedInPipeline = true;
1215
1228
  }
1216
1229
  else {
1217
1230
  throw new Error(`No support for $lookup of with properties ${lookupProps.join(', ')}`);
@@ -1257,7 +1270,9 @@ export class FormsAngular {
1257
1270
  }
1258
1271
  // Push the $unwind, add our own findFunc, and increment the pipelineStage counter
1259
1272
  retVal.push(array[pipelineSection + 1]);
1260
- let lookedUpFindQry = await this.doFindFuncPromise(req, resource);
1273
+ let lookedUpFindQry = restrictedInPipeline
1274
+ ? undefined
1275
+ : await this.doFindFuncPromise(req, resource);
1261
1276
  if (lookedUpFindQry) {
1262
1277
  // Now we need to put the lookup base into the criteria
1263
1278
  lookedUpFindQry = this.prefixQuery(lookedUpFindQry, lookupField);
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.369",
9
+ "version": "0.12.0-beta.370",
10
10
  "packageManager": "npm@10.2.4",
11
11
  "type": "module",
12
12
  "engines": {