In my project I have several classes that look like this:
"use strict";
var exports = module.exports = {};
var SystemsDAO = require('./dao/systems/SystemsDAO.js');
var aop = require('./dbAOPUtils.js');
var Proxy = require('harmony-proxy');
var sqlite3 = require('sqlite3').verbose();
/* Wraps a SystemServiceObject and passes in a constructed
* DAO object as an argument to specified functions. */
exports.SystemsDAOIntercepter = function(obj) {
let handler = {
get(target, propKey, receiver) {
const origMethod = target[propKey];
return function(...args) {
console.log('systemDAOIntercepter: BEGIN');
// Create a reportsdao object and proxy it through an dbSQLiteConnectionIntercepter
// (So we don't have to create it for every single method)
var systemdao = new SystemsDAO('blah');
var proxSystemDAO = aop.dbSQLiteConnectionIntercepter(systemdao, sqlite3.OPEN_READONLY);
args.push(proxSystemDAO);
console.log('propKey: ' + target[propKey]);
let result = null;
result = origMethod.apply(this, args);
console.log('systemsDAOIntercepter: END');
return result;
};
}
};
return new Proxy(obj, handler);
};
Is it possible to pass in a type for an argument so that I only need a single DAOIntercepter class, and not one for each data access object?
I can see the part where I require()
the SystemsDAO
working for this by passing the file name, but as for instantiation of that class, I can't really see how it would be possible to do that.