-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
140 lines (120 loc) · 3.03 KB
/
Copy pathindex.js
File metadata and controls
140 lines (120 loc) · 3.03 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
* UniMapperJS - universal object mapper for SQL and noSQL databases
* @author Roman Jámbor
*/
const {StringType} = require("./src/types/StringType");
const {NumberType} = require("./src/types/NumberType");
const {BooleanType} = require("./src/types/BooleanType");
const {DateType} = require("./src/types/DateType");
const {UuidType} = require("./src/types/UuidType");
const {ForeignType} = require("./src/types/ForeignType");
const {Domain} = require("./src/Domain");
/**
* Object with type returning getters
* @type {{string: StringType, number: NumberType, boolean: BooleanType, date: DateType, uuid: UuidType}}
*/
const type = {
/** @type StringType */
string: null,
/** @type NumberType */
number: null,
/** @type BooleanType */
boolean: null,
/** @type DateType */
date: null,
/** @type UuidType */
uuid: null
};
// StringType
Object.defineProperty(type, "string", {
get: function () {
return new StringType();
}
});
// NumberType
Object.defineProperty(type, "number", {
get: function () {
return new NumberType();
}
});
// BooleanType
Object.defineProperty(type, "boolean", {
get: function () {
return new BooleanType();
}
});
// DateType
Object.defineProperty(type, "date", {
get: function () {
return new DateType();
}
});
// DateType
Object.defineProperty(type, "uuid", {
get: function () {
return new UuidType();
}
});
// ForeignType
Object.defineProperty(type, "foreign", {
value: function (entity) {
return new ForeignType(entity);
}
});
const $fs = require("fs");
const $path = require("path");
function goThroughDir(dir, action) {
let list = $fs.readdirSync(dir);
list.forEach(function (fileName) {
if (fileName.charAt(0) === "." || fileName === "node_modules") return;
let file = $path.resolve(dir, fileName);
file = file.charAt(0).toLowerCase() + file.slice(1);
let stat = $fs.lstatSync(file);
if (stat) {
if (stat.isDirectory()) {
goThroughDir(file, action);
} else if (stat.isFile()) {
action(file);
}
}
});
}
module.exports = {
type: type,
/**
* @type {UnitOfWork}
*/
UnitOfWork: require("./src/UnitOfWork").UnitOfWork,
/**
*
* @param {Object} adapter
* @param {String | Object} connectionInfo
* @returns {Domain}
*/
createDomain: function createDomain(adapter, connectionInfo) {
return new Domain(adapter, connectionInfo);
},
/**
* Init entities from given path
* @param path
*/
initEntitiesFrom(path) {
path = $path.resolve(path);
//path = path.charAt(0).toLowerCase() + path.slice(1); // lowercase drive letter on windows
goThroughDir(path, (file) => {
if (file.slice(-3) !== ".js" || file.indexOf("seed") !== -1) return;
file = "./" + $path.relative(__dirname, file).replace(/\\/g, "/");
/*let c = */require(file);
// console.log(c);
// let p = $path.parse(file);
// let cls = c[p.base] || c["default"] || c;
// if (Object.getPrototypeOf(cls) === Entity) { // extends from entity
//
// }
});
},
async immediate() {
return new Promise(r => setImmediate(r));
// return new Promise(r => process.nextTick(r));
}
};