@steedos/objectql 3.0.13-beta.8 → 3.0.13
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/lib/actions/field_updates.js +84 -153
- package/lib/actions/field_updates.js.map +1 -1
- package/lib/actions/index.js +1 -1
- package/lib/actions/workflow_notifications.js +50 -111
- package/lib/actions/workflow_notifications.js.map +1 -1
- package/lib/actions/workflow_outbound_messages.js +43 -94
- package/lib/actions/workflow_outbound_messages.js.map +1 -1
- package/lib/actions/workflow_rule.js +80 -177
- package/lib/actions/workflow_rule.js.map +1 -1
- package/lib/broker.js +19 -49
- package/lib/broker.js.map +1 -1
- package/lib/driver/field-encrytion/index.js +1 -1
- package/lib/driver/field-encrytion/mongosharedconst.js +17 -17
- package/lib/driver/field-encrytion/mongosharedconst.js.map +1 -1
- package/lib/driver/format.js +3 -3
- package/lib/driver/format.js.map +1 -1
- package/lib/driver/index.js +1 -1
- package/lib/driver/metadata.js +286 -387
- package/lib/driver/metadata.js.map +1 -1
- package/lib/driver/metadataOld.js +104 -105
- package/lib/driver/metadataOld.js.map +1 -1
- package/lib/driver/meteorMongo.js +5 -8
- package/lib/driver/meteorMongo.js.map +1 -1
- package/lib/driver/mongo.js +321 -506
- package/lib/driver/mongo.js.map +1 -1
- package/lib/driver/mysql.js +16 -20
- package/lib/driver/mysql.js.map +1 -1
- package/lib/driver/oracle.js +25 -38
- package/lib/driver/oracle.js.map +1 -1
- package/lib/driver/postgres.js +16 -20
- package/lib/driver/postgres.js.map +1 -1
- package/lib/driver/sqlite3.js +15 -19
- package/lib/driver/sqlite3.js.map +1 -1
- package/lib/driver/sqlserver.js +20 -33
- package/lib/driver/sqlserver.js.map +1 -1
- package/lib/errors/index.js +10 -11
- package/lib/errors/index.js.map +1 -1
- package/lib/formula/core.js +307 -594
- package/lib/formula/core.js.map +1 -1
- package/lib/formula/field_formula.js +80 -126
- package/lib/formula/field_formula.js.map +1 -1
- package/lib/formula/index.js +56 -97
- package/lib/formula/index.js.map +1 -1
- package/lib/formula/params.js +11 -11
- package/lib/formula/params.js.map +1 -1
- package/lib/formula/recompute.js +41 -166
- package/lib/formula/recompute.js.map +1 -1
- package/lib/formula/simple_params.js +12 -12
- package/lib/formula/simple_params.js.map +1 -1
- package/lib/formula/util.js +43 -67
- package/lib/formula/util.js.map +1 -1
- package/lib/functions/function.js +68 -86
- package/lib/functions/function.js.map +1 -1
- package/lib/index.js +3 -3
- package/lib/index.js.map +1 -1
- package/lib/services/datasourceServiceFactory.js +77 -111
- package/lib/services/datasourceServiceFactory.js.map +1 -1
- package/lib/services/index.js +3 -3
- package/lib/services/index.js.map +1 -1
- package/lib/summary/core.js +162 -355
- package/lib/summary/core.js.map +1 -1
- package/lib/summary/field_summary.js +44 -71
- package/lib/summary/field_summary.js.map +1 -1
- package/lib/summary/index.js +65 -80
- package/lib/summary/index.js.map +1 -1
- package/lib/summary/recompute.js +19 -47
- package/lib/summary/recompute.js.map +1 -1
- package/lib/triggers/trigger.js +108 -142
- package/lib/triggers/trigger.js.map +1 -1
- package/lib/ts-types/index.js +1 -1
- package/lib/typeorm/driver.js +250 -450
- package/lib/typeorm/driver.js.map +1 -1
- package/lib/typeorm/index.js +1 -1
- package/lib/typeorm/util.js +28 -28
- package/lib/typeorm/util.js.map +1 -1
- package/lib/types/action.js +24 -33
- package/lib/types/action.js.map +1 -1
- package/lib/types/app.js +210 -355
- package/lib/types/app.js.map +1 -1
- package/lib/types/connection.js +42 -78
- package/lib/types/connection.js.map +1 -1
- package/lib/types/dashboard.js +56 -77
- package/lib/types/dashboard.js.map +1 -1
- package/lib/types/datasource.js +359 -705
- package/lib/types/datasource.js.map +1 -1
- package/lib/types/defaultValue.js +53 -65
- package/lib/types/defaultValue.js.map +1 -1
- package/lib/types/field.js +165 -137
- package/lib/types/field.js.map +1 -1
- package/lib/types/field_permission.js +35 -66
- package/lib/types/field_permission.js.map +1 -1
- package/lib/types/index.js +1 -1
- package/lib/types/list_view.d.ts +1 -0
- package/lib/types/list_view.js +37 -43
- package/lib/types/list_view.js.map +1 -1
- package/lib/types/metadata.js +6 -6
- package/lib/types/metadata.js.map +1 -1
- package/lib/types/method_base.js +95 -128
- package/lib/types/method_base.js.map +1 -1
- package/lib/types/object.js +2034 -3015
- package/lib/types/object.js.map +1 -1
- package/lib/types/object_events.js +24 -37
- package/lib/types/object_events.js.map +1 -1
- package/lib/types/object_layouts.js +15 -38
- package/lib/types/object_layouts.js.map +1 -1
- package/lib/types/object_permission.js +99 -85
- package/lib/types/object_permission.js.map +1 -1
- package/lib/types/report.js +70 -98
- package/lib/types/report.js.map +1 -1
- package/lib/types/restrictionRule.js +47 -96
- package/lib/types/restrictionRule.js.map +1 -1
- package/lib/types/schema.js +115 -177
- package/lib/types/schema.js.map +1 -1
- package/lib/types/shareRule.js +53 -102
- package/lib/types/shareRule.js.map +1 -1
- package/lib/types/trigger.js +43 -56
- package/lib/types/trigger.js.map +1 -1
- package/lib/types/validation_rules.js +18 -56
- package/lib/types/validation_rules.js.map +1 -1
- package/lib/util/convert.js +24 -24
- package/lib/util/convert.js.map +1 -1
- package/lib/util/field.js +16 -28
- package/lib/util/field.js.map +1 -1
- package/lib/util/function_expression.js +7 -8
- package/lib/util/function_expression.js.map +1 -1
- package/lib/util/index.d.ts +1 -0
- package/lib/util/index.js +80 -97
- package/lib/util/index.js.map +1 -1
- package/lib/util/locale.js +4 -4
- package/lib/util/locale.js.map +1 -1
- package/lib/util/perf.d.ts +11 -0
- package/lib/util/perf.js +49 -0
- package/lib/util/perf.js.map +1 -0
- package/lib/util/permission_shares.js +7 -7
- package/lib/util/permission_shares.js.map +1 -1
- package/lib/util/suffix.js +19 -19
- package/lib/util/suffix.js.map +1 -1
- package/lib/util/transform.js +1 -1
- package/lib/validators/index.js +10 -10
- package/lib/validators/index.js.map +1 -1
- package/package.json +13 -14
package/lib/typeorm/driver.js
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SteedosTypeormDriver = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function SteedosTypeormDriver(config) {
|
|
13
|
-
this._config = config;
|
|
14
|
-
this._url = config.url;
|
|
15
|
-
}
|
|
16
|
-
SteedosTypeormDriver.prototype.getSupportedColumnTypes = function () {
|
|
4
|
+
const driver_1 = require("../driver");
|
|
5
|
+
const typeorm_1 = require("typeorm");
|
|
6
|
+
const filters_1 = require("@steedos/filters");
|
|
7
|
+
const odata_v4_typeorm_1 = require("@steedos/odata-v4-typeorm");
|
|
8
|
+
const typeorm_2 = require("../typeorm");
|
|
9
|
+
const _ = require("underscore");
|
|
10
|
+
class SteedosTypeormDriver {
|
|
11
|
+
getSupportedColumnTypes() {
|
|
17
12
|
return [
|
|
18
13
|
driver_1.SteedosFieldDBType.varchar,
|
|
19
14
|
driver_1.SteedosFieldDBType.text,
|
|
@@ -21,82 +16,51 @@ var SteedosTypeormDriver = (function () {
|
|
|
21
16
|
driver_1.SteedosFieldDBType.date,
|
|
22
17
|
driver_1.SteedosFieldDBType.dateTime
|
|
23
18
|
];
|
|
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
|
-
return
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
case 2: return [2];
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
SteedosTypeormDriver.prototype.createQueryRunner = function () {
|
|
75
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
76
|
-
var _a;
|
|
77
|
-
return tslib_1.__generator(this, function (_b) {
|
|
78
|
-
switch (_b.label) {
|
|
79
|
-
case 0:
|
|
80
|
-
if (this._queryRunner) {
|
|
81
|
-
return [2, this._queryRunner];
|
|
82
|
-
}
|
|
83
|
-
if (!!this._client) return [3, 2];
|
|
84
|
-
return [4, this.connect()];
|
|
85
|
-
case 1:
|
|
86
|
-
_b.sent();
|
|
87
|
-
_b.label = 2;
|
|
88
|
-
case 2:
|
|
89
|
-
_a = this;
|
|
90
|
-
return [4, this._client.driver.createQueryRunner("master")];
|
|
91
|
-
case 3:
|
|
92
|
-
_a._queryRunner = _b.sent();
|
|
93
|
-
return [2, this._queryRunner];
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
|
-
SteedosTypeormDriver.prototype.formatFiltersToTypeormQuery = function (filters) {
|
|
99
|
-
var odataQuery = "";
|
|
19
|
+
}
|
|
20
|
+
_url;
|
|
21
|
+
_client;
|
|
22
|
+
databaseVersion;
|
|
23
|
+
_config;
|
|
24
|
+
get config() {
|
|
25
|
+
return this._config;
|
|
26
|
+
}
|
|
27
|
+
_queryRunner;
|
|
28
|
+
_entities;
|
|
29
|
+
constructor(config) {
|
|
30
|
+
this._config = config;
|
|
31
|
+
this._url = config.url;
|
|
32
|
+
}
|
|
33
|
+
async connect(reconnect) {
|
|
34
|
+
if (!this._entities) {
|
|
35
|
+
throw new Error("Entities must be registered before connect");
|
|
36
|
+
}
|
|
37
|
+
if (!this._client || reconnect) {
|
|
38
|
+
let options = this.getConnectionOptions();
|
|
39
|
+
this._client = await (0, typeorm_1.createConnection)(options);
|
|
40
|
+
this.databaseVersion = await this.getDatabaseVersion();
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async close() {
|
|
45
|
+
if (this._client) {
|
|
46
|
+
await this._client.close();
|
|
47
|
+
this._client = null;
|
|
48
|
+
this._queryRunner = null;
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async createQueryRunner() {
|
|
53
|
+
if (this._queryRunner) {
|
|
54
|
+
return this._queryRunner;
|
|
55
|
+
}
|
|
56
|
+
if (!this._client) {
|
|
57
|
+
await this.connect();
|
|
58
|
+
}
|
|
59
|
+
this._queryRunner = await this._client.driver.createQueryRunner("master");
|
|
60
|
+
return this._queryRunner;
|
|
61
|
+
}
|
|
62
|
+
formatFiltersToTypeormQuery(filters) {
|
|
63
|
+
let odataQuery = "";
|
|
100
64
|
if (_.isString(filters)) {
|
|
101
65
|
odataQuery = filters;
|
|
102
66
|
}
|
|
@@ -106,9 +70,9 @@ var SteedosTypeormDriver = (function () {
|
|
|
106
70
|
return {
|
|
107
71
|
$filter: odataQuery
|
|
108
72
|
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
73
|
+
}
|
|
74
|
+
getTypeormFilters(filters) {
|
|
75
|
+
let emptyFilters = {};
|
|
112
76
|
if (_.isUndefined(filters)) {
|
|
113
77
|
return emptyFilters;
|
|
114
78
|
}
|
|
@@ -118,26 +82,26 @@ var SteedosTypeormDriver = (function () {
|
|
|
118
82
|
if (_.isArray(filters) && !filters.length) {
|
|
119
83
|
return emptyFilters;
|
|
120
84
|
}
|
|
121
|
-
|
|
85
|
+
let typeormFilters = this.formatFiltersToTypeormQuery(filters);
|
|
122
86
|
return typeormFilters;
|
|
123
|
-
}
|
|
124
|
-
|
|
87
|
+
}
|
|
88
|
+
getTypeormFieldsOptions(fields, primaryKeys) {
|
|
125
89
|
if (typeof fields === "string") {
|
|
126
|
-
fields = fields.split(",").map(
|
|
90
|
+
fields = fields.split(",").map((n) => { return n.trim(); });
|
|
127
91
|
}
|
|
128
92
|
if (!(fields && fields.length)) {
|
|
129
93
|
return {};
|
|
130
94
|
}
|
|
131
|
-
|
|
132
|
-
fields.forEach(
|
|
95
|
+
let projection = "";
|
|
96
|
+
fields.forEach((field) => {
|
|
133
97
|
if (field && primaryKeys.indexOf(field) < 0) {
|
|
134
|
-
projection +=
|
|
98
|
+
projection += `${field},`;
|
|
135
99
|
}
|
|
136
100
|
});
|
|
137
101
|
projection = projection.replace(/,$/g, "");
|
|
138
102
|
if (primaryKeys && primaryKeys.length) {
|
|
139
103
|
if (projection) {
|
|
140
|
-
projection =
|
|
104
|
+
projection = `${primaryKeys.join(",")},${projection}`;
|
|
141
105
|
}
|
|
142
106
|
else {
|
|
143
107
|
projection = primaryKeys.join(",");
|
|
@@ -146,9 +110,9 @@ var SteedosTypeormDriver = (function () {
|
|
|
146
110
|
return {
|
|
147
111
|
$select: projection
|
|
148
112
|
};
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
113
|
+
}
|
|
114
|
+
getTypeormSortOptions(sort, defaultSort) {
|
|
115
|
+
let result = {};
|
|
152
116
|
if (!(sort && typeof sort === "string" && sort.length)) {
|
|
153
117
|
if (defaultSort) {
|
|
154
118
|
sort = defaultSort;
|
|
@@ -157,11 +121,11 @@ var SteedosTypeormDriver = (function () {
|
|
|
157
121
|
return result;
|
|
158
122
|
}
|
|
159
123
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
arraySort.forEach(
|
|
124
|
+
let arraySort = sort.split(",").map((n) => { return n.trim(); });
|
|
125
|
+
let stringSort = "";
|
|
126
|
+
arraySort.forEach((n) => {
|
|
163
127
|
if (n) {
|
|
164
|
-
stringSort +=
|
|
128
|
+
stringSort += `${n},`;
|
|
165
129
|
}
|
|
166
130
|
});
|
|
167
131
|
stringSort = stringSort.replace(/,$/g, "");
|
|
@@ -171,11 +135,9 @@ var SteedosTypeormDriver = (function () {
|
|
|
171
135
|
};
|
|
172
136
|
}
|
|
173
137
|
return result;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if (skip === void 0) { skip = 0; }
|
|
178
|
-
var result = {};
|
|
138
|
+
}
|
|
139
|
+
getTypeormTopAndSkipOptions(top = 0, skip = 0) {
|
|
140
|
+
let result = {};
|
|
179
141
|
if (top > 0) {
|
|
180
142
|
result.$top = top;
|
|
181
143
|
}
|
|
@@ -183,350 +145,188 @@ var SteedosTypeormDriver = (function () {
|
|
|
183
145
|
result.$skip = skip;
|
|
184
146
|
}
|
|
185
147
|
return result;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
return [4, (0, odata_v4_typeorm_1.executeQuery)(queryBuilder, queryOptions, sqlOptions)];
|
|
209
|
-
case 2:
|
|
210
|
-
result = _a.sent();
|
|
211
|
-
return [2, result.map(function (item) {
|
|
212
|
-
if (primaryKeys) {
|
|
213
|
-
if (primaryKeys.length === 1) {
|
|
214
|
-
var key = primaryKeys[0];
|
|
215
|
-
item['_id'] = item[key] ? item[key] : "";
|
|
216
|
-
}
|
|
217
|
-
else if (primaryKeys.length > 1) {
|
|
218
|
-
item['_ids'] = {};
|
|
219
|
-
primaryKeys.forEach(function (key) {
|
|
220
|
-
item['_ids'][key] = item[key] ? item[key] : "";
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
return item;
|
|
225
|
-
})];
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
};
|
|
230
|
-
SteedosTypeormDriver.prototype.count = function (tableName, query) {
|
|
231
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
232
|
-
var entity, filterQuery, repository, queryBuilder, result;
|
|
233
|
-
return tslib_1.__generator(this, function (_a) {
|
|
234
|
-
switch (_a.label) {
|
|
235
|
-
case 0: return [4, this.connect()];
|
|
236
|
-
case 1:
|
|
237
|
-
_a.sent();
|
|
238
|
-
entity = this._entities[tableName];
|
|
239
|
-
if (!entity) {
|
|
240
|
-
throw new Error("".concat(tableName, " is not exist or not registered in the connect"));
|
|
241
|
-
}
|
|
242
|
-
filterQuery = this.getTypeormFilters(query.filters);
|
|
243
|
-
repository = this._client.getRepository(entity);
|
|
244
|
-
queryBuilder = repository.createQueryBuilder(tableName);
|
|
245
|
-
return [4, (0, odata_v4_typeorm_1.executeCountQuery)(queryBuilder, filterQuery, { alias: tableName, type: this.sqlLang })];
|
|
246
|
-
case 2:
|
|
247
|
-
result = _a.sent();
|
|
248
|
-
return [2, result];
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
});
|
|
252
|
-
};
|
|
253
|
-
SteedosTypeormDriver.prototype.findOne = function (tableName, id, query) {
|
|
254
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
255
|
-
var entity, repository, primaryKeys, filterQuery, projection, queryBuilder, result, key;
|
|
256
|
-
return tslib_1.__generator(this, function (_a) {
|
|
257
|
-
switch (_a.label) {
|
|
258
|
-
case 0: return [4, this.connect()];
|
|
259
|
-
case 1:
|
|
260
|
-
_a.sent();
|
|
261
|
-
entity = this._entities[tableName];
|
|
262
|
-
if (!entity) {
|
|
263
|
-
throw new Error("".concat(tableName, " is not exist or not registered in the connect"));
|
|
264
|
-
}
|
|
265
|
-
repository = this._client.getRepository(entity);
|
|
266
|
-
primaryKeys = (0, typeorm_2.getPrimaryKeys)(repository);
|
|
267
|
-
filterQuery = this.getTypeormFilters([[primaryKeys[0], "=", id]]);
|
|
268
|
-
projection = this.getTypeormFieldsOptions(query ? query.fields : [], primaryKeys);
|
|
269
|
-
queryBuilder = repository.createQueryBuilder(tableName);
|
|
270
|
-
return [4, (0, odata_v4_typeorm_1.executeQuery)(queryBuilder, Object.assign(filterQuery, projection), { alias: tableName, type: this.sqlLang })];
|
|
271
|
-
case 2:
|
|
272
|
-
result = _a.sent();
|
|
273
|
-
if (result && result[0]) {
|
|
274
|
-
if (primaryKeys) {
|
|
275
|
-
if (primaryKeys.length === 1) {
|
|
276
|
-
key = primaryKeys[0];
|
|
277
|
-
result[0]['_id'] = result[0][key] ? result[0][key] : "";
|
|
278
|
-
}
|
|
279
|
-
else if (primaryKeys.length > 1) {
|
|
280
|
-
result[0]['_ids'] = {};
|
|
281
|
-
primaryKeys.forEach(function (key) {
|
|
282
|
-
result[0]['_ids'][key] = result[0][key] ? result[0][key] : "";
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
return [2, result[0]];
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
return [2, null];
|
|
290
|
-
}
|
|
291
|
-
return [2];
|
|
292
|
-
}
|
|
293
|
-
});
|
|
294
|
-
});
|
|
295
|
-
};
|
|
296
|
-
SteedosTypeormDriver.prototype.run = function (sql, param) {
|
|
297
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
298
|
-
var queryRunner;
|
|
299
|
-
return tslib_1.__generator(this, function (_a) {
|
|
300
|
-
switch (_a.label) {
|
|
301
|
-
case 0: return [4, this.createQueryRunner()];
|
|
302
|
-
case 1:
|
|
303
|
-
queryRunner = _a.sent();
|
|
304
|
-
_a.label = 2;
|
|
305
|
-
case 2:
|
|
306
|
-
_a.trys.push([2, , 3, 8]);
|
|
307
|
-
return [2, queryRunner.query(sql, param)];
|
|
308
|
-
case 3:
|
|
309
|
-
if (!(queryRunner !== this._queryRunner)) return [3, 5];
|
|
310
|
-
return [4, queryRunner.release()];
|
|
311
|
-
case 4:
|
|
312
|
-
_a.sent();
|
|
313
|
-
_a.label = 5;
|
|
314
|
-
case 5:
|
|
315
|
-
if (!(this._client.driver.options.type === "sqljs")) return [3, 7];
|
|
316
|
-
return [4, this._client.driver.autoSave()];
|
|
317
|
-
case 6:
|
|
318
|
-
_a.sent();
|
|
319
|
-
_a.label = 7;
|
|
320
|
-
case 7: return [7];
|
|
321
|
-
case 8: return [2];
|
|
322
|
-
}
|
|
323
|
-
});
|
|
324
|
-
});
|
|
325
|
-
};
|
|
326
|
-
SteedosTypeormDriver.prototype.insert = function (tableName, data) {
|
|
327
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
328
|
-
var entity, repository, result, primaryKeys, id;
|
|
329
|
-
return tslib_1.__generator(this, function (_a) {
|
|
330
|
-
switch (_a.label) {
|
|
331
|
-
case 0: return [4, this.connect()];
|
|
332
|
-
case 1:
|
|
333
|
-
_a.sent();
|
|
334
|
-
entity = this._entities[tableName];
|
|
335
|
-
if (!entity) {
|
|
336
|
-
throw new Error("".concat(tableName, " is not exist or not registered in the connect"));
|
|
337
|
-
}
|
|
338
|
-
repository = this._client.getRepository(entity);
|
|
339
|
-
return [4, repository.insert(data)];
|
|
340
|
-
case 2:
|
|
341
|
-
result = _a.sent();
|
|
342
|
-
if (!(result.identifiers && result.identifiers.length)) return [3, 4];
|
|
343
|
-
primaryKeys = (0, typeorm_2.getPrimaryKeys)(repository);
|
|
344
|
-
if (!(primaryKeys && primaryKeys.length === 1)) return [3, 4];
|
|
345
|
-
id = primaryKeys[0] && result.identifiers[0][primaryKeys[0]];
|
|
346
|
-
if (!id) return [3, 4];
|
|
347
|
-
return [4, this.findOne(tableName, id)];
|
|
348
|
-
case 3: return [2, _a.sent()];
|
|
349
|
-
case 4: return [2];
|
|
148
|
+
}
|
|
149
|
+
async find(tableName, query) {
|
|
150
|
+
await this.connect();
|
|
151
|
+
let entity = this._entities[tableName];
|
|
152
|
+
if (!entity) {
|
|
153
|
+
throw new Error(`${tableName} is not exist or not registered in the connect`);
|
|
154
|
+
}
|
|
155
|
+
let repository = this._client.getRepository(entity);
|
|
156
|
+
let primaryKeys = (0, typeorm_2.getPrimaryKeys)(repository);
|
|
157
|
+
let filterQuery = this.getTypeormFilters(query.filters);
|
|
158
|
+
let projection = this.getTypeormFieldsOptions(query.fields, primaryKeys);
|
|
159
|
+
let sort = this.getTypeormSortOptions(query.sort);
|
|
160
|
+
let topAndSkip = this.getTypeormTopAndSkipOptions(query.top, query.skip);
|
|
161
|
+
const queryBuilder = repository.createQueryBuilder(tableName);
|
|
162
|
+
let queryOptions = Object.assign(filterQuery, projection, sort, topAndSkip);
|
|
163
|
+
let sqlOptions = { alias: tableName, type: this.sqlLang, version: this.databaseVersion };
|
|
164
|
+
let result = await (0, odata_v4_typeorm_1.executeQuery)(queryBuilder, queryOptions, sqlOptions);
|
|
165
|
+
return result.map((item) => {
|
|
166
|
+
if (primaryKeys) {
|
|
167
|
+
if (primaryKeys.length === 1) {
|
|
168
|
+
let key = primaryKeys[0];
|
|
169
|
+
item['_id'] = item[key] ? item[key] : "";
|
|
350
170
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
var entity, fields, repository;
|
|
357
|
-
return tslib_1.__generator(this, function (_a) {
|
|
358
|
-
switch (_a.label) {
|
|
359
|
-
case 0: return [4, this.connect()];
|
|
360
|
-
case 1:
|
|
361
|
-
_a.sent();
|
|
362
|
-
entity = this._entities[tableName];
|
|
363
|
-
if (!entity) {
|
|
364
|
-
throw new Error("".concat(tableName, " is not exist or not registered in the connect"));
|
|
365
|
-
}
|
|
366
|
-
fields = Object.keys(data);
|
|
367
|
-
if (!fields.length) {
|
|
368
|
-
throw new Error("the params 'data' must not be empty");
|
|
369
|
-
}
|
|
370
|
-
repository = this._client.getRepository(entity);
|
|
371
|
-
return [4, repository.update(id, data)];
|
|
372
|
-
case 2:
|
|
373
|
-
_a.sent();
|
|
374
|
-
return [4, this.findOne(tableName, id)];
|
|
375
|
-
case 3: return [2, _a.sent()];
|
|
171
|
+
else if (primaryKeys.length > 1) {
|
|
172
|
+
item['_ids'] = {};
|
|
173
|
+
primaryKeys.forEach((key) => {
|
|
174
|
+
item['_ids'][key] = item[key] ? item[key] : "";
|
|
175
|
+
});
|
|
376
176
|
}
|
|
377
|
-
}
|
|
177
|
+
}
|
|
178
|
+
return item;
|
|
378
179
|
});
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
180
|
+
}
|
|
181
|
+
async count(tableName, query) {
|
|
182
|
+
await this.connect();
|
|
183
|
+
let entity = this._entities[tableName];
|
|
184
|
+
if (!entity) {
|
|
185
|
+
throw new Error(`${tableName} is not exist or not registered in the connect`);
|
|
186
|
+
}
|
|
187
|
+
let filterQuery = this.getTypeormFilters(query.filters);
|
|
188
|
+
let repository = this._client.getRepository(entity);
|
|
189
|
+
const queryBuilder = repository.createQueryBuilder(tableName);
|
|
190
|
+
let result = await (0, odata_v4_typeorm_1.executeCountQuery)(queryBuilder, filterQuery, { alias: tableName, type: this.sqlLang });
|
|
191
|
+
return result;
|
|
192
|
+
}
|
|
193
|
+
async findOne(tableName, id, query) {
|
|
194
|
+
await this.connect();
|
|
195
|
+
let entity = this._entities[tableName];
|
|
196
|
+
if (!entity) {
|
|
197
|
+
throw new Error(`${tableName} is not exist or not registered in the connect`);
|
|
198
|
+
}
|
|
199
|
+
let repository = this._client.getRepository(entity);
|
|
200
|
+
let primaryKeys = (0, typeorm_2.getPrimaryKeys)(repository);
|
|
201
|
+
let filterQuery = this.getTypeormFilters([[primaryKeys[0], "=", id]]);
|
|
202
|
+
let projection = this.getTypeormFieldsOptions(query ? query.fields : [], primaryKeys);
|
|
203
|
+
const queryBuilder = repository.createQueryBuilder(tableName);
|
|
204
|
+
let result = await (0, odata_v4_typeorm_1.executeQuery)(queryBuilder, Object.assign(filterQuery, projection), { alias: tableName, type: this.sqlLang });
|
|
205
|
+
if (result && result[0]) {
|
|
206
|
+
if (primaryKeys) {
|
|
207
|
+
if (primaryKeys.length === 1) {
|
|
208
|
+
let key = primaryKeys[0];
|
|
209
|
+
result[0]['_id'] = result[0][key] ? result[0][key] : "";
|
|
402
210
|
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
var entity, repository;
|
|
409
|
-
return tslib_1.__generator(this, function (_a) {
|
|
410
|
-
switch (_a.label) {
|
|
411
|
-
case 0: return [4, this.connect()];
|
|
412
|
-
case 1:
|
|
413
|
-
_a.sent();
|
|
414
|
-
entity = this._entities[tableName];
|
|
415
|
-
if (!entity) {
|
|
416
|
-
throw new Error("".concat(tableName, " is not exist or not registered in the connect"));
|
|
417
|
-
}
|
|
418
|
-
repository = this._client.getRepository(entity);
|
|
419
|
-
return [4, repository.delete(id)];
|
|
420
|
-
case 2:
|
|
421
|
-
_a.sent();
|
|
422
|
-
return [2];
|
|
211
|
+
else if (primaryKeys.length > 1) {
|
|
212
|
+
result[0]['_ids'] = {};
|
|
213
|
+
primaryKeys.forEach((key) => {
|
|
214
|
+
result[0]['_ids'][key] = result[0][key] ? result[0][key] : "";
|
|
215
|
+
});
|
|
423
216
|
}
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
});
|
|
460
|
-
});
|
|
461
|
-
};
|
|
462
|
-
SteedosTypeormDriver.prototype.dropEntities = function () {
|
|
463
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
464
|
-
var objects;
|
|
465
|
-
return tslib_1.__generator(this, function (_a) {
|
|
466
|
-
switch (_a.label) {
|
|
467
|
-
case 0:
|
|
468
|
-
objects = {};
|
|
469
|
-
this._entities = this.getEntities(objects);
|
|
470
|
-
return [4, this.connect()];
|
|
471
|
-
case 1:
|
|
472
|
-
_a.sent();
|
|
473
|
-
return [4, this._client.synchronize(true)];
|
|
474
|
-
case 2:
|
|
475
|
-
_a.sent();
|
|
476
|
-
return [4, this.close()];
|
|
477
|
-
case 3:
|
|
478
|
-
_a.sent();
|
|
479
|
-
this._entities = null;
|
|
480
|
-
return [2];
|
|
217
|
+
}
|
|
218
|
+
return result[0];
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
async run(sql, param) {
|
|
225
|
+
const queryRunner = await this.createQueryRunner();
|
|
226
|
+
try {
|
|
227
|
+
return queryRunner.query(sql, param);
|
|
228
|
+
}
|
|
229
|
+
finally {
|
|
230
|
+
if (queryRunner !== this._queryRunner) {
|
|
231
|
+
await queryRunner.release();
|
|
232
|
+
}
|
|
233
|
+
if (this._client.driver.options.type === "sqljs") {
|
|
234
|
+
await this._client.driver.autoSave();
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
async insert(tableName, data) {
|
|
239
|
+
await this.connect();
|
|
240
|
+
let entity = this._entities[tableName];
|
|
241
|
+
if (!entity) {
|
|
242
|
+
throw new Error(`${tableName} is not exist or not registered in the connect`);
|
|
243
|
+
}
|
|
244
|
+
let repository = this._client.getRepository(entity);
|
|
245
|
+
let result = await repository.insert(data);
|
|
246
|
+
if (result.identifiers && result.identifiers.length) {
|
|
247
|
+
let primaryKeys = (0, typeorm_2.getPrimaryKeys)(repository);
|
|
248
|
+
if (primaryKeys && primaryKeys.length === 1) {
|
|
249
|
+
let id = primaryKeys[0] && result.identifiers[0][primaryKeys[0]];
|
|
250
|
+
if (id) {
|
|
251
|
+
return await this.findOne(tableName, id);
|
|
481
252
|
}
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
async update(tableName, id, data) {
|
|
257
|
+
await this.connect();
|
|
258
|
+
let entity = this._entities[tableName];
|
|
259
|
+
if (!entity) {
|
|
260
|
+
throw new Error(`${tableName} is not exist or not registered in the connect`);
|
|
261
|
+
}
|
|
262
|
+
let fields = Object.keys(data);
|
|
263
|
+
if (!fields.length) {
|
|
264
|
+
throw new Error("the params 'data' must not be empty");
|
|
265
|
+
}
|
|
266
|
+
let repository = this._client.getRepository(entity);
|
|
267
|
+
await repository.update(id, data);
|
|
268
|
+
return await this.findOne(tableName, id);
|
|
269
|
+
}
|
|
270
|
+
async updateOne(tableName, id, data) {
|
|
271
|
+
await this.connect();
|
|
272
|
+
let entity = this._entities[tableName];
|
|
273
|
+
if (!entity) {
|
|
274
|
+
throw new Error(`${tableName} is not exist or not registered in the connect`);
|
|
275
|
+
}
|
|
276
|
+
let fields = Object.keys(data);
|
|
277
|
+
if (!fields.length) {
|
|
278
|
+
throw new Error("the params 'data' must not be empty");
|
|
279
|
+
}
|
|
280
|
+
let repository = this._client.getRepository(entity);
|
|
281
|
+
await repository.update(id, data);
|
|
282
|
+
return await this.findOne(tableName, id);
|
|
283
|
+
}
|
|
284
|
+
async delete(tableName, id) {
|
|
285
|
+
await this.connect();
|
|
286
|
+
let entity = this._entities[tableName];
|
|
287
|
+
if (!entity) {
|
|
288
|
+
throw new Error(`${tableName} is not exist or not registered in the connect`);
|
|
289
|
+
}
|
|
290
|
+
let repository = this._client.getRepository(entity);
|
|
291
|
+
await repository.delete(id);
|
|
292
|
+
}
|
|
293
|
+
async directFind(tableName, query) {
|
|
294
|
+
return this.find(tableName, query);
|
|
295
|
+
}
|
|
296
|
+
async directInsert(tableName, data) {
|
|
297
|
+
return this.insert(tableName, data);
|
|
298
|
+
}
|
|
299
|
+
async directUpdate(tableName, id, data) {
|
|
300
|
+
return this.update(tableName, id, data);
|
|
301
|
+
}
|
|
302
|
+
async directDelete(tableName, id) {
|
|
303
|
+
return this.delete(tableName, id);
|
|
304
|
+
}
|
|
305
|
+
async getDatabaseVersion() {
|
|
306
|
+
return "";
|
|
307
|
+
}
|
|
308
|
+
async dropEntities() {
|
|
309
|
+
let objects = {};
|
|
486
310
|
this._entities = this.getEntities(objects);
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
return [4, this._client.synchronize()];
|
|
508
|
-
case 2:
|
|
509
|
-
_a.sent();
|
|
510
|
-
return [2];
|
|
511
|
-
}
|
|
512
|
-
});
|
|
513
|
-
});
|
|
514
|
-
};
|
|
515
|
-
SteedosTypeormDriver.prototype.init = function (objects) {
|
|
516
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
517
|
-
return tslib_1.__generator(this, function (_a) {
|
|
518
|
-
switch (_a.label) {
|
|
519
|
-
case 0:
|
|
520
|
-
this.registerEntities(objects);
|
|
521
|
-
return [4, this.connect(true)];
|
|
522
|
-
case 1:
|
|
523
|
-
_a.sent();
|
|
524
|
-
return [2];
|
|
525
|
-
}
|
|
526
|
-
});
|
|
527
|
-
});
|
|
528
|
-
};
|
|
529
|
-
return SteedosTypeormDriver;
|
|
530
|
-
}());
|
|
311
|
+
await this.connect();
|
|
312
|
+
await this._client.synchronize(true);
|
|
313
|
+
await this.close();
|
|
314
|
+
this._entities = null;
|
|
315
|
+
}
|
|
316
|
+
registerEntities(objects) {
|
|
317
|
+
this._entities = this.getEntities(objects);
|
|
318
|
+
}
|
|
319
|
+
async dropTables() {
|
|
320
|
+
await this.dropEntities();
|
|
321
|
+
}
|
|
322
|
+
async createTables(objects) {
|
|
323
|
+
await this.init(objects);
|
|
324
|
+
await this._client.synchronize();
|
|
325
|
+
}
|
|
326
|
+
async init(objects) {
|
|
327
|
+
this.registerEntities(objects);
|
|
328
|
+
await this.connect(true);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
531
331
|
exports.SteedosTypeormDriver = SteedosTypeormDriver;
|
|
532
332
|
//# sourceMappingURL=driver.js.map
|