oak-domain 2.6.3 → 2.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/compiler/schemalBuilder.js +18 -12
- package/lib/entities/Modi.js +1 -0
- package/lib/entities/ModiEntity.js +1 -0
- package/lib/entities/Oper.js +1 -0
- package/lib/entities/OperEntity.js +1 -0
- package/lib/entities/User.js +1 -0
- package/lib/entities/UserEntityGrant.js +1 -0
- package/lib/store/AsyncRowStore.js +40 -42
- package/lib/store/checker.js +278 -134
- package/lib/types/DataType.d.ts +4 -1
- package/lib/types/DataType.js +2 -1
- package/lib/types/Locale.d.ts +1 -0
- package/lib/types/Style.d.ts +11 -0
- package/lib/types/Style.js +2 -0
- package/lib/types/Timer.d.ts +3 -2
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +1 -0
- package/lib/types/schema/DataTypes.d.ts +2 -0
- package/lib/utils/SimpleConnector.js +6 -5
- package/lib/utils/mask.d.ts +5 -0
- package/lib/utils/mask.js +35 -0
- package/lib/utils/money.d.ts +5 -0
- package/lib/utils/money.js +24 -0
- package/lib/utils/validator.d.ts +1 -0
- package/lib/utils/validator.js +8 -3
- package/package.json +3 -2
- package/src/entities/Modi.ts +1 -0
- package/src/entities/ModiEntity.ts +1 -0
- package/src/entities/Oper.ts +1 -0
- package/src/entities/OperEntity.ts +1 -0
- package/src/entities/User.ts +1 -0
- package/src/entities/UserEntityGrant.ts +1 -0
- package/lib/utils/cron.d.ts +0 -1
- package/lib/utils/cron.js +0 -18
|
@@ -1123,7 +1123,8 @@ function constructFilter(statements, entity) {
|
|
|
1123
1123
|
case 'Int':
|
|
1124
1124
|
case 'Uint':
|
|
1125
1125
|
case 'Float':
|
|
1126
|
-
case 'Double':
|
|
1126
|
+
case 'Double':
|
|
1127
|
+
case 'Price': {
|
|
1127
1128
|
type2 = factory.createTypeReferenceNode(factory.createIdentifier('Q_NumberValue'));
|
|
1128
1129
|
break;
|
|
1129
1130
|
}
|
|
@@ -1276,7 +1277,8 @@ function constructProjection(statements, entity) {
|
|
|
1276
1277
|
case 'File':
|
|
1277
1278
|
case 'SingleGeo':
|
|
1278
1279
|
case 'Geo':
|
|
1279
|
-
case 'Object':
|
|
1280
|
+
case 'Object':
|
|
1281
|
+
case 'Price': {
|
|
1280
1282
|
properties.push([name_4, false]);
|
|
1281
1283
|
break;
|
|
1282
1284
|
}
|
|
@@ -1639,7 +1641,8 @@ function constructSorter(statements, entity) {
|
|
|
1639
1641
|
case 'Boolean':
|
|
1640
1642
|
case 'Datetime':
|
|
1641
1643
|
case 'Image':
|
|
1642
|
-
case 'File':
|
|
1644
|
+
case 'File':
|
|
1645
|
+
case 'Price': {
|
|
1643
1646
|
type2 = factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword);
|
|
1644
1647
|
break;
|
|
1645
1648
|
}
|
|
@@ -2658,6 +2661,7 @@ var initialStatements = function () { return [
|
|
|
2658
2661
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier('Text')),
|
|
2659
2662
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier('Datetime')),
|
|
2660
2663
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier('File')),
|
|
2664
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier('Price')),
|
|
2661
2665
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier('Image')),
|
|
2662
2666
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier('PrimaryKey')),
|
|
2663
2667
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier('ForeignKey')),
|
|
@@ -2934,15 +2938,13 @@ function constructAttributes(entity) {
|
|
|
2934
2938
|
], true)));
|
|
2935
2939
|
break;
|
|
2936
2940
|
}
|
|
2937
|
-
case '
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
case 'Double': {
|
|
2945
|
-
attrAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("type"), factory.createStringLiteral("double")), factory.createPropertyAssignment(factory.createIdentifier("params"), factory.createObjectLiteralExpression([
|
|
2941
|
+
case 'Double':
|
|
2942
|
+
case 'Float':
|
|
2943
|
+
case 'Decimal': {
|
|
2944
|
+
if (['Double', 'Float'].includes(text)) {
|
|
2945
|
+
console.warn("".concat(entity, "\u5BF9\u8C61\u4E2D\u8FD8\u6709").concat(text, "\u7C7B\u578B\u5B9A\u4E49\uFF0C\u73B0\u5728\u7EDF\u4E00\u7528Decimal\u8FDB\u884C\u5B58\u50A8"));
|
|
2946
|
+
}
|
|
2947
|
+
attrAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("type"), factory.createStringLiteral("decimal")), factory.createPropertyAssignment(factory.createIdentifier("params"), factory.createObjectLiteralExpression([
|
|
2946
2948
|
factory.createPropertyAssignment(factory.createIdentifier("precision"), factory.createNumericLiteral(typeArguments[0].literal.text)),
|
|
2947
2949
|
factory.createPropertyAssignment(factory.createIdentifier("scale"), factory.createNumericLiteral(typeArguments[1].literal.text))
|
|
2948
2950
|
], true)));
|
|
@@ -2952,6 +2954,10 @@ function constructAttributes(entity) {
|
|
|
2952
2954
|
attrAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("type"), factory.createStringLiteral("boolean")));
|
|
2953
2955
|
break;
|
|
2954
2956
|
}
|
|
2957
|
+
case 'Price': {
|
|
2958
|
+
attrAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("type"), factory.createStringLiteral("money")));
|
|
2959
|
+
break;
|
|
2960
|
+
}
|
|
2955
2961
|
case 'Datetime': {
|
|
2956
2962
|
attrAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("type"), factory.createStringLiteral("datetime")));
|
|
2957
2963
|
break;
|
package/lib/entities/Modi.js
CHANGED
package/lib/entities/Oper.js
CHANGED
package/lib/entities/User.js
CHANGED
|
@@ -64,93 +64,91 @@ var AsyncContext = /** @class */ (function () {
|
|
|
64
64
|
};
|
|
65
65
|
AsyncContext.prototype.commit = function () {
|
|
66
66
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
67
|
-
var
|
|
68
|
-
var e_1,
|
|
69
|
-
return tslib_1.__generator(this, function (
|
|
70
|
-
switch (
|
|
67
|
+
var commitEvents, commitEvents_1, commitEvents_1_1, e, e_1_1;
|
|
68
|
+
var e_1, _a;
|
|
69
|
+
return tslib_1.__generator(this, function (_b) {
|
|
70
|
+
switch (_b.label) {
|
|
71
71
|
case 0:
|
|
72
|
-
if (!this.uuid) return [3 /*break*/,
|
|
72
|
+
if (!this.uuid) return [3 /*break*/, 9];
|
|
73
73
|
return [4 /*yield*/, this.rowStore.commit(this.uuid)];
|
|
74
74
|
case 1:
|
|
75
|
-
|
|
75
|
+
_b.sent();
|
|
76
76
|
this.uuid = undefined;
|
|
77
|
-
|
|
77
|
+
commitEvents = this.events.commit;
|
|
78
|
+
this.resetEvents();
|
|
79
|
+
_b.label = 2;
|
|
78
80
|
case 2:
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
_b.trys.push([2, 7, 8, 9]);
|
|
82
|
+
commitEvents_1 = tslib_1.__values(commitEvents), commitEvents_1_1 = commitEvents_1.next();
|
|
83
|
+
_b.label = 3;
|
|
82
84
|
case 3:
|
|
83
|
-
if (!!
|
|
84
|
-
e =
|
|
85
|
+
if (!!commitEvents_1_1.done) return [3 /*break*/, 6];
|
|
86
|
+
e = commitEvents_1_1.value;
|
|
85
87
|
return [4 /*yield*/, e()];
|
|
86
88
|
case 4:
|
|
87
|
-
|
|
88
|
-
|
|
89
|
+
_b.sent();
|
|
90
|
+
_b.label = 5;
|
|
89
91
|
case 5:
|
|
90
|
-
|
|
92
|
+
commitEvents_1_1 = commitEvents_1.next();
|
|
91
93
|
return [3 /*break*/, 3];
|
|
92
94
|
case 6: return [3 /*break*/, 9];
|
|
93
95
|
case 7:
|
|
94
|
-
e_1_1 =
|
|
96
|
+
e_1_1 = _b.sent();
|
|
95
97
|
e_1 = { error: e_1_1 };
|
|
96
98
|
return [3 /*break*/, 9];
|
|
97
99
|
case 8:
|
|
98
100
|
try {
|
|
99
|
-
if (
|
|
101
|
+
if (commitEvents_1_1 && !commitEvents_1_1.done && (_a = commitEvents_1.return)) _a.call(commitEvents_1);
|
|
100
102
|
}
|
|
101
103
|
finally { if (e_1) throw e_1.error; }
|
|
102
104
|
return [7 /*endfinally*/];
|
|
103
|
-
case 9:
|
|
104
|
-
this.resetEvents();
|
|
105
|
-
_d.label = 10;
|
|
106
|
-
case 10: return [2 /*return*/];
|
|
105
|
+
case 9: return [2 /*return*/];
|
|
107
106
|
}
|
|
108
107
|
});
|
|
109
108
|
});
|
|
110
109
|
};
|
|
111
110
|
AsyncContext.prototype.rollback = function () {
|
|
112
111
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
113
|
-
var
|
|
114
|
-
var e_2,
|
|
115
|
-
return tslib_1.__generator(this, function (
|
|
116
|
-
switch (
|
|
112
|
+
var rollbackEvents, rollbackEvents_1, rollbackEvents_1_1, e, e_2_1;
|
|
113
|
+
var e_2, _a;
|
|
114
|
+
return tslib_1.__generator(this, function (_b) {
|
|
115
|
+
switch (_b.label) {
|
|
117
116
|
case 0:
|
|
118
|
-
if (!this.uuid) return [3 /*break*/,
|
|
117
|
+
if (!this.uuid) return [3 /*break*/, 9];
|
|
119
118
|
return [4 /*yield*/, this.rowStore.rollback(this.uuid)];
|
|
120
119
|
case 1:
|
|
121
|
-
|
|
120
|
+
_b.sent();
|
|
122
121
|
// console.log('rollback', this.uuid);
|
|
123
122
|
this.uuid = undefined;
|
|
124
|
-
|
|
123
|
+
rollbackEvents = this.events.rollback;
|
|
124
|
+
this.resetEvents();
|
|
125
|
+
_b.label = 2;
|
|
125
126
|
case 2:
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
_b.trys.push([2, 7, 8, 9]);
|
|
128
|
+
rollbackEvents_1 = tslib_1.__values(rollbackEvents), rollbackEvents_1_1 = rollbackEvents_1.next();
|
|
129
|
+
_b.label = 3;
|
|
129
130
|
case 3:
|
|
130
|
-
if (!!
|
|
131
|
-
e =
|
|
131
|
+
if (!!rollbackEvents_1_1.done) return [3 /*break*/, 6];
|
|
132
|
+
e = rollbackEvents_1_1.value;
|
|
132
133
|
return [4 /*yield*/, e()];
|
|
133
134
|
case 4:
|
|
134
|
-
|
|
135
|
-
|
|
135
|
+
_b.sent();
|
|
136
|
+
_b.label = 5;
|
|
136
137
|
case 5:
|
|
137
|
-
|
|
138
|
+
rollbackEvents_1_1 = rollbackEvents_1.next();
|
|
138
139
|
return [3 /*break*/, 3];
|
|
139
140
|
case 6: return [3 /*break*/, 9];
|
|
140
141
|
case 7:
|
|
141
|
-
e_2_1 =
|
|
142
|
+
e_2_1 = _b.sent();
|
|
142
143
|
e_2 = { error: e_2_1 };
|
|
143
144
|
return [3 /*break*/, 9];
|
|
144
145
|
case 8:
|
|
145
146
|
try {
|
|
146
|
-
if (
|
|
147
|
+
if (rollbackEvents_1_1 && !rollbackEvents_1_1.done && (_a = rollbackEvents_1.return)) _a.call(rollbackEvents_1);
|
|
147
148
|
}
|
|
148
149
|
finally { if (e_2) throw e_2.error; }
|
|
149
150
|
return [7 /*endfinally*/];
|
|
150
|
-
case 9:
|
|
151
|
-
this.resetEvents();
|
|
152
|
-
_d.label = 10;
|
|
153
|
-
case 10: return [2 /*return*/];
|
|
151
|
+
case 9: return [2 /*return*/];
|
|
154
152
|
}
|
|
155
153
|
});
|
|
156
154
|
});
|
package/lib/store/checker.js
CHANGED
|
@@ -339,12 +339,18 @@ function translateCascadeRelationFilterMaker(schema, lch, entity2, pathPrefix) {
|
|
|
339
339
|
};
|
|
340
340
|
var filterMaker = paths.length ? translateFilterMakerIter(entity2, 0) : translateRelationFilter(entity2);
|
|
341
341
|
if (!paths.length) {
|
|
342
|
+
// 不可能是create
|
|
342
343
|
return function (oper, userId) { return filterMaker(userId); };
|
|
343
344
|
}
|
|
344
345
|
/**
|
|
345
346
|
* 针对第一层做一下特别优化,比如对象A指向对象B(多对一),如果A的cascadePath是 'B',
|
|
346
347
|
* 当create A时,会带有Bid。此时生成该B对象上的相关表达式查询返回,可以避免必须将此判定在对象创建之后再做
|
|
347
348
|
* 另一使用场景是,在查询A时,如果带有Bid(在对象跳一对多子对象场景下很常见),可以提前判定这个查询对某些用户一定返回空集
|
|
349
|
+
*
|
|
350
|
+
* 20230306:
|
|
351
|
+
* 在前台的权限判断中,会将list上的filter当成内在的限制对create动作进行判断,此时有一种可能是,filter并不能直接判断出外键,但会限制外键的查询范围。
|
|
352
|
+
* 例如,在jichuang项目中,就存在park/list上,平台的用户去访问时,其查询条件是{ system: { platformId: 1 }};而用户的关系落在system.platform.platformProvider上,
|
|
353
|
+
* 此时如直接通过data上的外键判断就会失败,需要通过对filter上相应的语义解构,进行进一步的判断
|
|
348
354
|
*/
|
|
349
355
|
var _a = tslib_1.__read(paths, 1), attr = _a[0];
|
|
350
356
|
var relation = (0, relation_1.judgeRelation)(schema, entity2, attr);
|
|
@@ -352,54 +358,129 @@ function translateCascadeRelationFilterMaker(schema, lch, entity2, pathPrefix) {
|
|
|
352
358
|
var filterMaker2 = paths.length > 1
|
|
353
359
|
? (relation === 2 ? translateFilterMakerIter(attr, 1) : translateFilterMakerIter(relation, 1))
|
|
354
360
|
: (relation === 2 ? translateRelationFilter(attr) : translateRelationFilter(relation));
|
|
361
|
+
var translateCreateFilterMaker = function (entity, filter, userId) {
|
|
362
|
+
var counters = [];
|
|
363
|
+
if (filter) {
|
|
364
|
+
if (relation === 2) {
|
|
365
|
+
if (filter.entity === attr && filter.entityId) {
|
|
366
|
+
// 这里对entityId的限定的数据只要和userId有一条relation,就不能否定可能会有创建动作(外键在最终create时,data上一定会有判定)
|
|
367
|
+
counters.push({
|
|
368
|
+
$entity: attr,
|
|
369
|
+
$filter: (0, filter_1.addFilterSegment)(filterMaker2(userId), { id: filter.entityId }),
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
if (filter[attr]) {
|
|
373
|
+
counters.push({
|
|
374
|
+
$entity: attr,
|
|
375
|
+
$filter: (0, filter_1.addFilterSegment)(filterMaker2(userId), filter[attr]),
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
(0, assert_1.default)(typeof relation === 'string');
|
|
381
|
+
if (filter["".concat(attr, "Id")]) {
|
|
382
|
+
var filterMaker3 = paths.length > 1 ? translateFilterMakerIter(relation, 1) : translateRelationFilter(relation);
|
|
383
|
+
// 这里对attrId的限定的数据只要和userId有一条relation,就不能否定可能会有创建动作(外键在最终create时,data上一定会有判定)
|
|
384
|
+
counters.push({
|
|
385
|
+
$entity: relation,
|
|
386
|
+
$filter: (0, filter_1.addFilterSegment)(filterMaker3(userId), { id: filter["".concat(attr, "Id")] }),
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
if (filter[attr]) {
|
|
390
|
+
counters.push({
|
|
391
|
+
$entity: relation,
|
|
392
|
+
$filter: (0, filter_1.addFilterSegment)(filterMaker2(userId), filter[attr]),
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
if (filter.$and) {
|
|
397
|
+
var countersAnd = filter.$and.map(function (ele) { return translateCreateFilterMaker(entity, ele, userId); });
|
|
398
|
+
// and 只要有一个满足就行
|
|
399
|
+
var ca2 = countersAnd.filter(function (ele) { return !(ele instanceof Exception_1.OakUserUnpermittedException); });
|
|
400
|
+
counters.push.apply(counters, tslib_1.__spreadArray([], tslib_1.__read(ca2), false));
|
|
401
|
+
}
|
|
402
|
+
if (filter.$or) {
|
|
403
|
+
var countersOr = filter.$and.map(function (ele) { return translateCreateFilterMaker(entity, ele, userId); });
|
|
404
|
+
// or也只要有一个满足就行(不能否定)
|
|
405
|
+
var co2 = countersOr.filter(function (ele) { return !(ele instanceof Exception_1.OakUserUnpermittedException); });
|
|
406
|
+
counters.push.apply(counters, tslib_1.__spreadArray([], tslib_1.__read(co2), false));
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
if (counters.length === 0) {
|
|
410
|
+
// 一个counter都找不出来,说明当前路径上不满足
|
|
411
|
+
return new Exception_1.OakUserUnpermittedException();
|
|
412
|
+
}
|
|
413
|
+
else if (counters.length === 1) {
|
|
414
|
+
return counters[0];
|
|
415
|
+
}
|
|
416
|
+
// 是or关系,只要其中有一个满足就可以通过
|
|
417
|
+
return {
|
|
418
|
+
$$or: counters,
|
|
419
|
+
};
|
|
420
|
+
};
|
|
355
421
|
return function (operation, userId) {
|
|
356
422
|
var action = operation.action;
|
|
357
423
|
if (action === 'create') {
|
|
358
424
|
var data = operation.data;
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
425
|
+
if (data) {
|
|
426
|
+
// 有data的情形根据data判定
|
|
427
|
+
var getForeignKeyId_1 = function (d) {
|
|
428
|
+
if (relation === 2) {
|
|
429
|
+
if (d.entity === attr && typeof d.entityId === 'string') {
|
|
430
|
+
return d.entityId;
|
|
431
|
+
}
|
|
432
|
+
throw new Exception_1.OakUserUnpermittedException();
|
|
363
433
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
434
|
+
else {
|
|
435
|
+
(0, assert_1.default)(typeof relation === 'string');
|
|
436
|
+
if (typeof d["".concat(attr, "Id")] === 'string') {
|
|
437
|
+
return d["".concat(attr, "Id")];
|
|
438
|
+
}
|
|
439
|
+
throw new Exception_1.OakUserUnpermittedException();
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
if (relation === 2) {
|
|
443
|
+
if (data instanceof Array) {
|
|
444
|
+
var fkIds = (0, lodash_1.uniq)(data.map(function (d) { return getForeignKeyId_1(d); }));
|
|
445
|
+
return {
|
|
446
|
+
$entity: attr,
|
|
447
|
+
$filter: (0, filter_1.addFilterSegment)(filterMaker2(userId), { id: { $in: fkIds } }),
|
|
448
|
+
$count: fkIds.length,
|
|
449
|
+
};
|
|
370
450
|
}
|
|
371
|
-
|
|
451
|
+
var fkId_1 = getForeignKeyId_1(data);
|
|
452
|
+
return {
|
|
453
|
+
$entity: attr,
|
|
454
|
+
$filter: (0, filter_1.addFilterSegment)(filterMaker2(userId), { id: fkId_1 }),
|
|
455
|
+
};
|
|
372
456
|
}
|
|
373
|
-
|
|
374
|
-
if (relation === 2) {
|
|
457
|
+
(0, assert_1.default)(typeof relation === 'string');
|
|
375
458
|
if (data instanceof Array) {
|
|
376
459
|
var fkIds = (0, lodash_1.uniq)(data.map(function (d) { return getForeignKeyId_1(d); }));
|
|
377
460
|
return {
|
|
378
|
-
$entity:
|
|
461
|
+
$entity: relation,
|
|
379
462
|
$filter: (0, filter_1.addFilterSegment)(filterMaker2(userId), { id: { $in: fkIds } }),
|
|
380
463
|
$count: fkIds.length,
|
|
381
464
|
};
|
|
382
465
|
}
|
|
383
|
-
var
|
|
384
|
-
return {
|
|
385
|
-
$entity: attr,
|
|
386
|
-
$filter: (0, filter_1.addFilterSegment)(filterMaker2(userId), { id: fkId_1 }),
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
(0, assert_1.default)(typeof relation === 'string');
|
|
390
|
-
if (data instanceof Array) {
|
|
391
|
-
var fkIds = (0, lodash_1.uniq)(data.map(function (d) { return getForeignKeyId_1(d); }));
|
|
466
|
+
var fkId = getForeignKeyId_1(data);
|
|
392
467
|
return {
|
|
393
468
|
$entity: relation,
|
|
394
|
-
$filter: (0, filter_1.addFilterSegment)(filterMaker2(userId), { id:
|
|
395
|
-
$count: fkIds.length,
|
|
469
|
+
$filter: (0, filter_1.addFilterSegment)(filterMaker2(userId), { id: fkId }),
|
|
396
470
|
};
|
|
397
471
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
472
|
+
else {
|
|
473
|
+
// todo
|
|
474
|
+
var filter_4 = operation.filter;
|
|
475
|
+
if (filter_4) {
|
|
476
|
+
var counter = translateCreateFilterMaker(entity2, filter_4, userId);
|
|
477
|
+
if (counter instanceof Exception_1.OakUserUnpermittedException) {
|
|
478
|
+
throw counter;
|
|
479
|
+
}
|
|
480
|
+
return counter;
|
|
481
|
+
}
|
|
482
|
+
throw new Exception_1.OakUserUnpermittedException();
|
|
483
|
+
}
|
|
403
484
|
}
|
|
404
485
|
var filter = operation.filter;
|
|
405
486
|
if (relation === 2 && (filter === null || filter === void 0 ? void 0 : filter.entity) === attr && (filter === null || filter === void 0 ? void 0 : filter.entityId)) {
|
|
@@ -450,8 +531,77 @@ function translateActionAuthFilterMaker(schema, relationItem, entity, pathPrefix
|
|
|
450
531
|
var filterMaker = translateCascadeRelationFilterMaker(schema, relationItem, entity, pathPrefix);
|
|
451
532
|
return filterMaker;
|
|
452
533
|
}
|
|
534
|
+
function execCreateCounter(context, counter) {
|
|
535
|
+
if (counter === null || counter === void 0 ? void 0 : counter.$$and) {
|
|
536
|
+
// 每个counter都要满足才能过
|
|
537
|
+
var counters = counter === null || counter === void 0 ? void 0 : counter.$$and;
|
|
538
|
+
(0, assert_1.default)(counters.length > 0);
|
|
539
|
+
var counterResults = counters.map(function (ele) { return execCreateCounter(context, ele); });
|
|
540
|
+
if (counterResults[0] instanceof Promise) {
|
|
541
|
+
return Promise.all(counterResults)
|
|
542
|
+
.then(function (cr2) {
|
|
543
|
+
var unpermitted = cr2.find(function (ele) { return ele instanceof Exception_1.OakUserUnpermittedException; });
|
|
544
|
+
if (unpermitted) {
|
|
545
|
+
return unpermitted;
|
|
546
|
+
}
|
|
547
|
+
return undefined;
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
else {
|
|
551
|
+
var unpermitted = counterResults.find(function (ele) { return ele instanceof Exception_1.OakUserUnpermittedException; });
|
|
552
|
+
if (unpermitted) {
|
|
553
|
+
return unpermitted;
|
|
554
|
+
}
|
|
555
|
+
else {
|
|
556
|
+
return undefined;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
else if (counter === null || counter === void 0 ? void 0 : counter.$$or) {
|
|
561
|
+
// 只要有一个counter能过就算过
|
|
562
|
+
var counters = counter === null || counter === void 0 ? void 0 : counter.$$or;
|
|
563
|
+
(0, assert_1.default)(counters.length > 0);
|
|
564
|
+
var counterResults = counters.map(function (ele) { return execCreateCounter(context, ele); });
|
|
565
|
+
if (counterResults[0] instanceof Promise) {
|
|
566
|
+
return Promise.all(counterResults)
|
|
567
|
+
.then(function (cr2) {
|
|
568
|
+
var permittedIdx = cr2.indexOf(undefined);
|
|
569
|
+
if (permittedIdx !== -1) {
|
|
570
|
+
return undefined;
|
|
571
|
+
}
|
|
572
|
+
return new Exception_1.OakUserUnpermittedException();
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
else {
|
|
576
|
+
var permittedIndex = counterResults.indexOf(undefined);
|
|
577
|
+
if (permittedIndex !== -1) {
|
|
578
|
+
return undefined;
|
|
579
|
+
}
|
|
580
|
+
else {
|
|
581
|
+
return new Exception_1.OakUserUnpermittedException();
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
else if (counter === null || counter === void 0 ? void 0 : counter.$entity) {
|
|
586
|
+
var _a = counter, $entity = _a.$entity, $filter = _a.$filter, _b = _a.$count, $count_1 = _b === void 0 ? 1 : _b;
|
|
587
|
+
var count = context.count($entity, {
|
|
588
|
+
filter: $filter,
|
|
589
|
+
}, { dontCollect: true });
|
|
590
|
+
if (count instanceof Promise) {
|
|
591
|
+
return count.then(function (c2) {
|
|
592
|
+
if (c2 >= $count_1) {
|
|
593
|
+
return undefined;
|
|
594
|
+
}
|
|
595
|
+
return new Exception_1.OakUserUnpermittedException();
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
else {
|
|
599
|
+
return count >= $count_1 ? undefined : new Exception_1.OakUserUnpermittedException();
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
453
603
|
function makePotentialFilter(operation, context, filterMaker) {
|
|
454
|
-
var e_1, _a;
|
|
604
|
+
var e_1, _a, e_2, _b;
|
|
455
605
|
var userId = context.getCurrentUserId();
|
|
456
606
|
(0, assert_1.default)(userId);
|
|
457
607
|
var filters = filterMaker instanceof Array ? filterMaker.map(function (ele) {
|
|
@@ -470,103 +620,81 @@ function makePotentialFilter(operation, context, filterMaker) {
|
|
|
470
620
|
*/
|
|
471
621
|
var filtersOr = [];
|
|
472
622
|
var isAsyncOr = false;
|
|
473
|
-
|
|
474
|
-
var
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
var
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
return undefined;
|
|
623
|
+
try {
|
|
624
|
+
for (var filters_1 = tslib_1.__values(filters), filters_1_1 = filters_1.next(); !filters_1_1.done; filters_1_1 = filters_1.next()) {
|
|
625
|
+
var f = filters_1_1.value;
|
|
626
|
+
if (f instanceof Array) {
|
|
627
|
+
var isAsyncAnd = false;
|
|
628
|
+
(0, assert_1.default)(f.length > 0);
|
|
629
|
+
var filtersAnd = [];
|
|
630
|
+
try {
|
|
631
|
+
for (var f_1 = (e_2 = void 0, tslib_1.__values(f)), f_1_1 = f_1.next(); !f_1_1.done; f_1_1 = f_1.next()) {
|
|
632
|
+
var ff = f_1_1.value;
|
|
633
|
+
if ((ff === null || ff === void 0 ? void 0 : ff.$$and) || (ff === null || ff === void 0 ? void 0 : ff.$$or) || (ff === null || ff === void 0 ? void 0 : ff.$entity)) {
|
|
634
|
+
// 每个counter都要满足才能过
|
|
635
|
+
var result = execCreateCounter(context, ff);
|
|
636
|
+
if (result instanceof Promise) {
|
|
637
|
+
isAsyncAnd = true;
|
|
489
638
|
}
|
|
490
|
-
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
639
|
+
filtersAnd.push(result);
|
|
640
|
+
}
|
|
641
|
+
else if (ff) {
|
|
642
|
+
filtersAnd.push(ff);
|
|
643
|
+
}
|
|
495
644
|
}
|
|
496
645
|
}
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
}
|
|
500
|
-
};
|
|
501
|
-
try {
|
|
502
|
-
for (var f_1 = (e_2 = void 0, tslib_1.__values(f)), f_1_1 = f_1.next(); !f_1_1.done; f_1_1 = f_1.next()) {
|
|
503
|
-
var ff = f_1_1.value;
|
|
504
|
-
_loop_2(ff);
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
508
|
-
finally {
|
|
509
|
-
try {
|
|
510
|
-
if (f_1_1 && !f_1_1.done && (_b = f_1.return)) _b.call(f_1);
|
|
511
|
-
}
|
|
512
|
-
finally { if (e_2) throw e_2.error; }
|
|
513
|
-
}
|
|
514
|
-
if (isAsyncAnd = true) {
|
|
515
|
-
isAsyncOr = true;
|
|
516
|
-
filtersOr.push(isAsyncAnd ? Promise.all(filtersAnd).then(function (fa) {
|
|
517
|
-
var e_3, _a;
|
|
518
|
-
var faR = [];
|
|
646
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
647
|
+
finally {
|
|
519
648
|
try {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
649
|
+
if (f_1_1 && !f_1_1.done && (_b = f_1.return)) _b.call(f_1);
|
|
650
|
+
}
|
|
651
|
+
finally { if (e_2) throw e_2.error; }
|
|
652
|
+
}
|
|
653
|
+
if (isAsyncAnd = true) {
|
|
654
|
+
isAsyncOr = true;
|
|
655
|
+
filtersOr.push(isAsyncAnd ? Promise.all(filtersAnd).then(function (fa) {
|
|
656
|
+
var e_3, _a;
|
|
657
|
+
var faR = [];
|
|
658
|
+
try {
|
|
659
|
+
for (var fa_1 = (e_3 = void 0, tslib_1.__values(fa)), fa_1_1 = fa_1.next(); !fa_1_1.done; fa_1_1 = fa_1.next()) {
|
|
660
|
+
var faItem = fa_1_1.value;
|
|
661
|
+
if (faItem instanceof Exception_1.OakUserUnpermittedException) {
|
|
662
|
+
return faItem;
|
|
663
|
+
}
|
|
664
|
+
else if (faItem) {
|
|
665
|
+
faR.push(faItem);
|
|
666
|
+
}
|
|
524
667
|
}
|
|
525
|
-
|
|
526
|
-
|
|
668
|
+
}
|
|
669
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
670
|
+
finally {
|
|
671
|
+
try {
|
|
672
|
+
if (fa_1_1 && !fa_1_1.done && (_a = fa_1.return)) _a.call(fa_1);
|
|
527
673
|
}
|
|
674
|
+
finally { if (e_3) throw e_3.error; }
|
|
528
675
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
if (fa_1_1 && !fa_1_1.done && (_a = fa_1.return)) _a.call(fa_1);
|
|
676
|
+
if (faR.length > 0) {
|
|
677
|
+
return {
|
|
678
|
+
$and: faR,
|
|
679
|
+
};
|
|
534
680
|
}
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
$and: faR,
|
|
540
|
-
};
|
|
541
|
-
}
|
|
542
|
-
}) : {
|
|
543
|
-
$and: filtersAnd,
|
|
544
|
-
});
|
|
681
|
+
}) : {
|
|
682
|
+
$and: filtersAnd,
|
|
683
|
+
});
|
|
684
|
+
}
|
|
545
685
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
if (count instanceof Promise) {
|
|
554
|
-
isAsyncOr = true;
|
|
555
|
-
filtersOr.push(count.then(function (c2) { return c2 >= $count_2 ? undefined : new Exception_1.OakUserUnpermittedException(); }));
|
|
686
|
+
else {
|
|
687
|
+
if ((f === null || f === void 0 ? void 0 : f.$$and) || (f === null || f === void 0 ? void 0 : f.$$or) || (f === null || f === void 0 ? void 0 : f.$entity)) {
|
|
688
|
+
var counterResults = execCreateCounter(context, f);
|
|
689
|
+
if (counterResults instanceof Promise) {
|
|
690
|
+
isAsyncOr = true;
|
|
691
|
+
}
|
|
692
|
+
filtersOr.push(counterResults);
|
|
556
693
|
}
|
|
557
|
-
else {
|
|
558
|
-
filtersOr.push(
|
|
694
|
+
else if (f) {
|
|
695
|
+
filtersOr.push(f);
|
|
559
696
|
}
|
|
560
697
|
}
|
|
561
|
-
else if (f) {
|
|
562
|
-
filtersOr.push(f);
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
};
|
|
566
|
-
try {
|
|
567
|
-
for (var filters_1 = tslib_1.__values(filters), filters_1_1 = filters_1.next(); !filters_1_1.done; filters_1_1 = filters_1.next()) {
|
|
568
|
-
var f = filters_1_1.value;
|
|
569
|
-
_loop_1(f);
|
|
570
698
|
}
|
|
571
699
|
}
|
|
572
700
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -603,18 +731,30 @@ function makePotentialFilter(operation, context, filterMaker) {
|
|
|
603
731
|
*/
|
|
604
732
|
function createAuthCheckers(schema, authDict) {
|
|
605
733
|
var checkers = [];
|
|
606
|
-
var
|
|
734
|
+
var _loop_1 = function (entity) {
|
|
607
735
|
var _a;
|
|
608
736
|
if (authDict[entity]) {
|
|
609
737
|
var _b = authDict[entity], relationAuth = _b.relationAuth, actionAuth = _b.actionAuth;
|
|
610
738
|
if (relationAuth) {
|
|
611
739
|
var raFilterMakerDict_1 = {};
|
|
612
740
|
var userEntityName = "user".concat((0, string_1.firstLetterUpperCase)(entity));
|
|
741
|
+
var allAuthItem = [];
|
|
613
742
|
for (var r in relationAuth) {
|
|
743
|
+
var authItem = relationAuth[r];
|
|
614
744
|
Object.assign(raFilterMakerDict_1, (_a = {},
|
|
615
|
-
_a[r] = translateActionAuthFilterMaker(schema,
|
|
745
|
+
_a[r] = translateActionAuthFilterMaker(schema, authItem, userEntityName, entity),
|
|
616
746
|
_a));
|
|
747
|
+
if (authItem instanceof Array) {
|
|
748
|
+
allAuthItem.push.apply(allAuthItem, tslib_1.__spreadArray([], tslib_1.__read(authItem), false));
|
|
749
|
+
}
|
|
750
|
+
else {
|
|
751
|
+
allAuthItem.push(authItem);
|
|
752
|
+
}
|
|
617
753
|
}
|
|
754
|
+
// 如果不指定relation,则使用所有的authItem的or组合
|
|
755
|
+
Object.assign(raFilterMakerDict_1, {
|
|
756
|
+
'@@all': translateActionAuthFilterMaker(schema, allAuthItem, userEntityName, entity),
|
|
757
|
+
});
|
|
618
758
|
var entityIdAttr_1 = "".concat(entity, "Id");
|
|
619
759
|
checkers.push({
|
|
620
760
|
entity: userEntityName,
|
|
@@ -624,8 +764,12 @@ function createAuthCheckers(schema, authDict) {
|
|
|
624
764
|
var data = operation.data;
|
|
625
765
|
(0, assert_1.default)(!(data instanceof Array));
|
|
626
766
|
var _a = data, relation = _a.relation, _b = entityIdAttr_1, entityId = _a[_b];
|
|
767
|
+
if (!relation) {
|
|
768
|
+
// 不指定relation测试是否有创建权限
|
|
769
|
+
return makePotentialFilter(operation, context, raFilterMakerDict_1['@@all']);
|
|
770
|
+
}
|
|
627
771
|
if (!raFilterMakerDict_1[relation]) {
|
|
628
|
-
|
|
772
|
+
throw new Exception_1.OakUserUnpermittedException();
|
|
629
773
|
}
|
|
630
774
|
var filter = makePotentialFilter(operation, context, raFilterMakerDict_1[relation]);
|
|
631
775
|
return filter;
|
|
@@ -694,7 +838,7 @@ function createAuthCheckers(schema, authDict) {
|
|
|
694
838
|
// todo 等实现的时候再写
|
|
695
839
|
}
|
|
696
840
|
if (actionAuth) {
|
|
697
|
-
var
|
|
841
|
+
var _loop_2 = function (a) {
|
|
698
842
|
var filterMaker = translateActionAuthFilterMaker(schema, actionAuth[a], entity);
|
|
699
843
|
checkers.push({
|
|
700
844
|
entity: entity,
|
|
@@ -709,13 +853,13 @@ function createAuthCheckers(schema, authDict) {
|
|
|
709
853
|
});
|
|
710
854
|
};
|
|
711
855
|
for (var a in actionAuth) {
|
|
712
|
-
|
|
856
|
+
_loop_2(a);
|
|
713
857
|
}
|
|
714
858
|
}
|
|
715
859
|
}
|
|
716
860
|
};
|
|
717
861
|
for (var entity in schema) {
|
|
718
|
-
|
|
862
|
+
_loop_1(entity);
|
|
719
863
|
}
|
|
720
864
|
return checkers;
|
|
721
865
|
}
|
|
@@ -784,7 +928,7 @@ function createRemoveCheckers(schema, authDict) {
|
|
|
784
928
|
}
|
|
785
929
|
// 当删除一时,要确认多上面没有指向一的数据
|
|
786
930
|
var entities = (0, lodash_1.union)(Object.keys(OneToManyMatrix), Object.keys(OneToManyOnEntityMatrix));
|
|
787
|
-
var
|
|
931
|
+
var _loop_3 = function (entity) {
|
|
788
932
|
checkers.push({
|
|
789
933
|
entity: entity,
|
|
790
934
|
action: 'remove',
|
|
@@ -793,7 +937,7 @@ function createRemoveCheckers(schema, authDict) {
|
|
|
793
937
|
var e_6, _a, e_7, _b;
|
|
794
938
|
var promises = [];
|
|
795
939
|
if (OneToManyMatrix[entity]) {
|
|
796
|
-
var
|
|
940
|
+
var _loop_5 = function (otm) {
|
|
797
941
|
var _g, _h;
|
|
798
942
|
var _j = tslib_1.__read(otm, 2), e = _j[0], attr = _j[1];
|
|
799
943
|
var proj = (_g = {
|
|
@@ -832,7 +976,7 @@ function createRemoveCheckers(schema, authDict) {
|
|
|
832
976
|
try {
|
|
833
977
|
for (var _c = (e_6 = void 0, tslib_1.__values(OneToManyMatrix[entity])), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
834
978
|
var otm = _d.value;
|
|
835
|
-
|
|
979
|
+
_loop_5(otm);
|
|
836
980
|
}
|
|
837
981
|
}
|
|
838
982
|
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
@@ -844,7 +988,7 @@ function createRemoveCheckers(schema, authDict) {
|
|
|
844
988
|
}
|
|
845
989
|
}
|
|
846
990
|
if (OneToManyOnEntityMatrix[entity]) {
|
|
847
|
-
var
|
|
991
|
+
var _loop_6 = function (otm) {
|
|
848
992
|
var _l, _m, _o;
|
|
849
993
|
var proj = {
|
|
850
994
|
id: 1,
|
|
@@ -890,7 +1034,7 @@ function createRemoveCheckers(schema, authDict) {
|
|
|
890
1034
|
try {
|
|
891
1035
|
for (var _e = (e_7 = void 0, tslib_1.__values(OneToManyOnEntityMatrix[entity])), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
892
1036
|
var otm = _f.value;
|
|
893
|
-
|
|
1037
|
+
_loop_6(otm);
|
|
894
1038
|
}
|
|
895
1039
|
}
|
|
896
1040
|
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
@@ -910,7 +1054,7 @@ function createRemoveCheckers(schema, authDict) {
|
|
|
910
1054
|
try {
|
|
911
1055
|
for (var entities_1 = tslib_1.__values(entities), entities_1_1 = entities_1.next(); !entities_1_1.done; entities_1_1 = entities_1.next()) {
|
|
912
1056
|
var entity = entities_1_1.value;
|
|
913
|
-
|
|
1057
|
+
_loop_3(entity);
|
|
914
1058
|
}
|
|
915
1059
|
}
|
|
916
1060
|
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
@@ -920,13 +1064,13 @@ function createRemoveCheckers(schema, authDict) {
|
|
|
920
1064
|
}
|
|
921
1065
|
finally { if (e_4) throw e_4.error; }
|
|
922
1066
|
}
|
|
923
|
-
var
|
|
1067
|
+
var _loop_4 = function (entity) {
|
|
924
1068
|
var e_8, _b;
|
|
925
1069
|
var cascadeRemove = authDict[entity].cascadeRemove;
|
|
926
1070
|
if (cascadeRemove) {
|
|
927
1071
|
var entitiesOnEntityAttr = [];
|
|
928
1072
|
var hasAllEntity = false;
|
|
929
|
-
var
|
|
1073
|
+
var _loop_7 = function (attr) {
|
|
930
1074
|
if (attr === '@entity') {
|
|
931
1075
|
hasAllEntity = true;
|
|
932
1076
|
return "continue";
|
|
@@ -1001,13 +1145,13 @@ function createRemoveCheckers(schema, authDict) {
|
|
|
1001
1145
|
}
|
|
1002
1146
|
};
|
|
1003
1147
|
for (var attr in cascadeRemove) {
|
|
1004
|
-
|
|
1148
|
+
_loop_7(attr);
|
|
1005
1149
|
}
|
|
1006
1150
|
if (hasAllEntity) {
|
|
1007
1151
|
var attributes = schema[entity].attributes;
|
|
1008
1152
|
var ref = attributes.entity.ref;
|
|
1009
1153
|
var restEntities = (0, lodash_1.difference)(ref, entitiesOnEntityAttr);
|
|
1010
|
-
var
|
|
1154
|
+
var _loop_8 = function (e) {
|
|
1011
1155
|
checkers.push({
|
|
1012
1156
|
entity: e,
|
|
1013
1157
|
action: 'remove',
|
|
@@ -1043,7 +1187,7 @@ function createRemoveCheckers(schema, authDict) {
|
|
|
1043
1187
|
try {
|
|
1044
1188
|
for (var restEntities_1 = (e_8 = void 0, tslib_1.__values(restEntities)), restEntities_1_1 = restEntities_1.next(); !restEntities_1_1.done; restEntities_1_1 = restEntities_1.next()) {
|
|
1045
1189
|
var e = restEntities_1_1.value;
|
|
1046
|
-
|
|
1190
|
+
_loop_8(e);
|
|
1047
1191
|
}
|
|
1048
1192
|
}
|
|
1049
1193
|
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
@@ -1058,7 +1202,7 @@ function createRemoveCheckers(schema, authDict) {
|
|
|
1058
1202
|
};
|
|
1059
1203
|
// 注入声明的cascade删除时的外键处理动作
|
|
1060
1204
|
for (var entity in authDict) {
|
|
1061
|
-
|
|
1205
|
+
_loop_4(entity);
|
|
1062
1206
|
}
|
|
1063
1207
|
return checkers;
|
|
1064
1208
|
}
|
package/lib/types/DataType.d.ts
CHANGED
|
@@ -8,11 +8,14 @@ export declare type Text = string;
|
|
|
8
8
|
export declare type Image = string;
|
|
9
9
|
export declare type File = string;
|
|
10
10
|
export declare type Datetime = number | Date;
|
|
11
|
+
export declare type Day = number | Date;
|
|
12
|
+
export declare type Time = number | Date;
|
|
11
13
|
export declare type Boolean = boolean;
|
|
14
|
+
export declare type Price = number;
|
|
12
15
|
export declare type PrimaryKey = string;
|
|
13
16
|
export declare type ForeignKey<E extends string> = string;
|
|
14
17
|
export declare type Sequence = string;
|
|
15
18
|
export { Geo, SingleGeo } from './Geo';
|
|
16
|
-
export declare type DataTypes = number | string | Datetime | Geo | Object | SingleGeo;
|
|
19
|
+
export declare type DataTypes = number | string | Datetime | Day | Time | Geo | Object | SingleGeo;
|
|
17
20
|
export declare const types: string[];
|
|
18
21
|
export declare const unIndexedTypes: string[];
|
package/lib/types/DataType.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.unIndexedTypes = exports.types = void 0;
|
|
4
|
-
exports.types = ['Int', 'Uint', 'Double', 'Float', 'String', 'Text', 'Datetime', '
|
|
4
|
+
exports.types = ['Int', 'Uint', 'Double', 'Float', 'String', 'Text', 'Datetime', 'Day', 'Time',
|
|
5
|
+
'Boolean', 'Image', 'File', 'Geo', 'SingleGeo', 'Price'];
|
|
5
6
|
exports.unIndexedTypes = ['Text', 'Image', 'File', 'Object'];
|
package/lib/types/Locale.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ declare type LocaleOfValue<V extends Record<string, string>> = {
|
|
|
13
13
|
};
|
|
14
14
|
export declare type LocaleDef<Sc extends Record<string, any>, Ac extends string, R extends string, V extends Record<string, string>> = {
|
|
15
15
|
[L in Language]?: {
|
|
16
|
+
name: string;
|
|
16
17
|
attr: LocaleOfSchema<Sc> & {
|
|
17
18
|
[A in keyof V]: string;
|
|
18
19
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EntityDict } from './Entity';
|
|
2
|
+
import { EntityDict as BaseEntityDict } from '../base-app-domain';
|
|
3
|
+
declare type ThemeColor = 'default' | 'success' | 'warning' | 'error';
|
|
4
|
+
export declare type ColorDict<ED extends BaseEntityDict & EntityDict> = {
|
|
5
|
+
[T in keyof ED]?: {
|
|
6
|
+
[A in keyof ED[T]['OpSchema']]?: {
|
|
7
|
+
[E in ED[T]['OpSchema'][A]]?: ThemeColor | `#${string}`;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export {};
|
package/lib/types/Timer.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { RecurrenceRule, RecurrenceSpecDateRange, RecurrenceSpecObjLit } from 'node-schedule';
|
|
1
2
|
import { EntityDict } from './Entity';
|
|
2
|
-
import { AsyncContext } from
|
|
3
|
+
import { AsyncContext } from '../store/AsyncRowStore';
|
|
3
4
|
declare type RoutineFn<ED extends EntityDict, Cxt extends AsyncContext<ED>> = (context: Cxt) => Promise<string>;
|
|
4
5
|
export declare type Routine<ED extends EntityDict, Cxt extends AsyncContext<ED>> = {
|
|
5
6
|
name: string;
|
|
@@ -7,7 +8,7 @@ export declare type Routine<ED extends EntityDict, Cxt extends AsyncContext<ED>>
|
|
|
7
8
|
};
|
|
8
9
|
export declare type Timer<ED extends EntityDict, Cxt extends AsyncContext<ED>> = {
|
|
9
10
|
name: string;
|
|
10
|
-
cron: string;
|
|
11
|
+
cron: RecurrenceRule | RecurrenceSpecDateRange | RecurrenceSpecObjLit | Date | string | number;
|
|
11
12
|
fn: RoutineFn<ED, Cxt>;
|
|
12
13
|
};
|
|
13
14
|
export {};
|
package/lib/types/index.d.ts
CHANGED
package/lib/types/index.js
CHANGED
|
@@ -22,3 +22,4 @@ tslib_1.__exportStar(require("./Connector"), exports);
|
|
|
22
22
|
tslib_1.__exportStar(require("./Timer"), exports);
|
|
23
23
|
tslib_1.__exportStar(require("./Port"), exports);
|
|
24
24
|
tslib_1.__exportStar(require("./Endpoint"), exports);
|
|
25
|
+
tslib_1.__exportStar(require("./Style"), exports);
|
|
@@ -10,7 +10,7 @@ function makeContentTypeAndBody(data) {
|
|
|
10
10
|
if (process.env.OAK_PLATFORM !== 'wechatMp') {
|
|
11
11
|
if (data instanceof FormData) {
|
|
12
12
|
return {
|
|
13
|
-
contentType: 'multipart/form-data',
|
|
13
|
+
// contentType: 'multipart/form-data',
|
|
14
14
|
body: data,
|
|
15
15
|
};
|
|
16
16
|
}
|
|
@@ -39,11 +39,12 @@ var SimpleConnector = /** @class */ (function (_super) {
|
|
|
39
39
|
_a = makeContentTypeAndBody(params), contentType = _a.contentType, body = _a.body;
|
|
40
40
|
return [4 /*yield*/, global.fetch(this.serverUrl, {
|
|
41
41
|
method: 'POST',
|
|
42
|
-
headers: {
|
|
43
|
-
'Content-Type': contentType,
|
|
42
|
+
headers: Object.assign({
|
|
44
43
|
'oak-cxt': cxtStr,
|
|
45
44
|
'oak-aspect': name,
|
|
46
|
-
},
|
|
45
|
+
}, contentType && {
|
|
46
|
+
'Content-Type': contentType,
|
|
47
|
+
}),
|
|
47
48
|
body: body,
|
|
48
49
|
})];
|
|
49
50
|
case 1:
|
|
@@ -106,7 +107,7 @@ var SimpleConnector = /** @class */ (function (_super) {
|
|
|
106
107
|
});
|
|
107
108
|
};
|
|
108
109
|
SimpleConnector.prototype.serializeResult = function (result, context, headers, body) {
|
|
109
|
-
if (result instanceof stream_1.Stream) {
|
|
110
|
+
if (result instanceof stream_1.Stream || result instanceof Buffer) {
|
|
110
111
|
return {
|
|
111
112
|
body: result,
|
|
112
113
|
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
declare const maskIdCard: (idCardNumber: string) => string;
|
|
2
|
+
declare const maskMobile: (mobile: string) => string;
|
|
3
|
+
declare const maskName: (name: string) => string;
|
|
4
|
+
declare const maskStar: (str: string, front: number, end: number, star: string) => string;
|
|
5
|
+
export { maskIdCard, maskMobile, maskName, maskStar, };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.maskStar = exports.maskName = exports.maskMobile = exports.maskIdCard = void 0;
|
|
4
|
+
var maskIdCard = function (idCardNumber) {
|
|
5
|
+
if (!idCardNumber instanceof String) {
|
|
6
|
+
throw new Error("身份证号码必须是String类型");
|
|
7
|
+
}
|
|
8
|
+
var begin = idCardNumber.slice(0, 4);
|
|
9
|
+
var end = idCardNumber.slice(idCardNumber.length - 4, 4);
|
|
10
|
+
for (var i = 0; i < idCardNumber.length - 8; i++) {
|
|
11
|
+
begin = begin.concat("*");
|
|
12
|
+
}
|
|
13
|
+
return begin.concat(end);
|
|
14
|
+
};
|
|
15
|
+
exports.maskIdCard = maskIdCard;
|
|
16
|
+
var maskMobile = function (mobile) {
|
|
17
|
+
var begin = mobile.slice(0, 3);
|
|
18
|
+
var end = mobile.slice(7, 11);
|
|
19
|
+
return begin.concat("****").concat(end);
|
|
20
|
+
};
|
|
21
|
+
exports.maskMobile = maskMobile;
|
|
22
|
+
var maskName = function (name) {
|
|
23
|
+
return name.slice(0, name.length - 1).concat("*");
|
|
24
|
+
};
|
|
25
|
+
exports.maskName = maskName;
|
|
26
|
+
var maskStar = function (str, frontLen, endLen, star) {
|
|
27
|
+
if (star === void 0) { star = '*'; }
|
|
28
|
+
var len = str.length - frontLen - endLen;
|
|
29
|
+
var xing = '';
|
|
30
|
+
for (var i = 0; i < len; i++) {
|
|
31
|
+
xing += star;
|
|
32
|
+
}
|
|
33
|
+
return str.substring(0, frontLen) + xing + str.substring(str.length - endLen);
|
|
34
|
+
};
|
|
35
|
+
exports.maskStar = maskStar;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
declare const ToCent: (float: number) => number;
|
|
2
|
+
declare const ToYuan: (int: number) => number;
|
|
3
|
+
declare const StringToCent: (value: string, allowNegative?: true) => number | undefined;
|
|
4
|
+
declare const CentToString: (value: number) => string | undefined;
|
|
5
|
+
export { ToCent, ToYuan, StringToCent, CentToString, };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CentToString = exports.StringToCent = exports.ToYuan = exports.ToCent = void 0;
|
|
4
|
+
var ToCent = function (float) {
|
|
5
|
+
return Math.round(float * 100);
|
|
6
|
+
};
|
|
7
|
+
exports.ToCent = ToCent;
|
|
8
|
+
var ToYuan = function (int) {
|
|
9
|
+
return Math.round(int) / 100;
|
|
10
|
+
};
|
|
11
|
+
exports.ToYuan = ToYuan;
|
|
12
|
+
var StringToCent = function (value, allowNegative) {
|
|
13
|
+
var numValue = parseInt(value, 10);
|
|
14
|
+
if (typeof numValue === 'number' && (numValue >= 0 || allowNegative)) {
|
|
15
|
+
return ToCent(numValue);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
exports.StringToCent = StringToCent;
|
|
19
|
+
var CentToString = function (value) {
|
|
20
|
+
if (typeof value === 'number') {
|
|
21
|
+
return "".concat(ToYuan(value));
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
exports.CentToString = CentToString;
|
package/lib/utils/validator.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export declare const isNickname: ValidatorFunction;
|
|
|
16
16
|
export declare const isSizedCaptcha: ValidatorFunction;
|
|
17
17
|
export declare const isDigital: ValidatorFunction;
|
|
18
18
|
export declare const isPhone: ValidatorFunction;
|
|
19
|
+
export declare const isTel: ValidatorFunction;
|
|
19
20
|
export declare const isNumber: ValidatorFunction;
|
|
20
21
|
export declare const isMoney: ValidatorMoneyFunction;
|
|
21
22
|
export declare const isVehicleNumber: ValidatorFunction;
|
package/lib/utils/validator.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
'use strict';
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.checkAttributesScope = exports.checkAttributesNotNull = exports.isVehicleNumber = exports.isMoney = exports.isNumber = exports.isPhone = exports.isDigital = exports.isSizedCaptcha = exports.isNickname = exports.isUrl = exports.isSoldierNumber = exports.isBirthNumber = exports.isTwCardNumber = exports.isAmCardNumber = exports.isHkCardNumber = exports.isPassportNumber = exports.isIdCardNumber = exports.isCaptcha = exports.isPassword = exports.isMobile = void 0;
|
|
6
|
+
exports.checkAttributesScope = exports.checkAttributesNotNull = exports.isVehicleNumber = exports.isMoney = exports.isNumber = exports.isTel = exports.isPhone = exports.isDigital = exports.isSizedCaptcha = exports.isNickname = exports.isUrl = exports.isSoldierNumber = exports.isBirthNumber = exports.isTwCardNumber = exports.isAmCardNumber = exports.isHkCardNumber = exports.isPassportNumber = exports.isIdCardNumber = exports.isCaptcha = exports.isPassword = exports.isMobile = void 0;
|
|
7
7
|
var types_1 = require("../types");
|
|
8
8
|
var isMobile = function (text) {
|
|
9
9
|
return ((text) && (typeof text === "string") && ((/^1[3|4|5|6|7|8|9]\d{9}$/.test(text))));
|
|
@@ -79,14 +79,19 @@ var isPhone = function (phone) {
|
|
|
79
79
|
return /^(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}$/.test(phone);
|
|
80
80
|
};
|
|
81
81
|
exports.isPhone = isPhone;
|
|
82
|
+
var isTel = function (text) {
|
|
83
|
+
// 1、133xxxx4545 2、0571-630xx239 3、400-123-1400
|
|
84
|
+
var reg = /^(((\d{3,4}-)?[0-9]{7,8})|(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}|((400)-(\d{3})-(\d{4})(.)(\d{1,4})|(400)-(\d{3})-(\d{4}$)|(400)(\d{3})(\d{4}$)|(400)-(\d{4})-(\d{3}$)))$/.test(text);
|
|
85
|
+
return reg;
|
|
86
|
+
};
|
|
87
|
+
exports.isTel = isTel;
|
|
82
88
|
var isNumber = function (str) {
|
|
83
89
|
return /^[0-9]*$/.test(str);
|
|
84
90
|
};
|
|
85
91
|
exports.isNumber = isNumber;
|
|
86
92
|
var isMoney = function (str, zero) {
|
|
87
|
-
// zero为true包含零
|
|
93
|
+
// 金额,最多可以有两位小数 zero为true包含零
|
|
88
94
|
if (zero) {
|
|
89
|
-
// 金额,最多可以有两位小数
|
|
90
95
|
return /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(str);
|
|
91
96
|
}
|
|
92
97
|
return /(^[1-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/.test(str);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oak-domain",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.5",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "XuChang"
|
|
6
6
|
},
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"@types/luxon": "^2.0.9",
|
|
28
28
|
"@types/mocha": "^8.2.0",
|
|
29
29
|
"@types/node": "^14.14.25",
|
|
30
|
+
"@types/node-schedule": "^2.1.0",
|
|
30
31
|
"@types/react": "^17.0.2",
|
|
31
32
|
"@types/uuid": "^8.3.0",
|
|
32
33
|
"@types/wechat-miniprogram": "^3.4.1",
|
|
@@ -40,9 +41,9 @@
|
|
|
40
41
|
"typescript": "^4.7.4"
|
|
41
42
|
},
|
|
42
43
|
"dependencies": {
|
|
43
|
-
"@datasert/cronjs-matcher": "^1.2.0",
|
|
44
44
|
"dayjs": "^1.11.5",
|
|
45
45
|
"lodash": "^4.17.21",
|
|
46
|
+
"node-schedule": "^2.1.1",
|
|
46
47
|
"uuid": "^9.0.0"
|
|
47
48
|
}
|
|
48
49
|
}
|
package/src/entities/Modi.ts
CHANGED
package/src/entities/Oper.ts
CHANGED
package/src/entities/User.ts
CHANGED
package/lib/utils/cron.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function schedule(cron: string, fn: (date: Date) => any): void;
|
package/lib/utils/cron.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.schedule = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var cronjs_matcher_1 = require("@datasert/cronjs-matcher");
|
|
6
|
-
var dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
7
|
-
function schedule(cron, fn) {
|
|
8
|
-
var futureMatches = (0, cronjs_matcher_1.getFutureMatches)(cron, {
|
|
9
|
-
matchCount: 1,
|
|
10
|
-
});
|
|
11
|
-
var date = (0, dayjs_1.default)(futureMatches[0]);
|
|
12
|
-
var interval = date.diff((0, dayjs_1.default)(), 'ms');
|
|
13
|
-
setTimeout(function () {
|
|
14
|
-
fn(new Date());
|
|
15
|
-
schedule(cron, fn);
|
|
16
|
-
}, interval);
|
|
17
|
-
}
|
|
18
|
-
exports.schedule = schedule;
|