@lcap/nasl 3.0.0-beta.5 → 3.0.0-beta.7

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 (121) hide show
  1. package/out/automate/engine/utils.js +1 -1
  2. package/out/automate/engine/utils.js.map +1 -1
  3. package/out/breakpoint/generator/BreakpointNode.js +30 -1
  4. package/out/breakpoint/generator/BreakpointNode.js.map +1 -1
  5. package/out/breakpoint/shared/utils.js +1 -1
  6. package/out/breakpoint/shared/utils.js.map +1 -1
  7. package/out/common/BaseNode.js +1 -1
  8. package/out/common/BaseNode.js.map +1 -1
  9. package/out/common/Command.js +1 -1
  10. package/out/common/Command.js.map +1 -1
  11. package/out/concepts/BatchAssignment__.js +3 -3
  12. package/out/concepts/BatchAssignment__.js.map +1 -1
  13. package/out/concepts/BindEvent__.js +3 -3
  14. package/out/concepts/BindEvent__.js.map +1 -1
  15. package/out/concepts/CallConnector__.d.ts +42 -0
  16. package/out/concepts/CallConnector__.js +198 -0
  17. package/out/concepts/CallConnector__.js.map +1 -0
  18. package/out/concepts/CallInterface__.js +2 -4
  19. package/out/concepts/CallInterface__.js.map +1 -1
  20. package/out/concepts/CallLogic__.js +1 -1
  21. package/out/concepts/CallLogic__.js.map +1 -1
  22. package/out/concepts/CallQueryComponent__.js +2 -2
  23. package/out/concepts/CallQueryComponent__.js.map +1 -1
  24. package/out/concepts/ConnectorTrigger__.d.ts +78 -0
  25. package/out/concepts/ConnectorTrigger__.js +155 -0
  26. package/out/concepts/ConnectorTrigger__.js.map +1 -0
  27. package/out/concepts/Connector__.d.ts +464 -0
  28. package/out/concepts/Connector__.js +698 -0
  29. package/out/concepts/Connector__.js.map +1 -0
  30. package/out/concepts/DataSource__.js +1 -1
  31. package/out/concepts/DataSource__.js.map +1 -1
  32. package/out/concepts/EntityProperty__.js +1 -1
  33. package/out/concepts/EntityProperty__.js.map +1 -1
  34. package/out/concepts/MemberExpression__.js +1 -1
  35. package/out/concepts/MemberExpression__.js.map +1 -1
  36. package/out/concepts/MsgTriggerEvent__.d.ts +137 -0
  37. package/out/concepts/MsgTriggerEvent__.js +228 -0
  38. package/out/concepts/MsgTriggerEvent__.js.map +1 -0
  39. package/out/concepts/MsgTriggerLauncher__.d.ts +118 -0
  40. package/out/concepts/MsgTriggerLauncher__.js +204 -0
  41. package/out/concepts/MsgTriggerLauncher__.js.map +1 -0
  42. package/out/concepts/SelectMembers__.js +1 -1
  43. package/out/concepts/SelectMembers__.js.map +1 -1
  44. package/out/concepts/StringLiteral__.js +5 -1
  45. package/out/concepts/StringLiteral__.js.map +1 -1
  46. package/out/concepts/TriggerEvent__.d.ts +120 -0
  47. package/out/concepts/TriggerEvent__.js +222 -0
  48. package/out/concepts/TriggerEvent__.js.map +1 -0
  49. package/out/concepts/TriggerLauncher__.d.ts +88 -0
  50. package/out/concepts/TriggerLauncher__.js +235 -0
  51. package/out/concepts/TriggerLauncher__.js.map +1 -0
  52. package/out/concepts/TypeAnnotation__.js +1 -1
  53. package/out/concepts/TypeAnnotation__.js.map +1 -1
  54. package/out/concepts/ViewElement__.js +1 -1
  55. package/out/concepts/ViewElement__.js.map +1 -1
  56. package/out/concepts/types__.d.ts +124 -0
  57. package/out/concepts/types__.js +3 -0
  58. package/out/concepts/types__.js.map +1 -0
  59. package/out/sentry/index.d.ts +8 -4
  60. package/out/sentry/index.js +84 -54
  61. package/out/sentry/index.js.map +1 -1
  62. package/out/server/entity2LogicNamespace.js +1 -1
  63. package/out/server/entity2LogicNamespace.js.map +1 -1
  64. package/out/server/extendBaseNode.js +9 -1
  65. package/out/server/extendBaseNode.js.map +1 -1
  66. package/out/server/formatTsUtils.js +2 -2
  67. package/out/server/formatTsUtils.js.map +1 -1
  68. package/out/server/getConnector.d.ts +11 -0
  69. package/out/server/getConnector.js +42 -0
  70. package/out/server/getConnector.js.map +1 -0
  71. package/out/server/getInterfaces.js +1 -1
  72. package/out/server/getInterfaces.js.map +1 -1
  73. package/out/server/getLogics.js +2 -2
  74. package/out/server/getLogics.js.map +1 -1
  75. package/out/server/getMemberIdentifier.js +2 -2
  76. package/out/server/getMemberIdentifier.js.map +1 -1
  77. package/out/server/getScope.js +3 -3
  78. package/out/server/getScope.js.map +1 -1
  79. package/out/server/naslServer.d.ts +2 -2
  80. package/out/server/naslServer.js +19 -7
  81. package/out/server/naslServer.js.map +1 -1
  82. package/out/server/translator.js +3 -3
  83. package/out/server/translator.js.map +1 -1
  84. package/out/service/storage/init.js +1 -1
  85. package/out/service/storage/init.js.map +1 -1
  86. package/out/utils/string.js +1 -1
  87. package/out/utils/string.js.map +1 -1
  88. package/package.json +1 -1
  89. package/src/automate/engine/utils.js +1 -1
  90. package/src/breakpoint/generator/BreakpointNode.ts +40 -1
  91. package/src/breakpoint/shared/utils.ts +1 -1
  92. package/src/common/BaseNode.ts +1 -1
  93. package/src/common/Command.ts +1 -1
  94. package/src/common/dist/Command.js +39 -0
  95. package/src/concepts/BatchAssignment__.ts +3 -3
  96. package/src/concepts/BindEvent__.ts +3 -3
  97. package/src/concepts/CallInterface__.ts +2 -3
  98. package/src/concepts/CallLogic__.ts +1 -1
  99. package/src/concepts/CallQueryComponent__.ts +2 -2
  100. package/src/concepts/DataSource__.ts +2 -2
  101. package/src/concepts/EntityProperty__.ts +1 -7
  102. package/src/concepts/MemberExpression__.ts +1 -1
  103. package/src/concepts/SelectMembers__.ts +1 -1
  104. package/src/concepts/StringLiteral__.ts +5 -1
  105. package/src/concepts/TypeAnnotation__.ts +17 -17
  106. package/src/concepts/ViewElement__.ts +1 -1
  107. package/src/concepts/dist/Entity__.js +729 -0
  108. package/src/concepts/dist/StringLiteral__.js +158 -0
  109. package/src/sentry/index.ts +99 -57
  110. package/src/server/dist/naslServer.js +52 -1
  111. package/src/server/entity2LogicNamespace.ts +1 -1
  112. package/src/server/extendBaseNode.ts +10 -1
  113. package/src/server/formatTsUtils.ts +2 -2
  114. package/src/server/getInterfaces.ts +1 -1
  115. package/src/server/getLogics.ts +2 -2
  116. package/src/server/getMemberIdentifier.ts +2 -2
  117. package/src/server/getScope.ts +3 -3
  118. package/src/server/naslServer.ts +12 -7
  119. package/src/server/translator.ts +3 -3
  120. package/src/service/storage/init.ts +1 -1
  121. package/src/utils/string.ts +1 -1
