@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.
Files changed (141) hide show
  1. package/lib/actions/field_updates.js +84 -153
  2. package/lib/actions/field_updates.js.map +1 -1
  3. package/lib/actions/index.js +1 -1
  4. package/lib/actions/workflow_notifications.js +50 -111
  5. package/lib/actions/workflow_notifications.js.map +1 -1
  6. package/lib/actions/workflow_outbound_messages.js +43 -94
  7. package/lib/actions/workflow_outbound_messages.js.map +1 -1
  8. package/lib/actions/workflow_rule.js +80 -177
  9. package/lib/actions/workflow_rule.js.map +1 -1
  10. package/lib/broker.js +19 -49
  11. package/lib/broker.js.map +1 -1
  12. package/lib/driver/field-encrytion/index.js +1 -1
  13. package/lib/driver/field-encrytion/mongosharedconst.js +17 -17
  14. package/lib/driver/field-encrytion/mongosharedconst.js.map +1 -1
  15. package/lib/driver/format.js +3 -3
  16. package/lib/driver/format.js.map +1 -1
  17. package/lib/driver/index.js +1 -1
  18. package/lib/driver/metadata.js +286 -387
  19. package/lib/driver/metadata.js.map +1 -1
  20. package/lib/driver/metadataOld.js +104 -105
  21. package/lib/driver/metadataOld.js.map +1 -1
  22. package/lib/driver/meteorMongo.js +5 -8
  23. package/lib/driver/meteorMongo.js.map +1 -1
  24. package/lib/driver/mongo.js +321 -506
  25. package/lib/driver/mongo.js.map +1 -1
  26. package/lib/driver/mysql.js +16 -20
  27. package/lib/driver/mysql.js.map +1 -1
  28. package/lib/driver/oracle.js +25 -38
  29. package/lib/driver/oracle.js.map +1 -1
  30. package/lib/driver/postgres.js +16 -20
  31. package/lib/driver/postgres.js.map +1 -1
  32. package/lib/driver/sqlite3.js +15 -19
  33. package/lib/driver/sqlite3.js.map +1 -1
  34. package/lib/driver/sqlserver.js +20 -33
  35. package/lib/driver/sqlserver.js.map +1 -1
  36. package/lib/errors/index.js +10 -11
  37. package/lib/errors/index.js.map +1 -1
  38. package/lib/formula/core.js +307 -594
  39. package/lib/formula/core.js.map +1 -1
  40. package/lib/formula/field_formula.js +80 -126
  41. package/lib/formula/field_formula.js.map +1 -1
  42. package/lib/formula/index.js +56 -97
  43. package/lib/formula/index.js.map +1 -1
  44. package/lib/formula/params.js +11 -11
  45. package/lib/formula/params.js.map +1 -1
  46. package/lib/formula/recompute.js +41 -166
  47. package/lib/formula/recompute.js.map +1 -1
  48. package/lib/formula/simple_params.js +12 -12
  49. package/lib/formula/simple_params.js.map +1 -1
  50. package/lib/formula/util.js +43 -67
  51. package/lib/formula/util.js.map +1 -1
  52. package/lib/functions/function.js +68 -86
  53. package/lib/functions/function.js.map +1 -1
  54. package/lib/index.js +3 -3
  55. package/lib/index.js.map +1 -1
  56. package/lib/services/datasourceServiceFactory.js +77 -111
  57. package/lib/services/datasourceServiceFactory.js.map +1 -1
  58. package/lib/services/index.js +3 -3
  59. package/lib/services/index.js.map +1 -1
  60. package/lib/summary/core.js +162 -355
  61. package/lib/summary/core.js.map +1 -1
  62. package/lib/summary/field_summary.js +44 -71
  63. package/lib/summary/field_summary.js.map +1 -1
  64. package/lib/summary/index.js +65 -80
  65. package/lib/summary/index.js.map +1 -1
  66. package/lib/summary/recompute.js +19 -47
  67. package/lib/summary/recompute.js.map +1 -1
  68. package/lib/triggers/trigger.js +108 -142
  69. package/lib/triggers/trigger.js.map +1 -1
  70. package/lib/ts-types/index.js +1 -1
  71. package/lib/typeorm/driver.js +250 -450
  72. package/lib/typeorm/driver.js.map +1 -1
  73. package/lib/typeorm/index.js +1 -1
  74. package/lib/typeorm/util.js +28 -28
  75. package/lib/typeorm/util.js.map +1 -1
  76. package/lib/types/action.js +24 -33
  77. package/lib/types/action.js.map +1 -1
  78. package/lib/types/app.js +210 -355
  79. package/lib/types/app.js.map +1 -1
  80. package/lib/types/connection.js +42 -78
  81. package/lib/types/connection.js.map +1 -1
  82. package/lib/types/dashboard.js +56 -77
  83. package/lib/types/dashboard.js.map +1 -1
  84. package/lib/types/datasource.js +359 -705
  85. package/lib/types/datasource.js.map +1 -1
  86. package/lib/types/defaultValue.js +53 -65
  87. package/lib/types/defaultValue.js.map +1 -1
  88. package/lib/types/field.js +165 -137
  89. package/lib/types/field.js.map +1 -1
  90. package/lib/types/field_permission.js +35 -66
  91. package/lib/types/field_permission.js.map +1 -1
  92. package/lib/types/index.js +1 -1
  93. package/lib/types/list_view.d.ts +1 -0
  94. package/lib/types/list_view.js +37 -43
  95. package/lib/types/list_view.js.map +1 -1
  96. package/lib/types/metadata.js +6 -6
  97. package/lib/types/metadata.js.map +1 -1
  98. package/lib/types/method_base.js +95 -128
  99. package/lib/types/method_base.js.map +1 -1
  100. package/lib/types/object.js +2034 -3015
  101. package/lib/types/object.js.map +1 -1
  102. package/lib/types/object_events.js +24 -37
  103. package/lib/types/object_events.js.map +1 -1
  104. package/lib/types/object_layouts.js +15 -38
  105. package/lib/types/object_layouts.js.map +1 -1
  106. package/lib/types/object_permission.js +99 -85
  107. package/lib/types/object_permission.js.map +1 -1
  108. package/lib/types/report.js +70 -98
  109. package/lib/types/report.js.map +1 -1
  110. package/lib/types/restrictionRule.js +47 -96
  111. package/lib/types/restrictionRule.js.map +1 -1
  112. package/lib/types/schema.js +115 -177
  113. package/lib/types/schema.js.map +1 -1
  114. package/lib/types/shareRule.js +53 -102
  115. package/lib/types/shareRule.js.map +1 -1
  116. package/lib/types/trigger.js +43 -56
  117. package/lib/types/trigger.js.map +1 -1
  118. package/lib/types/validation_rules.js +18 -56
  119. package/lib/types/validation_rules.js.map +1 -1
  120. package/lib/util/convert.js +24 -24
  121. package/lib/util/convert.js.map +1 -1
  122. package/lib/util/field.js +16 -28
  123. package/lib/util/field.js.map +1 -1
  124. package/lib/util/function_expression.js +7 -8
  125. package/lib/util/function_expression.js.map +1 -1
  126. package/lib/util/index.d.ts +1 -0
  127. package/lib/util/index.js +80 -97
  128. package/lib/util/index.js.map +1 -1
  129. package/lib/util/locale.js +4 -4
  130. package/lib/util/locale.js.map +1 -1
  131. package/lib/util/perf.d.ts +11 -0
  132. package/lib/util/perf.js +49 -0
  133. package/lib/util/perf.js.map +1 -0
  134. package/lib/util/permission_shares.js +7 -7
  135. package/lib/util/permission_shares.js.map +1 -1
  136. package/lib/util/suffix.js +19 -19
  137. package/lib/util/suffix.js.map +1 -1
  138. package/lib/util/transform.js +1 -1
  139. package/lib/validators/index.js +10 -10
  140. package/lib/validators/index.js.map +1 -1
  141. package/package.json +13 -14
