Merge branch 'dev' of gitea.51mars.com:Oak-Team/oak-domain into dev

This commit is contained in:
Xu Chang 2024-08-30 14:18:42 +08:00
commit 8f908ddc21
8 changed files with 29 additions and 13 deletions

View File

@ -79,7 +79,7 @@ function createUniqueCheckers(schema) {
entity,
action: 'create',
type: 'logicalData',
priority: types_1.CHECKER_MAX_PRIORITY,
priority: types_1.CHECKER_MAX_PRIORITY, // 优先级要放在最低所有前置的checker/trigger将数据完整之后再在这里检测
checker: (operation, context) => {
const { data } = operation;
if (data instanceof Array) {
@ -95,9 +95,9 @@ function createUniqueCheckers(schema) {
}
}, {
entity,
action: 'update',
action: 'update', // 只检查update其它状态转换的action应该不会涉及unique约束的属性
type: 'logicalData',
priority: types_1.CHECKER_MAX_PRIORITY,
priority: types_1.CHECKER_MAX_PRIORITY, // 优先级要放在最低所有前置的checker/trigger将数据完整之后再在这里检测
checker: (operation, context) => {
const { data, filter: operationFilter } = operation;
if (data) {
@ -227,7 +227,7 @@ function createActionTransformerCheckers(actionDefDict) {
action: 'create',
type: 'logical',
entity,
priority: 10,
priority: 10, // 优先级要高先于真正的data检查进行
checker: (operation) => {
const { data } = operation;
if (data instanceof Array) {

View File

@ -19,6 +19,8 @@ export declare class OakException<ED extends EntityDict & BaseEntityDict> extend
tag2?: boolean;
tag3?: any;
}
export declare class OakMakeSureByMySelfException<ED extends EntityDict & BaseEntityDict> extends OakException<ED> {
}
export declare class OakPartialSuccess<ED extends EntityDict & BaseEntityDict> extends OakException<ED> {
}
export declare class OakDataException<ED extends EntityDict & BaseEntityDict> extends OakException<ED> {

View File

@ -1,6 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeException = exports.OakExternalException = exports.OakPreConditionUnsetException = exports.OakDeadlock = exports.OakCongruentRowExists = exports.OakRowLockedException = exports.OakUnloggedInException = exports.OakUserInvisibleException = exports.OakUserUnpermittedException = exports.OakAttrCantUpdateException = exports.OakAttrNotNullException = exports.OakInputIllegalException = exports.OakRowInconsistencyException = exports.OakServerProxyException = exports.OakNetworkException = exports.OakImportDataParseException = exports.OakUniqueViolationException = exports.OakUserException = exports.OakRowUnexistedException = exports.OakOperExistedException = exports.OakNoRelationDefException = exports.OakDataException = exports.OakPartialSuccess = exports.OakException = void 0;
exports.makeException = exports.OakExternalException = exports.OakPreConditionUnsetException = exports.OakDeadlock = exports.OakCongruentRowExists = exports.OakRowLockedException = exports.OakUnloggedInException = exports.OakUserInvisibleException = exports.OakUserUnpermittedException = exports.OakAttrCantUpdateException = exports.OakAttrNotNullException = exports.OakInputIllegalException = exports.OakRowInconsistencyException = exports.OakServerProxyException = exports.OakNetworkException = exports.OakImportDataParseException = exports.OakUniqueViolationException = exports.OakUserException = exports.OakRowUnexistedException = exports.OakOperExistedException = exports.OakNoRelationDefException = exports.OakDataException = exports.OakPartialSuccess = exports.OakMakeSureByMySelfException = exports.OakException = void 0;
const relation_1 = require("../store/relation");
const lodash_1 = require("../utils/lodash");
class OakException extends Error {
@ -90,6 +90,10 @@ class OakException extends Error {
tag3;
}
exports.OakException = OakException;
// 这个异常表示模块自己处理跨事务一致性框架pass在分布式数据传递时会用到backend-base老版本有使用先保留
class OakMakeSureByMySelfException extends OakException {
}
exports.OakMakeSureByMySelfException = OakMakeSureByMySelfException;
// 这个异常表示事务虽然没有完全成功,但是仍然应该提交并抛出异常(在分布式数据传递时会用到)
class OakPartialSuccess extends OakException {
}

View File

@ -1,3 +1,4 @@
/// <reference types="node" />
/**
* assert打包体积过大
*/

View File

@ -60,7 +60,7 @@ function destructRelationPath(schema, entity, path, relationFilter, recursive) {
},
filter: relationFilter,
} // as ED['userRelation']['Selection']
},
}, // as ED[keyof ED]['Selection']['data'],
getData: (d) => {
return d.userRelation$entity;
},

View File

@ -13,8 +13,10 @@ const isPassword = (text) => {
return ((text) && (typeof text === "string") && (/^[a-zA-Z0-9!.@]{8,16}$/.test(text)));
};
exports.isPassword = isPassword;
const isCaptcha = (text) => {
return ((text) && (typeof text === "string") && (/^\d{4}$/.test(text)));
const isCaptcha = (text, num) => {
const n = num || 4;
const regex = new RegExp(`^\\d{${n}}$`);
return ((text) && (typeof text === "string") && (regex.test(text)));
};
exports.isCaptcha = isCaptcha;
const isIdCardNumber = (text) => {

View File

@ -102,6 +102,11 @@ export class OakException<ED extends EntityDict & BaseEntityDict> extends Error
tag3?: any;
}
// 这个异常表示模块自己处理跨事务一致性框架pass在分布式数据传递时会用到backend-base老版本有使用先保留
export class OakMakeSureByMySelfException<ED extends EntityDict & BaseEntityDict> extends OakException<ED> {
}
// 这个异常表示事务虽然没有完全成功,但是仍然应该提交并抛出异常(在分布式数据传递时会用到)
export class OakPartialSuccess<ED extends EntityDict & BaseEntityDict> extends OakException<ED> {

View File

@ -17,15 +17,17 @@ type ValidatorMoneyFunction = (
export const isMobile: ValidatorFunction = (text) => {
return ( (text) && (typeof text === "string") && ((/^1[3|4|5|6|7|8|9]\d{9}$/.test(text))) );
return ((text) && (typeof text === "string") && ((/^1[3|4|5|6|7|8|9]\d{9}$/.test(text))));
};
export const isPassword: ValidatorFunction = (text) => {
return ((text) && (typeof text === "string") && (/^[a-zA-Z0-9!.@]{8,16}$/.test(text)))
};
export const isCaptcha: ValidatorFunction = (text) => {
return ((text) && (typeof text === "string") && (/^\d{4}$/.test(text)))
export const isCaptcha: ValidatorFunction = (text: string, num?: number) => {
const n = num || 4;
const regex: RegExp = new RegExp(`^\\d{${n}}$`);
return ((text) && (typeof text === "string") && (regex.test(text)))
};
export const isIdCardNumber: ValidatorFunction = (text) => {
@ -127,7 +129,7 @@ export const isEmail: ValidatorFunction = (str) => {
export function checkAttributesNotNull<ED extends EntityDict, T extends keyof EntityDict>(entity: T, data: Partial<ED[T]['CreateSingle']['data']>, attributes: Array<keyof ED[T]['CreateSingle']['data']>, allowEmpty?: true) {
const attrs = attributes.filter(
(attr) => {
if (data[attr] === null || data[attr] === ''|| data[attr] === undefined) {
if (data[attr] === null || data[attr] === '' || data[attr] === undefined) {
return true;
}
if (!allowEmpty && !data.hasOwnProperty(attr)) {
@ -144,7 +146,7 @@ export function checkAttributesNotNull<ED extends EntityDict, T extends keyof En
export function checkAttributesScope<ED extends EntityDict, T extends keyof EntityDict>(entity: T, data: Partial<ED[T]['CreateSingle']['data']>, attributes: Array<keyof ED[T]['CreateSingle']['data']>) {
const attrs = attributes.filter(
attr => !data.hasOwnProperty(attr)
) as string[];
) as string[];
if (attrs.length > 0) {
throw new OakInputIllegalException(entity as string, attrs, '多余的属性');