@researchdatabox/sails-hook-redbox-storage-mongo 1.5.3 → 5.0.0-RC1

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.
Files changed (37) hide show
  1. package/README.md +20 -5
  2. package/dist/config/record.d.ts +3 -0
  3. package/dist/config/record.js +7 -0
  4. package/dist/config/storage.d.ts +105 -0
  5. package/dist/config/storage.js +25 -0
  6. package/dist/index.d.ts +16 -0
  7. package/dist/index.js +31 -0
  8. package/dist/models/DeletedRecord.d.ts +7 -0
  9. package/dist/models/DeletedRecord.js +37 -0
  10. package/dist/models/IntegrationAudit.d.ts +22 -0
  11. package/dist/models/IntegrationAudit.js +112 -0
  12. package/dist/models/Record.d.ts +13 -0
  13. package/dist/models/Record.js +64 -0
  14. package/dist/models/RecordAudit.d.ts +9 -0
  15. package/dist/models/RecordAudit.js +47 -0
  16. package/dist/models/index.d.ts +10 -0
  17. package/dist/models/index.js +32 -0
  18. package/dist/services/MongoStorageService.d.ts +83 -0
  19. package/dist/services/MongoStorageService.js +1276 -0
  20. package/dist/services/index.d.ts +5 -0
  21. package/dist/services/index.js +51 -0
  22. package/package.json +66 -32
  23. package/.github/dependabot.yml +0 -12
  24. package/api/models/DeletedRecord.js +0 -24
  25. package/api/models/Record.js +0 -41
  26. package/api/models/RecordAudit.js +0 -18
  27. package/api/services/MongoStorageService.js +0 -905
  28. package/config/record.js +0 -3
  29. package/config/storage.js +0 -73
  30. package/index.js +0 -21
  31. package/test/unit/.mocharc.js +0 -21
  32. package/test/unit/bootstrap.js +0 -63
  33. package/test/unit/db/storage.test.js +0 -121
  34. package/transformer/ExportJSONTransformer.js +0 -47
  35. package/tsconfig.json +0 -39
  36. package/typescript/api/services/MongoStorageService.ts +0 -1005
  37. package/typescript/transformer/ExportJSONTransformer.ts +0 -65
