@researchdatabox/sails-hook-redbox-storage-mongo 1.5.1 → 1.5.3

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.
@@ -12,7 +12,7 @@ var __await = (this && this.__await) || function (v) { return this instanceof __
12
12
  var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
13
13
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
14
14
  var g = generator.apply(thisArg, _arguments || []), i, q = [];
15
- return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
15
+ return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
16
16
  function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
17
17
  function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
18
18
  function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
@@ -24,6 +24,7 @@ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _ar
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.Services = void 0;
26
26
  const rxjs_1 = require("rxjs");
27
+ const rxjs_2 = require("rxjs");
27
28
  const uuid_1 = require("uuid");
28
29
  const luxon_1 = require("luxon");
29
30
  const mongodb = require("mongodb");
@@ -371,7 +372,7 @@ var Services;
371
372
  });
372
373
  }
373
374
  getDeletedRecords(workflowState_1) {
374
- return __awaiter(this, arguments, void 0, function* (workflowState, recordType = undefined, start, rows = 10, username, roles, brand, editAccessOnly = undefined, packageType = undefined, sort = undefined, filterFields = undefined, filterString = undefined, filterMode = 'regex') {
375
+ return __awaiter(this, arguments, void 0, function* (workflowState, recordType = undefined, start, rows = 10, username, roles, brand, editAccessOnly = undefined, packageType = undefined, sort = undefined, filterFields = undefined, filterString = undefined, filterMode = 'regex', secondarySort = undefined) {
375
376
  let query = {
376
377
  "deletedRecordMetadata.metaMetadata.brandId": brand.id
377
378
  };
@@ -395,6 +396,9 @@ var Services;
395
396
  options['sort'][`${sort.substring(0, sort.indexOf(':'))}`] = _.toNumber(sort.substring(sort.indexOf(':') + 1));
396
397
  }
397
398
  }
399
+ if (!_.isEmpty(secondarySort)) {
400
+ options['sort'][`${secondarySort.substring(0, secondarySort.indexOf(':'))}`] = _.toNumber(secondarySort.substring(secondarySort.indexOf(':') + 1));
401
+ }
398
402
  let roleNames = this.getRoleNames(roles, brand);
399
403
  let andArray = [];
400
404
  let permissions = {
@@ -666,10 +670,12 @@ var Services;
666
670
  }
667
671
  updateDatastream(oid, record, newMetadata, fileRoot, fileIdsAdded) {
668
672
  return FormsService.getFormByName(record.metaMetadata.form, true)
669
- .flatMap(form => {
673
+ .pipe((0, rxjs_2.mergeMap)(form => {
674
+ form = form !== null && form !== void 0 ? form : { attachmentFields: [] };
675
+ const typedForm = form;
670
676
  const reqs = [];
671
- record.metaMetadata.attachmentFields = form.attachmentFields;
672
- _.each(form.attachmentFields, (attField) => __awaiter(this, void 0, void 0, function* () {
677
+ record.metaMetadata.attachmentFields = typedForm.attachmentFields;
678
+ _.each(typedForm.attachmentFields, (attField) => __awaiter(this, void 0, void 0, function* () {
673
679
  const oldAttachments = record.metadata[attField];
674
680
  const newAttachments = newMetadata[attField];
675
681
  const removeIds = [];
@@ -695,7 +701,7 @@ var Services;
695
701
  reqs.push((0, rxjs_1.of)({ "request": "dummy" }));
696
702
  }
697
703
  return (0, rxjs_1.of)(reqs);
698
- });
704
+ }));
699
705
  }
700
706
  removeDatastream(oid, datastream) {
701
707
  return __awaiter(this, void 0, void 0, function* () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@researchdatabox/sails-hook-redbox-storage-mongo",
3
- "version": "1.5.1",
3
+ "version": "1.5.3",
4
4
  "description": "A MongoDB storage plugin for ReDBox.",
5
5
  "main": "index.js",
6
6
  "sails": {
@@ -41,18 +41,18 @@
41
41
  "chai": "5.2.0",
42
42
  "fs": "0.0.1-security",
43
43
  "luxon": "^3.7.1",
44
- "mocha": "11.5.0",
44
+ "mocha": "11.7.1",
45
45
  "mocha-junit-reporter": "2.2.1",
46
46
  "mongodb": "6.16.0",
47
47
  "sails": "1.5.14",
48
48
  "stream": "0.0.3",
49
- "typescript": "5.5.4",
49
+ "typescript": "5.9.2",
50
50
  "util": "0.12.5"
51
51
  },
52
52
  "dependencies": {
53
53
  "json2csv": "^5.0.3",
54
54
  "lodash": "^4.17.21",
55
- "uuid": "8.3.0"
55
+ "uuid": "11.1.0"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "luxon": ">=3.0.0",
@@ -1,4 +1,5 @@
1
1
  import { Observable, of } from 'rxjs';
2
+ import { mergeMap } from 'rxjs';
2
3
 
3
4
  import { Sails, Model } from "sails";
4
5
  import { v1 as uuidv1 } from 'uuid';
@@ -407,7 +408,7 @@ export module Services {
407
408
  return record;
408
409
  }
409
410
 
410
- public async getDeletedRecords(workflowState, recordType = undefined, start, rows = 10, username, roles, brand, editAccessOnly = undefined, packageType = undefined, sort = undefined, filterFields = undefined, filterString = undefined, filterMode:string = 'regex') {
411
+ public async getDeletedRecords(workflowState, recordType = undefined, start, rows = 10, username, roles, brand, editAccessOnly = undefined, packageType = undefined, sort = undefined, filterFields = undefined, filterString = undefined, filterMode:string = 'regex', secondarySort = undefined) {
411
412
 
412
413
 
413
414
  // BrandId ...
@@ -436,6 +437,11 @@ export module Services {
436
437
  options['sort'][`${sort.substring(0, sort.indexOf(':'))}`] = _.toNumber(sort.substring(sort.indexOf(':') + 1));
437
438
  }
438
439
  }
440
+
441
+ if(!_.isEmpty(secondarySort)) {
442
+ options['sort'][`${secondarySort.substring(0, secondarySort.indexOf(':'))}`] = _.toNumber(secondarySort.substring(secondarySort.indexOf(':') + 1));
443
+ }
444
+
439
445
  // Authorization ...
440
446
  let roleNames = this.getRoleNames(roles, brand);
441
447
  let andArray = [];
@@ -734,38 +740,44 @@ export module Services {
734
740
  public updateDatastream(oid: string, record, newMetadata, fileRoot, fileIdsAdded): any {
735
741
  // loop thru the attachment fields and determine if we need to add or remove
736
742
  return FormsService.getFormByName(record.metaMetadata.form, true)
737
- .flatMap(form => {
738
- const reqs = [];
739
- record.metaMetadata.attachmentFields = form.attachmentFields;
740
- _.each(form.attachmentFields, async (attField) => {
741
- const oldAttachments = record.metadata[attField];
742
- const newAttachments = newMetadata[attField];
743
- const removeIds = [];
744
- // process removals
745
- if (!_.isUndefined(oldAttachments) && !_.isNull(oldAttachments) && !_.isNull(newAttachments)) {
746
- const toRemove = _.differenceBy(oldAttachments, newAttachments, 'fileId');
747
- _.each(toRemove, (removeAtt) => {
748
- if (removeAtt.type == 'attachment') {
749
- removeIds.push(new Datastream(removeAtt));
750
- }
751
- });
752
- }
753
- // process additions
754
- if (!_.isUndefined(newAttachments) && !_.isNull(newAttachments)) {
755
- const toAdd = _.differenceBy(newAttachments, oldAttachments, 'fileId');
756
- _.each(toAdd, (addAtt) => {
757
- if (addAtt.type == 'attachment') {
758
- fileIdsAdded.push(new Datastream(addAtt));
759
- }
760
- });
743
+ .pipe(
744
+ mergeMap(form => {
745
+ // For any generated, view-only forms, the form may be null, add a coalescence to avoid breaking
746
+ // the attachment update process.
747
+ form = form ?? { attachmentFields: [] };
748
+ const typedForm = form as { attachmentFields: string[] };
749
+ const reqs = [];
750
+ record.metaMetadata.attachmentFields = typedForm.attachmentFields;
751
+ _.each(typedForm.attachmentFields, async (attField) => {
752
+ const oldAttachments = record.metadata[attField];
753
+ const newAttachments = newMetadata[attField];
754
+ const removeIds = [];
755
+ // process removals
756
+ if (!_.isUndefined(oldAttachments) && !_.isNull(oldAttachments) && !_.isNull(newAttachments)) {
757
+ const toRemove = _.differenceBy(oldAttachments, newAttachments, 'fileId');
758
+ _.each(toRemove, (removeAtt) => {
759
+ if (removeAtt.type == 'attachment') {
760
+ removeIds.push(new Datastream(removeAtt));
761
+ }
762
+ });
763
+ }
764
+ // process additions
765
+ if (!_.isUndefined(newAttachments) && !_.isNull(newAttachments)) {
766
+ const toAdd = _.differenceBy(newAttachments, oldAttachments, 'fileId');
767
+ _.each(toAdd, (addAtt) => {
768
+ if (addAtt.type == 'attachment') {
769
+ fileIdsAdded.push(new Datastream(addAtt));
770
+ }
771
+ });
772
+ }
773
+ reqs.push(this.addAndRemoveDatastreams(oid, fileIdsAdded, removeIds));
774
+ });
775
+ if (_.isEmpty(reqs)) {
776
+ reqs.push(of({ "request": "dummy" }));
761
777
  }
762
- reqs.push(this.addAndRemoveDatastreams(oid, fileIdsAdded, removeIds));
763
- });
764
- if (_.isEmpty(reqs)) {
765
- reqs.push(of({ "request": "dummy" }));
766
- }
767
- return of(reqs);
768
- });
778
+ return of(reqs);
779
+ })
780
+ );
769
781
  }
770
782
 
771
783
  public async removeDatastream(oid, datastream: Datastream) {