@@ -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
- var tslib_1 = require("tslib");
6
- var index_1 = require("../services/index");
7
- var driver_1 = require("../driver");
8
- var _ = require("lodash");
9
- var _1 = require(".");
10
- var index_2 = require("../services/index");
11
- var path = require("path");
12
- var metadata_registrar_1 = require("@steedos/metadata-registrar");
13
- var metadata_1 = require("../driver/metadata");
14
- var clone = require("clone");
15
- var cachers = require("@steedos/cachers");
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
- var SteedosDataSourceType = (function () {
28
- function SteedosDataSourceType(datasource_name, config, schema) {
29
- this._objects = {};
30
- this._cacheObjects = [];
31
- this.metadataObjectsName = {};
32
- this.initializing = false;
33
- this.initPromise = null;
34
- this._objectsConfig = {};
35
- this._objectsRolesPermission = {};
36
- this._objectsSpaceRolesPermission = {};
37
- this._name = datasource_name;
38
- this.config = config;
39
- this._url = config.url;
40
- this._host = config.host;
41
- this._port = config.port;
42
- this._username = config.username;
43
- this._password = config.password;
44
- this._database = config.database;
45
- this._connectString = config.connectString;
46
- this._timezone = config.timezone;
47
- this._options = config.options;
48
- this._schema = schema;
49
- this._driver = config.driver;
50
- this._logging = config.logging;
51
- this._locale = config.locale;
52
- if (_.has(config, "enable_space")) {
53
- this._enable_space = config.enable_space;
54
- }
55
- else {
56
- if (this._driver == SteedosDatabaseDriverType.MeteorMongo ||
57
- (this._driver == SteedosDatabaseDriverType.Mongo &&
58
- this.name === defaultDatasourceName)) {
59
- this._enable_space = true;
60
- }
61
- else {
62
- this._enable_space = false;
63
- }
64
- }
65
- this.initDriver();
66
- if (config.getRoles && !_.isFunction(config.getRoles)) {
67
- throw new Error("getRoles must be a function");
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._getRoles = config.getRoles;
89
+ return this.getCacheObjects();
70
90
  }
71
- Object.defineProperty(SteedosDataSourceType.prototype, "name", {
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
- SteedosDataSourceType.prototype.getCacheObject = function (objectName) {
149
- return clone(_.find(this.cacheObjects, function (item) {
150
- return (item === null || item === void 0 ? void 0 : item.metadata.name) === objectName;
93
+ }
94
+ getCacheObject(objectName) {
95
+ return clone(_.find(this.cacheObjects, (item) => {
96
+ return item?.metadata.name === objectName;
151
97
  }));
152
- };
153
- SteedosDataSourceType.prototype.flushCacheObjects = function () {
154
- return tslib_1.__awaiter(this, void 0, void 0, function () {
155
- var _a;
156
- return tslib_1.__generator(this, function (_b) {
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
- SteedosDataSourceType.prototype.setLocalObject = function (objectApiName, object) {
104
+ }
105
+ setLocalObject(objectApiName, object) {
172
106
  this._objects[objectApiName] = object;
173
- };
174
- SteedosDataSourceType.prototype.getObject = function (objectApiName) {
107
+ }
108
+ getObject(objectApiName) {
175
109
  return this.getLocalObject(objectApiName);
176
- };
177
- SteedosDataSourceType.prototype.getLocalObject = function (objectApiName) {
110
+ }
111
+ getLocalObject(objectApiName) {
178
112
  return this._objects[objectApiName];
179
- };
180
- SteedosDataSourceType.prototype.getObjectsConfig = function () {
113
+ }
114
+ getObjectsConfig() {
181
115
  return this._objectsConfig;
182
- };
183
- SteedosDataSourceType.prototype.getObjectConfig = function (objectName) {
116
+ }
117
+ getObjectConfig(objectName) {
184
118
  return this._objectsConfig[objectName];
185
- };
186
- SteedosDataSourceType.prototype.setObject = function (objectApiName, objectConfig) {
187
- return tslib_1.__awaiter(this, void 0, void 0, function () {
188
- var serviceName, object, findIndex;
189
- return tslib_1.__generator(this, function (_a) {
190
- serviceName = (0, index_1.getObjectServiceName)(objectApiName);
191
- object = new _1.SteedosObjectType(objectApiName, this, objectConfig);
192
- this._objectsConfig[objectApiName] = objectConfig;
193
- findIndex = _.findIndex(this.cacheObjects, function (item) {
194
- var _a;
195
- return ((_a = item === null || item === void 0 ? void 0 : item.metadata) === null || _a === void 0 ? void 0 : _a.name) === objectApiName;
196
- });
197
- if (findIndex != -1) {
198
- this.cacheObjects[findIndex] = Object.assign({ service: { name: serviceName } }, { metadata: objectConfig });
199
- }
200
- else {
201
- this.cacheObjects.push(Object.assign({ service: { name: serviceName } }, { metadata: objectConfig }));
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
- SteedosDataSourceType.prototype.removeObject = function (object_name) {
140
+ }
141
+ removeObject(object_name) {
214
142
  this.removeLocalObject(object_name);
215
143
  this.schema.metadataRegister.removeObject(object_name);
216
- };
217
- SteedosDataSourceType.prototype.getAdapter = function (objectName) {
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
- SteedosDataSourceType.prototype.initDriver = function () {
226
- var driverConfig = {
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("the driver ".concat(this.config.driver, " is not supported"));
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
- SteedosDataSourceType.prototype.initObject = function (objectConfig) {
274
- return tslib_1.__awaiter(this, void 0, void 0, function () {
275
- var localObjectConfig;
276
- return tslib_1.__generator(this, function (_a) {
277
- switch (_a.label) {
278
- case 0:
279
- if (objectConfig.isMetadata) {
280
- this.metadataObjectsName[objectConfig.name] = true;
281
- }
282
- localObjectConfig = (0, metadata_registrar_1.getObjectConfig)(objectConfig.name);
283
- if (localObjectConfig) {
284
- objectConfig.listeners = localObjectConfig.listeners;
285
- objectConfig.methods = localObjectConfig.methods;
286
- }
287
- (0, metadata_registrar_1.setObjectConfig)(objectConfig);
288
- return [4, this.setObject(objectConfig.name, objectConfig)];
289
- case 1:
290
- _a.sent();
291
- return [2];
292
- }
293
- });
294
- });
295
- };
296
- SteedosDataSourceType.prototype.initObjects = function () {
297
- return tslib_1.__awaiter(this, void 0, void 0, function () {
298
- var objects, self, _a, _b, _c, object, objectConfig, e_1_1;
299
- var _d, e_1, _e, _f;
300
- return tslib_1.__generator(this, function (_g) {
301
- switch (_g.label) {
302
- case 0:
303
- objects = this.cacheObjects;
304
- self = this;
305
- _g.label = 1;
306
- case 1:
307
- _g.trys.push([1, 7, 8, 13]);
308
- _a = true, _b = tslib_1.__asyncValues(_.values(objects));
309
- _g.label = 2;
310
- case 2: return [4, _b.next()];
311
- case 3:
312
- if (!(_c = _g.sent(), _d = _c.done, !_d)) return [3, 6];
313
- _f = _c.value;
314
- _a = false;
315
- object = _f;
316
- objectConfig = object.metadata;
317
- return [4, self.initObject(objectConfig)];
318
- case 4:
319
- _g.sent();
320
- _g.label = 5;
321
- case 5:
322
- _a = true;
323
- return [3, 2];
324
- case 6: return [3, 13];
325
- case 7:
326
- e_1_1 = _g.sent();
327
- e_1 = { error: e_1_1 };
328
- return [3, 13];
329
- case 8:
330
- _g.trys.push([8, , 11, 12]);
331
- if (!(!_a && !_d && (_e = _b.return))) return [3, 10];
332
- return [4, _e.call(_b)];
333
- case 9:
334
- _g.sent();
335
- _g.label = 10;
336
- case 10: return [3, 12];
337
- case 11:
338
- if (e_1) throw e_1.error;
339
- return [7];
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
- SteedosDataSourceType.prototype.getObjectRolesPermission = function (object_name) {
273
+ }
274
+ getObjectRolesPermission(object_name) {
395
275
  return this._objectsRolesPermission[object_name];
396
- };
397
- SteedosDataSourceType.prototype.setObjectSpacePermission = function (object_name, spaceId, objectRolePermission) {
398
- var objectPermissions = this._objectsSpaceRolesPermission[object_name];
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
- var objectSpacePermissions = this._objectsSpaceRolesPermission[object_name][spaceId];
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
- SteedosDataSourceType.prototype.getObjectSpaceRolesPermission = function (object_name, spaceId) {
409
- var cacherPermissionObjects = cachers
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
- var permission = {};
295
+ const permission = {};
416
296
  _.each(_.filter(cacherPermissionObjects[spaceId], function (objectPermission) {
417
297
  return objectPermission.object_name === object_name;
418
- }), function (item) {
298
+ }), (item) => {
419
299
  permission[item.name] = new _1.SteedosObjectPermissionType(object_name, item);
420
300
  });
421
301
  return permission;
422
- };
423
- SteedosDataSourceType.prototype.removeObjectSpacePermission = function (object_name, spaceId, objectRolePermissionName) {
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
- SteedosDataSourceType.prototype.getRoles = function (userId) {
430
- return tslib_1.__awaiter(this, void 0, void 0, function () {
431
- return tslib_1.__generator(this, function (_a) {
432
- switch (_a.label) {
433
- case 0:
434
- if (!this._getRoles) return [3, 2];
435
- return [4, this._getRoles(userId)];
436
- case 1: return [2, _a.sent()];
437
- case 2: return [2, ["admin"]];
438
- }
439
- });
440
- });
441
- };
442
- SteedosDataSourceType.prototype.find = function (tableName, query, userId) {
443
- return tslib_1.__awaiter(this, void 0, void 0, function () {
444
- return tslib_1.__generator(this, function (_a) {
445
- switch (_a.label) {
446
- case 0: return [4, this.getAdapter(tableName).find(tableName, query, userId)];
447
- case 1: return [2, _a.sent()];
448
- }
449
- });
450
- });
451
- };
452
- SteedosDataSourceType.prototype.aggregate = function (tableName, query, externalPipeline, userId) {
453
- return tslib_1.__awaiter(this, void 0, void 0, function () {
454
- return tslib_1.__generator(this, function (_a) {
455
- switch (_a.label) {
456
- case 0: return [4, this.getAdapter(tableName).aggregate(tableName, query, externalPipeline, userId)];
457
- case 1: return [2, _a.sent()];
458
- }
459
- });
460
- });
461
- };
462
- SteedosDataSourceType.prototype.findOne = function (tableName, id, query, userId) {
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
- SteedosDataSourceType.prototype.count = function (tableName, query, userId) {
530
- return tslib_1.__awaiter(this, void 0, void 0, function () {
531
- return tslib_1.__generator(this, function (_a) {
532
- switch (_a.label) {
533
- case 0: return [4, this.getAdapter(tableName).count(tableName, query, userId)];
534
- case 1: return [2, _a.sent()];
535
- }
536
- });
537
- });
538
- };
539
- SteedosDataSourceType.prototype.directFind = function (tableName, query, userId) {
540
- return tslib_1.__awaiter(this, void 0, void 0, function () {
541
- return tslib_1.__generator(this, function (_a) {
542
- switch (_a.label) {
543
- case 0: return [4, this.getAdapter(tableName).directFind(tableName, query, userId)];
544
- case 1: return [2, _a.sent()];
545
- }
546
- });
547
- });
548
- };
549
- SteedosDataSourceType.prototype.directInsert = function (tableName, doc, userId) {
550
- return tslib_1.__awaiter(this, void 0, void 0, function () {
551
- return tslib_1.__generator(this, function (_a) {
552
- switch (_a.label) {
553
- case 0: return [4, this.getAdapter(tableName).directInsert(tableName, doc, userId)];
554
- case 1: return [2, _a.sent()];
555
- }
556
- });
557
- });
558
- };
559
- SteedosDataSourceType.prototype.directUpdate = function (tableName, id, doc, userId) {
560
- return tslib_1.__awaiter(this, void 0, void 0, function () {
561
- return tslib_1.__generator(this, function (_a) {
562
- switch (_a.label) {
563
- case 0: return [4, this.getAdapter(tableName).directUpdate(tableName, id, doc, userId)];
564
- case 1: return [2, _a.sent()];
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
- SteedosDataSourceType.prototype.dropTables = function () {
645
- return tslib_1.__awaiter(this, void 0, void 0, function () {
646
- return tslib_1.__generator(this, function (_a) {
647
- switch (_a.label) {
648
- case 0:
649
- if (!this._adapter.dropEntities) return [3, 2];
650
- return [4, this._adapter.dropEntities()];
651
- case 1: return [2, _a.sent()];
652
- case 2: return [2];
653
- }
654
- });
655
- });
656
- };
657
- SteedosDataSourceType.prototype.createTables = function () {
658
- return tslib_1.__awaiter(this, void 0, void 0, function () {
659
- return tslib_1.__generator(this, function (_a) {
660
- switch (_a.label) {
661
- case 0:
662
- if (!this._adapter.createTables) return [3, 2];
663
- return [4, this._adapter.createTables(this._objects)];
664
- case 1: return [2, _a.sent()];
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
- this.initializing = true;
678
- this.initPromise = (function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
679
- var broker_1, _a, error_1;
680
- return tslib_1.__generator(this, function (_b) {
681
- switch (_b.label) {
682
- case 0:
683
- _b.trys.push([0, 3, , 4]);
684
- this.initObjectPermissions();
685
- if (!!this.service) return [3, 2];
686
- broker_1 = this._schema.metadataBroker;
687
- _a = this;
688
- return [4, (0, index_2.createDataSourceService)(broker_1, this)];
689
- case 1:
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
- _this.setObjectPermission(object_name, objectRolePermission);
424
+ this.setObjectPermission(object_name, objectRolePermission);
713
425
  });
714
426
  });
715
- };
716
- SteedosDataSourceType.prototype.initTypeORM = function () {
717
- return tslib_1.__awaiter(this, void 0, void 0, function () {
718
- var _objects;
719
- return tslib_1.__generator(this, function (_a) {
720
- switch (_a.label) {
721
- case 0:
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
- SteedosDataSourceType.prototype.getAppsConfig = function () {
435
+ if (this._adapter.init) {
436
+ await this._adapter.init(_objects);
437
+ }
438
+ }
439
+ getAppsConfig() {
739
440
  return (0, _1.getAppConfigs)();
740
- };
741
- SteedosDataSourceType.prototype.getDashboardsConfig = function () {
441
+ }
442
+ getDashboardsConfig() {
742
443
  return (0, _1.getDashboardConfigs)();
743
- };
744
- SteedosDataSourceType.prototype.connect = function () {
745
- return tslib_1.__awaiter(this, void 0, void 0, function () {
746
- return tslib_1.__generator(this, function (_a) {
747
- switch (_a.label) {
748
- case 0:
749
- if (!this._adapter.connect) return [3, 2];
750
- return [4, this._adapter.connect()];
751
- case 1:
752
- _a.sent();
753
- _a.label = 2;
754
- case 2:
755
- if (!this._adapter.init) return [3, 4];
756
- return [4, this._adapter.init(this._objects)];
757
- case 3:
758
- _a.sent();
759
- _a.label = 4;
760
- case 4: return [2];
761
- }
762
- });
763
- });
764
- };
765
- SteedosDataSourceType.prototype.close = function () {
766
- return tslib_1.__awaiter(this, void 0, void 0, function () {
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
- return SteedosDataSourceType;
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);