@researchdatabox/sails-hook-redbox-storage-mongo 1.4.8
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.
- package/README.md +10 -0
- package/api/models/DeletedRecord.js +24 -0
- package/api/models/Record.js +41 -0
- package/api/models/RecordAudit.js +18 -0
- package/api/services/MongoStorageService.js +895 -0
- package/config/record.js +3 -0
- package/config/storage.js +73 -0
- package/index.js +21 -0
- package/package.json +53 -0
- package/test/bootstrap.js +65 -0
- package/transformer/ExportJSONTransformer.js +47 -0
- package/tsconfig.json +39 -0
- package/typescript/api/services/MongoStorageService.ts +958 -0
- package/typescript/transformer/ExportJSONTransformer.ts +65 -0
package/config/record.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@researchdatabox/sails-hook-redbox-storage-mongo",
|
|
3
|
+
"version": "1.4.8",
|
|
4
|
+
"description": "A MongoDB storage plugin for ReDBox.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"sails": {
|
|
7
|
+
"isHook": true
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/redbox-mint/sails-hook-redbox-storage-mongo.git"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"test": "NODE_ENV=test; mocha",
|
|
15
|
+
"installHook": "docker run -v $(pwd):/opt/sailshook qcifengineering/redbox-portal /bin/bash -c 'cd /opt/redbox-portal;yarn add \"file:/opt/sailshook\"'; docker commit $(docker ps -lq) redboxportalwithhook",
|
|
16
|
+
"runDev": "docker-compose -f support/development/docker-compose.yml up"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"sails",
|
|
20
|
+
"hook",
|
|
21
|
+
"redbox",
|
|
22
|
+
"redbox research",
|
|
23
|
+
"redbox storage",
|
|
24
|
+
"redbox mongodb"
|
|
25
|
+
],
|
|
26
|
+
"author": "QCIF Engineering dev@redboxresearchdata.com.au",
|
|
27
|
+
"license": "GPL-3.0",
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@researchdatabox/redbox-core-types": "^1.4.3",
|
|
30
|
+
"@types/chai": "^4.2.12",
|
|
31
|
+
"@types/lodash": "^4.14.159",
|
|
32
|
+
"@types/mocha": "^8.0.3",
|
|
33
|
+
"chai": "^4.2.0",
|
|
34
|
+
"fs": "0.0.1-security",
|
|
35
|
+
"mocha": "^8.1.1",
|
|
36
|
+
"moment": "^2.29.1",
|
|
37
|
+
"mongodb": "^6.2.0",
|
|
38
|
+
"rxjs": "^6.6.2",
|
|
39
|
+
"rxjs-compat": "^6.6.7",
|
|
40
|
+
"sails": "^1.2.5",
|
|
41
|
+
"stream": "0.0.2",
|
|
42
|
+
"typescript": "^5.2.2",
|
|
43
|
+
"util": "^0.12.4"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"json2csv": "^5.0.3",
|
|
47
|
+
"lodash": "^4.17.21",
|
|
48
|
+
"uuid": "8.3.0"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
var Sails = require('sails').Sails;
|
|
2
|
+
|
|
3
|
+
describe('Bootstrap tests ::', function() {
|
|
4
|
+
// Var to hold a running sails app instance
|
|
5
|
+
var _sails;
|
|
6
|
+
var appPath = '/opt/redbox-portal'
|
|
7
|
+
|
|
8
|
+
// Before running any tests, attempt to lift Sails
|
|
9
|
+
before(function (done) {
|
|
10
|
+
|
|
11
|
+
// Hook will timeout in 10 seconds
|
|
12
|
+
this.timeout(11000);
|
|
13
|
+
|
|
14
|
+
// Attempt to lift sails
|
|
15
|
+
Sails().lift({
|
|
16
|
+
appPath: appPath,
|
|
17
|
+
models: {
|
|
18
|
+
migrate: 'drop'
|
|
19
|
+
},
|
|
20
|
+
datastores: {
|
|
21
|
+
mongodb: {
|
|
22
|
+
adapter: require(appPath+'/node_modules/sails-mongo'),
|
|
23
|
+
url: "mongodb://mongodb:27017/redbox-portal"
|
|
24
|
+
},
|
|
25
|
+
redboxStorage: {
|
|
26
|
+
adapter: require(appPath+'/node_modules/sails-mongo'),
|
|
27
|
+
url: 'mongodb://mongodb:27017/redbox-storage'
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
globals: {
|
|
31
|
+
sails: true,
|
|
32
|
+
_: require('lodash'),
|
|
33
|
+
async: require('async'),
|
|
34
|
+
models: true,
|
|
35
|
+
services: true
|
|
36
|
+
},
|
|
37
|
+
hooks: {
|
|
38
|
+
// Skip grunt (unless your hook uses it)
|
|
39
|
+
"grunt": false
|
|
40
|
+
},
|
|
41
|
+
log: {level: "verbose"}
|
|
42
|
+
},function (err, __sails) {
|
|
43
|
+
if (err) return done(err);
|
|
44
|
+
_sails = __sails;
|
|
45
|
+
return done();
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// After tests are complete, lower Sails
|
|
50
|
+
after(function (done) {
|
|
51
|
+
|
|
52
|
+
// Lower Sails (if it successfully lifted)
|
|
53
|
+
if (_sails) {
|
|
54
|
+
return _sails.lower(done);
|
|
55
|
+
}
|
|
56
|
+
// Otherwise just return
|
|
57
|
+
return done();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Test that Sails can lift with the hook in place
|
|
61
|
+
it ('sails does not crash', function() {
|
|
62
|
+
return true;
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { Transform } = require('stream');
|
|
4
|
+
const moment = require("moment");
|
|
5
|
+
class ExportJSONTransformer extends Transform {
|
|
6
|
+
constructor(recordtype, modifiedBefore, modifiedAfter) {
|
|
7
|
+
super();
|
|
8
|
+
this.first = true;
|
|
9
|
+
this.push(`{ "recordType": "${recordtype}",\n "dateGenerated": "${moment().toISOString()}",\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
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
}
|