package/config/record.js DELETED
@@ -1,3 +0,0 @@
1
- module.exports.record = {
2
- datastreamService: 'mongostorageservice'
3
- };
package/config/storage.js DELETED
@@ -1,73 +0,0 @@
1
- module.exports.storage = {
2
- // when loaded, this plugin will set itself as the default
3
- serviceName: "mongostorageservice",
4
- mongodb: {
5
- indices: [
6
- {
7
- key: {
8
- 'harvestId': 1
9
- }
10
- },
11
- {
12
- key: {
13
- 'dateCreated': 1
14
- }
15
- },
16
- {
17
- key: {
18
- 'dateCreated': -1
19
- }
20
- },
21
- {
22
- key: {
23
- 'lastSaveDate': 1
24
- }
25
- },
26
- {
27
- key: {
28
- 'lastSaveDate': -1
29
- }
30
- },
31
- {
32
- key: {
33
- 'metaMetadata.brandId': 1
34
- }
35
- },
36
- {
37
- key: {
38
- 'metaMetadata.type': 1
39
- }
40
- },
41
- {
42
- key: {
43
- 'metaMetadata.createdOn': 1
44
- }
45
- },
46
- {
47
- key: {
48
- 'metaMetadata.createdOn': -1
49
- }
50
- },
51
- {
52
- key: {
53
- 'metaMetadata.lastSaveDate': 1
54
- }
55
- },
56
- {
57
- key: {
58
- 'metaMetadata.lastSaveDate': -1
59
- }
60
- },
61
- {
62
- key: {
63
- 'redboxOid': 1
64
- }
65
- },
66
- {
67
- key: {
68
- 'redboxOid': -1
69
- }
70
- }
71
- ]
72
- }
73
- };
package/index.js DELETED
@@ -1,21 +0,0 @@
1
- const _ = require('lodash');
2
- var configService = require('../../../api/services/ConfigService.js');
3
-
4
- module.exports = function (sails) {
5
- return {
6
- initialize: function (cb) {
7
- // merge this Hook's configuration with RB's
8
- configService.mergeHookConfig('@researchdatabox/sails-hook-redbox-storage-mongo', sails.config);
9
- return cb();
10
- },
11
- //If each route middleware do not exist sails.lift will fail during hook.load()
12
- routes: {
13
- before: {},
14
- after: {}
15
- },
16
- configure: function () {
17
- },
18
- defaults: {
19
- }
20
- }
21
- };
@@ -1,21 +0,0 @@
1
- "use strict";
2
-
3
- module.exports = {
4
- require: "chai",
5
- recursive: true,
6
- slow: 2000,
7
- timeout: "20s",
8
- ui: "bdd",
9
- global: ["sails", "moment", "_", "expect"],
10
- };
11
-
12
- if (process.env.CI === "true") {
13
- console.log("Mocha running in CI.");
14
- // (For CI) Run mocha and write results to a junit format file:
15
- module.exports["reporter"] = "mocha-junit-reporter";
16
- module.exports["reporter-option"] = "mochaFile=/opt/redbox-portal/node_modules/@researchdatabox/sails-hook-redbox-storage-mongo/support/junit/unit-mocha.xml";
17
- } else {
18
- console.log("Mocha running in local dev.");
19
- // (For development) Run mocha and show the results on stdout:
20
- module.exports["reporter"] = "spec";
21
- }
@@ -1,63 +0,0 @@
1
- var sails = require("sails");
2
- var _ = require("lodash");
3
-
4
- global.moment = require("moment");
5
- global.sails = sails;
6
- global._ = _;
7
-
8
- /* global before, after */
9
-
10
- before(function (done) {
11
- import("chai").then((chai) => {
12
- global.chai = chai;
13
- global.should = chai.should();
14
- global.expect = chai.expect;
15
-
16
- // Set the timeout so that Sails has enough time to lift.
17
- this.timeout(60000);
18
- sails.lift({
19
- log: {
20
- level: "verbose",
21
- },
22
- hooks: {
23
- grunt: false,
24
- },
25
- models: {
26
- datastore: "mongodb",
27
- migrate: "drop",
28
- },
29
- datastores: {
30
- mongodb: {
31
- adapter: require('sails-mongo'),
32
- url: "mongodb://mongodb:27017/redbox-portal"
33
- },
34
- redboxStorage: {
35
- adapter: require('sails-mongo'),
36
- url: 'mongodb://mongodb:27017/redbox-storage'
37
- }
38
- },
39
- security: {
40
- csrf: false,
41
- },
42
- auth: {
43
- default: {
44
- local: {
45
- default: {
46
- token: "auth-default-local-default-token",
47
- },
48
- },
49
- },
50
- },
51
- }, function (err, server) {
52
- if (err) return done(err);
53
- done(err, sails);
54
- });
55
- });
56
- });
57
-
58
- after(function (done) {
59
- // here you can clear fixtures, etc.
60
- if (sails && _.isFunction(sails.lower)) {
61
- sails.lower(done);
62
- }
63
- });
@@ -1,121 +0,0 @@
1
- const service = require("../../../api/services/MongoStorageService");
2
-
3
-
4
- /* global describe, it, expect */
5
-
6
- async function sleep(ms = 300) {
7
- return new Promise(resolve => setTimeout(resolve, ms));
8
- }
9
-
10
- describe("Records", function () {
11
- [
12
- {
13
- // missing 'editPending' does not cause error
14
- args: {
15
- record: {
16
- metadata: {},
17
- "authorization": {
18
- "viewRoles": ["Admin", "Librarians"],
19
- "editRoles": ["Admin", "Librarians"],
20
- "view": ["example-2@redboxresearchdata.com.au"],
21
- "edit": [],
22
- "viewPending": ["example-1@redboxresearchdata.com.au"]
23
- }
24
- }
25
- },
26
- expected: {
27
- record: {
28
- "authorization": {
29
- "viewRoles": ["Admin", "Librarians"],
30
- "editRoles": ["Admin", "Librarians"],
31
- "view": ["example-2@redboxresearchdata.com.au", "example-1@redboxresearchdata.com.au"],
32
- "edit": [],
33
- "viewPending": [],
34
- "editPending": [],
35
- }
36
- }
37
- },
38
- },
39
- {
40
- // duplicate entries in pending array are transformed to in one entry in real access array
41
- args: {
42
- record: {
43
- metadata: {},
44
- "authorization": {
45
- "viewRoles": ["Admin", "Librarians"],
46
- "editRoles": ["Admin", "Librarians"],
47
- "view": ["example-2@redboxresearchdata.com.au"],
48
- "edit": [],
49
- "viewPending": [],
50
- "editPending": ["example-1@redboxresearchdata.com.au", "example-1@redboxresearchdata.com.au"],
51
- }
52
- }
53
- },
54
- expected: {
55
- record: {
56
- "authorization": {
57
- "viewRoles": ["Admin", "Librarians"],
58
- "editRoles": ["Admin", "Librarians"],
59
- "view": ["example-2@redboxresearchdata.com.au"],
60
- "edit": ["example-1@redboxresearchdata.com.au"],
61
- "viewPending": [],
62
- "editPending": [],
63
- }
64
- }
65
- },
66
- },
67
- {
68
- // same entry in real access array and pending is removed from pending array
69
- args: {
70
- record: {
71
- metadata: {},
72
- "authorization": {
73
- "viewRoles": ["Admin", "Librarians"],
74
- "editRoles": ["Admin", "Librarians"],
75
- "view": ["example-2@redboxresearchdata.com.au"],
76
- "edit": ["example-1@redboxresearchdata.com.au"],
77
- "viewPending": [],
78
- "editPending": ["example-1@redboxresearchdata.com.au"],
79
- }
80
- }
81
- },
82
- expected: {
83
- record: {
84
- "authorization": {
85
- "viewRoles": ["Admin", "Librarians"],
86
- "editRoles": ["Admin", "Librarians"],
87
- "view": ["example-2@redboxresearchdata.com.au"],
88
- "edit": ["example-1@redboxresearchdata.com.au"],
89
- "viewPending": [],
90
- "editPending": [],
91
- }
92
- }
93
- },
94
- }
95
- ].forEach(({args, expected}) => {
96
- it(`should provideUserAccessAndRemovePendingAccess as expected '${JSON.stringify(args)}' = ${JSON.stringify(expected)}`, async function () {
97
-
98
- const brand = 'testing-brand';
99
- const record = args.record;
100
- const recordType = "rdmp";
101
-
102
- const response = await service.create(brand, record, recordType);
103
-
104
- expect(response.oid).to.have.lengthOf(32);
105
-
106
- const oid = response.oid;
107
- const userid = "example-1@redboxresearchdata.com.au";
108
- const pendingValue = "example-1@redboxresearchdata.com.au";
109
-
110
- service.provideUserAccessAndRemovePendingAccess(oid, userid, pendingValue);
111
- // TODO: provideUserAccessAndRemovePendingAccess is a sync method, but it calls async methods.
112
- // So, wait for a bit for the method to complete.
113
- // This means that any errors may not be raised, as they occur in an untracked async function.
114
- await sleep(5000);
115
-
116
- const result = await service.getMeta(oid);
117
-
118
- expect(result.authorization).to.eql(expected.record.authorization);
119
- });
120
- });
121
- });
@@ -1,47 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const { Transform } = require('stream');
4
- const luxon_1 = require("luxon");
5
- class ExportJSONTransformer extends Transform {
6
- constructor(recordtype, modifiedBefore, modifiedAfter) {
7
- super();
8
- this.first = true;
9
- this.push(`{ "recordType": "${recordtype}",\n "dateGenerated": "${luxon_1.DateTime.now().toISO()}",\n`);
10
- if (!_.isEmpty(modifiedBefore) || !_.isEmpty(modifiedAfter)) {
11
- this.push(`"dateModifiedRange": ${this.getDateModifiedRangeObject(modifiedBefore, modifiedAfter)},\n`);
12
- }
13
- this.push(`"records":[ `);
14
- }
15
- getDateModifiedRangeObject(modifiedBefore, modifiedAfter) {
16
- let rangeObject = {};
17
- if (!_.isEmpty(modifiedAfter)) {
18
- rangeObject["from"] = modifiedAfter;
19
- }
20
- else {
21
- rangeObject["from"] = "";
22
- }
23
- if (!_.isEmpty(modifiedBefore)) {
24
- rangeObject["to"] = modifiedBefore;
25
- }
26
- else {
27
- rangeObject["to"] = "";
28
- }
29
- return JSON.stringify(rangeObject);
30
- }
31
- _transform(chunk, encoding, done) {
32
- let data = chunk.toString();
33
- if (!this.first) {
34
- this.push(",\n");
35
- }
36
- else {
37
- this.first = false;
38
- }
39
- this.push(data);
40
- done();
41
- }
42
- _flush(done) {
43
- this.push("]\n }");
44
- done();
45
- }
46
- }
47
- module.exports = ExportJSONTransformer;
package/tsconfig.json DELETED
@@ -1,39 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es6",
4
- "module": "commonjs",
5
- "moduleResolution": "node",
6
- "isolatedModules": false,
7
- "jsx": "react",
8
- "experimentalDecorators": true,
9
- "emitDecoratorMetadata": true,
10
- "declaration": false,
11
- "noImplicitAny": false,
12
- "noImplicitUseStrict": false,
13
- "removeComments": true,
14
- "noLib": false,
15
- "preserveConstEnums": true,
16
- "sourceMap": false,
17
- "outDir": "./",
18
- "rootDir": "./typescript"
19
- },
20
- "exclude": [
21
- "node_modules/**",
22
- "typings/browser/**",
23
- "typings/browser.d.ts",
24
- "test/integration/**/*.ts"
25
- ],
26
- "include": [
27
- "typescript/**/*.ts"
28
- ],
29
- "compileOnSave": true,
30
- "buildOnSave": false,
31
- "atom": {
32
- "rewriteTsconfig": false
33
- },
34
- "typeAcquisition": {
35
- "include": [
36
- "lodash"
37
- ]
38
- }
39
- }