@steedos/objectql 3.0.13-beta.5 → 3.0.13-beta.50
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 +62 -87
- 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 +101 -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.js +36 -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 +2005 -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.js +79 -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/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 +12 -12
package/lib/types/datasource.js
CHANGED
|
@@ -2,18 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SteedosDataSourceType = exports.SteedosDatabaseDriverType = void 0;
|
|
4
4
|
exports.getDataSource = getDataSource;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var defaultDatasourceName = "default";
|
|
5
|
+
const index_1 = require("../services/index");
|
|
6
|
+
const driver_1 = require("../driver");
|
|
7
|
+
const _ = require("lodash");
|
|
8
|
+
const _1 = require(".");
|
|
9
|
+
const index_2 = require("../services/index");
|
|
10
|
+
const path = require("path");
|
|
11
|
+
const metadata_registrar_1 = require("@steedos/metadata-registrar");
|
|
12
|
+
const metadata_1 = require("../driver/metadata");
|
|
13
|
+
const clone = require("clone");
|
|
14
|
+
const cachers = require("@steedos/cachers");
|
|
15
|
+
const defaultDatasourceName = "default";
|
|
17
16
|
var SteedosDatabaseDriverType;
|
|
18
17
|
(function (SteedosDatabaseDriverType) {
|
|
19
18
|
SteedosDatabaseDriverType["Mongo"] = "mongo";
|
|
@@ -24,206 +23,135 @@ var SteedosDatabaseDriverType;
|
|
|
24
23
|
SteedosDatabaseDriverType["Oracle"] = "oracle";
|
|
25
24
|
SteedosDatabaseDriverType["MySql"] = "mysql";
|
|
26
25
|
})(SteedosDatabaseDriverType || (exports.SteedosDatabaseDriverType = SteedosDatabaseDriverType = {}));
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
this.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
this.
|
|
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
|
-
this.
|
|
66
|
-
|
|
67
|
-
|
|
26
|
+
class SteedosDataSourceType {
|
|
27
|
+
_name;
|
|
28
|
+
get name() {
|
|
29
|
+
return this._name;
|
|
30
|
+
}
|
|
31
|
+
_adapter;
|
|
32
|
+
get adapter() {
|
|
33
|
+
return this._adapter;
|
|
34
|
+
}
|
|
35
|
+
_getRoles;
|
|
36
|
+
_url;
|
|
37
|
+
_host;
|
|
38
|
+
_port;
|
|
39
|
+
_username;
|
|
40
|
+
_password;
|
|
41
|
+
_database;
|
|
42
|
+
_connectString;
|
|
43
|
+
_timezone;
|
|
44
|
+
_options;
|
|
45
|
+
_locale;
|
|
46
|
+
_schema;
|
|
47
|
+
_objects = {};
|
|
48
|
+
_cacheObjects = [];
|
|
49
|
+
metadataObjectsName = {};
|
|
50
|
+
_metadataAdapter;
|
|
51
|
+
initializing = false;
|
|
52
|
+
initPromise = null;
|
|
53
|
+
get cacheObjects() {
|
|
54
|
+
return this._cacheObjects;
|
|
55
|
+
}
|
|
56
|
+
set cacheObjects(value) {
|
|
57
|
+
this._cacheObjects = value;
|
|
58
|
+
}
|
|
59
|
+
_service;
|
|
60
|
+
get service() {
|
|
61
|
+
return this._service;
|
|
62
|
+
}
|
|
63
|
+
set service(value) {
|
|
64
|
+
this._service = value;
|
|
65
|
+
}
|
|
66
|
+
_objectsConfig = {};
|
|
67
|
+
_objectsRolesPermission = {};
|
|
68
|
+
_objectsSpaceRolesPermission = {};
|
|
69
|
+
_driver;
|
|
70
|
+
_logging;
|
|
71
|
+
_config;
|
|
72
|
+
_enable_space;
|
|
73
|
+
get enable_space() {
|
|
74
|
+
return this._enable_space;
|
|
75
|
+
}
|
|
76
|
+
get config() {
|
|
77
|
+
return this._config;
|
|
78
|
+
}
|
|
79
|
+
set config(value) {
|
|
80
|
+
this._config = value;
|
|
81
|
+
}
|
|
82
|
+
get driver() {
|
|
83
|
+
return this._driver;
|
|
84
|
+
}
|
|
85
|
+
async getObjects(useCache = true) {
|
|
86
|
+
if (useCache === false) {
|
|
87
|
+
await this.flushCacheObjects();
|
|
68
88
|
}
|
|
69
|
-
this.
|
|
89
|
+
return this.getCacheObjects();
|
|
70
90
|
}
|
|
71
|
-
|
|
72
|
-
get: function () {
|
|
73
|
-
return this._name;
|
|
74
|
-
},
|
|
75
|
-
enumerable: false,
|
|
76
|
-
configurable: true
|
|
77
|
-
});
|
|
78
|
-
Object.defineProperty(SteedosDataSourceType.prototype, "adapter", {
|
|
79
|
-
get: function () {
|
|
80
|
-
return this._adapter;
|
|
81
|
-
},
|
|
82
|
-
enumerable: false,
|
|
83
|
-
configurable: true
|
|
84
|
-
});
|
|
85
|
-
Object.defineProperty(SteedosDataSourceType.prototype, "cacheObjects", {
|
|
86
|
-
get: function () {
|
|
87
|
-
return this._cacheObjects;
|
|
88
|
-
},
|
|
89
|
-
set: function (value) {
|
|
90
|
-
this._cacheObjects = value;
|
|
91
|
-
},
|
|
92
|
-
enumerable: false,
|
|
93
|
-
configurable: true
|
|
94
|
-
});
|
|
95
|
-
Object.defineProperty(SteedosDataSourceType.prototype, "service", {
|
|
96
|
-
get: function () {
|
|
97
|
-
return this._service;
|
|
98
|
-
},
|
|
99
|
-
set: function (value) {
|
|
100
|
-
this._service = value;
|
|
101
|
-
},
|
|
102
|
-
enumerable: false,
|
|
103
|
-
configurable: true
|
|
104
|
-
});
|
|
105
|
-
Object.defineProperty(SteedosDataSourceType.prototype, "enable_space", {
|
|
106
|
-
get: function () {
|
|
107
|
-
return this._enable_space;
|
|
108
|
-
},
|
|
109
|
-
enumerable: false,
|
|
110
|
-
configurable: true
|
|
111
|
-
});
|
|
112
|
-
Object.defineProperty(SteedosDataSourceType.prototype, "config", {
|
|
113
|
-
get: function () {
|
|
114
|
-
return this._config;
|
|
115
|
-
},
|
|
116
|
-
set: function (value) {
|
|
117
|
-
this._config = value;
|
|
118
|
-
},
|
|
119
|
-
enumerable: false,
|
|
120
|
-
configurable: true
|
|
121
|
-
});
|
|
122
|
-
Object.defineProperty(SteedosDataSourceType.prototype, "driver", {
|
|
123
|
-
get: function () {
|
|
124
|
-
return this._driver;
|
|
125
|
-
},
|
|
126
|
-
enumerable: false,
|
|
127
|
-
configurable: true
|
|
128
|
-
});
|
|
129
|
-
SteedosDataSourceType.prototype.getObjects = function () {
|
|
130
|
-
return tslib_1.__awaiter(this, arguments, void 0, function (useCache) {
|
|
131
|
-
if (useCache === void 0) { useCache = true; }
|
|
132
|
-
return tslib_1.__generator(this, function (_a) {
|
|
133
|
-
switch (_a.label) {
|
|
134
|
-
case 0:
|
|
135
|
-
if (!(useCache === false)) return [3, 2];
|
|
136
|
-
return [4, this.flushCacheObjects()];
|
|
137
|
-
case 1:
|
|
138
|
-
_a.sent();
|
|
139
|
-
_a.label = 2;
|
|
140
|
-
case 2: return [2, this.getCacheObjects()];
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
};
|
|
145
|
-
SteedosDataSourceType.prototype.getCacheObjects = function () {
|
|
91
|
+
getCacheObjects() {
|
|
146
92
|
return clone(this.cacheObjects, false);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return clone(_.find(this.cacheObjects,
|
|
150
|
-
return
|
|
93
|
+
}
|
|
94
|
+
getCacheObject(objectName) {
|
|
95
|
+
return clone(_.find(this.cacheObjects, (item) => {
|
|
96
|
+
return item?.metadata.name === objectName;
|
|
151
97
|
}));
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
switch (_b.label) {
|
|
158
|
-
case 0:
|
|
159
|
-
_a = this;
|
|
160
|
-
return [4, this.schema.metadataRegister.getObjectsConfig(this.name)];
|
|
161
|
-
case 1:
|
|
162
|
-
_a.cacheObjects = _b.sent();
|
|
163
|
-
return [2];
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
};
|
|
168
|
-
SteedosDataSourceType.prototype.getLocalObjects = function () {
|
|
98
|
+
}
|
|
99
|
+
async flushCacheObjects() {
|
|
100
|
+
this.cacheObjects = await this.schema.metadataRegister.getObjectsConfig(this.name);
|
|
101
|
+
}
|
|
102
|
+
getLocalObjects() {
|
|
169
103
|
return this._objects;
|
|
170
|
-
}
|
|
171
|
-
|
|
104
|
+
}
|
|
105
|
+
setLocalObject(objectApiName, object) {
|
|
172
106
|
this._objects[objectApiName] = object;
|
|
173
|
-
}
|
|
174
|
-
|
|
107
|
+
}
|
|
108
|
+
getObject(objectApiName) {
|
|
175
109
|
return this.getLocalObject(objectApiName);
|
|
176
|
-
}
|
|
177
|
-
|
|
110
|
+
}
|
|
111
|
+
getLocalObject(objectApiName) {
|
|
178
112
|
return this._objects[objectApiName];
|
|
179
|
-
}
|
|
180
|
-
|
|
113
|
+
}
|
|
114
|
+
getObjectsConfig() {
|
|
181
115
|
return this._objectsConfig;
|
|
182
|
-
}
|
|
183
|
-
|
|
116
|
+
}
|
|
117
|
+
getObjectConfig(objectName) {
|
|
184
118
|
return this._objectsConfig[objectName];
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
this._objects[objectApiName] = object;
|
|
204
|
-
return [2, object];
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
};
|
|
208
|
-
SteedosDataSourceType.prototype.removeLocalObject = function (objectApiName) {
|
|
119
|
+
}
|
|
120
|
+
async setObject(objectApiName, objectConfig) {
|
|
121
|
+
const serviceName = (0, index_1.getObjectServiceName)(objectApiName);
|
|
122
|
+
let object = new _1.SteedosObjectType(objectApiName, this, objectConfig);
|
|
123
|
+
this._objectsConfig[objectApiName] = objectConfig;
|
|
124
|
+
const findIndex = _.findIndex(this.cacheObjects, (item) => {
|
|
125
|
+
return item?.metadata?.name === objectApiName;
|
|
126
|
+
});
|
|
127
|
+
if (findIndex != -1) {
|
|
128
|
+
this.cacheObjects[findIndex] = Object.assign({ service: { name: serviceName } }, { metadata: objectConfig });
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
this.cacheObjects.push(Object.assign({ service: { name: serviceName } }, { metadata: objectConfig }));
|
|
132
|
+
}
|
|
133
|
+
this._objects[objectApiName] = object;
|
|
134
|
+
return object;
|
|
135
|
+
}
|
|
136
|
+
removeLocalObject(objectApiName) {
|
|
209
137
|
delete this._objectsConfig[objectApiName];
|
|
210
138
|
delete this._objects[objectApiName];
|
|
211
139
|
this.schema.removeObjectMap(objectApiName);
|
|
212
|
-
}
|
|
213
|
-
|
|
140
|
+
}
|
|
141
|
+
removeObject(object_name) {
|
|
214
142
|
this.removeLocalObject(object_name);
|
|
215
143
|
this.schema.metadataRegister.removeObject(object_name);
|
|
216
|
-
}
|
|
217
|
-
|
|
144
|
+
}
|
|
145
|
+
getAdapter(objectName) {
|
|
218
146
|
if (this.name === "default" && this.metadataObjectsName[objectName]) {
|
|
219
147
|
return this._metadataAdapter;
|
|
220
148
|
}
|
|
221
149
|
else {
|
|
222
150
|
return this._adapter;
|
|
223
151
|
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
|
|
152
|
+
}
|
|
153
|
+
initDriver() {
|
|
154
|
+
let driverConfig = {
|
|
227
155
|
url: this._url,
|
|
228
156
|
host: this._host,
|
|
229
157
|
port: this._port,
|
|
@@ -263,567 +191,293 @@ var SteedosDataSourceType = (function () {
|
|
|
263
191
|
this._adapter = new driver_1.SteedosMySqlDriver(driverConfig);
|
|
264
192
|
break;
|
|
265
193
|
default:
|
|
266
|
-
throw new Error(
|
|
194
|
+
throw new Error(`the driver ${this.config.driver} is not supported`);
|
|
267
195
|
}
|
|
268
196
|
}
|
|
269
197
|
else {
|
|
270
198
|
this._adapter = this.config.driver;
|
|
271
199
|
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
case 12: return [7];
|
|
341
|
-
case 13: return [2, true];
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
});
|
|
345
|
-
};
|
|
346
|
-
SteedosDataSourceType.prototype.loadFiles = function () {
|
|
347
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
348
|
-
var _a, _b, objectPath, filePath, e_2_1;
|
|
349
|
-
var e_2, _c;
|
|
350
|
-
return tslib_1.__generator(this, function (_d) {
|
|
351
|
-
switch (_d.label) {
|
|
352
|
-
case 0:
|
|
353
|
-
_d.trys.push([0, 5, 6, 7]);
|
|
354
|
-
_a = tslib_1.__values(this.config.objectFiles), _b = _a.next();
|
|
355
|
-
_d.label = 1;
|
|
356
|
-
case 1:
|
|
357
|
-
if (!!_b.done) return [3, 4];
|
|
358
|
-
objectPath = _b.value;
|
|
359
|
-
filePath = objectPath;
|
|
360
|
-
if (!path.isAbsolute(objectPath)) {
|
|
361
|
-
filePath = path.join(process.cwd(), objectPath);
|
|
362
|
-
}
|
|
363
|
-
return [4, (0, metadata_registrar_1.registerMetadataConfigs)(filePath, this._name, null)];
|
|
364
|
-
case 2:
|
|
365
|
-
_d.sent();
|
|
366
|
-
_d.label = 3;
|
|
367
|
-
case 3:
|
|
368
|
-
_b = _a.next();
|
|
369
|
-
return [3, 1];
|
|
370
|
-
case 4: return [3, 7];
|
|
371
|
-
case 5:
|
|
372
|
-
e_2_1 = _d.sent();
|
|
373
|
-
e_2 = { error: e_2_1 };
|
|
374
|
-
return [3, 7];
|
|
375
|
-
case 6:
|
|
376
|
-
try {
|
|
377
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
378
|
-
}
|
|
379
|
-
finally { if (e_2) throw e_2.error; }
|
|
380
|
-
return [7];
|
|
381
|
-
case 7: return [2];
|
|
382
|
-
}
|
|
383
|
-
});
|
|
384
|
-
});
|
|
385
|
-
};
|
|
386
|
-
SteedosDataSourceType.prototype.setObjectPermission = function (object_name, objectRolePermission) {
|
|
387
|
-
var objectPermissions = this._objectsRolesPermission[object_name];
|
|
200
|
+
}
|
|
201
|
+
async initObject(objectConfig) {
|
|
202
|
+
if (objectConfig.isMetadata) {
|
|
203
|
+
this.metadataObjectsName[objectConfig.name] = true;
|
|
204
|
+
}
|
|
205
|
+
const localObjectConfig = (0, metadata_registrar_1.getObjectConfig)(objectConfig.name);
|
|
206
|
+
if (localObjectConfig) {
|
|
207
|
+
objectConfig.listeners = localObjectConfig.listeners;
|
|
208
|
+
objectConfig.methods = localObjectConfig.methods;
|
|
209
|
+
}
|
|
210
|
+
(0, metadata_registrar_1.setObjectConfig)(objectConfig);
|
|
211
|
+
await this.setObject(objectConfig.name, objectConfig);
|
|
212
|
+
}
|
|
213
|
+
async initObjects() {
|
|
214
|
+
let objects = this.cacheObjects;
|
|
215
|
+
let self = this;
|
|
216
|
+
for await (const object of _.values(objects)) {
|
|
217
|
+
const objectConfig = object.metadata;
|
|
218
|
+
await self.initObject(objectConfig);
|
|
219
|
+
}
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
constructor(datasource_name, config, schema) {
|
|
223
|
+
this._name = datasource_name;
|
|
224
|
+
this.config = config;
|
|
225
|
+
this._url = config.url;
|
|
226
|
+
this._host = config.host;
|
|
227
|
+
this._port = config.port;
|
|
228
|
+
this._username = config.username;
|
|
229
|
+
this._password = config.password;
|
|
230
|
+
this._database = config.database;
|
|
231
|
+
this._connectString = config.connectString;
|
|
232
|
+
this._timezone = config.timezone;
|
|
233
|
+
this._options = config.options;
|
|
234
|
+
this._schema = schema;
|
|
235
|
+
this._driver = config.driver;
|
|
236
|
+
this._logging = config.logging;
|
|
237
|
+
this._locale = config.locale;
|
|
238
|
+
if (_.has(config, "enable_space")) {
|
|
239
|
+
this._enable_space = config.enable_space;
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
if (this._driver == SteedosDatabaseDriverType.MeteorMongo ||
|
|
243
|
+
(this._driver == SteedosDatabaseDriverType.Mongo &&
|
|
244
|
+
this.name === defaultDatasourceName)) {
|
|
245
|
+
this._enable_space = true;
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
this._enable_space = false;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
this.initDriver();
|
|
252
|
+
if (config.getRoles && !_.isFunction(config.getRoles)) {
|
|
253
|
+
throw new Error("getRoles must be a function");
|
|
254
|
+
}
|
|
255
|
+
this._getRoles = config.getRoles;
|
|
256
|
+
}
|
|
257
|
+
async loadFiles() {
|
|
258
|
+
for (const objectPath of this.config.objectFiles) {
|
|
259
|
+
let filePath = objectPath;
|
|
260
|
+
if (!path.isAbsolute(objectPath)) {
|
|
261
|
+
filePath = path.join(process.cwd(), objectPath);
|
|
262
|
+
}
|
|
263
|
+
await (0, metadata_registrar_1.registerMetadataConfigs)(filePath, this._name, null);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
setObjectPermission(object_name, objectRolePermission) {
|
|
267
|
+
let objectPermissions = this._objectsRolesPermission[object_name];
|
|
388
268
|
if (!objectPermissions) {
|
|
389
269
|
this._objectsRolesPermission[object_name] = {};
|
|
390
270
|
}
|
|
391
271
|
this._objectsRolesPermission[object_name][objectRolePermission.name] =
|
|
392
272
|
new _1.SteedosObjectPermissionType(object_name, objectRolePermission);
|
|
393
|
-
}
|
|
394
|
-
|
|
273
|
+
}
|
|
274
|
+
getObjectRolesPermission(object_name) {
|
|
395
275
|
return this._objectsRolesPermission[object_name];
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
|
|
276
|
+
}
|
|
277
|
+
setObjectSpacePermission(object_name, spaceId, objectRolePermission) {
|
|
278
|
+
let objectPermissions = this._objectsSpaceRolesPermission[object_name];
|
|
399
279
|
if (!objectPermissions) {
|
|
400
280
|
this._objectsSpaceRolesPermission[object_name] = {};
|
|
401
281
|
}
|
|
402
|
-
|
|
282
|
+
let objectSpacePermissions = this._objectsSpaceRolesPermission[object_name][spaceId];
|
|
403
283
|
if (!objectSpacePermissions) {
|
|
404
284
|
this._objectsSpaceRolesPermission[object_name][spaceId] = {};
|
|
405
285
|
}
|
|
406
286
|
this._objectsSpaceRolesPermission[object_name][spaceId][objectRolePermission.name] = new _1.SteedosObjectPermissionType(object_name, objectRolePermission);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
|
|
287
|
+
}
|
|
288
|
+
getObjectSpaceRolesPermission(object_name, spaceId) {
|
|
289
|
+
const cacherPermissionObjects = cachers
|
|
410
290
|
.getCacher("permission_objects")
|
|
411
291
|
.get("permission_objects");
|
|
412
292
|
if (_.isEmpty(cacherPermissionObjects)) {
|
|
413
293
|
return;
|
|
414
294
|
}
|
|
415
|
-
|
|
295
|
+
const permission = {};
|
|
416
296
|
_.each(_.filter(cacherPermissionObjects[spaceId], function (objectPermission) {
|
|
417
297
|
return objectPermission.object_name === object_name;
|
|
418
|
-
}),
|
|
298
|
+
}), (item) => {
|
|
419
299
|
permission[item.name] = new _1.SteedosObjectPermissionType(object_name, item);
|
|
420
300
|
});
|
|
421
301
|
return permission;
|
|
422
|
-
}
|
|
423
|
-
|
|
302
|
+
}
|
|
303
|
+
removeObjectSpacePermission(object_name, spaceId, objectRolePermissionName) {
|
|
424
304
|
if (this._objectsSpaceRolesPermission[object_name] &&
|
|
425
305
|
this._objectsSpaceRolesPermission[object_name][spaceId]) {
|
|
426
306
|
delete this._objectsSpaceRolesPermission[object_name][spaceId][objectRolePermissionName];
|
|
427
307
|
}
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
return
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
return
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
464
|
-
return tslib_1.__generator(this, function (_a) {
|
|
465
|
-
switch (_a.label) {
|
|
466
|
-
case 0: return [4, this.getAdapter(tableName).findOne(tableName, id, query, userId)];
|
|
467
|
-
case 1: return [2, _a.sent()];
|
|
468
|
-
}
|
|
469
|
-
});
|
|
470
|
-
});
|
|
471
|
-
};
|
|
472
|
-
SteedosDataSourceType.prototype.insert = function (tableName, doc, userId) {
|
|
473
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
474
|
-
return tslib_1.__generator(this, function (_a) {
|
|
475
|
-
switch (_a.label) {
|
|
476
|
-
case 0: return [4, this.getAdapter(tableName).insert(tableName, doc, userId)];
|
|
477
|
-
case 1: return [2, _a.sent()];
|
|
478
|
-
}
|
|
479
|
-
});
|
|
480
|
-
});
|
|
481
|
-
};
|
|
482
|
-
SteedosDataSourceType.prototype.update = function (tableName, id, doc, userId) {
|
|
483
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
484
|
-
return tslib_1.__generator(this, function (_a) {
|
|
485
|
-
switch (_a.label) {
|
|
486
|
-
case 0: return [4, this.getAdapter(tableName).update(tableName, id, doc, userId)];
|
|
487
|
-
case 1: return [2, _a.sent()];
|
|
488
|
-
}
|
|
489
|
-
});
|
|
490
|
-
});
|
|
491
|
-
};
|
|
492
|
-
SteedosDataSourceType.prototype.updateOne = function (tableName, id, doc, userId) {
|
|
493
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
494
|
-
return tslib_1.__generator(this, function (_a) {
|
|
495
|
-
switch (_a.label) {
|
|
496
|
-
case 0: return [4, this.getAdapter(tableName).updateOne(tableName, id, doc, userId)];
|
|
497
|
-
case 1: return [2, _a.sent()];
|
|
498
|
-
}
|
|
499
|
-
});
|
|
500
|
-
});
|
|
501
|
-
};
|
|
502
|
-
SteedosDataSourceType.prototype.updateMany = function (tableName, queryFilters, doc, userId) {
|
|
503
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
504
|
-
return tslib_1.__generator(this, function (_a) {
|
|
505
|
-
switch (_a.label) {
|
|
506
|
-
case 0: return [4, this.getAdapter(tableName).updateMany(tableName, queryFilters, doc, userId)];
|
|
507
|
-
case 1: return [2, _a.sent()];
|
|
508
|
-
}
|
|
509
|
-
});
|
|
510
|
-
});
|
|
511
|
-
};
|
|
512
|
-
SteedosDataSourceType.prototype.delete = function (tableName, id, userId) {
|
|
513
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
514
|
-
return tslib_1.__generator(this, function (_a) {
|
|
515
|
-
switch (_a.label) {
|
|
516
|
-
case 0: return [4, this.getAdapter(tableName).delete(tableName, id, userId)];
|
|
517
|
-
case 1: return [2, _a.sent()];
|
|
518
|
-
}
|
|
519
|
-
});
|
|
520
|
-
});
|
|
521
|
-
};
|
|
522
|
-
SteedosDataSourceType.prototype.formatRecord = function (doc, objectConfig) {
|
|
523
|
-
var formatRecord = this.getAdapter(objectConfig.name).formatRecord;
|
|
308
|
+
}
|
|
309
|
+
async getRoles(userId) {
|
|
310
|
+
if (this._getRoles) {
|
|
311
|
+
return await this._getRoles(userId);
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
return ["admin"];
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
async find(tableName, query, userId) {
|
|
318
|
+
return await this.getAdapter(tableName).find(tableName, query, userId);
|
|
319
|
+
}
|
|
320
|
+
async aggregate(tableName, query, externalPipeline, userId) {
|
|
321
|
+
return await this.getAdapter(tableName).aggregate(tableName, query, externalPipeline, userId);
|
|
322
|
+
}
|
|
323
|
+
async findOne(tableName, id, query, userId) {
|
|
324
|
+
return await this.getAdapter(tableName).findOne(tableName, id, query, userId);
|
|
325
|
+
}
|
|
326
|
+
async insert(tableName, doc, userId) {
|
|
327
|
+
return await this.getAdapter(tableName).insert(tableName, doc, userId);
|
|
328
|
+
}
|
|
329
|
+
async update(tableName, id, doc, userId) {
|
|
330
|
+
return await this.getAdapter(tableName).update(tableName, id, doc, userId);
|
|
331
|
+
}
|
|
332
|
+
async updateOne(tableName, id, doc, userId) {
|
|
333
|
+
return await this.getAdapter(tableName).updateOne(tableName, id, doc, userId);
|
|
334
|
+
}
|
|
335
|
+
async updateMany(tableName, queryFilters, doc, userId) {
|
|
336
|
+
return await this.getAdapter(tableName).updateMany(tableName, queryFilters, doc, userId);
|
|
337
|
+
}
|
|
338
|
+
async delete(tableName, id, userId) {
|
|
339
|
+
return await this.getAdapter(tableName).delete(tableName, id, userId);
|
|
340
|
+
}
|
|
341
|
+
formatRecord(doc, objectConfig) {
|
|
342
|
+
const formatRecord = this.getAdapter(objectConfig.name).formatRecord;
|
|
524
343
|
if (typeof formatRecord === "function") {
|
|
525
344
|
return formatRecord(doc, objectConfig);
|
|
526
345
|
}
|
|
527
346
|
return doc;
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
return
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
return
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
}
|
|
566
|
-
});
|
|
567
|
-
});
|
|
568
|
-
};
|
|
569
|
-
SteedosDataSourceType.prototype.directDelete = function (tableName, id, userId) {
|
|
570
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
571
|
-
return tslib_1.__generator(this, function (_a) {
|
|
572
|
-
switch (_a.label) {
|
|
573
|
-
case 0: return [4, this.getAdapter(tableName).directDelete(tableName, id, userId)];
|
|
574
|
-
case 1: return [2, _a.sent()];
|
|
575
|
-
}
|
|
576
|
-
});
|
|
577
|
-
});
|
|
578
|
-
};
|
|
579
|
-
SteedosDataSourceType.prototype.directAggregate = function (tableName, query, externalPipeline, userId) {
|
|
580
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
581
|
-
return tslib_1.__generator(this, function (_a) {
|
|
582
|
-
switch (_a.label) {
|
|
583
|
-
case 0: return [4, this.getAdapter(tableName).directAggregate(tableName, query, externalPipeline, userId)];
|
|
584
|
-
case 1: return [2, _a.sent()];
|
|
585
|
-
}
|
|
586
|
-
});
|
|
587
|
-
});
|
|
588
|
-
};
|
|
589
|
-
SteedosDataSourceType.prototype.directAggregatePrefixalPipeline = function (tableName, query, prefixalPipeline, userId) {
|
|
590
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
591
|
-
return tslib_1.__generator(this, function (_a) {
|
|
592
|
-
switch (_a.label) {
|
|
593
|
-
case 0: return [4, this.getAdapter(tableName).directAggregatePrefixalPipeline(tableName, query, prefixalPipeline, userId)];
|
|
594
|
-
case 1: return [2, _a.sent()];
|
|
595
|
-
}
|
|
596
|
-
});
|
|
597
|
-
});
|
|
598
|
-
};
|
|
599
|
-
SteedosDataSourceType.prototype.directUpdateMany = function (tableName, queryFilters, doc, userId) {
|
|
600
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
601
|
-
return tslib_1.__generator(this, function (_a) {
|
|
602
|
-
switch (_a.label) {
|
|
603
|
-
case 0: return [4, this.getAdapter(tableName).directUpdateMany(tableName, queryFilters, doc, userId)];
|
|
604
|
-
case 1: return [2, _a.sent()];
|
|
605
|
-
}
|
|
606
|
-
});
|
|
607
|
-
});
|
|
608
|
-
};
|
|
609
|
-
SteedosDataSourceType.prototype._makeNewID = function (tableName) {
|
|
610
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
611
|
-
return tslib_1.__generator(this, function (_a) {
|
|
612
|
-
switch (_a.label) {
|
|
613
|
-
case 0: return [4, this.getAdapter(tableName)._makeNewID(tableName)];
|
|
614
|
-
case 1: return [2, _a.sent()];
|
|
615
|
-
}
|
|
616
|
-
});
|
|
617
|
-
});
|
|
618
|
-
};
|
|
619
|
-
Object.defineProperty(SteedosDataSourceType.prototype, "schema", {
|
|
620
|
-
get: function () {
|
|
621
|
-
return this._schema;
|
|
622
|
-
},
|
|
623
|
-
enumerable: false,
|
|
624
|
-
configurable: true
|
|
625
|
-
});
|
|
626
|
-
SteedosDataSourceType.prototype.dropEntities = function () {
|
|
627
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
628
|
-
return tslib_1.__generator(this, function (_a) {
|
|
629
|
-
switch (_a.label) {
|
|
630
|
-
case 0:
|
|
631
|
-
if (!this._adapter.dropEntities) return [3, 2];
|
|
632
|
-
return [4, this._adapter.dropEntities()];
|
|
633
|
-
case 1: return [2, _a.sent()];
|
|
634
|
-
case 2: return [2];
|
|
635
|
-
}
|
|
636
|
-
});
|
|
637
|
-
});
|
|
638
|
-
};
|
|
639
|
-
SteedosDataSourceType.prototype.registerEntities = function () {
|
|
347
|
+
}
|
|
348
|
+
async count(tableName, query, userId) {
|
|
349
|
+
return await this.getAdapter(tableName).count(tableName, query, userId);
|
|
350
|
+
}
|
|
351
|
+
async directFind(tableName, query, userId) {
|
|
352
|
+
return await this.getAdapter(tableName).directFind(tableName, query, userId);
|
|
353
|
+
}
|
|
354
|
+
async directInsert(tableName, doc, userId) {
|
|
355
|
+
return await this.getAdapter(tableName).directInsert(tableName, doc, userId);
|
|
356
|
+
}
|
|
357
|
+
async directUpdate(tableName, id, doc, userId) {
|
|
358
|
+
return await this.getAdapter(tableName).directUpdate(tableName, id, doc, userId);
|
|
359
|
+
}
|
|
360
|
+
async directDelete(tableName, id, userId) {
|
|
361
|
+
return await this.getAdapter(tableName).directDelete(tableName, id, userId);
|
|
362
|
+
}
|
|
363
|
+
async directAggregate(tableName, query, externalPipeline, userId) {
|
|
364
|
+
return await this.getAdapter(tableName).directAggregate(tableName, query, externalPipeline, userId);
|
|
365
|
+
}
|
|
366
|
+
async directAggregatePrefixalPipeline(tableName, query, prefixalPipeline, userId) {
|
|
367
|
+
return await this.getAdapter(tableName).directAggregatePrefixalPipeline(tableName, query, prefixalPipeline, userId);
|
|
368
|
+
}
|
|
369
|
+
async directUpdateMany(tableName, queryFilters, doc, userId) {
|
|
370
|
+
return await this.getAdapter(tableName).directUpdateMany(tableName, queryFilters, doc, userId);
|
|
371
|
+
}
|
|
372
|
+
async _makeNewID(tableName) {
|
|
373
|
+
return await this.getAdapter(tableName)._makeNewID(tableName);
|
|
374
|
+
}
|
|
375
|
+
get schema() {
|
|
376
|
+
return this._schema;
|
|
377
|
+
}
|
|
378
|
+
async dropEntities() {
|
|
379
|
+
if (this._adapter.dropEntities) {
|
|
380
|
+
return await this._adapter.dropEntities();
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
registerEntities() {
|
|
640
384
|
if (this._adapter.registerEntities) {
|
|
641
385
|
return this._adapter.registerEntities(this._objects);
|
|
642
386
|
}
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
return
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
case 2: return [2];
|
|
666
|
-
}
|
|
667
|
-
});
|
|
668
|
-
});
|
|
669
|
-
};
|
|
670
|
-
SteedosDataSourceType.prototype.init = function () {
|
|
671
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
672
|
-
var _this = this;
|
|
673
|
-
return tslib_1.__generator(this, function (_a) {
|
|
674
|
-
if (this.initializing) {
|
|
675
|
-
return [2, this.initPromise];
|
|
387
|
+
}
|
|
388
|
+
async dropTables() {
|
|
389
|
+
if (this._adapter.dropEntities) {
|
|
390
|
+
return await this._adapter.dropEntities();
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
async createTables() {
|
|
394
|
+
if (this._adapter.createTables) {
|
|
395
|
+
return await this._adapter.createTables(this._objects);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
async init() {
|
|
399
|
+
if (this.initializing) {
|
|
400
|
+
return this.initPromise;
|
|
401
|
+
}
|
|
402
|
+
this.initializing = true;
|
|
403
|
+
this.initPromise = (async () => {
|
|
404
|
+
try {
|
|
405
|
+
this.initObjectPermissions();
|
|
406
|
+
if (!this.service) {
|
|
407
|
+
const broker = this._schema.metadataBroker;
|
|
408
|
+
this.service = await (0, index_2.createDataSourceService)(broker, this);
|
|
676
409
|
}
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
_a.service = _b.sent();
|
|
691
|
-
_b.label = 2;
|
|
692
|
-
case 2: return [3, 4];
|
|
693
|
-
case 3:
|
|
694
|
-
error_1 = _b.sent();
|
|
695
|
-
console.error("Initialization failed for datasource:", this.name, error_1);
|
|
696
|
-
this.initializing = false;
|
|
697
|
-
this.initPromise = null;
|
|
698
|
-
throw error_1;
|
|
699
|
-
case 4: return [2];
|
|
700
|
-
}
|
|
701
|
-
});
|
|
702
|
-
}); })();
|
|
703
|
-
return [2, this.initPromise];
|
|
704
|
-
});
|
|
705
|
-
});
|
|
706
|
-
};
|
|
707
|
-
SteedosDataSourceType.prototype.initObjectPermissions = function () {
|
|
708
|
-
var _this = this;
|
|
709
|
-
_.each(this.config.objectsRolesPermission, function (objectRolesPermission, object_name) {
|
|
710
|
-
_.each(objectRolesPermission, function (objectRolePermission, role_name) {
|
|
410
|
+
}
|
|
411
|
+
catch (error) {
|
|
412
|
+
console.error("Initialization failed for datasource:", this.name, error);
|
|
413
|
+
this.initializing = false;
|
|
414
|
+
this.initPromise = null;
|
|
415
|
+
throw error;
|
|
416
|
+
}
|
|
417
|
+
})();
|
|
418
|
+
return this.initPromise;
|
|
419
|
+
}
|
|
420
|
+
initObjectPermissions() {
|
|
421
|
+
_.each(this.config.objectsRolesPermission, (objectRolesPermission, object_name) => {
|
|
422
|
+
_.each(objectRolesPermission, (objectRolePermission, role_name) => {
|
|
711
423
|
objectRolePermission.name = role_name;
|
|
712
|
-
|
|
424
|
+
this.setObjectPermission(object_name, objectRolePermission);
|
|
713
425
|
});
|
|
714
426
|
});
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
_objects = {};
|
|
723
|
-
_.map(this.cacheObjects, function (item) {
|
|
724
|
-
if (item && item.metadata) {
|
|
725
|
-
_objects[item.metadata.name] = item.metadata;
|
|
726
|
-
}
|
|
727
|
-
});
|
|
728
|
-
if (!this._adapter.init) return [3, 2];
|
|
729
|
-
return [4, this._adapter.init(_objects)];
|
|
730
|
-
case 1:
|
|
731
|
-
_a.sent();
|
|
732
|
-
_a.label = 2;
|
|
733
|
-
case 2: return [2];
|
|
734
|
-
}
|
|
735
|
-
});
|
|
427
|
+
}
|
|
428
|
+
async initTypeORM() {
|
|
429
|
+
const _objects = {};
|
|
430
|
+
_.map(this.cacheObjects, (item) => {
|
|
431
|
+
if (item && item.metadata) {
|
|
432
|
+
_objects[item.metadata.name] = item.metadata;
|
|
433
|
+
}
|
|
736
434
|
});
|
|
737
|
-
|
|
738
|
-
|
|
435
|
+
if (this._adapter.init) {
|
|
436
|
+
await this._adapter.init(_objects);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
getAppsConfig() {
|
|
739
440
|
return (0, _1.getAppConfigs)();
|
|
740
|
-
}
|
|
741
|
-
|
|
441
|
+
}
|
|
442
|
+
getDashboardsConfig() {
|
|
742
443
|
return (0, _1.getDashboardConfigs)();
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
var _a;
|
|
768
|
-
return tslib_1.__generator(this, function (_b) {
|
|
769
|
-
if ((_a = this._adapter) === null || _a === void 0 ? void 0 : _a.close)
|
|
770
|
-
this._adapter.close();
|
|
771
|
-
return [2];
|
|
772
|
-
});
|
|
773
|
-
});
|
|
774
|
-
};
|
|
775
|
-
SteedosDataSourceType.prototype.renameCollection = function (newObjectApiName, oldObjectApiName) {
|
|
776
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
777
|
-
var adapter, collection, newCollection, dropTarget, count;
|
|
778
|
-
return tslib_1.__generator(this, function (_a) {
|
|
779
|
-
switch (_a.label) {
|
|
780
|
-
case 0:
|
|
781
|
-
if (!(this.driver === SteedosDatabaseDriverType.Mongo)) return [3, 4];
|
|
782
|
-
adapter = this.adapter;
|
|
783
|
-
return [4, adapter.connect()];
|
|
784
|
-
case 1:
|
|
785
|
-
_a.sent();
|
|
786
|
-
collection = adapter.collection(oldObjectApiName);
|
|
787
|
-
newCollection = adapter.collection(newObjectApiName);
|
|
788
|
-
dropTarget = false;
|
|
789
|
-
return [4, newCollection.count({})];
|
|
790
|
-
case 2:
|
|
791
|
-
count = _a.sent();
|
|
792
|
-
if (count == 0) {
|
|
793
|
-
dropTarget = true;
|
|
794
|
-
}
|
|
795
|
-
return [4, collection.rename(newObjectApiName, {
|
|
796
|
-
dropTarget: dropTarget,
|
|
797
|
-
})];
|
|
798
|
-
case 3: return [2, _a.sent()];
|
|
799
|
-
case 4: return [2];
|
|
800
|
-
}
|
|
801
|
-
});
|
|
802
|
-
});
|
|
803
|
-
};
|
|
804
|
-
SteedosDataSourceType.prototype.isCollectionExitsRecords = function (objectApiName) {
|
|
805
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
806
|
-
var adapter, collection, count;
|
|
807
|
-
return tslib_1.__generator(this, function (_a) {
|
|
808
|
-
switch (_a.label) {
|
|
809
|
-
case 0:
|
|
810
|
-
if (!(this.driver === SteedosDatabaseDriverType.Mongo)) return [3, 3];
|
|
811
|
-
adapter = this.adapter;
|
|
812
|
-
return [4, adapter.connect()];
|
|
813
|
-
case 1:
|
|
814
|
-
_a.sent();
|
|
815
|
-
collection = adapter.collection(objectApiName);
|
|
816
|
-
return [4, collection.count({})];
|
|
817
|
-
case 2:
|
|
818
|
-
count = _a.sent();
|
|
819
|
-
return [2, !!count];
|
|
820
|
-
case 3: return [2];
|
|
821
|
-
}
|
|
444
|
+
}
|
|
445
|
+
async connect() {
|
|
446
|
+
if (this._adapter.connect)
|
|
447
|
+
await this._adapter.connect();
|
|
448
|
+
if (this._adapter.init)
|
|
449
|
+
await this._adapter.init(this._objects);
|
|
450
|
+
}
|
|
451
|
+
async close() {
|
|
452
|
+
if (this._adapter?.close)
|
|
453
|
+
this._adapter.close();
|
|
454
|
+
}
|
|
455
|
+
async renameCollection(newObjectApiName, oldObjectApiName) {
|
|
456
|
+
if (this.driver === SteedosDatabaseDriverType.Mongo) {
|
|
457
|
+
const adapter = this.adapter;
|
|
458
|
+
await adapter.connect();
|
|
459
|
+
const collection = adapter.collection(oldObjectApiName);
|
|
460
|
+
const newCollection = adapter.collection(newObjectApiName);
|
|
461
|
+
let dropTarget = false;
|
|
462
|
+
let count = await newCollection.count({});
|
|
463
|
+
if (count == 0) {
|
|
464
|
+
dropTarget = true;
|
|
465
|
+
}
|
|
466
|
+
return await collection.rename(newObjectApiName, {
|
|
467
|
+
dropTarget: dropTarget,
|
|
822
468
|
});
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
async isCollectionExitsRecords(objectApiName) {
|
|
472
|
+
if (this.driver === SteedosDatabaseDriverType.Mongo) {
|
|
473
|
+
const adapter = this.adapter;
|
|
474
|
+
await adapter.connect();
|
|
475
|
+
const collection = adapter.collection(objectApiName);
|
|
476
|
+
let count = await collection.count({});
|
|
477
|
+
return !!count;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
827
481
|
exports.SteedosDataSourceType = SteedosDataSourceType;
|
|
828
482
|
function getDataSource(datasourceName, schema) {
|
|
829
483
|
return (schema ? schema : (0, _1.getSteedosSchema)()).getDataSource(datasourceName);
|