-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
78 lines (60 loc) · 2.24 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* Index File for OST Storage
*/
'use strict';
const rootPrefix = '.',
version = require(rootPrefix + '/package.json').version,
OSTBase = require('@ostdotcom/base'),
coreConstant = require(rootPrefix + '/config/coreConstant');
const InstanceComposer = OSTBase.InstanceComposer;
require(rootPrefix + '/services/dynamodb/api');
require(rootPrefix + '/services/autoScale/api');
require(rootPrefix + '/lib/models/shardHelper');
const OSTStorage = function(configStrategy) {
const oThis = this,
instanceComposer = (oThis.ic = new InstanceComposer(configStrategy)),
DynamodbShardHelper = instanceComposer.getShadowedClassFor(coreConstant.icNameSpace, 'DynamodbShardHelper'),
dynamoDBApiService = instanceComposer.getInstanceFor(coreConstant.icNameSpace, 'dynamoDBApiService'),
autoScaleApiService = instanceComposer.getInstanceFor(coreConstant.icNameSpace, 'autoScaleApiService');
if (!configStrategy) {
throw 'Mandatory argument configStrategy missing';
}
oThis.version = version;
const model = (oThis.model = {});
model.DynamodbShardHelper = DynamodbShardHelper;
oThis.dynamoDBService = dynamoDBApiService;
oThis.autoScalingService = autoScaleApiService;
};
const getInstanceKey = function(configStrategy) {
return [
configStrategy.storage.apiVersion,
configStrategy.storage.apiKey,
configStrategy.storage.region,
configStrategy.storage.endpoint,
configStrategy.storage.enableSsl,
configStrategy.storage.autoScaling.apiVersion,
configStrategy.storage.autoScaling.apiKey,
configStrategy.storage.autoScaling.region,
configStrategy.storage.autoScaling.endpoint,
configStrategy.storage.autoScaling.enableSsl
].join('-');
};
const instanceMap = {};
const Factory = function() {};
Factory.prototype = {
getInstance: function(configStrategy) {
// check if instance already present
let instanceKey = getInstanceKey(configStrategy),
_instance = instanceMap[instanceKey];
if (!_instance) {
_instance = new OSTStorage(configStrategy);
instanceMap[instanceKey] = _instance;
}
return _instance;
}
};
const factory = new Factory();
OSTStorage.getInstance = function() {
return factory.getInstance.apply(factory, arguments);
};
module.exports = OSTStorage;