oak-domain 2.6.7 → 2.6.8

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.
@@ -5,30 +5,35 @@ var Action_1 = require("./Action");
5
5
  exports.desc = {
6
6
  attributes: {
7
7
  targetEntity: {
8
+ notNull: true,
8
9
  type: "varchar",
9
10
  params: {
10
11
  length: 32
11
12
  }
12
13
  },
13
14
  entity: {
15
+ notNull: true,
14
16
  type: "varchar",
15
17
  params: {
16
18
  length: 32
17
19
  }
18
20
  },
19
21
  entityId: {
22
+ notNull: true,
20
23
  type: "varchar",
21
24
  params: {
22
25
  length: 64
23
26
  }
24
27
  },
25
28
  action: {
29
+ notNull: true,
26
30
  type: "varchar",
27
31
  params: {
28
32
  length: 16
29
33
  }
30
34
  },
31
35
  data: {
36
+ notNull: true,
32
37
  type: "object"
33
38
  },
34
39
  filter: {
@@ -5,10 +5,12 @@ var action_1 = require("../../actions/action");
5
5
  exports.desc = {
6
6
  attributes: {
7
7
  modiId: {
8
+ notNull: true,
8
9
  type: "ref",
9
10
  ref: "modi"
10
11
  },
11
12
  entity: {
13
+ notNull: true,
12
14
  type: "varchar",
13
15
  params: {
14
16
  length: 32
@@ -16,6 +18,7 @@ exports.desc = {
16
18
  ref: ["user", "userEntityGrant"]
17
19
  },
18
20
  entityId: {
21
+ notNull: true,
19
22
  type: "varchar",
20
23
  params: {
21
24
  length: 64
@@ -5,12 +5,14 @@ var action_1 = require("../../actions/action");
5
5
  exports.desc = {
6
6
  attributes: {
7
7
  action: {
8
+ notNull: true,
8
9
  type: "varchar",
9
10
  params: {
10
11
  length: 16
11
12
  }
12
13
  },
13
14
  data: {
15
+ notNull: true,
14
16
  type: "object"
15
17
  },
16
18
  filter: {
@@ -24,6 +26,7 @@ exports.desc = {
24
26
  ref: "user"
25
27
  },
26
28
  targetEntity: {
29
+ notNull: true,
27
30
  type: "varchar",
28
31
  params: {
29
32
  length: 32
@@ -5,10 +5,12 @@ var action_1 = require("../../actions/action");
5
5
  exports.desc = {
6
6
  attributes: {
7
7
  operId: {
8
+ notNull: true,
8
9
  type: "ref",
9
10
  ref: "oper"
10
11
  },
11
12
  entity: {
13
+ notNull: true,
12
14
  type: "varchar",
13
15
  params: {
14
16
  length: 32
@@ -16,6 +18,7 @@ exports.desc = {
16
18
  ref: ["user", "userEntityGrant"]
17
19
  },
18
20
  entityId: {
21
+ notNull: true,
19
22
  type: "varchar",
20
23
  params: {
21
24
  length: 64
@@ -5,18 +5,21 @@ var action_1 = require("../../actions/action");
5
5
  exports.desc = {
6
6
  attributes: {
7
7
  entity: {
8
+ notNull: true,
8
9
  type: "varchar",
9
10
  params: {
10
11
  length: 32
11
12
  }
12
13
  },
13
14
  entityId: {
15
+ notNull: true,
14
16
  type: "varchar",
15
17
  params: {
16
18
  length: 64
17
19
  }
18
20
  },
19
21
  relation: {
22
+ notNull: true,
20
23
  type: "varchar",
21
24
  params: {
22
25
  length: 32
@@ -8,6 +8,7 @@ function createDynamicCheckers(schema, authDict) {
8
8
  var checkers = [];
9
9
  checkers.push.apply(checkers, tslib_1.__spreadArray([], tslib_1.__read((0, modi_1.createModiRelatedCheckers)(schema)), false));
10
10
  checkers.push.apply(checkers, tslib_1.__spreadArray([], tslib_1.__read((0, checker_1.createRemoveCheckers)(schema, authDict)), false));
11
+ checkers.push.apply(checkers, tslib_1.__spreadArray([], tslib_1.__read((0, checker_1.createCreateCheckers)(schema)), false));
11
12
  if (authDict) {
12
13
  checkers.push.apply(checkers, tslib_1.__spreadArray([], tslib_1.__read((0, checker_1.createAuthCheckers)(schema, authDict)), false));
13
14
  }
@@ -2917,7 +2917,10 @@ function constructAttributes(entity) {
2917
2917
  var result = [];
2918
2918
  schemaAttrs.forEach(function (attr) {
2919
2919
  var attrAssignments = [];
2920
- var name = attr.name, type = attr.type;
2920
+ var name = attr.name, type = attr.type, allowNull = attr.questionToken;
2921
+ if (!allowNull) {
2922
+ attrAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("notNull"), factory.createTrue()));
2923
+ }
2921
2924
  var name2 = name;
2922
2925
  if (ts.isTypeReferenceNode(type)) {
2923
2926
  var typeName = type.typeName, typeArguments = type.typeArguments;
@@ -30,3 +30,4 @@ export declare function createAuthCheckers<ED extends EntityDict & BaseEntityDic
30
30
  * 如果有的对象允许删除,需要使用trigger来处理其相关联的外键对象,这些trigger写作before,则会在checker之前执行,仍然可以删除成功
31
31
  */
32
32
  export declare function createRemoveCheckers<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED> | SyncContext<ED>>(schema: StorageSchema<ED>, authDict?: AuthDefDict<ED>): Checker<ED, keyof ED, Cxt>[];
33
+ export declare function createCreateCheckers<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED> | SyncContext<ED>>(schema: StorageSchema<ED>): Checker<ED, keyof ED, Cxt>[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createRemoveCheckers = exports.createAuthCheckers = exports.translateCheckerInSyncContext = exports.translateCheckerInAsyncContext = void 0;
3
+ exports.createCreateCheckers = exports.createRemoveCheckers = exports.createAuthCheckers = exports.translateCheckerInSyncContext = exports.translateCheckerInAsyncContext = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var assert_1 = tslib_1.__importDefault(require("assert"));
6
6
  var filter_1 = require("../store/filter");
@@ -11,6 +11,7 @@ var string_1 = require("../utils/string");
11
11
  var lodash_1 = require("../utils/lodash");
12
12
  var relation_1 = require("./relation");
13
13
  var uuid_1 = require("../utils/uuid");
14
+ var action_1 = require("../actions/action");
14
15
  /**
15
16
  *
16
17
  * @param checker 要翻译的checker
@@ -1216,3 +1217,155 @@ function createRemoveCheckers(schema, authDict) {
1216
1217
  return checkers;
1217
1218
  }
1218
1219
  exports.createRemoveCheckers = createRemoveCheckers;
1220
+ function checkAttributeLegal(schema, entity, data) {
1221
+ var _a;
1222
+ var attributes = schema[entity].attributes;
1223
+ for (var attr in data) {
1224
+ if (attributes[attr]) {
1225
+ var _b = attributes[attr], type = _b.type, params = _b.params, defaultValue = _b.default, enumeration = _b.enumeration, notNull = _b.notNull;
1226
+ if (data[attr] === null || data[attr] === undefined) {
1227
+ if (notNull && defaultValue === undefined) {
1228
+ throw new Exception_1.OakAttrNotNullException(entity, [attr]);
1229
+ }
1230
+ if (defaultValue !== undefined) {
1231
+ Object.assign(data, (_a = {},
1232
+ _a[attr] = defaultValue,
1233
+ _a));
1234
+ }
1235
+ continue;
1236
+ }
1237
+ switch (type) {
1238
+ case 'char':
1239
+ case 'varchar': {
1240
+ if (typeof data[attr] !== 'string') {
1241
+ throw new Exception_1.OakInputIllegalException(entity, [attr], 'not a string');
1242
+ }
1243
+ var length_1 = params.length;
1244
+ if (length_1 && data[attr].length > length_1) {
1245
+ throw new Exception_1.OakInputIllegalException(entity, [attr], 'too long');
1246
+ }
1247
+ break;
1248
+ }
1249
+ case 'int':
1250
+ case 'smallint':
1251
+ case 'tinyint':
1252
+ case 'bigint':
1253
+ case 'decimal':
1254
+ case 'money': {
1255
+ if (typeof data[attr] !== 'number') {
1256
+ throw new Exception_1.OakInputIllegalException(entity, [attr], 'not a number');
1257
+ }
1258
+ var _c = params || {}, min = _c.min, max = _c.max;
1259
+ if (typeof min === 'number' && data[attr] < min) {
1260
+ throw new Exception_1.OakInputIllegalException(entity, [attr], 'too small');
1261
+ }
1262
+ if (typeof max === 'number' && data[attr] > max) {
1263
+ throw new Exception_1.OakInputIllegalException(entity, [attr], 'too big');
1264
+ }
1265
+ break;
1266
+ }
1267
+ case 'enum': {
1268
+ (0, assert_1.default)(enumeration);
1269
+ if (!enumeration.includes(data[attr])) {
1270
+ throw new Exception_1.OakInputIllegalException(entity, [attr], 'not in enumberation');
1271
+ }
1272
+ break;
1273
+ }
1274
+ }
1275
+ }
1276
+ else {
1277
+ // 这里似乎还有一种update中带cascade remove的case,等遇到再说(貌似cascadeUpdate没有处理完整这种情况) by Xc
1278
+ if (typeof data[attr] === 'object' && data[attr].action === 'remove') {
1279
+ console.warn('cascade remove可能是未处理的边界,请注意');
1280
+ }
1281
+ }
1282
+ }
1283
+ }
1284
+ function createCreateCheckers(schema) {
1285
+ var checkers = [];
1286
+ var _loop_9 = function (entity) {
1287
+ var _a = schema[entity], attributes = _a.attributes, actions = _a.actions;
1288
+ var notNullAttrs = Object.keys(attributes).filter(function (ele) { return attributes[ele].notNull; });
1289
+ var updateActions = (0, lodash_1.difference)(actions, action_1.excludeUpdateActions);
1290
+ checkers.push({
1291
+ entity: entity,
1292
+ type: 'data',
1293
+ action: 'create',
1294
+ checker: function (data) {
1295
+ var checkData = function (data2) {
1296
+ var e_9, _a, e_10, _b;
1297
+ var illegalNullAttrs = (0, lodash_1.difference)(notNullAttrs, Object.keys(data2));
1298
+ if (illegalNullAttrs.length > 0) {
1299
+ try {
1300
+ // 要处理多对一的cascade create
1301
+ for (var illegalNullAttrs_1 = (e_9 = void 0, tslib_1.__values(illegalNullAttrs)), illegalNullAttrs_1_1 = illegalNullAttrs_1.next(); !illegalNullAttrs_1_1.done; illegalNullAttrs_1_1 = illegalNullAttrs_1.next()) {
1302
+ var attr = illegalNullAttrs_1_1.value;
1303
+ if (attr === 'entityId') {
1304
+ if (illegalNullAttrs.includes('entity')) {
1305
+ continue;
1306
+ }
1307
+ }
1308
+ else if (attr === 'entity' && attributes[attr].type === 'ref') {
1309
+ var hasCascadeCreate = false;
1310
+ try {
1311
+ for (var _c = (e_10 = void 0, tslib_1.__values(attributes[attr].ref)), _d = _c.next(); !_d.done; _d = _c.next()) {
1312
+ var ref = _d.value;
1313
+ if (data2[ref] && data2[ref].action === 'create') {
1314
+ hasCascadeCreate = true;
1315
+ break;
1316
+ }
1317
+ }
1318
+ }
1319
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
1320
+ finally {
1321
+ try {
1322
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
1323
+ }
1324
+ finally { if (e_10) throw e_10.error; }
1325
+ }
1326
+ if (hasCascadeCreate) {
1327
+ continue;
1328
+ }
1329
+ }
1330
+ else if (attributes[attr].type === 'ref') {
1331
+ var ref = attributes[attr].ref;
1332
+ if (data2[ref] && data2[ref].action === 'create') {
1333
+ continue;
1334
+ }
1335
+ }
1336
+ // 到这里说明确实是有not null的属性没有赋值
1337
+ throw new Exception_1.OakAttrNotNullException(entity, illegalNullAttrs);
1338
+ }
1339
+ }
1340
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
1341
+ finally {
1342
+ try {
1343
+ if (illegalNullAttrs_1_1 && !illegalNullAttrs_1_1.done && (_a = illegalNullAttrs_1.return)) _a.call(illegalNullAttrs_1);
1344
+ }
1345
+ finally { if (e_9) throw e_9.error; }
1346
+ }
1347
+ }
1348
+ checkAttributeLegal(schema, entity, data2);
1349
+ };
1350
+ if (data instanceof Array) {
1351
+ data.forEach(function (ele) { return checkData(ele); });
1352
+ }
1353
+ else {
1354
+ checkData(data);
1355
+ }
1356
+ }
1357
+ }, {
1358
+ entity: entity,
1359
+ type: 'data',
1360
+ action: updateActions,
1361
+ checker: function (data) {
1362
+ checkAttributeLegal(schema, entity, data);
1363
+ }
1364
+ });
1365
+ };
1366
+ for (var entity in schema) {
1367
+ _loop_9(entity);
1368
+ }
1369
+ return checkers;
1370
+ }
1371
+ exports.createCreateCheckers = createCreateCheckers;
package/lib/store/modi.js CHANGED
@@ -151,8 +151,8 @@ function createModiRelatedTriggers(schema) {
151
151
  var _this = this;
152
152
  var triggers = [];
153
153
  var _loop_2 = function (entity) {
154
- var inModi = schema[entity].inModi;
155
- if (inModi) {
154
+ var toModi = schema[entity].toModi;
155
+ if (toModi) {
156
156
  // 当关联modi的对象被删除时,对应的modi也删除。这里似乎只需要删除掉活跃对象?因为oper不能删除,所以oper和modi是必须要支持对deleted对象的容错?
157
157
  // 这里没有想清楚,by Xc 20230209
158
158
  triggers.push({
@@ -55,6 +55,7 @@ function judgeRelation(schema, entity, attr) {
55
55
  else if (attributes.hasOwnProperty('entity')
56
56
  && attributes.hasOwnProperty('entityId')
57
57
  && schema.hasOwnProperty(attr)) {
58
+ (0, assert_1.default)(attributes.entity.ref.includes(attr), '不应当出现的case');
58
59
  // 反向指针的外键
59
60
  return 2;
60
61
  }
@@ -5,7 +5,6 @@ var tslib_1 = require("tslib");
5
5
  var dayjs_1 = tslib_1.__importDefault(require("dayjs"));
6
6
  var fs_1 = require("fs");
7
7
  var filter_1 = require("../store/filter");
8
- var node_zlib_1 = require("node:zlib");
9
8
  var stream_1 = require("stream");
10
9
  var uuid_1 = require("../utils/uuid");
11
10
  /**
@@ -23,7 +22,7 @@ function vaccumEntities(option, context) {
23
22
  case 0:
24
23
  entities = option.entities, backupDir = option.backupDir;
25
24
  _loop_1 = function (ele) {
26
- var entity, filter, aliveLine, filter2, zip, now, backFile, fd_1, attributes_1, projection_1, attr, count_1, appendData_1, gzip_1, source_1, destination_1, _c, _d, _e;
25
+ var entity, filter, aliveLine, filter2, zip, now, backFile, fd_1, attributes_1, projection_1, attr, count_1, appendData_1, createGzip, gzip_1, source_1, destination_1, _c, _d, _e;
27
26
  var _f, _g;
28
27
  return tslib_1.__generator(this, function (_h) {
29
28
  switch (_h.label) {
@@ -37,7 +36,7 @@ function vaccumEntities(option, context) {
37
36
  if (filter) {
38
37
  filter2 = (0, filter_1.combineFilters)([filter2, filter]);
39
38
  }
40
- if (!backupDir) return [3 /*break*/, 4];
39
+ if (!(backupDir && process.env.OAK_PLATFORM === 'server')) return [3 /*break*/, 4];
41
40
  zip = option.zip;
42
41
  now = (0, dayjs_1.default)();
43
42
  backFile = "".concat(backupDir, "/").concat(entity, "-").concat(now.format('YYYY-MM-DD HH:mm:ss'), ".csv");
@@ -107,7 +106,8 @@ function vaccumEntities(option, context) {
107
106
  return [3 /*break*/, 4];
108
107
  case 2:
109
108
  if (!zip) return [3 /*break*/, 4];
110
- gzip_1 = (0, node_zlib_1.createGzip)();
109
+ createGzip = require('zlib').createGzip;
110
+ gzip_1 = createGzip();
111
111
  source_1 = (0, fs_1.createReadStream)(backFile);
112
112
  destination_1 = (0, fs_1.createWriteStream)("".concat(backFile, ".zip"));
113
113
  return [4 /*yield*/, new Promise(function (resolve, reject) {
@@ -65,7 +65,7 @@ export interface EntityShape {
65
65
  $$updateAt$$: number | Date;
66
66
  $$deleteAt$$?: number | Date | null;
67
67
  }
68
- interface GeneralEntityShape extends EntityShape {
68
+ export interface GeneralEntityShape extends EntityShape {
69
69
  [K: string]: any;
70
70
  }
71
71
  export declare type MakeAction<A extends string> = A;
@@ -55,12 +55,15 @@ export declare class OakRowInconsistencyException<ED extends EntityDict> extends
55
55
  export declare class OakInputIllegalException<ED extends EntityDict> extends OakUserException<ED> {
56
56
  private attributes;
57
57
  private entity;
58
- constructor(entity: string, attributes: string[], message?: string);
59
- getEntity(): string;
58
+ constructor(entity: keyof ED, attributes: string[], message?: string);
59
+ getEntity(): keyof ED;
60
60
  getAttributes(): string[];
61
61
  addAttributesPrefix(prefix: string): void;
62
62
  toString(): string;
63
63
  }
64
+ export declare class OakAttrNotNullException<ED extends EntityDict> extends OakInputIllegalException<ED> {
65
+ constructor(entity: keyof ED, attributes: string[], message?: string);
66
+ }
64
67
  /**
65
68
  * 用户权限不够时抛的异常
66
69
  */
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeException = exports.OakPreConditionUnsetException = exports.OakDeadlock = exports.OakCongruentRowExists = exports.OakRowLockedException = exports.OakUnloggedInException = exports.OakUserUnpermittedException = exports.OakInputIllegalException = exports.OakRowInconsistencyException = exports.OakUserException = exports.OakExternalException = exports.OakRowUnexistedException = exports.OakOperExistedException = exports.OakImportDataParseException = exports.OakUniqueViolationException = exports.OakDataException = exports.OakException = void 0;
3
+ exports.makeException = exports.OakPreConditionUnsetException = exports.OakDeadlock = exports.OakCongruentRowExists = exports.OakRowLockedException = exports.OakUnloggedInException = exports.OakUserUnpermittedException = exports.OakAttrNotNullException = exports.OakInputIllegalException = exports.OakRowInconsistencyException = exports.OakUserException = exports.OakExternalException = exports.OakRowUnexistedException = exports.OakOperExistedException = exports.OakImportDataParseException = exports.OakUniqueViolationException = exports.OakDataException = exports.OakException = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var assert_1 = tslib_1.__importDefault(require("assert"));
6
6
  var OakException = /** @class */ (function (_super) {
@@ -179,6 +179,15 @@ var OakInputIllegalException = /** @class */ (function (_super) {
179
179
  }(OakUserException));
180
180
  exports.OakInputIllegalException = OakInputIllegalException;
181
181
  ;
182
+ // 属性为空
183
+ var OakAttrNotNullException = /** @class */ (function (_super) {
184
+ tslib_1.__extends(OakAttrNotNullException, _super);
185
+ function OakAttrNotNullException(entity, attributes, message) {
186
+ return _super.call(this, entity, attributes, message || '属性不允许为空') || this;
187
+ }
188
+ return OakAttrNotNullException;
189
+ }(OakInputIllegalException));
190
+ exports.OakAttrNotNullException = OakAttrNotNullException;
182
191
  /**
183
192
  * 用户权限不够时抛的异常
184
193
  */
@@ -344,6 +353,11 @@ function makeException(data) {
344
353
  e.setOpRecords(data.opRecords);
345
354
  return e;
346
355
  }
356
+ case 'OakAttrNotNullException': {
357
+ var e = new OakAttrNotNullException(data.entity, data.attributes, data.message);
358
+ e.setOpRecords(data.opRecords);
359
+ return e;
360
+ }
347
361
  default:
348
362
  return;
349
363
  }
@@ -114,7 +114,7 @@ function checkAttributesNotNull(entity, data, attributes, allowEmpty) {
114
114
  }
115
115
  });
116
116
  if (attrs.length > 0) {
117
- throw new types_1.OakInputIllegalException(entity, attrs, '属性不能为空');
117
+ throw new types_1.OakAttrNotNullException(entity, attrs, '属性不能为空');
118
118
  }
119
119
  }
120
120
  exports.checkAttributesNotNull = checkAttributesNotNull;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oak-domain",
3
- "version": "2.6.7",
3
+ "version": "2.6.8",
4
4
  "author": {
5
5
  "name": "XuChang"
6
6
  },