Merge branch 'release'
This commit is contained in:
commit
18e4411a83
|
|
@ -16,10 +16,10 @@ function checkUniqueBetweenRows(rows, uniqAttrs) {
|
|||
let s = '';
|
||||
for (const a of uniqAttrs) {
|
||||
if (row[a] === null || row[a] === undefined) {
|
||||
s + row.id;
|
||||
s += row.id;
|
||||
}
|
||||
else {
|
||||
s + `-${row[a]}`;
|
||||
s += `-${row[a]}`;
|
||||
}
|
||||
}
|
||||
if (dict[s]) {
|
||||
|
|
@ -188,7 +188,17 @@ function createActionTransformerCheckers(actionDefDict) {
|
|||
type: 'row',
|
||||
entity,
|
||||
filter: conditionalFilter,
|
||||
errMsg: '',
|
||||
errMsg: '数据状态已经改变',
|
||||
inconsistentRows: {
|
||||
entity,
|
||||
selection: (filter) => ({
|
||||
data: {
|
||||
id: 1,
|
||||
[attr]: 1,
|
||||
},
|
||||
filter,
|
||||
}),
|
||||
},
|
||||
});
|
||||
// 这里用data类型的checker改数据了不太好,先这样
|
||||
checkers.push({
|
||||
|
|
@ -331,7 +341,6 @@ function createAttrUpdateCheckers(schema, attrUpdateMatrix) {
|
|||
}
|
||||
if (f) {
|
||||
const rr = (0, filter_1.contains)(entity, context.getSchema(), data, f);
|
||||
console.log(rr);
|
||||
const result = (0, filter_1.checkFilterContains)(entity, context, f, filter, true);
|
||||
if (result instanceof Promise) {
|
||||
return result.then((v) => {
|
||||
|
|
|
|||
|
|
@ -68,7 +68,8 @@ function translateCheckerInAsyncContext(checker, schema) {
|
|||
throw e;
|
||||
}
|
||||
else {
|
||||
const rows2 = await context.select(entity, {
|
||||
// 可能会暴露隐私信息,暂时不能这样做。by Xc
|
||||
/* const rows2 = await context.select(entity, {
|
||||
data: getFullProjection(entity, context.getSchema()),
|
||||
filter: Object.assign({}, operationFilter, {
|
||||
$not: filter2,
|
||||
|
|
@ -76,9 +77,9 @@ function translateCheckerInAsyncContext(checker, schema) {
|
|||
}, {
|
||||
dontCollect: true,
|
||||
blockTrigger: true,
|
||||
});
|
||||
}); */
|
||||
const e = new Exception_1.OakRowInconsistencyException(undefined, errMsg);
|
||||
e.addData(entity, rows2);
|
||||
// e.addData(entity, rows2);
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,9 +1,14 @@
|
|||
import { EntityDict, OpRecord, SelectOpResult } from "./Entity";
|
||||
import { EntityDict, OpRecord } from "./Entity";
|
||||
export declare class OakException<ED extends EntityDict> extends Error {
|
||||
opRecord: SelectOpResult<ED>;
|
||||
opRecords: OpRecord<ED>[];
|
||||
constructor(message?: string);
|
||||
addData<T extends keyof ED>(entity: T, rows: Partial<ED[T]['OpSchema']>[]): void;
|
||||
setOpRecords(opRecord: SelectOpResult<ED>): void;
|
||||
setOpRecords(opRecords: OpRecord<ED>[]): void;
|
||||
getSerialData(): {
|
||||
name: string;
|
||||
message: string;
|
||||
opRecords: OpRecord<ED>[];
|
||||
};
|
||||
toString(): string;
|
||||
}
|
||||
export declare class OakMakeSureByMySelfException<ED extends EntityDict> extends OakException<ED> {
|
||||
|
|
@ -158,6 +163,6 @@ export declare class OakExternalException<ED extends EntityDict> extends OakUser
|
|||
export declare function makeException<ED extends EntityDict>(data: {
|
||||
name: string;
|
||||
message?: string;
|
||||
opRecords: SelectOpResult<ED>;
|
||||
opRecords: OpRecord<ED>[];
|
||||
[A: string]: any;
|
||||
}): OakException<ED> | undefined;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ exports.makeException = exports.OakExternalException = exports.OakPreConditionUn
|
|||
const tslib_1 = require("tslib");
|
||||
const assert_1 = tslib_1.__importDefault(require("assert"));
|
||||
class OakException extends Error {
|
||||
opRecord;
|
||||
opRecords;
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = new.target.name;
|
||||
|
|
@ -17,36 +17,32 @@ class OakException extends Error {
|
|||
else {
|
||||
this.__proto__ = new.target.prototype;
|
||||
}
|
||||
this.opRecord = {
|
||||
a: 's',
|
||||
d: {},
|
||||
};
|
||||
this.opRecords = [];
|
||||
}
|
||||
addData(entity, rows) {
|
||||
const { d } = this.opRecord;
|
||||
const addSingleRow = (rowRoot, row) => {
|
||||
const { id } = row;
|
||||
if (rowRoot[id]) {
|
||||
Object.assign(rowRoot[id], row);
|
||||
}
|
||||
else {
|
||||
rowRoot[id] = row;
|
||||
const record = {
|
||||
a: 's',
|
||||
d: {
|
||||
[entity]: {},
|
||||
}
|
||||
};
|
||||
if (!d[entity]) {
|
||||
d[entity] = {};
|
||||
for (const row of rows) {
|
||||
record.d[entity][row.id] = row;
|
||||
}
|
||||
rows.forEach(row => addSingleRow(d[entity], row));
|
||||
this.opRecords.push(record);
|
||||
}
|
||||
setOpRecords(opRecord) {
|
||||
this.opRecord = opRecord;
|
||||
setOpRecords(opRecords) {
|
||||
this.opRecords = opRecords;
|
||||
}
|
||||
toString() {
|
||||
return JSON.stringify({
|
||||
getSerialData() {
|
||||
return {
|
||||
name: this.constructor.name,
|
||||
message: this.message,
|
||||
opRecord: this.opRecord,
|
||||
});
|
||||
opRecords: this.opRecords,
|
||||
};
|
||||
}
|
||||
toString() {
|
||||
return JSON.stringify(this.getSerialData());
|
||||
}
|
||||
}
|
||||
exports.OakException = OakException;
|
||||
|
|
@ -85,9 +81,9 @@ class OakNoRelationDefException extends OakDataException {
|
|||
this.actions = actions;
|
||||
}
|
||||
toString() {
|
||||
const data = super.getSerialData();
|
||||
return JSON.stringify({
|
||||
name: this.constructor.name,
|
||||
message: this.message,
|
||||
...data,
|
||||
entity: this.entity,
|
||||
action: this.actions,
|
||||
});
|
||||
|
|
@ -105,7 +101,11 @@ class OakRowUnexistedException extends OakDataException {
|
|||
this.rows = rows;
|
||||
}
|
||||
toString() {
|
||||
return JSON.stringify({ rows: this.rows });
|
||||
const data = super.getSerialData();
|
||||
return JSON.stringify({
|
||||
...data,
|
||||
rows: this.rows
|
||||
});
|
||||
}
|
||||
getRows() {
|
||||
return this.rows;
|
||||
|
|
@ -140,10 +140,8 @@ class OakRowInconsistencyException extends OakUserException {
|
|||
(0, assert_1.default)(!data, '现在使用addData接口来传数据');
|
||||
}
|
||||
toString() {
|
||||
return JSON.stringify({
|
||||
name: this.constructor.name,
|
||||
message: this.message,
|
||||
});
|
||||
const data = super.getSerialData();
|
||||
return JSON.stringify(data);
|
||||
}
|
||||
}
|
||||
exports.OakRowInconsistencyException = OakRowInconsistencyException;
|
||||
|
|
@ -169,10 +167,10 @@ class OakInputIllegalException extends OakUserException {
|
|||
this.attributes = this.attributes.map(ele => `${prefix}.${ele}`);
|
||||
}
|
||||
toString() {
|
||||
const data = super.getSerialData();
|
||||
return JSON.stringify({
|
||||
...data,
|
||||
entity: this.entity,
|
||||
name: this.constructor.name,
|
||||
message: this.message,
|
||||
attributes: this.attributes,
|
||||
});
|
||||
}
|
||||
|
|
@ -209,10 +207,10 @@ class OakUserUnpermittedException extends OakUserException {
|
|||
this.operation = operation;
|
||||
}
|
||||
toString() {
|
||||
const data = super.getSerialData();
|
||||
return JSON.stringify({
|
||||
...data,
|
||||
entity: this.entity,
|
||||
name: this.constructor.name,
|
||||
message: this.message,
|
||||
operation: this.operation,
|
||||
});
|
||||
}
|
||||
|
|
@ -231,10 +229,10 @@ class OakUserInvisibleException extends OakUserException {
|
|||
this.operation = operation;
|
||||
}
|
||||
toString() {
|
||||
const data = super.getSerialData();
|
||||
return JSON.stringify({
|
||||
...data,
|
||||
entity: this.entity,
|
||||
name: this.constructor.name,
|
||||
message: this.message,
|
||||
operation: this.operation,
|
||||
});
|
||||
}
|
||||
|
|
@ -279,9 +277,9 @@ class OakCongruentRowExists extends OakUserException {
|
|||
return this.entity;
|
||||
}
|
||||
toString() {
|
||||
const data = super.getSerialData();
|
||||
return JSON.stringify({
|
||||
name: this.constructor.name,
|
||||
message: this.message,
|
||||
...data,
|
||||
data: this.data,
|
||||
entity: this.entity,
|
||||
});
|
||||
|
|
@ -310,9 +308,9 @@ class OakPreConditionUnsetException extends OakUserException {
|
|||
this.code = code;
|
||||
}
|
||||
toString() {
|
||||
const data = super.getSerialData();
|
||||
return JSON.stringify({
|
||||
name: this.constructor.name,
|
||||
message: this.message,
|
||||
...data,
|
||||
code: this.code,
|
||||
entity: this.entity,
|
||||
});
|
||||
|
|
@ -333,9 +331,10 @@ class OakExternalException extends OakUserException {
|
|||
this.data = data;
|
||||
}
|
||||
toString() {
|
||||
const data = super.getSerialData();
|
||||
return JSON.stringify({
|
||||
...data,
|
||||
code: this.code,
|
||||
message: this.message,
|
||||
source: this.source,
|
||||
data: this.data,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "oak-domain",
|
||||
"version": "5.0.4",
|
||||
"version": "5.0.5",
|
||||
"author": {
|
||||
"name": "XuChang"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -17,10 +17,10 @@ function checkUniqueBetweenRows(rows: Record<string, any>[], uniqAttrs: string[]
|
|||
let s = '';
|
||||
for (const a of uniqAttrs) {
|
||||
if (row[a] === null || row[a] === undefined) {
|
||||
s + row.id;
|
||||
s += row.id;
|
||||
}
|
||||
else {
|
||||
s + `-${row[a]}`;
|
||||
s += `-${row[a]}`;
|
||||
}
|
||||
}
|
||||
if (dict[s]) {
|
||||
|
|
@ -224,7 +224,17 @@ function createActionTransformerCheckers<ED extends EntityDict & BaseEntityDict,
|
|||
type: 'row',
|
||||
entity,
|
||||
filter: conditionalFilter,
|
||||
errMsg: '',
|
||||
errMsg: '数据状态已经改变',
|
||||
inconsistentRows: {
|
||||
entity,
|
||||
selection: (filter) => ({
|
||||
data: {
|
||||
id: 1,
|
||||
[attr]: 1,
|
||||
},
|
||||
filter,
|
||||
}),
|
||||
},
|
||||
} as RowChecker<ED, keyof ED, Cxt>);
|
||||
|
||||
// 这里用data类型的checker改数据了不太好,先这样
|
||||
|
|
@ -405,7 +415,6 @@ function createAttrUpdateCheckers<ED extends EntityDict & BaseEntityDict, Cxt ex
|
|||
}
|
||||
if (f) {
|
||||
const rr = contains<ED, keyof ED>(entity, context.getSchema(), data, f);
|
||||
console.log(rr);
|
||||
const result = checkFilterContains<ED, keyof ED, Cxt | FrontCxt>(entity, context, f, filter, true);
|
||||
if (result instanceof Promise) {
|
||||
return result.then(
|
||||
|
|
|
|||
|
|
@ -81,7 +81,8 @@ export function translateCheckerInAsyncContext<
|
|||
throw e;
|
||||
}
|
||||
else {
|
||||
const rows2 = await context.select(entity, {
|
||||
// 可能会暴露隐私信息,暂时不能这样做。by Xc
|
||||
/* const rows2 = await context.select(entity, {
|
||||
data: getFullProjection(entity, context.getSchema()),
|
||||
filter: Object.assign({}, operationFilter, {
|
||||
$not: filter2,
|
||||
|
|
@ -89,10 +90,10 @@ export function translateCheckerInAsyncContext<
|
|||
}, {
|
||||
dontCollect: true,
|
||||
blockTrigger: true,
|
||||
});
|
||||
}); */
|
||||
|
||||
const e = new OakRowInconsistencyException<ED>(undefined, errMsg);
|
||||
e.addData(entity, rows2);
|
||||
// e.addData(entity, rows2);
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import assert from "assert";
|
|||
import { EntityDict, OpRecord, SelectOpResult } from "./Entity";
|
||||
|
||||
export class OakException<ED extends EntityDict> extends Error {
|
||||
opRecord: SelectOpResult<ED>;
|
||||
opRecords: OpRecord<ED>[];
|
||||
constructor(message?: string) {
|
||||
super(message);
|
||||
this.name = new.target.name;
|
||||
|
|
@ -14,41 +14,37 @@ export class OakException<ED extends EntityDict> extends Error {
|
|||
} else {
|
||||
(this as any).__proto__ = new.target.prototype;
|
||||
}
|
||||
this.opRecord = {
|
||||
a: 's',
|
||||
d: {},
|
||||
};
|
||||
this.opRecords = [];
|
||||
}
|
||||
|
||||
addData<T extends keyof ED>(entity: T, rows: Partial<ED[T]['OpSchema']>[]) {
|
||||
const { d } = this.opRecord;
|
||||
const addSingleRow = (rowRoot: Record<string, Partial<ED[T]['OpSchema']>>, row: Partial<ED[T]['OpSchema']>) => {
|
||||
const { id } = row;
|
||||
if (rowRoot[id!]) {
|
||||
Object.assign(rowRoot[id!], row);
|
||||
const record: SelectOpResult<ED> = {
|
||||
a: 's',
|
||||
d: {
|
||||
[entity]: {},
|
||||
}
|
||||
else {
|
||||
rowRoot[id!] = row;
|
||||
}
|
||||
};
|
||||
if (!d[entity]) {
|
||||
d[entity] = {};
|
||||
} as SelectOpResult<ED>;
|
||||
for (const row of rows) {
|
||||
(record as any).d[entity][row.id] = row;
|
||||
}
|
||||
rows.forEach(
|
||||
row => addSingleRow(d[entity]!, row)
|
||||
);
|
||||
|
||||
this.opRecords.push(record);
|
||||
}
|
||||
|
||||
setOpRecords(opRecord: SelectOpResult<ED>) {
|
||||
this.opRecord = opRecord;
|
||||
setOpRecords(opRecords: OpRecord<ED>[]) {
|
||||
this.opRecords = opRecords;
|
||||
}
|
||||
|
||||
getSerialData() {
|
||||
return {
|
||||
name: this.constructor.name,
|
||||
message: this.message,
|
||||
opRecords: this.opRecords,
|
||||
};
|
||||
}
|
||||
|
||||
toString() {
|
||||
return JSON.stringify({
|
||||
name: this.constructor.name,
|
||||
message: this.message,
|
||||
opRecord: this.opRecord,
|
||||
});
|
||||
return JSON.stringify(this.getSerialData());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -97,9 +93,9 @@ export class OakNoRelationDefException<ED extends EntityDict, T extends keyof ED
|
|||
}
|
||||
|
||||
toString(): string {
|
||||
const data = super.getSerialData();
|
||||
return JSON.stringify({
|
||||
name: this.constructor.name,
|
||||
message: this.message,
|
||||
...data,
|
||||
entity: this.entity,
|
||||
action: this.actions,
|
||||
});
|
||||
|
|
@ -122,7 +118,11 @@ export class OakRowUnexistedException<ED extends EntityDict> extends OakDataExce
|
|||
}
|
||||
|
||||
toString() {
|
||||
return JSON.stringify({rows: this.rows });
|
||||
const data = super.getSerialData();
|
||||
return JSON.stringify({
|
||||
...data,
|
||||
rows: this.rows
|
||||
});
|
||||
}
|
||||
|
||||
getRows() {
|
||||
|
|
@ -162,10 +162,8 @@ export class OakRowInconsistencyException<ED extends EntityDict> extends OakUser
|
|||
}
|
||||
|
||||
toString(): string {
|
||||
return JSON.stringify({
|
||||
name: this.constructor.name,
|
||||
message: this.message,
|
||||
});
|
||||
const data = super.getSerialData();
|
||||
return JSON.stringify(data);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -196,10 +194,10 @@ export class OakInputIllegalException<ED extends EntityDict> extends OakUserExce
|
|||
}
|
||||
|
||||
toString(): string {
|
||||
const data = super.getSerialData();
|
||||
return JSON.stringify({
|
||||
...data,
|
||||
entity: this.entity,
|
||||
name: this.constructor.name,
|
||||
message: this.message,
|
||||
attributes: this.attributes,
|
||||
});
|
||||
}
|
||||
|
|
@ -238,10 +236,10 @@ export class OakUserUnpermittedException<ED extends EntityDict, T extends keyof
|
|||
|
||||
|
||||
toString(): string {
|
||||
const data = super.getSerialData();
|
||||
return JSON.stringify({
|
||||
...data,
|
||||
entity: this.entity,
|
||||
name: this.constructor.name,
|
||||
message: this.message,
|
||||
operation: this.operation,
|
||||
});
|
||||
}
|
||||
|
|
@ -262,10 +260,10 @@ export class OakUserInvisibleException<ED extends EntityDict, T extends keyof ED
|
|||
|
||||
|
||||
toString(): string {
|
||||
const data = super.getSerialData();
|
||||
return JSON.stringify({
|
||||
...data,
|
||||
entity: this.entity,
|
||||
name: this.constructor.name,
|
||||
message: this.message,
|
||||
operation: this.operation,
|
||||
});
|
||||
}
|
||||
|
|
@ -311,9 +309,9 @@ export class OakCongruentRowExists<ED extends EntityDict, T extends keyof ED> ex
|
|||
}
|
||||
|
||||
toString(): string {
|
||||
const data = super.getSerialData();
|
||||
return JSON.stringify({
|
||||
name: this.constructor.name,
|
||||
message: this.message,
|
||||
...data,
|
||||
data: this.data,
|
||||
entity: this.entity,
|
||||
});
|
||||
|
|
@ -344,9 +342,9 @@ export class OakPreConditionUnsetException<ED extends EntityDict> extends OakUse
|
|||
|
||||
|
||||
toString(): string {
|
||||
const data = super.getSerialData();
|
||||
return JSON.stringify({
|
||||
name: this.constructor.name,
|
||||
message: this.message,
|
||||
...data,
|
||||
code: this.code,
|
||||
entity: this.entity,
|
||||
});
|
||||
|
|
@ -369,9 +367,10 @@ export class OakExternalException<ED extends EntityDict> extends OakUserExceptio
|
|||
}
|
||||
|
||||
toString(): string {
|
||||
const data = super.getSerialData();
|
||||
return JSON.stringify({
|
||||
...data,
|
||||
code: this.code,
|
||||
message: this.message,
|
||||
source: this.source,
|
||||
data: this.data,
|
||||
});
|
||||
|
|
@ -381,7 +380,7 @@ export class OakExternalException<ED extends EntityDict> extends OakUserExceptio
|
|||
export function makeException<ED extends EntityDict>(data: {
|
||||
name: string;
|
||||
message?: string;
|
||||
opRecords: SelectOpResult<ED>;
|
||||
opRecords: OpRecord<ED>[];
|
||||
[A: string]: any;
|
||||
}) {
|
||||
const { name } = data;
|
||||
|
|
|
|||
Loading…
Reference in New Issue