@@ -0,0 +1,729 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ var __assign = (this && this.__assign) || function () {
16
+ __assign = Object.assign || function(t) {
17
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
18
+ s = arguments[i];
19
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
20
+ t[p] = s[p];
21
+ }
22
+ return t;
23
+ };
24
+ return __assign.apply(this, arguments);
25
+ };
26
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
27
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
28
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
29
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
30
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
31
+ };
32
+ var __spreadArrays = (this && this.__spreadArrays) || function () {
33
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
34
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
35
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
36
+ r[k] = a[j];
37
+ return r;
38
+ };
39
+ exports.__esModule = true;
40
+ exports.Entity = void 0;
41
+ var translator_1 = require("../translator");
42
+ var entity2LogicNamespace_1 = require("../server/entity2LogicNamespace");
43
+ var decorators_1 = require("../decorators");
44
+ var utils = require("../utils");
45
+ var uuid_1 = require("uuid");
46
+ var BaseNode_1 = require("../common/BaseNode");
47
+ var classMap_1 = require("../common/classMap");
48
+ var EntityProperty__1 = require("./EntityProperty__");
49
+ var EntityIndex__1 = require("./EntityIndex__");
50
+ /**
51
+ * 实体
52
+ */
53
+ var Entity = /** @class */ (function (_super) {
54
+ __extends(Entity, _super);
55
+ /**
56
+ * @param source 需要合并的部分参数
57
+ */
58
+ function Entity(source) {
59
+ var _this = this;
60
+ source = Object.assign({}, Entity_1.getDefaultOptions(), source);
61
+ _this = _super.call(this, source) || this;
62
+ /**
63
+ * 产品概念
64
+ */
65
+ _this.concept = 'Entity';
66
+ /**
67
+ * 实体名称
68
+ */
69
+ _this.name = undefined;
70
+ /**
71
+ * 唯一标识
72
+ */
73
+ _this.uuid = uuid_1.v4().replace(/-/g, '');
74
+ /**
75
+ * 数据库表名
76
+ */
77
+ _this.tableName = undefined;
78
+ /**
79
+ * 实体描述
80
+ */
81
+ _this.description = undefined;
82
+ /**
83
+ * 实体来源
84
+ */
85
+ _this.origin = 'ide';
86
+ /**
87
+ * 实体属性列表
88
+ */
89
+ _this.properties = [];
90
+ /**
91
+ * 实体索引列表
92
+ */
93
+ _this.indexes = [];
94
+ _super.prototype.subConstructor.call(_this, source);
95
+ return _this;
96
+ }
97
+ Entity_1 = Entity;
98
+ Object.defineProperty(Entity.prototype, "module", {
99
+ /**
100
+ * 祖先 Module
101
+ */
102
+ get: function () {
103
+ return this.getAncestor('Module');
104
+ },
105
+ enumerable: false,
106
+ configurable: true
107
+ });
108
+ Object.defineProperty(Entity.prototype, "app", {
109
+ /**
110
+ * 祖先 App
111
+ */
112
+ get: function () {
113
+ return this.getAncestor('App');
114
+ },
115
+ enumerable: false,
116
+ configurable: true
117
+ });
118
+ Object.defineProperty(Entity.prototype, "dataSource", {
119
+ /**
120
+ * 祖先 DataSource
121
+ */
122
+ get: function () {
123
+ return this.getAncestor('DataSource');
124
+ },
125
+ enumerable: false,
126
+ configurable: true
127
+ });
128
+ Entity.prototype.getClassName = function () {
129
+ return 'Entity';
130
+ };
131
+ Entity.from = function (source, parentNode, parentKey) {
132
+ return _super.from.call(this, source, parentNode, parentKey);
133
+ };
134
+ /**
135
+ * 从父级删除该节点
136
+ * @internal
137
+ */
138
+ Entity.prototype._delete = function () {
139
+ var _a, _b;
140
+ var params = null;
141
+ if (this.parentNode) {
142
+ params = (_b = (_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.__removeEntity) === null || _b === void 0 ? void 0 : _b.call(_a, this);
143
+ }
144
+ return params;
145
+ };
146
+ /**
147
+ * 设置实体描述
148
+ */
149
+ Entity.prototype.setDescription = function (description) {
150
+ var object = {
151
+ description: description
152
+ };
153
+ this.update(__assign({}, object));
154
+ };
155
+ Entity.prototype.getPropertyExistingNames = function (excludedList) {
156
+ if (excludedList === void 0) { excludedList = []; }
157
+ var excludedSet = new Set(excludedList);
158
+ return (this.properties || []).filter(function (item) { return !excludedSet.has(item); }).map(function (item) { return item.name; });
159
+ };
160
+ Entity.prototype.getPropertyUniqueName = function (name) {
161
+ if (name === void 0) { name = 'property1'; }
162
+ return utils.unique(name, this.getPropertyExistingNames(), undefined, false);
163
+ };
164
+ Entity.prototype._insertPropertyAt = function (options, index) {
165
+ var propertyOptions = {};
166
+ var relationOptions = { parentNode: this, parentKey: 'properties' };
167
+ var property;
168
+ if (!options) {
169
+ property = EntityProperty__1["default"].from(__assign(__assign({}, propertyOptions), { name: this.getPropertyUniqueName() }), this, 'properties');
170
+ }
171
+ else if (typeof options === 'string') {
172
+ property = EntityProperty__1["default"].from(__assign(__assign({}, propertyOptions), { name: options }), this, 'properties');
173
+ }
174
+ else if (options instanceof EntityProperty__1["default"]) {
175
+ options.ensureDelete(); // 同一实例不支持多处存在
176
+ property = options;
177
+ Object.assign(property, relationOptions);
178
+ }
179
+ else {
180
+ property = EntityProperty__1["default"].from(__assign(__assign({}, propertyOptions), options), this, 'properties');
181
+ }
182
+ this.properties.splice(index, 0, property);
183
+ return property;
184
+ };
185
+ Entity.prototype.insertPropertyAt = function (options, index) {
186
+ var node = this._insertPropertyAt(options, index);
187
+ node.create({
188
+ index: index,
189
+ parentNode: this,
190
+ parentKey: 'properties'
191
+ });
192
+ return node;
193
+ };
194
+ Entity.prototype._addProperty = function (options) {
195
+ var index = this.properties.length;
196
+ return this._insertPropertyAt(options, index);
197
+ };
198
+ Entity.prototype.addProperty = function (options) {
199
+ var node = this._addProperty(options);
200
+ var index = this.properties.indexOf(node);
201
+ node.create({
202
+ index: index,
203
+ parentNode: this,
204
+ parentKey: 'properties'
205
+ });
206
+ return node;
207
+ };
208
+ Entity.prototype.getEntityIndexExistingNames = function (excludedList) {
209
+ if (excludedList === void 0) { excludedList = []; }
210
+ var excludedSet = new Set(excludedList);
211
+ return (this.indexes || []).filter(function (item) { return !excludedSet.has(item); }).map(function (item) { return item.name; });
212
+ };
213
+ Entity.prototype.getEntityIndexUniqueName = function (name) {
214
+ if (name === void 0) { name = 'entityIndex1'; }
215
+ return utils.unique(name, this.getEntityIndexExistingNames(), undefined, false);
216
+ };
217
+ Entity.prototype._insertEntityIndexAt = function (options, index) {
218
+ var entityIndexOptions = {};
219
+ var relationOptions = { parentNode: this, parentKey: 'indexes' };
220
+ var entityIndex;
221
+ if (!options) {
222
+ entityIndex = EntityIndex__1["default"].from(__assign(__assign({}, entityIndexOptions), { name: this.getEntityIndexUniqueName() }), this, 'indexes');
223
+ }
224
+ else if (typeof options === 'string') {
225
+ entityIndex = EntityIndex__1["default"].from(__assign(__assign({}, entityIndexOptions), { name: options }), this, 'indexes');
226
+ }
227
+ else if (options instanceof EntityIndex__1["default"]) {
228
+ options.ensureDelete(); // 同一实例不支持多处存在
229
+ entityIndex = options;
230
+ Object.assign(entityIndex, relationOptions);
231
+ }
232
+ else {
233
+ entityIndex = EntityIndex__1["default"].from(__assign(__assign({}, entityIndexOptions), options), this, 'indexes');
234
+ }
235
+ this.indexes.splice(index, 0, entityIndex);
236
+ return entityIndex;
237
+ };
238
+ Entity.prototype.insertEntityIndexAt = function (options, index) {
239
+ var node = this._insertEntityIndexAt(options, index);
240
+ node.create({
241
+ index: index,
242
+ parentNode: this,
243
+ parentKey: 'indexes'
244
+ });
245
+ return node;
246
+ };
247
+ Entity.prototype._addEntityIndex = function (options) {
248
+ var index = this.indexes.length;
249
+ return this._insertEntityIndexAt(options, index);
250
+ };
251
+ Entity.prototype.addEntityIndex = function (options) {
252
+ var node = this._addEntityIndex(options);
253
+ var index = this.indexes.indexOf(node);
254
+ node.create({
255
+ index: index,
256
+ parentNode: this,
257
+ parentKey: 'indexes'
258
+ });
259
+ return node;
260
+ };
261
+ Entity.prototype.removeProperty = function (options) {
262
+ var property;
263
+ if (typeof options === 'string') {
264
+ property = this.properties.find(function (item) { return item.name === options; });
265
+ if (!property) {
266
+ throw new Error('找不到实体属性 ' + options);
267
+ }
268
+ }
269
+ else {
270
+ property = options;
271
+ }
272
+ return property["delete"]();
273
+ };
274
+ Entity.prototype.__removeEntityProperty = function (property) {
275
+ var parentKey = property.parentKey;
276
+ var params = {
277
+ parentNode: this,
278
+ parentKey: parentKey,
279
+ index: -1,
280
+ object: null,
281
+ oldObject: property
282
+ };
283
+ if (parentKey) {
284
+ params.parentKey = parentKey;
285
+ if (Array.isArray(this[parentKey])) {
286
+ var index = this[parentKey].indexOf(property);
287
+ ~index && this[parentKey].splice(index, 1);
288
+ params.index = index;
289
+ }
290
+ else if (this[parentKey] === property) {
291
+ params.index = 0;
292
+ this[parentKey] = undefined;
293
+ }
294
+ }
295
+ return params;
296
+ };
297
+ Entity.prototype.removeEntityIndex = function (options) {
298
+ var entityIndex;
299
+ if (typeof options === 'string') {
300
+ entityIndex = this.indexes.find(function (item) { return item.name === options; });
301
+ if (!entityIndex) {
302
+ throw new Error('找不到实体索引 ' + options);
303
+ }
304
+ }
305
+ else {
306
+ entityIndex = options;
307
+ }
308
+ return entityIndex["delete"]();
309
+ };
310
+ Entity.prototype.__removeEntityIndex = function (entityIndex) {
311
+ var parentKey = entityIndex.parentKey;
312
+ var params = {
313
+ parentNode: this,
314
+ parentKey: parentKey,
315
+ index: -1,
316
+ object: null,
317
+ oldObject: entityIndex
318
+ };
319
+ if (parentKey) {
320
+ params.parentKey = parentKey;
321
+ if (Array.isArray(this[parentKey])) {
322
+ var index = this[parentKey].indexOf(entityIndex);
323
+ ~index && this[parentKey].splice(index, 1);
324
+ params.index = index;
325
+ }
326
+ else if (this[parentKey] === entityIndex) {
327
+ params.index = 0;
328
+ this[parentKey] = undefined;
329
+ }
330
+ }
331
+ return params;
332
+ };
333
+ //================================================================================
334
+ // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
335
+ // 自动生成的代码已结束。下面可以手动编写。
336
+ //================================================================================
337
+ Entity.prototype.getPropertyExistingColumnNames = function (excludedList) {
338
+ if (excludedList === void 0) { excludedList = []; }
339
+ var excludedSet = new Set(excludedList);
340
+ return (this.properties || []).filter(function (item) { return !excludedSet.has(item); }).map(function (item) { return item.columnName; });
341
+ };
342
+ Entity.prototype.getPropertyUniqueColumnName = function (name, excludedList) {
343
+ if (name === void 0) { name = 'property1'; }
344
+ if (excludedList === void 0) { excludedList = []; }
345
+ return utils.unique(name, this.getPropertyExistingColumnNames(excludedList), undefined, false);
346
+ };
347
+ Entity.prototype.getPropertyExistingNameList = function (excludedList) {
348
+ if (excludedList === void 0) { excludedList = []; }
349
+ var excludedSet = Array.from(new Set(excludedList));
350
+ var namelist = excludedSet.map(function (item) { return item.name; });
351
+ return (this.properties || []).filter(function (item) { return !namelist.includes(item.name); }).map(function (item) { return item.name; });
352
+ };
353
+ /**
354
+ * 设置实体表名并修改表名
355
+ */
356
+ Entity.prototype.setName = function (name) {
357
+ var object = {
358
+ name: name
359
+ };
360
+ // 根据 name 格式化表名
361
+ var oldName = this.name;
362
+ var oldTableName = this.tableName;
363
+ this.name = name;
364
+ this.tableName = name;
365
+ this.__formatTableName();
366
+ if (this.tableName !== oldTableName && !this.isIgnoreFormatTableAndColumnName()) {
367
+ object.tableName = this.tableName;
368
+ }
369
+ this.name = oldName;
370
+ this.tableName = oldTableName;
371
+ this.update(__assign(__assign({}, object), { field: 'name' }));
372
+ };
373
+ /**
374
+ * 设置实体表名
375
+ */
376
+ Entity.prototype.setTableName = function (tableName) {
377
+ var object = {
378
+ tableName: tableName
379
+ };
380
+ var oldTableName = this.tableName;
381
+ this.tableName = tableName;
382
+ this.__formatTableName();
383
+ if (this.tableName !== tableName && !this.isIgnoreFormatTableAndColumnName()) {
384
+ object.tableName = this.tableName;
385
+ }
386
+ this.tableName = oldTableName;
387
+ this.update(__assign({}, object));
388
+ };
389
+ // Excel、数据源导入的实体不进行表名格式化
390
+ Entity.prototype.isIgnoreFormatTableAndColumnName = function () {
391
+ return this.origin !== 'ide' && this.origin !== 'sql';
392
+ };
393
+ Entity.prototype.genFormatTableName = function () {
394
+ return this.parentNode.genFormatEntityTableName(this);
395
+ };
396
+ /**
397
+ * 根据全局设置中的数据库命名规则,生成 属性列名
398
+ */
399
+ Entity.prototype.genFormatPropertyColumnName = function (property) {
400
+ // Excel、数据源导入的实体不进行列名格式化
401
+ if (this.isIgnoreFormatTableAndColumnName()) {
402
+ return property.columnName || property.name;
403
+ }
404
+ var columnNameRule = this.app.preferenceMap['namingConvention.columnName'];
405
+ var formatMap = {
406
+ camelCase: utils.snake2Camel,
407
+ snake_case: utils.Camel2Snake
408
+ };
409
+ var columnNameFormatter = formatMap[columnNameRule];
410
+ var newColumnName = columnNameFormatter && columnNameFormatter(property.columnName || property.name, true);
411
+ newColumnName = this.getPropertyUniqueColumnName(newColumnName, [property]);
412
+ return newColumnName;
413
+ };
414
+ /**
415
+ * 根据全局设置中的数据库命名规则,将 实体表名 重命名
416
+ * 此方法不会 update
417
+ */
418
+ Entity.prototype.__formatTableName = function () {
419
+ // Excel、数据源导入的实体不进行表名格式化
420
+ if (this.isIgnoreFormatTableAndColumnName()) {
421
+ return;
422
+ }
423
+ var newTableName = this.genFormatTableName();
424
+ if (newTableName && newTableName !== this.tableName) {
425
+ this.tableName = newTableName;
426
+ }
427
+ };
428
+ /**
429
+ * 根据全局设置中的数据库命名规则,将 实体表名 重命名
430
+ */
431
+ Entity.prototype.formatTableName = function () {
432
+ // Excel、数据源导入的实体不进行表名格式化
433
+ if (this.isIgnoreFormatTableAndColumnName()) {
434
+ return;
435
+ }
436
+ var newTableName = this.genFormatTableName();
437
+ if (newTableName && newTableName !== this.tableName) {
438
+ this.update({ tableName: newTableName });
439
+ }
440
+ };
441
+ /**
442
+ * 根据全局设置中的数据库命名规则,将 属性列名 重命名
443
+ */
444
+ Entity.prototype.formatPropertyColumnName = function () {
445
+ // Excel、数据源导入的实体不进行列名格式化
446
+ if (this.isIgnoreFormatTableAndColumnName()) {
447
+ return;
448
+ }
449
+ // 重命名 properties columnName
450
+ this.properties.forEach(function (prop) { return prop.formatColumnName(); });
451
+ };
452
+ /**
453
+ * 根据全局设置中的数据库命名规则,将 属性列名 重命名
454
+ * 此方法不会 update
455
+ */
456
+ Entity.prototype.__formatPropertyColumnName = function () {
457
+ // Excel、数据源导入的实体不进行列名格式化
458
+ if (this.isIgnoreFormatTableAndColumnName()) {
459
+ return;
460
+ }
461
+ this.properties.forEach(function (prop) { return prop.__formatColumnName(); });
462
+ };
463
+ /**
464
+ * 根据全局设置中的数据库命名规则,将 实体表名 和 属性列名 重命名
465
+ */
466
+ Entity.prototype.formatTableAndColumnName = function () {
467
+ // Excel、数据源导入的实体不进行格式化
468
+ if (this.isIgnoreFormatTableAndColumnName()) {
469
+ return;
470
+ }
471
+ // 重命名 tableName
472
+ this.formatTableName();
473
+ // 重命名 properties columnName
474
+ this.formatPropertyColumnName();
475
+ };
476
+ Entity.getDefaultOptions = function () {
477
+ return {
478
+ properties: [
479
+ {
480
+ concept: 'EntityProperty',
481
+ name: 'id',
482
+ columnName: 'id',
483
+ label: '主键',
484
+ description: '主键',
485
+ primaryKey: true,
486
+ required: true,
487
+ typeAnnotation: {
488
+ concept: 'TypeAnnotation',
489
+ typeKind: 'primitive',
490
+ typeNamespace: 'nasl.core',
491
+ typeName: 'Long'
492
+ },
493
+ display: {
494
+ inTable: false,
495
+ inFilter: false,
496
+ inForm: false,
497
+ inDetail: false
498
+ }
499
+ },
500
+ {
501
+ concept: 'EntityProperty',
502
+ name: 'createdTime',
503
+ columnName: 'createdTime',
504
+ label: '创建时间',
505
+ description: '创建时间',
506
+ typeAnnotation: {
507
+ concept: 'TypeAnnotation',
508
+ typeKind: 'primitive',
509
+ typeNamespace: 'nasl.core',
510
+ typeName: 'DateTime'
511
+ },
512
+ display: {
513
+ inTable: true,
514
+ inFilter: false,
515
+ inForm: false,
516
+ inDetail: false
517
+ }
518
+ },
519
+ {
520
+ concept: 'EntityProperty',
521
+ name: 'updatedTime',
522
+ columnName: 'updatedTime',
523
+ label: '更新时间',
524
+ description: '更新时间',
525
+ typeAnnotation: {
526
+ concept: 'TypeAnnotation',
527
+ typeKind: 'primitive',
528
+ typeNamespace: 'nasl.core',
529
+ typeName: 'DateTime'
530
+ },
531
+ display: {
532
+ inTable: true,
533
+ inFilter: false,
534
+ inForm: false,
535
+ inDetail: false
536
+ }
537
+ },
538
+ {
539
+ concept: 'EntityProperty',
540
+ name: 'createdBy',
541
+ columnName: 'createdBy',
542
+ label: '创建者',
543
+ description: '创建者',
544
+ typeAnnotation: {
545
+ concept: 'TypeAnnotation',
546
+ typeKind: 'primitive',
547
+ typeNamespace: 'nasl.core',
548
+ typeName: 'String'
549
+ },
550
+ display: {
551
+ inTable: false,
552
+ inFilter: false,
553
+ inForm: false,
554
+ inDetail: false
555
+ }
556
+ },
557
+ {
558
+ concept: 'EntityProperty',
559
+ name: 'updatedBy',
560
+ columnName: 'updatedBy',
561
+ label: '更新者',
562
+ description: '更新者',
563
+ typeAnnotation: {
564
+ concept: 'TypeAnnotation',
565
+ typeKind: 'primitive',
566
+ typeNamespace: 'nasl.core',
567
+ typeName: 'String'
568
+ },
569
+ display: {
570
+ inTable: false,
571
+ inFilter: false,
572
+ inForm: false,
573
+ inDetail: false
574
+ }
575
+ },
576
+ ]
577
+ };
578
+ };
579
+ Entity.prototype.toEmbeddedTS = function (state) {
580
+ var code = "export class " + this.name + " {\n";
581
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0) + 1);
582
+ code += "__name: '" + this.getNamespace() + "." + this.name + "';\n";
583
+ this.properties.forEach(function (property) {
584
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0) + 1);
585
+ code += property.toEmbeddedTS(translator_1.shiftState(state, code, { tabSize: 0 }));
586
+ code += ';\n';
587
+ });
588
+ if (this.indexes && this.indexes.length) {
589
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0) + 1);
590
+ code += "__IndexList() {\n";
591
+ code += " return [";
592
+ this.indexes.forEach(function (entityIndex) {
593
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0) + 1);
594
+ code += '\n ';
595
+ code += entityIndex.toEmbeddedTS(translator_1.shiftState(state, code, { tabSize: 0 }));
596
+ });
597
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0)) + "\n ];\n }\n";
598
+ }
599
+ var ns = this.ns;
600
+ /**
601
+ * 11个函数的总行数
602
+ * 如果修改这里,可能会影响到dataSource的重命名, 在naslserver中,可能要一起修改
603
+ */
604
+ code += "\nstatic logics = {\n";
605
+ ns.logics.forEach(function (logic) {
606
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0) + 1);
607
+ code += logic.toEmbeddedTS(translator_1.shiftState(state, code), 'inObject');
608
+ });
609
+ code += '}\n';
610
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0)) + '}\n';
611
+ return code;
612
+ };
613
+ Entity.prototype.getNamespace = function () {
614
+ if (this.parentNode && this.parentNode.getNamespace)
615
+ return this.parentNode.getNamespace() + "." + this.parentNode.name + ".entities";
616
+ else
617
+ throw new Error('无法获取命名空间,请设置 parentNode!');
618
+ };
619
+ /**
620
+ * 生成宿主语言的文件路径
621
+ * @param name 一般不用传,用于 rename
622
+ */
623
+ Entity.prototype.getEmbeddedFilePath = function (name) {
624
+ if (name === void 0) { name = this.name; }
625
+ return "/embedded/" + this.app.name + "/datasources/" + this.parentNode.name + "/entities/" + name + ".ts";
626
+ };
627
+ Object.defineProperty(Entity.prototype, "ns", {
628
+ get: function () {
629
+ var ns = entity2LogicNamespace_1.entity2LogicNamespace(this);
630
+ ns.path = this.getNamespace();
631
+ return ns;
632
+ },
633
+ enumerable: false,
634
+ configurable: true
635
+ });
636
+ Object.defineProperty(Entity.prototype, "logics", {
637
+ // @excludedInJSON()
638
+ // nslogic: Namespace;
639
+ get: function () {
640
+ var ns = this.ns;
641
+ return ns.logics;
642
+ },
643
+ enumerable: false,
644
+ configurable: true
645
+ });
646
+ Entity.prototype.toEmbeddedTSFile = function () {
647
+ var code = "namespace " + this.getNamespace() + " {\n";
648
+ code += ' @nasl.annotation.Entity()\n';
649
+ var state = translator_1.createCompilerState(code, { tabSize: 1 });
650
+ try {
651
+ code += this.toEmbeddedTS(state);
652
+ }
653
+ catch (err) {
654
+ code += '';
655
+ console.log(err);
656
+ }
657
+ code += '}\n';
658
+ return {
659
+ code: code,
660
+ filePath: this.getEmbeddedFilePath(),
661
+ sourceMap: state.sourceMap
662
+ };
663
+ };
664
+ Object.defineProperty(Entity.prototype, "propertyPrimaryKeyNames", {
665
+ // 获取当前实体的所有主键名称
666
+ get: function () {
667
+ var arr = [];
668
+ this.properties.forEach(function (property) {
669
+ if (property.primaryKey) {
670
+ arr.push(property.name);
671
+ }
672
+ });
673
+ return arr;
674
+ },
675
+ enumerable: false,
676
+ configurable: true
677
+ });
678
+ /**
679
+ * 获取已有的属性
680
+ * 因为这个primaryIndex不允许添加
681
+ * @param excludedList 排除的集合
682
+ * @returns 有属性
683
+ */
684
+ Entity.prototype.getRenderEntityIndexExistingNames = function (excludedList) {
685
+ if (excludedList === void 0) { excludedList = []; }
686
+ var arr = this.getEntityIndexExistingNames(excludedList);
687
+ console.log(excludedList, arr);
688
+ return __spreadArrays(arr, ['primaryIndex']);
689
+ };
690
+ var Entity_1;
691
+ __decorate([
692
+ decorators_1.property()
693
+ ], Entity.prototype, "concept");
694
+ __decorate([
695
+ decorators_1.property()
696
+ ], Entity.prototype, "name");
697
+ __decorate([
698
+ decorators_1.property()
699
+ ], Entity.prototype, "uuid");
700
+ __decorate([
701
+ decorators_1.property()
702
+ ], Entity.prototype, "tableName");
703
+ __decorate([
704
+ decorators_1.property()
705
+ ], Entity.prototype, "description");
706
+ __decorate([
707
+ decorators_1.property()
708
+ ], Entity.prototype, "origin");
709
+ __decorate([
710
+ decorators_1.property('EntityProperty')
711
+ ], Entity.prototype, "properties");
712
+ __decorate([
713
+ decorators_1.property('EntityIndex')
714
+ ], Entity.prototype, "indexes");
715
+ __decorate([
716
+ translator_1.withSourceMap()
717
+ ], Entity.prototype, "toEmbeddedTS");
718
+ Entity = Entity_1 = __decorate([
719
+ decorators_1.concept('实体')
720
+ ], Entity);
721
+ return Entity;
722
+ }(BaseNode_1["default"]));
723
+ exports.Entity = Entity;
724
+ classMap_1["default"].Entity = Entity;
725
+ exports["default"] = Entity;
726
+ //================================================================================
727
+ // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
728
+ // 自动生成的代码已结束。下面可以手动编写。
729
+ //================================================================================